1 39 40 package com.sun.japex; 41 42 import java.util.*; 43 import java.text.*; 44 import java.net.*; 45 import java.io.File ; 46 47 public class Engine { 48 49 public Engine() { 50 } 51 52 public TestSuite start(String configFile) { 53 TestSuite testSuite = null; 54 Boolean computeResult = null; 55 56 try { 57 ConfigFileLoader cfl = new ConfigFileLoader(configFile); 59 testSuite = cfl.getTestSuite(); 60 61 Iterator jdi = testSuite.getDriverInfoList().iterator(); 63 while (jdi.hasNext()) { 64 DriverInfo di = (DriverInfo) jdi.next(); 65 66 System.out.print(" " + di.getName()); 68 69 int runsPerDriver = testSuite.getIntParam(Constants.RUNS_PER_DRIVER); 70 71 int nOfThreads = testSuite.getIntParam(Constants.NUMBER_OF_THREADS); 73 JapexDriverBase drivers[][] = new JapexDriverBase[nOfThreads][runsPerDriver]; 74 for (int i = 0; i < nOfThreads; i++) { 75 for (int j = 0; j < runsPerDriver; j++) { 76 drivers[i][j] = di.getJapexDriver(); drivers[i][j].setTestSuite(testSuite); 78 drivers[i][j].initializeDriver(); 79 } 80 } 81 82 for (int driverRun = 0; driverRun < runsPerDriver; driverRun++) { 83 System.out.print("\n Run " + (driverRun + 1) + ": "); 84 85 List tcList = di.getTestCases(driverRun); 87 int nOfTests = tcList.size(); 88 89 double geomMeanresult = 1.0; 91 double aritMeanresult = 0.0; 93 double harmMeanresultInverse = 0.0; 95 96 Iterator tci = tcList.iterator(); 98 while (tci.hasNext()) { 99 long runTime = 0L; 100 TestCase tc = (TestCase) tci.next(); 101 102 System.out.print(tc.getTestName() + ","); 103 104 if (nOfThreads == 1) { 106 drivers[0][driverRun].setTestCase(tc); drivers[0][driverRun].prepareAndWarmup(); 108 109 runTime = Util.currentTimeMillis(); 111 112 drivers[0][driverRun].run(); 113 } 114 else { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); 116 117 Thread threads[] = new Thread [nOfThreads]; 119 for (int i = 0; i < nOfThreads; i++) { 120 threads[i] = new Thread (drivers[i][driverRun]); 121 threads[i].setPriority(Thread.MAX_PRIORITY); 122 } 123 124 for (int i = 0; i < nOfThreads; i++) { 127 drivers[i][driverRun].setTestCase(tc); drivers[i][driverRun].prepareAndWarmup(); 129 } 130 131 runTime = Util.currentTimeMillis(); 133 134 for (int i = 0; i < nOfThreads; i++) { 136 threads[i].start(); 137 } 138 139 for (int i = 0; i < nOfThreads; i++) { 141 threads[i].join(); 142 } 143 } 144 145 runTime = Util.currentTimeMillis() - runTime; 147 148 if (!testSuite.hasParam(Constants.RUN_TIME)) { 150 tc.setDoubleParam(Constants.ACTUAL_RUN_TIME, runTime); 151 } 152 153 for (int i = 0; i < nOfThreads; i++) { 155 drivers[i][driverRun].finish(tc); 156 } 157 158 double result = 0.0; 159 160 if (computeResult == null) { 161 if (!tc.hasParam(Constants.RESULT_VALUE)) { 162 result = 163 tc.getIntParam(Constants.ACTUAL_RUN_ITERATIONS) / 164 (runTime / 1000.0); 165 testSuite.setParam(Constants.RESULT_UNIT, "TPS"); 166 167 computeResult = Boolean.TRUE; 168 tc.setDoubleParam(Constants.RESULT_VALUE, result); 169 } 170 else { 171 result = tc.getDoubleParam(Constants.RESULT_VALUE); 172 computeResult = Boolean.FALSE; 173 } 174 } 175 else if (computeResult == Boolean.TRUE 176 && !tc.hasParam(Constants.RESULT_VALUE)) 177 { 178 result = 179 tc.getIntParam(Constants.ACTUAL_RUN_ITERATIONS) / 180 (runTime / 1000.0); 181 tc.setDoubleParam(Constants.RESULT_VALUE, result); 182 } 183 else if (computeResult == Boolean.FALSE 184 && tc.hasParam(Constants.RESULT_VALUE)) 185 { 186 result = tc.getDoubleParam(Constants.RESULT_VALUE); 187 } 188 else { 189 throw new RuntimeException ( 190 "The output parameter '" + Constants.RESULT_VALUE 191 + "' must be computed by either all or none of " 192 + "the drivers for the results to be comparable"); 193 } 194 195 aritMeanresult += result / nOfTests; 197 geomMeanresult *= Math.pow(result, 1.0 / nOfTests); 198 harmMeanresultInverse += 1.0 / (nOfTests * result); 199 200 System.out.print(tc.getDoubleParam(Constants.RESULT_VALUE) + ","); 202 System.out.flush(); 203 } 204 205 206 System.out.print( 207 "aritmean," + Util.formatDouble(aritMeanresult) + 208 ",geommean," + Util.formatDouble(geomMeanresult) + 209 ",harmmean," + Util.formatDouble(1.0 / harmMeanresultInverse)); 210 211 for (int i = 0; i < nOfThreads; i++) { 213 drivers[i][driverRun].terminateDriver(); 214 } 215 } 216 217 if (runsPerDriver > 1) { 218 System.out.print("\n Avgs: "); 220 Iterator tci = di.getAggregateTestCases().iterator(); 221 while (tci.hasNext()) { 222 TestCase tc = (TestCase) tci.next(); 223 System.out.print(tc.getTestName() + ","); 224 System.out.print(tc.getDoubleParam(Constants.RESULT_VALUE) + ","); 225 } 226 System.out.print( 227 "aritmean," + 228 di.getDoubleParam(Constants.RESULT_ARIT_MEAN) + 229 ",geommean," + 230 di.getDoubleParam(Constants.RESULT_GEOM_MEAN) + 231 ",harmmean," + 232 di.getDoubleParam(Constants.RESULT_HARM_MEAN)); 233 234 System.out.print("\n Stdev: "); 236 tci = di.getAggregateTestCases().iterator(); 237 while (tci.hasNext()) { 238 TestCase tc = (TestCase) tci.next(); 239 System.out.print(tc.getTestName() + ","); 240 System.out.print(tc.getDoubleParam(Constants.RESULT_VALUE_STDDEV) + ","); 241 } 242 System.out.println( 243 "aritmean," + 244 di.getDoubleParam(Constants.RESULT_ARIT_MEAN_STDDEV) + 245 ",geommean," + 246 di.getDoubleParam(Constants.RESULT_GEOM_MEAN_STDDEV) + 247 ",harmmean," + 248 di.getDoubleParam(Constants.RESULT_HARM_MEAN_STDDEV)); 249 } 250 else { 251 System.out.println(""); 252 } 253 } 254 } 255 catch (Exception e) { 256 e.printStackTrace(); 257 throw new RuntimeException (e); 258 } 259 260 return testSuite; 261 } 262 } 263 | Popular Tags |