From 9ef051dbc5db22c384246d1ee4462a19b987163e Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Wed, 7 Feb 2024 20:46:18 +0100 Subject: [PATCH] [K/N][Tests] Migrate test override_konan_properties0 ^KT-61259 --- .../backend.native/tests/build.gradle | 15 ---- .../tests/runtime/basic/driver0.out | 1 - .../native.tests/testData/driver}/driver0.kt | 0 native/native.tests/testData/driver/hello.kt | 1 - .../kotlin/konan/test/KonanDriverTest.kt | 76 +++++++++++++++++-- .../support/compilation/TestCompilation.kt | 18 +++-- 6 files changed, 81 insertions(+), 30 deletions(-) delete mode 100644 kotlin-native/backend.native/tests/runtime/basic/driver0.out rename {kotlin-native/backend.native/tests/runtime/basic => native/native.tests/testData/driver}/driver0.kt (100%) delete mode 100644 native/native.tests/testData/driver/hello.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index ca89de7c169..82d3ff93d10 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -914,21 +914,6 @@ standaloneTest("testing_stacktrace") { } } -// Just check that the driver is able to produce runnable binaries. -tasks.register("driver0", KonanDriverTest) { - disabled = isAggressiveGC // No need to test with different GC schedulers - useGoldenData = true - source = "runtime/basic/driver0.kt" -} - -tasks.register("driver_opt", KonanDriverTest) { - disabled = (cacheTesting != null) // Cache is not compatible with -opt. - || isAggressiveGC // No need to test with different GC schedulers - useGoldenData = true - source = "runtime/basic/driver_opt.kt" - flags = ["-opt"] -} - // A helper method to create interop artifacts void createInterop(String name, Closure conf) { konanArtifacts { diff --git a/kotlin-native/backend.native/tests/runtime/basic/driver0.out b/kotlin-native/backend.native/tests/runtime/basic/driver0.out deleted file mode 100644 index af5626b4a11..00000000000 --- a/kotlin-native/backend.native/tests/runtime/basic/driver0.out +++ /dev/null @@ -1 +0,0 @@ -Hello, world! diff --git a/kotlin-native/backend.native/tests/runtime/basic/driver0.kt b/native/native.tests/testData/driver/driver0.kt similarity index 100% rename from kotlin-native/backend.native/tests/runtime/basic/driver0.kt rename to native/native.tests/testData/driver/driver0.kt diff --git a/native/native.tests/testData/driver/hello.kt b/native/native.tests/testData/driver/hello.kt deleted file mode 100644 index dbd2d6996f7..00000000000 --- a/native/native.tests/testData/driver/hello.kt +++ /dev/null @@ -1 +0,0 @@ -fun main() = println("hello") \ No newline at end of file diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/KonanDriverTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/KonanDriverTest.kt index 229782355c4..f0e275015ba 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/KonanDriverTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/KonanDriverTest.kt @@ -9,6 +9,11 @@ import com.intellij.testFramework.TestDataPath import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.konan.test.blackbox.AbstractNativeSimpleTest import org.jetbrains.kotlin.konan.test.blackbox.support.NativeSimpleTestSupport +import org.jetbrains.kotlin.konan.test.blackbox.support.TestCase +import org.jetbrains.kotlin.konan.test.blackbox.support.TestCompilerArgs +import org.jetbrains.kotlin.konan.test.blackbox.support.TestModule +import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.ExecutableCompilation +import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationArtifact import org.jetbrains.kotlin.konan.test.blackbox.support.settings.Binaries import org.jetbrains.kotlin.konan.test.blackbox.support.settings.GCScheduler import org.jetbrains.kotlin.konan.test.blackbox.support.settings.KotlinNativeHome @@ -21,6 +26,8 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import java.io.File import kotlin.test.assertFalse +import kotlin.test.assertEquals +import kotlin.test.assertTrue import kotlin.time.Duration @Tag("driver") @@ -32,16 +39,16 @@ class KonanDriverTest : AbstractNativeSimpleTest() { private val konanc get() = konanHome.resolve("bin").resolve(if (HostManager.hostIsMingw) "konanc.bat" else "konanc") private val testSuiteDir = File("native/native.tests/testData/driver") + private val source = testSuiteDir.resolve("driver0.kt") @Test fun testLLVMVariantDev() { // We use clang from Xcode on macOS for apple targets, // so it is hard to reliably detect LLVM variant for these targets. -// Assumptions.assumeFalse(targets.hostTarget.family.isAppleFamily && targets.testTarget.family.isAppleFamily) + Assumptions.assumeFalse(targets.hostTarget.family.isAppleFamily && targets.testTarget.family.isAppleFamily) // No need to test with different GC schedulers Assumptions.assumeFalse(testRunSettings.get() == GCScheduler.AGGRESSIVE) - val source = testSuiteDir.resolve("hello.kt") val flags = listOf("-Xllvm-variant=dev", "-Xverbose-phases=ObjectFiles") val args = mutableListOf("-output", buildDir.resolve("kexe.kexe").absolutePath).apply { add("-target") @@ -52,12 +59,71 @@ class KonanDriverTest : AbstractNativeSimpleTest() { add("-Xpartial-linkage-loglevel=error") } - val result: RunProcessResult = runProcess(konanc.absolutePath, source.absolutePath, *args.toTypedArray()) { + val compilationResult: RunProcessResult = runProcess(konanc.absolutePath, source.absolutePath, *args.toTypedArray()) { timeout = Duration.parse("5m") } assertFalse( - result.stdout.contains("-essentials"), - "`-essentials` must not be in stdout of dev LLVM.\nSTDOUT: ${result.stdout}\nSTDERR: ${result.stderr}\n---" + compilationResult.stdout.contains("-essentials"), + "`-essentials` must not be in stdout of dev LLVM.\nSTDOUT: ${compilationResult.stdout}\nSTDERR: ${compilationResult.stderr}\n---" + ) + } + + @Test + fun testDriverProducesRunnableBinaries() { + // No need to test with different GC schedulers + Assumptions.assumeFalse(testRunSettings.get() == GCScheduler.AGGRESSIVE) + + val module = TestModule.Exclusive("moduleName", emptySet(), emptySet(), emptySet()) + val kexe = buildDir.resolve("kexe.kexe") + val compilation = ExecutableCompilation( + settings = testRunSettings, + freeCompilerArgs = TestCompilerArgs.EMPTY, + sourceModules = listOf(module), + extras = TestCase.NoTestRunnerExtras("main"), + dependencies = emptyList(), + expectedArtifact = TestCompilationArtifact.Executable(kexe), + tryPassSystemCacheDirectory = true + ) + runProcess(konanc.absolutePath, source.absolutePath, *compilation.getCompilerArgs()) { + timeout = Duration.parse("5m") + } + val runResult: RunProcessResult = runProcess(kexe.absolutePath) { + timeout = Duration.parse("5m") + } + assertEquals("Hello, world!", runResult.stdout) + } + + @Test + fun testOverrideKonanProperties() { + // No need to test with different GC schedulers + Assumptions.assumeFalse(testRunSettings.get() == GCScheduler.AGGRESSIVE) + + val module = TestModule.Exclusive("moduleName", emptySet(), emptySet(), emptySet()) + val kexe = buildDir.resolve("kexe.kexe") + val compilation = ExecutableCompilation( + settings = testRunSettings, + freeCompilerArgs = TestCompilerArgs( + listOf( + "-opt", + "-Xverbose-phases=MandatoryBitcodeLLVMPostprocessingPhase", + if (HostManager.hostIsMingw) + "-Xoverride-konan-properties=\"llvmInlineThreshold=76\"" + else "-Xoverride-konan-properties=llvmInlineThreshold=76" + )), + sourceModules = listOf(module), + extras = TestCase.NoTestRunnerExtras("main"), + dependencies = emptyList(), + expectedArtifact = TestCompilationArtifact.Executable(kexe), + tryPassSystemCacheDirectory = true + ) + val compilationResult = runProcess(konanc.absolutePath, source.absolutePath, *compilation.getCompilerArgs()) { + timeout = Duration.parse("5m") + } + val expected = "inline_threshold: 76" + assertTrue( + compilationResult.stdout.contains(expected), + "Compiler's stdout must contain string: $expected\n" + + "STDOUT:\n${compilationResult.stdout}\nSTDERR:${compilationResult.stderr}" ) } } 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 37a193778f4..8e0610f877d 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 @@ -125,14 +125,7 @@ internal abstract class BasicCompilation( protected open fun postCompileCheck() = Unit private fun doCompile(): TestCompilationResult.ImmediateResult { - val compilerArgs = buildArgs { - applyCommonArgs() - applySpecificArgs(this) - applyDependencies(this) - applyFreeArgs() - applyCompilerPlugins() - applySources() - } + val compilerArgs = getCompilerArgs() val loggedCompilerInput = LoggedData.CompilerInput(sourceModules) val loggedCompilerParameters = LoggedData.CompilerParameters(home, compilerArgs) @@ -180,6 +173,15 @@ internal abstract class BasicCompilation( return result } + + fun getCompilerArgs() = buildArgs { + applyCommonArgs() + applySpecificArgs(this) + applyDependencies(this) + applyFreeArgs() + applyCompilerPlugins() + applySources() + } } internal abstract class SourceBasedCompilation(