| OLD | NEW |
| 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 | 9 |
| 10 interface TestSuite { | 10 interface TestSuite { |
| 11 void forEachTest(Function onTest, [Function onDone]); | 11 void forEachTest(Function onTest, [Function onDone]); |
| 12 } | 12 } |
| 13 | 13 |
| 14 | 14 |
| 15 class CCTestListerIsolate extends Isolate { |
| 16 CCTestListerIsolate() : super.heavy(); |
| 17 |
| 18 void main() { |
| 19 port.receive((String runnerPath, SendPort replyTo) { |
| 20 var p = new Process(runnerPath, ["--list"]); |
| 21 StringInputStream stdoutStream = new StringInputStream(p.stdout); |
| 22 List<String> tests = new List<String>(); |
| 23 stdoutStream.dataHandler = () { |
| 24 String line = stdoutStream.readLine(); |
| 25 while (line != null) { |
| 26 tests.add(line); |
| 27 line = stdoutStream.readLine(); |
| 28 } |
| 29 }; |
| 30 p.exitHandler = (code) { |
| 31 if (code < 0) { |
| 32 print("Failed to list tests: $runnerPath --list"); |
| 33 replyTo.send(""); |
| 34 } |
| 35 for (String test in tests) { |
| 36 replyTo.send(test); |
| 37 } |
| 38 replyTo.send(""); |
| 39 }; |
| 40 p.start(); |
| 41 }); |
| 42 } |
| 43 } |
| 44 |
| 45 |
| 46 class CCTestSuite implements TestSuite { |
| 47 Map configuration; |
| 48 String runnerPath; |
| 49 List<String> statusFilePaths; |
| 50 Function doTest; |
| 51 Function doDone; |
| 52 ReceivePort receiveTestName; |
| 53 TestExpectations testExpectations; |
| 54 |
| 55 CCTestSuite(Map this.configuration, |
| 56 String runnerName, |
| 57 List<String> this.statusFilePaths) { |
| 58 runnerPath = TestUtils.getBuildDir(configuration) + runnerName; |
| 59 } |
| 60 |
| 61 void complexStatusMatching() => false; |
| 62 |
| 63 void testNameHandler(String testName, ignore) { |
| 64 if (testName == "") { |
| 65 receiveTestName.close(); |
| 66 } else { |
| 67 var timeout = configuration['timeout']; |
| 68 var expectations = testExpectations.expectations(testName); |
| 69 |
| 70 if (expectations.contains(SKIP)) return; |
| 71 |
| 72 // TODO(ager): Pass extra options to the tests. |
| 73 doTest(new TestCase(testName, |
| 74 runnerPath, |
| 75 [testName], |
| 76 timeout, |
| 77 completeHandler, |
| 78 expectations)); |
| 79 receiveTestName.receive(testNameHandler); |
| 80 } |
| 81 } |
| 82 |
| 83 void forEachTest(Function onTest, [Function onDone]) { |
| 84 doTest = onTest; |
| 85 onDone = (ignore) => (onDone != null) ? onDone() : null; |
| 86 |
| 87 testExpectations = |
| 88 new TestExpectations(complexMatching: complexStatusMatching()); |
| 89 for (var statusFilePath in statusFilePaths) { |
| 90 ReadTestExpectationsInto(testExpectations, |
| 91 statusFilePath, |
| 92 configuration); |
| 93 } |
| 94 |
| 95 receiveTestName = new ReceivePort(); |
| 96 new CCTestListerIsolate().spawn().then((port) { |
| 97 port.send(runnerPath, receiveTestName); |
| 98 receiveTestName.receive(testNameHandler); |
| 99 }); |
| 100 } |
| 101 |
| 102 void completeHandler(TestCase testCase) { |
| 103 } |
| 104 } |
| 105 |
| 106 |
| 15 class StandardTestSuite implements TestSuite { | 107 class StandardTestSuite implements TestSuite { |
| 16 Map configuration; | 108 Map configuration; |
| 17 String directoryPath; | 109 String directoryPath; |
| 18 List<String> statusFilePaths; | 110 List<String> statusFilePaths; |
| 19 Function doTest; | 111 Function doTest; |
| 20 Function doDone; | 112 Function doDone; |
| 21 String shellPath; | 113 String shellPath; |
| 22 TestExpectations testExpectations; | 114 TestExpectations testExpectations; |
| 23 | 115 |
| 24 StandardTestSuite(Map this.configuration, | 116 StandardTestSuite(Map this.configuration, |
| 25 String this.directoryPath, | 117 String this.directoryPath, |
| 26 List<String> this.statusFilePaths) { | 118 List<String> this.statusFilePaths) { |
| 27 shellPath = getDartShellFileName(configuration) ; | 119 shellPath = TestUtils.getDartShellFileName(configuration) ; |
| 28 } | 120 } |
| 29 | 121 |
| 30 | 122 |
| 31 void isTestFile(String filename) => filename.endsWith("Test.dart"); | 123 void isTestFile(String filename) => filename.endsWith("Test.dart"); |
| 32 | 124 |
| 33 void listRecursively() => false; | 125 void listRecursively() => false; |
| 34 | 126 |
| 35 void complexStatusMatching() => false; | 127 void complexStatusMatching() => false; |
| 36 | 128 |
| 37 void forEachTest(Function onTest, [Function onDone = null]) { | 129 void forEachTest(Function onTest, [Function onDone = null]) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 isNegative)); | 184 isNegative)); |
| 93 } | 185 } |
| 94 } | 186 } |
| 95 | 187 |
| 96 void completeHandler(TestCase testCase) { | 188 void completeHandler(TestCase testCase) { |
| 97 } | 189 } |
| 98 | 190 |
| 99 List<List<String>> argumentLists(String filename, Map optionsFromFile) { | 191 List<List<String>> argumentLists(String filename, Map optionsFromFile) { |
| 100 List args = ["--ignore-unrecognized-flags"]; | 192 List args = ["--ignore-unrecognized-flags"]; |
| 101 if (configuration["checked"]) { | 193 if (configuration["checked"]) { |
| 194 args.add('--enable_asserts'); |
| 102 args.add("--enable_type_checks"); | 195 args.add("--enable_type_checks"); |
| 103 } | 196 } |
| 104 if (configuration["component"] == "leg") { | 197 if (configuration["component"] == "leg") { |
| 105 args.add("--enable_leg"); | 198 args.add("--enable_leg"); |
| 106 } | 199 } |
| 107 if (configuration["component"] == "dartc") { | 200 if (configuration["component"] == "dartc") { |
| 108 if (configuration["mode"] == "release") { | 201 if (configuration["mode"] == "release") { |
| 109 args.add("--optimize"); | 202 args.add("--optimize"); |
| 110 } | 203 } |
| 111 } | 204 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } else if (contents.contains("@dynamic-type-error") && | 263 } else if (contents.contains("@dynamic-type-error") && |
| 171 configuration['checked']) { | 264 configuration['checked']) { |
| 172 isNegative = true; | 265 isNegative = true; |
| 173 } | 266 } |
| 174 | 267 |
| 175 return { "vmOptions": result, | 268 return { "vmOptions": result, |
| 176 "dartOptions": dartOptions, | 269 "dartOptions": dartOptions, |
| 177 "isNegative" : isNegative }; | 270 "isNegative" : isNegative }; |
| 178 } | 271 } |
| 179 } | 272 } |
| 273 |
| 274 |
| 275 class TestUtils { |
| 276 static String getExecutableName(Map configuration) { |
| 277 switch (configuration['component']) { |
| 278 case 'vm': |
| 279 return 'dart_bin'; |
| 280 case 'dartc': |
| 281 return 'compiler/bin/dartc_test'; |
| 282 case 'frog': |
| 283 case 'leg': |
| 284 return 'frog/bin/frog'; |
| 285 case 'frogsh': |
| 286 return 'frog/bin/frogsh'; |
| 287 default: |
| 288 throw "Unknown executable for: ${configuration['component']}"; |
| 289 } |
| 290 } |
| 291 |
| 292 |
| 293 static String getDartShellFileName(Map configuration) { |
| 294 var name = getBuildDir(configuration) + getExecutableName(configuration); |
| 295 if (!(new File(name)).existsSync()) { |
| 296 throw "Executable '$name' does not exist"; |
| 297 } |
| 298 return name; |
| 299 } |
| 300 |
| 301 static String getBuildDir(Map configuration) { |
| 302 var buildDir = ''; |
| 303 var system = configuration['system']; |
| 304 if (system == 'linux') { |
| 305 buildDir = 'out/'; |
| 306 } else if (system == 'macos') { |
| 307 buildDir = 'xcodebuild/'; |
| 308 } |
| 309 buildDir += (configuration['mode'] == 'debug') ? 'Debug_' : 'Release_'; |
| 310 buildDir += configuration['architecture'] + '/'; |
| 311 return buildDir; |
| 312 } |
| 313 } |
| OLD | NEW |