[Native][tests] Add "compile only tests" mode

This commit is contained in:
Dmitriy Dolovov
2022-05-04 16:12:33 +03:00
committed by Space
parent edf7319cad
commit 50de3d6257
8 changed files with 54 additions and 5 deletions
+2
View File
@@ -50,6 +50,7 @@ enum class TestProperty(shortName: String) {
TEST_TARGET("target"),
TEST_MODE("mode"),
FORCE_STANDALONE("forceStandalone"),
COMPILE_ONLY("compileOnly"),
OPTIMIZATION_MODE("optimizationMode"),
MEMORY_MODEL("memoryModel"),
USE_THREAD_STATE_CHECKER("useThreadStateChecker"),
@@ -117,6 +118,7 @@ fun nativeTest(taskName: String, vararg tags: String) = projectTest(taskName, jU
TestProperty.TEST_TARGET.setUpFromGradleProperty(this)
TestProperty.TEST_MODE.setUpFromGradleProperty(this)
TestProperty.FORCE_STANDALONE.setUpFromGradleProperty(this)
TestProperty.COMPILE_ONLY.setUpFromGradleProperty(this)
TestProperty.OPTIMIZATION_MODE.setUpFromGradleProperty(this)
TestProperty.MEMORY_MODEL.setUpFromGradleProperty(this)
TestProperty.USE_THREAD_STATE_CHECKER.setUpFromGradleProperty(this)
@@ -44,6 +44,7 @@ internal enum class ClassLevelProperty(shortName: String) {
TEST_TARGET("target"),
TEST_MODE("mode"),
FORCE_STANDALONE("forceStandalone"),
COMPILE_ONLY("compileOnly"),
OPTIMIZATION_MODE("optimizationMode"),
MEMORY_MODEL("memoryModel"),
USE_THREAD_STATE_CHECKER("useThreadStateChecker"),
@@ -159,6 +159,7 @@ private object NativeTestSupport {
output += CacheMode::class to cacheMode
output += computeTestMode(enforcedProperties)
output += computeForcedStandaloneTestKind(enforcedProperties)
output += computeForcedNoopTestRunner(enforcedProperties)
output += computeTimeouts(enforcedProperties)
return nativeTargets
@@ -230,6 +231,15 @@ private object NativeTestSupport {
)
)
private fun computeForcedNoopTestRunner(enforcedProperties: EnforcedProperties): ForcedNoopTestRunner =
ForcedNoopTestRunner(
ClassLevelProperty.COMPILE_ONLY.readValue(
enforcedProperties,
String::toBooleanStrictOrNull,
default = false
)
)
private fun computeTimeouts(enforcedProperties: EnforcedProperties): Timeouts {
val executionTimeout = ClassLevelProperty.EXECUTION_TIMEOUT.readValue(
enforcedProperties,
@@ -9,13 +9,13 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.LoggedData
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
import org.opentest4j.TestAbortedException
internal abstract class AbstractRunner<R> {
internal abstract class AbstractRunner<R>: Runner<R> {
protected abstract fun buildRun(): AbstractRun
protected abstract fun buildResultHandler(runResult: RunResult): ResultHandler
protected abstract fun getLoggedParameters(): LoggedData.TestRunParameters
protected abstract fun handleUnexpectedFailure(t: Throwable): Nothing
fun run(): R = try {
final override fun run(): R = try {
val run = buildRun()
val runResult = run.run()
val resultHandler = buildResultHandler(runResult)
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.blackboxtest.support.runner
internal object NoopTestRunner : Runner<Unit> {
override fun run() {
/* do nothing */
}
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.blackboxtest.support.runner
internal interface Runner<R> {
fun run(): R
}
@@ -6,15 +6,18 @@
package org.jetbrains.kotlin.konan.blackboxtest.support.runner
import org.jetbrains.kotlin.konan.blackboxtest.support.TestName
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.ForcedNoopTestRunner
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTargets
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Settings
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
internal object TestRunners {
// Currently, only local test runner is supported.
fun createProperTestRunner(testRun: TestRun, settings: Settings): AbstractRunner<*> = with(settings) {
with(get<KotlinNativeTargets>()) {
// Currently, only local and noop test runners are supported.
fun createProperTestRunner(testRun: TestRun, settings: Settings): Runner<Unit> = with(settings) {
if (get<ForcedNoopTestRunner>().value) {
NoopTestRunner
} else with(get<KotlinNativeTargets>()) {
if (testTarget == hostTarget)
LocalTestRunner(testRun)
else
@@ -6,6 +6,9 @@
package org.jetbrains.kotlin.konan.blackboxtest.support.settings
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.target.KonanTarget
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
import java.io.File
@@ -63,6 +66,14 @@ internal enum class TestMode(private val description: String) {
@JvmInline
internal value class ForcedStandaloneTestKind(val value: Boolean)
/**
* Whether tests should be compiled only (true) or compiled and executed (false, the default).
*
* TODO: need to reconsider this setting when other [Runner]s than [LocalTestRunner] and [NoopTestRunner] are supported
*/
@JvmInline
internal value class ForcedNoopTestRunner(val value: Boolean)
/**
* Optimization mode to be applied.
*/