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