-
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.
- Loading branch information
Showing
8 changed files
with
117 additions
and
6 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
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
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
45 changes: 45 additions & 0 deletions
45
core/src/test/java/org/pastalab/fray/core/test/FrayRunner.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,45 @@ | ||
package org.pastalab.fray.core.test; | ||
|
||
import kotlin.Unit; | ||
import kotlin.jvm.functions.Function0; | ||
import org.pastalab.fray.core.TestRunner; | ||
import org.pastalab.fray.core.command.Configuration; | ||
import org.pastalab.fray.core.command.ExecutionInfo; | ||
import org.pastalab.fray.core.command.LambdaExecutor; | ||
import org.pastalab.fray.core.randomness.ControlledRandom; | ||
import org.pastalab.fray.core.scheduler.FifoScheduler; | ||
import org.pastalab.fray.core.scheduler.Scheduler; | ||
|
||
|
||
public class FrayRunner { | ||
public Throwable runTest(Function0<Unit> exec) { | ||
return runTest(exec, new FifoScheduler(), 1); | ||
} | ||
|
||
public Throwable runTest(Function0<Unit> exec, Scheduler scheduler, int iter) { | ||
String testName = this.getClass().getSimpleName(); | ||
Configuration config = new Configuration( | ||
new ExecutionInfo( | ||
new LambdaExecutor(() -> { | ||
exec.invoke(); | ||
return null; | ||
}), | ||
false, | ||
true, | ||
false, | ||
10000 | ||
), | ||
"/tmp/report", | ||
iter, | ||
scheduler, | ||
new ControlledRandom(), | ||
true, | ||
false, | ||
true, | ||
false, | ||
false | ||
); | ||
TestRunner runner = new TestRunner(config); | ||
return runner.run(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
core/src/test/java/org/pastalab/fray/core/test/primitives/WaitTest.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.core.test.primitives; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.pastalab.fray.core.test.FrayRunner; | ||
import org.pastalab.fray.runtime.DeadlockException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class WaitTest extends FrayRunner { | ||
|
||
@Test | ||
public void testWaitWithoutMonitorLock() { | ||
Throwable result = runTest(() -> { | ||
try { | ||
wait(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return null; | ||
}); | ||
assertTrue(result instanceof IllegalMonitorStateException); | ||
} | ||
|
||
@Test | ||
public void testWaitWithMonitorLock() { | ||
Throwable result = runTest(() -> { | ||
try { | ||
synchronized (this) { | ||
wait(); | ||
} | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return null; | ||
}); | ||
assertTrue(result instanceof DeadlockException); | ||
} | ||
} |
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