From ef5346e62e33fb30069aa672d2641fbd012c6210 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Wed, 13 Sep 2023 12:16:31 +0200 Subject: [PATCH] [K/N] Use enforced property PIPELINE_TYPE in CompilerOutputTest to avoid duplicated "-language-version" setting. --- .../kotlin/konan/blackboxtest/CompilerOutputTest.kt | 5 ++--- .../blackboxtest/support/ConfigurationProperties.kt | 13 +++++++------ .../konan/blackboxtest/support/NativeTestSupport.kt | 12 +++++++++--- .../konan/blackboxtest/support/TestDirectives.kt | 1 + .../support/compilation/TestCompilation.kt | 9 ++++----- .../support/group/ExtTestCaseGroupProvider.kt | 7 +++++++ .../support/settings/TestProcessSettings.kt | 4 ++++ 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt index 1da953c85ed..f2442861e6d 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CompilerOutputTest.kt @@ -21,11 +21,11 @@ import java.io.File @TestDataPath("\$PROJECT_ROOT") @EnforcedProperty(ClassLevelProperty.COMPILER_OUTPUT_INTERCEPTOR, "NONE") +@EnforcedProperty(ClassLevelProperty.PIPELINE_TYPE, "DEFAULT") class CompilerOutputTest : AbstractNativeSimpleTest() { - // TODO: unmute after fix of KT-61773 @Test - fun testReleaseCompilerAgainstPreReleaseLibrary() = muteForK2(isK2 = testRunSettings.get() == PipelineType.K2) { + fun testReleaseCompilerAgainstPreReleaseLibrary() = muteForK2(isK2 = true) { // TODO: unmute after fix of KT-61773 // We intentionally use JS testdata, because the compilers should behave the same way in such a test. // To be refactored later, after CompileKotlinAgainstCustomBinariesTest.testReleaseCompilerAgainstPreReleaseLibraryJs is fixed. val rootDir = File("compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs") @@ -74,7 +74,6 @@ class CompilerOutputTest : AbstractNativeSimpleTest() { ): TestCompilationResult { val testCase = generateTestCaseWithSingleModule(source, TestCompilerArgs(freeCompilerArgs)) val compilation = LibraryCompilation( - pipelineType = null, settings = testRunSettings, freeCompilerArgs = testCase.freeCompilerArgs, sourceModules = testCase.modules, diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt index 8bfde34aefe..d105ab73764 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/ConfigurationProperties.kt @@ -22,6 +22,7 @@ internal enum class ProcessLevelProperty(shortName: String) { /*************** Class-level system properties ***************/ +@Repeatable @Target(AnnotationTarget.CLASS) internal annotation class EnforcedProperty(val property: ClassLevelProperty, val propertyValue: String) @@ -33,11 +34,11 @@ internal annotation class AcceptablePropertyValues(val property: ClassLevelPrope internal class EnforcedProperties(testClass: Class<*>) { private val enforcedAnnotations: Map = buildMap { - testClass.annotations.forEach { annotation -> - when (annotation) { - is EnforcedProperty -> this[annotation.property] = annotation.propertyValue - is EnforcedHostTarget -> this[ClassLevelProperty.TEST_TARGET] = HostManager.host.name - } + testClass.getAnnotationsByType(EnforcedProperty::class.java).forEach { + this[it.property] = it.propertyValue + } + if (testClass.isAnnotationPresent(EnforcedHostTarget::class.java)) { + this[ClassLevelProperty.TEST_TARGET] = HostManager.host.name } } @@ -69,7 +70,7 @@ internal enum class ClassLevelProperty(shortName: String) { EXECUTION_TIMEOUT("executionTimeout"), SANITIZER("sanitizer"), COMPILER_OUTPUT_INTERCEPTOR("compilerOutputInterceptor"), - + PIPELINE_TYPE("pipelineType"), ; internal val propertyName = fullPropertyName(shortName) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt index 24c1101c472..65b34beec18 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt @@ -210,7 +210,7 @@ private object NativeTestSupport { output += computeForcedNoopTestRunner(enforcedProperties) output += computeTimeouts(enforcedProperties) // Parse annotations of current class, since there's no way to put annotations to upper-level enclosing class - output += computePipelineType(testClass.get()) + output += computePipelineType(enforcedProperties, testClass.get()) output += computeUsedPartialLinkageConfig(enclosingTestClass) output += computeCompilerOutputInterceptor(enforcedProperties) @@ -468,10 +468,16 @@ private object NativeTestSupport { ) } - private fun computePipelineType(testClass: Class<*>): PipelineType { - return if (testClass.annotations.any { it is FirPipeline }) + private fun computePipelineType(enforcedProperties: EnforcedProperties, testClass: Class<*>): PipelineType { + val pipelineTypeFromFirPipelineAnnotation = if (testClass.annotations.any { it is FirPipeline }) PipelineType.K2 else PipelineType.K1 + + return ClassLevelProperty.PIPELINE_TYPE.readValue( + enforcedProperties, + PipelineType.entries.toTypedArray(), + default = pipelineTypeFromFirPipelineAnnotation + ) } private fun computeUsedPartialLinkageConfig(enclosingTestClass: Class<*>): UsedPartialLinkageConfig { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt index 4d1efc1e7aa..8253794016a 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt @@ -160,6 +160,7 @@ internal enum class TestRunnerType { } internal enum class MutedOption { + DEFAULT, K1, K2 } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt index de7259edcc7..be259142566 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt @@ -139,7 +139,7 @@ internal abstract class SourceBasedCompilation( private val gcType: GCType, private val gcScheduler: GCScheduler, private val allocator: Allocator, - private val pipelineType: PipelineType?, + private val pipelineType: PipelineType, freeCompilerArgs: TestCompilerArgs, compilerPlugins: CompilerPlugins, override val sourceModules: Collection, @@ -162,7 +162,7 @@ internal abstract class SourceBasedCompilation( sanitizer.compilerFlag?.let { compilerFlag -> add(compilerFlag) } gcType.compilerFlag?.let { compilerFlag -> add(compilerFlag) } gcScheduler.compilerFlag?.let { compilerFlag -> add(compilerFlag) } - pipelineType?.compilerFlags?.forEach { compilerFlag -> add(compilerFlag) } + pipelineType.compilerFlags.forEach { compilerFlag -> add(compilerFlag) } applyK2MPPArgs(this) } @@ -191,8 +191,7 @@ internal class LibraryCompilation( freeCompilerArgs: TestCompilerArgs, sourceModules: Collection, dependencies: Iterable>, - expectedArtifact: KLIB, - pipelineType: PipelineType? = settings.get(), + expectedArtifact: KLIB ) : SourceBasedCompilation( targets = settings.get(), home = settings.get(), @@ -204,7 +203,7 @@ internal class LibraryCompilation( gcType = settings.get(), gcScheduler = settings.get(), allocator = settings.get(), - pipelineType = pipelineType, + pipelineType = settings.get(), freeCompilerArgs = freeCompilerArgs, compilerPlugins = settings.get(), sourceModules = sourceModules, diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt index 39fc24b6045..de14a8c40af 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt @@ -167,6 +167,13 @@ private class ExtTestDataFile( IGNORE_BACKEND_DIRECTIVE_PREFIX, IGNORE_BACKEND_K2_DIRECTIVE_PREFIX ) + PipelineType.DEFAULT -> + isIgnoredTarget( + backend, + testDataFile, + /*includeAny = */true, + IGNORE_BACKEND_DIRECTIVE_PREFIX, + ) } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt index aa5a8d40f21..fa5792b1abd 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt @@ -274,6 +274,10 @@ internal sealed class CacheMode { } internal enum class PipelineType(val mutedOption: MutedOption, val compilerFlags: List) { + DEFAULT( + MutedOption.DEFAULT, + emptyList() + ), K1( MutedOption.K1, listOf("-language-version", "1.9")