From 8c799c6d5702db15ed26f1e133ba246ac4a2b673 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Wed, 26 Jun 2024 17:41:43 +0200 Subject: [PATCH 1/8] Add basic CI --- .github/workflows/run-litmus.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/run-litmus.yml diff --git a/.github/workflows/run-litmus.yml b/.github/workflows/run-litmus.yml new file mode 100644 index 0000000..7f2301c --- /dev/null +++ b/.github/workflows/run-litmus.yml @@ -0,0 +1,39 @@ +name: Run litmus tests on different platforms + +on: + push: + branches: + - dev-gh-ci + - development + - main + +jobs: + linux-run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v4 + with: + java-version: 17 + - run: chmod +x gradlew + - name: Assemble CLI binary + run: ./gradlew cli:linkReleaseExecutableLinuxX64 + - name: Run litmus tests via CLI + run: ./cli/build/bin/linuxX64/releaseExecutable/cli.kexe -r pthread ".*" + + macos-run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v4 + with: + java-version: 17 + - run: chmod +x gradlew + - name: Assemble CLI binary (x64) + run: ./gradlew cli:linkReleaseExecutableMacosX64 + - name: Run litmus tests via CLI (x64) + run: ./cli/build/bin/macosX64/releaseExecutable/cli.kexe -r pthread ".*" + - name: Assemble CLI binary (arm) + run: ./gradlew cli:linkReleaseExecutableMacosArm64 + - name: Run litmus tests via CLI (arm) + run: ./cli/build/bin/macosArm64/releaseExecutable/cli.kexe -r pthread ".*" From 3e4eb49fbb648f604b21de199af53becfd4fd601 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Wed, 26 Jun 2024 17:44:20 +0200 Subject: [PATCH 2/8] Fix 1 --- .github/workflows/run-litmus.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-litmus.yml b/.github/workflows/run-litmus.yml index 7f2301c..cd7f9fc 100644 --- a/.github/workflows/run-litmus.yml +++ b/.github/workflows/run-litmus.yml @@ -14,6 +14,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-java@v4 with: + distribution: oracle java-version: 17 - run: chmod +x gradlew - name: Assemble CLI binary From c82e4e1a964295670adb276f4caca0780be45fb1 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Wed, 26 Jun 2024 17:49:37 +0200 Subject: [PATCH 3/8] Fix 2 + add jcstress run to CI --- .github/workflows/run-litmus.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/run-litmus.yml b/.github/workflows/run-litmus.yml index cd7f9fc..57598e1 100644 --- a/.github/workflows/run-litmus.yml +++ b/.github/workflows/run-litmus.yml @@ -21,6 +21,8 @@ jobs: run: ./gradlew cli:linkReleaseExecutableLinuxX64 - name: Run litmus tests via CLI run: ./cli/build/bin/linuxX64/releaseExecutable/cli.kexe -r pthread ".*" + - name: Run a single test with JCStress + run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" macos-run: runs-on: ubuntu-latest @@ -28,13 +30,17 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-java@v4 with: + distribution: oracle java-version: 17 - run: chmod +x gradlew - name: Assemble CLI binary (x64) run: ./gradlew cli:linkReleaseExecutableMacosX64 - name: Run litmus tests via CLI (x64) run: ./cli/build/bin/macosX64/releaseExecutable/cli.kexe -r pthread ".*" + - name: Run a single test with JCStress + run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" - name: Assemble CLI binary (arm) run: ./gradlew cli:linkReleaseExecutableMacosArm64 - name: Run litmus tests via CLI (arm) run: ./cli/build/bin/macosArm64/releaseExecutable/cli.kexe -r pthread ".*" + From a7ea1ddff7a846ce599d5b3816588799fa33ed68 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Thu, 4 Jul 2024 14:54:54 +0200 Subject: [PATCH 4/8] Fix 3 --- .github/workflows/run-litmus.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-litmus.yml b/.github/workflows/run-litmus.yml index 57598e1..c05fa89 100644 --- a/.github/workflows/run-litmus.yml +++ b/.github/workflows/run-litmus.yml @@ -25,7 +25,7 @@ jobs: run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" macos-run: - runs-on: ubuntu-latest + runs-on: macos-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-java@v4 @@ -33,14 +33,16 @@ jobs: distribution: oracle java-version: 17 - run: chmod +x gradlew - - name: Assemble CLI binary (x64) - run: ./gradlew cli:linkReleaseExecutableMacosX64 - - name: Run litmus tests via CLI (x64) + - name: Assemble all CLI artifacts + run: ./gradlew cli:assemble + - name: Run litmus tests via CLI (x64 + debug) + run: ./cli/build/bin/macosX64/debugExecutable/cli.kexe -r pthread ".*" + - name: Run litmus tests via CLI (x64 + release) run: ./cli/build/bin/macosX64/releaseExecutable/cli.kexe -r pthread ".*" - name: Run a single test with JCStress run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" - - name: Assemble CLI binary (arm) - run: ./gradlew cli:linkReleaseExecutableMacosArm64 - - name: Run litmus tests via CLI (arm) + - name: Run litmus tests via CLI (arm + debug) + run: ./cli/build/bin/macosArm64/debugExecutable/cli.kexe -r pthread ".*" + - name: Run litmus tests via CLI (arm + release) run: ./cli/build/bin/macosArm64/releaseExecutable/cli.kexe -r pthread ".*" From cbc23b3c20559afeb1b80f01cc70d19df5731e7e Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Sun, 7 Jul 2024 18:42:01 +0200 Subject: [PATCH 5/8] Fix 4 + fix bug in printing jcstress results --- .github/workflows/run-litmus.yml | 13 +++++-------- .../jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt | 9 +++++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/run-litmus.yml b/.github/workflows/run-litmus.yml index c05fa89..bb8923c 100644 --- a/.github/workflows/run-litmus.yml +++ b/.github/workflows/run-litmus.yml @@ -33,16 +33,13 @@ jobs: distribution: oracle java-version: 17 - run: chmod +x gradlew - - name: Assemble all CLI artifacts - run: ./gradlew cli:assemble - - name: Run litmus tests via CLI (x64 + debug) - run: ./cli/build/bin/macosX64/debugExecutable/cli.kexe -r pthread ".*" + - name: Assemble CLI binary (x64 + release) + run: ./gradlew cli:linkReleaseExecutableMacosX64 - name: Run litmus tests via CLI (x64 + release) run: ./cli/build/bin/macosX64/releaseExecutable/cli.kexe -r pthread ".*" - name: Run a single test with JCStress - run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" - - name: Run litmus tests via CLI (arm + debug) - run: ./cli/build/bin/macosArm64/debugExecutable/cli.kexe -r pthread ".*" + run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' .*" + - name: Assemble CLI binary (arm + release) + run: ./gradlew cli:linkReleaseExecutableMacosArm64 - name: Run litmus tests via CLI (arm + release) run: ./cli/build/bin/macosArm64/releaseExecutable/cli.kexe -r pthread ".*" - diff --git a/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt b/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt index fd4efce..3862138 100644 --- a/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt +++ b/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt @@ -79,8 +79,13 @@ class CliJvm : CliCommon() { ) JCStressRunner.DEFAULT_LITMUSKT_PARAMS else params // jcstress defaults are different val jcsRunner = runner as JCStressRunner // use the correct runTests()! - val results = jcsRunner.runTests(tests, jcsParams).first() - echo("\n" + results.generateTable()) + val results = jcsRunner.runTests(tests, jcsParams) + + echo() + (tests zip results).forEach { (test, result) -> + echo("results for ${test.alias}:") + echo(result.generateTable() + "\n") + } } } } From 29cfa94dd85b4695673f860ee35256be44782b51 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Sun, 7 Jul 2024 18:59:27 +0200 Subject: [PATCH 6/8] Fix 4 + fix bug in parsing jcstress results --- .github/workflows/run-litmus.yml | 2 +- cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt | 6 +++++- .../main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run-litmus.yml b/.github/workflows/run-litmus.yml index bb8923c..e1f5965 100644 --- a/.github/workflows/run-litmus.yml +++ b/.github/workflows/run-litmus.yml @@ -38,7 +38,7 @@ jobs: - name: Run litmus tests via CLI (x64 + release) run: ./cli/build/bin/macosX64/releaseExecutable/cli.kexe -r pthread ".*" - name: Run a single test with JCStress - run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' .*" + run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" - name: Assemble CLI binary (arm + release) run: ./gradlew cli:linkReleaseExecutableMacosArm64 - name: Run litmus tests via CLI (arm + release) diff --git a/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt b/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt index 3862138..1c16614 100644 --- a/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt +++ b/cli/src/jvmMain/kotlin/org/jetbrains/litmuskt/CliJvm.kt @@ -82,7 +82,11 @@ class CliJvm : CliCommon() { val results = jcsRunner.runTests(tests, jcsParams) echo() - (tests zip results).forEach { (test, result) -> + if (results.isEmpty()) { + echo("no tests were run, perhaps they are missing jcstress wrappers?", err = true) + return + } + results.forEach { (test, result) -> echo("results for ${test.alias}:") echo(result.generateTable() + "\n") } diff --git a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt index 1c286b2..4395c7b 100644 --- a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt +++ b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt @@ -41,7 +41,7 @@ class JCStressRunner( internal fun startTests( tests: List>, params: LitmusRunParams - ): () -> List { + ): () -> Map, LitmusResult> { val mvn = ProcessBuilder("mvn", "install", "verify", "-U") .directory(jcstressDirectory.toFile()) .redirectOutput(ProcessBuilder.Redirect.INHERIT) @@ -71,13 +71,13 @@ class JCStressRunner( return handle@{ jcs.waitFor() if (jcs.exitValue() != 0) error("jcstress exited with code ${jcs.exitValue()}") - return@handle tests.map { test -> parseJCStressResults(test) } + return@handle tests.associateWith { test -> parseJCStressResults(test) } } } override fun startTest(test: LitmusTest, params: LitmusRunParams): () -> LitmusResult { val handle = startTests(listOf(test), params) - return { handle().first() } + return { handle()[test] ?: error("test $test did not produce a result; perhaps its wrapper is missing?") } } /** @@ -142,7 +142,7 @@ class JCStressRunner( fun JCStressRunner.runTests( tests: List>, params: LitmusRunParams, -): List = startTests(tests, params).invoke() +): Map, LitmusResult> = startTests(tests, params).invoke() /** * Split a sequence into two: one with the first [size] elements and one with the rest. From d8dd41f91679f23a1b57fd6b8b5168c8efde3919 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Sun, 4 Aug 2024 18:27:57 +0200 Subject: [PATCH 7/8] Add comment, fix jcstress result collection bug, run all tests with jcstress --- .github/workflows/run-litmus.yml | 13 +++++++++---- .../kotlin/org/jetbrains/litmuskt/JCStressRunner.kt | 9 +++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run-litmus.yml b/.github/workflows/run-litmus.yml index e1f5965..63483bd 100644 --- a/.github/workflows/run-litmus.yml +++ b/.github/workflows/run-litmus.yml @@ -7,6 +7,9 @@ on: - development - main +# Note: this CI run is an "integration"-test or "smoke"-test. It is intended to verify that +# the basics of the tool work. It is NOT intended to be complete or to discover weak behaviors. + jobs: linux-run: runs-on: ubuntu-latest @@ -21,8 +24,9 @@ jobs: run: ./gradlew cli:linkReleaseExecutableLinuxX64 - name: Run litmus tests via CLI run: ./cli/build/bin/linuxX64/releaseExecutable/cli.kexe -r pthread ".*" - - name: Run a single test with JCStress - run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" + - name: Run litmus tests with JCStress + # takes ~10 mins + run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m sanity' .*" macos-run: runs-on: macos-latest @@ -37,8 +41,9 @@ jobs: run: ./gradlew cli:linkReleaseExecutableMacosX64 - name: Run litmus tests via CLI (x64 + release) run: ./cli/build/bin/macosX64/releaseExecutable/cli.kexe -r pthread ".*" - - name: Run a single test with JCStress - run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m quick' StoreBuffering.Plain" + - name: Run litmus tests with JCStress + # takes ~10 mins + run: ./gradlew :cli:jvmRun --args="-r jcstress -j '-m sanity' .*" - name: Assemble CLI binary (arm + release) run: ./gradlew cli:linkReleaseExecutableMacosArm64 - name: Run litmus tests via CLI (arm + release) diff --git a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt index 4395c7b..2f0f731 100644 --- a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt +++ b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt @@ -71,7 +71,11 @@ class JCStressRunner( return handle@{ jcs.waitFor() if (jcs.exitValue() != 0) error("jcstress exited with code ${jcs.exitValue()}") - return@handle tests.associateWith { test -> parseJCStressResults(test) } + // not all tests might have generated wrappers + return@handle tests + .associateWith { test -> parseJCStressResults(test) } + .filterValues { it != null } + .mapValues { (_, result) -> result!! } // remove nullable type } } @@ -100,8 +104,9 @@ class JCStressRunner( * <-- these lines repeat per each configuration, so the results are summed in the end * ... */ - private fun parseJCStressResults(test: LitmusTest<*>): LitmusResult { + private fun parseJCStressResults(test: LitmusTest<*>): LitmusResult? { val resultsFile = jcstressDirectory / "results" / "${test.javaFQN}.html" + if (Files.notExists(resultsFile)) return null var lines = Files.lines(resultsFile).asSequence() val allOutcomes = test.outcomeSpec.all From e6fbc8f88ddbb0288fb6088e36a8190d92078486 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Sun, 4 Aug 2024 20:26:46 +0200 Subject: [PATCH 8/8] Fix jcstress result not parsing default outcome (add parseOutcome() to LitmusAutoOutcome) --- .../autooutcomes/BooleanAutoOutcomes.kt | 10 ++++++++- .../litmuskt/autooutcomes/IntAutoOutcomes.kt | 16 ++++++++++++++ .../autooutcomes/LitmusAutoOutcome.kt | 1 + .../litmuskt/autooutcomes/LongAutoOutcomes.kt | 16 ++++++++++++++ .../kotlin/org/jetbrains/litmuskt/Codegen.kt | 21 +++++++++++-------- .../org/jetbrains/litmuskt/JCStressRunner.kt | 7 +++---- 6 files changed, 57 insertions(+), 14 deletions(-) diff --git a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/BooleanAutoOutcomes.kt b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/BooleanAutoOutcomes.kt index 4f1f83f..3ba985c 100644 --- a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/BooleanAutoOutcomes.kt +++ b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/BooleanAutoOutcomes.kt @@ -2,7 +2,11 @@ package org.jetbrains.litmuskt.autooutcomes import org.jetbrains.litmuskt.LitmusOutcomeSpecScope -// TODO +/** + * "Z" is the name for Boolean outcomes in JCStress. + */ + +// TODO: codegen open class LitmusZZOutcome( var r1: Boolean = false, @@ -16,6 +20,10 @@ open class LitmusZZOutcome( } final override fun toList() = listOf(r1, r2) + final override fun parseOutcome(str: String): LitmusZZOutcome { + val rs = str.split(", ").map(String::toBooleanStrict) + return LitmusZZOutcome(rs[0], rs[1]) + } } fun LitmusOutcomeSpecScope.accept(r1: Boolean, r2: Boolean) = diff --git a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/IntAutoOutcomes.kt b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/IntAutoOutcomes.kt index 9ecd149..2eda0e8 100644 --- a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/IntAutoOutcomes.kt +++ b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/IntAutoOutcomes.kt @@ -13,6 +13,10 @@ open class LitmusIOutcome( } final override fun toList() = listOf(r1) + final override fun parseOutcome(str: String): LitmusIOutcome { + val rs = str.split(", ").map(String::toInt) + return LitmusIOutcome(rs[0]) + } } fun LitmusOutcomeSpecScope.accept(r1: Int) = @@ -36,6 +40,10 @@ open class LitmusIIOutcome( } final override fun toList() = listOf(r1, r2) + final override fun parseOutcome(str: String): LitmusIIOutcome { + val rs = str.split(", ").map(String::toInt) + return LitmusIIOutcome(rs[0], rs[1]) + } } fun LitmusOutcomeSpecScope.accept(r1: Int, r2: Int) = @@ -60,6 +68,10 @@ open class LitmusIIIOutcome( } final override fun toList() = listOf(r1, r2, r3) + final override fun parseOutcome(str: String): LitmusIIIOutcome { + val rs = str.split(", ").map(String::toInt) + return LitmusIIIOutcome(rs[0], rs[1], rs[2]) + } } fun LitmusOutcomeSpecScope.accept(r1: Int, r2: Int, r3: Int) = @@ -85,6 +97,10 @@ open class LitmusIIIIOutcome( } final override fun toList() = listOf(r1, r2, r3, r4) + final override fun parseOutcome(str: String): LitmusIIIIOutcome { + val rs = str.split(", ").map(String::toInt) + return LitmusIIIIOutcome(rs[0], rs[1], rs[2], rs[3]) + } } fun LitmusOutcomeSpecScope.accept(r1: Int, r2: Int, r3: Int, r4: Int) = diff --git a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LitmusAutoOutcome.kt b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LitmusAutoOutcome.kt index ce26e27..0b10855 100644 --- a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LitmusAutoOutcome.kt +++ b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LitmusAutoOutcome.kt @@ -25,5 +25,6 @@ sealed interface LitmusAutoOutcome { // for JCStress interop fun toList(): List + fun parseOutcome(str: String): LitmusAutoOutcome } diff --git a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LongAutoOutcomes.kt b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LongAutoOutcomes.kt index 4d5e759..fb1e7ac 100644 --- a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LongAutoOutcomes.kt +++ b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/autooutcomes/LongAutoOutcomes.kt @@ -13,6 +13,10 @@ open class LitmusLOutcome( } final override fun toList() = listOf(r1) + final override fun parseOutcome(str: String): LitmusLOutcome { + val rs = str.split(", ").map(String::toLong) + return LitmusLOutcome(rs[0]) + } } fun LitmusOutcomeSpecScope.accept(r1: Long) = @@ -36,6 +40,10 @@ open class LitmusLLOutcome( } final override fun toList() = listOf(r1, r2) + final override fun parseOutcome(str: String): LitmusLLOutcome { + val rs = str.split(", ").map(String::toLong) + return LitmusLLOutcome(rs[0], rs[1]) + } } fun LitmusOutcomeSpecScope.accept(r1: Long, r2: Long) = @@ -60,6 +68,10 @@ open class LitmusLLLOutcome( } final override fun toList() = listOf(r1, r2, r3) + final override fun parseOutcome(str: String): LitmusLLLOutcome { + val rs = str.split(", ").map(String::toLong) + return LitmusLLLOutcome(rs[0], rs[1], rs[2]) + } } fun LitmusOutcomeSpecScope.accept(r1: Long, r2: Long, r3: Long) = @@ -85,6 +97,10 @@ open class LitmusLLLLOutcome( } final override fun toList() = listOf(r1, r2, r3, r4) + final override fun parseOutcome(str: String): LitmusLLLLOutcome { + val rs = str.split(", ").map(String::toLong) + return LitmusLLLLOutcome(rs[0], rs[1], rs[2], rs[3]) + } } fun LitmusOutcomeSpecScope.accept(r1: Long, r2: Long, r3: Long, r4: Long) = diff --git a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/Codegen.kt b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/Codegen.kt index 79ce4fa..6f035ee 100644 --- a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/Codegen.kt +++ b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/Codegen.kt @@ -19,7 +19,7 @@ fun generateWrapperFile(test: LitmusTest<*>, generatedSrc: Path): Boolean { val targetCode = try { generateWrapperCode(test) } catch (e: Throwable) { - System.err.println("WARNING: could not generate wrapper for ${test.alias} because: ${e.message}") + System.err.println("WARNING: could not generate wrapper for ${test.alias} because:\n" + e.stackTraceToString()) return false } targetFile.writeText(targetCode) @@ -37,12 +37,15 @@ private fun generateWrapperCode(test: LitmusTest<*>): String { val outcomeTypeName = autoOutcomeClassList.first().simpleName!! .removePrefix("Litmus") .removeSuffix("Outcome") - val (outcomeVarType, outcomeVarCount) = when (outcomeTypeName) { - "I" -> "Integer" to 1 - "II" -> "Integer" to 2 - "III" -> "Integer" to 3 - "IIII" -> "Integer" to 4 - else -> error("unknown AutoOutcome type $outcomeTypeName") + + val outcomeVarTypes = outcomeTypeName.map { c -> + when (c) { + 'I' -> "Integer" + 'L' -> "Long" + 'Z' -> "Boolean" + // TODO: add others once they are created + else -> error("unrecognized outcome type '$c'") + } } val javaTestGetter: String = run { @@ -56,8 +59,8 @@ private fun generateWrapperCode(test: LitmusTest<*>): String { """ @Arbiter public void a($jcstressResultClassName r) { - List<$outcomeVarType> result = (List<$outcomeVarType>) (Object) ((LitmusAutoOutcome) fA.invoke(state)).toList(); - ${List(outcomeVarCount) { "r.r${it + 1} = result.get($it);" }.joinToString("\n ")} + List result = (List) (Object) ((LitmusAutoOutcome) fA.invoke(state)).toList(); + ${List(outcomeVarTypes.size) { "r.r${it + 1} = (${outcomeVarTypes[it]}) result.get($it);" }.joinToString("\n ")} } """.trim() } diff --git a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt index 2f0f731..83a7f48 100644 --- a/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt +++ b/jcstress-wrapper/src/main/kotlin/org/jetbrains/litmuskt/JCStressRunner.kt @@ -1,5 +1,6 @@ package org.jetbrains.litmuskt +import org.jetbrains.litmuskt.autooutcomes.LitmusAutoOutcome import org.jetbrains.litmuskt.barriers.JvmCyclicBarrier import java.nio.file.Files import java.nio.file.Path @@ -109,9 +110,6 @@ class JCStressRunner( if (Files.notExists(resultsFile)) return null var lines = Files.lines(resultsFile).asSequence() - val allOutcomes = test.outcomeSpec.all - val outcomeStrings = allOutcomes.associateBy { it.toString().trim('(', ')') } - // get the number of observed outcomes lines = lines.dropWhile { !it.contains("Observed States") } val observedOutcomesLine = lines.splitFirst().let { (first, rest) -> lines = rest; first } @@ -120,9 +118,10 @@ class JCStressRunner( // skip to with outcomes lines = lines.drop(3) val linesOutcomes = lines.splitTake(observedSize).let { (first, rest) -> lines = rest; first } + val outcomeParser = test.stateProducer() as LitmusAutoOutcome val outcomesOrdered = linesOutcomes.map { val outcomeString = parseElementData(it) - outcomeStrings[outcomeString] ?: error("unrecognized outcome: $outcomeString") + outcomeParser.parseOutcome(outcomeString) }.toList() // lines with "bgColor" and "width" are the only ones with data