Search in sources :

Example 1 with StringBProgram

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

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

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

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

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

StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)15 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)14 Test (org.junit.Test)14 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)9 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)8 NativeContinuation (org.mozilla.javascript.NativeContinuation)7 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)6 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)5 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)2 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)2 BProgramJsProxy (il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BProgramJsProxy)1 JsEventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Context (org.mozilla.javascript.Context)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1 Scriptable (org.mozilla.javascript.Scriptable)1 ScriptableInputStream (org.mozilla.javascript.serialize.ScriptableInputStream)1 ScriptableOutputStream (org.mozilla.javascript.serialize.ScriptableOutputStream)1