use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class EventsWithDataTest method testEventsWithData.
@Test
public void testEventsWithData() throws Exception {
BProgram bpr = new SingleResourceBProgram("EventsWithData.js", "programName", new SimpleEventSelectionStrategy(99l));
BProgramRunner rnr = new BProgramRunner(bpr);
rnr.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener events = rnr.addListener(new InMemoryEventLoggingListener());
rnr.run();
assertEquals(Arrays.asList("e1", "e2", "e1e2"), events.getEvents().stream().map(BEvent::getName).collect(toList()));
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram in project BPjs by bThink-BGU.
the class TicTacToeVerMain method main.
public static void main(String[] args) throws InterruptedException {
// Create a program
BProgram bprog = new SingleResourceBProgram("BPJSTicTacToe.js");
bprog.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
bprog.setDaemonMode(true);
String simulatedPlayer = "bp.registerBThread('XMoves', function() {\n" + "while (true) {\n" + "bsync({ request:[ X(0, 0), X(0, 1), X(0, 2), X(1, 0), \n" + "X(1, 1), X(1, 2), X(2, 0), X(2, 1), X(2, 2) ] }, 10); \n" + "}\n" + "});\n";
// This bthread models the requirement that X never wins.
String xCantWinRequirementBThread = "bp.registerBThread( \"req:NoXWin\", function(){\n" + " bp.sync({waitFor:StaticEvents.XWin});\n" + " bp.ASSERT(false, \"Found a trace where X wins.\");\n" + "});";
bprog.appendSource(simulatedPlayer);
bprog.appendSource(xCantWinRequirementBThread);
// bprog.appendSource(infiBThread);
try {
DfsBProgramVerifier vfr = new DfsBProgramVerifier();
vfr.setDetectDeadlocks(false);
vfr.setMaxTraceLength(70);
// vfr.setDebugMode(true);
vfr.setVisitedNodeStore(new BProgramStateVisitedStateStore(false));
vfr.setProgressListener(new BriefPrintDfsVerifierListener());
final VerificationResult res = vfr.verify(bprog);
if (res.isCounterExampleFound()) {
System.out.println("Found a counterexample");
res.getCounterExampleTrace().forEach(nd -> System.out.println(" " + nd.getLastEvent()));
} else {
System.out.println("No counterexample found.");
}
System.out.printf("Scanned %,d states\n", res.getScannedStatesCount());
System.out.printf("Time: %,d milliseconds\n", res.getTimeMillies());
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
System.out.println("end of run");
}
use of il.ac.bgu.cs.bp.bpjs.model.BProgram 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.BProgram 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.BProgram 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