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());
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations