Search in sources :

Example 31 with StringBProgram

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

the class DfsBProgramVerifierTest method testMaxTraceLength.

@Test(timeout = 2000)
public void testMaxTraceLength() throws Exception {
    String source = "bp.registerBThread('bt1', function(){" + "    bp.sync({ request:[ bp.Event(\"X\") ] });\n" + "    bp.sync({ request:[ bp.Event(\"X\") ] });\n" + "    bp.sync({ request:[ bp.Event(\"X\") ] });\n" + "    bp.sync({ request:[ bp.Event(\"X\") ] });\n" + "    bp.sync({ request:[ bp.Event(\"X\") ] });\n" + "    bp.sync({ request:[ bp.Event(\"X\") ] });\n" + "    bp.ASSERT(false, \"\");" + "});";
    BProgram bprog = new StringBProgram(source);
    DfsBProgramVerifier sut = new DfsBProgramVerifier();
    sut.setIterationCountGap(1);
    sut.setProgressListener(new PrintDfsVerifierListener());
    sut.setDebugMode(true);
    VerificationResult res = sut.verify(bprog);
    assertTrue(res.isViolationFound());
    sut.setMaxTraceLength(6);
    res = sut.verify(new StringBProgram(source));
    assertFalse(res.isViolationFound());
}
Also used : PrintDfsVerifierListener(il.ac.bgu.cs.bp.bpjs.analysis.listeners.PrintDfsVerifierListener) ResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.ResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) TestUtils.traceEventNamesString(il.ac.bgu.cs.bp.bpjs.TestUtils.traceEventNamesString) TestUtils.eventNamesString(il.ac.bgu.cs.bp.bpjs.TestUtils.eventNamesString) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 32 with StringBProgram

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

the class BrokenCodeTest method brokenSyntaxDfsTest.

@Test(expected = BPjsCodeEvaluationException.class)
public void brokenSyntaxDfsTest() throws Exception {
    try (InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream("broken/syntaxError.js")) {
        String raw = new String(resource.readAllBytes(), StandardCharsets.UTF_8);
        String post = Arrays.asList(raw.split("\n")).stream().filter(s -> !s.contains("REMOVE")).collect(joining("\n"));
        BProgram bp = new StringBProgram(post);
        DfsBProgramVerifier vfr = new DfsBProgramVerifier();
        vfr.verify(bp);
    }
}
Also used : BProgramRunnerListenerAdapter(il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter) Arrays(java.util.Arrays) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) BPjsCodeEvaluationException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) ResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.ResourceBProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) InputStream(java.io.InputStream) InputStream(java.io.InputStream) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) ResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.ResourceBProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 33 with StringBProgram

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

the class ArrayExecutionTraceTest method testGetLastEvent.

/**
 * Test of getLastEvent method, of class ArrayExecutionTrace.
 */
@Test
public void testGetLastEvent() {
    ArrayExecutionTrace sut = new ArrayExecutionTrace(new StringBProgram(""));
    sut.push(makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_1, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_2, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_3, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_4, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    assertEquals(EVT_4, sut.getLastEvent().get());
    sut.cycleTo(EVT_3, 2);
    assertEquals(EVT_3, sut.getLastEvent().get());
}
Also used : MockBThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.mocks.MockBThreadSyncSnapshot) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 34 with StringBProgram

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

the class ArrayExecutionTraceTest method testgetFinalCycle.

/**
 * Test of isCyclic method, of class ArrayExecutionTrace.
 */
@Test
public void testgetFinalCycle() {
    ArrayExecutionTrace sut = new ArrayExecutionTrace(new StringBProgram(""));
    sut.push(makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    assertTrue(sut.getLastEvent().isEmpty());
    sut.advance(EVT_1, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_2, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_3, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_4, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    assertTrue(sut.getFinalCycle().isEmpty());
    sut.cycleTo(EVT_3, 2);
    assertEquals(3, sut.getFinalCycle().size());
}
Also used : MockBThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.mocks.MockBThreadSyncSnapshot) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 35 with StringBProgram

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

the class ArrayExecutionTraceTest method testClear.

/**
 * Test of clear method, of class ArrayExecutionTrace.
 */
@Test
public void testClear() {
    ArrayExecutionTrace sut = new ArrayExecutionTrace(new StringBProgram(""));
    sut.push(makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_1, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_2, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_3, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    sut.advance(EVT_4, makeBPSS(new MockBThreadSyncSnapshot(SyncStatement.make())));
    assertEquals(5, sut.getStateCount());
    sut.clear();
    assertEquals(0, sut.getStateCount());
    assertTrue(sut.getLastEvent().isEmpty());
}
Also used : MockBThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.mocks.MockBThreadSyncSnapshot) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Aggregations

StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)43 Test (org.junit.Test)40 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)36 ResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.ResourceBProgram)22 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)10 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)10 PrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.PrintDfsVerifierListener)9 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)9 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)8 NativeContinuation (org.mozilla.javascript.NativeContinuation)7 TestUtils.traceEventNamesString (il.ac.bgu.cs.bp.bpjs.TestUtils.traceEventNamesString)5 DeadlockViolation (il.ac.bgu.cs.bp.bpjs.analysis.violations.DeadlockViolation)5 DetectedSafetyViolation (il.ac.bgu.cs.bp.bpjs.analysis.violations.DetectedSafetyViolation)5 Arrays (java.util.Arrays)5 Collectors.joining (java.util.stream.Collectors.joining)5 TestUtils.eventNamesString (il.ac.bgu.cs.bp.bpjs.TestUtils.eventNamesString)4 JsErrorViolation (il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation)4 Violation (il.ac.bgu.cs.bp.bpjs.analysis.violations.Violation)4