PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tests/gov/nasa/jpf/test/bdd/comparisons/OutOfMemory_ComparisonTest.java

https://bitbucket.org/rhein/jpf-bdd
Java | 260 lines | 207 code | 16 blank | 37 comment | 48 complexity | 715fe70f56c56afcacd9e93dadc7fc06 MD5 | raw file
  1. package gov.nasa.jpf.test.bdd.comparisons;
  2. import gov.nasa.jpf.bdd.TrackWithBDD;
  3. import gov.nasa.jpf.vm.Verify;
  4. import gov.nasa.jpf.test.bdd.listeners.StateSpaceCounter;
  5. import gov.nasa.jpf.util.test.TestJPF;
  6. import org.junit.Test;
  7. /**
  8. * This test shows a case where normal JPF terminates with a OutOfMemory-Exception and jpf-bdd does not.
  9. * In fact jpf-bdd is finished after less than a second.
  10. *
  11. * I switched the testing with normal jpf off, because i want to keep this class with the normal unit-Tests and
  12. * the run with normal JPF takes about 10 minutes.
  13. *
  14. * @author rhein
  15. *
  16. */
  17. public class OutOfMemory_ComparisonTest extends TestJPF {
  18. private static final String[] JPF_BDD = {"+listener=,gov.nasa.jpf.bdd.BddListener,"
  19. + "gov.nasa.jpf.test.bdd.listeners.StateSpaceCounter,"
  20. //+ "gov.nasa.jpf.test.bdd.listeners.StateSpaceDotWithBDD"
  21. ,"+search.class=gov.nasa.jpf.search.heuristic.BFSHeuristic"
  22. };
  23. private static final String[] NO_BDD = {"+listener=,gov.nasa.jpf.test.bdd.listeners.StateSpaceCounter,"
  24. //+ "gov.nasa.jpf.test.bdd.listeners.StateSpaceDotWithBDD"
  25. ,"+search.class=gov.nasa.jpf.search.heuristic.BFSHeuristic"
  26. ,"+jvm.insn_factory.class=gov.nasa.jpf.jvm.bytecode.InstructionFactory"
  27. //,"vm.class=gov.nasa.jpf.jvm.JVM"
  28. };
  29. static boolean testBDD = true;
  30. static boolean testNoBDD = false;
  31. @TrackWithBDD
  32. static boolean a1;
  33. @TrackWithBDD
  34. static boolean a2;
  35. @TrackWithBDD
  36. static boolean a3;
  37. @TrackWithBDD
  38. static boolean a4;
  39. @TrackWithBDD
  40. static boolean a5;
  41. @TrackWithBDD
  42. static boolean a6;
  43. @TrackWithBDD
  44. static boolean a7;
  45. @TrackWithBDD
  46. static boolean a8;
  47. @TrackWithBDD
  48. static boolean a9;
  49. @TrackWithBDD
  50. static boolean a10;
  51. @TrackWithBDD
  52. static boolean a11;
  53. @TrackWithBDD
  54. static boolean a12;
  55. @TrackWithBDD
  56. static boolean a13;
  57. @TrackWithBDD
  58. static boolean a14;
  59. @TrackWithBDD
  60. static boolean a15;
  61. @TrackWithBDD
  62. static boolean a16;
  63. @TrackWithBDD
  64. static boolean a17;
  65. @TrackWithBDD
  66. static boolean a18;
  67. @TrackWithBDD
  68. static boolean a19;
  69. @TrackWithBDD
  70. static boolean a20;
  71. @TrackWithBDD
  72. static boolean a21;
  73. @TrackWithBDD
  74. static boolean a22;
  75. @TrackWithBDD
  76. static boolean a23;
  77. @TrackWithBDD
  78. static boolean a24;
  79. @TrackWithBDD
  80. static boolean a25;
  81. @TrackWithBDD
  82. static boolean a26;
  83. @TrackWithBDD
  84. static boolean a27;
  85. @TrackWithBDD
  86. static boolean a28;
  87. @TrackWithBDD
  88. static boolean a29;
  89. @Test
  90. public void timingTest() throws Throwable {
  91. StateSpaceCounter.reset();
  92. boolean OOMwithBDD = false;
  93. if (testBDD) {
  94. try {
  95. executeJPF_Bdd();
  96. } catch (Throwable t) {
  97. if (t.getMessage().contains("gov.nasa.jpf.jvm.NoOutOfMemoryErrorProperty")
  98. || t.getMessage().contains("Java heap space")) {
  99. OOMwithBDD = true;
  100. t.printStackTrace();
  101. }
  102. }
  103. }
  104. long bddMaxStateID = StateSpaceCounter.maxStateID;
  105. long bddBacktracked = StateSpaceCounter.backtracked;
  106. long bddInsns = StateSpaceCounter.insns;
  107. long bddTime = StateSpaceCounter.time;
  108. long bddStateSave = StateSpaceCounter.newStates;
  109. long bddVisited = StateSpaceCounter.visitedStates;
  110. long bddCGs = StateSpaceCounter.createdCGs;
  111. System.gc();
  112. StateSpaceCounter.reset();
  113. boolean OOMwithoutbdd = false;
  114. if (testNoBDD) {
  115. try {
  116. executeJPF_no_bdd();
  117. } catch (Throwable t) {
  118. if (t.getMessage().contains("gov.nasa.jpf.jvm.NoOutOfMemoryErrorProperty")
  119. || t.getMessage().contains("Java heap space")) {
  120. System.out.println(t.getClass());
  121. OOMwithoutbdd = true;
  122. t.printStackTrace();
  123. }
  124. }
  125. }
  126. long nbddMaxStateID = StateSpaceCounter.maxStateID;
  127. long nbddBacktracked = StateSpaceCounter.backtracked;
  128. long nbddInsns = StateSpaceCounter.insns;
  129. long nbddTime = StateSpaceCounter.time;
  130. long nbddStateSave = StateSpaceCounter.newStates;
  131. long nbddVisited = StateSpaceCounter.visitedStates;
  132. long nbddCGs = StateSpaceCounter.createdCGs;
  133. System.out.println("StateSpaceSize : ");
  134. System.out.println(" normal : " + (nbddMaxStateID+1));
  135. System.out.println(" jpf-bdd: " + (bddMaxStateID+1));
  136. System.out.println("Backtracked : ");
  137. System.out.println(" normal : " + nbddBacktracked);
  138. System.out.println(" jpf-bdd: " + bddBacktracked);
  139. System.out.println("Visited : ");
  140. System.out.println(" normal : " + nbddVisited);
  141. System.out.println(" jpf-bdd: " + bddVisited);
  142. System.out.println("newStates : ");
  143. System.out.println(" normal : " + nbddStateSave);
  144. System.out.println(" jpf-bdd: " + bddStateSave);
  145. System.out.println("Instructions : ");
  146. System.out.println(" normal : " + nbddInsns);
  147. System.out.println(" jpf-bdd: " + bddInsns);
  148. System.out.println("ChoiceGenerators : ");
  149. System.out.println(" normal : " + nbddCGs);
  150. System.out.println(" jpf-bdd: " + bddCGs);
  151. System.out.println("Time : ");
  152. System.out.println(" normal : " + nbddTime);
  153. System.out.println(" jpf-bdd: " + bddTime);
  154. System.out.println("OOM-Errors: ");
  155. System.out.println(" normal : " + OOMwithoutbdd);
  156. System.out.println(" jpf-bdd: " + OOMwithBDD);
  157. assertTrue("OOM with jpf-bdd",!OOMwithBDD);
  158. StateSpaceCounter.printCGs=false;
  159. }
  160. public void executeJPF_no_bdd() {
  161. //if (verifyAssertionErrorDetails("some details", NO_BDD)) {
  162. if(verifyNoPropertyViolation(NO_BDD)) {
  163. testFunction_no_bdd();
  164. }
  165. if (isJPFRun())
  166. System.exit(0);
  167. }
  168. public void executeJPF_Bdd() {
  169. if(verifyNoPropertyViolation(JPF_BDD)) {
  170. testFunction_bdd();
  171. }
  172. if (isJPFRun())
  173. System.exit(0);
  174. }
  175. public void testFunction_no_bdd() {
  176. @SuppressWarnings("unused")
  177. int i = 0;
  178. //LinkedList<Boolean> list = new LinkedList<Boolean>();
  179. if (a1 = Verify.getBoolean()) {i++;/* list.add(a1); */}
  180. if (a2 = Verify.getBoolean()) {i++;/* list.add(a2); */}
  181. if (a3 = Verify.getBoolean()) {i++;/* list.add(a3); */}
  182. if (a4 = Verify.getBoolean()) {i++;/* list.add(a4); */}
  183. if (a5 = Verify.getBoolean()) {i++;/* list.add(a5); */}
  184. if (a6 = Verify.getBoolean()) {i++;/* list.add(a6); */}
  185. if (a7 = Verify.getBoolean()) {i++;/* list.add(a7); */}
  186. if (a8 = Verify.getBoolean()) {i++;/* list.add(a8); */}
  187. if (a9 = Verify.getBoolean()) {i++;/* list.add(a9); */}
  188. if (a10 = Verify.getBoolean()){i++;/* list.add(a10); */}
  189. if (a11 = Verify.getBoolean()){i++;/* list.add(a11); */}
  190. if (a12 = Verify.getBoolean()){i++;/* list.add(a12); */}
  191. if (a13 = Verify.getBoolean()){i++;/* list.add(a13); */}
  192. if (a14 = Verify.getBoolean()){i++;/* list.add(a14); */}
  193. if (a15 = Verify.getBoolean()){i++;/* list.add(a15); */}
  194. if (a16 = Verify.getBoolean()){i++;/* list.add(a16); */}
  195. if (a17 = Verify.getBoolean()){i++;/* list.add(a17); */}
  196. if (a18 = Verify.getBoolean()){i++;/* list.add(a18); */}
  197. if (a19 = Verify.getBoolean()){i++;/* list.add(a19); */}
  198. /*if (a20 = Verify.getBoolean()){list.add(a20);}
  199. if (a21 = Verify.getBoolean()){list.add(a21);}
  200. if (a22 = Verify.getBoolean()){list.add(a22);}
  201. if (a23 = Verify.getBoolean()){list.add(a23);}
  202. if (a24 = Verify.getBoolean()){list.add(a24);}
  203. if (a25 = Verify.getBoolean()){list.add(a25);}
  204. if (a26 = Verify.getBoolean()){list.add(a26);}
  205. if (a27 = Verify.getBoolean()){list.add(a27);}
  206. if (a28 = Verify.getBoolean()){list.add(a28);}
  207. if (a29 = Verify.getBoolean()){list.add(a29);}*/
  208. }
  209. public void testFunction_bdd() {
  210. int i = 0;
  211. //LinkedList<Boolean> list = new LinkedList<Boolean>();
  212. if (a1) {i++;/* list.add(a1); */}
  213. if (a2) {i++;/* list.add(a2); */}
  214. if (a3) {i++;/* list.add(a3); */}
  215. if (a4) {i++;/* list.add(a4); */}
  216. if (a5) {i++;/* list.add(a5); */}
  217. if (a6) {i++;/* list.add(a6); */}
  218. if (a7) {i++;/* list.add(a7); */}
  219. if (a8) {i++;/* list.add(a8); */}
  220. if (a9) {i++;/* list.add(a9); */}
  221. if (a10) {i++;/* list.add(a10); */}
  222. if (a11) {i++;/* list.add(a11); */}
  223. if (a12) {i++;/* list.add(a12); */}
  224. if (a13) {i++;/* list.add(a13); */}
  225. if (a14) {i++;/* list.add(a14); */}
  226. if (a15) {i++;/* list.add(a15); */}
  227. if (a16) {i++;/* list.add(a16); */}
  228. if (a17) {i++;/* list.add(a17); */}
  229. if (a18) {i++;/* list.add(a18); */}
  230. if (a19) {i++;/* list.add(a19); */}
  231. /*if (a20){list.add(a20);}
  232. if (a21){list.add(a21);}
  233. if (a22){list.add(a22);}
  234. if (a23){list.add(a23);}
  235. if (a24){list.add(a24);}
  236. if (a25){list.add(a25);}
  237. if (a26){list.add(a26);}
  238. if (a27){list.add(a27);}
  239. if (a28){list.add(a28);}
  240. if (a29){list.add(a29);}*/
  241. //Debug.printBDDshort(); //works, but the bdds get too long for console printout
  242. System.out.println(i);
  243. }
  244. }