| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #library("test_runner"); | 5 #library("test_runner"); |
| 6 | 6 |
| 7 | |
| 8 #import("status_file_parser.dart"); | 7 #import("status_file_parser.dart"); |
| 8 #import("test_progress.dart"); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Classes and methods for executing tests. | 11 * Classes and methods for executing tests. |
| 12 * | 12 * |
| 13 * This module includes: | 13 * This module includes: |
| 14 * - Managing parallel execution of tests, including timeout checks. | 14 * - Managing parallel execution of tests, including timeout checks. |
| 15 * - Evaluating the output of each test as pass/fail/crash/timeout. | 15 * - Evaluating the output of each test as pass/fail/crash/timeout. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 final int NO_TIMEOUT = 0; | 18 final int NO_TIMEOUT = 0; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 Process process; | 91 Process process; |
| 92 TestCase testCase; | 92 TestCase testCase; |
| 93 int timeout; | 93 int timeout; |
| 94 bool timedOut = false; | 94 bool timedOut = false; |
| 95 Date startTime; | 95 Date startTime; |
| 96 Timer timeoutTimer; | 96 Timer timeoutTimer; |
| 97 List<String> stdout; | 97 List<String> stdout; |
| 98 List<String> stderr; | 98 List<String> stderr; |
| 99 List<Function> handlers; | 99 List<Function> handlers; |
| 100 | 100 |
| 101 | |
| 102 RunningProcess(this.testCase, [this.timeout = NO_TIMEOUT]); | 101 RunningProcess(this.testCase, [this.timeout = NO_TIMEOUT]); |
| 103 | 102 |
| 104 void exitHandler(int exitCode) { | 103 void exitHandler(int exitCode) { |
| 105 new TestOutput(testCase, exitCode, timedOut, stdout, | 104 new TestOutput(testCase, exitCode, timedOut, stdout, |
| 106 stderr, new Date.now().difference(startTime)); | 105 stderr, new Date.now().difference(startTime)); |
| 107 process.close(); | 106 process.close(); |
| 108 timeoutTimer.cancel(); | 107 timeoutTimer.cancel(); |
| 109 testCase.completed(); | 108 testCase.completed(); |
| 110 } | 109 } |
| 111 | 110 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 timedOut = true; | 145 timedOut = true; |
| 147 process.kill(); | 146 process.kill(); |
| 148 } | 147 } |
| 149 } | 148 } |
| 150 | 149 |
| 151 | 150 |
| 152 class ProcessQueue { | 151 class ProcessQueue { |
| 153 int numProcesses = 0; | 152 int numProcesses = 0; |
| 154 final int maxProcesses; | 153 final int maxProcesses; |
| 155 Queue<TestCase> tests; | 154 Queue<TestCase> tests; |
| 155 ProgressIndicator progress; |
| 156 | 156 |
| 157 ProcessQueue(this.maxProcesses) : tests = new Queue<TestCase>(); | 157 ProcessQueue(this.maxProcesses, this.progress) |
| 158 : tests = new Queue<TestCase>(); |
| 158 | 159 |
| 159 tryRunTest() { | 160 tryRunTest() { |
| 160 if (numProcesses < maxProcesses && !tests.isEmpty()) { | 161 if (numProcesses < maxProcesses && !tests.isEmpty()) { |
| 161 TestCase test = tests.removeFirst(); | 162 TestCase test = tests.removeFirst(); |
| 162 print("running ${test.displayName}"); | 163 progress.start(test); |
| 163 // TODO(whesse): Refactor into various test output methods. | 164 // TODO(whesse): Refactor into various test output methods. |
| 164 Function old_callback = test.completedHandler; | 165 Function old_callback = test.completedHandler; |
| 165 Function wrapper = (TestCase test_arg) { | 166 Function wrapper = (TestCase test_arg) { |
| 166 numProcesses--; | 167 numProcesses--; |
| 167 print("finished ${test_arg.displayName}"); | 168 progress.done(test_arg); |
| 168 tryRunTest(); | 169 tryRunTest(); |
| 169 old_callback(test_arg); | 170 old_callback(test_arg); |
| 170 }; | 171 }; |
| 171 test.completedHandler = wrapper; | 172 test.completedHandler = wrapper; |
| 172 | 173 |
| 173 // TODO(whesse): Add timeout information to TestCase, use it here. | 174 // TODO(whesse): Add timeout information to TestCase, use it here. |
| 174 new RunningProcess(test, 60).start(); | 175 new RunningProcess(test, 60).start(); |
| 175 numProcesses++; | 176 numProcesses++; |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 | 179 |
| 179 runTest(TestCase test) { | 180 runTest(TestCase test) { |
| 181 progress.testAdded(); |
| 180 tests.add(test); | 182 tests.add(test); |
| 181 tryRunTest(); | 183 tryRunTest(); |
| 182 } | 184 } |
| 183 } | 185 } |
| OLD | NEW |