use of il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy 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.eventselection.PrioritizedBSyncEventSelectionStrategy in project BPjs by bThink-BGU.
the class StatementsWithDataTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
SingleResourceBProgram bprog = new SingleResourceBProgram("StatementsWithData.js");
BProgramRunner sut = new BProgramRunner();
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.setBProgram(bprog);
sut.getBProgram().setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
sut.addListener(new BProgramRunnerListenerAdapter() {
});
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
EventPattern expected = new EventPattern().append(new BEvent("1")).append(new BEvent("2")).append(new BEvent("3"));
assertTrue(expected.matches(eventLogger.getEvents()));
}
use of il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy in project BPjs by bThink-BGU.
the class TTTButton 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);
JFrame f = new TicTacToeGameMain();
BProgramRunner rnr = new BProgramRunner(bprog);
rnr.addListener(new PrintBProgramRunnerListener());
TTTdisplayGame = new TTTDisplayGame(bprog, rnr);
rnr.run();
System.out.println("end of run");
}
use of il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy in project BPjs by bThink-BGU.
the class BSyncDataPassingTest method priorityDataTest_noBlocking.
@Test
public void priorityDataTest_noBlocking() {
BProgram bp = new SingleResourceBProgram("BSyncDataPassingTest.js");
bp.putInGlobalScope("block30", false);
bp.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
BProgramRunner rnr = new BProgramRunner(bp);
InMemoryEventLoggingListener eventsLogger = rnr.addListener(new InMemoryEventLoggingListener());
rnr.addListener(new PrintBProgramRunnerListener());
rnr.run();
assertEquals(Arrays.asList("p30", "p20", "p10", "p3", "p2", "p1"), eventsLogger.eventNames());
}
use of il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy in project BPjs by bThink-BGU.
the class BSyncDataPassingTest method priorityDataTest_blocking.
@Test
public void priorityDataTest_blocking() {
BProgram bp = new SingleResourceBProgram("BSyncDataPassingTest.js");
bp.putInGlobalScope("block30", true);
bp.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy(17));
BProgramRunner rnr = new BProgramRunner(bp);
InMemoryEventLoggingListener eventsLogger = rnr.addListener(new InMemoryEventLoggingListener());
rnr.addListener(new PrintBProgramRunnerListener());
rnr.run();
assertEquals(Arrays.asList("p20", "p10", "p3", "p2", "p1"), eventsLogger.eventNames());
}
Aggregations