| 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 14 matching lines...) Expand all Loading... |
| 25 typedef bool EnqueMoreWork(ProcessQueue queue); | 25 typedef bool EnqueMoreWork(ProcessQueue queue); |
| 26 | 26 |
| 27 /** A command executed as a step in a test case. */ | 27 /** A command executed as a step in a test case. */ |
| 28 class Command { | 28 class Command { |
| 29 /** Path to the executable of this command. */ | 29 /** Path to the executable of this command. */ |
| 30 String executable; | 30 String executable; |
| 31 | 31 |
| 32 /** Command line arguments to the executable. */ | 32 /** Command line arguments to the executable. */ |
| 33 List<String> arguments; | 33 List<String> arguments; |
| 34 | 34 |
| 35 /** Environment variables set when running the command */ |
| 36 Map<String, String> environment; |
| 37 |
| 35 /** The actual command line that will be executed. */ | 38 /** The actual command line that will be executed. */ |
| 36 String commandLine; | 39 String commandLine; |
| 37 | 40 |
| 38 Command(this.executable, this.arguments) { | 41 Command(this.executable, this.arguments, [this.environment = const {}]) { |
| 39 if (Platform.operatingSystem == 'windows') { | 42 if (Platform.operatingSystem == 'windows') { |
| 40 // Windows can't handle the first command if it is a .bat file or the like | 43 // Windows can't handle the first command if it is a .bat file or the like |
| 41 // with the slashes going the other direction. | 44 // with the slashes going the other direction. |
| 42 // TODO(efortuna): Remove this when fixed (Issue 1306). | 45 // TODO(efortuna): Remove this when fixed (Issue 1306). |
| 43 executable = executable.replaceAll('/', '\\'); | 46 executable = executable.replaceAll('/', '\\'); |
| 44 } | 47 } |
| 45 commandLine = "$executable ${Strings.join(arguments, ' ')}"; | 48 commandLine = "$executable ${Strings.join(arguments, ' ')}"; |
| 46 } | 49 } |
| 47 | 50 |
| 48 String toString() => commandLine; | 51 String toString() => commandLine; |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 // This RunningProcess object is done, and hands over control to | 629 // This RunningProcess object is done, and hands over control to |
| 627 // BatchRunner.startTest(), which handles reporting, etc. | 630 // BatchRunner.startTest(), which handles reporting, etc. |
| 628 timeoutTimer.cancel(); | 631 timeoutTimer.cancel(); |
| 629 processQueue._getBatchRunner(testCase).startTest(testCase); | 632 processQueue._getBatchRunner(testCase).startTest(testCase); |
| 630 } else { | 633 } else { |
| 631 runCommand(testCase.commands[currentStep++], stepExitHandler); | 634 runCommand(testCase.commands[currentStep++], stepExitHandler); |
| 632 } | 635 } |
| 633 } | 636 } |
| 634 } | 637 } |
| 635 | 638 |
| 636 VoidFunction makeReadHandler(StringInputStream source, List<String> destinatio
n) { | 639 VoidFunction makeReadHandler(StringInputStream source, |
| 640 List<String> destination) { |
| 637 void handler () { | 641 void handler () { |
| 638 if (source.closed) return; // TODO(whesse): Remove when bug is fixed. | 642 if (source.closed) return; // TODO(whesse): Remove when bug is fixed. |
| 639 var line = source.readLine(); | 643 var line = source.readLine(); |
| 640 while (null != line) { | 644 while (null != line) { |
| 641 destination.add(line); | 645 destination.add(line); |
| 642 line = source.readLine(); | 646 line = source.readLine(); |
| 643 } | 647 } |
| 644 } | 648 } |
| 645 return handler; | 649 return handler; |
| 646 } | 650 } |
| 647 | 651 |
| 648 void start() { | 652 void start() { |
| 649 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP)); | 653 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP)); |
| 650 stdout = new List<String>(); | 654 stdout = new List<String>(); |
| 651 stderr = new List<String>(); | 655 stderr = new List<String>(); |
| 652 currentStep = 0; | 656 currentStep = 0; |
| 653 startTime = new Date.now(); | 657 startTime = new Date.now(); |
| 654 runCommand(testCase.commands[currentStep++], stepExitHandler); | 658 runCommand(testCase.commands[currentStep++], stepExitHandler); |
| 655 } | 659 } |
| 656 | 660 |
| 657 void runCommand(Command command, | 661 void runCommand(Command command, |
| 658 void exitHandler(int exitCode)) { | 662 void exitHandler(int exitCode)) { |
| 659 process = Process.start(command.executable, command.arguments); | 663 ProcessOptions options = new ProcessOptions(); |
| 664 options.environment = command.environment; |
| 665 process = Process.start(command.executable, |
| 666 command.arguments, |
| 667 options); |
| 660 process.onExit = exitHandler; | 668 process.onExit = exitHandler; |
| 661 process.onError = (e) { | 669 process.onError = (e) { |
| 662 print("Error starting process:"); | 670 print("Error starting process:"); |
| 663 print(" Command: $command"); | 671 print(" Command: $command"); |
| 664 print(" Error: $e"); | 672 print(" Error: $e"); |
| 665 testComplete(-1, false); | 673 testComplete(-1, false); |
| 666 }; | 674 }; |
| 667 InputStream stdoutStream = process.stdout; | 675 InputStream stdoutStream = process.stdout; |
| 668 InputStream stderrStream = process.stderr; | 676 InputStream stderrStream = process.stderr; |
| 669 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); | 677 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 // the developer doesn't waste his or her time trying to fix a bunch of | 1244 // the developer doesn't waste his or her time trying to fix a bunch of |
| 1237 // tests that appear to be broken but were actually just flakes that | 1245 // tests that appear to be broken but were actually just flakes that |
| 1238 // didn't get retried because there had already been one failure. | 1246 // didn't get retried because there had already been one failure. |
| 1239 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; | 1247 bool allowRetry = _MAX_FAILED_NO_RETRY > _progress.numFailedTests; |
| 1240 new RunningProcess(test, allowRetry, this).start(); | 1248 new RunningProcess(test, allowRetry, this).start(); |
| 1241 } | 1249 } |
| 1242 _numProcesses++; | 1250 _numProcesses++; |
| 1243 } | 1251 } |
| 1244 } | 1252 } |
| 1245 } | 1253 } |
| OLD | NEW |