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