[Test] Introduce directive for ignoring codegen tests for FIR with LT
^KT-56757
This commit is contained in:
committed by
Space Team
parent
9ee60e4648
commit
f47040696e
+22
-10
@@ -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<ServiceRegistrationData>
|
||||
get() = listOf(service(::SuppressionChecker.bind(customIgnoreDirective)))
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override fun suppressIfNeeded(failedAssertions: List<WrappedException>): List<WrappedException> {
|
||||
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<TargetBackend>?) : TestService {
|
||||
fun extractIgnoreDirective(module: TestModule): ValueDirective<TargetBackend>? {
|
||||
fun extractIgnoreDirectives(module: TestModule): List<ValueDirective<TargetBackend>>? {
|
||||
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<ValueDirective<TargetBackend>>): 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<TargetBackend>): SuppressionResult {
|
||||
val ignoredBackends = module.directives[ignoreDirective]
|
||||
|
||||
|
||||
+37
-18
@@ -32,6 +32,11 @@ object CodegenTestDirectives : SimpleDirectivesContainer() {
|
||||
applicability = Global
|
||||
)
|
||||
|
||||
val IGNORE_BACKEND_K2_LIGHT_TREE by enumDirective<TargetBackend>(
|
||||
description = "Ignore specific backend if test uses K2 frontend in Light tree mode",
|
||||
applicability = Global
|
||||
)
|
||||
|
||||
val IGNORE_BACKEND_MULTI_MODULE by enumDirective<TargetBackend>(
|
||||
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<TargetBackend>? = null
|
||||
): ValueDirective<TargetBackend>? =
|
||||
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<ValueDirective<TargetBackend>> {
|
||||
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<TargetBackend>,
|
||||
customIgnoreDirective: ValueDirective<TargetBackend>?
|
||||
): ValueDirective<TargetBackend>? {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user