[Native][tests] Add "force standalone tests" mode

This commit is contained in:
Dmitriy Dolovov
2022-05-04 12:22:54 +03:00
committed by Space
parent ebcbb9a6a6
commit e15000a6c2
6 changed files with 33 additions and 7 deletions
+2
View File
@@ -49,6 +49,7 @@ enum class TestProperty(shortName: String) {
COMPILER_CLASSPATH("compilerClasspath"),
TEST_TARGET("target"),
TEST_MODE("mode"),
FORCE_STANDALONE("forceStandalone"),
OPTIMIZATION_MODE("optimizationMode"),
MEMORY_MODEL("memoryModel"),
USE_THREAD_STATE_CHECKER("useThreadStateChecker"),
@@ -115,6 +116,7 @@ fun nativeTest(taskName: String, vararg tags: String) = projectTest(taskName, jU
// Pass Gradle properties as JVM properties so test process can read them.
TestProperty.TEST_TARGET.setUpFromGradleProperty(this)
TestProperty.TEST_MODE.setUpFromGradleProperty(this)
TestProperty.FORCE_STANDALONE.setUpFromGradleProperty(this)
TestProperty.OPTIMIZATION_MODE.setUpFromGradleProperty(this)
TestProperty.MEMORY_MODEL.setUpFromGradleProperty(this)
TestProperty.USE_THREAD_STATE_CHECKER.setUpFromGradleProperty(this)
@@ -43,6 +43,7 @@ internal class EnforcedProperties(testClass: Class<*>) {
internal enum class ClassLevelProperty(shortName: String) {
TEST_TARGET("target"),
TEST_MODE("mode"),
FORCE_STANDALONE("forceStandalone"),
OPTIMIZATION_MODE("optimizationMode"),
MEMORY_MODEL("memoryModel"),
USE_THREAD_STATE_CHECKER("useThreadStateChecker"),
@@ -158,6 +158,7 @@ private object NativeTestSupport {
output += nativeTargets
output += CacheMode::class to cacheMode
output += computeTestMode(enforcedProperties)
output += computeForcedStandaloneTestKind(enforcedProperties)
output += computeTimeouts(enforcedProperties)
return nativeTargets
@@ -220,6 +221,15 @@ private object NativeTestSupport {
private fun computeTestMode(enforcedProperties: EnforcedProperties): TestMode =
ClassLevelProperty.TEST_MODE.readValue(enforcedProperties, TestMode.values(), default = TestMode.TWO_STAGE_MULTI_MODULE)
private fun computeForcedStandaloneTestKind(enforcedProperties: EnforcedProperties): ForcedStandaloneTestKind =
ForcedStandaloneTestKind(
ClassLevelProperty.FORCE_STANDALONE.readValue(
enforcedProperties,
String::toBooleanStrictOrNull,
default = false
)
)
private fun computeTimeouts(enforcedProperties: EnforcedProperties): Timeouts {
val executionTimeout = ClassLevelProperty.EXECUTION_TIMEOUT.readValue(
enforcedProperties,
@@ -73,7 +73,7 @@ internal class ExtTestCaseGroupProvider : TestCaseGroupProvider, TestDisposable(
if (extTestDataFile.isRelevant)
testCases += extTestDataFile.createTestCase(
definitelyStandaloneTest = testDataFile in standalones,
definitelyStandaloneTest = settings.get<ForcedStandaloneTestKind>().value || testDataFile in standalones,
sharedModules = sharedModules
)
else
@@ -168,7 +168,8 @@ private class ExtTestDataFile(
return doCreateTestCase(isStandaloneTest, sharedModules)
}
/** Determine if the current test should be compiled as a standalone test, i.e.
/**
* Determine if the current test should be compiled as a standalone test, i.e.
* - package names are not patched
* - test is compiled independently of any other tests
*/
@@ -10,10 +10,7 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.TestCase.NoTestRunnerExtr
import org.jetbrains.kotlin.konan.blackboxtest.support.TestCase.WithTestRunnerExtras
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestRunCheck.*
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.TestRunChecks
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.GeneratedSources
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Settings
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.TestRoots
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
import org.jetbrains.kotlin.test.directives.model.Directive
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
@@ -182,9 +179,15 @@ internal class StandardTestCaseGroupProvider : TestCaseGroupProvider {
val registeredDirectives = directivesParser.build()
val freeCompilerArgs = parseFreeCompilerArgs(registeredDirectives, location)
val testKind = parseTestKind(registeredDirectives, location)
val expectedTimeoutFailure = parseExpectedTimeoutFailure(registeredDirectives)
val testKind = parseTestKind(registeredDirectives, location).let { testKind ->
if (testKind == TestKind.REGULAR && settings.get<ForcedStandaloneTestKind>().value)
TestKind.STANDALONE
else
testKind
}
if (testKind == TestKind.REGULAR) {
// Fix package declarations to avoid unintended conflicts between symbols with the same name in different test cases.
fixPackageNames(testModules.values, nominalPackageName, testDataFile)
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.konan.blackboxtest.support.settings
import org.jetbrains.kotlin.konan.blackboxtest.support.TestKind
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
import java.io.File
@@ -54,6 +55,14 @@ internal enum class TestMode(private val description: String) {
override fun toString() = description
}
/**
* Whether to force [TestKind.STANDALONE] for all tests where [TestKind] is assumed to be [TestKind.REGULAR] otherwise:
* - either explicitly specified in the test data file: // KIND: REGULAR
* - or // KIND: is not specified in the test data file and thus automatically considered as [TestKind.REGULAR]
*/
@JvmInline
internal value class ForcedStandaloneTestKind(val value: Boolean)
/**
* Optimization mode to be applied.
*/