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

Side by Side Diff: tools/testing/dart/test_suite.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
« no previous file with comments | « tools/testing/dart/test_runner.dart ('k') | no next file » | 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_suite"); 5 #library("test_suite");
6 6
7 #import("status_file_parser.dart"); 7 #import("status_file_parser.dart");
8 #import("test_runner.dart"); 8 #import("test_runner.dart");
9 #import("multitest.dart"); 9 #import("multitest.dart");
10 10
11 #source("browser_test.dart"); 11 #source("browser_test.dart");
12 12
13 interface TestSuite { 13 interface TestSuite {
14 void forEachTest(Function onTest, Map testCache, [Function onDone]); 14 void forEachTest(Function onTest, Map testCache, String globalTempDir(),
15 [Function onDone]);
15 } 16 }
16 17
17 18
18 class CCTestListerIsolate extends Isolate { 19 class CCTestListerIsolate extends Isolate {
19 CCTestListerIsolate() : super.heavy(); 20 CCTestListerIsolate() : super.heavy();
20 21
21 void main() { 22 void main() {
22 port.receive((String runnerPath, SendPort replyTo) { 23 port.receive((String runnerPath, SendPort replyTo) {
23 var p = new Process.start(runnerPath, ["--list"]); 24 var p = new Process.start(runnerPath, ["--list"]);
24 StringInputStream stdoutStream = new StringInputStream(p.stdout); 25 StringInputStream stdoutStream = new StringInputStream(p.stdout);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 doTest(new TestCase('$suiteName/$testName', 97 doTest(new TestCase('$suiteName/$testName',
97 runnerPath, 98 runnerPath,
98 args, 99 args,
99 configuration, 100 configuration,
100 completeHandler, 101 completeHandler,
101 expectations)); 102 expectations));
102 } 103 }
103 } 104 }
104 105
105 void forEachTest(Function onTest, Map testCache, [Function onDone]) { 106 void forEachTest(Function onTest, Map testCache, String globalTempDir(),
107 [Function onDone]) {
106 doTest = onTest; 108 doTest = onTest;
107 doDone = (ignore) => (onDone != null) ? onDone() : null; 109 doDone = (ignore) => (onDone != null) ? onDone() : null;
108 110
109 var filesRead = 0; 111 var filesRead = 0;
110 void statusFileRead() { 112 void statusFileRead() {
111 filesRead++; 113 filesRead++;
112 if (filesRead == statusFilePaths.length) { 114 if (filesRead == statusFilePaths.length) {
113 receiveTestName = new ReceivePort(); 115 receiveTestName = new ReceivePort();
114 new CCTestListerIsolate().spawn().then((port) { 116 new CCTestListerIsolate().spawn().then((port) {
115 port.send(runnerPath, receiveTestName.toSendPort()); 117 port.send(runnerPath, receiveTestName.toSendPort());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 Map configuration; 151 Map configuration;
150 String suiteName; 152 String suiteName;
151 String directoryPath; 153 String directoryPath;
152 List<String> statusFilePaths; 154 List<String> statusFilePaths;
153 Function doTest; 155 Function doTest;
154 Function doDone; 156 Function doDone;
155 int activeTestGenerators = 0; 157 int activeTestGenerators = 0;
156 bool listingDone = false; 158 bool listingDone = false;
157 TestExpectations testExpectations; 159 TestExpectations testExpectations;
158 List<TestInformation> cachedTests; 160 List<TestInformation> cachedTests;
159 final String pathSeparator; 161 final String dartDir;
162 Function globalTemporaryDirectory;
160 163
161 StandardTestSuite(Map this.configuration, 164 StandardTestSuite(Map this.configuration,
162 String this.suiteName, 165 String this.suiteName,
163 String this.directoryPath, 166 String this.directoryPath,
164 List<String> this.statusFilePaths) 167 List<String> this.statusFilePaths)
165 : pathSeparator = new Platform().pathSeparator(); 168 : dartDir = TestUtils.dartDir();
166 169
167 bool isTestFile(String filename) => filename.endsWith("Test.dart"); 170 bool isTestFile(String filename) => filename.endsWith("Test.dart");
168 171
169 bool listRecursively() => false; 172 bool listRecursively() => false;
170 173
171 bool complexStatusMatching() => false; 174 bool complexStatusMatching() => false;
172 175
173 String shellPath() => TestUtils.dartShellFileName(configuration); 176 String shellPath() => TestUtils.dartShellFileName(configuration);
174 177
175 List<String> additionalOptions() => []; 178 List<String> additionalOptions(String filename) => [];
176 179
177 void forEachTest(Function onTest, Map testCache, [Function onDone = null]) { 180 void forEachTest(Function onTest, Map testCache, String globalTempDir(),
181 [Function onDone = null]) {
178 doTest = onTest; 182 doTest = onTest;
179 doDone = (onDone != null) ? onDone : (() => null); 183 doDone = (onDone != null) ? onDone : (() => null);
184 globalTemporaryDirectory = globalTempDir;
180 185
181 var filesRead = 0; 186 var filesRead = 0;
182 void statusFileRead() { 187 void statusFileRead() {
183 filesRead++; 188 filesRead++;
184 if (filesRead == statusFilePaths.length) { 189 if (filesRead == statusFilePaths.length) {
185 // Checked if we have already found and generated the tests for 190 // Checked if we have already found and generated the tests for
186 // this suite. 191 // this suite.
187 if (!testCache.containsKey(suiteName)) { 192 if (!testCache.containsKey(suiteName)) {
188 cachedTests = testCache[suiteName] = []; 193 cachedTests = testCache[suiteName] = [];
189 processDirectory(); 194 processDirectory();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 if (optionsFromFile['isMultitest']) return; 355 if (optionsFromFile['isMultitest']) return;
351 bool isWebTest = optionsFromFile['containsDomImport']; 356 bool isWebTest = optionsFromFile['containsDomImport'];
352 bool isLibraryDefinition = optionsFromFile['isLibraryDefinition']; 357 bool isLibraryDefinition = optionsFromFile['isLibraryDefinition'];
353 if (!isLibraryDefinition && optionsFromFile['containsSourceOrImport']) { 358 if (!isLibraryDefinition && optionsFromFile['containsSourceOrImport']) {
354 print('Warning for $filename: Browser tests require #library ' + 359 print('Warning for $filename: Browser tests require #library ' +
355 'in any file that uses #import or #source'); 360 'in any file that uses #import or #source');
356 } 361 }
357 362
358 final String component = configuration['component']; 363 final String component = configuration['component'];
359 final String testPath = new File(filename).fullPathSync(); 364 final String testPath = new File(filename).fullPathSync();
360 String dartDir = new File('.').fullPathSync();
361 if (!testPath.startsWith(dartDir) ||
362 dartDir.endsWith('/frog')) {
363 dartDir = new File('..').fullPathSync();
364 if (!testPath.startsWith(dartDir)) {
365 print('Run test.dart from the dart directory or' +
366 ' an immediate subdirectory only.');
367 Expect.fail('Could not find top level dart directory.');
368 }
369 }
370 365
371 for (var vmOptions in optionsFromFile['vmOptions']) { 366 for (var vmOptions in optionsFromFile['vmOptions']) {
372 // Create a unique temporary directory for each set of vmOptions. 367 // Create a unique temporary directory for each set of vmOptions.
373 // TODO(dart:429): Replace separate replaceAlls with a RegExp when 368 // TODO(dart:429): Replace separate replaceAlls with a RegExp when
374 // replaceAll(RegExp, String) is implemented. 369 // replaceAll(RegExp, String) is implemented.
375 String optionsName = ''; 370 String optionsName = '';
376 if (optionsFromFile['vmOptions'].length > 1) { 371 if (optionsFromFile['vmOptions'].length > 1) {
377 optionsName = Strings.join(vmOptions, '-').replaceAll('-','') 372 optionsName = Strings.join(vmOptions, '-').replaceAll('-','')
378 .replaceAll('=','') 373 .replaceAll('=','')
379 .replaceAll('/',''); 374 .replaceAll('/','');
380 } 375 }
381 Directory tempDir = 376 Directory tempDir =
382 createTemporaryDirectory(testPath, dartDir, optionsName); 377 createTemporaryDirectory(testPath, optionsName);
383 378
384 String dartWrapperFilename = '${tempDir.path}/test.dart'; 379 String dartWrapperFilename = '${tempDir.path}/test.dart';
385 String compiledDartWrapperFilename = '${tempDir.path}/test.js'; 380 String compiledDartWrapperFilename = '${tempDir.path}/test.js';
386 String domLibraryImport = (component == 'chromium') ? 381 String domLibraryImport = (component == 'chromium') ?
387 '$dartDir/client/testing/unittest/dom_for_unittest.dart' : 'dart:dom'; 382 '$dartDir/client/testing/unittest/dom_for_unittest.dart' : 'dart:dom';
388 383
389 String htmlPath = '${tempDir.path}/test.html'; 384 String htmlPath = '${tempDir.path}/test.html';
390 if (!isWebTest) { 385 if (!isWebTest) {
391 // test.dart will import the dart test directly, if it is a library, 386 // test.dart will import the dart test directly, if it is a library,
392 // or indirectly through test_as_library.dart, if it is not. 387 // or indirectly through test_as_library.dart, if it is not.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 executable, 483 executable,
489 args, 484 args,
490 configuration, 485 configuration,
491 completeHandler, 486 completeHandler,
492 expectations, 487 expectations,
493 optionsFromFile['isNegative']); 488 optionsFromFile['isNegative']);
494 doTest(testCase); 489 doTest(testCase);
495 } 490 }
496 } 491 }
497 492
493 bool get requiresCleanTemporaryDirectory() =>
494 configuration['component'] == 'dartc' ||
495 configuration['component'] == 'chromium';
496
498 /** 497 /**
499 * Create a directory for the generated test. Drop the path to the 498 * Create a directory for the generated test. Drop the path to the
500 * dart checkout and the final ".dart" from the test path, and replace 499 * dart checkout and the final ".dart" from the test path, and replace
501 * all path separators with underscores. 500 * all path separators with underscores.
502 */ 501 */
503 Directory createTemporaryDirectory(String testPath, 502 Directory createTemporaryDirectory(String testPath,
Mads Ager (google) 2012/01/18 15:26:29 This confused me a little. Maybe we should call th
504 String dartDir,
505 String optionsName) { 503 String optionsName) {
506 String testUniqueName = 504 String testUniqueName =
507 testPath.substring(dartDir.length + 1, testPath.length - 5); 505 testPath.substring(dartDir.length + 1, testPath.length - 5);
508 testUniqueName = testUniqueName.replaceAll('/', '_'); 506 testUniqueName = testUniqueName.replaceAll('/', '_');
509 testUniqueName += '-$optionsName'; 507 testUniqueName += '-$optionsName';
508
510 // Create '[build dir]/generated_tests/$component/$testUniqueName', 509 // Create '[build dir]/generated_tests/$component/$testUniqueName',
511 // including any intermediate directories that don't exist. 510 // including any intermediate directories that don't exist.
512 var generatedTestPath = ['generated_tests', 511 String debugMode =
512 (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_';
513 var generatedTestPath = [debugMode + configuration["arch"],
514 'generated_tests',
513 configuration['component'], 515 configuration['component'],
514 testUniqueName]; 516 testUniqueName];
515 517
516 String tempDirPath = TestUtils.buildDir(configuration); 518 String tempDirPath = TestUtils.buildDir(configuration);
519 if (requiresCleanTemporaryDirectory) {
520 tempDirPath = globalTemporaryDirectory();
521 }
517 Directory tempDir = new Directory(tempDirPath); 522 Directory tempDir = new Directory(tempDirPath);
518 if (!tempDir.existsSync()) { 523 if (!tempDir.existsSync()) {
519 // Dartium tests can be run with no build step, with no output directory. 524 // Dartium tests can be run with no build step, with no output directory.
520 // This special case builds the build directory that should be there. 525 // This special case builds the build directory that should be there.
521 var buildPath = tempDirPath.split('/'); 526 var buildPath = tempDirPath.split('/');
522 tempDirPath = buildPath[0]; 527 tempDirPath = buildPath[0];
523 if (tempDirPath == '') { 528 if (tempDirPath == '') {
524 throw new Exception( 529 throw new Exception(
525 'Non-relative path to build directory in test_suite.dart'); 530 'Non-relative path to build directory in test_suite.dart');
526 } 531 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 594 }
590 } 595 }
591 596
592 void completeHandler(TestCase testCase) { 597 void completeHandler(TestCase testCase) {
593 } 598 }
594 599
595 List<List<String>> argumentListsFromFile(String filename, 600 List<List<String>> argumentListsFromFile(String filename,
596 Map optionsFromFile, 601 Map optionsFromFile,
597 bool enableFatalTypeErrors) { 602 bool enableFatalTypeErrors) {
598 List args = TestUtils.standardOptions(configuration); 603 List args = TestUtils.standardOptions(configuration);
599 args.addAll(additionalOptions()); 604 args.addAll(additionalOptions(filename));
600 if (enableFatalTypeErrors && configuration['component'] == 'dartc') { 605 if (enableFatalTypeErrors && configuration['component'] == 'dartc') {
601 args.add('--fatal-type-errors'); 606 args.add('--fatal-type-errors');
602 } 607 }
603 608
604 bool isMultitest = optionsFromFile["isMultitest"]; 609 bool isMultitest = optionsFromFile["isMultitest"];
605 List<String> dartOptions = optionsFromFile["dartOptions"]; 610 List<String> dartOptions = optionsFromFile["dartOptions"];
606 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"]; 611 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"];
607 Expect.isTrue(!isMultitest || dartOptions == null); 612 Expect.isTrue(!isMultitest || dartOptions == null);
608 if (dartOptions == null) { 613 if (dartOptions == null) {
609 args.add(filename); 614 args.add(filename);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 void activityStarted() { ++activityCount; } 729 void activityStarted() { ++activityCount; }
725 730
726 void activityCompleted() { 731 void activityCompleted() {
727 if (--activityCount == 0) { 732 if (--activityCount == 0) {
728 directoryListingDone(true); 733 directoryListingDone(true);
729 } 734 }
730 } 735 }
731 736
732 String shellPath() => TestUtils.compilerPath(configuration); 737 String shellPath() => TestUtils.compilerPath(configuration);
733 738
734 List<String> additionalOptions() { 739 List<String> additionalOptions(String filename) {
735 // TODO(ager): potentially register cleanup action to delete the temporary 740 filename = new File(filename).fullPathSync();
736 // directories? 741 Directory tempDir = createTemporaryDirectory(filename, 'dartc-test');
737 var tempDir = new Directory('');
738 tempDir.createTempSync();
739 return 742 return
740 [ '--fatal-warnings', '--fatal-type-errors', 743 [ '--fatal-warnings', '--fatal-type-errors',
741 '-check-only', '-out', tempDir.path]; 744 '-check-only', '-out', tempDir.path];
742 } 745 }
743 746
744 void processDirectory() { 747 void processDirectory() {
745 directoryPath = getDirname(directoryPath); 748 directoryPath = getDirname(directoryPath);
746 // Enqueueing the directory listers is an activity. 749 // Enqueueing the directory listers is an activity.
747 activityStarted(); 750 activityStarted();
748 for (String testDir in _testDirs) { 751 for (String testDir in _testDirs) {
(...skipping 12 matching lines...) Expand all
761 activityCompleted(); 764 activityCompleted();
762 } 765 }
763 } 766 }
764 767
765 768
766 class JUnitTestSuite implements TestSuite { 769 class JUnitTestSuite implements TestSuite {
767 Map configuration; 770 Map configuration;
768 String suiteName; 771 String suiteName;
769 String directoryPath; 772 String directoryPath;
770 String statusFilePath; 773 String statusFilePath;
771 String dartDir; 774 final String dartDir;
772 String buildDir; 775 String buildDir;
773 String classPath; 776 String classPath;
774 List<String> testClasses; 777 List<String> testClasses;
775 Function doTest; 778 Function doTest;
776 Function doDone; 779 Function doDone;
777 TestExpectations testExpectations; 780 TestExpectations testExpectations;
778 781
779 JUnitTestSuite(Map this.configuration, 782 JUnitTestSuite(Map this.configuration,
780 String this.suiteName, 783 String this.suiteName,
781 String this.directoryPath, 784 String this.directoryPath,
782 String this.statusFilePath); 785 String this.statusFilePath)
786 : dartDir = TestUtils.dartDir();
783 787
784 bool isTestFile(String filename) => filename.endsWith("Tests.java") && 788 bool isTestFile(String filename) => filename.endsWith("Tests.java") &&
785 !filename.contains('com/google/dart/compiler/vm') && 789 !filename.contains('com/google/dart/compiler/vm') &&
786 !filename.contains('com/google/dart/corelib/SharedTests.java'); 790 !filename.contains('com/google/dart/corelib/SharedTests.java');
787 791
788 void forEachTest(Function onTest, 792 void forEachTest(Function onTest,
789 Map testCacheIgnored, 793 Map testCacheIgnored,
794 String globalTempDir(),
790 [Function onDone = null]) { 795 [Function onDone = null]) {
791 doTest = onTest; 796 doTest = onTest;
792 doDone = (onDone != null) ? onDone : (() => null); 797 doDone = (onDone != null) ? onDone : (() => null);
793 798
794 if (configuration['component'] != 'dartc') { 799 if (configuration['component'] != 'dartc') {
795 // Do nothing. Asynchronously report that the suite is enqueued. 800 // Do nothing. Asynchronously report that the suite is enqueued.
796 new Timer((timerUnused){ doDone(); }, 0); 801 new Timer((timerUnused){ doDone(); }, 0);
797 return; 802 return;
798 } 803 }
799 RegExp pattern = configuration['selectors']['dartc']; 804 RegExp pattern = configuration['selectors']['dartc'];
800 if (!pattern.hasMatch('junit_tests')) { 805 if (!pattern.hasMatch('junit_tests')) {
801 new Timer((timerUnused){ doDone(); }, 0); 806 new Timer((timerUnused){ doDone(); }, 0);
802 return; 807 return;
803 } 808 }
804 809
805 dartDir = new File('.').fullPathSync();
806 if (dartDir.endsWith('compiler')) {
807 dartDir = new File('..').fullPathSync();
808 if (!new File('$dartDir/tools/test.dart').existsSync()) {
809 throw new Exception('Cannot find client checkout $dartDir');
810 }
811 }
812 buildDir = TestUtils.buildDir(configuration); 810 buildDir = TestUtils.buildDir(configuration);
813 computeClassPath(); 811 computeClassPath();
814 testClasses = <String>[]; 812 testClasses = <String>[];
815 // Do not read the status file. 813 // Do not read the status file.
816 // All exclusions are hardcoded in this script, as they are in testcfg.py. 814 // All exclusions are hardcoded in this script, as they are in testcfg.py.
817 processDirectory(); 815 processDirectory();
818 } 816 }
819 817
820 void processDirectory() { 818 void processDirectory() {
821 directoryPath = getDirname(directoryPath); 819 directoryPath = getDirname(directoryPath);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 return outputDir; 952 return outputDir;
955 } 953 }
956 954
957 static String buildDir(Map configuration) { 955 static String buildDir(Map configuration) {
958 var buildDir = outputDir(configuration); 956 var buildDir = outputDir(configuration);
959 buildDir += (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_'; 957 buildDir += (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_';
960 buildDir += configuration['arch']; 958 buildDir += configuration['arch'];
961 return buildDir; 959 return buildDir;
962 } 960 }
963 961
962 static String dartDir() {
963 Directory dart;
964 if (new File('tools/testing/dart/test_suite.dart').existsSync()) {
965 return new File('.').fullPathSync();
966 } else if (new File('../tools/testing/dart/test_suite.dart').existsSync()) {
967 return new File('..').fullPathSync();
968 } else {
969 print('Run test.dart from the dart directory or' +
970 ' an immediate subdirectory only.');
971 Expect.fail('Could not find top level dart directory.');
972 }
973 }
974
964 static List<String> standardOptions(Map configuration) { 975 static List<String> standardOptions(Map configuration) {
965 List args = ["--ignore-unrecognized-flags"]; 976 List args = ["--ignore-unrecognized-flags"];
966 if (configuration["checked"]) { 977 if (configuration["checked"]) {
967 args.add('--enable_asserts'); 978 args.add('--enable_asserts');
968 args.add("--enable_type_checks"); 979 args.add("--enable_type_checks");
969 } 980 }
970 if (configuration["component"] == "leg") { 981 if (configuration["component"] == "leg") {
971 args.add("--enable_leg"); 982 args.add("--enable_leg");
972 args.add("--leg_only"); 983 args.add("--leg_only");
973 } 984 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 * $noCrash tests are expected to be flaky but not crash 1035 * $noCrash tests are expected to be flaky but not crash
1025 * $pass tests are expected to pass 1036 * $pass tests are expected to pass
1026 * $failOk tests are expected to fail that we won't fix 1037 * $failOk tests are expected to fail that we won't fix
1027 * $fail tests are expected to fail that we should fix 1038 * $fail tests are expected to fail that we should fix
1028 * $crash tests are expected to crash that we should fix 1039 * $crash tests are expected to crash that we should fix
1029 * $timeout tests are allowed to timeout 1040 * $timeout tests are allowed to timeout
1030 """; 1041 """;
1031 print(report); 1042 print(report);
1032 } 1043 }
1033 } 1044 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_runner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698