Skip to content

Commit

Permalink
Merge 74c7333 into f02f1fa
Browse files Browse the repository at this point in the history
  • Loading branch information
acepace committed Apr 21, 2018
2 parents f02f1fa + 74c7333 commit e689bd2
Show file tree
Hide file tree
Showing 16 changed files with 755 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
BProgramSyncSnapshot other = (BProgramSyncSnapshot) obj;
if (isStateValid() != other.isStateValid()) {
return false;
}
if (!isStateValid()) {
if (!getFailedAssertion().equals(other.getFailedAssertion()) ) {
return false;
}
}
return Objects.equals(threadSnapshots, other.threadSnapshots);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
/*
* The MIT License
*
* Copyright 2017 michael.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package il.ac.bgu.cs.bp.bpjs.analysis.DFSVerifierTests;

import static il.ac.bgu.cs.bp.bpjs.TestUtils.eventNamesString;

import il.ac.bgu.cs.bp.bpjs.analysis.*;
import il.ac.bgu.cs.bp.bpjs.model.BProgram;
import il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner;
import il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram;
import il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener;
import il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener;

import org.junit.Test;

import static il.ac.bgu.cs.bp.bpjs.TestUtils.traceEventNamesString;
import static org.junit.Assert.*;

import il.ac.bgu.cs.bp.bpjs.model.StringBProgram;
import il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener;

/**
* @author michael
*/
public class DfsBProgramVerifierTest {

@Test
public void simpleAAABTrace() throws Exception {
BProgram program = new SingleResourceBProgram("DFSVerifierTests/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(), ""));
}

@Test
public void simpleAAABTrace_hashedNodeStore() throws Exception {
BProgram program = new SingleResourceBProgram("DFSVerifierTests/AAABTrace.js");
DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setProgressListener(new BriefPrintDfsVerifierListener());
program.appendSource(Requirements.eventNotSelected("B"));
VisitedStateStore stateStore = new BProgramStateVisitedStateStore(true);
sut.setVisitedNodeStore(stateStore);
VerificationResult res = sut.verify(program);
assertTrue(res.isCounterExampleFound());
assertEquals("AAAB", traceEventNamesString(res.getCounterExampleTrace(), ""));
//Add trivial getter check
VisitedStateStore retStore = sut.getVisitedNodeStore();
assertSame(retStore, stateStore);
}

@Test
public void testAAABRun() {
BProgram program = new SingleResourceBProgram("DFSVerifierTests/AAABTrace.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("^(AAAB)+$"));
}

@Test
public void deadlockTrace() throws Exception {
BProgram program = new SingleResourceBProgram("DFSVerifierTests/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(), ""));
}

@Test
public void testDeadlockSetting() throws Exception {
BProgram program = new SingleResourceBProgram("DFSVerifierTests/deadlocking.js");
DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setDetectDeadlocks(false);
VerificationResult res = sut.verify(program);
assertFalse(res.isCounterExampleFound());
assertEquals(VerificationResult.ViolationType.None, res.getViolationType());
}


@Test
public void deadlockRun() {
BProgram program = new SingleResourceBProgram("DFSVerifierTests/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$"));

}

@Test
public void testTwoSimpleBThreads() throws Exception {
BProgram bprog = new StringBProgram(
"bp.registerBThread('bt1', function(){bsync({ request:[ bp.Event(\"STAM1\") ] });});"
+ "bp.registerBThread('bt2', function(){bsync({ request:[ bp.Event(\"STAM2\") ] });});");

DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setIterationCountGap(1);
sut.setProgressListener(new BriefPrintDfsVerifierListener());
sut.setDetectDeadlocks(false);
VerificationResult res = sut.verify(bprog);

assertTrue(res.isVerifiedSuccessfully());
assertEquals(3, res.getScannedStatesCount());
assertEquals(VerificationResult.ViolationType.None, res.getViolationType());
}

@Test(timeout = 2000)
public void testTwoLoopingBThreads() throws Exception {
BProgram bprog = new StringBProgram("bp.registerBThread('bt1', function(){" + " while(true){\n"
+ " bsync({ request:[ bp.Event(\"STAM1\") ] });\n" + "}});\n"
+ "bp.registerBThread('bt2', function(){" + " while(true){\n"
+ " bsync({ request:[ bp.Event(\"STAM2\") ] });\n" + "}});\n" + "");

DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setIterationCountGap(1);
sut.setProgressListener(new BriefPrintDfsVerifierListener());
sut.setDebugMode(true);
VerificationResult res = sut.verify(bprog);

assertFalse(res.isCounterExampleFound());
assertEquals(1, res.getScannedStatesCount());
}

@Test(timeout = 2000)
public void testVariablesInBT() throws Exception {
BProgram bprog = new StringBProgram("bp.registerBThread('bt1', function(){" + //
" for(var i=0; i<10; i++){\n" + //
" bsync({ waitFor:[ bp.Event(\"X\") ] });\n" + //
" }\n" + //
" bsync({ block:[ bp.Event(\"X\") ] });\n" + //
"});\n" + //

"bp.registerBThread('bt2', function(){" + //
" while(true){\n" + //
" bsync({ request:[ bp.Event(\"X\") ] });\n" + //
"}});\n" + //
"" //
);

DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setIterationCountGap(1);
sut.setProgressListener(new BriefPrintDfsVerifierListener());
sut.setDebugMode(true);
VerificationResult res = sut.verify(bprog);

assertTrue(res.isCounterExampleFound());
assertEquals(res.getViolationType(), VerificationResult.ViolationType.Deadlock);
assertEquals(10, res.getScannedStatesCount());
}

@Test(timeout = 2000)
public void testVariablesEquailtyInBT() throws Exception {
BProgram bprog = new StringBProgram( //
"bp.registerBThread('bt1', function(){" + //
" while(true) \n" + //
" for(var i=0; i<10; i++){\n" + //
" bsync({ waitFor:[ bp.Event(\"X\") ] });\n" + //
" }\n" + //
"});\n" + "bp.registerBThread('bt2', function(){" + //
" while(true){\n" + //
" bsync({ request:[ bp.Event(\"X\") ] });\n" + //
"}});\n");

DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setIterationCountGap(1);
sut.setProgressListener(new BriefPrintDfsVerifierListener());
sut.setDebugMode(true);
VerificationResult res = sut.verify(bprog);

assertFalse(res.isCounterExampleFound());
assertEquals(res.getViolationType(), VerificationResult.ViolationType.None);
assertEquals(10, res.getScannedStatesCount());
}

@Test(timeout = 3000)
public void tesJavaVariablesInBT() throws Exception {
BProgram bprog = new StringBProgram( //
"bp.registerBThread('bt1', function(){" + //
" while(true) \n" + //
" for(var i=0; i<10; i++){\n" + //
" bsync({ request:[ bp.Event(\"X\"+i) ] });\n" + //
" if (i == 5) {bsync({ request:[ bp.Event(\"X\"+i) ] });}\n" + //
" }\n" + //
"});\n" +
"var x = bp.EventSet( \"X\", function(e){\r\n" +
" return e.getName().startsWith(\"X\");\r\n" +
"} );\r\n" +
"" +
"bp.registerBThread('bt2', function(){" + //
" var lastE = {name:\"what\"};" + //
" while(true) {\n" + //
" var e = bsync({ waitFor: x});\n" + //
" lastE = e;" + //
" if( e.name == lastE.name) { bp.ASSERT(false,\"Poof\");} " + //
"}});\n"
);

DfsBProgramVerifier sut = new DfsBProgramVerifier();
sut.setIterationCountGap(1);
sut.setProgressListener(new BriefPrintDfsVerifierListener());
sut.setDebugMode(true);
VerificationResult res = sut.verify(bprog);

assertEquals(res.getViolationType(), VerificationResult.ViolationType.FailedAssertion);
assertTrue(res.isCounterExampleFound());
assertEquals(1, res.getScannedStatesCount());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package il.ac.bgu.cs.bp.bpjs.analysis.examples;
package il.ac.bgu.cs.bp.bpjs.analysis.DFSVerifierTests;

import il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore;
import il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier;
Expand All @@ -34,66 +34,66 @@
import il.ac.bgu.cs.bp.bpjs.analysis.VisitedStateStore;

/**
* This program runs the DFS verifier against the same maze using different
* {@link VisitedStateStore} implementations, and prints the timing results
* This program runs the DFS verifier against the same maze using different
* {@link VisitedStateStore} implementations, and prints the timing results
* to the console.
*
* <p>
* Run this test as follows:
* <ul>
* <li>Build the BPjs uber-jar: {@code mvn package -P uber-jar}</li>
* <li>Build the BPjs tests-jar: {@code mvn jar:test-jar}</li>
* <li>Run and collect output: {@code java -Xmx4G -cp [uber jar]:[tests jar] il.ac.bgu.cs.bp.bpjs.analysis.examples.StateStorePerformanceComparison}</li>
* <li>Build the BPjs uber-jar: {@code mvn package -P uber-jar}</li>
* <li>Build the BPjs tests-jar: {@code mvn jar:test-jar}</li>
* <li>Run and collect output: {@code java -Xmx4G -cp [uber jar]:[tests jar] il.ac.bgu.cs.bp.bpjs.analysis.DFSVerifierTests.StateStorePerformanceComparison}</li>
* </ul>
*
*
* @author michael
*/
public class StateStorePerformanceComparison {

private static String MAZE_NAME = "complex2";

private final static String IMPLEMENTATION = "MazesNegative.js";
private final static BEvent TARGET_FOUND_EVENT = BEvent.named("targetFound");
private static final int ITERATIONS = 100;
private static final int HEAT_UP_ITERATIONS = 10;

private static String MAZE_NAME = "complex2";

public static void main(String[] args) throws Exception {
if ( args.length == 1 ) {

if (args.length == 1) {
MAZE_NAME = args[0];
}

// prepare verifier
DfsBProgramVerifier verifier = new DfsBProgramVerifier();
verifier.setDetectDeadlocks( false );
verifier.setDetectDeadlocks(false);

// test
verifier.setVisitedNodeStore(new BProgramStateVisitedStateStore(false) );
verifier.setVisitedNodeStore(new BProgramStateVisitedStateStore(false));
runVerifier(verifier);
verifier.setVisitedNodeStore(new BProgramStateVisitedStateStore(true) );
verifier.setVisitedNodeStore(new BProgramStateVisitedStateStore(true));
runVerifier(verifier);
verifier.setVisitedNodeStore(new ForgetfulVisitedStateStore());
runVerifier(verifier);

}

private static BProgram makeBProgram() {
// prepare b-program
final BProgram bprog = new SingleResourceBProgram(IMPLEMENTATION);
bprog.putInGlobalScope("MAZE_NAME", MAZE_NAME);
bprog.putInGlobalScope("TARGET_FOUND_EVENT", TARGET_FOUND_EVENT);
bprog.appendSource( Requirements.eventNotSelected(TARGET_FOUND_EVENT.getName()) );
bprog.appendSource(Requirements.eventNotSelected(TARGET_FOUND_EVENT.getName()));
return bprog;
}

private static void runVerifier(DfsBProgramVerifier vfr) throws Exception {
System.out.println("Testing " + vfr.getVisitedNodeStore() );
System.out.println("Testing " + vfr.getVisitedNodeStore());
System.out.println("Heating up");
for ( int i=0; i<HEAT_UP_ITERATIONS; i++ ) {
for (int i = 0; i < HEAT_UP_ITERATIONS; i++) {
vfr.verify(makeBProgram());
}
for (int i = 0; i < ITERATIONS; i++) {
VerificationResult res = vfr.verify(makeBProgram());
System.out.println(res.getTimeMillies());
}

}
}
Loading

0 comments on commit e689bd2

Please sign in to comment.