-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test framework (#44)
* Create feature test module. * Add integration tests.
- Loading branch information
Showing
15 changed files
with
342 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
core/src/test/java/org/pastalab/fray/core/test/primitives/IntStreamTest.java
This file was deleted.
Oops, something went wrong.
135 changes: 0 additions & 135 deletions
135
core/src/test/java/org/pastalab/fray/core/test/primitives/WaitTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
group = "org.pastalab.fray.test" | ||
version = "0.1.4-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation(platform("org.junit:junit-bom:5.10.0")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
testImplementation(project(":core")) | ||
testImplementation("io.github.classgraph:classgraph:4.8.177") | ||
testCompileOnly(project(":runtime")) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
val jvmti = project(":jvmti") | ||
val jdk = project(":instrumentation:jdk") | ||
val agent = project(":instrumentation:agent") | ||
executable("${jdk.layout.buildDirectory.get().asFile}/java-inst/bin/java") | ||
jvmArgs("-agentpath:${jvmti.layout.buildDirectory.get().asFile}/native-libs/libjvmti.so") | ||
jvmArgs("-javaagent:${agent.layout.buildDirectory.get().asFile}/libs/" + | ||
"${agent.name}-${agent.version}-shadow.jar") | ||
jvmArgs("-Dfray.debug=true") | ||
dependsOn(":instrumentation:jdk:build") | ||
dependsOn(":instrumentation:agent:build") | ||
dependsOn(":jvmti:build") | ||
} |
22 changes: 22 additions & 0 deletions
22
integration-test/src/main/java/org/pastalab/fray/test/ExpectedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.pastalab.fray.test; | ||
|
||
public class ExpectedException extends RuntimeException { | ||
public ExpectedException() { | ||
} | ||
|
||
public ExpectedException(String message) { | ||
super(message); | ||
} | ||
|
||
public ExpectedException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ExpectedException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ExpectedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
integration-test/src/main/java/org/pastalab/fray/test/fail/wait/IntStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.pastalab.fray.test.fail.wait; | ||
|
||
import org.pastalab.fray.test.ExpectedException; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class IntStream { | ||
public static void main(String[] args) { | ||
AtomicInteger x = new AtomicInteger(); | ||
java.util.stream.IntStream.range(1, 10).parallel().forEach((i) -> x.compareAndSet(i-1, i+1)); | ||
if (x.get() != 10) { | ||
throw new ExpectedException("x (" + x.get() + ") is not 10"); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
integration-test/src/main/java/org/pastalab/fray/test/fail/wait/NotifyOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.pastalab.fray.test.fail.wait; | ||
|
||
import org.pastalab.fray.test.ExpectedException; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class NotifyOrder { | ||
public static void notifyOrder() throws InterruptedException { | ||
Object o = new Object(); | ||
CountDownLatch latch = new CountDownLatch(2); | ||
AtomicBoolean flag = new AtomicBoolean(false); | ||
AtomicBoolean notifyFlag = new AtomicBoolean(false); | ||
AtomicBoolean bugFound = new AtomicBoolean(false); | ||
Thread t1 = new Thread(() -> { | ||
synchronized (o) { | ||
try { | ||
latch.countDown(); | ||
while (!notifyFlag.get()) { | ||
o.wait(); | ||
} | ||
flag.set(true); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}); | ||
Thread t2 = new Thread(() -> { | ||
synchronized (o) { | ||
try { | ||
latch.countDown(); | ||
while (!notifyFlag.get()) { | ||
o.wait(); | ||
} | ||
if (!flag.get()) { | ||
bugFound.set(true); | ||
} | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}); | ||
t1.start(); | ||
t2.start(); | ||
latch.await(); | ||
synchronized (o) { | ||
notifyFlag.set(true); | ||
o.notifyAll(); | ||
} | ||
t1.join(); | ||
t2.join(); | ||
if (bugFound.get()) { | ||
throw new ExpectedException("notify order bug found"); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
notifyOrder(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
integration-test/src/main/java/org/pastalab/fray/test/fail/wait/WaitSpuriousWakeup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.pastalab.fray.test.fail.wait; | ||
|
||
import org.pastalab.fray.test.ExpectedException; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class WaitSpuriousWakeup { | ||
public static void main(String[] args) { | ||
Object o = new Object(); | ||
CountDownLatch latch = new CountDownLatch(1); | ||
AtomicBoolean flag = new AtomicBoolean(false); | ||
Thread t = new Thread(() -> { | ||
synchronized (o) { | ||
try { | ||
latch.countDown(); | ||
o.wait(); | ||
flag.set(true); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
|
||
t.start(); | ||
try { | ||
latch.await(); // Wait for the thread to start | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
synchronized (o) { | ||
// Flag can be set before notify is called due to spurious wake up | ||
if (flag.get()) { | ||
throw new ExpectedException("Spurious wakeup bug found"); | ||
} | ||
o.notify(); | ||
} | ||
} | ||
} |
Oops, something went wrong.