Skip to content

Commit

Permalink
Refactor tests into separate subproject
Browse files Browse the repository at this point in the history
  • Loading branch information
DLochmelis33 committed Jan 22, 2024
1 parent 9798a48 commit a97540d
Show file tree
Hide file tree
Showing 28 changed files with 78 additions and 183 deletions.
2 changes: 2 additions & 0 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ kotlin {
}
jvm {
withJava()
jvmToolchain(8)
}

sourceSets {
commonMain {
dependencies {
implementation(project(":core"))
implementation(project(":testsuite"))
implementation("com.github.ajalt.clikt:clikt:4.2.1")
}
}
Expand Down
16 changes: 13 additions & 3 deletions cli/src/commonMain/kotlin/komem/litmus/CliCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.arguments.transformAll
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.int
import komem.litmus.barriers.BarrierProducer
import komem.litmus.generated.LitmusTestRegistry
import kotlin.time.Duration

Expand Down Expand Up @@ -38,7 +37,7 @@ abstract class CliCommon : CliktCommand(
}
regexes.flatMap { LitmusTestRegistry[it] }.toSet()
}
.check("no tests were selected") { it.isNotEmpty() }
.check("no tests were selected") { it.isNotEmpty() || listOnly }

protected val PARALLELISM_DISABLED = Int.MAX_VALUE - 1
protected val PARALLELISM_AUTO = Int.MAX_VALUE - 2
Expand All @@ -57,10 +56,15 @@ abstract class CliCommon : CliktCommand(
protected abstract val barrierProducer: BarrierProducer
// TODO: we don't talk about memshuffler for now

protected val listOnly by option("-l", "--listOnly").flag()
// TODO: dry run = simply list tests

override fun run() {
echo("selected tests: \n" + tests.joinToString("\n") { " - " + LitmusTestRegistry.resolveName(it) })
if (listOnly) {
runListOnly()
return
}
echo("selected tests: \n" + tests.joinToString("\n") { " - " + it.name })
echo("in total: ${tests.size} tests")
echo()

Expand Down Expand Up @@ -118,6 +122,12 @@ abstract class CliCommon : CliktCommand(
}
}
}

private fun runListOnly() {
echo("all known tests:\n" + LitmusTestRegistry.all().joinToString("\n") { " * " + it.name })
echo()
echo("selected tests:\n" + tests.joinToString("\n") { " - " + it.name })
}
}

