use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class VerificationResultOptionsTest method testWaitingIsNotDeadlock.
@Test
public void testWaitingIsNotDeadlock() throws Exception {
final SingleResourceBProgram bprog = new SingleResourceBProgram("VerificationResultOptions.js");
bprog.putInGlobalScope("addWaiter", true);
bprog.putInGlobalScope("createDeadlock", false);
bprog.putInGlobalScope("createFailedAssertion", false);
DfsBProgramVerifier vfr = new DfsBProgramVerifier();
final VerificationResult res = vfr.verify(bprog);
assertEquals(VerificationResult.ViolationType.None, res.getViolationType());
assertFalse(res.isCounterExampleFound());
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class VerificationResultOptionsTest method testViolatingProgram.
@Test
public void testViolatingProgram() throws Exception {
final SingleResourceBProgram bprog = new SingleResourceBProgram("VerificationResultOptions.js");
bprog.putInGlobalScope("addWaiter", false);
bprog.putInGlobalScope("createDeadlock", false);
bprog.putInGlobalScope("createFailedAssertion", true);
DfsBProgramVerifier vfr = new DfsBProgramVerifier();
final VerificationResult res = vfr.verify(bprog);
assertEquals(VerificationResult.ViolationType.FailedAssertion, res.getViolationType());
assertTrue(res.isCounterExampleFound());
assertEquals("assertor", res.getFailedAssertion().getBThreadName());
assertEquals("B happened", res.getFailedAssertion().getMessage());
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class BpSyncTests method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("bp-sync.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
assertEquals("hello,world", TestUtils.eventNamesString(eventLogger.getEvents(), ","));
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class ExternalEventsDaemonTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("ExternalEventsDaemon.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
new Thread(() -> {
try {
for (int i = 0; i < 4; i++) {
Thread.sleep(500);
sut.getBProgram().enqueueExternalEvent(new BEvent("ext1"));
}
} catch (InterruptedException ex) {
Logger.getLogger(ExternalEventsDaemonTest.class.getName()).log(Level.SEVERE, null, ex);
}
}).start();
sut.run();
assertTrue(sut.getBProgram().getFromGlobalScope("internalDaemonMode", Boolean.class).get());
eventLogger.getEvents().forEach(e -> System.out.println(e));
final BEvent in1a = new BEvent("in1a");
final BEvent in1b = new BEvent("in1b");
final BEvent ext1 = new BEvent("ext1");
EventPattern expected = new EventPattern().append(ext1).append(in1a).append(in1b).append(ext1).append(in1a).append(in1b).append(ext1).append(in1a).append(in1b);
assertTrue(expected.matches(eventLogger.getEvents()));
}
use of il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram in project BPjs by bThink-BGU.
the class FailedAssertionTest method testAssertion.
@Test
public void testAssertion() throws InterruptedException {
final SingleResourceBProgram bprog = new SingleResourceBProgram("FailedAssertionTest.js");
BProgramRunner sut = new BProgramRunner(bprog);
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
System.out.println("About to start program");
bprog.putInGlobalScope("shouldFail", true);
sut.run();
assertEquals(Arrays.asList("piff", "puff", "poof!"), eventLogger.eventNames());
assertTrue(sut.hasFailedAssertion());
FailedAssertion fa = sut.getFailedAssertion();
assertEquals("assertor", fa.getBThreadName());
assertEquals("Poof has happened.", fa.getMessage());
}
Aggregations