Search in sources :

Example 1 with BriefPrintDfsVerifierListener

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

the class DfsBProgramVerifierTest method testTwoLoopingBThreads.

@Test(timeout = 2000)
public void testTwoLoopingBThreads() throws Exception {
    BProgram bprog = new StringBProgram("bp.registerBThread('bt1', function(){" + "    while(true){\n" + "       bsync({ request:[ bp.Event(\"STAM1\") ] });\n" + "}});\n" + "bp.registerBThread('bt2', function(){" + "    while(true){\n" + "       bsync({ request:[ bp.Event(\"STAM2\") ] });\n" + "}});\n" + "");
    DfsBProgramVerifier sut = new DfsBProgramVerifier();
    sut.setIterationCountGap(1);
    sut.setProgressListener(new BriefPrintDfsVerifierListener());
    sut.setDebugMode(true);
    VerificationResult res = sut.verify(bprog);
    assertFalse(res.isCounterExampleFound());
    assertEquals(1, res.getScannedStatesCount());
}
Also used : BriefPrintDfsVerifierListener(il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 2 with BriefPrintDfsVerifierListener

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

the class DfsBProgramVerifierTest method testTwoSimpleBThreads.

@Test
public void testTwoSimpleBThreads() throws Exception {
    BProgram bprog = new StringBProgram("bp.registerBThread('bt1', function(){bsync({ request:[ bp.Event(\"STAM1\") ] });});" + "bp.registerBThread('bt2', function(){bsync({ request:[ bp.Event(\"STAM2\") ] });});");
    DfsBProgramVerifier sut = new DfsBProgramVerifier();
    sut.setIterationCountGap(1);
    sut.setProgressListener(new BriefPrintDfsVerifierListener());
    sut.setDetectDeadlocks(false);
    VerificationResult res = sut.verify(bprog);
    assertTrue(res.isVerifiedSuccessfully());
    assertEquals(3, res.getScannedStatesCount());
    assertEquals(VerificationResult.ViolationType.None, res.getViolationType());
}
Also used : BriefPrintDfsVerifierListener(il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 3 with BriefPrintDfsVerifierListener

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

the class DfsBProgramVerifierTest method simpleAAABTrace_hashedNodeStore.

@Test
public void simpleAAABTrace_hashedNodeStore() throws Exception {
    BProgram program = new SingleResourceBProgram("AAABTrace.js");
    DfsBProgramVerifier sut = new DfsBProgramVerifier();
    sut.setProgressListener(new BriefPrintDfsVerifierListener());
    program.appendSource(Requirements.eventNotSelected("B"));
    sut.setVisitedNodeStore(new BProgramStateVisitedStateStore(true));
    VerificationResult res = sut.verify(program);
    assertTrue(res.isCounterExampleFound());
    assertEquals("AAAB", traceEventNamesString(res.getCounterExampleTrace(), ""));
}
Also used : BriefPrintDfsVerifierListener(il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 4 with BriefPrintDfsVerifierListener

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

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

BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)6 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)6 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)5 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)4 Test (org.junit.Test)4 BProgramStateVisitedStateStore (il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore)2 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)2 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)2 Node (il.ac.bgu.cs.bp.bpjs.analysis.Node)1 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)1