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

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: Use the correct version of DeMorgan's law when rearranging if statements. 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_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 tempDir,
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 tempDir,
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 String 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 tempDir,
181 [Function onDone = null]) {
178 doTest = onTest; 182 doTest = onTest;
179 doDone = (onDone != null) ? onDone : (() => null); 183 doDone = (onDone != null) ? onDone : (() => null);
184 globalTemporaryDirectory = tempDir;
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 doTest(testCase); 484 doTest(testCase);
490 } 485 }
491 } 486 }
492 487
493 /** 488 /**
494 * Create a directory for the generated test. Drop the path to the 489 * Create a directory for the generated test. Drop the path to the
495 * dart checkout and the final ".dart" from the test path, and replace 490 * dart checkout and the final ".dart" from the test path, and replace
496 * all path separators with underscores. 491 * all path separators with underscores.
497 */ 492 */
498 Directory createTemporaryDirectory(String testPath, 493 Directory createTemporaryDirectory(String testPath,
499 String dartDir,
500 String optionsName) { 494 String optionsName) {
501 String testUniqueName = 495 String testUniqueName =
502 testPath.substring(dartDir.length + 1, testPath.length - 5); 496 testPath.substring(dartDir.length + 1, testPath.length - 5);
503 testUniqueName = testUniqueName.replaceAll('/', '_'); 497 testUniqueName = testUniqueName.replaceAll('/', '_');
504 testUniqueName += '-$optionsName'; 498 testUniqueName += '-$optionsName';
505 // Create '[build dir]/generated_tests/$component/$testUniqueName', 499 // Create '[build dir]/generated_tests/$component/$testUniqueName',
506 // including any intermediate directories that don't exist. 500 // including any intermediate directories that don't exist.
507 var generatedTestPath = ['generated_tests', 501 var generatedTestPath = ['generated_tests',
508 configuration['component'], 502 configuration['component'],
509 testUniqueName]; 503 testUniqueName];
510 504
511 String tempDirPath = TestUtils.buildDir(configuration); 505 String tempDirPath = TestUtils.buildDir(configuration);
506 if (configuration['component'] == 'dartc' ||
507 configuration['component'] == 'chromium') {
508 // We don't create a temporary directory for dartc and chromium
509 // tests on Windows, since they aren't supported on it.
510 Expect.isTrue(new Platform().operatingSystem() != 'windows',
Mads Ager (chromium) 2012/01/18 06:57:17 I would move this assert to where we actually crea
Bill Hesse 2012/01/18 11:52:38 We can drop the assert, or change it to Expect.isT
511 'dartc and chromium components not supported on windows');
512 tempDirPath = globalTemporaryDirectory;
513 }
512 Directory tempDir = new Directory(tempDirPath); 514 Directory tempDir = new Directory(tempDirPath);
513 if (!tempDir.existsSync()) { 515 if (!tempDir.existsSync()) {
514 // Dartium tests can be run with no build step, with no output directory. 516 // Dartium tests can be run with no build step, with no output directory.
515 // This special case builds the build directory that should be there. 517 // This special case builds the build directory that should be there.
516 var buildPath = tempDirPath.split('/'); 518 var buildPath = tempDirPath.split('/');
517 tempDirPath = buildPath[0]; 519 tempDirPath = buildPath[0];
518 if (tempDirPath == '') { 520 if (tempDirPath == '') {
519 throw new Exception( 521 throw new Exception(
520 'Non-relative path to build directory in test_suite.dart'); 522 'Non-relative path to build directory in test_suite.dart');
521 } 523 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } 586 }
585 } 587 }
586 588
587 void completeHandler(TestCase testCase) { 589 void completeHandler(TestCase testCase) {
588 } 590 }
589 591
590 List<List<String>> argumentListsFromFile(String filename, 592 List<List<String>> argumentListsFromFile(String filename,
591 Map optionsFromFile, 593 Map optionsFromFile,
592 bool enableFatalTypeErrors) { 594 bool enableFatalTypeErrors) {
593 List args = TestUtils.standardOptions(configuration); 595 List args = TestUtils.standardOptions(configuration);
594 args.addAll(additionalOptions()); 596 args.addAll(additionalOptions(filename));
595 if (enableFatalTypeErrors && configuration['component'] == 'dartc') { 597 if (enableFatalTypeErrors && configuration['component'] == 'dartc') {
596 args.add('--fatal-type-errors'); 598 args.add('--fatal-type-errors');
597 } 599 }
598 600
599 bool isMultitest = optionsFromFile["isMultitest"]; 601 bool isMultitest = optionsFromFile["isMultitest"];
600 List<String> dartOptions = optionsFromFile["dartOptions"]; 602 List<String> dartOptions = optionsFromFile["dartOptions"];
601 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"]; 603 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"];
602 Expect.isTrue(!isMultitest || dartOptions == null); 604 Expect.isTrue(!isMultitest || dartOptions == null);
603 if (dartOptions == null) { 605 if (dartOptions == null) {
604 args.add(filename); 606 args.add(filename);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 void activityStarted() { ++activityCount; } 721 void activityStarted() { ++activityCount; }
720 722
721 void activityCompleted() { 723 void activityCompleted() {
722 if (--activityCount == 0) { 724 if (--activityCount == 0) {
723 directoryListingDone(true); 725 directoryListingDone(true);
724 } 726 }
725 } 727 }
726 728
727 String shellPath() => TestUtils.compilerPath(configuration); 729 String shellPath() => TestUtils.compilerPath(configuration);
728 730
729 List<String> additionalOptions() { 731 List<String> additionalOptions(String filename) {
730 // TODO(ager): potentially register cleanup action to delete the temporary 732 filename = new File(filename).fullPathSync();
731 // directories? 733 Directory tempDir = createTemporaryDirectory(filename, 'dartc-test');
732 var tempDir = new Directory('');
733 tempDir.createTempSync();
734 return 734 return
735 [ '--fatal-warnings', '--fatal-type-errors', 735 [ '--fatal-warnings', '--fatal-type-errors',
736 '-check-only', '-out', tempDir.path]; 736 '-check-only', '-out', tempDir.path];
737 } 737 }
738 738
739 void processDirectory() { 739 void processDirectory() {
740 directoryPath = getDirname(directoryPath); 740 directoryPath = getDirname(directoryPath);
741 // Enqueueing the directory listers is an activity. 741 // Enqueueing the directory listers is an activity.
742 activityStarted(); 742 activityStarted();
743 for (String testDir in _testDirs) { 743 for (String testDir in _testDirs) {
(...skipping 12 matching lines...) Expand all
756 activityCompleted(); 756 activityCompleted();
757 } 757 }
758 } 758 }
759 759
760 760
761 class JUnitTestSuite implements TestSuite { 761 class JUnitTestSuite implements TestSuite {
762 Map configuration; 762 Map configuration;
763 String suiteName; 763 String suiteName;
764 String directoryPath; 764 String directoryPath;
765 String statusFilePath; 765 String statusFilePath;
766 String dartDir; 766 final String dartDir;
767 String buildDir; 767 String buildDir;
768 String classPath; 768 String classPath;
769 List<String> testClasses; 769 List<String> testClasses;
770 Function doTest; 770 Function doTest;
771 Function doDone; 771 Function doDone;
772 TestExpectations testExpectations; 772 TestExpectations testExpectations;
773 773
774 JUnitTestSuite(Map this.configuration, 774 JUnitTestSuite(Map this.configuration,
775 String this.suiteName, 775 String this.suiteName,
776 String this.directoryPath, 776 String this.directoryPath,
777 String this.statusFilePath); 777 String this.statusFilePath)
778 : dartDir = TestUtils.dartDir();
778 779
779 bool isTestFile(String filename) => filename.endsWith("Tests.java") && 780 bool isTestFile(String filename) => filename.endsWith("Tests.java") &&
780 !filename.contains('com/google/dart/compiler/vm') && 781 !filename.contains('com/google/dart/compiler/vm') &&
781 !filename.contains('com/google/dart/corelib/SharedTests.java'); 782 !filename.contains('com/google/dart/corelib/SharedTests.java');
782 783
783 void forEachTest(Function onTest, 784 void forEachTest(Function onTest,
784 Map testCacheIgnored, 785 Map testCacheIgnored,
786 String tempDir,
785 [Function onDone = null]) { 787 [Function onDone = null]) {
786 doTest = onTest; 788 doTest = onTest;
787 doDone = (onDone != null) ? onDone : (() => null); 789 doDone = (onDone != null) ? onDone : (() => null);
788 790
789 if (configuration['component'] != 'dartc') { 791 if (configuration['component'] != 'dartc') {
790 // Do nothing. Asynchronously report that the suite is enqueued. 792 // Do nothing. Asynchronously report that the suite is enqueued.
791 new Timer((timerUnused){ doDone(); }, 0); 793 new Timer((timerUnused){ doDone(); }, 0);
792 return; 794 return;
793 } 795 }
794 RegExp pattern = configuration['selectors']['dartc']; 796 RegExp pattern = configuration['selectors']['dartc'];
795 if (!pattern.hasMatch('junit_tests')) { 797 if (!pattern.hasMatch('junit_tests')) {
796 new Timer((timerUnused){ doDone(); }, 0); 798 new Timer((timerUnused){ doDone(); }, 0);
797 return; 799 return;
798 } 800 }
799 801
800 dartDir = new File('.').fullPathSync();
801 if (dartDir.endsWith('compiler')) {
802 dartDir = new File('..').fullPathSync();
803 if (!new File('$dartDir/tools/test.dart').existsSync()) {
804 throw new Exception('Cannot find client checkout $dartDir');
805 }
806 }
807 buildDir = TestUtils.buildDir(configuration); 802 buildDir = TestUtils.buildDir(configuration);
808 computeClassPath(); 803 computeClassPath();
809 testClasses = <String>[]; 804 testClasses = <String>[];
810 // Do not read the status file. 805 // Do not read the status file.
811 // All exclusions are hardcoded in this script, as they are in testcfg.py. 806 // All exclusions are hardcoded in this script, as they are in testcfg.py.
812 processDirectory(); 807 processDirectory();
813 } 808 }
814 809
815 void processDirectory() { 810 void processDirectory() {
816 directoryPath = getDirname(directoryPath); 811 directoryPath = getDirname(directoryPath);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 return outputDir; 941 return outputDir;
947 } 942 }
948 943
949 static String buildDir(Map configuration) { 944 static String buildDir(Map configuration) {
950 var buildDir = outputDir(configuration); 945 var buildDir = outputDir(configuration);
951 buildDir += (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_'; 946 buildDir += (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_';
952 buildDir += configuration['arch']; 947 buildDir += configuration['arch'];
953 return buildDir; 948 return buildDir;
954 } 949 }
955 950
951 static String dartDir() {
952 Directory dart;
953 if (new File('tools/testing/dart/test_suite.dart').existsSync()) {
954 return new File('.').fullPathSync();
955 } else if (new File('../tools/testing/dart/test_suite.dart').existsSync()) {
956 return new File('..').fullPathSync();
957 } else {
958 print('Run test.dart from the dart directory or' +
959 ' an immediate subdirectory only.');
960 Expect.fail('Could not find top level dart directory.');
961 }
962 }
963
956 static List<String> standardOptions(Map configuration) { 964 static List<String> standardOptions(Map configuration) {
957 List args = ["--ignore-unrecognized-flags"]; 965 List args = ["--ignore-unrecognized-flags"];
958 if (configuration["checked"]) { 966 if (configuration["checked"]) {
959 args.add('--enable_asserts'); 967 args.add('--enable_asserts');
960 args.add("--enable_type_checks"); 968 args.add("--enable_type_checks");
961 } 969 }
962 if (configuration["component"] == "leg") { 970 if (configuration["component"] == "leg") {
963 args.add("--enable_leg"); 971 args.add("--enable_leg");
964 args.add("--leg_only"); 972 args.add("--leg_only");
965 } 973 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 * $noCrash tests are expected to be flaky but not crash 1024 * $noCrash tests are expected to be flaky but not crash
1017 * $pass tests are expected to pass 1025 * $pass tests are expected to pass
1018 * $failOk tests are expected to fail that we won't fix 1026 * $failOk tests are expected to fail that we won't fix
1019 * $fail tests are expected to fail that we should fix 1027 * $fail tests are expected to fail that we should fix
1020 * $crash tests are expected to crash that we should fix 1028 * $crash tests are expected to crash that we should fix
1021 * $timeout tests are allowed to timeout 1029 * $timeout tests are allowed to timeout
1022 """; 1030 """;
1023 print(report); 1031 print(report);
1024 } 1032 }
1025 } 1033 }
OLDNEW
« tools/testing/dart/test_runner.dart ('K') | « tools/testing/dart/test_runner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698