OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'dart:async'; |
5 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
6 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
7 import 'sourcemap_helper.dart'; | 8 import 'sourcemap_helper.dart'; |
8 import 'sourcemap_html_helper.dart'; | 9 import 'sourcemap_html_helper.dart'; |
9 import 'package:compiler/src/filenames.dart'; | 10 import 'package:compiler/src/filenames.dart'; |
10 | 11 |
11 main(List<String> arguments) { | 12 main(List<String> arguments) { |
12 bool showAll = false; | 13 bool showAll = false; |
| 14 bool measure = false; |
13 Uri outputUri; | 15 Uri outputUri; |
14 if (arguments.isNotEmpty) { | 16 Set<String> configurations = new Set<String>(); |
15 outputUri = Uri.base.resolve(nativeToUriPath(arguments.last)); | 17 for (String argument in arguments) { |
16 showAll = arguments.contains('-a'); | 18 if (argument.startsWith('-')) { |
| 19 if (argument == '-a') { |
| 20 /// Generate visualization for all user methods. |
| 21 showAll = true; |
| 22 } else if (argument == '-m') { |
| 23 /// Measure instead of reporting the number of missing code points. |
| 24 measure = true; |
| 25 } else if (argument.startsWith('--out=')) { |
| 26 /// Generate visualization for the first configuration. |
| 27 outputUri = Uri.base.resolve( |
| 28 nativeToUriPath(argument.substring('--out='.length))); |
| 29 } else if (argument.startsWith('-o')) { |
| 30 /// Generate visualization for the first configuration. |
| 31 outputUri = Uri.base.resolve( |
| 32 nativeToUriPath(argument.substring('-o'.length))); |
| 33 } else { |
| 34 print("Unknown option '$argument'."); |
| 35 return; |
| 36 } |
| 37 } else { |
| 38 if (TEST_CONFIGURATIONS.containsKey(argument)) { |
| 39 configurations.add(argument); |
| 40 } else { |
| 41 print("Unknown configuration '$argument'. " |
| 42 "Must be one of '${TEST_CONFIGURATIONS.keys.join("', '")}'"); |
| 43 return; |
| 44 } |
| 45 } |
17 } | 46 } |
| 47 |
| 48 if (configurations.isEmpty) { |
| 49 configurations.addAll(TEST_CONFIGURATIONS.keys); |
| 50 } |
| 51 String outputConfig = configurations.first; |
| 52 |
18 asyncTest(() async { | 53 asyncTest(() async { |
19 String filename = | 54 List<Measurement> measurements = <Measurement>[]; |
20 'tests/compiler/dart2js/sourcemaps/invokes_test_file.dart'; | 55 for (String config in configurations) { |
21 SourceMapProcessor processor = new SourceMapProcessor(filename); | 56 List<String> options = TEST_CONFIGURATIONS[config]; |
22 List<SourceMapInfo> infoList = await processor.process( | 57 Measurement measurement = await runTests( |
23 ['--use-new-source-info', '--csp', '--disable-inlining']); | 58 config, |
24 List<SourceMapInfo> userInfoList = <SourceMapInfo>[]; | 59 options, |
25 List<SourceMapInfo> failureList = <SourceMapInfo>[]; | 60 showAll: showAll, |
26 for (SourceMapInfo info in infoList) { | 61 measure: measure, |
27 if (info.element.library.isPlatformLibrary) continue; | 62 outputUri: outputConfig == config ? outputUri : null); |
28 userInfoList.add(info); | 63 if (measurement != null) { |
29 Iterable<CodePoint> missingCodePoints = | 64 measurements.add(measurement); |
30 info.codePoints.where((c) => c.isMissing); | 65 } |
| 66 } |
| 67 for (Measurement measurement in measurements) { |
| 68 print(measurement); |
| 69 } |
| 70 }); |
| 71 } |
| 72 |
| 73 const Map<String, List<String>> TEST_CONFIGURATIONS = const { |
| 74 'old': const [], |
| 75 'ssa': const ['--use-new-source-info', ], |
| 76 'cps': const ['--use-new-source-info', '--use-cps-ir'], |
| 77 }; |
| 78 |
| 79 Future<Measurement> runTests( |
| 80 String config, |
| 81 List<String> options, |
| 82 {bool showAll: false, |
| 83 Uri outputUri, |
| 84 bool measure: false}) async { |
| 85 if (config == 'old' && !measure) return null; |
| 86 |
| 87 String filename = |
| 88 'tests/compiler/dart2js/sourcemaps/invokes_test_file.dart'; |
| 89 SourceMapProcessor processor = new SourceMapProcessor(filename); |
| 90 List<SourceMapInfo> infoList = await processor.process( |
| 91 ['--csp', '--disable-inlining'] |
| 92 ..addAll(options), |
| 93 verbose: !measure); |
| 94 List<SourceMapInfo> userInfoList = <SourceMapInfo>[]; |
| 95 List<SourceMapInfo> failureList = <SourceMapInfo>[]; |
| 96 Measurement measurement = new Measurement(config); |
| 97 for (SourceMapInfo info in infoList) { |
| 98 if (info.element.library.isPlatformLibrary) continue; |
| 99 userInfoList.add(info); |
| 100 Iterable<CodePoint> missingCodePoints = |
| 101 info.codePoints.where((c) => c.isMissing); |
| 102 measurement.missing += missingCodePoints.length; |
| 103 measurement.count += info.codePoints.length; |
| 104 if (!measure) { |
31 if (!missingCodePoints.isEmpty) { | 105 if (!missingCodePoints.isEmpty) { |
32 print('Missing code points ${missingCodePoints} for ' | 106 print("Missing code points for ${info.element} in '$filename':"); |
33 '${info.element} in $filename'); | 107 for (CodePoint codePoint in missingCodePoints) { |
| 108 print(" $codePoint"); |
| 109 } |
34 failureList.add(info); | 110 failureList.add(info); |
35 } | 111 } |
36 } | 112 } |
37 if (failureList.isNotEmpty) { | 113 } |
38 if (outputUri == null) { | 114 if (failureList.isNotEmpty) { |
| 115 if (outputUri == null) { |
| 116 if (!measure) { |
39 Expect.fail( | 117 Expect.fail( |
40 "Missing code points found. " | 118 "Missing code points found. " |
41 "Run the test with a URI option, `source_mapping_test <uri>`, to " | 119 "Run the test with a URI option, " |
| 120 "`source_mapping_test --out=<uri> $config`, to " |
42 "create a html visualization of the missing code points."); | 121 "create a html visualization of the missing code points."); |
43 } else { | |
44 createTraceSourceMapHtml(outputUri, processor, | |
45 showAll ? userInfoList : failureList); | |
46 } | 122 } |
47 } else if (outputUri != null) { | 123 } else { |
48 createTraceSourceMapHtml(outputUri, processor, userInfoList); | 124 createTraceSourceMapHtml(outputUri, processor, |
| 125 showAll ? userInfoList : failureList); |
49 } | 126 } |
50 }); | 127 } else if (outputUri != null) { |
| 128 createTraceSourceMapHtml(outputUri, processor, userInfoList); |
| 129 } |
| 130 return measurement; |
51 } | 131 } |
| 132 |
| 133 class Measurement { |
| 134 final String config; |
| 135 int missing = 0; |
| 136 int count = 0; |
| 137 |
| 138 Measurement(this.config); |
| 139 |
| 140 String toString() { |
| 141 double percentage = 100 * missing / count; |
| 142 return "Config '${config}': $missing of $count ($percentage%) missing"; |
| 143 } |
| 144 } |
OLD | NEW |