/src/examples/gov/nasa/jpf/bdd/jpfWSExperiments/SimpleExperiment2.java
Java | 159 lines | 113 code | 19 blank | 27 comment | 22 complexity | 3161ac04c04c40866a7f02c00761e0cd MD5 | raw file
- package gov.nasa.jpf.bdd.jpfWSExperiments;
- import gov.nasa.jpf.bdd.BddManager;
- import gov.nasa.jpf.bdd.TrackWithBDD;
- import gov.nasa.jpf.vm.Verify;
- import gov.nasa.jpf.util.test.TestJPF;
- import org.junit.Test;
- public class SimpleExperiment2 extends TestJPF {
- private static final String[] JPF_BDD = {"+listener+=,gov.nasa.jpf.bdd.jpfWSExperiments.StateSpaceCounter,"
- +"gov.nasa.jpf.bdd.BddListener,"
- //+ "gov.nasa.jpf.listener.StateSpaceDot"
- //+ "gov.nasa.jpf.test.bdd.listeners.StateSpaceDotWithBDD"
- ,"+search.class=gov.nasa.jpf.search.heuristic.BFSHeuristic"
- };
- private static final String[] NO_BDD = {"+listener=,gov.nasa.jpf.bdd.jpfWSExperiments.StateSpaceCounter,"
- //+ "gov.nasa.jpf.listener.StateSpaceDot"
- //+ "gov.nasa.jpf.test.bdd.listeners.StateSpaceDotWithBDD"
- ,"+search.class=gov.nasa.jpf.search.heuristic.BFSHeuristic"
- ,"+vm.insn_factory.class=gov.nasa.jpf.jvm.bytecode.InstructionFactory"
- };
-
- static boolean testBDD = true;
- static boolean testNoBDD = true;
-
- @TrackWithBDD
- static boolean a1,a2,a3,a4,a5,a6,a7,a8;
-
- @Test
- public void timingTest() throws Throwable {
-
- StateSpaceCounter.reset();
-
- if (testBDD) {
- executeExperiment2JPF_Bdd();
- }
- long bddMaxStateID = StateSpaceCounter.maxStateID;
- long bddBacktracked = StateSpaceCounter.backtracked;
- long bddInsns = StateSpaceCounter.insns;
- long bddTime = StateSpaceCounter.time;
- long bddStateSave = StateSpaceCounter.newStates;
- long bddVisited = StateSpaceCounter.visitedStates;
- long bddCGs = StateSpaceCounter.createdCGs;
-
- System.gc();
- StateSpaceCounter.reset();
- BddManager.resetStatics();
-
- if (testNoBDD) {
- executeExperiment2JPF_no_bdd();
- }
-
- long nbddMaxStateID = StateSpaceCounter.maxStateID;
- long nbddBacktracked = StateSpaceCounter.backtracked;
- long nbddInsns = StateSpaceCounter.insns;
- long nbddTime = StateSpaceCounter.time;
- long nbddStateSave = StateSpaceCounter.newStates;
- long nbddVisited = StateSpaceCounter.visitedStates;
- long nbddCGs = StateSpaceCounter.createdCGs;
-
- System.out.println("StateSpaceSize : ");
- System.out.println(" normal : " + (nbddMaxStateID+1));
- System.out.println(" jpf-bdd: " + (bddMaxStateID+1));
- System.out.println("Backtracked : ");
- System.out.println(" normal : " + nbddBacktracked);
- System.out.println(" jpf-bdd: " + bddBacktracked);
- System.out.println("Visited : ");
- System.out.println(" normal : " + nbddVisited);
- System.out.println(" jpf-bdd: " + bddVisited);
- System.out.println("newStates : ");
- System.out.println(" normal : " + nbddStateSave);
- System.out.println(" jpf-bdd: " + bddStateSave);
- System.out.println("Instructions : ");
- System.out.println(" normal : " + nbddInsns);
- System.out.println(" jpf-bdd: " + bddInsns);
- System.out.println("ChoiceGenerators : ");
- System.out.println(" normal : " + nbddCGs);
- System.out.println(" jpf-bdd: " + bddCGs);
- System.out.println("Time : ");
- System.out.println(" normal : " + nbddTime);
- System.out.println(" jpf-bdd: " + bddTime);
-
- StateSpaceCounter.printCGs=false;
-
- }
- public void executeExperiment2JPF_no_bdd() {
- // this seems to be necessary to run the tests in eclipse (JPF does not find this classfile any more?)
- //String[] args = addCurrentClassLocationToArgs(NO_BDD);
- //if(verifyNoPropertyViolation(args)) {
- if(verifyNoPropertyViolation()) {
- experiment2_no_bdd();
- }
- if (isJPFRun())
- System.exit(0);
- }
- public void executeExperiment2JPF_Bdd() {
- // this seems to be necessary to run the tests in eclipse (JPF does not find this classfile any more?)
- //String[] args = addCurrentClassLocationToArgs(JPF_BDD);
- //if(verifyNoPropertyViolation(args)) {
- if(verifyNoPropertyViolation()) {
- experiment2_bdd();
- }
- if (isJPFRun())
- System.exit(0);
- }
- public void experiment2_no_bdd() {
- @SuppressWarnings("unused")
- int i = 0;
- if (a1 = Verify.getBoolean()) {i++;}
- if (a2 = Verify.getBoolean()) {i++;}
- if (a3 = Verify.getBoolean()) {i++;}
- if (a4 = Verify.getBoolean()) {i++;}
- if (a5 = Verify.getBoolean()) {i++;}
- if (a6 = Verify.getBoolean()) {i++;}
- if (a7 = Verify.getBoolean()) {i++;}
- if (a8 = Verify.getBoolean()) {i++;}
- //System.out.println(i);
- }
- public void experiment2_bdd() {
- int i = 0;
- if (a1) {i++;}
- if (a2) {i++;}
- if (a3) {i++;}
- if (a4) {i++;}
- if (a5) {i++;}
- if (a6) {i++;}
- if (a7) {i++;}
- if (a8) {i++;}
-
- //Verify.breakTransition();
- /*
- * If the artificial transition break above is
- * not enabled there will be no state merging
- * after the last BDD-ChoiceGenerator (on a8).
- * This means that every number (except 0 and 8)
- * will be printed twice.
- */
- System.out.println(i);
-
- //Debug.printBDDshort();
- //works, but the bdds get too long for console printout
- }
- /**
- * This method adds the location of the classfile of this class as a classpath configuration option to the configuration array.
- * In fact it creates a new array with one additional entry.
- * @param originalArgs
- * @return
- */
- private String[] addCurrentClassLocationToArgs(String[] originalArgs) {
- String[] args = new String[originalArgs.length + 1];
- System.arraycopy(originalArgs, 0, args, 0, originalArgs.length);
- args[args.length-1] = "+classpath+=;build/examples/";
- return args;
- }
- }
-