From 20f6b0cb0cf1b8c4291f4063f4bbe2c9a6d118ca Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Wed, 14 Feb 2024 16:29:23 +0100 Subject: [PATCH] [K/N][Tests] Migrate test ir_providers_mismatch ^KT-61259 --- .../backend.native/tests/build.gradle | 46 ----------------- .../testData/irProvidersMismatch}/empty.kt | 0 .../irProvidersMismatch.kt | 0 .../irProvidersMismatch}/manifest.properties | 0 .../konan/test/blackbox/KlibResolverTest.kt | 50 +++++++++++++++++++ 5 files changed, 50 insertions(+), 46 deletions(-) rename {kotlin-native/backend.native/tests/link/ir_providers/library => native/native.tests/testData/irProvidersMismatch}/empty.kt (100%) rename kotlin-native/backend.native/tests/link/ir_providers/hello.kt => native/native.tests/testData/irProvidersMismatch/irProvidersMismatch.kt (100%) rename {kotlin-native/backend.native/tests/link/ir_providers/library => native/native.tests/testData/irProvidersMismatch}/manifest.properties (100%) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index ae8fe678eab..d0a6a2ea4e1 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1611,52 +1611,6 @@ dynamicTest("interop_kotlin_exception_hook") { outputChecker = { s -> s.contains("OK. Kotlin unhandled exception hook") } } -standaloneTest("library_ir_provider_mismatch") { - enabled = !isAggressiveGC // No need to test with different GC schedulers - - String librarySource = "$projectDir/link/ir_providers/library/empty.kt" - String invalidManifest = "$projectDir/link/ir_providers/library/manifest.properties" - String mainSource = "$projectDir/link/ir_providers/hello.kt" - - File outputDir = project.layout.buildDirectory.dir(name).get().asFile - String currentTarget = project.target.name - - inputs.files(librarySource, invalidManifest) - inputs.property("target", currentTarget) - outputs.dir(outputDir) - source = mainSource - - doBeforeBuild { - konanc("$librarySource -target $currentTarget -p library -o $outputDir/unsupported_ir_provider/empty.klib -manifest $invalidManifest") - konanc("$librarySource -target $currentTarget -p library -o $outputDir/supported_ir_provider/empty.klib ") - - // Should not be successful: - boolean failed = false - String command = "$mainSource -target $currentTarget -p program -o $outputDir/failed.kexe -l $outputDir/unsupported_ir_provider/empty.klib" - try { - konanc(command) - } catch (Throwable t) { - String exceptionText = t.message - exceptionText = PlatformInfo.isWindows() ? exceptionText.replace("\\", "/") : exceptionText - - String expectedText = "warning: KLIB resolver: Skipping '$outputDir/unsupported_ir_provider/empty.klib'. The library requires unknown IR provider: UNSUPPORTED" - expectedText = PlatformInfo.isWindows() ? expectedText.replace("\\", "/") : expectedText - - if (t instanceof GradleException && exceptionText.contains(expectedText)) { - failed = true - } else { - throw t - } - } - - if (!failed) { - throw new GradleException("Kotlin/Natice invocation is successful but should fail:\n$command") - } - } - - flags = ["-l", "$outputDir/supported_ir_provider/empty.klib"] -} - standaloneTest("kt51302") { enabled = project.target.name == project.hostName source = "serialization/KT-51302/main.kt" diff --git a/kotlin-native/backend.native/tests/link/ir_providers/library/empty.kt b/native/native.tests/testData/irProvidersMismatch/empty.kt similarity index 100% rename from kotlin-native/backend.native/tests/link/ir_providers/library/empty.kt rename to native/native.tests/testData/irProvidersMismatch/empty.kt diff --git a/kotlin-native/backend.native/tests/link/ir_providers/hello.kt b/native/native.tests/testData/irProvidersMismatch/irProvidersMismatch.kt similarity index 100% rename from kotlin-native/backend.native/tests/link/ir_providers/hello.kt rename to native/native.tests/testData/irProvidersMismatch/irProvidersMismatch.kt diff --git a/kotlin-native/backend.native/tests/link/ir_providers/library/manifest.properties b/native/native.tests/testData/irProvidersMismatch/manifest.properties similarity index 100% rename from kotlin-native/backend.native/tests/link/ir_providers/library/manifest.properties rename to native/native.tests/testData/irProvidersMismatch/manifest.properties diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KlibResolverTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KlibResolverTest.kt index 410352a41b5..54726c0bb8e 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KlibResolverTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/KlibResolverTest.kt @@ -5,10 +5,15 @@ package org.jetbrains.kotlin.konan.test.blackbox +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.TestKind +import org.jetbrains.kotlin.konan.test.blackbox.support.TestName +import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.CompilationToolException import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.LibraryCompilation import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationArtifact.KLIB import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilationResult.Companion.assertSuccess +import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestExecutable import org.jetbrains.kotlin.library.SearchPathResolver import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Tag @@ -63,6 +68,50 @@ class KlibResolverTest : AbstractNativeSimpleTest() { } } + @Test + fun testIrProvidersMatch() { + testIrProvidersMismatchImpl(irProvidersMismatchSrcDir, TestCompilerArgs.EMPTY) + } + + @Test + fun testIrProvidersMismatch() { + val freeCompilerArgs = TestCompilerArgs(listOf( + "-manifest", + irProvidersMismatchSrcDir.resolve("manifest.properties").absolutePath + )) + try { + testIrProvidersMismatchImpl(irProvidersMismatchSrcDir, freeCompilerArgs) + } catch (cte: CompilationToolException) { + if (!cte.reason.contains("The library requires unknown IR provider: UNSUPPORTED")) + throw cte + } + } + + private fun testIrProvidersMismatchImpl(srcDir: File, freeCompilerArgs: TestCompilerArgs) { + val testCaseKlib = generateTestCaseWithSingleModule(srcDir.resolve("empty.kt"), freeCompilerArgs) + val klibResult = LibraryCompilation( + settings = testRunSettings, + freeCompilerArgs = testCaseKlib.freeCompilerArgs, + sourceModules = testCaseKlib.modules, + dependencies = listOf(), + expectedArtifact = getLibraryArtifact(testCaseKlib, buildDir) + ).result.assertSuccess() + + val testCase = generateTestCaseWithSingleFile( + sourceFile = srcDir.resolve("irProvidersMismatch.kt"), + testKind = TestKind.STANDALONE_NO_TR, + extras = TestCase.NoTestRunnerExtras("main"), + ) + val executableResult = + compileToExecutable(testCase, klibResult.resultingArtifact.asLibraryDependency()).assertSuccess() + val testExecutable = TestExecutable( + executableResult.resultingArtifact, + executableResult.loggedData, + listOf(TestName("testIrProvidersMismatch")) + ) + runExecutableAndVerify(testCase, testExecutable) + } + private fun createModules(vararg modules: Module): List { val mapping: Map = modules.groupBy(Module::name).mapValues { it.value.singleOrNull() ?: error("Duplicated modules: ${it.value}") @@ -152,5 +201,6 @@ class KlibResolverTest : AbstractNativeSimpleTest() { companion object { private const val USER_DIR = "user.dir" + private val irProvidersMismatchSrcDir = File("native/native.tests/testData/irProvidersMismatch") } }