use of il.ac.bgu.cs.bp.bpjs.model.StringBProgram in project BPjs by bThink-BGU.
the class DfsBProgramVerifierTest method testTwoLoopingBThreads.
@Test(timeout = 2000)
public void testTwoLoopingBThreads() throws Exception {
BProgram bprog = new StringBProgram("bp.registerBThread('bt1', function(){" + " while(true){\n" + " bsync({ request:[ bp.Event(\"STAM1\") ] });\n" + "}});\n" + "bp.registerBThread('bt2', function(){" + " while(true){\n" + " bsync({ request:[ bp.Event(\"STAM2\") ] });\n" + "}});\n" + "");
DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setIterationCountGap(1);
sut.setProgressListener(new BriefPrintDfsVerifierListener());
sut.setDebugMode(true);
VerificationResult res = sut.verify(bprog);
assertFalse(res.isCounterExampleFound());
assertEquals(1, res.getScannedStatesCount());
}
use of il.ac.bgu.cs.bp.bpjs.model.StringBProgram in project BPjs by bThink-BGU.
the class DfsBProgramVerifierTest method testTwoSimpleBThreads.
@Test
public void testTwoSimpleBThreads() throws Exception {
BProgram bprog = new StringBProgram("bp.registerBThread('bt1', function(){bsync({ request:[ bp.Event(\"STAM1\") ] });});" + "bp.registerBThread('bt2', function(){bsync({ request:[ bp.Event(\"STAM2\") ] });});");
DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setIterationCountGap(1);
sut.setProgressListener(new BriefPrintDfsVerifierListener());
sut.setDetectDeadlocks(false);
VerificationResult res = sut.verify(bprog);
assertTrue(res.isVerifiedSuccessfully());
assertEquals(3, res.getScannedStatesCount());
assertEquals(VerificationResult.ViolationType.None, res.getViolationType());
}
use of il.ac.bgu.cs.bp.bpjs.model.StringBProgram in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testEqualityTrue.
@Test
public void testEqualityTrue() throws Exception {
// Generate a continuation
BProgram bprog = new StringBProgram(SRC);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
final BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
// Read frame data
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc);
ContinuationProgramState sut2 = new ContinuationProgramState(nc);
assertTrue(sut1.equals(sut2));
}
use of il.ac.bgu.cs.bp.bpjs.model.StringBProgram in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testInequalityLoop.
@Test
public void testInequalityLoop() throws Exception {
// Generate snapshot 1
BProgram bprog = new StringBProgram(SRC_LOOP_UPDATED_VAR);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc);
assertEquals(1.0, sut1.getVisibleVariables().get("dbl"));
assertEquals("a", sut1.getVisibleVariables().get("str"));
// Generate snapshot 2, pre-loop
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut2 = new ContinuationProgramState(nc);
assertEquals("b", sut2.getVisibleVariables().get("str"));
assertEquals(42.0, sut2.getVisibleVariables().get("dbl"));
// Generate snapshot 3, first loop
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut3 = new ContinuationProgramState(nc);
assertEquals(47.0, sut3.getVisibleVariables().get("dbl"));
assertEquals("ba", sut3.getVisibleVariables().get("str"));
// Generate snapshot 4, second loop
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut4 = new ContinuationProgramState(nc);
assertEquals(52.0, sut4.getVisibleVariables().get("dbl"));
assertEquals("baa", sut4.getVisibleVariables().get("str"));
assertFalse(sut2.equals(sut1));
}
use of il.ac.bgu.cs.bp.bpjs.model.StringBProgram in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testEqualityComplexObj.
@Test
public void testEqualityComplexObj() throws Exception {
// Generate continuation 1
BProgram bprog = new StringBProgram(SRC_WITH_COMPOUND_VARS);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc);
// Generate Continuation 2
bprog = new StringBProgram(SRC_WITH_COMPOUND_VARS);
cur = bprog.setup();
cur = cur.start(exSvc);
snapshot = cur.getBThreadSnapshots().iterator().next();
// Read frame data
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut2 = new ContinuationProgramState(nc);
// sanity
assertTrue(sut1.equals(sut1));
assertTrue(sut1.equals(sut2));
assertTrue(sut2.equals(sut1));
}
Aggregations