From 4765cfda533c85a582a1cf291c401584ad9a2a3d 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" This reverts commit 9ef051dbc5db22c384246d1ee4462a19b987163e. --- .../backend.native/tests/build.gradle | 15 ++++ .../tests/runtime/basic}/driver0.kt | 0 .../tests/runtime/basic/driver0.out | 1 + native/native.tests/testData/driver/hello.kt | 1 + .../kotlin/konan/test/KonanDriverTest.kt | 76 ++----------------- .../support/compilation/TestCompilation.kt | 18 ++--- 6 files changed, 30 insertions(+), 81 deletions(-) rename {native/native.tests/testData/driver => kotlin-native/backend.native/tests/runtime/basic}/driver0.kt (100%) create mode 100644 kotlin-native/backend.native/tests/runtime/basic/driver0.out create 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 3d495fbcb32..5c4561217a6 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -912,6 +912,21 @@ 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/native/native.tests/testData/driver/driver0.kt b/kotlin-native/backend.native/tests/runtime/basic/driver0.kt similarity index 100% rename from native/native.tests/testData/driver/driver0.kt rename to kotlin-native/backend.native/tests/runtime/basic/driver0.kt diff --git a/kotlin-native/backend.native/tests/runtime/basic/driver0.out b/kotlin-native/backend.native/tests/runtime/basic/driver0.out new file mode 100644 index 00000000000..af5626b4a11 --- /dev/null +++ b/kotlin-native/backend.native/tests/runtime/basic/driver0.out @@ -0,0 +1 @@ +Hello, world! diff --git a/native/native.tests/testData/driver/hello.kt b/native/native.tests/testData/driver/hello.kt new file mode 100644 index 00000000000..dbd2d6996f7 --- /dev/null +++ b/native/native.tests/testData/driver/hello.kt @@ -0,0 +1 @@ +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 f0e275015ba..229782355c4 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,11 +9,6 @@ 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 @@ -26,8 +21,6 @@ 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") @@ -39,16 +32,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") @@ -59,71 +52,12 @@ class KonanDriverTest : AbstractNativeSimpleTest() { add("-Xpartial-linkage-loglevel=error") } - val compilationResult: RunProcessResult = runProcess(konanc.absolutePath, source.absolutePath, *args.toTypedArray()) { + val result: RunProcessResult = 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---" - ) - } - - @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}" + result.stdout.contains("-essentials"), + "`-essentials` must not be in stdout of dev LLVM.\nSTDOUT: ${result.stdout}\nSTDERR: ${result.stderr}\n---" ) } } 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 77013be5499..0ade61a74ea 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,7 +125,14 @@ internal abstract class BasicCompilation( protected open fun postCompileCheck() = Unit private fun doCompile(): TestCompilationResult.ImmediateResult { - val compilerArgs = getCompilerArgs() + val compilerArgs = buildArgs { + applyCommonArgs() + applySpecificArgs(this) + applyDependencies(this) + applyFreeArgs() + applyCompilerPlugins() + applySources() + } val loggedCompilerInput = LoggedData.CompilerInput(sourceModules) val loggedCompilerParameters = LoggedData.CompilerParameters(home, compilerArgs) @@ -173,15 +180,6 @@ internal abstract class BasicCompilation( return result } - - fun getCompilerArgs() = buildArgs { - applyCommonArgs() - applySpecificArgs(this) - applyDependencies(this) - applyFreeArgs() - applyCompilerPlugins() - applySources() - } } internal abstract class SourceBasedCompilation(