| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 String _executable; | 383 String _executable; |
| 384 List<String> _batchArguments; | 384 List<String> _batchArguments; |
| 385 | 385 |
| 386 Process _process; | 386 Process _process; |
| 387 StringInputStream _stdoutStream; | 387 StringInputStream _stdoutStream; |
| 388 StringInputStream _stderrStream; | 388 StringInputStream _stderrStream; |
| 389 | 389 |
| 390 TestCase _currentTest; | 390 TestCase _currentTest; |
| 391 List<String> _testStdout; | 391 List<String> _testStdout; |
| 392 List<String> _testStderr; | 392 List<String> _testStderr; |
| 393 bool _stdoutDrained = false; |
| 393 bool _stderrDrained = false; | 394 bool _stderrDrained = false; |
| 394 Date _startTime; | 395 Date _startTime; |
| 395 Timer _timer; | 396 Timer _timer; |
| 396 | 397 |
| 397 bool _isWebDriver; | 398 bool _isWebDriver; |
| 398 | 399 |
| 399 BatchRunnerProcess(TestCase testCase) { | 400 BatchRunnerProcess(TestCase testCase) { |
| 400 _executable = testCase.commands.last().executable; | 401 _executable = testCase.commands.last().executable; |
| 401 _batchArguments = testCase.batchRunnerArguments; | 402 _batchArguments = testCase.batchRunnerArguments; |
| 402 _isWebDriver = testCase.configuration['component'] == 'webdriver'; | 403 _isWebDriver = testCase.configuration['component'] == 'webdriver'; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } else { | 449 } else { |
| 449 _process.kill(); | 450 _process.kill(); |
| 450 } | 451 } |
| 451 } | 452 } |
| 452 } | 453 } |
| 453 | 454 |
| 454 void doStartTest(TestCase testCase) { | 455 void doStartTest(TestCase testCase) { |
| 455 _startTime = new Date.now(); | 456 _startTime = new Date.now(); |
| 456 _testStdout = new List<String>(); | 457 _testStdout = new List<String>(); |
| 457 _testStderr = new List<String>(); | 458 _testStderr = new List<String>(); |
| 459 _stdoutDrained = false; |
| 458 _stderrDrained = false; | 460 _stderrDrained = false; |
| 459 _stdoutStream.onLine = _readStdout(_stdoutStream, _testStdout); | 461 _stdoutStream.onLine = _readStdout(_stdoutStream, _testStdout); |
| 460 _stderrStream.onLine = _readStderr(_stderrStream, _testStderr); | 462 _stderrStream.onLine = _readStderr(_stderrStream, _testStderr); |
| 461 _timer = new Timer(_timeoutHandler, testCase.timeout * 1000); | 463 _timer = new Timer(_timeoutHandler, testCase.timeout * 1000); |
| 462 var line = _createArgumentsLine(testCase.batchTestArguments); | 464 var line = _createArgumentsLine(testCase.batchTestArguments); |
| 463 _process.stdin.write(line.charCodes()); | 465 _process.stdin.write(line.charCodes()); |
| 464 } | 466 } |
| 465 | 467 |
| 466 String _createArgumentsLine(List<String> arguments) { | 468 String _createArgumentsLine(List<String> arguments) { |
| 467 return Strings.join(arguments, ' ') + '\n'; | 469 return Strings.join(arguments, ' ') + '\n'; |
| 468 } | 470 } |
| 469 | 471 |
| 470 void _testCompleted() { | 472 void _testCompleted() { |
| 471 var test = _currentTest; | 473 var test = _currentTest; |
| 472 _currentTest = null; | 474 _currentTest = null; |
| 473 test.completed(); | 475 test.completed(); |
| 474 } | 476 } |
| 475 | 477 |
| 476 int _reportResult(String output) { | 478 int _reportResult(String output) { |
| 479 _stdoutDrained = true; |
| 477 // output = '>>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT}' | 480 // output = '>>> TEST {PASS, FAIL, OK, CRASH, FAIL, TIMEOUT}' |
| 478 var outcome = output.split(" ")[2]; | 481 var outcome = output.split(" ")[2]; |
| 479 var exitCode = 0; | 482 var exitCode = 0; |
| 480 if (outcome == "CRASH") exitCode = -10; | 483 if (outcome == "CRASH") exitCode = -10; |
| 481 if (outcome == "FAIL" || outcome == "TIMEOUT") exitCode = 1; | 484 if (outcome == "FAIL" || outcome == "TIMEOUT") exitCode = 1; |
| 482 new TestOutput(_currentTest, exitCode, outcome == "TIMEOUT", _testStdout, | 485 new TestOutput(_currentTest, exitCode, outcome == "TIMEOUT", _testStdout, |
| 483 _testStderr, new Date.now().difference(_startTime)); | 486 _testStderr, new Date.now().difference(_startTime)); |
| 484 // Move on when both stdout and stderr has been drained. | 487 // Move on when both stdout and stderr has been drained. |
| 485 if (_stderrDrained) _testCompleted(); | 488 if (_stderrDrained) _testCompleted(); |
| 486 } | 489 } |
| 487 | 490 |
| 488 void _stderrDone() { | 491 void _stderrDone() { |
| 489 _stderrDrained = true; | 492 _stderrDrained = true; |
| 490 // Move on when both stdout and stderr has been drained. | 493 // Move on when both stdout and stderr has been drained. |
| 491 if (_currentTest.output != null) _testCompleted(); | 494 if (_stdoutDrained) _testCompleted(); |
| 492 } | 495 } |
| 493 | 496 |
| 494 Function _readStdout(StringInputStream stream, List<String> buffer) { | 497 Function _readStdout(StringInputStream stream, List<String> buffer) { |
| 495 return () { | 498 return () { |
| 496 var status; | 499 var status; |
| 497 var line = stream.readLine(); | 500 var line = stream.readLine(); |
| 498 while (line != null) { | 501 while (line != null) { |
| 499 if (line.startsWith('>>> TEST')) { | 502 if (line.startsWith('>>> TEST')) { |
| 500 status = line; | 503 status = line; |
| 501 } else if (line.startsWith('>>> BATCH START')) { | 504 } else if (line.startsWith('>>> BATCH START')) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 }; | 551 }; |
| 549 _process.kill(); | 552 _process.kill(); |
| 550 } | 553 } |
| 551 | 554 |
| 552 void _startProcess(then) { | 555 void _startProcess(then) { |
| 553 _process = new Process.start(_executable, _batchArguments); | 556 _process = new Process.start(_executable, _batchArguments); |
| 554 _stdoutStream = new StringInputStream(_process.stdout); | 557 _stdoutStream = new StringInputStream(_process.stdout); |
| 555 _stderrStream = new StringInputStream(_process.stderr); | 558 _stderrStream = new StringInputStream(_process.stderr); |
| 556 _testStdout = new List<String>(); | 559 _testStdout = new List<String>(); |
| 557 _testStderr = new List<String>(); | 560 _testStderr = new List<String>(); |
| 561 _stdoutDrained = false; |
| 558 _stderrDrained = false; | 562 _stderrDrained = false; |
| 559 _stdoutStream.onLine = _readStdout(_stdoutStream, _testStdout); | 563 _stdoutStream.onLine = _readStdout(_stdoutStream, _testStdout); |
| 560 _stderrStream.onLine = _readStderr(_stderrStream, _testStderr); | 564 _stderrStream.onLine = _readStderr(_stderrStream, _testStderr); |
| 561 _process.onExit = _exitHandler; | 565 _process.onExit = _exitHandler; |
| 562 _process.onStart = then; | 566 _process.onStart = then; |
| 563 } | 567 } |
| 564 } | 568 } |
| 565 | 569 |
| 566 /** | 570 /** |
| 567 * ProcessQueue is the master control class, responsible for running all | 571 * ProcessQueue is the master control class, responsible for running all |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // the developer doesn't waste his or her time trying to fix a bunch of | 805 // the developer doesn't waste his or her time trying to fix a bunch of |
| 802 // tests that appear to be broken but were actually just flakes that | 806 // tests that appear to be broken but were actually just flakes that |
| 803 // didn't get retried because there had already been one failure. | 807 // didn't get retried because there had already been one failure. |
| 804 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; | 808 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; |
| 805 new RunningProcess(test, allowRetry, this).start(); | 809 new RunningProcess(test, allowRetry, this).start(); |
| 806 } | 810 } |
| 807 _numProcesses++; | 811 _numProcesses++; |
| 808 } | 812 } |
| 809 } | 813 } |
| 810 } | 814 } |
| OLD | NEW |