use of il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier in project BPjs by bThink-BGU.
the class BProgramSyncSnapshotClonerTest method verifyProgram.
@Test
public void verifyProgram() throws Exception {
DfsBProgramVerifier vfr = new DfsBProgramVerifier();
BProgram bprog = new SingleResourceBProgram("BProgramSyncSnapshotClonerTest.js");
final VerificationResult res = vfr.verify(bprog);
System.out.println("res = " + res.getCounterExampleTrace());
}
use of il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier in project BPjs by bThink-BGU.
the class DiningPhilTest method verifyPhilosophers.
private static VerificationResult verifyPhilosophers(int philosopherCount) throws InterruptedException {
// Create a program
final SingleResourceBProgram bprog = new SingleResourceBProgram("BPJSDiningPhil.js");
bprog.putInGlobalScope("PHILOSOPHER_COUNT", philosopherCount);
try {
DfsBProgramVerifier vfr = new DfsBProgramVerifier();
vfr.setMaxTraceLength(50);
final VerificationResult res = vfr.verify(bprog);
System.out.printf("Scanned %,d states\n", res.getScannedStatesCount());
System.out.printf("Time: %,d milliseconds\n", res.getTimeMillies());
return res;
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
return null;
}
use of il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier in project BPjs by bThink-BGU.
the class StateStorePerformanceComparison method main.
public static void main(String[] args) throws Exception {
if (args.length == 1) {
MAZE_NAME = args[0];
}
// prepare verifier
DfsBProgramVerifier verifier = new DfsBProgramVerifier();
verifier.setDetectDeadlocks(false);
// test
verifier.setVisitedNodeStore(new BProgramStateVisitedStateStore(false));
runVerifier(verifier);
verifier.setVisitedNodeStore(new BProgramStateVisitedStateStore(true));
runVerifier(verifier);
verifier.setVisitedNodeStore(new ForgetfulVisitedStateStore());
runVerifier(verifier);
}
use of il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier 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.analysis.DfsBProgramVerifier in project BPjs by bThink-BGU.
the class Mazes method verify.
public void verify() throws InterruptedException {
SingleResourceBProgram bprog = prepareProgram();
bprog.appendSource(Requirements.eventNotSelected(targetFoundEvent.getName()));
try {
DfsBProgramVerifier vfr = new DfsBProgramVerifier();
vfr.setProgressListener(new BriefPrintDfsVerifierListener());
vfr.setIterationCountGap(10);
vfr.setVisitedNodeStore(new BProgramStateVisitedStateStore(false));
// vfr.setVisitedNodeStore(new ForgetfulVisitedStateStore());
// prevent from detecting cases where we ust hit a wall.
vfr.setDetectDeadlocks(false);
final VerificationResult res = vfr.verify(bprog);
char[][] maze = getMaze(bprog);
printMaze(maze);
if (res.isCounterExampleFound()) {
System.out.println("Found a counterexample");
for (Node nd : res.getCounterExampleTrace()) {
System.out.println(" " + nd.getLastEvent());
if (nd.getLastEvent() != null) {
String name = nd.getLastEvent().getName();
if (name.startsWith("Enter")) {
String loc = name.split("\\(")[1].replace(")", "").trim();
String[] coord = loc.split(",");
int col = Integer.parseInt(coord[0]);
int row = Integer.parseInt(coord[1]);
maze[row][col] = '•';
}
}
}
printMaze(maze);
} 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);
}
}
Aggregations