From 8518c3f54f6c66c769665adefdfdd3062471368b Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Wed, 21 Feb 2024 23:41:15 +0100 Subject: [PATCH] Revert "[K/N][Tests] Migrate test override_konan_properties0 and add testDriverVersion" This reverts commit fbe8db4b4556d4f4c0a86df8569e13fa47b49b31. --- .../backend.native/tests/build.gradle | 20 ++++++ .../tests/runtime/basic/driver_opt.kt | 9 +++ .../tests/runtime/basic/driver_opt.out | 1 + .../kotlin/konan/test/KonanDriverTest.kt | 68 +++++-------------- 4 files changed, 46 insertions(+), 52 deletions(-) create mode 100644 kotlin-native/backend.native/tests/runtime/basic/driver_opt.kt create mode 100644 kotlin-native/backend.native/tests/runtime/basic/driver_opt.out diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 13d415e80c5..3d495fbcb32 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1331,6 +1331,26 @@ standaloneTest("split_compilation_pipeline") { useGoldenData = true } +tasks.register("override_konan_properties0", KonanDriverTest) { + disabled = isAggressiveGC // No need to test with different GC schedulers + def overrides = PlatformInfo.isWindows() + ? '-Xoverride-konan-properties="llvmInlineThreshold=76"' + : '-Xoverride-konan-properties=llvmInlineThreshold=76' + flags = [ + "-opt", + "-Xverbose-phases=MandatoryBitcodeLLVMPostprocessingPhase", + overrides + ] + compilerMessages = true + source = "link/ir_providers/hello.kt" + def messages = "inline_threshold: 76\nhello\n" + outputChecker = { out -> + messages.split("\n") + .collect { line -> out.contains(line) } + .every { it == true } + } +} + /** * Builds tests into a single binary with TestRunner */ diff --git a/kotlin-native/backend.native/tests/runtime/basic/driver_opt.kt b/kotlin-native/backend.native/tests/runtime/basic/driver_opt.kt new file mode 100644 index 00000000000..4feb92951c3 --- /dev/null +++ b/kotlin-native/backend.native/tests/runtime/basic/driver_opt.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +// TODO: remove kotlin_native.io once overrides are in place. +fun main(args : Array) { + println("Hello, world!") +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/runtime/basic/driver_opt.out b/kotlin-native/backend.native/tests/runtime/basic/driver_opt.out new file mode 100644 index 00000000000..af5626b4a11 --- /dev/null +++ b/kotlin-native/backend.native/tests/runtime/basic/driver_opt.out @@ -0,0 +1 @@ +Hello, world! 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 9914c439074..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 @@ -14,7 +14,6 @@ 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.executor 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 @@ -44,29 +43,14 @@ class KonanDriverTest : AbstractNativeSimpleTest() { @Test fun testLLVMVariantDev() { - // On macOS for apple targets, clang++ from Xcode is used, which is not switchable as `dev/user`, - // so the test cannot detect LLVM variant for apple targets on macOS host. + // 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) // No need to test with different GC schedulers Assumptions.assumeFalse(testRunSettings.get() == GCScheduler.AGGRESSIVE) - compileSimpleFile(listOf("-Xllvm-variant=dev", "-Xverbose-phases=ObjectFiles")).let { - assertFalse( - it.stdout.contains("-essentials"), - "`-essentials` must not be in stdout of dev LLVM.\nSTDOUT: ${it.stdout}\nSTDERR: ${it.stderr}\n---" - ) - } - compileSimpleFile(listOf("-Xllvm-variant=user", "-Xverbose-phases=ObjectFiles")).let { - assertTrue( - it.stdout.contains("-essentials"), - "`-essentials` must be in stdout of user LLVM.\nSTDOUT: ${it.stdout}\nSTDERR: ${it.stderr}\n---" - ) - } - } - - private fun compileSimpleFile(flags: List): RunProcessResult { - val kexe = buildDir.resolve("kexe.kexe").also { it.delete() } - val args = mutableListOf("-output", kexe.absolutePath).apply { + val flags = listOf("-Xllvm-variant=dev", "-Xverbose-phases=ObjectFiles") + val args = mutableListOf("-output", buildDir.resolve("kexe.kexe").absolutePath).apply { add("-target") add(targets.testTarget.visibleName) addAll(flags) @@ -75,17 +59,22 @@ class KonanDriverTest : AbstractNativeSimpleTest() { add("-Xpartial-linkage-loglevel=error") } - val compilationResult = runProcess(konanc.absolutePath, source.absolutePath, *args.toTypedArray()) { + val compilationResult: RunProcessResult = runProcess(konanc.absolutePath, source.absolutePath, *args.toTypedArray()) { timeout = Duration.parse("5m") } - testRunSettings.executor.runProcess(kexe.absolutePath) // run generated executable just to check its sanity - return compilationResult + assertFalse( + 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").also { it.delete() } + val kexe = buildDir.resolve("kexe.kexe") val compilation = ExecutableCompilation( settings = testRunSettings, freeCompilerArgs = TestCompilerArgs.EMPTY, @@ -98,34 +87,10 @@ class KonanDriverTest : AbstractNativeSimpleTest() { runProcess(konanc.absolutePath, source.absolutePath, *compilation.getCompilerArgs()) { timeout = Duration.parse("5m") } - val runResult: RunProcessResult = with(testRunSettings) { - executor.runProcess(kexe.absolutePath) { - timeout = Duration.parse("1m") - } - } - assertEquals("Hello, world!", runResult.stdout) - } - - @Test - fun testDriverVersion() { - // 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").also { it.delete() } - val compilation = ExecutableCompilation( - settings = testRunSettings, - freeCompilerArgs = TestCompilerArgs(listOf("-version")), - sourceModules = listOf(module), - extras = TestCase.NoTestRunnerExtras("main"), - dependencies = emptyList(), - expectedArtifact = TestCompilationArtifact.Executable(kexe), - tryPassSystemCacheDirectory = true - ) - runProcess(konanc.absolutePath, source.absolutePath, *compilation.getCompilerArgs()) { + val runResult: RunProcessResult = runProcess(kexe.absolutePath) { timeout = Duration.parse("5m") } - assertFalse(kexe.exists()) + assertEquals("Hello, world!", runResult.stdout) } @Test @@ -134,7 +99,7 @@ class KonanDriverTest : AbstractNativeSimpleTest() { Assumptions.assumeFalse(testRunSettings.get() == GCScheduler.AGGRESSIVE) val module = TestModule.Exclusive("moduleName", emptySet(), emptySet(), emptySet()) - val kexe = buildDir.resolve("kexe.kexe").also { it.delete() } + val kexe = buildDir.resolve("kexe.kexe") val compilation = ExecutableCompilation( settings = testRunSettings, freeCompilerArgs = TestCompilerArgs( @@ -160,6 +125,5 @@ class KonanDriverTest : AbstractNativeSimpleTest() { "Compiler's stdout must contain string: $expected\n" + "STDOUT:\n${compilationResult.stdout}\nSTDERR:${compilationResult.stderr}" ) - testRunSettings.executor.runProcess(kexe.absolutePath) } }