From 7cf3ca29af1dd96bd5c4a40e36b89ab95fa0a424 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Wed, 30 Mar 2022 20:56:18 +0300 Subject: [PATCH] [Native][tests] Fix: Avoid including similar but mutually exclusive shared modules into the same compilation --- .../konan/blackboxtest/support/TestCase.kt | 44 +++++++++++++++---- .../support/runner/TestRunProvider.kt | 4 +- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCase.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCase.kt index 479ce81f3f5..82cc1fd7511 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCase.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCase.kt @@ -105,7 +105,7 @@ internal sealed class TestModule { other.directDependencySymbols == directDependencySymbols && other.directFriendSymbols == directFriendSymbols } - class Shared(override val name: String) : TestModule() { + data class Shared(override val name: String) : TestModule() { override val files: FailOnDuplicatesSet> = FailOnDuplicatesSet() } @@ -210,6 +210,17 @@ internal class TestCase( rootModules as Set } + // All shared modules used in the current test case. + val sharedModules: Set by lazy { + buildSet { + modules.forEach { module -> + module.allDependencies.forEach { dependency -> + if (dependency is TestModule.Shared) this += dependency + } + } + } + } + fun initialize(findSharedModule: ((moduleName: String) -> TestModule.Shared?)?) { // Check that there are no duplicated files among different modules. val duplicatedFiles = modules.flatMap { it.files }.groupingBy { it }.eachCount().filterValues { it > 1 }.keys @@ -253,7 +264,12 @@ internal interface TestCaseGroupId { internal interface TestCaseGroup { fun isEnabled(testCaseId: TestCaseId): Boolean fun getByName(testCaseId: TestCaseId): TestCase? - fun getRegularOnly(freeCompilerArgs: TestCompilerArgs, runnerType: TestRunnerType): Collection + + fun getRegularOnly( + freeCompilerArgs: TestCompilerArgs, + sharedModules: Set, + runnerType: TestRunnerType + ): Collection class Default( private val disabledTestCaseIds: Set, @@ -264,19 +280,29 @@ internal interface TestCaseGroup { override fun isEnabled(testCaseId: TestCaseId) = testCaseId !in disabledTestCaseIds override fun getByName(testCaseId: TestCaseId) = testCasesById[testCaseId] - override fun getRegularOnly(freeCompilerArgs: TestCompilerArgs, runnerType: TestRunnerType) = - testCasesById.values.filter { testCase -> - testCase.kind == TestKind.REGULAR - && testCase.extras().runnerType == runnerType - && testCase.freeCompilerArgs == freeCompilerArgs - } + override fun getRegularOnly( + freeCompilerArgs: TestCompilerArgs, + sharedModules: Set, + runnerType: TestRunnerType + ) = testCasesById.values.filter { testCase -> + testCase.kind == TestKind.REGULAR + && testCase.freeCompilerArgs == freeCompilerArgs + && testCase.sharedModules == sharedModules + && testCase.extras().runnerType == runnerType + } } companion object { val ALL_DISABLED = object : TestCaseGroup { override fun isEnabled(testCaseId: TestCaseId) = false override fun getByName(testCaseId: TestCaseId) = unsupported() - override fun getRegularOnly(freeCompilerArgs: TestCompilerArgs, runnerType: TestRunnerType) = unsupported() + + override fun getRegularOnly( + freeCompilerArgs: TestCompilerArgs, + sharedModules: Set, + runnerType: TestRunnerType + ) = unsupported() + private fun unsupported(): Nothing = fail { "This function should not be called" } } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRunProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRunProvider.kt index d9fde23f893..53400c55935 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRunProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/TestRunProvider.kt @@ -145,10 +145,11 @@ internal class TestRunProvider( TestCompilationCacheKey.Grouped( testCaseGroupId = testCaseId.testCaseGroupId, freeCompilerArgs = testCase.freeCompilerArgs, + sharedModules = testCase.sharedModules, runnerType = testRunnerType ) ) { - val testCases = testCaseGroup.getRegularOnly(testCase.freeCompilerArgs, testRunnerType) + val testCases = testCaseGroup.getRegularOnly(testCase.freeCompilerArgs, testCase.sharedModules, testRunnerType) assertTrue(testCases.isNotEmpty()) compilationFactory.testCasesToExecutable(testCases, settings) } @@ -180,6 +181,7 @@ internal class TestRunProvider( data class Grouped( val testCaseGroupId: TestCaseGroupId, val freeCompilerArgs: TestCompilerArgs, + val sharedModules: Set, val runnerType: TestRunnerType ) : TestCompilationCacheKey() }