OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Classes and methods for executing tests. | 6 * Classes and methods for executing tests. |
7 * | 7 * |
8 * This module includes: | 8 * This module includes: |
9 * - Managing parallel execution of tests, including timeout checks. | 9 * - Managing parallel execution of tests, including timeout checks. |
10 * - Evaluating the output of each test as pass/fail/crash/timeout. | 10 * - Evaluating the output of each test as pass/fail/crash/timeout. |
(...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 maxProcesses, | 2248 maxProcesses, |
2249 maxBrowserProcesses, | 2249 maxBrowserProcesses, |
2250 DateTime startTime, | 2250 DateTime startTime, |
2251 testSuites, | 2251 testSuites, |
2252 this._eventListener, | 2252 this._eventListener, |
2253 this._allDone, | 2253 this._allDone, |
2254 [bool verbose = false, | 2254 [bool verbose = false, |
2255 this._listTests = false, | 2255 this._listTests = false, |
2256 String recordingOutputFile, | 2256 String recordingOutputFile, |
2257 String recordedInputFile]) { | 2257 String recordedInputFile]) { |
2258 bool recording = recordingOutputFile != null; | 2258 void setupForListing(TestCaseEnqueuer testCaseEnqueuer) { |
2259 bool replaying = recordedInputFile != null; | 2259 _graph.events.where((event) => event is dgraph.GraphSealedEvent) |
| 2260 .listen((dgraph.GraphSealedEvent event) { |
| 2261 var testCases = new List.from(testCaseEnqueuer.remainingTestCases); |
| 2262 testCases.sort((a, b) => a.displayName.compareTo(b.displayName)); |
2260 | 2263 |
2261 // When the graph building is finished, notify event listeners. | 2264 print("\nGenerating all matching test cases ....\n"); |
2262 _graph.events | 2265 |
2263 .where((event) => event is dgraph.GraphSealedEvent).listen((event) { | 2266 for (TestCase testCase in testCases) { |
2264 eventAllTestsKnown(); | 2267 print("${testCase.displayName} " |
2265 }); | 2268 "Expectations: ${testCase.expectedOutcomes.join(', ')} " |
| 2269 "Configuration: '${testCase.configurationString}'"); |
| 2270 } |
| 2271 }); |
| 2272 } |
| 2273 |
| 2274 void setupForRunning(TestCaseEnqueuer testCaseEnqueuer) { |
| 2275 bool recording = recordingOutputFile != null; |
| 2276 bool replaying = recordedInputFile != null; |
| 2277 |
| 2278 // When the graph building is finished, notify event listeners. |
| 2279 _graph.events |
| 2280 .where((event) => event is dgraph.GraphSealedEvent).listen((event) { |
| 2281 eventAllTestsKnown(); |
| 2282 }); |
| 2283 |
| 2284 // Queue commands as they become "runnable" |
| 2285 var commandEnqueuer = new CommandEnqueuer(_graph); |
| 2286 |
| 2287 // CommandExecutor will execute commands |
| 2288 var executor; |
| 2289 if (recording) { |
| 2290 executor = new RecordingCommandExecutor(new Path(recordingOutputFile)); |
| 2291 } else if (replaying) { |
| 2292 executor = new ReplayingCommandExecutor(new Path(recordedInputFile)); |
| 2293 } else { |
| 2294 executor = new CommandExecutorImpl( |
| 2295 _globalConfiguration, maxProcesses, maxBrowserProcesses); |
| 2296 } |
| 2297 |
| 2298 // Run "runnable commands" using [executor] subject to |
| 2299 // maxProcesses/maxBrowserProcesses constraint |
| 2300 var commandQueue = new CommandQueue( |
| 2301 _graph, testCaseEnqueuer, executor, maxProcesses, maxBrowserProcesses, |
| 2302 verbose); |
| 2303 |
| 2304 // Finish test cases when all commands were run (or some failed) |
| 2305 var testCaseCompleter = |
| 2306 new TestCaseCompleter(_graph, testCaseEnqueuer, commandQueue); |
| 2307 testCaseCompleter.finishedTestCases.listen( |
| 2308 (TestCase finishedTestCase) { |
| 2309 // If we're recording, we don't report any TestCases to listeners. |
| 2310 if (!recording) { |
| 2311 eventFinishedTestCase(finishedTestCase); |
| 2312 } |
| 2313 }, |
| 2314 onDone: () { |
| 2315 // Wait until the commandQueue/execturo is done (it may need to stop |
| 2316 // batch runners, browser controllers, ....) |
| 2317 commandQueue.done.then((_) => eventAllTestsDone()); |
| 2318 }); |
| 2319 } |
2266 | 2320 |
2267 // Build up the dependency graph | 2321 // Build up the dependency graph |
2268 var testCaseEnqueuer = new TestCaseEnqueuer(_graph, (TestCase newTestCase) { | 2322 var testCaseEnqueuer = new TestCaseEnqueuer(_graph, (TestCase newTestCase) { |
2269 eventTestAdded(newTestCase); | 2323 eventTestAdded(newTestCase); |
2270 }); | 2324 }); |
2271 | 2325 |
2272 // Queue commands as they become "runnable" | 2326 // Either list or run the tests |
2273 var commandEnqueuer = new CommandEnqueuer(_graph); | 2327 if (_globalConfiguration['list']) { |
2274 | 2328 setupForListing(testCaseEnqueuer); |
2275 // CommandExecutor will execute commands | |
2276 var executor; | |
2277 if (recording) { | |
2278 executor = new RecordingCommandExecutor(new Path(recordingOutputFile)); | |
2279 } else if (replaying) { | |
2280 executor = new ReplayingCommandExecutor(new Path(recordedInputFile)); | |
2281 } else { | 2329 } else { |
2282 executor = new CommandExecutorImpl( | 2330 setupForRunning(testCaseEnqueuer); |
2283 _globalConfiguration, maxProcesses, maxBrowserProcesses); | |
2284 } | 2331 } |
2285 | 2332 |
2286 // Run "runnable commands" using [executor] subject to | |
2287 // maxProcesses/maxBrowserProcesses constraint | |
2288 var commandQueue = new CommandQueue( | |
2289 _graph, testCaseEnqueuer, executor, maxProcesses, maxBrowserProcesses, | |
2290 verbose); | |
2291 | |
2292 // Finish test cases when all commands were run (or some failed) | |
2293 var testCaseCompleter = | |
2294 new TestCaseCompleter(_graph, testCaseEnqueuer, commandQueue); | |
2295 testCaseCompleter.finishedTestCases.listen( | |
2296 (TestCase finishedTestCase) { | |
2297 // If we're recording, we don't report any TestCases to listeners. | |
2298 if (!recording) { | |
2299 eventFinishedTestCase(finishedTestCase); | |
2300 } | |
2301 }, | |
2302 onDone: () { | |
2303 // Wait until the commandQueue/execturo is done (it may need to stop | |
2304 // batch runners, browser controllers, ....) | |
2305 commandQueue.done.then((_) => eventAllTestsDone()); | |
2306 }); | |
2307 | |
2308 // Start enqueing all TestCases | 2333 // Start enqueing all TestCases |
2309 testCaseEnqueuer.enqueueTestSuites(testSuites); | 2334 testCaseEnqueuer.enqueueTestSuites(testSuites); |
2310 } | 2335 } |
2311 | 2336 |
2312 void eventFinishedTestCase(TestCase testCase) { | 2337 void eventFinishedTestCase(TestCase testCase) { |
2313 for (var listener in _eventListener) { | 2338 for (var listener in _eventListener) { |
2314 listener.done(testCase); | 2339 listener.done(testCase); |
2315 } | 2340 } |
2316 } | 2341 } |
2317 | 2342 |
2318 void eventTestAdded(TestCase testCase) { | 2343 void eventTestAdded(TestCase testCase) { |
2319 for (var listener in _eventListener) { | 2344 for (var listener in _eventListener) { |
2320 listener.testAdded(); | 2345 listener.testAdded(); |
2321 } | 2346 } |
2322 } | 2347 } |
2323 | 2348 |
2324 void eventAllTestsKnown() { | 2349 void eventAllTestsKnown() { |
2325 for (var listener in _eventListener) { | 2350 for (var listener in _eventListener) { |
2326 listener.allTestsKnown(); | 2351 listener.allTestsKnown(); |
2327 } | 2352 } |
2328 } | 2353 } |
2329 | 2354 |
2330 void eventAllTestsDone() { | 2355 void eventAllTestsDone() { |
2331 for (var listener in _eventListener) { | 2356 for (var listener in _eventListener) { |
2332 listener.allDone(); | 2357 listener.allDone(); |
2333 } | 2358 } |
2334 _allDone(); | 2359 _allDone(); |
2335 } | 2360 } |
2336 } | 2361 } |
OLD | NEW |