From f47040696e2e223d836f88f59bd33396008da5ce Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 17 Feb 2023 12:51:15 +0200 Subject: [PATCH] [Test] Introduce directive for ignoring codegen tests for FIR with LT ^KT-56757 --- .../test/backend/BlackBoxCodegenSuppressor.kt | 32 +++++++---- .../test/directives/CodegenTestDirectives.kt | 55 +++++++++++++------ 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt index f8d3e7a7b26..48676672dc6 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/BlackBoxCodegenSuppressor.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.WrappedException import org.jetbrains.kotlin.test.bind import org.jetbrains.kotlin.test.directives.CodegenTestDirectives -import org.jetbrains.kotlin.test.directives.extractIgnoredDirectiveForTargetBackend +import org.jetbrains.kotlin.test.directives.extractIgnoredDirectivesForTargetBackend import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.directives.model.ValueDirective import org.jetbrains.kotlin.test.model.AfterAnalysisChecker @@ -26,15 +26,19 @@ class BlackBoxCodegenSuppressor( override val additionalServices: List get() = listOf(service(::SuppressionChecker.bind(customIgnoreDirective))) - @OptIn(ExperimentalStdlibApi::class) override fun suppressIfNeeded(failedAssertions: List): List { val suppressionChecker = testServices.codegenSuppressionChecker val moduleStructure = testServices.moduleStructure - val ignoreDirective = suppressionChecker.extractIgnoreDirective(moduleStructure.modules.first()) ?: return failedAssertions - val suppressionResult = moduleStructure.modules.map { suppressionChecker.failuresInModuleAreIgnored(it, ignoreDirective) } - .firstOrNull { it.testMuted } ?: return failedAssertions - val additionalMessage = suppressionResult.matchedBackend?.let { "for $it" } ?: "" - return processAssertions(failedAssertions, ignoreDirective, additionalMessage) + val ignoreDirectives = suppressionChecker.extractIgnoreDirectives(moduleStructure.modules.first()) ?: return failedAssertions + for (ignoreDirective in ignoreDirectives) { + val suppressionResult = moduleStructure.modules + .map { suppressionChecker.failuresInModuleAreIgnored(it, ignoreDirective) } + .firstOrNull { it.testMuted } + ?: continue + val additionalMessage = suppressionResult.matchedBackend?.let { "for $it" } ?: "" + return processAssertions(failedAssertions, ignoreDirective, additionalMessage) + } + return failedAssertions } private fun processAssertions( @@ -58,16 +62,24 @@ class BlackBoxCodegenSuppressor( } class SuppressionChecker(val testServices: TestServices, val customIgnoreDirective: ValueDirective?) : TestService { - fun extractIgnoreDirective(module: TestModule): ValueDirective? { + fun extractIgnoreDirectives(module: TestModule): List>? { val targetBackend = testServices.defaultsProvider.defaultTargetBackend ?: module.targetBackend ?: return null - return extractIgnoredDirectiveForTargetBackend(module, targetBackend, customIgnoreDirective) + return extractIgnoredDirectivesForTargetBackend(module, targetBackend, customIgnoreDirective) } fun failuresInModuleAreIgnored(module: TestModule): Boolean { - val ignoreDirective = extractIgnoreDirective(module) ?: return false + val ignoreDirective = extractIgnoreDirectives(module) ?: return false return failuresInModuleAreIgnored(module, ignoreDirective).testMuted } + private fun failuresInModuleAreIgnored(module: TestModule, ignoreDirectives: List>): SuppressionResult { + for (ignoreDirective in ignoreDirectives) { + val result = failuresInModuleAreIgnored(module, ignoreDirective) + if (result.testMuted) return result + } + return SuppressionResult.NO_MUTE + } + fun failuresInModuleAreIgnored(module: TestModule, ignoreDirective: ValueDirective): SuppressionResult { val ignoredBackends = module.directives[ignoreDirective] diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt index 9375d424486..bb248e85fc9 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt @@ -32,6 +32,11 @@ object CodegenTestDirectives : SimpleDirectivesContainer() { applicability = Global ) + val IGNORE_BACKEND_K2_LIGHT_TREE by enumDirective( + description = "Ignore specific backend if test uses K2 frontend in Light tree mode", + applicability = Global + ) + val IGNORE_BACKEND_MULTI_MODULE by enumDirective( description = "Ignore failures of multimodule test on target backend", applicability = Global @@ -191,27 +196,41 @@ object CodegenTestDirectives : SimpleDirectivesContainer() { ) } -fun extractIgnoredDirectiveForTargetBackend( +fun extractIgnoredDirectivesForTargetBackend( module: TestModule, targetBackend: TargetBackend, customIgnoreDirective: ValueDirective? = null -): ValueDirective? = - when (module.frontendKind) { - FrontendKinds.ClassicFrontend -> CodegenTestDirectives.IGNORE_BACKEND_K1 - FrontendKinds.FIR -> CodegenTestDirectives.IGNORE_BACKEND_K2 - else -> null - }?.let { specificIgnoreDirective -> - when { - customIgnoreDirective != null -> customIgnoreDirective - !module.directives.contains(specificIgnoreDirective) -> CodegenTestDirectives.IGNORE_BACKEND - else -> { - val inCommonIgnored = module.directives[CodegenTestDirectives.IGNORE_BACKEND].let { targetBackend in it || TargetBackend.ANY in it } - val inSpecificIgnored = module.directives[specificIgnoreDirective].let { targetBackend in it || TargetBackend.ANY in it } - if (inCommonIgnored && inSpecificIgnored) { - throw AssertionError("Both, IGNORE_BACKEND and ${specificIgnoreDirective.name} contain target backend ${targetBackend.name}. Please remove one of them.") - } - if (inCommonIgnored) CodegenTestDirectives.IGNORE_BACKEND else specificIgnoreDirective +): List> { + val specificIgnoreDirectives = when (module.frontendKind) { + FrontendKinds.ClassicFrontend -> listOf(CodegenTestDirectives.IGNORE_BACKEND_K1) + FrontendKinds.FIR -> listOfNotNull( + CodegenTestDirectives.IGNORE_BACKEND_K2, + CodegenTestDirectives.IGNORE_BACKEND_K2_LIGHT_TREE.takeIf { module.directives.contains(FirDiagnosticsDirectives.USE_LIGHT_TREE) } + ) + else -> return emptyList() + } + val result = specificIgnoreDirectives.mapNotNull { + extractIgnoredDirectiveForTargetBackendForSpecificIgnoreDirective(module, targetBackend, it, customIgnoreDirective) + } + return result.takeIf { it.isNotEmpty() } ?: listOf(CodegenTestDirectives.IGNORE_BACKEND) +} + +private fun extractIgnoredDirectiveForTargetBackendForSpecificIgnoreDirective( + module: TestModule, + targetBackend: TargetBackend, + specificIgnoreDirective: ValueDirective, + customIgnoreDirective: ValueDirective? +): ValueDirective? { + return when { + customIgnoreDirective != null -> customIgnoreDirective + !module.directives.contains(specificIgnoreDirective) -> null//CodegenTestDirectives.IGNORE_BACKEND + else -> { + val inCommonIgnored = module.directives[CodegenTestDirectives.IGNORE_BACKEND].let { targetBackend in it || TargetBackend.ANY in it } + val inSpecificIgnored = module.directives[specificIgnoreDirective].let { targetBackend in it || TargetBackend.ANY in it } + if (inCommonIgnored && inSpecificIgnored) { + throw AssertionError("Both, IGNORE_BACKEND and ${specificIgnoreDirective.name} contain target backend ${targetBackend.name}. Please remove one of them.") } + if (inCommonIgnored) null else specificIgnoreDirective } } - +}