1 39 40 package com.sun.japex; 41 42 import java.util.Properties ; 43 44 public class JapexDriverBase implements JapexDriver { 45 46 private TestSuite _testSuite; 47 private TestCase _testCase; 48 49 public void setTestSuite(TestSuite testSuite) { 50 _testSuite = testSuite; 51 } 52 53 public void setTestCase(TestCase testCase) { 54 _testCase = testCase; 55 } 56 57 protected TestSuite getTestSuite() { 58 return _testSuite; 59 } 60 61 66 public void prepareAndWarmup() { 67 long millis, nanos; 68 TestCase tc = _testCase; 69 70 72 nanos = Util.currentTimeNanos(); 73 prepare(tc); 74 nanos = Util.currentTimeNanos() - nanos; 75 tc.setDoubleParam(Constants.ACTUAL_PREPARE_TIME, 76 Util.nanosToMillis(nanos)); 77 78 80 int warmupIterations = 0; 81 String warmupTime = tc.getParam(Constants.WARMUP_TIME); 82 if (warmupTime != null) { 83 long startTime = millis = Util.currentTimeMillis(); 85 long endTime = startTime + Util.parseDuration(warmupTime); 86 87 while (endTime > millis) { 88 warmup(tc); warmupIterations++; 90 millis = Util.currentTimeMillis(); 91 } 92 93 millis -= startTime; 95 96 tc.setIntParam(Constants.ACTUAL_WARMUP_ITERATIONS, warmupIterations); 98 } 99 else { 100 warmupIterations = tc.getIntParam(Constants.WARMUP_ITERATIONS); 102 103 nanos = Util.currentTimeNanos(); 104 for (int i = 0; i < warmupIterations; i++) { 105 warmup(tc); } 107 nanos = Util.currentTimeNanos() - nanos; 108 109 tc.setDoubleParam(Constants.ACTUAL_WARMUP_TIME, 111 Util.nanosToMillis(nanos)); 112 } 113 } 114 115 117 123 public void run() { 124 long millis, nanos; 125 TestCase tc = _testCase; 126 127 System.gc(); 129 130 int nOfThreads = tc.getIntParam(Constants.NUMBER_OF_THREADS); 132 133 int runIterations = 0; 134 String runTime = tc.getParam(Constants.RUN_TIME); 135 if (runTime != null) { 136 long startTime = Util.currentTimeMillis(); 138 long endTime = startTime + Util.parseDuration(runTime); 139 140 do { 142 run(tc); runIterations++; 144 millis = Util.currentTimeMillis(); 145 } while (endTime >= millis); 146 147 millis -= startTime; 149 } 150 else { 151 runIterations = tc.getIntParam(Constants.RUN_ITERATIONS) / nOfThreads; 153 154 nanos = Util.currentTimeNanos(); 156 for (int i = 0; i < runIterations; i++) { 157 run(tc); } 159 nanos = Util.currentTimeNanos() - nanos; 160 161 } 162 163 synchronized (tc) { 165 int actualRunIterations = 166 tc.hasParam(Constants.ACTUAL_RUN_ITERATIONS) ? 167 tc.getIntParam(Constants.ACTUAL_RUN_ITERATIONS) : 0; 168 tc.setIntParam(Constants.ACTUAL_RUN_ITERATIONS, 169 actualRunIterations + runIterations); 170 } 171 } 172 173 175 178 public void initializeDriver() { 179 } 180 181 184 public void prepare(TestCase testCase) { 185 } 186 187 190 public void warmup(TestCase testCase) { 191 } 192 193 196 public void run(TestCase testCase) { 197 } 198 199 202 public void finish(TestCase testCase) { 203 } 204 205 208 public void terminateDriver() { 209 } 210 211 } 212 | Popular Tags |