From a338cc31cbc2cd4b8701d8482fd830d2b94f15c2 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Tue, 21 Dec 2021 17:04:11 +0300 Subject: [PATCH] [Native][tests] Gradle property: GCType --- native/native.tests/build.gradle.kts | 1 + .../support/NativeBlackBoxTestSupport.kt | 11 ++++++++++ .../blackboxtest/support/TestCompiler.kt | 4 ++++ .../blackboxtest/support/TestDirectives.kt | 13 +++++++++++- .../support/settings/TestProcessSettings.kt | 20 +++++++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/native/native.tests/build.gradle.kts b/native/native.tests/build.gradle.kts index b4c35c4cde1..a85feddca02 100644 --- a/native/native.tests/build.gradle.kts +++ b/native/native.tests/build.gradle.kts @@ -51,6 +51,7 @@ enum class TestProperty(shortName: String) { OPTIMIZATION_MODE("optimizationMode"), MEMORY_MODEL("memoryModel"), USE_THREAD_STATE_CHECKER("useThreadStateChecker"), + GC_TYPE("gcType"), USE_CACHE("useCache"), EXECUTION_TIMEOUT("executionTimeout"); diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt index caf09c27a29..8ad3346eddf 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt @@ -64,6 +64,13 @@ class NativeBlackBoxTestSupport : BeforeEachCallback { } } + val gcType = computeGCType() + if (gcType != GCType.UNSPECIFIED) { + assertEquals(MemoryModel.EXPERIMENTAL, memoryModel) { + "GC type can be specified only with experimental memory model" + } + } + return root.getStore(NAMESPACE).getOrComputeIfAbsent(TestProcessSettings::class.java.name) { TestProcessSettings( computeNativeTargets(), @@ -73,6 +80,7 @@ class NativeBlackBoxTestSupport : BeforeEachCallback { optimizationMode, memoryModel, threadStateChecker, + gcType, CacheKind::class to computeCacheKind(), computeBaseDirs(), computeTimeouts() @@ -111,6 +119,8 @@ class NativeBlackBoxTestSupport : BeforeEachCallback { return if (useThreadStateChecker) ThreadStateChecker.ENABLED else ThreadStateChecker.DISABLED } + private fun computeGCType(): GCType = enumSystemProperty(GC_TYPE, GCType.values(), default = GCType.UNSPECIFIED) + private fun computeCacheKind(): CacheKind { val useCache = systemProperty(USE_CACHE, String::toBooleanStrictOrNull, default = true) return if (useCache) CacheKind.WithStaticCache else CacheKind.WithoutCache @@ -159,6 +169,7 @@ class NativeBlackBoxTestSupport : BeforeEachCallback { private const val OPTIMIZATION_MODE = "kotlin.internal.native.test.optimizationMode" private const val MEMORY_MODEL = "kotlin.internal.native.test.memoryModel" private const val USE_THREAD_STATE_CHECKER = "kotlin.internal.native.test.useThreadStateChecker" + private const val GC_TYPE = "kotlin.internal.native.test.gcType" private const val USE_CACHE = "kotlin.internal.native.test.useCache" private const val EXECUTION_TIMEOUT = "kotlin.internal.native.test.executionTimeout" private const val PROJECT_BUILD_DIR = "PROJECT_BUILD_DIR" diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt index cdb589c3517..461b3b253e4 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt @@ -53,6 +53,7 @@ internal class TestCompilationFactory { optimizationMode = settings.get(), memoryModel = settings.get(), threadStateChecker = settings.get(), + gcType = settings.get(), freeCompilerArgs = freeCompilerArgs, sourceModules = rootModules, dependencies = TestCompilationDependencies(libraries = libraries, friends = friends), @@ -97,6 +98,7 @@ internal class TestCompilationFactory { optimizationMode = settings.get(), memoryModel = settings.get(), threadStateChecker = settings.get(), + gcType = settings.get(), freeCompilerArgs = freeCompilerArgs, sourceModules = sourceModules, dependencies = TestCompilationDependencies(libraries = libraries, friends = friends), @@ -248,6 +250,7 @@ private class TestCompilationImpl( private val optimizationMode: OptimizationMode, private val memoryModel: MemoryModel, private val threadStateChecker: ThreadStateChecker, + private val gcType: GCType, private val freeCompilerArgs: TestCompilerArgs, private val sourceModules: Collection, private val dependencies: TestCompilationDependencies, @@ -276,6 +279,7 @@ private class TestCompilationImpl( optimizationMode.compilerFlag?.let { compilerFlag -> add(compilerFlag) } memoryModel.compilerFlags?.let { compilerFlags -> add(compilerFlags) } threadStateChecker.compilerFlag?.let { compilerFlag -> add(compilerFlag) } + gcType.compilerFlag?.let { compilerFlag -> add(compilerFlag) } addFlattened(dependencies.libraries) { library -> listOf("-l", library.resultingArtifactPath) } dependencies.friends.takeIf(Collection<*>::isNotEmpty)?.let { friends -> diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt index 9add844b70d..38009194d63 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestDirectives.kt @@ -104,7 +104,13 @@ internal class TestCompilerArgs(val compilerArgs: List) { companion object { val EMPTY = TestCompilerArgs(emptyList()) - fun findForbiddenArgs(compilerArgs: Iterable): Set = compilerArgs intersect EXPLICITLY_FORBIDDEN_COMPILER_ARGS + fun findForbiddenArgs(compilerArgs: Iterable): Set = buildSet { + addAll(compilerArgs) + retainAll(EXPLICITLY_FORBIDDEN_COMPILER_ARGS) + compilerArgs.mapNotNullTo(this) { arg -> + if (EXPLICITLY_FORBIDDEN_COMPILER_ARG_PREFIXES.any { prefix -> arg.startsWith(prefix) }) arg else null + } + } /** The set of compiler args that are not permitted to be explicitly specified using [FREE_COMPILER_ARGS]. */ private val EXPLICITLY_FORBIDDEN_COMPILER_ARGS = setOf( @@ -122,6 +128,11 @@ internal class TestCompilerArgs(val compilerArgs: List) { "-memory-model", "-Xcheck-state-at-external-calls" ) + + /** The set of compiler arg prefixes that are not permitted to be explicitly specified using [FREE_COMPILER_ARGS]. */ + private val EXPLICITLY_FORBIDDEN_COMPILER_ARG_PREFIXES = setOf( + "-Xgc=" + ) } } 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 a5390006fed..cd39db968da 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 @@ -45,6 +45,9 @@ internal enum class TestMode(private val description: String) { override fun toString() = description } +/** + * Optimization mode to be applied. + */ internal enum class OptimizationMode(private val description: String, val compilerFlag: String?) { DEBUG("Build with debug information", "-g"), OPT("Build with optimizations applied", "-opt"), @@ -53,6 +56,9 @@ internal enum class OptimizationMode(private val description: String, val compil override fun toString() = description + compilerFlag?.let { " ($it)" }.orEmpty() } +/** + * The Kotlin/Native memoty model. + */ internal enum class MemoryModel(val compilerFlags: List?) { DEFAULT(null), EXPERIMENTAL(listOf("-memory-model", "experimental")); @@ -60,6 +66,9 @@ internal enum class MemoryModel(val compilerFlags: List?) { override fun toString() = compilerFlags?.joinToString(prefix = "(", separator = " ", postfix = ")").orEmpty() } +/** + * Thread state checked. Can be applied only with [MemoryModel.EXPERIMENTAL] and [OptimizationMode.DEBUG]. + */ internal enum class ThreadStateChecker(val compilerFlag: String?) { DISABLED(null), ENABLED("-Xcheck-state-at-external-calls"); @@ -67,6 +76,17 @@ internal enum class ThreadStateChecker(val compilerFlag: String?) { override fun toString() = compilerFlag?.let { "($it)" }.orEmpty() } +/** + * Garbage collector type. Can be applied only with [MemoryModel.EXPERIMENTAL]. + */ +internal enum class GCType(val compilerFlag: String?) { + UNSPECIFIED(null), + NOOP("-Xgc=noop"), + STMS("-Xgc=stms"); + + override fun toString() = compilerFlag?.let { "($it)" }.orEmpty() +} + /** * Current project's directories. */