[Native][tests] Gradle property: GCType

This commit is contained in:
Dmitriy Dolovov
2021-12-21 17:04:11 +03:00
parent 2b43dce1a5
commit a338cc31cb
5 changed files with 48 additions and 1 deletions
+1
View File
@@ -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");
@@ -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"
@@ -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<TestModule>,
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 ->
@@ -104,7 +104,13 @@ internal class TestCompilerArgs(val compilerArgs: List<String>) {
companion object {
val EMPTY = TestCompilerArgs(emptyList())
fun findForbiddenArgs(compilerArgs: Iterable<String>): Set<String> = compilerArgs intersect EXPLICITLY_FORBIDDEN_COMPILER_ARGS
fun findForbiddenArgs(compilerArgs: Iterable<String>): Set<String> = 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<String>) {
"-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="
)
}
}
@@ -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<String>?) {
DEFAULT(null),
EXPERIMENTAL(listOf("-memory-model", "experimental"));
@@ -60,6 +66,9 @@ internal enum class MemoryModel(val compilerFlags: List<String>?) {
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.
*/