[Native][tests] Gradle property: kotlin.internal.native.test.target
This commit is contained in:
@@ -47,6 +47,7 @@ enum class TestProperty(shortName: String) {
|
|||||||
// effect on other Gradle tasks (ex: :kotlin-native:dist) that might be executed along with test task.
|
// effect on other Gradle tasks (ex: :kotlin-native:dist) that might be executed along with test task.
|
||||||
KOTLIN_NATIVE_HOME("nativeHome"),
|
KOTLIN_NATIVE_HOME("nativeHome"),
|
||||||
COMPILER_CLASSPATH("compilerClasspath"),
|
COMPILER_CLASSPATH("compilerClasspath"),
|
||||||
|
TEST_TARGET("target"),
|
||||||
TEST_MODE("mode"),
|
TEST_MODE("mode"),
|
||||||
OPTIMIZATION_MODE("optimizationMode"),
|
OPTIMIZATION_MODE("optimizationMode"),
|
||||||
MEMORY_MODEL("memoryModel"),
|
MEMORY_MODEL("memoryModel"),
|
||||||
@@ -57,10 +58,12 @@ enum class TestProperty(shortName: String) {
|
|||||||
|
|
||||||
private val propertyName = "kotlin.internal.native.test.$shortName"
|
private val propertyName = "kotlin.internal.native.test.$shortName"
|
||||||
|
|
||||||
fun setUpFromGradleProperty(task: Test, defaultValue: () -> Any? = { null }) {
|
fun setUpFromGradleProperty(task: Test, defaultValue: () -> String? = { null }) {
|
||||||
val propertyValue = task.project.findProperty(propertyName) ?: defaultValue()
|
val propertyValue = readGradleProperty(task) ?: defaultValue()
|
||||||
if (propertyValue != null) task.systemProperty(propertyName, propertyValue)
|
if (propertyValue != null) task.systemProperty(propertyName, propertyValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun readGradleProperty(task: Test): String? = task.project.findProperty(propertyName)?.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun blackBoxTest(taskName: String, vararg tags: String) = projectTest(taskName, jUnitMode = JUnitMode.JUnit5) {
|
fun blackBoxTest(taskName: String, vararg tags: String) = projectTest(taskName, jUnitMode = JUnitMode.JUnit5) {
|
||||||
@@ -92,7 +95,8 @@ fun blackBoxTest(taskName: String, vararg tags: String) = projectTest(taskName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestProperty.KOTLIN_NATIVE_HOME.setUpFromGradleProperty(this) {
|
TestProperty.KOTLIN_NATIVE_HOME.setUpFromGradleProperty(this) {
|
||||||
dependsOn(":kotlin-native:dist")
|
val testTarget = TestProperty.TEST_TARGET.readGradleProperty(this)
|
||||||
|
dependsOn(if (testTarget != null) ":kotlin-native:${testTarget}CrossDist" else ":kotlin-native:dist")
|
||||||
project(":kotlin-native").projectDir.resolve("dist").absolutePath
|
project(":kotlin-native").projectDir.resolve("dist").absolutePath
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +107,7 @@ fun blackBoxTest(taskName: String, vararg tags: String) = projectTest(taskName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pass Gradle properties as JVM properties so test process can read them.
|
// Pass Gradle properties as JVM properties so test process can read them.
|
||||||
|
TestProperty.TEST_TARGET.setUpFromGradleProperty(this)
|
||||||
TestProperty.TEST_MODE.setUpFromGradleProperty(this)
|
TestProperty.TEST_MODE.setUpFromGradleProperty(this)
|
||||||
TestProperty.OPTIMIZATION_MODE.setUpFromGradleProperty(this)
|
TestProperty.OPTIMIZATION_MODE.setUpFromGradleProperty(this)
|
||||||
TestProperty.MEMORY_MODEL.setUpFromGradleProperty(this)
|
TestProperty.MEMORY_MODEL.setUpFromGradleProperty(this)
|
||||||
|
|||||||
+30
-23
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.konan.blackboxtest.support
|
|||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.group.TestCaseGroupProvider
|
import org.jetbrains.kotlin.konan.blackboxtest.support.group.TestCaseGroupProvider
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
|
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
||||||
|
import org.jetbrains.kotlin.konan.target.Distribution
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
import org.jetbrains.kotlin.test.TestMetadata
|
import org.jetbrains.kotlin.test.TestMetadata
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
||||||
@@ -50,31 +51,34 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
|||||||
|
|
||||||
/*************** Test process settings ***************/
|
/*************** Test process settings ***************/
|
||||||
|
|
||||||
private fun ExtensionContext.getOrCreateTestProcessSettings(): TestProcessSettings {
|
private fun ExtensionContext.getOrCreateTestProcessSettings(): TestProcessSettings =
|
||||||
val optimizationMode = computeOptimizationMode()
|
root.getStore(NAMESPACE).getOrComputeIfAbsent(TestProcessSettings::class.java.name) {
|
||||||
val memoryModel = computeMemoryModel()
|
val optimizationMode = computeOptimizationMode()
|
||||||
|
val memoryModel = computeMemoryModel()
|
||||||
|
|
||||||
val threadStateChecker = computeThreadStateChecker()
|
val threadStateChecker = computeThreadStateChecker()
|
||||||
if (threadStateChecker == ThreadStateChecker.ENABLED) {
|
if (threadStateChecker == ThreadStateChecker.ENABLED) {
|
||||||
assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) {
|
assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) {
|
||||||
"Thread state checker can be enabled only with experimental memory model"
|
"Thread state checker can be enabled only with experimental memory model"
|
||||||
|
}
|
||||||
|
assertEquals(OptimizationMode.DEBUG, optimizationMode) {
|
||||||
|
"Thread state checker can be enabled only with debug optimization mode"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assertEquals(OptimizationMode.DEBUG, optimizationMode) {
|
|
||||||
"Thread state checker can be enabled only with debug optimization mode"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val gcType = computeGCType()
|
val gcType = computeGCType()
|
||||||
if (gcType != GCType.UNSPECIFIED) {
|
if (gcType != GCType.UNSPECIFIED) {
|
||||||
assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) {
|
assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) {
|
||||||
"GC type can be specified only with experimental memory model"
|
"GC type can be specified only with experimental memory model"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return root.getStore(NAMESPACE).getOrComputeIfAbsent(TestProcessSettings::class.java.name) {
|
val nativeHome = computeNativeHome()
|
||||||
|
val hostManager = HostManager(distribution = Distribution(nativeHome.path), experimental = false)
|
||||||
|
|
||||||
TestProcessSettings(
|
TestProcessSettings(
|
||||||
computeNativeTargets(),
|
computeNativeTargets(hostManager),
|
||||||
computeNativeHome(),
|
nativeHome,
|
||||||
computeNativeClassLoader(),
|
computeNativeClassLoader(),
|
||||||
computeTestMode(),
|
computeTestMode(),
|
||||||
optimizationMode,
|
optimizationMode,
|
||||||
@@ -86,11 +90,13 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
|||||||
computeTimeouts()
|
computeTimeouts()
|
||||||
)
|
)
|
||||||
}.cast()
|
}.cast()
|
||||||
}
|
|
||||||
|
|
||||||
private fun computeNativeTargets(): KotlinNativeTargets {
|
private fun computeNativeTargets(hostManager: HostManager): KotlinNativeTargets {
|
||||||
val hostTarget = HostManager.host
|
val hostTarget = HostManager.host
|
||||||
return KotlinNativeTargets(testTarget = hostTarget, hostTarget = hostTarget)
|
return KotlinNativeTargets(
|
||||||
|
testTarget = systemProperty(TEST_TARGET, hostManager::targetByName, default = hostTarget),
|
||||||
|
hostTarget = hostTarget
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeNativeHome(): KotlinNativeHome = KotlinNativeHome(File(requiredSystemProperty(KOTLIN_NATIVE_HOME)))
|
private fun computeNativeHome(): KotlinNativeHome = KotlinNativeHome(File(requiredSystemProperty(KOTLIN_NATIVE_HOME)))
|
||||||
@@ -165,6 +171,7 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
|||||||
|
|
||||||
private const val KOTLIN_NATIVE_HOME = "kotlin.internal.native.test.nativeHome"
|
private const val KOTLIN_NATIVE_HOME = "kotlin.internal.native.test.nativeHome"
|
||||||
private const val COMPILER_CLASSPATH = "kotlin.internal.native.test.compilerClasspath"
|
private const val COMPILER_CLASSPATH = "kotlin.internal.native.test.compilerClasspath"
|
||||||
|
private const val TEST_TARGET = "kotlin.internal.native.test.target"
|
||||||
private const val TEST_MODE = "kotlin.internal.native.test.mode"
|
private const val TEST_MODE = "kotlin.internal.native.test.mode"
|
||||||
private const val OPTIMIZATION_MODE = "kotlin.internal.native.test.optimizationMode"
|
private const val OPTIMIZATION_MODE = "kotlin.internal.native.test.optimizationMode"
|
||||||
private const val MEMORY_MODEL = "kotlin.internal.native.test.memoryModel"
|
private const val MEMORY_MODEL = "kotlin.internal.native.test.memoryModel"
|
||||||
@@ -183,7 +190,7 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
|||||||
val testProcessSettings = getOrCreateTestProcessSettings()
|
val testProcessSettings = getOrCreateTestProcessSettings()
|
||||||
val computedTestConfiguration = computeTestConfiguration(enclosingTestClass)
|
val computedTestConfiguration = computeTestConfiguration(enclosingTestClass)
|
||||||
|
|
||||||
/// Put settings that are always required:
|
// Put settings that are always required:
|
||||||
val settings = mutableListOf(
|
val settings = mutableListOf(
|
||||||
computedTestConfiguration,
|
computedTestConfiguration,
|
||||||
computeBinariesDirs(testProcessSettings.get(), testProcessSettings.get(), enclosingTestClass)
|
computeBinariesDirs(testProcessSettings.get(), testProcessSettings.get(), enclosingTestClass)
|
||||||
|
|||||||
Reference in New Issue
Block a user