Search in sources :

Example 1 with Node

use of il.ac.bgu.cs.bp.bpjs.analysis.Node in project BPjs by bThink-BGU.

the class DiningPhilTest method printCounterExample.

private static void printCounterExample(VerificationResult res) {
    System.out.println("Found a counterexample");
    final List<Node> trace = res.getCounterExampleTrace();
    trace.forEach(nd -> System.out.println(" " + nd.getLastEvent()));
    Node last = trace.get(trace.size() - 1);
    System.out.println("selectableEvents: " + last.getSelectableEvents());
    last.getSystemState().getBThreadSnapshots().stream().sorted((s1, s2) -> s1.getName().compareTo(s2.getName())).forEach(s -> {
        System.out.println(s.getName());
        System.out.println(s.getBSyncStatement());
        System.out.println();
    });
}
Also used : List(java.util.List) 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) Assert.fail(org.junit.Assert.fail) Test(org.junit.Test) Node(il.ac.bgu.cs.bp.bpjs.analysis.Node) Node(il.ac.bgu.cs.bp.bpjs.analysis.Node)

Example 2 with Node

use of il.ac.bgu.cs.bp.bpjs.analysis.Node 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)

Aggregations

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