use of il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation in project BPjs by bThink-BGU.
the class DfsBProgramVerifierTest method testJavaScriptError.
@Test
public void testJavaScriptError() throws Exception {
BProgram bprog = new StringBProgram("bp.registerBThread( function(){\n" + " bp.sync({request:bp.Event(\"A\")});\n" + " bp.sync({request:bp.Event(\"A\")});\n" + " bp.sync({request:bp.Event(\"A\")});\n" + " var myNullVar;\n" + " myNullVar.isNullAndSoThisInvocationShouldCrash();\n" + " bp.sync({request:bp.Event(\"A\")});\n" + "});");
final AtomicBoolean errorCalled = new AtomicBoolean();
final AtomicBoolean errorMadeSense = new AtomicBoolean();
DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setProgressListener(new DfsBProgramVerifier.ProgressListener() {
@Override
public void started(DfsBProgramVerifier vfr) {
}
@Override
public void iterationCount(long count, long statesHit, DfsBProgramVerifier vfr) {
}
@Override
public void maxTraceLengthHit(ExecutionTrace aTrace, DfsBProgramVerifier vfr) {
}
@Override
public void done(DfsBProgramVerifier vfr) {
}
@Override
public boolean violationFound(Violation aViolation, DfsBProgramVerifier vfr) {
errorCalled.set(aViolation instanceof JsErrorViolation);
JsErrorViolation jsev = (JsErrorViolation) aViolation;
errorMadeSense.set(jsev.decsribe().contains("isNullAndSoThisInvocationShouldCrash"));
System.out.println(jsev.getThrownException().getMessage());
return true;
}
});
sut.verify(bprog);
assertTrue(errorCalled.get());
assertTrue(errorMadeSense.get());
}
use of il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation in project BPjs by bThink-BGU.
the class DfsBProgramVerifier method getUnvisitedNextNode.
protected DfsTraversalNode getUnvisitedNextNode(DfsTraversalNode src, ExecutorService execSvc) throws ViolatingPathFoundException {
while (src.getEventIterator().hasNext()) {
final BEvent nextEvent = src.getEventIterator().next();
try {
DfsTraversalNode possibleNextNode = src.getNextNode(nextEvent, execSvc);
visitedEdgeCount++;
BProgramSyncSnapshot pns = possibleNextNode.getSystemState();
int stateIndexOnTrace = trace.indexOf(pns);
if (stateIndexOnTrace > -1) {
// cycle found
trace.cycleTo(nextEvent, stateIndexOnTrace);
Set<Violation> res = inspections.stream().map(i -> i.inspectTrace(trace)).filter(o -> o.isPresent()).map(Optional::get).collect(toSet());
for (Violation v : res) {
if (!listener.violationFound(v, this)) {
throw new ViolatingPathFoundException(v);
}
}
} else if (visited.isVisited(pns)) {
// non cyclic, revisiting a state from a different path.
// ... Quickly inspect the path and continue.
trace.advance(nextEvent, pns);
Set<Violation> res = inspections.stream().map(i -> i.inspectTrace(trace)).filter(o -> o.isPresent()).map(Optional::get).collect(toSet());
if (res.size() > 0) {
for (Violation v : res) {
if (!listener.violationFound(v, this)) {
throw new ViolatingPathFoundException(v);
}
}
}
trace.pop();
} else {
// advance to this newly discovered node
return possibleNextNode;
}
} catch (BPjsRuntimeException bprte) {
trace.advance(nextEvent, null);
Violation jsev = new JsErrorViolation(trace, bprte);
if (!listener.violationFound(jsev, this)) {
throw new ViolatingPathFoundException(jsev);
}
trace.pop();
}
}
return null;
}
Aggregations