1 39 40 package com.sun.japex; 41 42 import java.util.*; 43 import java.net.*; 44 import java.io.File ; 45 46 public class DriverInfo extends Params { 47 48 String _name; 49 JapexClassLoader _classLoader; 50 Class _class = null; 51 boolean _isNormal = false; 52 boolean _computeMeans = true; 53 54 TestCaseArrayList[] _testCases; 55 TestCaseArrayList _aggregateTestCases; 56 57 int _runsPerDriver; 58 59 static class JapexClassLoader extends URLClassLoader { 60 public JapexClassLoader(URL[] urls) { 61 super(urls); 62 } 63 public Class findClass(String name) throws ClassNotFoundException { 64 return super.findClass(name); 65 } 66 public void addURL(URL url) { 67 super.addURL(url); 68 } 69 } 70 71 public DriverInfo(String name, boolean isNormal, int runsPerDriver, 72 Properties params) 73 { 74 super(params); 75 _name = name; 76 _isNormal = isNormal; 77 _classLoader = newJapexClassLoader(); 78 79 _runsPerDriver = runsPerDriver; 80 } 81 82 public void setTestCases(TestCaseArrayList testCases) { 83 _testCases = new TestCaseArrayList[_runsPerDriver]; 84 for (int i = 0; i < _runsPerDriver; i++) { 85 _testCases[i] = (TestCaseArrayList) testCases.clone(); 86 } 87 88 _aggregateTestCases = (TestCaseArrayList) testCases.clone(); 89 } 90 91 private void computeMeans() { 92 final int runsPerDriver = _testCases.length; 93 94 if (_computeMeans) { 96 final int nOfTests = _testCases[0].size(); 97 98 for (int n = 0; n < nOfTests; n++) { 99 double avgRunsResult = 0.0; 100 101 double[] results = new double[runsPerDriver]; 102 103 for (int i = 0; i < runsPerDriver; i++) { 105 TestCase tc = (TestCase) _testCases[i].get(n); 106 results[i] = tc.getDoubleParam(Constants.RESULT_VALUE); 107 } 108 109 TestCase tc = (TestCase) _aggregateTestCases.get(n); 110 tc.setDoubleParam(Constants.RESULT_VALUE, Util.arithmeticMean(results)); 111 if (runsPerDriver > 1) { 112 tc.setDoubleParam(Constants.RESULT_VALUE_STDDEV, 113 runsPerDriver > 1 ? Util.standardDev(results) : 0.0); 114 } 115 } 116 117 double geomMeanresult = 1.0; 119 double aritMeanresult = 0.0; 121 double harmMeanresultInverse = 0.0; 123 124 Iterator tci = _aggregateTestCases.iterator(); 126 while (tci.hasNext()) { 127 TestCase tc = (TestCase) tci.next(); 128 double result = tc.getDoubleParam(Constants.RESULT_VALUE); 129 130 aritMeanresult += result / nOfTests; 132 geomMeanresult *= Math.pow(result, 1.0 / nOfTests); 133 harmMeanresultInverse += 1.0 / (nOfTests * result); 134 } 135 136 setDoubleParam(Constants.RESULT_ARIT_MEAN, aritMeanresult); 138 setDoubleParam(Constants.RESULT_GEOM_MEAN, geomMeanresult); 139 setDoubleParam(Constants.RESULT_HARM_MEAN, 1.0 / harmMeanresultInverse); 140 141 _computeMeans = false; 143 144 if (runsPerDriver == 1) { 146 return; 147 } 148 149 geomMeanresult = 1.0; 151 aritMeanresult = 0.0; 153 harmMeanresultInverse = 0.0; 155 156 tci = _aggregateTestCases.iterator(); 158 while (tci.hasNext()) { 159 TestCase tc = (TestCase) tci.next(); 160 double result = tc.getDoubleParam(Constants.RESULT_VALUE_STDDEV); 161 162 aritMeanresult += result / nOfTests; 164 geomMeanresult *= Math.pow(result, 1.0 / nOfTests); 165 harmMeanresultInverse += 1.0 / (nOfTests * result); 166 } 167 168 setDoubleParam(Constants.RESULT_ARIT_MEAN_STDDEV, aritMeanresult); 170 setDoubleParam(Constants.RESULT_GEOM_MEAN_STDDEV, geomMeanresult); 171 setDoubleParam(Constants.RESULT_HARM_MEAN_STDDEV, 1.0 / harmMeanresultInverse); 172 } 173 } 174 175 public List getTestCases(int driverRun) { 176 return _testCases[driverRun]; 177 } 178 179 public List getAggregateTestCases() { 180 computeMeans(); 181 return _aggregateTestCases; 182 } 183 184 JapexDriverBase getJapexDriver() throws ClassNotFoundException { 185 String className = getParam(Constants.DRIVER_CLASS); 186 if (_class == null) { 187 _class = _classLoader.findClass(className); 188 } 189 190 try { 191 Thread.currentThread().setContextClassLoader(_classLoader); 192 return (JapexDriverBase) _class.newInstance(); 193 } 194 catch (InstantiationException e) { 195 throw new RuntimeException (e); 196 } 197 catch (IllegalAccessException e) { 198 throw new RuntimeException (e); 199 } 200 catch (ClassCastException e) { 201 throw new RuntimeException ("Class '" + className 202 + "' must extend '" + JapexDriverBase.class.getName() + "'"); 203 } 204 } 205 206 public String getName() { 207 return _name; 208 } 209 210 public boolean isNormal() { 211 return _isNormal; 212 } 213 214 public void serialize(StringBuffer report, int spaces) { 215 report.append(Util.getSpaces(spaces) 216 + "<driver name=\"" + _name + "\">\n"); 217 218 222 Iterator tci = getAggregateTestCases().iterator(); 223 224 super.serialize(report, spaces + 2); 226 227 while (tci.hasNext()) { 229 TestCase tc = (TestCase) tci.next(); 230 tc.serialize(report, spaces + 2); 231 } 232 233 report.append(Util.getSpaces(spaces) + "</driver>\n"); 234 } 235 236 private JapexClassLoader newJapexClassLoader() { 237 JapexClassLoader result = new JapexClassLoader(new URL[0]); 238 String classPath = getParam(Constants.CLASS_PATH); 239 if (classPath == null) { 240 return result; 241 } 242 243 StringTokenizer tokenizer = new StringTokenizer(classPath, 244 System.getProperty("path.separator")); 245 246 while (tokenizer.hasMoreTokens()) { 247 String path = tokenizer.nextToken(); 248 try { 249 result.addURL(new File (path).toURL()); 250 } 251 catch (MalformedURLException e) { 252 } 254 } 255 return result; 256 } 257 } 258 | Popular Tags |