From 1d17478e2883278a85a768fce93ce5f934d3b67b Mon Sep 17 00:00:00 2001 From: Ao Li <5557706+aoli-al@users.noreply.github.com> Date: Sun, 1 Dec 2024 11:39:34 -0500 Subject: [PATCH] Create new test class at each iteration. (#69) * Create new test class at each iteration. * Format * Add tests to JUnit plugin. --- build.gradle.kts | 2 +- junit/build.gradle.kts | 24 +++++++++++++++++++++++ junit/src/main/kotlin/FrayTestExecutor.kt | 9 ++++++--- junit/src/test/java/DummyTest.java | 22 +++++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 junit/src/test/java/DummyTest.java diff --git a/build.gradle.kts b/build.gradle.kts index 42881c69..1d5d2a67 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ plugins { allprojects { group = "org.pastalab.fray" - version = "0.1.4-SNAPSHOT" + version = "0.1.6-SNAPSHOT" } repositories { diff --git a/junit/build.gradle.kts b/junit/build.gradle.kts index baaec7d7..b7d20412 100644 --- a/junit/build.gradle.kts +++ b/junit/build.gradle.kts @@ -13,4 +13,28 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1") implementation("org.junit.platform:junit-platform-engine:1.10.3") implementation("org.junit.platform:junit-platform-commons:1.10.3") + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform { + includeEngines("junit-jupiter", "fray") + } + dependsOn(":instrumentation:jdk:build") + val instrumentationTask = evaluationDependsOn(":instrumentation:agent") + .tasks.named("shadowJar").get() + val jdk = project(":instrumentation:jdk") + val jvmti = project(":jvmti") + val instrumentation = instrumentationTask.outputs.files.first().absolutePath + classpath += tasks.named("jar").get().outputs.files + files(configurations.runtimeClasspath) + executable("${jdk.layout.buildDirectory.get().asFile}/java-inst/bin/java") + jvmArgs("-agentpath:${jvmti.layout.buildDirectory.get().asFile}/native-libs/libjvmti.so") + jvmArgs("-javaagent:$instrumentation") + jvmArgs("-ea") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + jvmArgs("--add-opens", "java.base/java.util.concurrent.atomic=ALL-UNNAMED") + jvmArgs("--add-opens", "java.base/java.util=ALL-UNNAMED") + jvmArgs("--add-opens", "java.base/java.io=ALL-UNNAMED") + jvmArgs("--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED") + jvmArgs("--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED") } diff --git a/junit/src/main/kotlin/FrayTestExecutor.kt b/junit/src/main/kotlin/FrayTestExecutor.kt index 7ae5e63a..46570831 100644 --- a/junit/src/main/kotlin/FrayTestExecutor.kt +++ b/junit/src/main/kotlin/FrayTestExecutor.kt @@ -29,14 +29,17 @@ class FrayTestExecutor { fun executeTest(request: ExecutionRequest, descriptor: MethodTestDescriptor) { request.engineExecutionListener.executionStarted(descriptor) - val testInstance = descriptor.parent.testClass.getDeclaredConstructor().newInstance() - val testMethod = descriptor.testMethod val workDir = createTempDirectory(WORK_DIR).absolutePathString() val schedulerInfo = descriptor.getScheduler() val config = Configuration( ExecutionInfo( - LambdaExecutor { testMethod.invoke(testInstance) }, + LambdaExecutor { + val testInstance = + descriptor.parent.testClass.getDeclaredConstructor().newInstance() + val testMethod = descriptor.testMethod + testMethod.invoke(testInstance) + }, false, true, false, diff --git a/junit/src/test/java/DummyTest.java b/junit/src/test/java/DummyTest.java new file mode 100644 index 00000000..65d59600 --- /dev/null +++ b/junit/src/test/java/DummyTest.java @@ -0,0 +1,22 @@ +import org.junit.jupiter.api.Test; +import org.pastalab.fray.junit.annotations.ConcurrencyTest; + +public class DummyTest { + @Test + public void test() { + System.out.println("1"); + } + + @ConcurrencyTest + public void test2() { + System.out.println("2"); + } + + @ConcurrencyTest( + expectedException = AssertionError.class + ) + public void test3() { + assert(false); + } + +}