Search in sources :

Example 31 with BProgram

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

the class DfsBProgramVerifierTest method deadlockRun.

@Test
public void deadlockRun() throws Exception {
    BProgram program = new SingleResourceBProgram("deadlocking.js");
    BProgramRunner rnr = new BProgramRunner(program);
    rnr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = rnr.addListener(new InMemoryEventLoggingListener());
    rnr.run();
    eventLogger.getEvents().forEach(System.out::println);
    assertTrue(eventNamesString(eventLogger.getEvents(), "").matches("^A$"));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) 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) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) Test(org.junit.Test)

Example 32 with BProgram

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

the class DfsBProgramVerifierTest method simpleAAABTrace.

@Test
public void simpleAAABTrace() throws Exception {
    BProgram program = new SingleResourceBProgram("AAABTrace.js");
    DfsBProgramVerifier sut = new DfsBProgramVerifier();
    sut.setProgressListener(new BriefPrintDfsVerifierListener());
    program.appendSource(Requirements.eventNotSelected("B"));
    sut.setVisitedNodeStore(new ForgetfulVisitedStateStore());
    VerificationResult res = sut.verify(program);
    assertTrue(res.isCounterExampleFound());
    assertEquals("AAAB", traceEventNamesString(res.getCounterExampleTrace(), ""));
}
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) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 33 with BProgram

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

the class DfsBProgramVerifierTest method deadlockTrace.

@Test
public void deadlockTrace() throws Exception {
    BProgram program = new SingleResourceBProgram("deadlocking.js");
    DfsBProgramVerifier sut = new DfsBProgramVerifier();
    sut.setVisitedNodeStore(new ForgetfulVisitedStateStore());
    VerificationResult res = sut.verify(program);
    assertTrue(res.isCounterExampleFound());
    assertEquals(VerificationResult.ViolationType.Deadlock, res.getViolationType());
    assertEquals("A", traceEventNamesString(res.getCounterExampleTrace(), ""));
}
Also used : 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) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 34 with BProgram

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

the class BProgramSyncSnapshotClonerTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    System.out.println("\nSTART Serialization test");
    BProgram bprog = new SingleResourceBProgram("BProgramSyncSnapshotClonerTest.js");
    BProgramSyncSnapshot cur = bprog.setup();
    ExecutorService exSvc = ExecutorServiceMaker.makeWithName("test");
    cur = cur.start(exSvc);
    cur.triggerEvent(cur.getStatements().stream().flatMap(s -> s.getRequest().stream()).findFirst().get(), exSvc, emptySet());
    BProgramSyncSnapshotIO io = new BProgramSyncSnapshotIO(bprog);
    byte[] out = io.serialize(cur);
    System.out.println("de-serializing\n");
    io.deserialize(out);
    System.out.println("END Serialization test\n");
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Collections.emptySet(java.util.Collections.emptySet) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) Test(org.junit.Test) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) ExecutorService(java.util.concurrent.ExecutorService) ExecutorServiceMaker(il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) ExecutorService(java.util.concurrent.ExecutorService) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) Test(org.junit.Test)

Example 35 with BProgram

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

the class GetTimeTest method test.

@Test
public void test() throws InterruptedException {
    BProgram sut = new SingleResourceBProgram("getTimeTest.js");
    long timePre = System.currentTimeMillis();
    new BProgramRunner(sut).run();
    long timePost = System.currentTimeMillis();
    Long actual = sut.getFromGlobalScope("theTime", Long.class).get();
    assertTrue((actual >= timePre) && (actual <= timePost));
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Aggregations

BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)36 Test (org.junit.Test)29 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)23 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)21 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)11 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)10 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)9 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)8 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)7 NativeContinuation (org.mozilla.javascript.NativeContinuation)7 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)5 Scriptable (org.mozilla.javascript.Scriptable)5 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)4 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)3 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)3 BPjsCodeEvaluationException (il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException)2 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)2 EventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.EventSelectionStrategy)2 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2