Search in sources :

Example 6 with SingleResourceBProgram

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

the class DynamicBThreadAdditionTest method test.

@Test
public void test() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("dynamicBthreadAddition.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.run();
    Set<String> expected = new HashSet<>(Arrays.asList("e0", "e1", "e2", "e3"));
    assertEquals(expected, eventLogger.getEvents().stream().map(BEvent::getName).collect(toSet()));
}
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) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with SingleResourceBProgram

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

the class EventsWithDataTest method testEventsWithData.

@Test
public void testEventsWithData() throws Exception {
    BProgram bpr = new SingleResourceBProgram("EventsWithData.js", "programName", new SimpleEventSelectionStrategy(99l));
    BProgramRunner rnr = new BProgramRunner(bpr);
    rnr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener events = rnr.addListener(new InMemoryEventLoggingListener());
    rnr.run();
    assertEquals(Arrays.asList("e1", "e2", "e1e2"), events.getEvents().stream().map(BEvent::getName).collect(toList()));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SimpleEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy) 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) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 8 with SingleResourceBProgram

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

the class ExternalEventsTest method superStepTest.

@Test
public void superStepTest() throws InterruptedException {
    final BEvent in1a = new BEvent("in1a");
    final BEvent ext1 = new BEvent("ext1");
    final BEvent in1b = new BEvent("in1b");
    final SingleResourceBProgram bprog = new SingleResourceBProgram("ExternalEvents.js");
    bprog.setEventSelectionStrategy(new LoggingEventSelectionStrategyDecorator(bprog.getEventSelectionStrategy()));
    final BProgramRunner sut = new BProgramRunner(bprog);
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.getBProgram().enqueueExternalEvent(ext1);
    sut.run();
    eventLogger.getEvents().forEach(e -> System.out.println(e));
    EventPattern expected = new EventPattern().append(in1a).append(ext1).append(in1b);
    assertTrue(expected.matches(eventLogger.getEvents()));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) EventPattern(il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern) LoggingEventSelectionStrategyDecorator(il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 9 with SingleResourceBProgram

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

the class TicTacToeVerMain method main.

public static void main(String[] args) throws InterruptedException {
    // Create a program
    BProgram bprog = new SingleResourceBProgram("BPJSTicTacToe.js");
    bprog.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
    bprog.setDaemonMode(true);
    String simulatedPlayer = "bp.registerBThread('XMoves', function() {\n" + "while (true) {\n" + "bsync({ request:[ X(0, 0), X(0, 1), X(0, 2), X(1, 0), \n" + "X(1, 1), X(1, 2), X(2, 0), X(2, 1), X(2, 2) ] }, 10); \n" + "}\n" + "});\n";
    // This bthread models the requirement that X never wins.
    String xCantWinRequirementBThread = "bp.registerBThread( \"req:NoXWin\", function(){\n" + "	bp.sync({waitFor:StaticEvents.XWin});\n" + "	bp.ASSERT(false, \"Found a trace where X wins.\");\n" + "});";
    bprog.appendSource(simulatedPlayer);
    bprog.appendSource(xCantWinRequirementBThread);
    // bprog.appendSource(infiBThread);
    try {
        DfsBProgramVerifier vfr = new DfsBProgramVerifier();
        vfr.setDetectDeadlocks(false);
        vfr.setMaxTraceLength(70);
        // vfr.setDebugMode(true);
        vfr.setVisitedNodeStore(new BProgramStateVisitedStateStore(false));
        vfr.setProgressListener(new BriefPrintDfsVerifierListener());
        final VerificationResult res = vfr.verify(bprog);
        if (res.isCounterExampleFound()) {
            System.out.println("Found a counterexample");
            res.getCounterExampleTrace().forEach(nd -> System.out.println(" " + nd.getLastEvent()));
        } else {
            System.out.println("No counterexample found.");
        }
        System.out.printf("Scanned %,d states\n", res.getScannedStatesCount());
        System.out.printf("Time: %,d milliseconds\n", res.getTimeMillies());
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    }
    System.out.println("end of run");
}
Also used : BriefPrintDfsVerifierListener(il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener) BProgramStateVisitedStateStore(il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore) VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) 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) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)

Example 10 with SingleResourceBProgram

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

the class Mazes method verify.

public void verify() throws InterruptedException {
    SingleResourceBProgram bprog = prepareProgram();
    bprog.appendSource(Requirements.eventNotSelected(targetFoundEvent.getName()));
    try {
        DfsBProgramVerifier vfr = new DfsBProgramVerifier();
        vfr.setProgressListener(new BriefPrintDfsVerifierListener());
        vfr.setIterationCountGap(10);
        vfr.setVisitedNodeStore(new BProgramStateVisitedStateStore(false));
        // vfr.setVisitedNodeStore(new ForgetfulVisitedStateStore());
        // prevent from detecting cases where we ust hit a wall.
        vfr.setDetectDeadlocks(false);
        final VerificationResult res = vfr.verify(bprog);
        char[][] maze = getMaze(bprog);
        printMaze(maze);
        if (res.isCounterExampleFound()) {
            System.out.println("Found a counterexample");
            for (Node nd : res.getCounterExampleTrace()) {
                System.out.println(" " + nd.getLastEvent());
                if (nd.getLastEvent() != null) {
                    String name = nd.getLastEvent().getName();
                    if (name.startsWith("Enter")) {
                        String loc = name.split("\\(")[1].replace(")", "").trim();
                        String[] coord = loc.split(",");
                        int col = Integer.parseInt(coord[0]);
                        int row = Integer.parseInt(coord[1]);
                        maze[row][col] = '•';
                    }
                }
            }
            printMaze(maze);
        } else {
            System.out.println("No counterexample found.");
        }
        System.out.printf("Scanned %,d states\n", res.getScannedStatesCount());
        System.out.printf("Time: %,d milliseconds\n", res.getTimeMillies());
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    }
}
Also used : BriefPrintDfsVerifierListener(il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener) BProgramStateVisitedStateStore(il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore) VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Node(il.ac.bgu.cs.bp.bpjs.analysis.Node) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)

Aggregations

SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)45 Test (org.junit.Test)38 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)29 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)26 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)22 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)17 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)14 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)10 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)9 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)9 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)7 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)4 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)3 BProgramStateVisitedStateStore (il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore)2 Node (il.ac.bgu.cs.bp.bpjs.analysis.Node)1 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)1 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)1 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)1 FailedAssertion (il.ac.bgu.cs.bp.bpjs.model.FailedAssertion)1 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)1