00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import java.util.*;
00035 import java.io.*;
00036 import edu.ksu.cis.bandera.bui.session.datastructure.*;
00037 import edu.ksu.cis.bandera.bui.session.*;
00038 import edu.ksu.cis.bandera.bui.*;
00039 import edu.ksu.cis.bandera.util.*;
00040
00041 public class Bandera {
00042 private static final String sessionExtension = ".session";
00043 private static StringBuffer summary = new StringBuffer();
00044 private static boolean isDump;
00045 private static boolean genReport;
00046 private static String expectedPath;
00047
00048
00049
00050
00051 public static void assert(boolean b) {}
00052 public static void beginAtomic(){}
00053
00054
00055
00056
00057 public static boolean choose() {
00058 return false;
00059 }
00060 private static void doOneSession(Session ses) {
00061 if (ses == null)
00062 throw new RuntimeException("Cannot run null session!");
00063
00064 Driver driver = new Driver();
00065 driver.initCmdLine(ses, isDump, genReport, expectedPath);
00066 summary.append("--------------------------------------------------------------------------------\n");
00067 summary.append("Session: " + ses.getName() + "\n\n");
00068 driver.run();
00069
00070 summary.append(driver.getSummary());
00071 driver = null;
00072 summary.append("\n--------------------------------------------------------------------------------\n");
00073 }
00074 public static void endAtomic(){}
00075
00076
00077
00078 private static void help()
00079 {
00080 System.out.println("Bandera parameter list:");
00081 System.out.println(" -h, --h, --help, -?, --?, -help Print this help screen.");
00082 System.out.println(" -s {sesfile} [sesnames...] --> run Bandera with specified session file.");
00083 System.out.println(" If your session file doesn't end with " + sessionExtension + " Bandera will append it.");
00084 System.out.println(" If you omit the sesnames part, it will run *ALL* sessions in the");
00085 System.out.println(" session file.");
00086 System.out.println(" You can run only some sessions of the session file by listing it, e.g.:");
00087 System.out.println(" java Bandera -s test ses1 dedlok multitrd3");
00088 System.out.println(" This will run bandera using test." + sessionExtension + " and run");
00089 System.out.println(" ses1, dedlok, and multitrd3 sessions.\n");
00090 System.out.println(" -sd does the same things as -s except it dumps Jimple and Java codes");
00091 System.out.println(" in intermediate steps.");
00092 System.out.println(" -st <path> does the same things as -rd except it generates test report");
00093 System.out.println(" -r {sesfile} [sesnames...] --> run Mr. Roboto with specified session file.");
00094 System.out.println(" -rd does the same things as -r except it dumps Jimple and Java codes");
00095 System.out.println(" in intermediate steps.");
00096 System.out.println(" -rt <path> does the same things as -rd except it generates test report");
00097 System.out.println("Running Bandera without parameter will bring you to the GUI directly.\nSee manual for details.");
00098 }
00099
00100
00101
00102
00103 public static void main(String[] args) {
00104 if (args.length == 0) {
00105 edu.ksu.cis.bandera.bui.BUI.main(args);
00106 } else {
00107
00108 if ((args.length == 1) && ((args[0].equals("-h")) || (args[0].equals("--help")) || (args[0].equals("-help")) || (args[0].equals("-?")) || (args[0].equals("--h") || (args[0].equals("--?"))))) {
00109 help();
00110 return;
00111 }
00112
00113
00114 if ((args.length >= 2) && (args[0].equals("-s") || args[0].equals("-sd") || args[0].equals("-st"))) {
00115 Preferences.load();
00116
00117
00118 int sessionIdx = 1;
00119 if (args[0].equals("-sd"))
00120 isDump = true;
00121 if (args[0].equals("-st")) {
00122 isDump = true;
00123 genReport = true;
00124 expectedPath = args[1];
00125 sessionIdx = 2;
00126 if (args.length < 3) {
00127 help();
00128 return;
00129 }
00130 }
00131 String st;
00132 if (args[sessionIdx].endsWith(sessionExtension))
00133 st = args[sessionIdx];
00134 else
00135 st = args[sessionIdx] + sessionExtension;
00136
00137
00138 try {
00139
00140 Sessions allses = null;
00141 try {
00142 allses = new SessionsSaverLoader().load(st);
00143 if (allses == null)
00144 throw new Exception();
00145 summary.append("Execution Summary:\n\nSession file " + st + " is successfully loaded.\n\n");
00146 } catch (Exception ex) {
00147 throw new Exception("Cannot load session file '" + st + "'");
00148 }
00149
00150
00151 if (args.length == sessionIdx + 1) {
00152 for (Enumeration e = allses.getSessions().elements(); e.hasMoreElements();) {
00153 doOneSession((Session) e.nextElement());
00154 }
00155 } else {
00156
00157 for (int i = sessionIdx + 1; i < args.length; i++) {
00158 doOneSession(allses.getSession(args[i]));
00159 }
00160 }
00161 } catch (Exception e) {
00162 summary.append("Error: " + e.getMessage());
00163 }
00164
00165
00166 if (genReport)
00167 edu.ksu.cis.bandera.report.HTMLReportGenerator.generateSummary(st, "index.html");
00168 System.out.println(summary);
00169
00170 Preferences.save();
00171 System.exit(0);
00172 } else
00173 if ((args.length >= 2) && ((args[0].equals("-r")) || (args[0].equals("-rd"))) || (args[0].equals("-rt"))) {
00174 Preferences.load();
00175
00176
00177 int sessionIdx = 1;
00178 if (args[0].equals("-rd"))
00179 isDump = true;
00180 if (args[0].equals("-rt")) {
00181 isDump = true;
00182 genReport = true;
00183 expectedPath = args[1];
00184 sessionIdx = 2;
00185 if (args.length < 3) {
00186 help();
00187 return;
00188 }
00189 }
00190 String st;
00191 if (args[sessionIdx].endsWith(sessionExtension))
00192 st = args[sessionIdx];
00193 else
00194 st = args[sessionIdx] + sessionExtension;
00195
00196
00197 try {
00198
00199 Sessions allses = null;
00200 try {
00201 allses = new SessionsSaverLoader().load(st);
00202 if (allses == null)
00203 throw new Exception();
00204 summary.append("Execution Summary:\n\nSession file " + st + " is successfully loaded.\n\n");
00205 } catch (Exception ex) {
00206 throw new Exception("Cannot load session file '" + st + "'");
00207 }
00208 Vector sessionNames = new Vector();
00209
00210 if (args.length == 2) {
00211 for (Enumeration e = allses.getSessions().elements(); e.hasMoreElements();) {
00212 sessionNames.add(((Session) e.nextElement()).getName());
00213 }
00214 } else {
00215
00216 for (int i = 0; i < args.length - 2; i++) {
00217 Session s = allses.getSession(args[i + 2]);
00218 if (s != null)
00219 sessionNames.add(s.getName());
00220 else
00221 System.out.println("Session " + args[i + 2] + " is not found!\n");
00222 }
00223 }
00224 edu.ksu.cis.bandera.bui.BUI.main(new String[0]);
00225 new edu.ksu.cis.bandera.bui.roboto.MrRoboto(st, sessionNames, isDump, genReport, expectedPath).run();
00226 } catch (Exception e) {
00227 summary.append("Error: " + e.getMessage());
00228 }
00229
00230 if (genReport)
00231 edu.ksu.cis.bandera.report.HTMLReportGenerator.generateSummary(st, "index.html");
00232 System.out.println(summary);
00233
00234 Preferences.save();
00235 System.exit(0);
00236 } else {
00237 System.out.println("Error! See help for details!");
00238 help();
00239 }
00240 }
00241 }
00242
00243
00244
00245
00246 public static int random(int n)
00247 {
00248 if(n>=0){
00249 for(int i=1; i<=n; i++)
00250 if(choose())
00251 return i;
00252 return 0;
00253 }
00254 else
00255 System.out.println("Bad argument");
00256 return -1;
00257
00258 }
00259
00260
00261
00262
00263 public static boolean randomBool()
00264 {
00265 return choose();
00266 }
00267 }