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

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

Issue 9024008: Change the process API to be completely asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Presubmit fixes Created 8 years, 12 months 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 testCase.dynamic.compilerArguments, 213 testCase.dynamic.compilerArguments,
214 compilerExitHandler); 214 compilerExitHandler);
215 } else { 215 } else {
216 runCommand(testCase.executablePath, testCase.arguments, exitHandler); 216 runCommand(testCase.executablePath, testCase.arguments, exitHandler);
217 } 217 }
218 } 218 }
219 219
220 void runCommand(String executable, 220 void runCommand(String executable,
221 List<String> arguments, 221 List<String> arguments,
222 void exitHandler(int exitCode)) { 222 void exitHandler(int exitCode)) {
223 process = new Process(executable, arguments); 223 process = new Process.start(executable, arguments);
224 process.exitHandler = exitHandler; 224 process.exitHandler = exitHandler;
225 startTime = new Date.now(); 225 startTime = new Date.now();
226 process.start();
227 InputStream stdoutStream = process.stdout; 226 InputStream stdoutStream = process.stdout;
228 InputStream stderrStream = process.stderr; 227 InputStream stderrStream = process.stderr;
229 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream); 228 StringInputStream stdoutStringStream = new StringInputStream(stdoutStream);
230 StringInputStream stderrStringStream = new StringInputStream(stderrStream); 229 StringInputStream stderrStringStream = new StringInputStream(stderrStream);
231 stdoutStringStream.lineHandler = 230 stdoutStringStream.lineHandler =
232 makeReadHandler(stdoutStringStream, stdout); 231 makeReadHandler(stdoutStringStream, stdout);
233 stderrStringStream.lineHandler = 232 stderrStringStream.lineHandler =
234 makeReadHandler(stderrStringStream, stderr); 233 makeReadHandler(stderrStringStream, stderr);
235 timeoutTimer = new Timer(timeoutHandler, 1000 * testCase.timeout); 234 timeoutTimer = new Timer(timeoutHandler, 1000 * testCase.timeout);
236 } 235 }
(...skipping 11 matching lines...) Expand all
248 Process _process; 247 Process _process;
249 StringInputStream _stdoutStream; 248 StringInputStream _stdoutStream;
250 StringInputStream _stderrStream; 249 StringInputStream _stderrStream;
251 250
252 TestCase _currentTest; 251 TestCase _currentTest;
253 StringBuffer _testStdout; 252 StringBuffer _testStdout;
254 StringBuffer _testStderr; 253 StringBuffer _testStderr;
255 Date _startTime; 254 Date _startTime;
256 Timer _timer; 255 Timer _timer;
257 256
258 DartcBatchRunnerProcess(String this._executable) { 257 DartcBatchRunnerProcess(String this._executable);
259 _startProcess();
260 }
261 258
262 bool get active() => _currentTest != null; 259 bool get active() => _currentTest != null;
263 260
264 void startTest(TestCase testCase) { 261 void startTest(TestCase testCase) {
265 _currentTest = testCase; 262 _currentTest = testCase;
266 if (testCase.executablePath != _executable) { 263 if (_process === null) {
267 // Restart this runner with the right executable for this test. 264 // Start process if not yet started.
265 _executable = testCase.executablePath;
266 _startProcess(() {
267 doStartTest(testCase);
268 });
269 } else if (testCase.executablePath != _executable) {
270 // Restart this runner with the right executable for this test
271 // if needed.
268 _executable = testCase.executablePath; 272 _executable = testCase.executablePath;
269 _process.exitHandler = (exitCode) { 273 _process.exitHandler = (exitCode) {
270 _process.close(); 274 _process.close();
271 _startProcess(); 275 _startProcess(() {
272 doStartTest(testCase); 276 doStartTest(testCase);
277 });
273 }; 278 };
274 _process.kill(); 279 _process.kill();
275 } else { 280 } else {
276 doStartTest(testCase); 281 doStartTest(testCase);
277 } 282 }
278 } 283 }
279 284
280 void terminate() { 285 void terminate() {
281 _process.exitHandler = (exitCode) { 286 if (_process !== null) {
282 _process.close(); 287 _process.exitHandler = (exitCode) {
283 }; 288 _process.close();
284 _process.kill(); 289 };
290 _process.kill();
291 }
285 } 292 }
286 293
287 void doStartTest(TestCase testCase) { 294 void doStartTest(TestCase testCase) {
288 _startTime = new Date.now(); 295 _startTime = new Date.now();
289 _testStdout = new List<String>(); 296 _testStdout = new List<String>();
290 _testStderr = new List<String>(); 297 _testStderr = new List<String>();
291 _stdoutStream.lineHandler = _readOutput(_stdoutStream, _testStdout); 298 _stdoutStream.lineHandler = _readOutput(_stdoutStream, _testStdout);
292 _stderrStream.lineHandler = _readOutput(_stderrStream, _testStderr); 299 _stderrStream.lineHandler = _readOutput(_stderrStream, _testStderr);
293 _timer = new Timer(_timeoutHandler(testCase), testCase.timeout * 1000); 300 _timer = new Timer(_timeoutHandler(testCase), testCase.timeout * 1000);
294 _process.stdin.write(_createArgumentsLine(testCase.arguments).charCodes()); 301 _process.stdin.write(_createArgumentsLine(testCase.arguments).charCodes());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (!status.contains("CRASH")) { 342 if (!status.contains("CRASH")) {
336 _reportResult(status); 343 _reportResult(status);
337 } 344 }
338 } 345 }
339 }; 346 };
340 } 347 }
341 348
342 void _exitHandler(exitCode) { 349 void _exitHandler(exitCode) {
343 if (_timer != null) _timer.cancel(); 350 if (_timer != null) _timer.cancel();
344 _process.close(); 351 _process.close();
345 _startProcess(); 352 _startProcess(() {
346 _reportResult(">>> TEST CRASH"); 353 _reportResult(">>> TEST CRASH");
354 });
347 } 355 }
348 356
349 void _timeoutHandler(TestCase test) { 357 void _timeoutHandler(TestCase test) {
350 return (ignore) { 358 return (ignore) {
351 _process.exitHandler = (exitCode) { 359 _process.exitHandler = (exitCode) {
352 _process.close(); 360 _process.close();
353 _startProcess(); 361 _startProcess(() {
354 _reportResult(">>> TEST TIMEOUT"); 362 _reportResult(">>> TEST TIMEOUT");
363 });
355 }; 364 };
356 _process.kill(); 365 _process.kill();
357 }; 366 };
358 } 367 }
359 368
360 void _startProcess() { 369 void _startProcess(then) {
361 _process = new Process(_executable, ['-batch']); 370 _process = new Process.start(_executable, ['-batch']);
362 _stdoutStream = new StringInputStream(_process.stdout); 371 _stdoutStream = new StringInputStream(_process.stdout);
363 _stderrStream = new StringInputStream(_process.stderr); 372 _stderrStream = new StringInputStream(_process.stderr);
364 _testStdout = new List<String>(); 373 _testStdout = new List<String>();
365 _testStderr = new List<String>(); 374 _testStderr = new List<String>();
366 _stdoutStream.lineHandler = _readOutput(_stdoutStream, _testStdout); 375 _stdoutStream.lineHandler = _readOutput(_stdoutStream, _testStdout);
367 _stderrStream.lineHandler = _readOutput(_stderrStream, _testStderr); 376 _stderrStream.lineHandler = _readOutput(_stderrStream, _testStderr);
368 _process.exitHandler = _exitHandler; 377 _process.exitHandler = _exitHandler;
369 _process.start(); 378 _process.startHandler = then;
370 } 379 }
371 } 380 }
372 381
373 382
374 class ProcessQueue { 383 class ProcessQueue {
375 int _numProcesses = 0; 384 int _numProcesses = 0;
376 int _activeTestListers = 0; 385 int _activeTestListers = 0;
377 int _maxProcesses; 386 int _maxProcesses;
378 bool _verbose; 387 bool _verbose;
379 Function _enqueueMoreWork; 388 Function _enqueueMoreWork;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (test.configuration['component'] == 'dartc') { 475 if (test.configuration['component'] == 'dartc') {
467 _ensureDartcBatchRunnersStarted(test.executablePath); 476 _ensureDartcBatchRunnersStarted(test.executablePath);
468 _getDartcBatchRunnerProcess().startTest(test); 477 _getDartcBatchRunnerProcess().startTest(test);
469 } else { 478 } else {
470 new RunningProcess(test).start(); 479 new RunningProcess(test).start();
471 } 480 }
472 _numProcesses++; 481 _numProcesses++;
473 } 482 }
474 } 483 }
475 } 484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698