1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.Config; 22 import gov.nasa.jpf.Error; 23 import gov.nasa.jpf.ErrorList; 24 import gov.nasa.jpf.JPF; 25 26 import java.io.PrintStream ; 27 28 import junit.framework.TestCase; 29 30 31 35 public abstract class TestJPF extends TestCase { 36 static PrintStream out = System.out; 37 38 protected TestJPF (String name) { 39 super(name); 40 } 41 42 protected void runJPFDeadlock (String [] args) { 43 report(args); 44 45 try { 46 Config conf = JPF.createConfig(args); 47 48 if (conf.getTargetArg() != null) { 49 JPF jpf = new JPF(conf); 50 jpf.run(); 51 52 ErrorList errors = jpf.getSearchErrors(); 53 54 if (errors != null) { 55 for (int i = 0; i < errors.size(); i++) { 56 Error e = (Error ) errors.get(i); 57 58 if ("Deadlock".equals(e.getMessage())) { 59 System.out.println("found Deadlock"); 60 61 return; } 63 } 64 } 65 } 66 } catch (Throwable x) { 67 x.printStackTrace(); 68 fail("JPF internal exception executing: " + args[0] + "." + args[1] + " : " + x); 69 } 70 71 fail("JPF failed to detect deadlock"); 72 } 73 74 77 protected void runJPFassertionError (String [] args) { 78 runJPFException(args, "java.lang.AssertionError"); 79 } 80 81 84 protected void runJPFnoAssertionError (String [] args) { 85 runJPFnoException(args); 86 } 87 88 protected void runJPFnoException (String [] args) { 89 ExceptionInfo xi = null; 90 91 report(args); 92 93 try { 94 gov.nasa.jpf.JPF.main(args); 96 97 xi = JVM.getVM().getPendingException(); 98 if (xi == null){ 99 return; } 101 } catch (Throwable t) { 102 fail("JPF internal exception executing: " + args[0] + "." + args[1] + 104 " : " + t); 105 } 106 107 fail("JPF caught exception executing: " + args[0] + "." + args[1] + 108 " : " + xi.getExceptionClassname()); 109 } 110 111 protected void runJPFException (String [] args, String xClassName) { 112 ExceptionInfo xi = null; 113 114 report(args); 115 116 try { 117 gov.nasa.jpf.JPF.main(args); 119 120 xi = JVM.getVM().getPendingException(); 121 if (xi == null){ 122 fail("JPF failed to catch exception executing: " + args[0] + "." + args[1] + 123 " , expected: " + xClassName); 124 } else if (!xClassName.equals(xi.getExceptionClassname())) { 125 fail("JPF caught wrong exception: " + xi.getExceptionClassname() + 126 ", expected: " + xClassName); 127 } 128 } catch (Throwable x) { 129 fail("JPF internal exception executing: " + args[0] + "." + args[1] + 130 " : " + x); 131 } 132 } 133 134 void report (String [] args) { 135 out.print(" running jpf with args:"); 136 137 for (int i = 0; i < args.length; i++) { 138 out.print(' '); 139 out.print(args[i]); 140 } 141 142 out.println(); 143 } 144 } 145 | Popular Tags |