Search in sources :

Example 6 with VerificationResult

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);
    }
}
Also used : BriefPrintDfsVerifierListener(il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener) BProgramStateVisitedStateStore(il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore) VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Node(il.ac.bgu.cs.bp.bpjs.analysis.Node) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)

Example 7 with VerificationResult

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());
}
Also used : VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) Test(org.junit.Test)

Example 8 with VerificationResult

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());
}
Also used : VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) Test(org.junit.Test)

Example 9 with VerificationResult

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());
}
Also used : VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) Test(org.junit.Test)

Example 10 with VerificationResult

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());
}
Also used : VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) Test(org.junit.Test)

Aggregations

VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)11 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)9 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)9 Test (org.junit.Test)7 BProgramStateVisitedStateStore (il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore)2 Node (il.ac.bgu.cs.bp.bpjs.analysis.Node)2 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)2 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)2 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)1 List (java.util.List)1 Assert.fail (org.junit.Assert.fail)1