Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: tools/testing/dart/test_runner.dart

Issue 8889016: Enable Dartium tests in tools/test.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import("status_file_parser.dart"); 7 #import("status_file_parser.dart");
8 #import("test_progress.dart"); 8 #import("test_progress.dart");
9 #import("test_suite.dart"); 9 #import("test_suite.dart");
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 arguments = newArguments; 73 arguments = newArguments;
74 } 74 }
75 } 75 }
76 76
77 int get timeout() => configuration['timeout']; 77 int get timeout() => configuration['timeout'];
78 78
79 void completed() { completedHandler(this); } 79 void completed() { completedHandler(this); }
80 } 80 }
81 81
82 82
83 /** RunningProcess.start() handles CompilingTestCase specially, executing
Mads Ager (google) 2011/12/09 13:19:37 BrowserTestCase I would reformulate to say someth
84 * the compilation command line first.
85 */
86 class BrowserTestCase extends TestCase {
87 String compilerPath;
88 List<String> compilerArguments;
89
90 BrowserTestCase(displayName,
91 this.compilerPath,
92 this.compilerArguments,
93 executablePath,
94 arguments,
95 configuration,
96 completedHandler,
97 expectedOutcomes,
98 [isNegative = false]) : super(displayName,
99 executablePath,
100 arguments,
101 configuration,
102 completedHandler,
103 expectedOutcomes,
104 isNegative);
105 }
106
107
108
83 class TestOutput { 109 class TestOutput {
84 // The TestCase this is the output from. 110 // The TestCase this is the output from.
85 TestCase testCase; 111 TestCase testCase;
86 int exitCode; 112 int exitCode;
87 bool timedOut; 113 bool timedOut;
88 bool failed = false; 114 bool failed = false;
89 List<String> stdout; 115 List<String> stdout;
90 List<String> stderr; 116 List<String> stderr;
91 Duration time; 117 Duration time;
92 118
93 TestOutput(this.testCase, this.exitCode, this.timedOut, this.stdout, 119 TestOutput(this.testCase, this.exitCode, this.timedOut, this.stdout,
94 this.stderr, this.time) { 120 this.stderr, this.time) {
95 testCase.output = this; 121 testCase.output = this;
96 } 122 }
97 123
98 String get result() => 124 String get result() =>
99 hasCrashed ? CRASH : (hasTimedOut ? TIMEOUT : (hasFailed ? FAIL : PASS)); 125 hasCrashed ? CRASH : (hasTimedOut ? TIMEOUT : (hasFailed ? FAIL : PASS));
100 126
101 bool get unexpectedOutput() => !testCase.expectedOutcomes.contains(result); 127 bool get unexpectedOutput() => !testCase.expectedOutcomes.contains(result);
102 128
103 // The Java dartc runner exits with code 253 in case of unhandles 129 // The Java dartc runner exits with code 253 in case of unhandled
104 // exceptions. 130 // exceptions.
105 // The VM uses std::abort to terminate on asserts. 131 // The VM uses std::abort to terminate on asserts.
106 // std::abort terminates with exit code 3 on Windows. 132 // std::abort terminates with exit code 3 on Windows.
107 bool get hasCrashed() { 133 bool get hasCrashed() {
108 if (new Platform().operatingSystem() == 'windows') { 134 if (new Platform().operatingSystem() == 'windows') {
109 if (exitCode == 3) { 135 if (exitCode == 3) {
110 return !timedOut; 136 return !timedOut;
111 } 137 }
112 return (!timedOut && 138 return (!timedOut &&
113 (exitCode != -1) && 139 (exitCode != -1) &&
114 (exitCode < 0) && 140 (exitCode < 0) &&
115 ((0x3FFFFF00 & exitCode) == 0)); 141 ((0x3FFFFF00 & exitCode) == 0));
116 } 142 }
117 return (!timedOut && 143 return (!timedOut &&
118 (exitCode != -1) && 144 (exitCode != -1) &&
119 ((exitCode < 0) || (exitCode == 253))); 145 ((exitCode < 0) || (exitCode == 253)));
120 } 146 }
121 147
122 bool get hasTimedOut() => timedOut; 148 bool get hasTimedOut() => timedOut;
123 149
124 bool get didFail() => exitCode != 0 && !hasCrashed; 150 bool get didFail() {
151 if (exitCode != 0 && !hasCrashed) return true;
152
153 // Browser tests fail unless stdout contains
154 // 'Content-Type: text/plain\nPASS'.
155 if (testCase is !BrowserTestCase) return false;
156 String previous_line = '';
157 for (String line in stdout) {
158 if (line == 'PASS' && previous_line == 'Content-Type: text/plain') {
159 return false;
160 }
161 previous_line = line;
162 }
163 return true;
164 }
125 165
126 // Reverse result of a negative test. 166 // Reverse result of a negative test.
127 bool get hasFailed() => (testCase.isNegative ? !didFail : didFail); 167 bool get hasFailed() => (testCase.isNegative ? !didFail : didFail);
128 } 168 }
129 169
130 170
131 class RunningProcess { 171 class RunningProcess {
132 Process process; 172 Process process;
133 TestCase testCase; 173 TestCase testCase;
134 bool timedOut = false; 174 bool timedOut = false;
135 Date startTime; 175 Date startTime;
136 Timer timeoutTimer; 176 Timer timeoutTimer;
137 List<String> stdout; 177 List<String> stdout;
138 List<String> stderr; 178 List<String> stderr;
139 List<Function> handlers; 179 List<Function> handlers;
140 180
141 RunningProcess(this.testCase); 181 RunningProcess(this.testCase);
142 182
143 void exitHandler(int exitCode) { 183 void exitHandler(int exitCode) {
144 new TestOutput(testCase, exitCode, timedOut, stdout, 184 new TestOutput(testCase, exitCode, timedOut, stdout,
145 stderr, new Date.now().difference(startTime)); 185 stderr, new Date.now().difference(startTime));
146 process.close(); 186 process.close();
147 timeoutTimer.cancel(); 187 timeoutTimer.cancel();
148 testCase.completed(); 188 testCase.completed();
149 } 189 }
150 190
191 void compilerExitHandler(int exitCode) {
192 if (exitCode != 0) {
193 exitHandler(exitCode);
194 } else {
195 runCommand(testCase.executablePath, testCase.arguments, exitHandler);
196 }
197 }
198
151 void makeReadHandler(StringInputStream source, List<String> destination) { 199 void makeReadHandler(StringInputStream source, List<String> destination) {
152 return () { 200 return () {
153 if (source.closed) return; // TODO(whesse): Remove when bug is fixed. 201 if (source.closed) return; // TODO(whesse): Remove when bug is fixed.
154 var line = source.readLine(); 202 var line = source.readLine();
155 while (null != line) { 203 while (null != line) {
156 destination.add(line); 204 destination.add(line);
157 line = source.readLine(); 205 line = source.readLine();
158 } 206 }
159 }; 207 };
160 } 208 }
161 209
162 void start() { 210 void start() {
163 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP)); 211 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP));
164 process = new Process(testCase.executablePath, testCase.arguments); 212 stdout = new List<String>();
213 stderr = new List<String>();
214 if (testCase is BrowserTestCase) {
215 runCommand(testCase.compilerPath,
216 testCase.compilerArguments,
217 compilerExitHandler);
218 } else {
219 runCommand(testCase.executablePath, testCase.arguments, exitHandler);
220 }
221 }
222
223 void runCommand(String executable,
224 List<String> arguments,
225 void exitHandler(int exitCode)) {
226 process = new Process(executable, arguments);
165 process.exitHandler = exitHandler; 227 process.exitHandler = exitHandler;
166 startTime = new Date.now(); 228 startTime = new Date.now();
167 process.start(); 229 process.start();
168
169 InputStream stdoutStream = process.stdout; 230 InputStream stdoutStream = process.stdout;
170 InputStream stderrStream = process.stderr; 231 InputStream stderrStream = process.stderr;
171 stdout = new List<String>();
172 stderr = new List<String>();
173 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); 232 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream);
174 StringInputStream stderrStringStream = new StringInputStream(stderrStream); 233 StringInputStream stderrStringStream = new StringInputStream(stderrStream);
175 stdoutStringStream.dataHandler = 234 stdoutStringStream.dataHandler =
176 makeReadHandler(stdoutStringStream, stdout); 235 makeReadHandler(stdoutStringStream, stdout);
177 stderrStringStream.dataHandler = 236 stderrStringStream.dataHandler =
178 makeReadHandler(stderrStringStream, stderr); 237 makeReadHandler(stderrStringStream, stderr);
179 timeoutTimer = new Timer(timeoutHandler, 1000 * testCase.timeout, false); 238 timeoutTimer = new Timer(timeoutHandler, 1000 * testCase.timeout, false);
180 } 239 }
181 240
Mads Ager (google) 2011/12/09 13:19:37 Remove the extra new lines.
241
242
182 void timeoutHandler(Timer unusedTimer) { 243 void timeoutHandler(Timer unusedTimer) {
183 timedOut = true; 244 timedOut = true;
184 process.kill(); 245 process.kill();
185 } 246 }
186 } 247 }
187 248
188 249
189 class DartcBatchRunnerProcess { 250 class DartcBatchRunnerProcess {
190 String _executable; 251 String _executable;
191 252
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 if (test.configuration['component'] == 'dartc') { 468 if (test.configuration['component'] == 'dartc') {
408 _ensureDartcBatchRunnersStarted(test.executablePath); 469 _ensureDartcBatchRunnersStarted(test.executablePath);
409 _getDartcBatchRunnerProcess().startTest(test); 470 _getDartcBatchRunnerProcess().startTest(test);
410 } else { 471 } else {
411 new RunningProcess(test).start(); 472 new RunningProcess(test).start();
412 } 473 }
413 _numProcesses++; 474 _numProcesses++;
414 } 475 }
415 } 476 }
416 } 477 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698