OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 dart2js.serialization_impact_test; | 5 library dart2js.serialization_resolved_ast_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:expect/expect.dart'; |
9 import 'package:compiler/src/commandline_options.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; |
10 import 'package:compiler/src/common/resolution.dart'; | 11 import 'package:compiler/src/common/backend_api.dart'; |
| 12 import 'package:compiler/src/common/names.dart'; |
11 import 'package:compiler/src/compiler.dart'; | 13 import 'package:compiler/src/compiler.dart'; |
12 import 'package:compiler/src/elements/elements.dart'; | 14 import 'package:compiler/src/elements/elements.dart'; |
13 import 'package:compiler/src/filenames.dart'; | 15 import 'package:compiler/src/filenames.dart'; |
14 import 'package:compiler/src/serialization/equivalence.dart'; | 16 import 'package:compiler/src/serialization/equivalence.dart'; |
15 import 'memory_compiler.dart'; | 17 import 'memory_compiler.dart'; |
16 import 'serialization_helper.dart'; | 18 import 'serialization_helper.dart'; |
| 19 import 'serialization_test_data.dart'; |
17 import 'serialization_test_helper.dart'; | 20 import 'serialization_test_helper.dart'; |
18 | 21 |
| 22 |
19 main(List<String> arguments) { | 23 main(List<String> arguments) { |
20 asyncTest(() async { | 24 asyncTest(() async { |
21 String serializedData = await serializeDartCore(); | 25 String serializedData = await serializeDartCore(serializeResolvedAst: true); |
22 if (arguments.isNotEmpty) { | 26 if (arguments.isNotEmpty) { |
23 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.last)); | 27 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.last)); |
24 await check(serializedData, entryPoint); | 28 await check(serializedData, entryPoint); |
25 } else { | 29 } else { |
26 Uri entryPoint = Uri.parse('memory:main.dart'); | 30 Uri entryPoint = Uri.parse('memory:main.dart'); |
27 await check(serializedData, entryPoint, {'main.dart': 'main() {}'}); | 31 for (Test test in TESTS) { |
| 32 await check(serializedData, entryPoint, test.sourceFiles); |
| 33 } |
28 } | 34 } |
29 }); | 35 }); |
30 } | 36 } |
31 | 37 |
32 Future check( | 38 Future check( |
33 String serializedData, | 39 String serializedData, |
34 Uri entryPoint, | 40 Uri entryPoint, |
35 [Map<String, String> sourceFiles = const <String, String>{}]) async { | 41 [Map<String, String> sourceFiles = const <String, String>{}]) async { |
36 | 42 |
37 Compiler compilerNormal = compilerFor( | 43 Compiler compilerNormal = compilerFor( |
38 memorySourceFiles: sourceFiles, | 44 memorySourceFiles: sourceFiles, |
39 options: [Flags.analyzeOnly]); | 45 options: [Flags.analyzeOnly]); |
40 compilerNormal.resolution.retainCachesForTesting = true; | 46 compilerNormal.resolution.retainCachesForTesting = true; |
41 await compilerNormal.run(entryPoint); | 47 await compilerNormal.run(entryPoint); |
42 | 48 |
43 Compiler compilerDeserialized = compilerFor( | 49 Compiler compilerDeserialized = compilerFor( |
44 memorySourceFiles: sourceFiles, | 50 memorySourceFiles: sourceFiles, |
45 options: [Flags.analyzeOnly]); | 51 options: [Flags.analyzeOnly]); |
46 compilerDeserialized.resolution.retainCachesForTesting = true; | 52 compilerDeserialized.resolution.retainCachesForTesting = true; |
47 deserialize(compilerDeserialized, serializedData); | 53 deserialize( |
| 54 compilerDeserialized, serializedData, deserializeResolvedAst: true); |
48 await compilerDeserialized.run(entryPoint); | 55 await compilerDeserialized.run(entryPoint); |
49 | 56 |
| 57 checkAllResolvedAsts(compilerNormal, compilerDeserialized, verbose: true); |
50 } | 58 } |
| 59 |
| 60 void checkAllResolvedAsts( |
| 61 Compiler compiler1, |
| 62 Compiler compiler2, |
| 63 {bool verbose: false}) { |
| 64 checkLoadedLibraryMembers( |
| 65 compiler1, |
| 66 compiler2, |
| 67 (Element member1) { |
| 68 return compiler1.resolution.hasResolvedAst(member1); |
| 69 }, |
| 70 checkResolvedAsts, |
| 71 verbose: true); |
| 72 } |
| 73 |
| 74 |
| 75 /// Check equivalence of [impact1] and [impact2]. |
| 76 void checkResolvedAsts(Compiler compiler1, Element member1, |
| 77 Compiler compiler2, Element member2, |
| 78 {bool verbose: false}) { |
| 79 ResolvedAst resolvedAst1 = compiler1.resolution.getResolvedAst(member1); |
| 80 ResolvedAst resolvedAst2 = |
| 81 compiler2.serialization.deserializer.getResolvedAst(member2); |
| 82 |
| 83 if (resolvedAst1 == null || resolvedAst2 == null) return; |
| 84 |
| 85 if (verbose) { |
| 86 print('Checking resolved asts for $member1 vs $member2'); |
| 87 } |
| 88 |
| 89 testResolvedAstEquivalence( |
| 90 resolvedAst1, resolvedAst2, const CheckStrategy()); |
| 91 } |
OLD | NEW |