[K/N][tests] Move driver tests into their own project ^KT-61259

This commit is contained in:
Alexander Shabalin
2024-03-07 12:01:06 +01:00
committed by Space Team
parent 316614bc9e
commit 8c6966765b
26 changed files with 87 additions and 59 deletions
+1
View File
@@ -814,6 +814,7 @@ tasks {
dependsOn(":kotlin-atomicfu-compiler-plugin:nativeTest")
dependsOn(":native:analysis-api-klib-reader:check")
dependsOn(":native:native.tests:test")
dependsOn(":native:native.tests:driver:check")
dependsOn(":native:native.tests:stress:check")
dependsOn(":native:objcexport-header-generator:check")
dependsOn(":native:swift:swift-export-standalone:test")
-1
View File
@@ -56,7 +56,6 @@ val debuggerTest = nativeTest("debuggerTest", "debugger")
val cachesTest = nativeTest("cachesTest", "caches")
val klibTest = nativeTest("klibTest", "klib")
val standaloneTest = nativeTest("standaloneTest", "standalone")
val driverTest = nativeTest("driverTest", "driver")
val testTags = findProperty("kotlin.native.tests.tags")?.toString()
// Note: arbitrary JUnit tag expressions can be used in this property.
@@ -0,0 +1,27 @@
plugins {
kotlin("jvm")
}
dependencies {
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
testImplementation(projectTests(":native:native.tests"))
}
sourceSets {
"main" { none() }
"test" {
projectDefault()
generatedTestDir()
}
}
testsJar {}
nativeTest(
"test",
null,
allowParallelExecution = false, // Driver tests run Native compiler from CLI. This is resource-intensive and should be done isolated.
)
@@ -41,7 +41,7 @@ class KonanDriverTest : AbstractNativeSimpleTest() {
private val buildDir get() = testRunSettings.get<Binaries>().testBinariesDir
private val konanc get() = konanHome.resolve("bin").resolve(if (HostManager.hostIsMingw) "konanc.bat" else "konanc")
private val testSuiteDir = File("native/native.tests/testData/driver")
private val testSuiteDir = File("native/native.tests/driver/testData")
private val source = testSuiteDir.resolve("driver0.kt")
@Test
@@ -16,7 +16,7 @@ import kotlin.test.fail
@ExtendWith(NativeSimpleTestSupport::class)
abstract class AbstractNativeSimpleTest {
internal lateinit var testRunSettings: SimpleTestRunSettings
lateinit var testRunSettings: SimpleTestRunSettings
internal lateinit var testRunProvider: SimpleTestRunProvider
fun muteForK2(isK2: Boolean, test: () -> Unit) {
@@ -103,7 +103,7 @@ internal class ExecutableBuilder(
}
internal val AbstractNativeSimpleTest.buildDir: File get() = testRunSettings.get<Binaries>().testBinariesDir
internal val AbstractNativeSimpleTest.targets: KotlinNativeTargets get() = testRunSettings.get()
val AbstractNativeSimpleTest.targets: KotlinNativeTargets get() = testRunSettings.get()
internal fun TestCompilationArtifact.KLIB.asLibraryDependency() =
ExistingDependency(this, TestCompilationDependencyType.Library)
@@ -22,7 +22,7 @@ import kotlin.time.DurationUnit
*
* Handles all the necessary formatting right inside of [computeText]. Caches the resulting text to avoid re-computation.
*/
internal abstract class LoggedData {
abstract class LoggedData {
private val text: String by lazy { computeText() }
protected abstract fun computeText(): String
final override fun toString() = text
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.konan.test.blackbox.support
/**
* Represents a package name.
*/
internal class PackageName private constructor(private val fqn: String, val segments: List<String>): Comparable<PackageName> {
class PackageName private constructor(private val fqn: String, val segments: List<String>): Comparable<PackageName> {
constructor(segments: List<String>) : this(segments.joinToString("."), segments)
constructor(fqn: String) : this(fqn, if (fqn.isNotEmpty()) fqn.split('.') else emptyList())
@@ -33,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: Comparable<TestName> {
class TestName: Comparable<TestName> {
private val fqn: String
val packageName: PackageName
@@ -20,7 +20,7 @@ import java.io.File
/**
* Represents a single file that will be supplied to the compiler.
*/
internal class TestFile<M : TestModule> private constructor(
class TestFile<M : TestModule> private constructor(
val location: File,
val module: M,
private var state: State
@@ -79,7 +79,7 @@ internal class TestFile<M : TestModule> private constructor(
* [TestModule.Shared] represents a "shared" module, i.e. the auxiliary module that can be used in multiple [TestCase]s.
* Such module is compiled to KLIB
*/
internal sealed class TestModule {
sealed class TestModule {
abstract val name: String
abstract val files: Set<TestFile<*>>
@@ -157,7 +157,7 @@ internal sealed class TestModule {
*
* [testCaseGroupId] - a unique ID of [TestCaseGroup] this [TestCase] belongs to.
*/
internal interface TestCaseId {
interface TestCaseId {
val testCaseGroupId: TestCaseGroupId
data class TestDataFile(val file: File) : TestCaseId {
@@ -181,7 +181,7 @@ internal interface TestCaseId {
* [nominalPackageName] - the unique package name that was computed for this [TestCase] based on [id].
* Note: It depends on the concrete [TestKind] whether the package name will be enforced for the [TestFile]s or not.
*/
internal class TestCase(
class TestCase(
val id: TestCaseId,
val kind: TestKind,
val modules: Set<TestModule.Exclusive>,
@@ -281,7 +281,7 @@ internal class TestCase(
/**
* A unique identified of [TestCaseGroup].
*/
internal interface TestCaseGroupId {
interface TestCaseGroupId {
data class TestDataDir(val dir: File) : TestCaseGroupId
data class Named(val uniqueName: String) : TestCaseGroupId
}
@@ -201,7 +201,7 @@ internal object TestDirectives : SimpleDirectivesContainer() {
}
// mimics class `JVMAssertionsMode`
internal enum class AssertionsMode(val description: String) {
enum class AssertionsMode(val description: String) {
ALWAYS_ENABLE("always-enable"),
ALWAYS_DISABLE("always-disable"),
JVM("jvm"),
@@ -214,20 +214,20 @@ internal enum class AssertionsMode(val description: String) {
}
}
internal enum class TestKind {
enum class TestKind {
REGULAR,
STANDALONE,
STANDALONE_NO_TR,
STANDALONE_LLDB;
}
internal enum class TestRunnerType {
enum class TestRunnerType {
DEFAULT,
WORKER,
NO_EXIT
}
internal enum class MutedOption {
enum class MutedOption {
DEFAULT,
K1,
K2
@@ -241,7 +241,7 @@ internal class TestCInteropArgs(cinteropArgs: List<String>) : TestCompilerArgs(e
constructor(vararg cinteropArgs: String) : this(cinteropArgs.asList())
}
internal open class TestCompilerArgs(
open class TestCompilerArgs(
val compilerArgs: List<String>,
val cinteropArgs: List<String> = emptyList(),
val assertionsMode: AssertionsMode = AssertionsMode.DEFAULT,
@@ -33,11 +33,11 @@ private fun AssertionsMode.assertionsEnabledWith(optimizationMode: OptimizationM
else -> optimizationMode != OptimizationMode.OPT
}
internal abstract class TestCompilation<A : TestCompilationArtifact> {
abstract class TestCompilation<A : TestCompilationArtifact> {
abstract val result: TestCompilationResult<out A>
}
internal abstract class BasicCompilation<A : TestCompilationArtifact>(
abstract class BasicCompilation<A : TestCompilationArtifact>(
protected val targets: KotlinNativeTargets,
protected val home: KotlinNativeHome,
private val classLoader: KotlinNativeClassLoader,
@@ -184,7 +184,7 @@ internal abstract class BasicCompilation<A : TestCompilationArtifact>(
}
}
internal abstract class SourceBasedCompilation<A : TestCompilationArtifact>(
abstract class SourceBasedCompilation<A : TestCompilationArtifact>(
targets: KotlinNativeTargets,
home: KotlinNativeHome,
classLoader: KotlinNativeClassLoader,
@@ -491,7 +491,7 @@ internal class SwiftCompilation<T: TestCompilationArtifact>(
}
}
internal class ExecutableCompilation(
class ExecutableCompilation(
settings: Settings,
freeCompilerArgs: TestCompilerArgs,
sourceModules: Collection<TestModule>,
@@ -664,7 +664,7 @@ internal class StaticCacheCompilation(
}
}
internal class CategorizedDependencies(uncategorizedDependencies: Iterable<TestCompilationDependency<*>>) {
class CategorizedDependencies(uncategorizedDependencies: Iterable<TestCompilationDependency<*>>) {
val failures: Set<TestCompilationResult.Failure> by lazy {
uncategorizedDependencies.flatMapToSet { dependency ->
when (val result = (dependency as? TestCompilation<*>)?.result) {
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.konan.test.blackbox.support.compilation
import java.io.File
internal sealed interface TestCompilationArtifact {
sealed interface TestCompilationArtifact {
val logFile: File
data class KLIB(val klibFile: File) : TestCompilationArtifact {
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.TestCompilat
* [IncludedLibrary] - similarly but included modules (-Xinclude).
* Note: there cannot be DependsOnLibrary type, since `dependsOn` dependency works only within a KLIB, not between KLIBs.
*/
internal sealed class TestCompilationDependencyType<A : TestCompilationArtifact>(private val artifactClass: Class<A>) {
sealed class TestCompilationDependencyType<A : TestCompilationArtifact>(private val artifactClass: Class<A>) {
object Library : TestCompilationDependencyType<KLIB>(KLIB::class.java)
object FriendLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java)
object IncludedLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java)
@@ -26,7 +26,7 @@ internal sealed class TestCompilationDependencyType<A : TestCompilationArtifact>
object LibraryStaticCache : TestCompilationDependencyType<KLIBStaticCache>(KLIBStaticCache::class.java)
}
internal sealed interface TestCompilationDependency<A : TestCompilationArtifact> {
sealed interface TestCompilationDependency<A : TestCompilationArtifact> {
val artifact: A
val type: TestCompilationDependencyType<A>
}
@@ -12,7 +12,7 @@ class CompilationToolException(val reason: String) : Exception() {
override fun toString() = "CompilationToolException: $reason"
}
internal sealed interface TestCompilationResult<A : TestCompilationArtifact> {
sealed interface TestCompilationResult<A : TestCompilationArtifact> {
sealed interface ImmediateResult<A : TestCompilationArtifact> : TestCompilationResult<A> {
val loggedData: LoggedData
}
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.konan.test.blackbox.support.runner
import org.jetbrains.kotlin.konan.test.blackbox.support.util.TestOutputFilter
import kotlin.time.Duration
internal data class RunResult(
data class RunResult(
val testExecutable: TestExecutable, // KT-62157: TODO extract out of RunResult and pass Pair(TestExecutable, RunResult)
val exitCode: Int?,
val timeout: Duration,
@@ -22,4 +22,4 @@ internal data class RunResult(
}
}
internal class ProcessOutput(val stdOut: TestOutputFilter.FilteredOutput, val stdErr: String)
class ProcessOutput(val stdOut: TestOutputFilter.FilteredOutput, val stdErr: String)
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import java.io.File
import java.io.IOException
internal class TestExecutable(
class TestExecutable(
val executable: Executable,
val loggedCompilationToolCall: LoggedData.CompilerCall,
val testNames: Collection<TestName>
@@ -50,7 +50,7 @@ internal class TestExecutable(
}
}
internal data class TestRun(
data class TestRun(
val displayName: String,
val executable: TestExecutable,
val runParameters: List<TestRunParameter>,
@@ -59,7 +59,7 @@ internal data class TestRun(
val expectedFailure: Boolean,
)
internal sealed interface TestRunParameter {
sealed interface TestRunParameter {
fun applyTo(programArgs: MutableList<String>)
sealed class WithFilter : TestRunParameter {
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Assumptions
import java.io.File
import kotlin.time.Duration
internal sealed interface TestRunCheck {
sealed interface TestRunCheck {
fun apply(testRun: TestRun, runResult: RunResult): Result
@@ -280,7 +280,7 @@ internal sealed interface TestRunCheck {
}
}
internal data class TestRunChecks(
data class TestRunChecks(
val executionTimeoutCheck: ExecutionTimeout,
val testFiltering: TestFiltering,
private val exitCodeCheck: ExitCode?,
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
import kotlin.reflect.KClass
internal abstract class Settings(private val parent: Settings?, settings: Iterable<Any>) {
abstract class Settings(private val parent: Settings?, settings: Iterable<Any>) {
private val map: Map<KClass<*>, Any> = buildMap {
settings.forEach {
val settingClass: KClass<*>
@@ -48,7 +48,7 @@ internal abstract class Settings(private val parent: Settings?, settings: Iterab
* | [TestClassSettings] | [TestProcessSettings] | The single top-level (enclosing) test class |
* | [TestRunSettings] | [TestClassSettings] | The single test run of a test function |
*/
internal class TestProcessSettings(vararg settings: Any) : Settings(parent = null, settings.asIterable())
class TestProcessSettings(vararg settings: Any) : Settings(parent = null, settings.asIterable())
internal class TestClassSettings(parent: TestProcessSettings, settings: Iterable<Any>) : Settings(parent, settings)
internal class TestRunSettings(parent: TestClassSettings, settings: Iterable<Any>) : Settings(parent, settings)
@@ -61,8 +61,8 @@ internal class TestRunSettings(parent: TestClassSettings, settings: Iterable<Any
* | [SimpleTestClassSettings] | [TestProcessSettings] | The single top-level (enclosing) test class |
* | [SimpleTestRunSettings] | [SimpleTestClassSettings] | The single test run of a test function |
*/
internal class SimpleTestClassSettings(parent: TestProcessSettings, settings: Iterable<Any>) : Settings(parent, settings)
internal class SimpleTestRunSettings(parent: SimpleTestClassSettings, settings: Iterable<Any>) : Settings(parent, settings)
class SimpleTestClassSettings(parent: TestProcessSettings, settings: Iterable<Any>) : Settings(parent, settings)
class SimpleTestRunSettings(parent: SimpleTestClassSettings, settings: Iterable<Any>) : Settings(parent, settings)
internal val Settings.configurables: Configurables
get() {
@@ -15,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap
private val executorCache: ConcurrentHashMap<KonanTarget, Executor> = ConcurrentHashMap()
internal val Settings.executor: Executor
val Settings.executor: Executor
get() = with(get<KotlinNativeTargets>()) {
executorCache.computeIfAbsent(testTarget) {
val configurables = configurables
@@ -26,7 +26,7 @@ internal class GeneratedSources(val testSourcesDir: File, val sharedSourcesDir:
* [sharedBinariesDir] - The directory with compiled shared modules (klibs).
* [givenBinariesDir] - The directory with the given (external) modules (klibs).
*/
internal class Binaries(val testBinariesDir: File, lazySharedBinariesDir: () -> File, lazyGivenBinariesDir: () -> File) {
class Binaries(val testBinariesDir: File, lazySharedBinariesDir: () -> File, lazyGivenBinariesDir: () -> File) {
val sharedBinariesDir: File by lazy { lazySharedBinariesDir() }
val givenBinariesDir: File by lazy { lazyGivenBinariesDir() }
}
@@ -25,14 +25,14 @@ import kotlin.time.Duration.Companion.seconds
/**
* The tested and the host Kotlin/Native targets.
*/
internal class KotlinNativeTargets(val testTarget: KonanTarget, val hostTarget: KonanTarget) {
class KotlinNativeTargets(val testTarget: KonanTarget, val hostTarget: KonanTarget) {
fun areDifferentTargets() = testTarget != hostTarget
}
/**
* The Kotlin/Native home.
*/
internal class KotlinNativeHome(val dir: File) {
class KotlinNativeHome(val dir: File) {
val librariesDir: File = dir.resolve("klib")
val stdlibFile: File = librariesDir.resolve("common/stdlib")
val properties: Properties by lazy {
@@ -56,7 +56,7 @@ internal class LLDB(nativeHome: KotlinNativeHome) {
/**
* Lazy-initialized class loader with the Kotlin/Native embedded compiler.
*/
internal class KotlinNativeClassLoader(private val lazyClassLoader: Lazy<ClassLoader>) {
class KotlinNativeClassLoader(private val lazyClassLoader: Lazy<ClassLoader>) {
val classLoader: ClassLoader get() = lazyClassLoader.value
}
@@ -82,7 +82,7 @@ internal enum class TestMode(private val description: String) {
* Kotlin compiler plugins to be used together with the the Kotlin/Native compiler.
*/
@JvmInline
internal value class CompilerPlugins(val compilerPluginJars: Set<File>) {
value class CompilerPlugins(val compilerPluginJars: Set<File>) {
init {
val invalidJars = compilerPluginJars.filterNot { it.isDirectory || (it.isFile && it.extension == "jar") }
assertTrue(invalidJars.isEmpty()) {
@@ -122,7 +122,7 @@ internal value class SharedExecutionTestRunner(val value: Boolean)
/**
* Optimization mode to be applied.
*/
internal enum class OptimizationMode(private val description: String, val compilerFlag: String?) {
enum class OptimizationMode(private val description: String, val compilerFlag: String?) {
DEBUG("Build with debug information", "-g"),
OPT("Build with optimizations applied", "-opt"),
NO("Don't use any specific optimizations", null);
@@ -133,7 +133,7 @@ internal enum class OptimizationMode(private val description: String, val compil
/**
* Thread state checked. Can be applied only with [OptimizationMode.DEBUG], [CacheMode.WithoutCache].
*/
internal enum class ThreadStateChecker(val compilerFlag: String?) {
enum class ThreadStateChecker(val compilerFlag: String?) {
DISABLED(null),
ENABLED("-Xbinary=checkStateAtExternalCalls=true");
@@ -143,7 +143,7 @@ internal enum class ThreadStateChecker(val compilerFlag: String?) {
/**
* Type of sanitizer. Can be applied only with [CacheMode.WithoutCache]
*/
internal enum class Sanitizer(val compilerFlag: String?) {
enum class Sanitizer(val compilerFlag: String?) {
NONE(null),
THREAD("-Xbinary=sanitizer=thread");
@@ -153,7 +153,7 @@ internal enum class Sanitizer(val compilerFlag: String?) {
/**
* Garbage collector type.
*/
internal enum class GCType(val compilerFlag: String?) {
enum class GCType(val compilerFlag: String?) {
UNSPECIFIED(null),
NOOP("-Xbinary=gc=noop"),
STWMS("-Xbinary=gc=stwms"),
@@ -166,7 +166,7 @@ internal enum class GCType(val compilerFlag: String?) {
override fun toString() = compilerFlag?.let { "($it)" }.orEmpty()
}
internal enum class GCScheduler(val compilerFlag: String?) {
enum class GCScheduler(val compilerFlag: String?) {
UNSPECIFIED(null),
MANUAL("-Xbinary=gcSchedulerType=manual"),
ADAPTIVE("-Xbinary=gcSchedulerType=adaptive"),
@@ -180,7 +180,7 @@ internal enum class GCScheduler(val compilerFlag: String?) {
override fun toString() = compilerFlag?.let { "($it)" }.orEmpty()
}
internal enum class Allocator(val compilerFlag: String?) {
enum class Allocator(val compilerFlag: String?) {
UNSPECIFIED(null),
STD("-Xallocator=std"),
MIMALLOC("-Xallocator=mimalloc"),
@@ -206,7 +206,7 @@ internal class Timeouts(val executionTimeout: Duration) {
/**
* Used cache mode.
*/
internal sealed class CacheMode {
sealed class CacheMode {
abstract val staticCacheForDistributionLibrariesRootDir: File?
abstract val useStaticCacheForUserLibraries: Boolean
abstract val makePerFileCaches: Boolean
@@ -283,7 +283,7 @@ internal sealed class CacheMode {
}
}
internal enum class PipelineType(val mutedOption: MutedOption, val compilerFlags: List<String>) {
enum class PipelineType(val mutedOption: MutedOption, val compilerFlags: List<String>) {
DEFAULT(
MutedOption.DEFAULT,
emptyList()
@@ -300,7 +300,7 @@ internal enum class PipelineType(val mutedOption: MutedOption, val compilerFlags
override fun toString() = if (compilerFlags.isEmpty()) "" else compilerFlags.joinToString(prefix = "(", postfix = ")", separator = " ")
}
internal enum class CompilerOutputInterceptor {
enum class CompilerOutputInterceptor {
DEFAULT,
NONE
}
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.konan.test.blackbox.support.util
internal class ArgsBuilder {
class ArgsBuilder {
private val args = mutableListOf<String>()
fun add(vararg args: String) {
@@ -16,15 +16,15 @@ internal class ArgsBuilder {
this.args += args
}
inline fun <T> add(rawArgs: Iterable<T>, transform: (T) -> String) {
fun <T> add(rawArgs: Iterable<T>, transform: (T) -> String) {
rawArgs.mapTo(args) { transform(it) }
}
inline fun <T> addFlattened(rawArgs: Iterable<T>, transform: (T) -> Iterable<String>) {
fun <T> addFlattened(rawArgs: Iterable<T>, transform: (T) -> Iterable<String>) {
rawArgs.flatMapTo(args) { transform(it) }
}
inline fun <T, R> addFlattenedTwice(rawArgs: Iterable<T>, transform1: (T) -> Iterable<R>, transform2: (R) -> String) {
fun <T, R> addFlattenedTwice(rawArgs: Iterable<T>, transform1: (T) -> Iterable<R>, transform2: (R) -> String) {
rawArgs.forEach { add(transform1(it), transform2) }
}
@@ -11,7 +11,7 @@ import java.util.*
internal fun <T> Collection<T>.toIdentitySet(): Set<T> =
Collections.newSetFromMap(IdentityHashMap<T, Boolean>()).apply { addAll(this@toIdentitySet) }
internal class FailOnDuplicatesSet<E : Any> : Set<E> {
class FailOnDuplicatesSet<E : Any> : Set<E> {
private val uniqueElements: MutableSet<E> = hashSetOf()
operator fun plusAssign(element: E) {
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
import java.text.ParseException
import org.jetbrains.kotlin.konan.test.blackbox.support.util.TCTestReportParseState as State
internal class TestReport(
class TestReport(
val passedTests: Collection<TestName>,
val failedTests: Collection<TestName>,
val ignoredTests: Collection<TestName>
@@ -26,7 +26,7 @@ internal class TestReport(
""".trimIndent()
}
internal interface TestOutputFilter {
interface TestOutputFilter {
fun filter(testOutput: String): FilteredOutput
data class FilteredOutput(val filteredOutput: String, val testReport: TestReport?)
+1
View File
@@ -652,6 +652,7 @@ if (buildProperties.inJpsBuildIdeaSync) {
":kotlin-test",
":kotlin-test:kotlin-test-js-it",
":native:native.tests",
":native:native.tests:driver",
":native:native.tests:stress"
project(':kotlin-stdlib-common').projectDir = "$rootDir/libraries/stdlib/common" as File