OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 // This test forks a second vm process that runs the BMU tool and verifies that |
| 6 // it produces some output. This test is mainly here to ensure that the BMU |
| 7 // tool compiles and runs. |
| 8 |
| 9 import "dart:async"; |
| 10 import "dart:convert"; |
| 11 import "dart:io"; |
| 12 |
| 13 import "package:path/path.dart"; |
| 14 |
| 15 // Tool script relative to the path of this test. |
| 16 var toolScript = "../../runtime/tools/verbose_gc_to_bmu.dart"; |
| 17 |
| 18 // Target script relative to this test. |
| 19 var targetScript = "../language/gc_test.dart"; |
| 20 const minOutputLines = 20; |
| 21 |
| 22 void checkExitCode(exitCode) { |
| 23 if (exitCode != 0) { |
| 24 print("Process terminated with exit code ${exitCode}."); |
| 25 exit(-1); |
| 26 } |
| 27 } |
| 28 |
| 29 void main() { |
| 30 // Compute paths for tool and target relative to the path of this script. |
| 31 var scriptDir = dirname(Platform.script.toFilePath()); |
| 32 var targPath = normalize(join(scriptDir, targetScript)); |
| 33 var targetResult = |
| 34 Process.runSync(Platform.executable, ["--verbose_gc", targPath]); |
| 35 checkExitCode(targetResult.exitCode); |
| 36 var gcLog = targetResult.stderr; |
| 37 var toolPath = normalize(join(scriptDir, toolScript)); |
| 38 Process.start(Platform.executable, [toolPath]).then((Process process) { |
| 39 // Feed the GC log of the target to the BMU tool. |
| 40 process.stdin.write(gcLog); |
| 41 process.stdin.close(); |
| 42 var stdoutStringStream = process.stdout |
| 43 .transform(UTF8.decoder) |
| 44 .transform(new LineSplitter()); |
| 45 var stderrStringStream = process.stderr |
| 46 .transform(UTF8.decoder) |
| 47 .transform(new LineSplitter()); |
| 48 // Wait for 3 future events: stdout and stderr streams closed, and |
| 49 // process terminated. |
| 50 var futures = []; |
| 51 var stdoutLines = []; |
| 52 var stderrLines = []; |
| 53 var subscription = stdoutStringStream.listen(stdoutLines.add); |
| 54 futures.add(subscription.asFuture(true)); |
| 55 subscription = stderrStringStream.listen(stderrLines.add); |
| 56 futures.add(subscription.asFuture(true)); |
| 57 futures.add(process.exitCode.then(checkExitCode)); |
| 58 Future.wait(futures).then((results) { |
| 59 if (stderrLines.isNotEmpty) { |
| 60 print("Unexpected output on stderr:"); |
| 61 print(stderrLines.join('\n')); |
| 62 exit(-1); |
| 63 } |
| 64 if (stdoutLines.length < minOutputLines) { |
| 65 print("Less than expected output on stdout:"); |
| 66 print(stdoutLines.join('\n')); |
| 67 exit(-1); |
| 68 } |
| 69 }); |
| 70 }); |
| 71 } |
OLD | NEW |