Add worker test runner. (#2303)
This commit is contained in:
@@ -177,14 +177,17 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
|
||||
put(ENABLE_ASSERTIONS, arguments.enableAssertions)
|
||||
|
||||
put(GENERATE_TEST_RUNNER, arguments.generateTestRunner)
|
||||
|
||||
when {
|
||||
arguments.generateWorkerTestRunner -> put(GENERATE_TEST_RUNNER, TestRunnerKind.WORKER)
|
||||
arguments.generateTestRunner -> put(GENERATE_TEST_RUNNER, TestRunnerKind.MAIN_THREAD)
|
||||
else -> put(GENERATE_TEST_RUNNER, TestRunnerKind.NONE)
|
||||
}
|
||||
// We need to download dependencies only if we use them ( = there are files to compile).
|
||||
put(CHECK_DEPENDENCIES, if (configuration.kotlinSourceRoots.isNotEmpty()) {
|
||||
true
|
||||
} else {
|
||||
arguments.checkDependencies
|
||||
})
|
||||
true
|
||||
} else {
|
||||
arguments.checkDependencies
|
||||
})
|
||||
if (arguments.friendModules != null)
|
||||
put(FRIEND_MODULES, arguments.friendModules!!.split(File.pathSeparator).filterNot(String::isEmpty))
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.bc
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.TestRunnerKind
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.Argument
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
@@ -22,8 +23,12 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-g", description = "Enable emitting debug information")
|
||||
var debug: Boolean = false
|
||||
|
||||
@Argument(value = "-generate-test-runner", deprecatedName = "-generate_test_runner", shortName = "-tr", description = "Produce a runner for unit tests")
|
||||
var generateTestRunner: Boolean = false
|
||||
@Argument(value = "-generate-test-runner", deprecatedName = "-generate_test_runner",
|
||||
shortName = "-tr", description = "Produce a runner for unit tests")
|
||||
var generateTestRunner = false
|
||||
@Argument(value = "-generate-worker-test-runner",
|
||||
shortName = "-trw", description = "Produce a worker runner for unit tests")
|
||||
var generateWorkerTestRunner = false
|
||||
|
||||
@Argument(value="-include-binary", deprecatedName = "-includeBinary", shortName = "-ib", valueDescription = "<path>", description = "Pack external binary within the klib")
|
||||
var includeBinaries: Array<String>? = null
|
||||
|
||||
-3
@@ -502,9 +502,6 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
|
||||
fun shouldOptimize() = config.configuration.getBoolean(KonanConfigKeys.OPTIMIZATION)
|
||||
|
||||
fun shouldGenerateTestRunner() =
|
||||
config.configuration.getBoolean(KonanConfigKeys.GENERATE_TEST_RUNNER)
|
||||
|
||||
override fun log(message: () -> String) {
|
||||
if (phase?.verbose ?: false) {
|
||||
println(message())
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create<List<String>>("libraries included into produced framework API")
|
||||
val FRIEND_MODULES: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create<List<String>>("friend module paths")
|
||||
val GENERATE_TEST_RUNNER: CompilerConfigurationKey<Boolean>
|
||||
val GENERATE_TEST_RUNNER: CompilerConfigurationKey<TestRunnerKind>
|
||||
= CompilerConfigurationKey.create("generate test runner")
|
||||
val INCLUDED_BINARY_FILES: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create("included binary file paths")
|
||||
|
||||
+3
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
import org.jetbrains.kotlin.konan.util.*
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
|
||||
@@ -83,7 +84,8 @@ object KonanPhases {
|
||||
(config.produce == CompilerOutputKind.LIBRARY)
|
||||
KonanPhase.LINK_STAGE.enabled = config.produce.isNativeBinary
|
||||
|
||||
KonanPhase.TEST_PROCESSOR.enabled = getBoolean(GENERATE_TEST_RUNNER)
|
||||
KonanPhase.TEST_PROCESSOR.enabled =
|
||||
getNotNull(KonanConfigKeys.GENERATE_TEST_RUNNER) != TestRunnerKind.NONE
|
||||
|
||||
val disabled = get(DISABLED_PHASES)
|
||||
disabled?.forEach { phases[known(it)]!!.enabled = false }
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
enum class TestRunnerKind {
|
||||
NONE,
|
||||
MAIN_THREAD,
|
||||
WORKER
|
||||
}
|
||||
+9
-10
@@ -5,12 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.reportCompilationError
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isArray
|
||||
import org.jetbrains.kotlin.backend.konan.report
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
@@ -28,8 +26,7 @@ internal fun findMainEntryPoint(context: Context): FunctionDescriptor? {
|
||||
val config = context.config.configuration
|
||||
if (config.get(KonanConfigKeys.PRODUCE) != PROGRAM) return null
|
||||
|
||||
val entryPoint = FqName(config.get(KonanConfigKeys.ENTRY) ?:
|
||||
if (context.shouldGenerateTestRunner()) testEntryName else defaultEntryName)
|
||||
val entryPoint = FqName(config.get(KonanConfigKeys.ENTRY) ?: defaultEntryName(config))
|
||||
|
||||
val entryName = entryPoint.shortName()
|
||||
val packageName = entryPoint.parent()
|
||||
@@ -59,10 +56,12 @@ internal fun findMainEntryPoint(context: Context): FunctionDescriptor? {
|
||||
return main
|
||||
}
|
||||
|
||||
private val defaultEntryName = "main"
|
||||
private val testEntryName = "kotlin.native.internal.test.main"
|
||||
|
||||
private val defaultEntryPackage = FqName.ROOT
|
||||
private fun defaultEntryName(config: CompilerConfiguration): String =
|
||||
when (config.get(KonanConfigKeys.GENERATE_TEST_RUNNER)) {
|
||||
TestRunnerKind.MAIN_THREAD -> "kotlin.native.internal.test.main"
|
||||
TestRunnerKind.WORKER -> "kotlin.native.internal.test.worker"
|
||||
else -> "main"
|
||||
}
|
||||
|
||||
private val KotlinType.filterClass: ClassDescriptor?
|
||||
get() {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.system.exitProcess
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
@ThreadLocal
|
||||
private val _generatedSuites = mutableListOf<TestSuite>()
|
||||
@@ -21,3 +22,12 @@ fun testLauncherEntryPoint(args: Array<String>): Int {
|
||||
fun main(args: Array<String>) {
|
||||
exitProcess(testLauncherEntryPoint(args))
|
||||
}
|
||||
|
||||
fun worker(args: Array<String>) {
|
||||
val worker = Worker.start()
|
||||
val result = worker.execute(TransferMode.SAFE, { args.freeze() }) {
|
||||
it -> testLauncherEntryPoint(it)
|
||||
}.result
|
||||
worker.requestTermination().result
|
||||
exitProcess(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user