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_library_test; | 5 library dart2js.serialization_library_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import '../memory_compiler.dart'; | 9 import '../memory_compiler.dart'; |
10 import 'package:async_helper/async_helper.dart'; | 10 import 'package:async_helper/async_helper.dart'; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 if (entryPoint != null) { | 46 if (entryPoint != null) { |
47 print("Multiple entrypoints are not supported."); | 47 print("Multiple entrypoints are not supported."); |
48 } | 48 } |
49 entryPoint = Uri.parse(arg); | 49 entryPoint = Uri.parse(arg); |
50 } | 50 } |
51 } | 51 } |
52 if (entryPoint == null) { | 52 if (entryPoint == null) { |
53 entryPoint = Uris.dart_core; | 53 entryPoint = Uris.dart_core; |
54 } | 54 } |
55 asyncTest(() async { | 55 asyncTest(() async { |
56 Compiler compiler = await compilerFor( | 56 Compiler compiler = |
57 entryPoint: entryPoint, options: [Flags.analyzeAll]); | 57 await compilerFor(entryPoint: entryPoint, options: [Flags.analyzeAll]); |
58 compiler.serialization.supportSerialization = true; | 58 compiler.serialization.supportSerialization = true; |
59 await compiler.run(entryPoint); | 59 await compiler.run(entryPoint); |
60 List<SerializedData> data = | 60 List<SerializedData> data = createData(compiler, |
61 createData(compiler, | 61 outPath: outPath, prettyPrint: prettyPrint, shardCount: shardCount); |
62 outPath: outPath, | |
63 prettyPrint: prettyPrint, | |
64 shardCount: shardCount); | |
65 await testAnalysis(compiler, data, entryPoint); | 62 await testAnalysis(compiler, data, entryPoint); |
66 }); | 63 }); |
67 } | 64 } |
68 | 65 |
69 List<SerializedData> createData( | 66 List<SerializedData> createData(Compiler compiler, |
70 Compiler compiler, | 67 {String outPath, bool prettyPrint, int shardCount: 3}) { |
71 {String outPath, | |
72 bool prettyPrint, | |
73 int shardCount: 3}) { | |
74 Iterable<LibraryElement> libraries1 = compiler.libraryLoader.libraries; | 68 Iterable<LibraryElement> libraries1 = compiler.libraryLoader.libraries; |
75 if (shardCount < 1 || shardCount > libraries1.length) { | 69 if (shardCount < 1 || shardCount > libraries1.length) { |
76 shardCount = libraries1.length; | 70 shardCount = libraries1.length; |
77 } | 71 } |
78 List<List<LibraryElement>> librarySplits = <List<LibraryElement>>[]; | 72 List<List<LibraryElement>> librarySplits = <List<LibraryElement>>[]; |
79 int offset = 0; | 73 int offset = 0; |
80 int shardSize = (libraries1.length / shardCount).ceil(); | 74 int shardSize = (libraries1.length / shardCount).ceil(); |
81 for (int shard = 0; shard < shardCount; shard++) { | 75 for (int shard = 0; shard < shardCount; shard++) { |
82 List<LibraryElement> libraries = <LibraryElement>[]; | 76 List<LibraryElement> libraries = <LibraryElement>[]; |
83 for (int index = 0; index < shardSize; index++) { | 77 for (int index = 0; index < shardSize; index++) { |
84 if (offset + index < libraries1.length) { | 78 if (offset + index < libraries1.length) { |
85 libraries.add(libraries1.elementAt(offset + index)); | 79 libraries.add(libraries1.elementAt(offset + index)); |
86 } | 80 } |
87 } | 81 } |
88 librarySplits.add(libraries); | 82 librarySplits.add(libraries); |
89 offset += shardSize; | 83 offset += shardSize; |
90 } | 84 } |
91 print(librarySplits.join('\n')); | 85 print(librarySplits.join('\n')); |
92 List<SerializedData> data = <SerializedData>[]; | 86 List<SerializedData> data = <SerializedData>[]; |
93 for (int shard = 0; shard < shardCount; shard++) { | 87 for (int shard = 0; shard < shardCount; shard++) { |
94 List<LibraryElement> libraries = librarySplits[shard]; | 88 List<LibraryElement> libraries = librarySplits[shard]; |
95 Serializer serializer = | 89 Serializer serializer = compiler.serialization.createSerializer(libraries); |
96 compiler.serialization.createSerializer(libraries); | |
97 String text = serializer.toText(const JsonSerializationEncoder()); | 90 String text = serializer.toText(const JsonSerializationEncoder()); |
98 String outText = text; | 91 String outText = text; |
99 if (prettyPrint) { | 92 if (prettyPrint) { |
100 outText = serializer.prettyPrint(); | 93 outText = serializer.prettyPrint(); |
101 } | 94 } |
102 if (outPath != null) { | 95 if (outPath != null) { |
103 String name = outPath; | 96 String name = outPath; |
104 String ext = ''; | 97 String ext = ''; |
105 int dotPos = outPath.lastIndexOf('.'); | 98 int dotPos = outPath.lastIndexOf('.'); |
106 if (dotPos != -1) { | 99 if (dotPos != -1) { |
107 name = outPath.substring(0, dotPos); | 100 name = outPath.substring(0, dotPos); |
108 ext = outPath.substring(dotPos); | 101 ext = outPath.substring(dotPos); |
109 } | 102 } |
110 new File('$name$shard$ext').writeAsStringSync(outText); | 103 new File('$name$shard$ext').writeAsStringSync(outText); |
111 } else if (prettyPrint) { | 104 } else if (prettyPrint) { |
112 print(outText); | 105 print(outText); |
113 } | 106 } |
114 data.add(new SerializedData(Uri.parse('memory:out$shard.data'), text)); | 107 data.add(new SerializedData(Uri.parse('memory:out$shard.data'), text)); |
115 } | 108 } |
116 return data; | 109 return data; |
117 } | 110 } |
118 | 111 |
119 Future testAnalysis( | 112 Future testAnalysis( |
120 Compiler compiler1, | 113 Compiler compiler1, List<SerializedData> data, Uri entryPoint) async { |
121 List<SerializedData> data, | |
122 Uri entryPoint) async { | |
123 Map<String, String> memorySourceFiles = <String, String>{}; | 114 Map<String, String> memorySourceFiles = <String, String>{}; |
124 List<Uri> resolutionInputs = <Uri>[]; | 115 List<Uri> resolutionInputs = <Uri>[]; |
125 for (int index = 0; index < data.length; index++) { | 116 for (int index = 0; index < data.length; index++) { |
126 SerializedData serializedData = data[index]; | 117 SerializedData serializedData = data[index]; |
127 serializedData.expandMemorySourceFiles(memorySourceFiles); | 118 serializedData.expandMemorySourceFiles(memorySourceFiles); |
128 serializedData.expandUris(resolutionInputs); | 119 serializedData.expandUris(resolutionInputs); |
129 } | 120 } |
130 CompilationResult result = await runCompiler( | 121 CompilationResult result = await runCompiler( |
131 entryPoint: entryPoint, | 122 entryPoint: entryPoint, |
132 memorySourceFiles: memorySourceFiles, | 123 memorySourceFiles: memorySourceFiles, |
133 resolutionInputs: resolutionInputs, | 124 resolutionInputs: resolutionInputs, |
134 options: [Flags.analyzeAll]); | 125 options: [Flags.analyzeAll]); |
135 Compiler compiler2 = result.compiler; | 126 Compiler compiler2 = result.compiler; |
136 for (LibraryElement library1 in compiler1.libraryLoader.libraries) { | 127 for (LibraryElement library1 in compiler1.libraryLoader.libraries) { |
137 LibraryElement library2 = | 128 LibraryElement library2 = |
138 compiler2.libraryLoader.lookupLibrary(library1.canonicalUri); | 129 compiler2.libraryLoader.lookupLibrary(library1.canonicalUri); |
139 if (library2 == null) { | 130 if (library2 == null) { |
140 throw new ArgumentError('No library ${library1.canonicalUri} found.'); | 131 throw new ArgumentError('No library ${library1.canonicalUri} found.'); |
141 } | 132 } |
142 checkLibraryContent('library1', 'library2', 'library', library1, library2); | 133 checkLibraryContent('library1', 'library2', 'library', library1, library2); |
143 checkAllResolvedAsts(compiler1, compiler2); | 134 checkAllResolvedAsts(compiler1, compiler2); |
144 checkAllImpacts(compiler1, compiler2); | 135 checkAllImpacts(compiler1, compiler2); |
145 } | 136 } |
146 Expect.isFalse(compiler2.reporter.hasReportedError, "Unexpected errors"); | 137 Expect.isFalse(compiler2.reporter.hasReportedError, "Unexpected errors"); |
147 } | 138 } |
OLD | NEW |