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

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: Changed name to createOutputDirectory 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 = createOutputDirectory(testPath, optionsName);
382 createTemporaryDirectory(testPath, dartDir, optionsName);
383 377
384 String dartWrapperFilename = '${tempDir.path}/test.dart'; 378 String dartWrapperFilename = '${tempDir.path}/test.dart';
385 String compiledDartWrapperFilename = '${tempDir.path}/test.js'; 379 String compiledDartWrapperFilename = '${tempDir.path}/test.js';
386 String domLibraryImport = (component == 'chromium') ? 380 String domLibraryImport = (component == 'chromium') ?
387 '$dartDir/client/testing/unittest/dom_for_unittest.dart' : 'dart:dom'; 381 '$dartDir/client/testing/unittest/dom_for_unittest.dart' : 'dart:dom';
388 382
389 String htmlPath = '${tempDir.path}/test.html'; 383 String htmlPath = '${tempDir.path}/test.html';
390 if (!isWebTest) { 384 if (!isWebTest) {
391 // test.dart will import the dart test directly, if it is a library, 385 // 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. 386 // 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, 482 executable,
489 args, 483 args,
490 configuration, 484 configuration,
491 completeHandler, 485 completeHandler,
492 expectations, 486 expectations,
493 optionsFromFile['isNegative']); 487 optionsFromFile['isNegative']);
494 doTest(testCase); 488 doTest(testCase);
495 } 489 }
496 } 490 }
497 491
492 bool get requiresCleanTemporaryDirectory() =>
493 configuration['component'] == 'dartc' ||
494 configuration['component'] == 'chromium';
495
498 /** 496 /**
499 * Create a directory for the generated test. Drop the path to the 497 * 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 498 * dart checkout and the final ".dart" from the test path, and replace
501 * all path separators with underscores. 499 * all path separators with underscores.
502 */ 500 */
503 Directory createTemporaryDirectory(String testPath, 501 Directory createOutputDirectory(String testPath, String optionsName) {
504 String dartDir,
505 String optionsName) {
506 String testUniqueName = 502 String testUniqueName =
507 testPath.substring(dartDir.length + 1, testPath.length - 5); 503 testPath.substring(dartDir.length + 1, testPath.length - 5);
508 testUniqueName = testUniqueName.replaceAll('/', '_'); 504 testUniqueName = testUniqueName.replaceAll('/', '_');
509 testUniqueName += '-$optionsName'; 505 testUniqueName += '-$optionsName';
506
510 // Create '[build dir]/generated_tests/$component/$testUniqueName', 507 // Create '[build dir]/generated_tests/$component/$testUniqueName',
511 // including any intermediate directories that don't exist. 508 // including any intermediate directories that don't exist.
512 var generatedTestPath = ['generated_tests', 509 String debugMode =
510 (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_';
511 var generatedTestPath = [debugMode + configuration["arch"],
512 'generated_tests',
513 configuration['component'], 513 configuration['component'],
514 testUniqueName]; 514 testUniqueName];
515 515
516 String tempDirPath = TestUtils.buildDir(configuration); 516 String tempDirPath = TestUtils.buildDir(configuration);
517 if (requiresCleanTemporaryDirectory) {
518 tempDirPath = globalTemporaryDirectory();
519 }
517 Directory tempDir = new Directory(tempDirPath); 520 Directory tempDir = new Directory(tempDirPath);
518 if (!tempDir.existsSync()) { 521 if (!tempDir.existsSync()) {
519 // Dartium tests can be run with no build step, with no output directory. 522 // 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. 523 // This special case builds the build directory that should be there.
521 var buildPath = tempDirPath.split('/'); 524 var buildPath = tempDirPath.split('/');
522 tempDirPath = buildPath[0]; 525 tempDirPath = buildPath[0];
523 if (tempDirPath == '') { 526 if (tempDirPath == '') {
524 throw new Exception( 527 throw new Exception(
525 'Non-relative path to build directory in test_suite.dart'); 528 'Non-relative path to build directory in test_suite.dart');
526 } 529 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 592 }
590 } 593 }
591 594
592 void completeHandler(TestCase testCase) { 595 void completeHandler(TestCase testCase) {
593 } 596 }
594 597
595 List<List<String>> argumentListsFromFile(String filename, 598 List<List<String>> argumentListsFromFile(String filename,
596 Map optionsFromFile, 599 Map optionsFromFile,
597 bool enableFatalTypeErrors) { 600 bool enableFatalTypeErrors) {
598 List args = TestUtils.standardOptions(configuration); 601 List args = TestUtils.standardOptions(configuration);
599 args.addAll(additionalOptions()); 602 args.addAll(additionalOptions(filename));
600 if (enableFatalTypeErrors && configuration['component'] == 'dartc') { 603 if (enableFatalTypeErrors && configuration['component'] == 'dartc') {
601 args.add('--fatal-type-errors'); 604 args.add('--fatal-type-errors');
602 } 605 }
603 606
604 bool isMultitest = optionsFromFile["isMultitest"]; 607 bool isMultitest = optionsFromFile["isMultitest"];
605 List<String> dartOptions = optionsFromFile["dartOptions"]; 608 List<String> dartOptions = optionsFromFile["dartOptions"];
606 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"]; 609 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"];
607 Expect.isTrue(!isMultitest || dartOptions == null); 610 Expect.isTrue(!isMultitest || dartOptions == null);
608 if (dartOptions == null) { 611 if (dartOptions == null) {
609 args.add(filename); 612 args.add(filename);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 void activityStarted() { ++activityCount; } 727 void activityStarted() { ++activityCount; }
725 728
726 void activityCompleted() { 729 void activityCompleted() {
727 if (--activityCount == 0) { 730 if (--activityCount == 0) {
728 directoryListingDone(true); 731 directoryListingDone(true);
729 } 732 }
730 } 733 }
731 734
732 String shellPath() => TestUtils.compilerPath(configuration); 735 String shellPath() => TestUtils.compilerPath(configuration);
733 736
734 List<String> additionalOptions() { 737 List<String> additionalOptions(String filename) {
735 // TODO(ager): potentially register cleanup action to delete the temporary 738 filename = new File(filename).fullPathSync();
736 // directories? 739 Directory tempDir = createOutputDirectory(filename, 'dartc-test');
737 var tempDir = new Directory('');
738 tempDir.createTempSync();
739 return 740 return
740 [ '--fatal-warnings', '--fatal-type-errors', 741 [ '--fatal-warnings', '--fatal-type-errors',
741 '-check-only', '-out', tempDir.path]; 742 '-check-only', '-out', tempDir.path];
742 } 743 }
743 744
744 void processDirectory() { 745 void processDirectory() {
745 directoryPath = getDirname(directoryPath); 746 directoryPath = getDirname(directoryPath);
746 // Enqueueing the directory listers is an activity. 747 // Enqueueing the directory listers is an activity.
747 activityStarted(); 748 activityStarted();
748 for (String testDir in _testDirs) { 749 for (String testDir in _testDirs) {
(...skipping 12 matching lines...) Expand all
761 activityCompleted(); 762 activityCompleted();
762 } 763 }
763 } 764 }
764 765
765 766
766 class JUnitTestSuite implements TestSuite { 767 class JUnitTestSuite implements TestSuite {
767 Map configuration; 768 Map configuration;
768 String suiteName; 769 String suiteName;
769 String directoryPath; 770 String directoryPath;
770 String statusFilePath; 771 String statusFilePath;
771 String dartDir; 772 final String dartDir;
772 String buildDir; 773 String buildDir;
773 String classPath; 774 String classPath;
774 List<String> testClasses; 775 List<String> testClasses;
775 Function doTest; 776 Function doTest;
776 Function doDone; 777 Function doDone;
777 TestExpectations testExpectations; 778 TestExpectations testExpectations;
778 779
779 JUnitTestSuite(Map this.configuration, 780 JUnitTestSuite(Map this.configuration,
780 String this.suiteName, 781 String this.suiteName,
781 String this.directoryPath, 782 String this.directoryPath,
782 String this.statusFilePath); 783 String this.statusFilePath)
784 : dartDir = TestUtils.dartDir();
783 785
784 bool isTestFile(String filename) => filename.endsWith("Tests.java") && 786 bool isTestFile(String filename) => filename.endsWith("Tests.java") &&
785 !filename.contains('com/google/dart/compiler/vm') && 787 !filename.contains('com/google/dart/compiler/vm') &&
786 !filename.contains('com/google/dart/corelib/SharedTests.java'); 788 !filename.contains('com/google/dart/corelib/SharedTests.java');
787 789
788 void forEachTest(Function onTest, 790 void forEachTest(Function onTest,
789 Map testCacheIgnored, 791 Map testCacheIgnored,
792 String globalTempDir(),
790 [Function onDone = null]) { 793 [Function onDone = null]) {
791 doTest = onTest; 794 doTest = onTest;
792 doDone = (onDone != null) ? onDone : (() => null); 795 doDone = (onDone != null) ? onDone : (() => null);
793 796
794 if (configuration['component'] != 'dartc') { 797 if (configuration['component'] != 'dartc') {
795 // Do nothing. Asynchronously report that the suite is enqueued. 798 // Do nothing. Asynchronously report that the suite is enqueued.
796 new Timer((timerUnused){ doDone(); }, 0); 799 new Timer((timerUnused){ doDone(); }, 0);
797 return; 800 return;
798 } 801 }
799 RegExp pattern = configuration['selectors']['dartc']; 802 RegExp pattern = configuration['selectors']['dartc'];
800 if (!pattern.hasMatch('junit_tests')) { 803 if (!pattern.hasMatch('junit_tests')) {
801 new Timer((timerUnused){ doDone(); }, 0); 804 new Timer((timerUnused){ doDone(); }, 0);
802 return; 805 return;
803 } 806 }
804 807
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); 808 buildDir = TestUtils.buildDir(configuration);
813 computeClassPath(); 809 computeClassPath();
814 testClasses = <String>[]; 810 testClasses = <String>[];
815 // Do not read the status file. 811 // Do not read the status file.
816 // All exclusions are hardcoded in this script, as they are in testcfg.py. 812 // All exclusions are hardcoded in this script, as they are in testcfg.py.
817 processDirectory(); 813 processDirectory();
818 } 814 }
819 815
820 void processDirectory() { 816 void processDirectory() {
821 directoryPath = getDirname(directoryPath); 817 directoryPath = getDirname(directoryPath);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 return outputDir; 950 return outputDir;
955 } 951 }
956 952
957 static String buildDir(Map configuration) { 953 static String buildDir(Map configuration) {
958 var buildDir = outputDir(configuration); 954 var buildDir = outputDir(configuration);
959 buildDir += (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_'; 955 buildDir += (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_';
960 buildDir += configuration['arch']; 956 buildDir += configuration['arch'];
961 return buildDir; 957 return buildDir;
962 } 958 }
963 959
960 static String dartDir() {
961 Directory dart;
962 if (new File('tools/testing/dart/test_suite.dart').existsSync()) {
963 return new File('.').fullPathSync();
964 } else if (new File('../tools/testing/dart/test_suite.dart').existsSync()) {
965 return new File('..').fullPathSync();
966 } else {
967 print('Run test.dart from the dart directory or' +
968 ' an immediate subdirectory only.');
969 Expect.fail('Could not find top level dart directory.');
970 }
971 }
972
964 static List<String> standardOptions(Map configuration) { 973 static List<String> standardOptions(Map configuration) {
965 List args = ["--ignore-unrecognized-flags"]; 974 List args = ["--ignore-unrecognized-flags"];
966 if (configuration["checked"]) { 975 if (configuration["checked"]) {
967 args.add('--enable_asserts'); 976 args.add('--enable_asserts');
968 args.add("--enable_type_checks"); 977 args.add("--enable_type_checks");
969 } 978 }
970 if (configuration["component"] == "leg") { 979 if (configuration["component"] == "leg") {
971 args.add("--enable_leg"); 980 args.add("--enable_leg");
972 args.add("--leg_only"); 981 args.add("--leg_only");
973 } 982 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 * $noCrash tests are expected to be flaky but not crash 1033 * $noCrash tests are expected to be flaky but not crash
1025 * $pass tests are expected to pass 1034 * $pass tests are expected to pass
1026 * $failOk tests are expected to fail that we won't fix 1035 * $failOk tests are expected to fail that we won't fix
1027 * $fail tests are expected to fail that we should fix 1036 * $fail tests are expected to fail that we should fix
1028 * $crash tests are expected to crash that we should fix 1037 * $crash tests are expected to crash that we should fix
1029 * $timeout tests are allowed to timeout 1038 * $timeout tests are allowed to timeout
1030 """; 1039 """;
1031 print(report); 1040 print(report);
1032 } 1041 }
1033 } 1042 }
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