Search in sources :

Example 1 with JsErrorViolation

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());
}
Also used : DeadlockViolation(il.ac.bgu.cs.bp.bpjs.analysis.violations.DeadlockViolation) JsErrorViolation(il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation) DetectedSafetyViolation(il.ac.bgu.cs.bp.bpjs.analysis.violations.DetectedSafetyViolation) Violation(il.ac.bgu.cs.bp.bpjs.analysis.violations.Violation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) JsErrorViolation(il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation) Test(org.junit.Test)

Example 2 with JsErrorViolation

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;
}
Also used : JsErrorViolation(il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation) Violation(il.ac.bgu.cs.bp.bpjs.analysis.violations.Violation) JsErrorViolation(il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation) BPjsRuntimeException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) BPjs(il.ac.bgu.cs.bp.bpjs.BPjs) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) Set(java.util.Set) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Violation(il.ac.bgu.cs.bp.bpjs.analysis.violations.Violation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Optional(java.util.Optional) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) ExecutorService(java.util.concurrent.ExecutorService) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) HashSet(java.util.HashSet) Collectors.toSet(java.util.stream.Collectors.toSet) Optional(java.util.Optional) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) BPjsRuntimeException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException) JsErrorViolation(il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation)

Aggregations

JsErrorViolation (il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation)2 Violation (il.ac.bgu.cs.bp.bpjs.analysis.violations.Violation)2 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)2 BPjs (il.ac.bgu.cs.bp.bpjs.BPjs)1 DeadlockViolation (il.ac.bgu.cs.bp.bpjs.analysis.violations.DeadlockViolation)1 DetectedSafetyViolation (il.ac.bgu.cs.bp.bpjs.analysis.violations.DetectedSafetyViolation)1 BPjsRuntimeException (il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException)1 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)1 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)1 ResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.ResourceBProgram)1 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors.toSet (java.util.stream.Collectors.toSet)1