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

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: Disable dartc test suite on non-dartc components. 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
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /**
84 * BrowserTestCase has an extra compilation command that is run by
85 * RunningProcess.start(), and it checks conditions on the test output
86 * in TestOutput.didFail().
87 */
88 class BrowserTestCase extends TestCase {
89 String compilerPath;
90 List<String> compilerArguments;
91
92 BrowserTestCase(displayName,
93 this.compilerPath,
94 this.compilerArguments,
95 executablePath,
96 arguments,
97 configuration,
98 completedHandler,
99 expectedOutcomes,
100 [isNegative = false]) : super(displayName,
101 executablePath,
102 arguments,
103 configuration,
104 completedHandler,
105 expectedOutcomes,
106 isNegative);
107 }
108
109
83 class TestOutput { 110 class TestOutput {
84 // The TestCase this is the output from. 111 // The TestCase this is the output from.
85 TestCase testCase; 112 TestCase testCase;
86 int exitCode; 113 int exitCode;
87 bool timedOut; 114 bool timedOut;
88 bool failed = false; 115 bool failed = false;
89 List<String> stdout; 116 List<String> stdout;
90 List<String> stderr; 117 List<String> stderr;
91 Duration time; 118 Duration time;
92 119
93 TestOutput(this.testCase, this.exitCode, this.timedOut, this.stdout, 120 TestOutput(this.testCase, this.exitCode, this.timedOut, this.stdout,
94 this.stderr, this.time) { 121 this.stderr, this.time) {
95 testCase.output = this; 122 testCase.output = this;
96 } 123 }
97 124
98 String get result() => 125 String get result() =>
99 hasCrashed ? CRASH : (hasTimedOut ? TIMEOUT : (hasFailed ? FAIL : PASS)); 126 hasCrashed ? CRASH : (hasTimedOut ? TIMEOUT : (hasFailed ? FAIL : PASS));
100 127
101 bool get unexpectedOutput() => !testCase.expectedOutcomes.contains(result); 128 bool get unexpectedOutput() => !testCase.expectedOutcomes.contains(result);
102 129
103 // The Java dartc runner exits with code 253 in case of unhandles 130 // The Java dartc runner exits with code 253 in case of unhandled
104 // exceptions. 131 // exceptions.
105 // The VM uses std::abort to terminate on asserts. 132 // The VM uses std::abort to terminate on asserts.
106 // std::abort terminates with exit code 3 on Windows. 133 // std::abort terminates with exit code 3 on Windows.
107 bool get hasCrashed() { 134 bool get hasCrashed() {
108 if (new Platform().operatingSystem() == 'windows') { 135 if (new Platform().operatingSystem() == 'windows') {
109 if (exitCode == 3) { 136 if (exitCode == 3) {
110 return !timedOut; 137 return !timedOut;
111 } 138 }
112 return (!timedOut && 139 return (!timedOut &&
113 (exitCode != -1) && 140 (exitCode != -1) &&
114 (exitCode < 0) && 141 (exitCode < 0) &&
115 ((0x3FFFFF00 & exitCode) == 0)); 142 ((0x3FFFFF00 & exitCode) == 0));
116 } 143 }
117 return (!timedOut && 144 return (!timedOut &&
118 (exitCode != -1) && 145 (exitCode != -1) &&
119 ((exitCode < 0) || (exitCode == 253))); 146 ((exitCode < 0) || (exitCode == 253)));
120 } 147 }
121 148
122 bool get hasTimedOut() => timedOut; 149 bool get hasTimedOut() => timedOut;
123 150
124 bool get didFail() => exitCode != 0 && !hasCrashed; 151 bool get didFail() {
152 if (exitCode != 0 && !hasCrashed) return true;
153
154 // Browser tests fail unless stdout contains
155 // 'Content-Type: text/plain\nPASS'.
156 if (testCase is !BrowserTestCase) return false;
157 String previous_line = '';
158 for (String line in stdout) {
159 if (line == 'PASS' && previous_line == 'Content-Type: text/plain') {
160 return false;
161 }
162 previous_line = line;
163 }
164 return true;
165 }
125 166
126 // Reverse result of a negative test. 167 // Reverse result of a negative test.
127 bool get hasFailed() => (testCase.isNegative ? !didFail : didFail); 168 bool get hasFailed() => (testCase.isNegative ? !didFail : didFail);
128 } 169 }
129 170
130 171
131 class RunningProcess { 172 class RunningProcess {
132 Process process; 173 Process process;
133 TestCase testCase; 174 TestCase testCase;
134 bool timedOut = false; 175 bool timedOut = false;
135 Date startTime; 176 Date startTime;
136 Timer timeoutTimer; 177 Timer timeoutTimer;
137 List<String> stdout; 178 List<String> stdout;
138 List<String> stderr; 179 List<String> stderr;
139 List<Function> handlers; 180 List<Function> handlers;
140 181
141 RunningProcess(this.testCase); 182 RunningProcess(this.testCase);
142 183
143 void exitHandler(int exitCode) { 184 void exitHandler(int exitCode) {
144 new TestOutput(testCase, exitCode, timedOut, stdout, 185 new TestOutput(testCase, exitCode, timedOut, stdout,
145 stderr, new Date.now().difference(startTime)); 186 stderr, new Date.now().difference(startTime));
146 process.close(); 187 process.close();
147 timeoutTimer.cancel(); 188 timeoutTimer.cancel();
148 testCase.completed(); 189 testCase.completed();
149 } 190 }
150 191
192 void compilerExitHandler(int exitCode) {
193 if (exitCode != 0) {
194 exitHandler(exitCode);
195 } else {
196 runCommand(testCase.executablePath, testCase.arguments, exitHandler);
197 }
198 }
199
151 void makeReadHandler(StringInputStream source, List<String> destination) { 200 void makeReadHandler(StringInputStream source, List<String> destination) {
152 return () { 201 return () {
153 if (source.closed) return; // TODO(whesse): Remove when bug is fixed. 202 if (source.closed) return; // TODO(whesse): Remove when bug is fixed.
154 var line = source.readLine(); 203 var line = source.readLine();
155 while (null != line) { 204 while (null != line) {
156 destination.add(line); 205 destination.add(line);
157 line = source.readLine(); 206 line = source.readLine();
158 } 207 }
159 }; 208 };
160 } 209 }
161 210
162 void start() { 211 void start() {
163 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP)); 212 Expect.isFalse(testCase.expectedOutcomes.contains(SKIP));
164 process = new Process(testCase.executablePath, testCase.arguments); 213 stdout = new List<String>();
214 stderr = new List<String>();
215 if (testCase is BrowserTestCase) {
216 runCommand(testCase.compilerPath,
217 testCase.compilerArguments,
218 compilerExitHandler);
219 } else {
220 runCommand(testCase.executablePath, testCase.arguments, exitHandler);
221 }
222 }
223
224 void runCommand(String executable,
225 List<String> arguments,
226 void exitHandler(int exitCode)) {
227 process = new Process(executable, arguments);
165 process.exitHandler = exitHandler; 228 process.exitHandler = exitHandler;
166 startTime = new Date.now(); 229 startTime = new Date.now();
167 process.start(); 230 process.start();
168
169 InputStream stdoutStream = process.stdout; 231 InputStream stdoutStream = process.stdout;
170 InputStream stderrStream = process.stderr; 232 InputStream stderrStream = process.stderr;
171 stdout = new List<String>();
172 stderr = new List<String>();
173 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); 233 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream);
174 StringInputStream stderrStringStream = new StringInputStream(stderrStream); 234 StringInputStream stderrStringStream = new StringInputStream(stderrStream);
175 stdoutStringStream.dataHandler = 235 stdoutStringStream.dataHandler =
176 makeReadHandler(stdoutStringStream, stdout); 236 makeReadHandler(stdoutStringStream, stdout);
177 stderrStringStream.dataHandler = 237 stderrStringStream.dataHandler =
178 makeReadHandler(stderrStringStream, stderr); 238 makeReadHandler(stderrStringStream, stderr);
179 timeoutTimer = new Timer(timeoutHandler, 1000 * testCase.timeout, false); 239 timeoutTimer = new Timer(timeoutHandler, 1000 * testCase.timeout, false);
180 } 240 }
181 241
182 void timeoutHandler(Timer unusedTimer) { 242 void timeoutHandler(Timer unusedTimer) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (test.configuration['component'] == 'dartc') { 472 if (test.configuration['component'] == 'dartc') {
413 _ensureDartcBatchRunnersStarted(test.executablePath); 473 _ensureDartcBatchRunnersStarted(test.executablePath);
414 _getDartcBatchRunnerProcess().startTest(test); 474 _getDartcBatchRunnerProcess().startTest(test);
415 } else { 475 } else {
416 new RunningProcess(test).start(); 476 new RunningProcess(test).start();
417 } 477 }
418 _numProcesses++; 478 _numProcesses++;
419 } 479 }
420 } 480 }
421 } 481 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698