[Native][tests] Choose the appropriate cache mode for the target under test

This commit is contained in:
Dmitriy Dolovov
2022-06-14 11:49:43 +04:00
committed by Space
parent c495c07b1a
commit 34129d54e5
2 changed files with 20 additions and 8 deletions
@@ -167,10 +167,11 @@ private object NativeTestSupport {
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 cacheMode = computeCacheMode(enforcedProperties, nativeHome, nativeTargets, optimizationMode)
val cacheMode = computeCacheMode(enforcedProperties, distribution, nativeTargets, optimizationMode)
if (cacheMode != CacheMode.WithoutCache) {
assertEquals(ThreadStateChecker.DISABLED, threadStateChecker) {
"Thread state checker can not be used with cache"
@@ -228,14 +229,14 @@ private object NativeTestSupport {
private fun computeCacheMode(
enforcedProperties: EnforcedProperties,
kotlinNativeHome: KotlinNativeHome,
distribution: Distribution,
kotlinNativeTargets: KotlinNativeTargets,
optimizationMode: OptimizationMode
): CacheMode {
val cacheMode = ClassLevelProperty.CACHE_MODE.readValue(
enforcedProperties,
CacheMode.Alias.values(),
default = CacheMode.Alias.STATIC_ONLY_DIST
default = CacheMode.defaultForTestTarget(distribution, kotlinNativeTargets)
)
val staticCacheRequiredForEveryLibrary = when (cacheMode) {
CacheMode.Alias.NO -> return CacheMode.WithoutCache
@@ -243,7 +244,7 @@ private object NativeTestSupport {
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 =
@@ -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.NoopTestRunner
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.test.services.JUnit5Assertions.assertTrue
import java.io.File
@@ -157,13 +159,13 @@ internal sealed interface CacheMode {
}
class WithStaticCache(
kotlinNativeHome: KotlinNativeHome,
distribution: Distribution,
kotlinNativeTargets: KotlinNativeTargets,
optimizationMode: OptimizationMode,
override val staticCacheRequiredForEveryLibrary: Boolean
) : CacheMode {
override val staticCacheRootDir: File = kotlinNativeHome.dir
.resolve("klib/cache")
override val staticCacheRootDir: File = File(distribution.klib)
.resolve("cache")
.resolve(
computeCacheDirName(
testTarget = kotlinNativeTargets.testTarget,
@@ -184,6 +186,15 @@ internal sealed interface CacheMode {
enum class Alias { NO, STATIC_ONLY_DIST, STATIC_EVERYWHERE }
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) =
"$testTarget${if (debuggable) "-g" else ""}$cacheKind"
}