fun commonMain(args: Array<String>, cli: CliCommon) {
Expand Down
1 change: 0 additions & 1 deletion cli/src/jvmMain/kotlin/komem/litmus/CliJvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.choice
import jcstressDirectory
import komem.litmus.barriers.JvmSpinBarrier
import komem.litmus.jcstress.JCStressRunner

class CliJvm : CliCommon() {
override val runner by option("-r", "--runner")
Expand Down
5 changes: 3 additions & 2 deletions codegen/src/main/kotlin/komem/litmus/LitmusTestProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class LitmusTestProcessor(val codeGenerator: CodeGenerator) : SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
val basePackage = "komem.litmus"
val registryFileName = "LitmusTestRegistry"
val testsPackage = "$basePackage.tests"

val testFiles = resolver.getAllFiles().filter { it.packageName.asString() == "$basePackage.testsuite" }.toList()
val testFiles = resolver.getAllFiles().filter { it.packageName.asString() == testsPackage }.toList()
val dependencies = Dependencies(true, *testFiles.toTypedArray())

val registryFile = try {
Expand All @@ -26,7 +27,7 @@ class LitmusTestProcessor(val codeGenerator: CodeGenerator) : SymbolProcessor {

val decls = testFiles.flatMap { it.declarations }.filterIsInstance<KSPropertyDeclaration>()
val namedTestsMap = decls.associate {
val relativePackage = it.packageName.asString().removePrefix("$basePackage.testsuite")
val relativePackage = it.packageName.asString().removePrefix(testsPackage)
val testAlias = (if (relativePackage.isEmpty()) "" else "$relativePackage.") +
it.containingFile!!.fileName.removeSuffix(".kt") +
"." + it.simpleName.getShortName()
Expand Down
20 changes: 0 additions & 20 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import org.jetbrains.kotlin.incremental.createDirectory

plugins {
kotlin("multiplatform")
id("com.google.devtools.ksp") version "1.9.20-1.0.13"
`java-library`
}

Expand Down Expand Up @@ -45,19 +44,13 @@ kotlin {
kotlinOptions.freeCompilerArgs = listOf("-Xtemporary-files-dir=${tempDir.absolutePath}")
}
}
binaries {
executable {
entryPoint = "main"
}
}
}
}
sourceSets {
commonMain {
dependencies {
implementation("org.jetbrains.kotlinx:atomicfu:0.20.2")
}
kotlin.srcDir(layout.buildDirectory.dir("generated/ksp/metadata/commonMain/kotlin/")) // ksp
}
commonTest {
dependencies {
Expand Down Expand Up @@ -105,19 +98,6 @@ tasks.register("bitcodeRelease") {
finalizedBy(bitcodeInternal)
}

// ======== ksp ========

dependencies {
add("kspCommonMainMetadata", project(":codegen"))
}

tasks.whenTaskAdded {
if (name == "kspCommonMainKotlinMetadata") {
val kspTask = this
tasks.matching { it.name.startsWith("compileKotlin") }.forEach { it.dependsOn(kspTask) }
}
}

val jcsDir: File get() = File(System.getenv("JCS_DIR") ?: error("JCS_DIR envvar is not set"))

tasks.register<Copy>("copyLibToJCStress") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package komem.litmus.barriers
package komem.litmus

interface Barrier {
fun await()
Expand Down
2 changes: 0 additions & 2 deletions core/src/commonMain/kotlin/komem/litmus/LitmusRunParams.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package komem.litmus

import komem.litmus.barriers.BarrierProducer

data class LitmusRunParams(
val batchSize: Int,
val syncPeriod: Int,
Expand Down
5 changes: 0 additions & 5 deletions core/src/commonMain/kotlin/komem/litmus/LitmusTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package komem.litmus

import komem.litmus.generated.LitmusTestRegistry

data class LitmusTest<S>(
val stateProducer: () -> S,
val threadFunctions: List<S.() -> Unit>,
Expand Down Expand Up @@ -49,6 +47,3 @@ class LitmusTestScope<S>(

fun <S> litmusTest(stateProducer: () -> S, setup: LitmusTestScope<S>.() -> Unit) =
LitmusTestScope(stateProducer).apply(setup).build()

val LitmusTest<*>.name get() = LitmusTestRegistry.resolveName(this)
val LitmusTest<*>.javaClassName get() = name.replace('.', '_')
21 changes: 0 additions & 21 deletions core/src/commonTest/kotlin/komem.litmus/infra/TestDefaults.kt

This file was deleted.

52 changes: 0 additions & 52 deletions core/src/commonTest/kotlin/komem.litmus/testsuite/ClassicTests.kt

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package komem.litmus.barriers

import komem.litmus.Barrier
import java.util.concurrent.CyclicBarrier

class JvmCyclicBarrier(threadCount: Int) : Barrier {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package komem.litmus.barriers

import komem.litmus.Barrier
import java.util.concurrent.atomic.AtomicInteger

class JvmSpinBarrier(private val threadCount: Int) : Barrier {
Expand Down
14 changes: 0 additions & 14 deletions core/src/jvmTest/kotlin/komem/litmus/infra/TestDefaults.jvm.kt

This file was deleted.

1 change: 0 additions & 1 deletion core/src/nativeMain/kotlin/komem.litmus/WorkerRunner.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package komem.litmus

import komem.litmus.barriers.Barrier
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.concurrent.ObsoleteWorkersApi
import kotlin.native.concurrent.TransferMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package komem.litmus.barriers
import barrier.CSpinBarrier
import barrier.barrier_wait
import barrier.create_barrier
import komem.litmus.Barrier
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.ExperimentalForeignApi

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package komem.litmus.barriers

import komem.litmus.Barrier
import kotlin.concurrent.AtomicInt

class KNativeSpinBarrier(private val threadCount: Int) : Barrier {
Expand Down
15 changes: 0 additions & 15 deletions core/src/nativeTest/kotlin/komem/litmus/NativeTest.kt

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions jcstress-wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ application {
mainClass = "MainKt"
}

kotlin {
jvmToolchain(8)
}

dependencies {
implementation(project(":core"))
implementation(project(":testsuite"))
implementation(kotlin("reflect"))
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package komem.litmus.jcstress
package komem.litmus

import komem.litmus.*
import java.nio.file.Path
import kotlin.system.exitProcess

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ include(":core")
include(":codegen")
include(":jcstress-wrapper")
include(":cli")
include(":testsuite")
Loading

0 comments on commit a97540d

Please sign in to comment.