1 39 40 package com.sun.japex; 41 42 import java.util.*; 43 import java.text.*; 44 import java.io.File ; 45 import com.sun.japex.testsuite.*; 46 47 import java.awt.Paint ; 48 import java.awt.Color ; 49 import java.awt.BorderLayout ; 50 import java.awt.event.ActionEvent ; 51 import java.awt.event.ActionListener ; 52 53 import javax.swing.JFrame ; 54 import javax.swing.JButton ; 55 import javax.swing.JPanel ; 56 import javax.swing.JSlider ; 57 import javax.swing.JToolBar ; 58 import javax.swing.event.ChangeEvent ; 59 import javax.swing.event.ChangeListener ; 60 61 import org.jfree.chart.*; 62 import org.jfree.data.category.DefaultCategoryDataset; 63 import org.jfree.ui.ApplicationFrame; 64 import org.jfree.ui.RefineryUtilities; 65 import org.jfree.chart.plot.CategoryPlot; 66 import org.jfree.chart.renderer.category.CategoryItemRenderer; 67 import org.jfree.chart.renderer.category.BarRenderer; 68 import org.jfree.chart.plot.PlotOrientation; 69 70 public class TestSuite extends Params { 71 72 String _name; 73 List _driverInfo = new ArrayList(); 74 75 81 public TestSuite(com.sun.japex.testsuite.TestSuite ts) { 82 _name = ts.getName(); 83 84 List params = ts.getParam(); 86 final String pathSep = System.getProperty("path.separator"); 87 List classPathURLs = new ArrayList(); 88 89 if (params != null) { 90 Iterator it = params.iterator(); 91 while (it.hasNext()) { 92 ParamType pt = (ParamType) it.next(); 93 String name = pt.getName(); 94 String value = pt.getValue(); 95 String oldValue = getParam(name); 96 97 setParam(name, 99 name.equals(Constants.CLASS_PATH) && oldValue != null ? 100 (oldValue + pathSep + value) : value); 101 } 102 } 103 104 if (!hasParam(Constants.WARMUP_TIME) && 106 !hasParam(Constants.WARMUP_ITERATIONS)) 107 { 108 setParam(Constants.WARMUP_ITERATIONS, 109 Constants.DEFAULT_WARMUP_ITERATIONS); 110 } 111 if (!hasParam(Constants.RUN_TIME) && 112 !hasParam(Constants.RUN_ITERATIONS)) 113 { 114 setParam(Constants.RUN_ITERATIONS, 115 Constants.DEFAULT_RUN_ITERATIONS); 116 } 117 118 if (!hasParam(Constants.REPORTS_DIRECTORY)) { 120 setParam(Constants.REPORTS_DIRECTORY, 121 Constants.DEFAULT_REPORTS_DIRECTORY); 122 } 123 124 if (!hasParam(Constants.NUMBER_OF_THREADS)) { 126 setParam(Constants.NUMBER_OF_THREADS, 127 Constants.DEFAULT_NUMBER_OF_THREADS); 128 } 129 else { 130 int nOfThreads = getIntParam(Constants.NUMBER_OF_THREADS); 131 if (nOfThreads < 1) { 132 throw new RuntimeException ( 133 "Parameter 'japex.numberOfThreads' must be at least 1"); 134 } 135 } 136 137 if (!hasParam(Constants.RUNS_PER_DRIVER)) { 139 setParam(Constants.RUNS_PER_DRIVER, 140 Constants.DEFAULT_RUNS_PER_DRIVER); 141 } 142 else { 143 int runsPerDriver = getIntParam(Constants.RUNS_PER_DRIVER); 144 if (runsPerDriver < 1) { 145 throw new RuntimeException ( 146 "Parameter 'japex.runsPerDriver' must be at least 1"); 147 } 148 } 149 150 setParam(Constants.VERSION, Constants.VERSION_VALUE); 152 setParam(Constants.OS_NAME, System.getProperty("os.name")); 153 setParam(Constants.OS_ARCHITECTURE, System.getProperty("os.arch")); 154 DateFormat df = new SimpleDateFormat("dd MMM yyyy/HH:mm:ss z"); 155 setParam(Constants.DATE_TIME, df.format(Japex.TODAY)); 156 setParam(Constants.VM_INFO, 157 System.getProperty("java.vendor") + " " + 158 System.getProperty("java.vm.version")); 159 160 Iterator it = ts.getDriver().iterator(); 162 while (it.hasNext()) { 163 TestSuiteType.DriverType dt = (TestSuiteType.DriverType) it.next(); 164 165 Properties driverParams = new Properties(getParams()); 166 Iterator driverParamsIt = dt.getParam().iterator(); 167 while (driverParamsIt.hasNext()) { 168 ParamType pt = (ParamType) driverParamsIt.next(); 169 driverParams.setProperty(pt.getName(), pt.getValue()); 170 } 171 172 if (driverParams.getProperty(Constants.DRIVER_CLASS) == null) { 174 driverParams.setProperty(Constants.DRIVER_CLASS, dt.getName()); 175 } 176 _driverInfo.add( 177 new DriverInfo(dt.getName(), dt.isNormal(), 178 getIntParam(Constants.RUNS_PER_DRIVER), 179 driverParams)); 180 } 181 182 TestCaseArrayList testCases = new TestCaseArrayList(); 184 it = ts.getTestCase().iterator(); 185 while (it.hasNext()) { 186 TestSuiteType.TestCaseType tc = 187 (TestSuiteType.TestCaseType) it.next(); 188 189 Properties localParams = new Properties(getParams()); 190 Iterator itParams = tc.getParam().iterator(); 191 while (itParams.hasNext()) { 192 ParamType pt = (ParamType) itParams.next(); 193 localParams.setProperty(pt.getName(), pt.getValue()); 194 } 195 testCases.add(new TestCase(tc.getName(), localParams)); 196 } 197 198 it = _driverInfo.iterator(); 200 while (it.hasNext()) { 201 DriverInfo di = (DriverInfo) it.next(); 202 di.setTestCases(testCases); 203 } 204 } 205 206 public String getName() { 207 return _name; 208 } 209 210 public List getDriverInfoList() { 211 return _driverInfo; 212 } 213 214 public void serialize(StringBuffer report) { 215 report.append("<testSuiteReport name=\"" + _name 216 + "\" xmlns=\"http://www.sun.com/japex/testSuiteReport\">\n"); 217 218 serialize(report, 2); 219 220 Iterator jdi = _driverInfo.iterator(); 222 while (jdi.hasNext()) { 223 DriverInfo di = (DriverInfo) jdi.next(); 224 di.serialize(report, 2); 225 } 226 227 report.append("</testSuiteReport>\n"); 228 } 229 230 public void generateDriverChart(String fileName) { 231 try { 232 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 233 String resultUnit = getParam(Constants.RESULT_UNIT); 234 235 DriverInfo normalizerDriver = null; 237 Iterator jdi = _driverInfo.iterator(); 238 while (jdi.hasNext()) { 239 DriverInfo di = (DriverInfo) jdi.next(); 240 if (di.isNormal()) { 241 normalizerDriver = di; 242 resultUnit = "% of " + resultUnit; 243 break; 244 } 245 } 246 247 jdi = _driverInfo.iterator(); 249 while (jdi.hasNext()) { 250 DriverInfo di = (DriverInfo) jdi.next(); 251 252 if (normalizerDriver != null) { 253 dataset.addValue( 254 normalizerDriver == di ? 100.0 : 255 (100.0 * di.getDoubleParam(Constants.RESULT_ARIT_MEAN) / 256 normalizerDriver.getDoubleParam(Constants.RESULT_ARIT_MEAN)), 257 di.getName(), 258 "Arithmetic Mean"); 259 dataset.addValue( 260 normalizerDriver == di ? 100.0 : 261 (100.0 * di.getDoubleParam(Constants.RESULT_GEOM_MEAN) / 262 normalizerDriver.getDoubleParam(Constants.RESULT_GEOM_MEAN)), 263 di.getName(), 264 "Geometric Mean"); 265 dataset.addValue( 266 normalizerDriver == di ? 100.0 : 267 (100.0 * di.getDoubleParam(Constants.RESULT_HARM_MEAN) / 268 normalizerDriver.getDoubleParam(Constants.RESULT_HARM_MEAN)), 269 di.getName(), 270 "Harmonic Mean"); 271 } 272 else { 273 dataset.addValue( 274 di.getDoubleParam(Constants.RESULT_ARIT_MEAN), 275 di.getName(), 276 "Arithmetic Mean"); 277 dataset.addValue( 278 di.getDoubleParam(Constants.RESULT_GEOM_MEAN), 279 di.getName(), 280 "Geometric Mean"); 281 dataset.addValue( 282 di.getDoubleParam(Constants.RESULT_HARM_MEAN), 283 di.getName(), 284 "Harmonic Mean"); 285 } 286 } 287 288 JFreeChart chart = ChartFactory.createBarChart3D( 289 "Result Summary (" + resultUnit + ")", 290 "", resultUnit, 291 dataset, 292 PlotOrientation.VERTICAL, 293 true, true, false); 294 chart.setAntiAlias(true); 295 296 ChartUtilities.saveChartAsJPEG(new File (fileName), chart, 600, 450); 297 } 298 catch (Exception e) { 299 e.printStackTrace(); 300 } 301 } 302 303 public int generateTestCaseCharts(String baseName, String extension) { 304 int nOfFiles = 0; 305 final int maxGroupSize = 5; 306 307 final int nOfTests = 309 ((DriverInfo) _driverInfo.get(0)).getAggregateTestCases().size(); 310 311 int groupSizesIndex = 0; 312 int[] groupSizes = calculateGroupSizes(nOfTests, maxGroupSize); 313 314 try { 315 String resultUnit = getParam(Constants.RESULT_UNIT); 316 317 DriverInfo normalizerDriver = null; 319 320 Iterator jdi = _driverInfo.iterator(); 321 while (jdi.hasNext()) { 322 DriverInfo di = (DriverInfo) jdi.next(); 323 if (di.isNormal()) { 324 normalizerDriver = di; 325 resultUnit = "% of " + resultUnit; 326 break; 327 } 328 } 329 330 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 332 333 int i = 0, thisGroupSize = 0; 334 for (; i < nOfTests; i++) { 335 jdi = _driverInfo.iterator(); 336 337 while (jdi.hasNext()) { 338 DriverInfo di = (DriverInfo) jdi.next(); 339 TestCase tc = (TestCase) di.getAggregateTestCases().get(i); 340 341 if (normalizerDriver != null) { 343 TestCase normalTc = 344 (TestCase) normalizerDriver.getAggregateTestCases().get(i); 345 dataset.addValue(normalizerDriver == di ? 100.0 : 346 (100.0 * tc.getDoubleParam(Constants.RESULT_VALUE) / 347 normalTc.getDoubleParam(Constants.RESULT_VALUE)), 348 di.getName(), 349 tc.getTestName()); 350 } 351 else { 352 dataset.addValue( 353 tc.getDoubleParam(Constants.RESULT_VALUE), 354 di.getName(), 355 tc.getTestName()); 356 } 357 } 358 359 thisGroupSize++; 360 361 if (thisGroupSize == groupSizes[groupSizesIndex]) { 363 JFreeChart chart = ChartFactory.createBarChart3D( 364 "Results per Test (" + resultUnit + ")", 365 "", resultUnit, 366 dataset, 367 PlotOrientation.VERTICAL, 368 true, true, false); 369 chart.setAntiAlias(true); 370 ChartUtilities.saveChartAsJPEG( 371 new File (baseName + Integer.toString(nOfFiles) + extension), 372 chart, 600, 450); 373 374 nOfFiles++; 375 groupSizesIndex++; 376 thisGroupSize = 0; 377 dataset = new DefaultCategoryDataset(); 378 } 379 } 380 } 381 catch (Exception e) { 382 e.printStackTrace(); 383 } 384 385 return nOfFiles; 386 } 387 388 393 private static int[] calculateGroupSizes(int nOfTests, int maxGroupSize) { 394 if (nOfTests <= maxGroupSize) { 395 return new int[] { nOfTests }; 396 } 397 398 int[] result = new int[nOfTests / maxGroupSize + 399 ((nOfTests % maxGroupSize > 0) ? 1 : 0)]; 400 401 int m1 = (nOfTests - maxGroupSize) / maxGroupSize; 403 for (int i = 0; i < m1; i++) { 404 result[i] = maxGroupSize; 405 } 406 407 int m2 = nOfTests - m1 * maxGroupSize; 409 if (m2 <= maxGroupSize) { 410 result[result.length - 1] = m2; 411 } 412 else { 413 result[result.length - 2] = (int) Math.ceil(m2 / 2.0); 415 result[result.length - 1] = m2 - result[result.length - 2]; 416 } 417 return result; 418 } 419 420 } 421 | Popular Tags |