Search in sources :

Example 1 with VerificationResult

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

use of il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult 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 3 with VerificationResult

use of il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult 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 4 with VerificationResult

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

the class StateStorePerformanceComparison method runVerifier.

private static void runVerifier(DfsBProgramVerifier vfr) throws Exception {
    System.out.println("Testing " + vfr.getVisitedNodeStore());
    System.out.println("Heating up");
    for (int i = 0; i < HEAT_UP_ITERATIONS; i++) {
        vfr.verify(makeBProgram());
    }
    for (int i = 0; i < ITERATIONS; i++) {
        VerificationResult res = vfr.verify(makeBProgram());
        System.out.println(res.getTimeMillies());
    }
}
Also used : VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)

Example 5 with VerificationResult

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

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