| 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 Date startTime; | 499 Date startTime; |
| 500 Timer timeoutTimer; | 500 Timer timeoutTimer; |
| 501 List<String> stdout; | 501 List<String> stdout; |
| 502 List<String> stderr; | 502 List<String> stderr; |
| 503 List<Function> handlers; | 503 List<Function> handlers; |
| 504 bool allowRetries; | 504 bool allowRetries; |
| 505 | 505 |
| 506 /** Which command of [testCase.commands] is currently being executed. */ | 506 /** Which command of [testCase.commands] is currently being executed. */ |
| 507 int currentStep; | 507 int currentStep; |
| 508 | 508 |
| 509 static final int kErrorStartingProcess = -171717; // Chosen arbitrarily. | |
| 510 | |
| 511 RunningProcess(TestCase this.testCase, | 509 RunningProcess(TestCase this.testCase, |
| 512 [this.allowRetries = false, this.processQueue]); | 510 [this.allowRetries = false, this.processQueue]); |
| 513 | 511 |
| 514 /** | 512 /** |
| 515 * Called when all commands are executed. [exitCode] is 0 if all command | 513 * Called when all commands are executed. [exitCode] is 0 if all command |
| 516 * succeded, otherwise it will have the exit code of the first failing | 514 * succeded, otherwise it will have the exit code of the first failing |
| 517 * command. | 515 * command. |
| 518 */ | 516 */ |
| 519 void testComplete(int exitCode) { | 517 void testComplete(int exitCode) { |
| 520 new TestOutput.fromCase(testCase, exitCode, timedOut, stdout, | 518 new TestOutput.fromCase(testCase, exitCode, timedOut, stdout, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 544 testCase.completed(); | 542 testCase.completed(); |
| 545 } | 543 } |
| 546 } | 544 } |
| 547 | 545 |
| 548 /** | 546 /** |
| 549 * Process exit handler called at the end of every command. It internally | 547 * Process exit handler called at the end of every command. It internally |
| 550 * treats all but the last command as compilation steps. The last command is | 548 * treats all but the last command as compilation steps. The last command is |
| 551 * the actual test and its output is analyzed in [testComplete]. | 549 * the actual test and its output is analyzed in [testComplete]. |
| 552 */ | 550 */ |
| 553 void stepExitHandler(int exitCode) { | 551 void stepExitHandler(int exitCode) { |
| 554 try { | 552 process.close(); |
| 555 process.close(); | |
| 556 } catch (ProcessException e) { | |
| 557 // If the process is already closed, continue. | |
| 558 } | |
| 559 int totalSteps = testCase.commands.length; | 553 int totalSteps = testCase.commands.length; |
| 560 String suffix =' (step $currentStep of $totalSteps)'; | 554 String suffix =' (step $currentStep of $totalSteps)'; |
| 561 if (currentStep == totalSteps) { // done with test command | 555 if (currentStep == totalSteps) { // done with test command |
| 562 testComplete(exitCode); | 556 testComplete(exitCode); |
| 563 } else if (exitCode != 0) { | 557 } else if (exitCode != 0) { |
| 564 stderr.add('test.dart: Compilation failed$suffix, exit code $exitCode\n'); | 558 stderr.add('test.dart: Compilation failed$suffix, exit code $exitCode\n'); |
| 565 testComplete(exitCode); | 559 testComplete(exitCode); |
| 566 } else { | 560 } else { |
| 567 stderr.add('test.dart: Compilation finished $suffix\n'); | 561 stderr.add('test.dart: Compilation finished $suffix\n'); |
| 568 stdout.add('test.dart: Compilation finished $suffix\n'); | 562 stdout.add('test.dart: Compilation finished $suffix\n'); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 599 void runCommand(Command command, | 593 void runCommand(Command command, |
| 600 void exitHandler(int exitCode)) { | 594 void exitHandler(int exitCode)) { |
| 601 if (Platform.operatingSystem() == 'windows') { | 595 if (Platform.operatingSystem() == 'windows') { |
| 602 // Windows can't handle the first command if it is a .bat file or the like | 596 // Windows can't handle the first command if it is a .bat file or the like |
| 603 // with the slashes going the other direction. | 597 // with the slashes going the other direction. |
| 604 // TODO(efortuna): Remove this when fixed (Issue 1306). | 598 // TODO(efortuna): Remove this when fixed (Issue 1306). |
| 605 command.executable = command.executable.replaceAll('/', '\\'); | 599 command.executable = command.executable.replaceAll('/', '\\'); |
| 606 } | 600 } |
| 607 process = new Process.start(command.executable, command.arguments); | 601 process = new Process.start(command.executable, command.arguments); |
| 608 process.onExit = exitHandler; | 602 process.onExit = exitHandler; |
| 609 process.onError = (error) { exitHandler(kErrorStartingProcess); }; | |
| 610 startTime = new Date.now(); | 603 startTime = new Date.now(); |
| 611 InputStream stdoutStream = process.stdout; | 604 InputStream stdoutStream = process.stdout; |
| 612 InputStream stderrStream = process.stderr; | 605 InputStream stderrStream = process.stderr; |
| 613 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); | 606 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); |
| 614 StringInputStream stderrStringStream = new StringInputStream(stderrStream); | 607 StringInputStream stderrStringStream = new StringInputStream(stderrStream); |
| 615 stdoutStringStream.onLine = | 608 stdoutStringStream.onLine = |
| 616 makeReadHandler(stdoutStringStream, stdout); | 609 makeReadHandler(stdoutStringStream, stdout); |
| 617 stderrStringStream.onLine = | 610 stderrStringStream.onLine = |
| 618 makeReadHandler(stderrStringStream, stderr); | 611 makeReadHandler(stderrStringStream, stderr); |
| 619 if (timeoutTimer == null) { | 612 if (timeoutTimer == null) { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 // the developer doesn't waste his or her time trying to fix a bunch of | 1136 // the developer doesn't waste his or her time trying to fix a bunch of |
| 1144 // tests that appear to be broken but were actually just flakes that | 1137 // tests that appear to be broken but were actually just flakes that |
| 1145 // didn't get retried because there had already been one failure. | 1138 // didn't get retried because there had already been one failure. |
| 1146 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; | 1139 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; |
| 1147 new RunningProcess(test, allowRetry, this).start(); | 1140 new RunningProcess(test, allowRetry, this).start(); |
| 1148 } | 1141 } |
| 1149 _numProcesses++; | 1142 _numProcesses++; |
| 1150 } | 1143 } |
| 1151 } | 1144 } |
| 1152 } | 1145 } |
| OLD | NEW |