Search in sources :

Example 1 with DfsBProgramVerifier

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

Example 2 with DfsBProgramVerifier

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;
}
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)

Example 3 with DfsBProgramVerifier

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);
}
Also used : BProgramStateVisitedStateStore(il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore) ForgetfulVisitedStateStore(il.ac.bgu.cs.bp.bpjs.analysis.ForgetfulVisitedStateStore) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)

Example 4 with DfsBProgramVerifier

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");
}
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) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)

Example 5 with DfsBProgramVerifier

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);
    }
}
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)9 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)8 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)8 Test (org.junit.Test)5 BProgramStateVisitedStateStore (il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore)3 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)2 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)2 ForgetfulVisitedStateStore (il.ac.bgu.cs.bp.bpjs.analysis.ForgetfulVisitedStateStore)1 Node (il.ac.bgu.cs.bp.bpjs.analysis.Node)1 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)1