[K/N][box-tests] Supported running box tests with per-file caches

This commit is contained in:
Igor Chevdar
2022-04-20 16:15:06 +05:00
committed by Space
parent 93929de53f
commit 03d21d9f79
7 changed files with 30 additions and 16 deletions
@@ -340,19 +340,18 @@ internal val dumpTestsPhase = makeCustomPhase<Context, IrModuleFragment>(
val testDumpFile = context.config.testDumpFile
requireNotNull(testDumpFile)
if (context.testCasesToDump.isEmpty()) {
testDumpFile.writeText("")
return@makeCustomPhase
}
if (!testDumpFile.exists)
testDumpFile.createNew()
testDumpFile.writeText(
context.testCasesToDump.asSequence()
if (context.testCasesToDump.isEmpty())
return@makeCustomPhase
testDumpFile.appendLines(
context.testCasesToDump
.flatMap { (suiteClassId, functionNames) ->
val suiteName = suiteClassId.asString()
functionNames.asSequence().map { "$suiteName:$it" }
}
.sorted()
.joinToString(separator = "\n")
)
}
)
@@ -1,5 +1,5 @@
infrastructure/testListing/bar/Common_testsKt:topLevel
infrastructure/testListing/bar/O:testObject
infrastructure/testListing/bar/Outer.Nested:nested
infrastructure/testListing/bar/Outer:outer
infrastructure/testListing/bar/Outer.Nested:nested
infrastructure/testListing/bar/O:testObject
infrastructure/testListing/bar/Util_testsKt:testFortyTwo
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.konan.blackboxtest.support
/**
* Represents a package name.
*/
internal class PackageName private constructor(private val fqn: String, val segments: List<String>) {
internal class PackageName private constructor(private val fqn: String, val segments: List<String>): Comparable<PackageName> {
constructor(segments: List<String>) : this(segments.joinToString("."), segments)
constructor(fqn: String) : this(fqn, if (fqn.isNotEmpty()) fqn.split('.') else emptyList())
@@ -18,6 +18,8 @@ internal class PackageName private constructor(private val fqn: String, val segm
override fun equals(other: Any?) = fqn == (other as? PackageName)?.fqn
override fun hashCode() = fqn.hashCode()
override fun compareTo(other: PackageName) = fqn.compareTo(other.fqn)
companion object {
val EMPTY = PackageName("", emptyList())
}
@@ -31,7 +33,7 @@ internal class PackageName private constructor(private val fqn: String, val segm
* [packagePartClassName] - package-part class name (if there is any)
* [functionName] - name of test function
*/
internal class TestName {
internal class TestName: Comparable<TestName> {
private val fqn: String
val packageName: PackageName
@@ -71,6 +73,8 @@ internal class TestName {
override fun equals(other: Any?) = fqn == (other as? TestName)?.fqn
override fun hashCode() = fqn.hashCode()
override fun compareTo(other: TestName) = fqn.compareTo(other.fqn)
companion object {
private fun Char.isEffectivelyUpperCase() = if (isUpperCase()) true else !isLowerCase()
private fun String?.isPackagePartClassName() = this != null && firstOrNull()?.isEffectivelyUpperCase() == true && endsWith("Kt")
@@ -244,9 +244,11 @@ private object NativeTestSupport {
CacheMode.Alias.NO -> return CacheMode.WithoutCache
CacheMode.Alias.STATIC_ONLY_DIST -> false
CacheMode.Alias.STATIC_EVERYWHERE -> true
CacheMode.Alias.STATIC_PER_FILE_EVERYWHERE -> true
}
val makePerFileCaches = cacheMode == CacheMode.Alias.STATIC_PER_FILE_EVERYWHERE
return CacheMode.WithStaticCache(distribution, kotlinNativeTargets, optimizationMode, staticCacheRequiredForEveryLibrary)
return CacheMode.WithStaticCache(distribution, kotlinNativeTargets, optimizationMode, staticCacheRequiredForEveryLibrary, makePerFileCaches)
}
private fun computeTestMode(enforcedProperties: EnforcedProperties): TestMode =
@@ -292,6 +292,8 @@ internal class StaticCacheCompilation(
cacheMode.staticCacheRootDir ?: fail { "No cache root directory found for cache mode $cacheMode" }
}
private val makePerFileCache: Boolean = settings.get<CacheMode>().makePerFileCaches
override fun applySpecificArgs(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
add("-produce", "static_cache")
@@ -310,6 +312,8 @@ internal class StaticCacheCompilation(
"-Xcache-directory=${expectedArtifact.cacheDir.path}",
"-Xcache-directory=$cacheRootDir"
)
if (makePerFileCache)
add("-Xmake-per-file-cache")
}
override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
@@ -152,17 +152,20 @@ internal class Timeouts(val executionTimeout: Duration) {
internal sealed interface CacheMode {
val staticCacheRootDir: File?
val staticCacheRequiredForEveryLibrary: Boolean
val makePerFileCaches: Boolean
object WithoutCache : CacheMode {
override val staticCacheRootDir: File? get() = null
override val staticCacheRequiredForEveryLibrary get() = false
override val makePerFileCaches: Boolean = false
}
class WithStaticCache(
distribution: Distribution,
kotlinNativeTargets: KotlinNativeTargets,
optimizationMode: OptimizationMode,
override val staticCacheRequiredForEveryLibrary: Boolean
override val staticCacheRequiredForEveryLibrary: Boolean,
override val makePerFileCaches: Boolean
) : CacheMode {
override val staticCacheRootDir: File = File(distribution.klib)
.resolve("cache")
@@ -183,7 +186,7 @@ internal sealed interface CacheMode {
}
}
enum class Alias { NO, STATIC_ONLY_DIST, STATIC_EVERYWHERE }
enum class Alias { NO, STATIC_ONLY_DIST, STATIC_EVERYWHERE, STATIC_PER_FILE_EVERYWHERE }
companion object {
fun defaultForTestTarget(distribution: Distribution, kotlinNativeTargets: KotlinNativeTargets): Alias {
@@ -34,7 +34,9 @@ internal object DumpedTestListing {
emptyLineEncountered = true
null
}
emptyLineEncountered -> parseError("Unexpected empty line")
else -> {
val (packageAndClass, functionName) = line.trim()
.split(':')
@@ -48,7 +50,7 @@ internal object DumpedTestListing {
}
}
}
}
}.sorted()
}
}