Search in sources :

Example 6 with BProgram

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

the class EventsWithDataTest method testEventsWithData.

@Test
public void testEventsWithData() throws Exception {
    BProgram bpr = new SingleResourceBProgram("EventsWithData.js", "programName", new SimpleEventSelectionStrategy(99l));
    BProgramRunner rnr = new BProgramRunner(bpr);
    rnr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener events = rnr.addListener(new InMemoryEventLoggingListener());
    rnr.run();
    assertEquals(Arrays.asList("e1", "e2", "e1e2"), events.getEvents().stream().map(BEvent::getName).collect(toList()));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SimpleEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy) 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) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 7 with BProgram

use of il.ac.bgu.cs.bp.bpjs.model.BProgram 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 8 with BProgram

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

the class ContinuationProgramStateTest method testEqualityTrue.

@Test
public void testEqualityTrue() throws Exception {
    // Generate a continuation
    BProgram bprog = new StringBProgram(SRC);
    BProgramSyncSnapshot cur = bprog.setup();
    cur = cur.start(exSvc);
    final BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
    // Read frame data
    NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
    ContinuationProgramState sut1 = new ContinuationProgramState(nc);
    ContinuationProgramState sut2 = new ContinuationProgramState(nc);
    assertTrue(sut1.equals(sut2));
}
Also used : BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) NativeContinuation(org.mozilla.javascript.NativeContinuation) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 9 with BProgram

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

the class ContinuationProgramStateTest method testInequalityLoop.

@Test
public void testInequalityLoop() throws Exception {
    // Generate snapshot 1
    BProgram bprog = new StringBProgram(SRC_LOOP_UPDATED_VAR);
    BProgramSyncSnapshot cur = bprog.setup();
    cur = cur.start(exSvc);
    BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
    NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
    ContinuationProgramState sut1 = new ContinuationProgramState(nc);
    assertEquals(1.0, sut1.getVisibleVariables().get("dbl"));
    assertEquals("a", sut1.getVisibleVariables().get("str"));
    // Generate snapshot 2, pre-loop
    cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
    snapshot = cur.getBThreadSnapshots().iterator().next();
    nc = (NativeContinuation) snapshot.getContinuation();
    ContinuationProgramState sut2 = new ContinuationProgramState(nc);
    assertEquals("b", sut2.getVisibleVariables().get("str"));
    assertEquals(42.0, sut2.getVisibleVariables().get("dbl"));
    // Generate snapshot 3, first loop
    cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
    snapshot = cur.getBThreadSnapshots().iterator().next();
    nc = (NativeContinuation) snapshot.getContinuation();
    ContinuationProgramState sut3 = new ContinuationProgramState(nc);
    assertEquals(47.0, sut3.getVisibleVariables().get("dbl"));
    assertEquals("ba", sut3.getVisibleVariables().get("str"));
    // Generate snapshot 4, second loop
    cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
    snapshot = cur.getBThreadSnapshots().iterator().next();
    nc = (NativeContinuation) snapshot.getContinuation();
    ContinuationProgramState sut4 = new ContinuationProgramState(nc);
    assertEquals(52.0, sut4.getVisibleVariables().get("dbl"));
    assertEquals("baa", sut4.getVisibleVariables().get("str"));
    assertFalse(sut2.equals(sut1));
}
Also used : BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) NativeContinuation(org.mozilla.javascript.NativeContinuation) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 10 with BProgram

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

the class ContinuationProgramStateTest method testEqualityComplexObj.

@Test
public void testEqualityComplexObj() throws Exception {
    // Generate continuation 1
    BProgram bprog = new StringBProgram(SRC_WITH_COMPOUND_VARS);
    BProgramSyncSnapshot cur = bprog.setup();
    cur = cur.start(exSvc);
    BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
    NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
    ContinuationProgramState sut1 = new ContinuationProgramState(nc);
    // Generate Continuation 2
    bprog = new StringBProgram(SRC_WITH_COMPOUND_VARS);
    cur = bprog.setup();
    cur = cur.start(exSvc);
    snapshot = cur.getBThreadSnapshots().iterator().next();
    // Read frame data
    nc = (NativeContinuation) snapshot.getContinuation();
    ContinuationProgramState sut2 = new ContinuationProgramState(nc);
    // sanity
    assertTrue(sut1.equals(sut1));
    assertTrue(sut1.equals(sut2));
    assertTrue(sut2.equals(sut1));
}
Also used : BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) NativeContinuation(org.mozilla.javascript.NativeContinuation) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Aggregations

BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)36 Test (org.junit.Test)29 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)23 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)21 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)11 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)10 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)9 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)8 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)7 NativeContinuation (org.mozilla.javascript.NativeContinuation)7 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)5 Scriptable (org.mozilla.javascript.Scriptable)5 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)4 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)3 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)3 BPjsCodeEvaluationException (il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException)2 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)2 EventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.EventSelectionStrategy)2 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2