1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 import java.util.Properties ; 25 import java.util.Calendar ; 26 import java.util.GregorianCalendar ; 27 import java.io.File ; 28 import java.io.FileReader ; 29 import java.io.FilenameFilter ; 30 import java.io.FileWriter ; 31 import java.io.IOException ; 32 import java.io.BufferedReader ; 33 import java.io.PrintWriter ; 34 import java.sql.Date ; 35 import java.sql.Time ; 36 import java.sql.Timestamp ; 37 38 48 public class GenerateReport { 49 50 static void CollectProperties () { 51 Properties ps = System.getProperties(); 52 char[] newline = {' '}; 53 propFile.println(PropertyUtil.sortProperties(ps,newline)); 54 } 55 56 static void CalculateRunLength () { 57 String odn = System.getProperty("outputdir"); 60 if (odn==null) odn = System.getProperty("user.dir"); 61 62 BufferedReader sumFile = null; 63 String firstLine = null; 64 String lastLine = null; 65 try { 66 sumFile = new BufferedReader (new FileReader (new File (new File (odn),SuiteName+".sum"))); 67 firstLine = sumFile.readLine(); 68 String aLine = firstLine; 69 while (aLine!=null) { 70 lastLine = aLine; 71 aLine = sumFile.readLine(); 72 } 73 sumFile.close(); 74 } catch (IOException ioe) { 75 ioe.printStackTrace(System.out); 76 } 77 78 int tsStart = 22+SuiteName.length(); 83 int tsEnd = firstLine.length()-8; 84 TestStart = Timestamp.valueOf(firstLine.substring(tsStart,tsEnd)); 85 tsStart-=2; tsEnd-=2; 87 Timestamp testEnd = Timestamp.valueOf(lastLine.substring(tsStart,tsEnd)); 88 89 long testLen = testEnd.getTime() - TestStart.getTime(); 90 int sec = (int) (testLen / 1000); 92 int min = sec / 60; 93 int hr = min / 60; 94 sec = sec - (min*60); min = min - (hr*60); Calendar cal = new GregorianCalendar (); 97 cal.set(Calendar.HOUR_OF_DAY,hr); 98 cal.set(Calendar.MINUTE,min); 99 cal.set(Calendar.SECOND,sec); 100 TestDuration = new Time (cal.getTime().getTime()); 101 } 102 103 static void CollectPassFailStats () { 104 String odn = System.getProperty("outputdir"); 106 if (odn==null) odn = System.getProperty("user.dir"); 107 CollectPassFailStats(new File (odn),""); 108 } 109 110 static void addLines(PrintWriter outFile, File inFile, String relativeName) { 111 BufferedReader readFile = null; 112 try { 113 readFile = new BufferedReader (new FileReader (inFile)); 114 String aLine = readFile.readLine(); 115 while (aLine!=null) { 116 outFile.print(relativeName); 117 outFile.print(":"); 118 outFile.println(aLine); 119 aLine = readFile.readLine(); 120 } 121 readFile.close(); 122 } catch (IOException ioe) { 123 ioe.printStackTrace(System.out); 124 } 125 126 } 127 128 static void addDiff(PrintWriter outFile, File inFile, String relativeName) { 129 BufferedReader readFile = null; 130 try { 131 readFile = new BufferedReader (new FileReader (inFile)); 132 outFile.print("********* Diff file "); 133 outFile.println(relativeName); 134 String aLine = readFile.readLine(); 135 while (aLine!=null) { 136 outFile.println(aLine); 137 aLine = readFile.readLine(); 138 } 139 readFile.close(); 140 } catch (IOException ioe) { 141 ioe.printStackTrace(System.out); 142 } 143 } 144 145 static void CollectPassFailStats (File dir,String relativeName) { 146 String [] fileList = dir.list(fileFilter); 148 int l = fileList.length; 149 for (int i=0;i<l;i++) { 150 String fileName = fileList[i]; 151 File file = new File (dir,fileName); 152 153 if (fileName.endsWith(".pass")) { 155 addLines(passFile,file,relativeName+"/"+fileName); 156 } 157 else if (fileName.endsWith(".fail")) { 159 addLines(failFile,file,relativeName+"/"+fileName); 160 } 161 else if (fileName.endsWith(".skip")) { 163 addLines(skipFile,file,relativeName+"/"+fileName); 164 } 165 else if (fileName.endsWith(".diff")) { 167 addDiff(diffFile,file,relativeName+"/"+fileName); 168 } 169 170 else { 173 String newDir; 174 if (relativeName.length()>0) 175 newDir = relativeName+"/"+fileName; 176 else newDir = fileName; 177 CollectPassFailStats(file, newDir); 178 } 179 } 180 } 181 182 static void CalculatePassFailStats() { 183 NumPass = CountLines (passFileName); 187 NumFail = CountLines (failFileName); 188 NumRun = NumPass+NumFail; 189 NumSkip = CountLines (skipFileName); 190 PercentPass = (int)Math.floor(100* ((double)NumPass/(double)NumRun)); 191 PercentFail = (int)Math.ceil(100* ((double)NumFail/(double)NumRun)); 192 } 193 194 static int CountLines(String fileName) { 195 BufferedReader readFile = null; 196 int line = 0; 197 try { 198 readFile = new BufferedReader (new FileReader (fileName)); 199 String aLine = readFile.readLine(); 200 while (aLine!=null) { 201 line++; 202 aLine = readFile.readLine(); 203 } 204 readFile.close(); 205 } catch (IOException ioe) { 206 ioe.printStackTrace(System.out); 207 } 208 return line; 209 } 210 211 static void OutputFile(String fileName) { 212 BufferedReader readFile = null; 213 try { 214 readFile = new BufferedReader (new FileReader (fileName)); 215 String aLine = readFile.readLine(); 216 while (aLine != null) { 217 reportFile.println(aLine); 218 aLine = readFile.readLine(); 219 } 220 readFile.close(); 221 } catch (IOException ioe) { 222 ioe.printStackTrace(System.out); 223 } 224 } 225 226 static PrintWriter setupFile(String fn) { 227 File f = null; 228 PrintWriter pw = null; 229 try { 230 f = new File (fn); 231 if (f.exists()) { 232 System.out.println("WARNING: removing "+fn); 233 f.delete(); 234 } 235 pw = new PrintWriter (new FileWriter (fn,true)); 236 } catch (IOException ioe) { 237 ioe.printStackTrace(System.out); 238 } 239 return pw; 240 } 241 242 public static void main(String [] args) { 243 SuiteName = args[0]; 244 String jvmName = args[1]; 245 String javaCmd = args[2]; 246 String classpath = args[3]; 247 String framework = args[4]; 248 String processexec = args[5]; 249 boolean useprocess = true; 250 if ( (processexec.toLowerCase()).startsWith("false") ) 251 useprocess = false; 252 String reportFileName = SuiteName+"_report.txt"; 253 reportFile = setupFile(reportFileName); 254 reportFile.print("Generating report for RunSuite "); 255 for (int i=0;i<args.length;i++) 256 reportFile.print(args[i]+" "); 257 reportFile.println(); 258 passFileName = SuiteName+"_pass.txt"; 259 failFileName = SuiteName+"_fail.txt"; 260 diffFileName = SuiteName+"_diff.txt"; 261 skipFileName = SuiteName+"_skip.txt"; 262 propFileName = SuiteName+"_prop.txt"; 263 passFile = setupFile(passFileName); 264 failFile = setupFile(failFileName); 265 diffFile = setupFile(diffFileName); 266 skipFile = setupFile(skipFileName); 267 propFile = setupFile(propFileName); 268 269 SysInfoLog sysLog = new SysInfoLog(); 271 try 272 { 273 sysLog.exec(jvmName, javaCmd, classpath, framework, reportFile, useprocess); 274 } 276 catch (Exception e) 277 { 278 System.out.println("SysInfoLog Exception: " + e.getMessage()); 279 } 280 281 reportFile.println("Test environment information:"); 282 reportFile.print("COMMAND LINE STYLE: "); 283 String jvm = System.getProperty("jvm"); 284 if (jvm == null) jvm="jdk13"; 285 reportFile.println(jvm); 286 reportFile.print("TEST CANONS: "); 287 String canondir = System.getProperty("canondir"); 288 if (canondir == null) canondir = "master"; 289 reportFile.println(canondir); 290 reportFile.println(DASHLINE); 291 292 reportFile.println(DASHLINE); 293 reportFile.println("Summary results:"); 294 CalculateRunLength(); 295 CollectPassFailStats(); 296 CollectProperties(); 297 passFile.close(); 298 failFile.close(); 299 skipFile.close(); 300 diffFile.close(); 301 propFile.close(); 302 CalculatePassFailStats(); 303 reportFile.println(); 304 reportFile.println("Test Run Started: "+TestStart); 305 reportFile.println("Test Run Duration: "+TestDuration); 306 reportFile.println(); 307 reportFile.println(NumRun+" Tests Run"); 308 if (PercentPass<10) reportFile.print(" "); 309 reportFile.println(PercentPass+"% Pass ("+NumPass+" tests passed)"); 310 if (PercentFail<10) reportFile.print(" "); 311 reportFile.println(PercentFail+"% Fail ("+NumFail+" tests failed)"); 312 reportFile.println(NumSkip + " Suites skipped"); 313 reportFile.println(DASHLINE); 314 315 if (NumFail>0) { 316 reportFile.println("Failed tests in: "+failFileName); 317 reportFile.println(DASHLINE); 318 } 319 320 if (NumPass>0) { 321 reportFile.println("Passed tests in: "+passFileName); 322 reportFile.println(DASHLINE); 323 } 324 325 if (NumSkip>0) { 326 reportFile.println("Skipped suites in: "+skipFileName); 327 reportFile.println(DASHLINE); 328 } 329 330 reportFile.println("System properties in: "+propFileName); 331 reportFile.println(DASHLINE); 332 333 reportFile.println(DASHLINE); 334 if (NumFail>0) { 335 reportFile.println("Failure Details:"); 336 OutputFile(diffFileName); 338 } 339 else reportFile.println("No Failures."); 340 reportFile.println(DASHLINE); 341 reportFile.close(); 342 343 System.out.println("Generated report: "+reportFileName); 344 } 345 346 static final String DASHLINE="------------------------------------------------------"; 347 static String passFileName, failFileName, diffFileName, skipFileName, propFileName; 348 static PrintWriter passFile, failFile, diffFile, skipFile, propFile; 349 static PrintWriter reportFile; 350 static FilenameFilter fileFilter = new GRFileFilter(); 351 static int NumPass, NumFail, NumRun, NumSkip; 352 static int PercentPass, PercentFail; 353 static Timestamp TestStart; 354 static Time TestDuration; 355 static String SuiteName; 356 } 357 | Popular Tags |