[Native][tests] Choose the appropriate cache mode for the target under test
This commit is contained in:
+6
-5
@@ -167,10 +167,11 @@ private object NativeTestSupport {
|
|||||||
|
|
||||||
val nativeHome = getOrCreateTestProcessSettings().get<KotlinNativeHome>()
|
val nativeHome = getOrCreateTestProcessSettings().get<KotlinNativeHome>()
|
||||||
|
|
||||||
val hostManager = HostManager(distribution = Distribution(nativeHome.dir.path), experimental = false)
|
val distribution = Distribution(nativeHome.dir.path)
|
||||||
|
val hostManager = HostManager(distribution, experimental = false)
|
||||||
val nativeTargets = computeNativeTargets(enforcedProperties, hostManager)
|
val nativeTargets = computeNativeTargets(enforcedProperties, hostManager)
|
||||||
|
|
||||||
val cacheMode = computeCacheMode(enforcedProperties, nativeHome, nativeTargets, optimizationMode)
|
val cacheMode = computeCacheMode(enforcedProperties, distribution, nativeTargets, optimizationMode)
|
||||||
if (cacheMode != CacheMode.WithoutCache) {
|
if (cacheMode != CacheMode.WithoutCache) {
|
||||||
assertEquals(ThreadStateChecker.DISABLED, threadStateChecker) {
|
assertEquals(ThreadStateChecker.DISABLED, threadStateChecker) {
|
||||||
"Thread state checker can not be used with cache"
|
"Thread state checker can not be used with cache"
|
||||||
@@ -228,14 +229,14 @@ private object NativeTestSupport {
|
|||||||
|
|
||||||
private fun computeCacheMode(
|
private fun computeCacheMode(
|
||||||
enforcedProperties: EnforcedProperties,
|
enforcedProperties: EnforcedProperties,
|
||||||
kotlinNativeHome: KotlinNativeHome,
|
distribution: Distribution,
|
||||||
kotlinNativeTargets: KotlinNativeTargets,
|
kotlinNativeTargets: KotlinNativeTargets,
|
||||||
optimizationMode: OptimizationMode
|
optimizationMode: OptimizationMode
|
||||||
): CacheMode {
|
): CacheMode {
|
||||||
val cacheMode = ClassLevelProperty.CACHE_MODE.readValue(
|
val cacheMode = ClassLevelProperty.CACHE_MODE.readValue(
|
||||||
enforcedProperties,
|
enforcedProperties,
|
||||||
CacheMode.Alias.values(),
|
CacheMode.Alias.values(),
|
||||||
default = CacheMode.Alias.STATIC_ONLY_DIST
|
default = CacheMode.defaultForTestTarget(distribution, kotlinNativeTargets)
|
||||||
)
|
)
|
||||||
val staticCacheRequiredForEveryLibrary = when (cacheMode) {
|
val staticCacheRequiredForEveryLibrary = when (cacheMode) {
|
||||||
CacheMode.Alias.NO -> return CacheMode.WithoutCache
|
CacheMode.Alias.NO -> return CacheMode.WithoutCache
|
||||||
@@ -243,7 +244,7 @@ private object NativeTestSupport {
|
|||||||
CacheMode.Alias.STATIC_EVERYWHERE -> true
|
CacheMode.Alias.STATIC_EVERYWHERE -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
return CacheMode.WithStaticCache(kotlinNativeHome, kotlinNativeTargets, optimizationMode, staticCacheRequiredForEveryLibrary)
|
return CacheMode.WithStaticCache(distribution, kotlinNativeTargets, optimizationMode, staticCacheRequiredForEveryLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeTestMode(enforcedProperties: EnforcedProperties): TestMode =
|
private fun computeTestMode(enforcedProperties: EnforcedProperties): TestMode =
|
||||||
|
|||||||
+14
-3
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.TestKind
|
|||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.LocalTestRunner
|
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.LocalTestRunner
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.NoopTestRunner
|
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.NoopTestRunner
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.Runner
|
import org.jetbrains.kotlin.konan.blackboxtest.support.runner.Runner
|
||||||
|
import org.jetbrains.kotlin.konan.properties.resolvablePropertyList
|
||||||
|
import org.jetbrains.kotlin.konan.target.Distribution
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -157,13 +159,13 @@ internal sealed interface CacheMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WithStaticCache(
|
class WithStaticCache(
|
||||||
kotlinNativeHome: KotlinNativeHome,
|
distribution: Distribution,
|
||||||
kotlinNativeTargets: KotlinNativeTargets,
|
kotlinNativeTargets: KotlinNativeTargets,
|
||||||
optimizationMode: OptimizationMode,
|
optimizationMode: OptimizationMode,
|
||||||
override val staticCacheRequiredForEveryLibrary: Boolean
|
override val staticCacheRequiredForEveryLibrary: Boolean
|
||||||
) : CacheMode {
|
) : CacheMode {
|
||||||
override val staticCacheRootDir: File = kotlinNativeHome.dir
|
override val staticCacheRootDir: File = File(distribution.klib)
|
||||||
.resolve("klib/cache")
|
.resolve("cache")
|
||||||
.resolve(
|
.resolve(
|
||||||
computeCacheDirName(
|
computeCacheDirName(
|
||||||
testTarget = kotlinNativeTargets.testTarget,
|
testTarget = kotlinNativeTargets.testTarget,
|
||||||
@@ -184,6 +186,15 @@ internal sealed interface CacheMode {
|
|||||||
enum class Alias { NO, STATIC_ONLY_DIST, STATIC_EVERYWHERE }
|
enum class Alias { NO, STATIC_ONLY_DIST, STATIC_EVERYWHERE }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
fun defaultForTestTarget(distribution: Distribution, kotlinNativeTargets: KotlinNativeTargets): Alias {
|
||||||
|
val cacheableTargets = distribution.properties
|
||||||
|
.resolvablePropertyList("cacheableTargets", kotlinNativeTargets.hostTarget.name)
|
||||||
|
.map { KonanTarget.predefinedTargets.getValue(it) }
|
||||||
|
.toSet()
|
||||||
|
|
||||||
|
return if (kotlinNativeTargets.testTarget in cacheableTargets) Alias.STATIC_ONLY_DIST else Alias.NO
|
||||||
|
}
|
||||||
|
|
||||||
private fun computeCacheDirName(testTarget: KonanTarget, cacheKind: String, debuggable: Boolean) =
|
private fun computeCacheDirName(testTarget: KonanTarget, cacheKind: String, debuggable: Boolean) =
|
||||||
"$testTarget${if (debuggable) "-g" else ""}$cacheKind"
|
"$testTarget${if (debuggable) "-g" else ""}$cacheKind"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user