diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt index f0b454d53f9..fbc2bf095b8 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt @@ -340,19 +340,18 @@ internal val dumpTestsPhase = makeCustomPhase( 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") ) } ) diff --git a/native/native.tests/testData/infrastructure/testListing/expected-test-listing.dump b/native/native.tests/testData/infrastructure/testListing/expected-test-listing.dump index b66bbdd6578..b3b34f94231 100644 --- a/native/native.tests/testData/infrastructure/testListing/expected-test-listing.dump +++ b/native/native.tests/testData/infrastructure/testListing/expected-test-listing.dump @@ -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 diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NamedEntities.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NamedEntities.kt index 5b284021613..b77c80ad5e8 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NamedEntities.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NamedEntities.kt @@ -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) { +internal class PackageName private constructor(private val fqn: String, val segments: List): Comparable { constructor(segments: List) : 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 { 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") diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt index 1bc605ce1b4..6d67e299f87 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.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 = diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt index 7d7baca6681..69584b001cb 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt @@ -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().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) { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt index ec0bdd371f3..995ec94ea34 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt @@ -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 { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestListing.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestListing.kt index 74665dd51fc..cb4392453c4 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestListing.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/util/TestListing.kt @@ -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() } }