From 17c5f5d5a2a44a5fe8edfd01d12ce4159a7d6244 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Fri, 31 Mar 2023 16:42:05 +0200 Subject: [PATCH] [Native][tests] Support FIR for KLIB evolution tests --- .../FirNativeKlibEvolutionTestGenerated.java | 262 ++++++++++++++++++ .../generators/tests/GenerateNativeTests.kt | 6 + .../AbstractNativeKlibEvolutionTest.kt | 95 ++++--- 3 files changed, 329 insertions(+), 34 deletions(-) create mode 100644 native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeKlibEvolutionTestGenerated.java diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeKlibEvolutionTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeKlibEvolutionTestGenerated.java new file mode 100644 index 00000000000..11e0b8aef90 --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeKlibEvolutionTestGenerated.java @@ -0,0 +1,262 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.blackboxtest; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.konan.blackboxtest.support.group.FirPipeline; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/binaryCompatibility/klibEvolution") +@TestDataPath("$PROJECT_ROOT") +@FirPipeline() +public class FirNativeKlibEvolutionTestGenerated extends AbstractNativeKlibEvolutionTest { + @Test + @TestMetadata("addAbstractMemberBody.kt") + public void testAddAbstractMemberBody() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addAbstractMemberBody.kt"); + } + + @Test + @TestMetadata("addCompanionObject.kt") + public void testAddCompanionObject() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addCompanionObject.kt"); + } + + @Test + @TestMetadata("addDefaultImplementations.kt") + public void testAddDefaultImplementations() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addDefaultImplementations.kt"); + } + + @Test + @TestMetadata("addEnumClassMember.kt") + public void testAddEnumClassMember() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addEnumClassMember.kt"); + } + + @Test + @TestMetadata("addLateinitToVar.kt") + public void testAddLateinitToVar() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addLateinitToVar.kt"); + } + + @Test + @TestMetadata("addOpenToClass.kt") + public void testAddOpenToClass() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addOpenToClass.kt"); + } + + @Test + @TestMetadata("addOpenToMember.kt") + public void testAddOpenToMember() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addOpenToMember.kt"); + } + + @Test + @TestMetadata("addOrRemoveConst.kt") + public void testAddOrRemoveConst() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addOrRemoveConst.kt"); + } + + @Test + @TestMetadata("addOrRemoveInitBlock.kt") + public void testAddOrRemoveInitBlock() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addOrRemoveInitBlock.kt"); + } + + @Test + @TestMetadata("addOverloads.kt") + public void testAddOverloads() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addOverloads.kt"); + } + + @Test + @TestMetadata("addParameterDefaulValue.kt") + public void testAddParameterDefaulValue() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addParameterDefaulValue.kt"); + } + + @Test + @TestMetadata("addPropertyAccessor.kt") + public void testAddPropertyAccessor() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addPropertyAccessor.kt"); + } + + @Test + @TestMetadata("addingSealedClassMember.kt") + public void testAddingSealedClassMember() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/addingSealedClassMember.kt"); + } + + @Test + public void testAllFilesPresentInKlibEvolution() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/binaryCompatibility/klibEvolution"), Pattern.compile("^(.+)\\.kt$"), null, false); + } + + @Test + @TestMetadata("changeBaseClassOrder.kt") + public void testChangeBaseClassOrder() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changeBaseClassOrder.kt"); + } + + @Test + @TestMetadata("changeCompanionToNestedObject.kt") + public void testChangeCompanionToNestedObject() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changeCompanionToNestedObject.kt"); + } + + @Test + @TestMetadata("changeConstInitialization.kt") + public void testChangeConstInitialization() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changeConstInitialization.kt"); + } + + @Test + @TestMetadata("changeNamesOfTypeParameters.kt") + public void testChangeNamesOfTypeParameters() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changeNamesOfTypeParameters.kt"); + } + + @Test + @TestMetadata("changeObjectToCompanion.kt") + public void testChangeObjectToCompanion() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changeObjectToCompanion.kt"); + } + + @Test + @TestMetadata("changeParameterDefaultValue.kt") + public void testChangeParameterDefaultValue() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changeParameterDefaultValue.kt"); + } + + @Test + @TestMetadata("changePropertyFromValToVar.kt") + public void testChangePropertyFromValToVar() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changePropertyFromValToVar.kt"); + } + + @Test + @TestMetadata("changePropertyInitialization.kt") + public void testChangePropertyInitialization() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/changePropertyInitialization.kt"); + } + + @Test + @TestMetadata("constructorParameterMarkValVar.kt") + public void testConstructorParameterMarkValVar() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/constructorParameterMarkValVar.kt"); + } + + @Test + @TestMetadata("deleteOverrideMember.kt") + public void testDeleteOverrideMember() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/deleteOverrideMember.kt"); + } + + @Test + @TestMetadata("deletePrivateMembers.kt") + public void testDeletePrivateMembers() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/deletePrivateMembers.kt"); + } + + @Test + @TestMetadata("inlineBodyChange.kt") + public void testInlineBodyChange() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/inlineBodyChange.kt"); + } + + @Test + @TestMetadata("inlineFunction.kt") + public void testInlineFunction() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/inlineFunction.kt"); + } + + @Test + @TestMetadata("makeFunctionInfixOrTailrec.kt") + public void testMakeFunctionInfixOrTailrec() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/makeFunctionInfixOrTailrec.kt"); + } + + @Test + @TestMetadata("moreSpecificBaseClass.kt") + public void testMoreSpecificBaseClass() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/moreSpecificBaseClass.kt"); + } + + @Test + @TestMetadata("moveMemberUpInHierarchy.kt") + public void testMoveMemberUpInHierarchy() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/moveMemberUpInHierarchy.kt"); + } + + @Test + @TestMetadata("newFakeOverride.kt") + public void testNewFakeOverride() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/newFakeOverride.kt"); + } + + @Test + @TestMetadata("newOverrideMember.kt") + public void testNewOverrideMember() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/newOverrideMember.kt"); + } + + @Test + @TestMetadata("removeAbstractFromClass.kt") + public void testRemoveAbstractFromClass() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/removeAbstractFromClass.kt"); + } + + @Test + @TestMetadata("removeInfixOrTailrecFromFunction.kt") + public void testRemoveInfixOrTailrecFromFunction() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/removeInfixOrTailrecFromFunction.kt"); + } + + @Test + @TestMetadata("removeLateinitFromVar.kt") + public void testRemoveLateinitFromVar() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/removeLateinitFromVar.kt"); + } + + @Test + @TestMetadata("removePropertyAccessor.kt") + public void testRemovePropertyAccessor() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/removePropertyAccessor.kt"); + } + + @Test + @TestMetadata("renameArguments.kt") + public void testRenameArguments() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/renameArguments.kt"); + } + + @Test + @TestMetadata("reorderClassConstructors.kt") + public void testReorderClassConstructors() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/reorderClassConstructors.kt"); + } + + @Test + @TestMetadata("turnClassIntoDataClass.kt") + public void testTurnClassIntoDataClass() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/turnClassIntoDataClass.kt"); + } + + @Test + @TestMetadata("widenSuperMemberVisibility.kt") + public void testWidenSuperMemberVisibility() throws Exception { + runTest("compiler/testData/binaryCompatibility/klibEvolution/widenSuperMemberVisibility.kt"); + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt index 17440b431bb..7e96b577bdc 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt @@ -75,6 +75,12 @@ fun main() { ) { model("binaryCompatibility/klibEvolution", recursive = false) } + testClass( + suiteTestClassName = "FirNativeKlibEvolutionTestGenerated", + annotations = listOf(provider()) + ) { + model("binaryCompatibility/klibEvolution", recursive = false) + } } // CInterop tests. diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt index 0e0adc72fb7..5d8230e4932 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibEvolutionTest.kt @@ -21,7 +21,9 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTarg import org.jetbrains.kotlin.konan.blackboxtest.support.settings.SimpleTestDirectories import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts import org.jetbrains.kotlin.konan.blackboxtest.support.util.* +import org.jetbrains.kotlin.test.Directives import org.jetbrains.kotlin.utils.DFS +import org.junit.jupiter.api.Assumptions import org.junit.jupiter.api.Tag import java.io.File import kotlin.math.max @@ -31,12 +33,24 @@ import org.jetbrains.kotlin.compatibility.binary.TestModule as TModule @Tag("klib-evolution") abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() { - protected fun runTest(@TestDataFile testPath: String): Unit = AbstractKlibBinaryCompatibilityTest.doTest( - filePath = testPath, - expectedResult = "OK", - produceKlib = ::buildKlib, - produceAndRunProgram = ::buildAndExecuteBinary - ) + // TODO: unmute after fixing KT-57711 + private fun isIgnoredTest(filePath: String): Boolean { + if (!this::class.java.simpleName.startsWith("Fir")) + return false + + val fileName = filePath.substringAfterLast('/') + return fileName == "addOrRemoveConst.kt" || fileName == "changeConstInitialization.kt" + } + + protected fun runTest(@TestDataFile testPath: String) { + Assumptions.assumeFalse(isIgnoredTest(testPath)) + AbstractKlibBinaryCompatibilityTest.doTest( + filePath = testPath, + expectedResult = "OK", + produceKlib = ::buildKlib, + produceAndRunProgram = ::buildAndExecuteBinary + ) + } private fun buildKlib( testModule: TModule, @@ -49,7 +63,7 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() { ) val klibFile = module.klibFile - val testCase = mkTestCase(module, COMPILER_ARGS_FOR_KLIB) + val testCase = makeTestCase(module.name, module.module, COMPILER_ARGS_FOR_KLIB) val compilation = LibraryCompilation( settings = testRunSettings, @@ -68,46 +82,58 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() { mainTestModule: TModule, expectedResult: String ) { - val binaryVersion = moduleVersions.values.maxOrNull() ?: 2 - - buildKlib(mainTestModule, binaryVersion) + val latestVersion = moduleVersions.values.maxOrNull() ?: 2 val (binarySourceDir, binaryOutputDir) = listOf(BINARY_SOURCE_DIR_NAME, BINARY_OUTPUT_DIR_NAME).map { buildDir.resolve(LAUNCHER_MODULE_NAME).resolve(it).apply { mkdirs() } } - val launcherModule = LightDependencyWithVersion(LAUNCHER_MODULE_NAME, binaryVersion).apply { - module.files += TestFile.createUncommitted( - location = binarySourceDir.resolve(LAUNCHER_FILE_NAME), - module = module, - text = generateBoxFunctionLauncher("box", expectedResult) - ) - } - val launcherDependencies = collectDependencies(mainTestModule.name, binaryVersion) + val launcherText = generateBoxFunctionLauncher("box", expectedResult) + val launcherFile = binarySourceDir.resolve(LAUNCHER_FILE_NAME) + TFile(mainTestModule, launcherFile.name, launcherText, Directives()) + + buildKlib(mainTestModule, latestVersion) + val executableFile = binaryOutputDir.resolve( "app." + testRunSettings.get().testTarget.family.exeSuffix ) + val executableArtifact = TestCompilationArtifact.Executable(executableFile) - val cachedDependencies = if (staticCacheRequiredForEveryLibrary) { + val cachedDependencies: List> = if (staticCacheRequiredForEveryLibrary) { latestDependencies.map { (module, deps) -> - buildCacheForKlib(module, deps) + val testModule = module.module + + val staticCacheCompilationOptions = if (testModule.name == mainTestModule.name) + StaticCacheCompilation.Options.ForIncludedLibraryWithTests(executableArtifact, DEFAULT_EXTRAS) + else + StaticCacheCompilation.Options.Regular + + buildCacheForKlib(module, staticCacheCompilationOptions, deps) module.klibFile.toStaticCacheArtifact().toDependency() } } else { emptyList() } - val testCase = mkTestCase(launcherModule, COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE) + val mainModuleDependencies: List> = collectDependencies(mainTestModule.name, latestVersion).map { module -> + val klibArtifact = module.klibFile.toKlib() + + val testModule = module.module + if (testModule.name == mainTestModule.name) + klibArtifact.toIncludedDependency() + else + klibArtifact.toDependency() + } + + val testCase = makeTestCase(LAUNCHER_MODULE_NAME, module = null, COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE) val compilation = ExecutableCompilation( settings = testRunSettings, freeCompilerArgs = testCase.freeCompilerArgs, sourceModules = testCase.modules, extras = testCase.extras, - dependencies = launcherDependencies.map { - it.klibFile.toKlib().toDependency() - } + cachedDependencies, - expectedArtifact = TestCompilationArtifact.Executable(executableFile) + dependencies = mainModuleDependencies + cachedDependencies, + expectedArtifact = executableArtifact ) val compilationResult = compilation.trigger() @@ -118,6 +144,7 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() { private fun buildCacheForKlib( module: LightDependencyWithVersion, + staticCacheCompilationOptions: StaticCacheCompilation.Options, moduleDependencies: Collection ) { val klib = module.klibFile @@ -125,7 +152,7 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() { val compilation = StaticCacheCompilation( settings = testRunSettings, freeCompilerArgs = COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE, - options = StaticCacheCompilation.Options.Regular, + options = staticCacheCompilationOptions, pipelineType = testRunSettings.get(), dependencies = moduleDependencies.map { it.klibFile.toStaticCacheArtifact().toDependency() @@ -240,13 +267,14 @@ abstract class AbstractNativeKlibEvolutionTest : AbstractNativeSimpleTest() { return extra } - private fun mkTestCase( - extra: LightDependencyWithVersion, + private fun makeTestCase( + id: String, + module: TestModule.Exclusive?, compilerArgs: TestCompilerArgs ): TestCase = TestCase( - id = TestCaseId.Named(extra.name), + id = TestCaseId.Named(id), kind = TestKind.STANDALONE, - modules = setOf(extra.module), + modules = setOfNotNull(module), freeCompilerArgs = compilerArgs, nominalPackageName = PackageName.EMPTY, checks = TestRunChecks.Default(testRunSettings.get().executionTimeout), @@ -282,10 +310,9 @@ private fun File.toStaticCacheArtifact() = KLIBStaticCache( klib = KLIB(this) ) -private fun KLIB.toDependency() = - ExistingDependency(this, TestCompilationDependencyType.Library) -private fun KLIBStaticCache.toDependency() = - ExistingDependency(this, TestCompilationDependencyType.LibraryStaticCache) +private fun KLIB.toDependency() = ExistingDependency(this, TestCompilationDependencyType.Library) +private fun KLIB.toIncludedDependency() = ExistingDependency(this, TestCompilationDependencyType.IncludedLibrary) +private fun KLIBStaticCache.toDependency() = ExistingDependency(this, TestCompilationDependencyType.LibraryStaticCache) private fun BasicCompilation.trigger(): TestCompilationResult.Success = result.assertSuccess()