OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 /// Test suite for running tests in a shared Dart VM. Take a look at | 5 /// Test suite for running tests in a shared Dart VM. Take a look at |
6 /// ../../../tests/fletch_tests/all_tests.dart for more information. | 6 /// ../../../tests/dartino_tests/all_tests.dart for more information. |
7 library test.fletch_test_suite; | 7 library test.dartino_test_suite; |
8 | 8 |
9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
10 | 10 |
11 import 'dart:convert' show | 11 import 'dart:convert' show |
12 JSON, | 12 JSON, |
13 LineSplitter, | 13 LineSplitter, |
14 UTF8, | 14 UTF8, |
15 Utf8Decoder; | 15 Utf8Decoder; |
16 | 16 |
17 import 'dart:async' show | 17 import 'dart:async' show |
(...skipping 14 matching lines...) Expand all Loading... |
32 TestCase; | 32 TestCase; |
33 | 33 |
34 import 'runtime_configuration.dart' show | 34 import 'runtime_configuration.dart' show |
35 RuntimeConfiguration; | 35 RuntimeConfiguration; |
36 | 36 |
37 import 'status_file_parser.dart' show | 37 import 'status_file_parser.dart' show |
38 Expectation, | 38 Expectation, |
39 ReadTestExpectationsInto, | 39 ReadTestExpectationsInto, |
40 TestExpectations; | 40 TestExpectations; |
41 | 41 |
42 import '../../../tests/fletch_tests/messages.dart' show | 42 import '../../../tests/dartino_tests/messages.dart' show |
43 ErrorMessage, | 43 ErrorMessage, |
44 Info, | 44 Info, |
45 ListTests, | 45 ListTests, |
46 ListTestsReply, | 46 ListTestsReply, |
47 Message, | 47 Message, |
48 NamedMessage, | 48 NamedMessage, |
49 RunTest, | 49 RunTest, |
50 TestFailed, | 50 TestFailed, |
51 TestStdoutLine, | 51 TestStdoutLine, |
52 TimedOut, | 52 TimedOut, |
53 messageTransformer; | 53 messageTransformer; |
54 | 54 |
55 class FletchTestRuntimeConfiguration extends RuntimeConfiguration { | 55 class DartinoTestRuntimeConfiguration extends RuntimeConfiguration { |
56 final String system; | 56 final String system; |
57 final String dartBinary; | 57 final String dartBinary; |
58 | 58 |
59 FletchTestRuntimeConfiguration(Map configuration) | 59 DartinoTestRuntimeConfiguration(Map configuration) |
60 : system = configuration['system'], | 60 : system = configuration['system'], |
61 dartBinary = '${TestUtils.buildDir(configuration)}' | 61 dartBinary = '${TestUtils.buildDir(configuration)}' |
62 '${io.Platform.pathSeparator}dart', | 62 '${io.Platform.pathSeparator}dart', |
63 super.subclass(); | 63 super.subclass(); |
64 } | 64 } |
65 | 65 |
66 class FletchTestSuite extends TestSuite { | 66 class DartinoTestSuite extends TestSuite { |
67 final String testSuiteDir; | 67 final String testSuiteDir; |
68 | 68 |
69 TestCompleter completer; | 69 TestCompleter completer; |
70 | 70 |
71 FletchTestSuite(Map configuration, this.testSuiteDir) | 71 DartinoTestSuite(Map configuration, this.testSuiteDir) |
72 : super(configuration, "fletch_tests"); | 72 : super(configuration, "dartino_tests"); |
73 | 73 |
74 void forEachTest( | 74 void forEachTest( |
75 void onTest(TestCase testCase), | 75 void onTest(TestCase testCase), |
76 Map testCache, | 76 Map testCache, |
77 [void onDone()]) { | 77 [void onDone()]) { |
78 this.doTest = onTest; | 78 this.doTest = onTest; |
79 if (configuration['runtime'] != 'fletch_tests') { | 79 if (configuration['runtime'] != 'dartino_tests') { |
80 onDone(); | 80 onDone(); |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 FletchTestRuntimeConfiguration runtimeConfiguration = | 84 DartinoTestRuntimeConfiguration runtimeConfiguration = |
85 new RuntimeConfiguration(configuration); | 85 new RuntimeConfiguration(configuration); |
86 | 86 |
87 TestExpectations expectations = new TestExpectations(); | 87 TestExpectations expectations = new TestExpectations(); |
88 String buildDir = TestUtils.buildDir(configuration); | 88 String buildDir = TestUtils.buildDir(configuration); |
89 String version; | 89 String version; |
90 | 90 |
91 // Define a path for temporary output generated during tests. | 91 // Define a path for temporary output generated during tests. |
92 String tempDirPath = '$buildDir/temporary_test_output'; | 92 String tempDirPath = '$buildDir/temporary_test_output'; |
93 io.Directory tempDir = new io.Directory(tempDirPath); | 93 io.Directory tempDir = new io.Directory(tempDirPath); |
94 try { | 94 try { |
95 tempDir.deleteSync(recursive: true); | 95 tempDir.deleteSync(recursive: true); |
96 } on io.FileSystemException catch (e) { | 96 } on io.FileSystemException catch (e) { |
97 // Ignored, we assume the file did not exist. | 97 // Ignored, we assume the file did not exist. |
98 } | 98 } |
99 | 99 |
100 String javaHome = _guessJavaHome(configuration["arch"]); | 100 String javaHome = _guessJavaHome(configuration["arch"]); |
101 if (javaHome == null) { | 101 if (javaHome == null) { |
102 String arch = configuration["arch"]; | 102 String arch = configuration["arch"]; |
103 print("Notice: Java tests are disabled"); | 103 print("Notice: Java tests are disabled"); |
104 print("Unable to find a JDK installation for architecture $arch"); | 104 print("Unable to find a JDK installation for architecture $arch"); |
105 print("Install a JDK or set JAVA_PATH to an existing installation."); | 105 print("Install a JDK or set JAVA_PATH to an existing installation."); |
106 // TODO(zerny): Throw an error if no-java is not supplied. | 106 // TODO(zerny): Throw an error if no-java is not supplied. |
107 } else { | 107 } else { |
108 print("Notice: Enabled Java tests using JDK at $javaHome"); | 108 print("Notice: Enabled Java tests using JDK at $javaHome"); |
109 } | 109 } |
110 | 110 |
111 bool helperProgramExited = false; | 111 bool helperProgramExited = false; |
112 io.Process vmProcess; | 112 io.Process vmProcess; |
113 ReadTestExpectationsInto( | 113 ReadTestExpectationsInto( |
114 expectations, '$testSuiteDir/fletch_tests.status', | 114 expectations, '$testSuiteDir/dartino_tests.status', |
115 configuration).then((_) { | 115 configuration).then((_) { |
116 return new io.File('$buildDir/gen/version.cc').readAsLines(); | 116 return new io.File('$buildDir/gen/version.cc').readAsLines(); |
117 }).then((List<String> versionFileLines) { | 117 }).then((List<String> versionFileLines) { |
118 // Search for the 'return "version_string";' line. | 118 // Search for the 'return "version_string";' line. |
119 for (String line in versionFileLines) { | 119 for (String line in versionFileLines) { |
120 if (line.contains('return')) { | 120 if (line.contains('return')) { |
121 version = line.substring( | 121 version = line.substring( |
122 line.indexOf('"') + 1, line.lastIndexOf('"')); | 122 line.indexOf('"') + 1, line.lastIndexOf('"')); |
123 } | 123 } |
124 } | 124 } |
125 assert(version != null); | 125 assert(version != null); |
126 }).then((_) { | 126 }).then((_) { |
127 return io.ServerSocket.bind(io.InternetAddress.LOOPBACK_IP_V4, 0); | 127 return io.ServerSocket.bind(io.InternetAddress.LOOPBACK_IP_V4, 0); |
128 }).then((io.ServerSocket server) { | 128 }).then((io.ServerSocket server) { |
129 return io.Process.start( | 129 return io.Process.start( |
130 runtimeConfiguration.dartBinary, | 130 runtimeConfiguration.dartBinary, |
131 ['-Dfletch-vm=$buildDir/fletch-vm', | 131 ['-Ddartino-vm=$buildDir/dartino-vm', |
132 '-Dfletch.version=$version', | 132 '-Ddartino.version=$version', |
133 '-Ddart-sdk=third_party/dart/sdk/', | 133 '-Ddart-sdk=third_party/dart/sdk/', |
134 '-Dtests-dir=tests/', | 134 '-Dtests-dir=tests/', |
135 '-Djava-home=$javaHome', | 135 '-Djava-home=$javaHome', |
136 '-Dtest.dart.build-dir=$buildDir', | 136 '-Dtest.dart.build-dir=$buildDir', |
137 '-Dtest.dart.build-arch=${configuration["arch"]}', | 137 '-Dtest.dart.build-arch=${configuration["arch"]}', |
138 '-Dtest.dart.build-system=${configuration["system"]}', | 138 '-Dtest.dart.build-system=${configuration["system"]}', |
139 '-Dtest.dart.build-clang=${configuration["clang"]}', | 139 '-Dtest.dart.build-clang=${configuration["clang"]}', |
140 '-Dtest.dart.build-asan=${configuration["asan"]}', | 140 '-Dtest.dart.build-asan=${configuration["asan"]}', |
141 '-Dtest.dart.temp-dir=$tempDirPath', | 141 '-Dtest.dart.temp-dir=$tempDirPath', |
142 '-Dtest.dart.servicec-dir=tools/servicec/', | 142 '-Dtest.dart.servicec-dir=tools/servicec/', |
143 '-c', | 143 '-c', |
144 '--packages=.packages', | 144 '--packages=.packages', |
145 '-Dtest.fletch_test_suite.port=${server.port}', | 145 '-Dtest.dartino_test_suite.port=${server.port}', |
146 '$testSuiteDir/fletch_test_suite.dart']).then((io.Process process) { | 146 '$testSuiteDir/dartino_test_suite.dart']).then((io.Process process) { |
147 process.exitCode.then((_) { | 147 process.exitCode.then((_) { |
148 helperProgramExited = true; | 148 helperProgramExited = true; |
149 server.close(); | 149 server.close(); |
150 }); | 150 }); |
151 vmProcess = process; | 151 vmProcess = process; |
152 return process.stdin.close(); | 152 return process.stdin.close(); |
153 }).then((_) { | 153 }).then((_) { |
154 return server.first.catchError((error) { | 154 return server.first.catchError((error) { |
155 // The VM died before we got a connection. | 155 // The VM died before we got a connection. |
156 assert(helperProgramExited); | 156 assert(helperProgramExited); |
157 return null; | 157 return null; |
158 }); | 158 }); |
159 }).then((io.Socket socket) { | 159 }).then((io.Socket socket) { |
160 server.close(); | 160 server.close(); |
161 return socket; | 161 return socket; |
162 }); | 162 }); |
163 }).then((io.Socket socket) { | 163 }).then((io.Socket socket) { |
164 assert(socket != null || helperProgramExited); | 164 assert(socket != null || helperProgramExited); |
165 completer = new TestCompleter(vmProcess, socket); | 165 completer = new TestCompleter(vmProcess, socket); |
166 completer.initialize(); | 166 completer.initialize(); |
167 return completer.requestTestNames(); | 167 return completer.requestTestNames(); |
168 }).then((List<String> testNames) { | 168 }).then((List<String> testNames) { |
169 for (String name in testNames) { | 169 for (String name in testNames) { |
170 Set<Expectation> expectedOutcomes = expectations.expectations(name); | 170 Set<Expectation> expectedOutcomes = expectations.expectations(name); |
171 TestCase testCase = new TestCase( | 171 TestCase testCase = new TestCase( |
172 'fletch_tests/$name', <Command>[], configuration, expectedOutcomes); | 172 'dartino_tests/$name', <Command>[], configuration, expectedOutcomes)
; |
173 var command = new FletchTestCommand(name, completer); | 173 var command = new DartinoTestCommand(name, completer); |
174 testCase.commands.add(command); | 174 testCase.commands.add(command); |
175 if (!expectedOutcomes.contains(Expectation.SKIP)) { | 175 if (!expectedOutcomes.contains(Expectation.SKIP)) { |
176 completer.expect(command); | 176 completer.expect(command); |
177 } | 177 } |
178 enqueueNewTestCase(testCase); | 178 enqueueNewTestCase(testCase); |
179 } | 179 } |
180 }).then((_) { | 180 }).then((_) { |
181 onDone(); | 181 onDone(); |
182 }); | 182 }); |
183 } | 183 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 if (javaHome == null) return false; | 254 if (javaHome == null) return false; |
255 return new io.File('$javaHome/include/jni.h').existsSync(); | 255 return new io.File('$javaHome/include/jni.h').existsSync(); |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 /// Pattern that matches warnings (from dart2js) that contain a comment saying | 259 /// Pattern that matches warnings (from dart2js) that contain a comment saying |
260 /// "NO_LINT". | 260 /// "NO_LINT". |
261 final RegExp noLintFilter = | 261 final RegExp noLintFilter = |
262 new RegExp(r"[^\n]*\n[^\n]*\n[^\n]* // NO_LINT\n *\^+\n"); | 262 new RegExp(r"[^\n]*\n[^\n]*\n[^\n]* // NO_LINT\n *\^+\n"); |
263 | 263 |
264 class FletchTestOutputCommand implements CommandOutput { | 264 class DartinoTestOutputCommand implements CommandOutput { |
265 final Command command; | 265 final Command command; |
266 final Duration time; | 266 final Duration time; |
267 final Message message; | 267 final Message message; |
268 final List<String> stdoutLines; | 268 final List<String> stdoutLines; |
269 | 269 |
270 FletchTestOutputCommand( | 270 DartinoTestOutputCommand( |
271 this.command, | 271 this.command, |
272 this.message, | 272 this.message, |
273 this.time, | 273 this.time, |
274 this.stdoutLines); | 274 this.stdoutLines); |
275 | 275 |
276 Expectation result(TestCase testCase) { | 276 Expectation result(TestCase testCase) { |
277 switch (message.type) { | 277 switch (message.type) { |
278 case 'TestPassed': | 278 case 'TestPassed': |
279 return Expectation.PASS; | 279 return Expectation.PASS; |
280 | 280 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 break; | 333 break; |
334 } | 334 } |
335 return UTF8.encode(result); | 335 return UTF8.encode(result); |
336 } | 336 } |
337 | 337 |
338 List<String> get diagnostics => <String>[]; | 338 List<String> get diagnostics => <String>[]; |
339 | 339 |
340 bool get compilationSkipped => false; | 340 bool get compilationSkipped => false; |
341 } | 341 } |
342 | 342 |
343 class FletchTestCommand implements Command { | 343 class DartinoTestCommand implements Command { |
344 final String _name; | 344 final String _name; |
345 | 345 |
346 final TestCompleter _completer; | 346 final TestCompleter _completer; |
347 | 347 |
348 FletchTestCommand(this._name, this._completer); | 348 DartinoTestCommand(this._name, this._completer); |
349 | 349 |
350 String get displayName => "fletch_test"; | 350 String get displayName => "dartino_test"; |
351 | 351 |
352 int get maxNumRetries => 0; | 352 int get maxNumRetries => 0; |
353 | 353 |
354 Future<FletchTestOutputCommand> run(int timeout) { | 354 Future<DartinoTestOutputCommand> run(int timeout) { |
355 Stopwatch sw = new Stopwatch()..start(); | 355 Stopwatch sw = new Stopwatch()..start(); |
356 return _completer.run(this, timeout).then((NamedMessage message) { | 356 return _completer.run(this, timeout).then((NamedMessage message) { |
357 FletchTestOutputCommand output = | 357 DartinoTestOutputCommand output = |
358 new FletchTestOutputCommand( | 358 new DartinoTestOutputCommand( |
359 this, message, sw.elapsed, _completer.testOutput[message.name]); | 359 this, message, sw.elapsed, _completer.testOutput[message.name]); |
360 _completer.done(this); | 360 _completer.done(this); |
361 return output; | 361 return output; |
362 }); | 362 }); |
363 } | 363 } |
364 | 364 |
365 String toString() => 'FletchTestCommand($_name)'; | 365 String toString() => 'DartinoTestCommand($_name)'; |
366 | 366 |
367 set displayName(_) => throw "not supported"; | 367 set displayName(_) => throw "not supported"; |
368 | 368 |
369 get commandLine => throw "not supported"; | 369 get commandLine => throw "not supported"; |
370 set commandLine(_) => throw "not supported"; | 370 set commandLine(_) => throw "not supported"; |
371 | 371 |
372 String get reproductionCommand => throw "not supported"; | 372 String get reproductionCommand => throw "not supported"; |
373 | 373 |
374 get outputIsUpToDate => throw "not supported"; | 374 get outputIsUpToDate => throw "not supported"; |
375 } | 375 } |
376 | 376 |
377 class TestCompleter { | 377 class TestCompleter { |
378 final Map<String, FletchTestCommand> expected = | 378 final Map<String, DartinoTestCommand> expected = |
379 new Map<String, FletchTestCommand>(); | 379 new Map<String, DartinoTestCommand>(); |
380 final Map<String, Completer> completers = new Map<String, Completer>(); | 380 final Map<String, Completer> completers = new Map<String, Completer>(); |
381 final Completer<List<String>> testNamesCompleter = | 381 final Completer<List<String>> testNamesCompleter = |
382 new Completer<List<String>>(); | 382 new Completer<List<String>>(); |
383 final Map<String, List<String>> testOutput = new Map<String, List<String>>(); | 383 final Map<String, List<String>> testOutput = new Map<String, List<String>>(); |
384 final io.Process vmProcess; | 384 final io.Process vmProcess; |
385 final io.Socket socket; | 385 final io.Socket socket; |
386 | 386 |
387 int exitCode; | 387 int exitCode; |
388 String stderr = ""; | 388 String stderr = ""; |
389 | 389 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 432 } |
433 process(messages); | 433 process(messages); |
434 } | 434 } |
435 | 435 |
436 Future<List<String>> requestTestNames() { | 436 Future<List<String>> requestTestNames() { |
437 if (socket == null) return new Future.value(<String>[]); | 437 if (socket == null) return new Future.value(<String>[]); |
438 socket.writeln(JSON.encode(const ListTests().toJson())); | 438 socket.writeln(JSON.encode(const ListTests().toJson())); |
439 return testNamesCompleter.future; | 439 return testNamesCompleter.future; |
440 } | 440 } |
441 | 441 |
442 void expect(FletchTestCommand command) { | 442 void expect(DartinoTestCommand command) { |
443 expected[command._name] = command; | 443 expected[command._name] = command; |
444 } | 444 } |
445 | 445 |
446 void done(FletchTestCommand command) { | 446 void done(DartinoTestCommand command) { |
447 expected.remove(command._name); | 447 expected.remove(command._name); |
448 if (expected.isEmpty) { | 448 if (expected.isEmpty) { |
449 allDone(); | 449 allDone(); |
450 } | 450 } |
451 } | 451 } |
452 | 452 |
453 Future run(FletchTestCommand command, int timeout) { | 453 Future run(DartinoTestCommand command, int timeout) { |
454 if (command._name == "self/testNeverCompletes") { | 454 if (command._name == "self/testNeverCompletes") { |
455 // Ensure timeout test times out quickly. | 455 // Ensure timeout test times out quickly. |
456 timeout = 1; | 456 timeout = 1; |
457 } | 457 } |
458 socket.writeln( | 458 socket.writeln( |
459 JSON.encode(new RunTest(command._name).toJson())); | 459 JSON.encode(new RunTest(command._name).toJson())); |
460 Timer timer = new Timer(new Duration(seconds: timeout), () { | 460 Timer timer = new Timer(new Duration(seconds: timeout), () { |
461 socket.writeln( | 461 socket.writeln( |
462 JSON.encode(new TimedOut(command._name).toJson())); | 462 JSON.encode(new TimedOut(command._name).toJson())); |
463 }); | 463 }); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 process(messages); | 516 process(messages); |
517 } | 517 } |
518 }); | 518 }); |
519 } | 519 } |
520 | 520 |
521 void allDone() { | 521 void allDone() { |
522 // This should cause the vmProcess to exit. | 522 // This should cause the vmProcess to exit. |
523 socket.close(); | 523 socket.close(); |
524 } | 524 } |
525 } | 525 } |
OLD | NEW |