Skip to content

Commit

Permalink
[K/N][tests] Move driver tests into their own project ^KT-61259
Browse files Browse the repository at this point in the history
  • Loading branch information
projedi authored and Space Team committed Mar 12, 2024
1 parent 316614b commit 8c69667
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 59 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion native/native.tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions native/native.tests/driver/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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.
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<*>>

Expand Down Expand Up @@ -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 {
Expand All @@ -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>,
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -491,7 +491,7 @@ internal class SwiftCompilation<T: TestCompilationArtifact>(
}
}

internal class ExecutableCompilation(
class ExecutableCompilation(
settings: Settings,
freeCompilerArgs: TestCompilerArgs,
sourceModules: Collection<TestModule>,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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)

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>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -50,7 +50,7 @@ internal class TestExecutable(
}
}

internal data class TestRun(
data class TestRun(
val displayName: String,
val executable: TestExecutable,
val runParameters: List<TestRunParameter>,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<*>
Expand Down Expand Up @@ -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)

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
Expand Down

0 comments on commit 8c69667

Please sign in to comment.