PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/examples/gov/nasa/jpf/bdd/jpfWSExperiments/SimpleExperiment2.java

https://bitbucket.org/rhein/jpf-bdd
Java | 159 lines | 113 code | 19 blank | 27 comment | 22 complexity | 3161ac04c04c40866a7f02c00761e0cd MD5 | raw file
  1. package gov.nasa.jpf.bdd.jpfWSExperiments;
  2. import gov.nasa.jpf.bdd.BddManager;
  3. import gov.nasa.jpf.bdd.TrackWithBDD;
  4. import gov.nasa.jpf.vm.Verify;
  5. import gov.nasa.jpf.util.test.TestJPF;
  6. import org.junit.Test;
  7. public class SimpleExperiment2 extends TestJPF {
  8. private static final String[] JPF_BDD = {"+listener+=,gov.nasa.jpf.bdd.jpfWSExperiments.StateSpaceCounter,"
  9. +"gov.nasa.jpf.bdd.BddListener,"
  10. //+ "gov.nasa.jpf.listener.StateSpaceDot"
  11. //+ "gov.nasa.jpf.test.bdd.listeners.StateSpaceDotWithBDD"
  12. ,"+search.class=gov.nasa.jpf.search.heuristic.BFSHeuristic"
  13. };
  14. private static final String[] NO_BDD = {"+listener=,gov.nasa.jpf.bdd.jpfWSExperiments.StateSpaceCounter,"
  15. //+ "gov.nasa.jpf.listener.StateSpaceDot"
  16. //+ "gov.nasa.jpf.test.bdd.listeners.StateSpaceDotWithBDD"
  17. ,"+search.class=gov.nasa.jpf.search.heuristic.BFSHeuristic"
  18. ,"+vm.insn_factory.class=gov.nasa.jpf.jvm.bytecode.InstructionFactory"
  19. };
  20. static boolean testBDD = true;
  21. static boolean testNoBDD = true;
  22. @TrackWithBDD
  23. static boolean a1,a2,a3,a4,a5,a6,a7,a8;
  24. @Test
  25. public void timingTest() throws Throwable {
  26. StateSpaceCounter.reset();
  27. if (testBDD) {
  28. executeExperiment2JPF_Bdd();
  29. }
  30. long bddMaxStateID = StateSpaceCounter.maxStateID;
  31. long bddBacktracked = StateSpaceCounter.backtracked;
  32. long bddInsns = StateSpaceCounter.insns;
  33. long bddTime = StateSpaceCounter.time;
  34. long bddStateSave = StateSpaceCounter.newStates;
  35. long bddVisited = StateSpaceCounter.visitedStates;
  36. long bddCGs = StateSpaceCounter.createdCGs;
  37. System.gc();
  38. StateSpaceCounter.reset();
  39. BddManager.resetStatics();
  40. if (testNoBDD) {
  41. executeExperiment2JPF_no_bdd();
  42. }
  43. long nbddMaxStateID = StateSpaceCounter.maxStateID;
  44. long nbddBacktracked = StateSpaceCounter.backtracked;
  45. long nbddInsns = StateSpaceCounter.insns;
  46. long nbddTime = StateSpaceCounter.time;
  47. long nbddStateSave = StateSpaceCounter.newStates;
  48. long nbddVisited = StateSpaceCounter.visitedStates;
  49. long nbddCGs = StateSpaceCounter.createdCGs;
  50. System.out.println("StateSpaceSize : ");
  51. System.out.println(" normal : " + (nbddMaxStateID+1));
  52. System.out.println(" jpf-bdd: " + (bddMaxStateID+1));
  53. System.out.println("Backtracked : ");
  54. System.out.println(" normal : " + nbddBacktracked);
  55. System.out.println(" jpf-bdd: " + bddBacktracked);
  56. System.out.println("Visited : ");
  57. System.out.println(" normal : " + nbddVisited);
  58. System.out.println(" jpf-bdd: " + bddVisited);
  59. System.out.println("newStates : ");
  60. System.out.println(" normal : " + nbddStateSave);
  61. System.out.println(" jpf-bdd: " + bddStateSave);
  62. System.out.println("Instructions : ");
  63. System.out.println(" normal : " + nbddInsns);
  64. System.out.println(" jpf-bdd: " + bddInsns);
  65. System.out.println("ChoiceGenerators : ");
  66. System.out.println(" normal : " + nbddCGs);
  67. System.out.println(" jpf-bdd: " + bddCGs);
  68. System.out.println("Time : ");
  69. System.out.println(" normal : " + nbddTime);
  70. System.out.println(" jpf-bdd: " + bddTime);
  71. StateSpaceCounter.printCGs=false;
  72. }
  73. public void executeExperiment2JPF_no_bdd() {
  74. // this seems to be necessary to run the tests in eclipse (JPF does not find this classfile any more?)
  75. //String[] args = addCurrentClassLocationToArgs(NO_BDD);
  76. //if(verifyNoPropertyViolation(args)) {
  77. if(verifyNoPropertyViolation()) {
  78. experiment2_no_bdd();
  79. }
  80. if (isJPFRun())
  81. System.exit(0);
  82. }
  83. public void executeExperiment2JPF_Bdd() {
  84. // this seems to be necessary to run the tests in eclipse (JPF does not find this classfile any more?)
  85. //String[] args = addCurrentClassLocationToArgs(JPF_BDD);
  86. //if(verifyNoPropertyViolation(args)) {
  87. if(verifyNoPropertyViolation()) {
  88. experiment2_bdd();
  89. }
  90. if (isJPFRun())
  91. System.exit(0);
  92. }
  93. public void experiment2_no_bdd() {
  94. @SuppressWarnings("unused")
  95. int i = 0;
  96. if (a1 = Verify.getBoolean()) {i++;}
  97. if (a2 = Verify.getBoolean()) {i++;}
  98. if (a3 = Verify.getBoolean()) {i++;}
  99. if (a4 = Verify.getBoolean()) {i++;}
  100. if (a5 = Verify.getBoolean()) {i++;}
  101. if (a6 = Verify.getBoolean()) {i++;}
  102. if (a7 = Verify.getBoolean()) {i++;}
  103. if (a8 = Verify.getBoolean()) {i++;}
  104. //System.out.println(i);
  105. }
  106. public void experiment2_bdd() {
  107. int i = 0;
  108. if (a1) {i++;}
  109. if (a2) {i++;}
  110. if (a3) {i++;}
  111. if (a4) {i++;}
  112. if (a5) {i++;}
  113. if (a6) {i++;}
  114. if (a7) {i++;}
  115. if (a8) {i++;}
  116. //Verify.breakTransition();
  117. /*
  118. * If the artificial transition break above is
  119. * not enabled there will be no state merging
  120. * after the last BDD-ChoiceGenerator (on a8).
  121. * This means that every number (except 0 and 8)
  122. * will be printed twice.
  123. */
  124. System.out.println(i);
  125. //Debug.printBDDshort();
  126. //works, but the bdds get too long for console printout
  127. }
  128. /**
  129. * This method adds the location of the classfile of this class as a classpath configuration option to the configuration array.
  130. * In fact it creates a new array with one additional entry.
  131. * @param originalArgs
  132. * @return
  133. */
  134. private String[] addCurrentClassLocationToArgs(String[] originalArgs) {
  135. String[] args = new String[originalArgs.length + 1];
  136. System.arraycopy(originalArgs, 0, args, 0, originalArgs.length);
  137. args[args.length-1] = "+classpath+=;build/examples/";
  138. return args;
  139. }
  140. }