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

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

Issue 9240011: Add temporary directory for dartc compilation of tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made test for temp directory a function. Created 8 years, 11 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 399 }
400 } 400 }
401 401
402 402
403 class ProcessQueue { 403 class ProcessQueue {
404 int _numProcesses = 0; 404 int _numProcesses = 0;
405 int _activeTestListers = 0; 405 int _activeTestListers = 0;
406 int _maxProcesses; 406 int _maxProcesses;
407 bool _verbose; 407 bool _verbose;
408 bool _listTests; 408 bool _listTests;
409 bool _keepGeneratedTests;
409 Function _enqueueMoreWork; 410 Function _enqueueMoreWork;
410 Queue<TestCase> _tests; 411 Queue<TestCase> _tests;
411 ProgressIndicator _progress; 412 ProgressIndicator _progress;
413 String _temporaryDirectory;
412 // For dartc batch processing we keep a list of batch processes. 414 // For dartc batch processing we keep a list of batch processes.
413 List<DartcBatchRunnerProcess> _batchProcesses; 415 List<DartcBatchRunnerProcess> _batchProcesses;
414 // Cache information about test cases per test suite. For multiple 416 // Cache information about test cases per test suite. For multiple
415 // configurations there is no need to repeatedly search the file 417 // configurations there is no need to repeatedly search the file
416 // system, generate tests, and search test files for options. 418 // system, generate tests, and search test files for options.
417 Map<String, List<TestInformation>> _testCache; 419 Map<String, List<TestInformation>> _testCache;
418 420
419 ProcessQueue(int this._maxProcesses, 421 ProcessQueue(int this._maxProcesses,
420 String progress, 422 String progress,
421 Date startTime, 423 Date startTime,
422 bool printTiming, 424 bool printTiming,
423 Function this._enqueueMoreWork, 425 Function this._enqueueMoreWork,
424 [bool verbose = false, 426 [bool this._verbose = false,
425 bool listTests = false]) 427 bool this._listTests = false,
428 bool this._keepGeneratedTests = false])
426 : _tests = new Queue<TestCase>(), 429 : _tests = new Queue<TestCase>(),
427 _progress = new ProgressIndicator.fromName(progress, 430 _progress = new ProgressIndicator.fromName(progress,
428 startTime, 431 startTime,
429 printTiming), 432 printTiming),
430 _batchProcesses = new List<DartcBatchRunnerProcess>(), 433 _batchProcesses = new List<DartcBatchRunnerProcess>(),
431 _testCache = new Map<String, List<TestInformation>>(), 434 _testCache = new Map<String, List<TestInformation>>() {
432 _verbose = verbose,
433 _listTests = listTests {
434 if (!_enqueueMoreWork(this)) _progress.allDone(); 435 if (!_enqueueMoreWork(this)) _progress.allDone();
435 } 436 }
436 437
437 void addTestSuite(TestSuite testSuite) { 438 void addTestSuite(TestSuite testSuite) {
438 _activeTestListers++; 439 _activeTestListers++;
439 testSuite.forEachTest(_runTest, _testCache, _testListerDone); 440 testSuite.forEachTest(_runTest, _testCache, globalTemporaryDirectory,
441 _testListerDone);
440 } 442 }
441 443
442 void _testListerDone() { 444 void _testListerDone() {
443 _activeTestListers--; 445 _activeTestListers--;
444 _checkDone(); 446 _checkDone();
445 } 447 }
446 448
449 String globalTemporaryDirectory() {
450 if (_temporaryDirectory != null) return _temporaryDirectory;
451
452 if (new Platform().operatingSystem() == 'windows') {
453 throw new Exception(
454 'Test suite requires temporary directory. Not supported on Windows.');
455 }
456 var tempDir = new Directory('');
457 tempDir.createTempSync();
458 _temporaryDirectory = tempDir.path;
459 return _temporaryDirectory;
460 }
461
462
447 void _checkDone() { 463 void _checkDone() {
448 // When there are no more active test listers ask for more work 464 // When there are no more active test listers ask for more work
449 // from process queue users. 465 // from process queue users.
450 if (_activeTestListers == 0 && !_enqueueMoreWork(this)) { 466 if (_activeTestListers == 0 && !_enqueueMoreWork(this)) {
451 _progress.allTestsKnown(); 467 _progress.allTestsKnown();
452 if (_tests.isEmpty() && _numProcesses == 0) { 468 if (_tests.isEmpty() && _numProcesses == 0) {
453 _terminateDartcBatchRunners(); 469 _terminateDartcBatchRunners();
454 _progress.allDone(); 470 if (_keepGeneratedTests || _temporaryDirectory == null) {
471 _progress.allDone();
472 } else if (!_temporaryDirectory.startsWith('/tmp/') ||
473 _temporaryDirectory.contains('/../')) {
474 // Let's be extra careful, since rm -rf is so dangerous.
475 print('Temporary directory $_temporaryDirectory unsafe to delete!');
476 _progress.allDone();
477 } else {
478 // TODO(dart:1211): Use delete(recursive=true) in Dart when it is
479 // implemented, and add Windows support.
480 var deletion =
481 new Process.start('/bin/rm', ['-rf', _temporaryDirectory]);
482 deletion.startHandler = (){
483 _progress.allDone();
484 };
485 }
455 } 486 }
456 } 487 }
457 } 488 }
458 489
459 void _runTest(TestCase test) { 490 void _runTest(TestCase test) {
460 _progress.testAdded(); 491 _progress.testAdded();
461 _tests.add(test); 492 _tests.add(test);
462 _tryRunTest(); 493 _tryRunTest();
463 } 494 }
464 495
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 test.displayName != 'dartc/junit_tests') { 535 test.displayName != 'dartc/junit_tests') {
505 _ensureDartcBatchRunnersStarted(test.executablePath); 536 _ensureDartcBatchRunnersStarted(test.executablePath);
506 _getDartcBatchRunnerProcess().startTest(test); 537 _getDartcBatchRunnerProcess().startTest(test);
507 } else { 538 } else {
508 new RunningProcess(test).start(); 539 new RunningProcess(test).start();
509 } 540 }
510 _numProcesses++; 541 _numProcesses++;
511 } 542 }
512 } 543 }
513 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698