From 8a8eb18efd8261d25674adb8e7b90649b4d239f0 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Fri, 8 Dec 2023 16:09:27 +0100 Subject: [PATCH] [K/N][tests] Make mention of the test data file grouping more visible When running `codegen/box` tests, Kotlin/Native test infrastructure divides test data files into groups and compiles each group in a single compilation. As a result, compilation problem with one test can cause an unrelated nearby test to fail. To make this less frustrating, this commit adjusts test failure reports: it moves the test grouping mention from the bottom of a report to the top and makes the wording more clear and actionable. --- .../konan/test/blackbox/support/LoggedData.kt | 36 ++++++++++++------- .../support/compilation/TestCompilation.kt | 15 ++++++-- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/LoggedData.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/LoggedData.kt index 3585b070e47..c741be89d65 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/LoggedData.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/LoggedData.kt @@ -53,12 +53,7 @@ internal abstract class LoggedData { } } - class CompilerParameters( - private val home: KotlinNativeHome, - private val compilerArgs: Array, - private val sourceModules: Collection, - private val environment: JVMEnvironment = JVMEnvironment() // Capture environment. - ) : LoggedData() { + class CompilerInput(private val sourceModules: Collection) : LoggedData() { private val testDataFiles: List get() = buildList { sourceModules.forEach { module -> @@ -68,16 +63,30 @@ internal abstract class LoggedData { sort() } + override fun computeText(): String = buildString { + val files = testDataFiles + if (files.size > 1) { + appendLine("NOTE: this compilation includes multiple test data files!") + appendLine(" So a test failure doesn't imply that something is wrong with that particular test.") + appendLine(" To check the single test data file, rerun the test with the following Gradle flag:") + appendLine(" -Pkotlin.internal.native.test.forceStandalone=true") + appendLine() + appendList("TEST DATA FILES (COMPILED TOGETHER):", testDataFiles) + } else { + appendLine("TEST DATA FILE: ${files.singleOrNull()}") + } + } + } + + class CompilerParameters( + private val home: KotlinNativeHome, + private val compilerArgs: Array, + private val environment: JVMEnvironment = JVMEnvironment() // Capture environment. + ) : LoggedData() { override fun computeText() = buildString { appendArguments("COMPILER ARGUMENTS:", listOf(home.dir.resolve("bin/kotlinc-native").path) + compilerArgs) appendLine() appendLine(environment) - - val testDataFiles = testDataFiles - if (testDataFiles.isNotEmpty()) { - appendLine() - appendList("TEST DATA FILES (COMPILED TOGETHER):", testDataFiles) - } } } @@ -100,6 +109,7 @@ internal abstract class LoggedData { class CompilationToolCall( private val toolName: String, + private val input: LoggedData?, private val parameters: LoggedData, val exitCode: ExitCode, val toolOutput: String, @@ -113,6 +123,8 @@ internal abstract class LoggedData { ) return buildString { + input?.let(::appendLine) + if (problems.isNotEmpty()) { appendLine("$toolName PROBLEMS:") problems.forEach(::appendLine) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt index 7ff62aecdd3..c29501fe381 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/support/compilation/TestCompilation.kt @@ -89,7 +89,8 @@ internal abstract class BasicCompilation( applySources() } - val loggedCompilerParameters = LoggedData.CompilerParameters(home, compilerArgs, sourceModules) + val loggedCompilerInput = LoggedData.CompilerInput(sourceModules) + val loggedCompilerParameters = LoggedData.CompilerParameters(home, compilerArgs) val (loggedCompilerCall: LoggedData, result: TestCompilationResult.ImmediateResult) = try { val compilerToolCallResult = when (compilerOutputInterceptor) { @@ -105,8 +106,15 @@ internal abstract class BasicCompilation( val (exitCode, compilerOutput, compilerOutputHasErrors, duration) = compilerToolCallResult - val loggedCompilationToolCall = - LoggedData.CompilationToolCall("COMPILER", loggedCompilerParameters, exitCode, compilerOutput, compilerOutputHasErrors, duration) + val loggedCompilationToolCall = LoggedData.CompilationToolCall( + "COMPILER", + loggedCompilerInput, + loggedCompilerParameters, + exitCode, + compilerOutput, + compilerOutputHasErrors, + duration + ) val result = if (exitCode != ExitCode.OK || compilerOutputHasErrors) TestCompilationResult.CompilationToolFailure(loggedCompilationToolCall) @@ -282,6 +290,7 @@ internal class CInteropCompilation( val loggedInteropCall = LoggedData.CompilationToolCall( toolName = "CINTEROP", + input = null, parameters = loggedCInteropParameters, exitCode = exitCode, toolOutput = cinteropOutput,