From 9832edddab3ae6d09f0e66fcc0a20744f3f28d57 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Fri, 23 Feb 2024 13:12:59 +0100 Subject: [PATCH] Revert "Revert "[K/N][Tests] Migrate test override_konan_properties0 and add testDriverVersion"" This reverts commit 8518c3f54f6c66c769665adefdfdd3062471368b. --- .../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, 52 insertions(+), 46 deletions(-) delete mode 100644 kotlin-native/backend.native/tests/runtime/basic/driver_opt.kt delete 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 ca2571cc7dd..8ba17ab0977 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1292,26 +1292,6 @@ 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 deleted file mode 100644 index 4feb92951c3..00000000000 --- a/kotlin-native/backend.native/tests/runtime/basic/driver_opt.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * 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 deleted file mode 100644 index af5626b4a11..00000000000 --- a/kotlin-native/backend.native/tests/runtime/basic/driver_opt.out +++ /dev/null @@ -1 +0,0 @@ -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 f0e275015ba..9914c439074 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,6 +14,7 @@ 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 @@ -43,14 +44,29 @@ class KonanDriverTest : AbstractNativeSimpleTest() { @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. + // 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. 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 flags = listOf("-Xllvm-variant=dev", "-Xverbose-phases=ObjectFiles") - val args = mutableListOf("-output", buildDir.resolve("kexe.kexe").absolutePath).apply { + 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 { add("-target") add(targets.testTarget.visibleName) addAll(flags) @@ -59,22 +75,17 @@ class KonanDriverTest : AbstractNativeSimpleTest() { add("-Xpartial-linkage-loglevel=error") } - val compilationResult: RunProcessResult = runProcess(konanc.absolutePath, source.absolutePath, *args.toTypedArray()) { + val compilationResult = runProcess(konanc.absolutePath, source.absolutePath, *args.toTypedArray()) { timeout = Duration.parse("5m") } - assertFalse( - compilationResult.stdout.contains("-essentials"), - "`-essentials` must not be in stdout of dev LLVM.\nSTDOUT: ${compilationResult.stdout}\nSTDERR: ${compilationResult.stderr}\n---" - ) + testRunSettings.executor.runProcess(kexe.absolutePath) // run generated executable just to check its sanity + return compilationResult } @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 kexe = buildDir.resolve("kexe.kexe").also { it.delete() } val compilation = ExecutableCompilation( settings = testRunSettings, freeCompilerArgs = TestCompilerArgs.EMPTY, @@ -87,19 +98,43 @@ class KonanDriverTest : AbstractNativeSimpleTest() { runProcess(konanc.absolutePath, source.absolutePath, *compilation.getCompilerArgs()) { timeout = Duration.parse("5m") } - val runResult: RunProcessResult = runProcess(kexe.absolutePath) { - 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()) { + timeout = Duration.parse("5m") + } + assertFalse(kexe.exists()) + } + @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 kexe = buildDir.resolve("kexe.kexe").also { it.delete() } val compilation = ExecutableCompilation( settings = testRunSettings, freeCompilerArgs = TestCompilerArgs( @@ -125,5 +160,6 @@ class KonanDriverTest : AbstractNativeSimpleTest() { "Compiler's stdout must contain string: $expected\n" + "STDOUT:\n${compilationResult.stdout}\nSTDERR:${compilationResult.stderr}" ) + testRunSettings.executor.runProcess(kexe.absolutePath) } }