use of il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult 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);
}
}
use of il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult 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.analysis.VerificationResult 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.analysis.VerificationResult in project BPjs by bThink-BGU.
the class VerificationResultOptionsTest method testDeadlockedProgram.
@Test
public void testDeadlockedProgram() throws Exception {
final SingleResourceBProgram bprog = new SingleResourceBProgram("VerificationResultOptions.js");
bprog.putInGlobalScope("addWaiter", false);
bprog.putInGlobalScope("createDeadlock", true);
bprog.putInGlobalScope("createFailedAssertion", false);
DfsBProgramVerifier vfr = new DfsBProgramVerifier();
final VerificationResult res = vfr.verify(bprog);
assertEquals(VerificationResult.ViolationType.Deadlock, res.getViolationType());
assertTrue(res.isCounterExampleFound());
}
use of il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult in project BPjs by bThink-BGU.
the class VerificationResultOptionsTest method testOKProgram.
@Test
public void testOKProgram() throws Exception {
final SingleResourceBProgram bprog = new SingleResourceBProgram("VerificationResultOptions.js");
bprog.putInGlobalScope("addWaiter", false);
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());
}
Aggregations