| 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'; |
| 11 import 'package:compiler/src/common.dart'; |
| 11 import 'package:compiler/src/commandline_options.dart'; | 12 import 'package:compiler/src/commandline_options.dart'; |
| 12 import 'package:compiler/src/common/names.dart'; | 13 import 'package:compiler/src/common/names.dart'; |
| 13 import 'package:compiler/src/compiler.dart'; | 14 import 'package:compiler/src/compiler.dart'; |
| 14 import 'package:compiler/src/diagnostics/invariant.dart'; | 15 import 'package:compiler/src/diagnostics/invariant.dart'; |
| 15 import 'package:compiler/src/elements/elements.dart'; | 16 import 'package:compiler/src/elements/elements.dart'; |
| 16 import 'package:compiler/src/serialization/json_serializer.dart'; | 17 import 'package:compiler/src/serialization/json_serializer.dart'; |
| 17 import 'package:compiler/src/serialization/serialization.dart'; | 18 import 'package:compiler/src/serialization/serialization.dart'; |
| 19 import 'package:expect/expect.dart'; |
| 18 | 20 |
| 19 import 'equivalence_test.dart'; | 21 import 'equivalence_test.dart'; |
| 22 import 'test_helper.dart'; |
| 23 import 'resolved_ast_test.dart'; |
| 24 import 'helper.dart'; |
| 20 | 25 |
| 21 main(List<String> arguments) { | 26 main(List<String> arguments) { |
| 22 // Ensure that we can print out constant expressions. | 27 // Ensure that we can print out constant expressions. |
| 23 DEBUG_MODE = true; | 28 DEBUG_MODE = true; |
| 24 | 29 |
| 25 Uri entryPoint; | 30 Uri entryPoint; |
| 26 String outPath; | 31 String outPath; |
| 27 int shardCount = 3; | 32 int shardCount = 3; |
| 28 bool prettyPrint = false; | 33 bool prettyPrint = false; |
| 29 for (String arg in arguments) { | 34 for (String arg in arguments) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 45 } | 50 } |
| 46 } | 51 } |
| 47 if (entryPoint == null) { | 52 if (entryPoint == null) { |
| 48 entryPoint = Uris.dart_core; | 53 entryPoint = Uris.dart_core; |
| 49 } | 54 } |
| 50 asyncTest(() async { | 55 asyncTest(() async { |
| 51 Compiler compiler = await compilerFor( | 56 Compiler compiler = await compilerFor( |
| 52 entryPoint: entryPoint, options: [Flags.analyzeAll]); | 57 entryPoint: entryPoint, options: [Flags.analyzeAll]); |
| 53 compiler.serialization.supportSerialization = true; | 58 compiler.serialization.supportSerialization = true; |
| 54 await compiler.run(entryPoint); | 59 await compiler.run(entryPoint); |
| 55 List<String> data = | 60 List<SerializedData> data = |
| 56 createData(compiler, | 61 createData(compiler, |
| 57 outPath: outPath, | 62 outPath: outPath, |
| 58 prettyPrint: prettyPrint, | 63 prettyPrint: prettyPrint, |
| 59 shardCount: shardCount); | 64 shardCount: shardCount); |
| 60 testEquivalence(data, compiler.libraryLoader.libraries); | 65 await testAnalysis(compiler, data, entryPoint); |
| 61 await testAnalysis(data, entryPoint); | |
| 62 }); | 66 }); |
| 63 } | 67 } |
| 64 | 68 |
| 65 List<String> createData( | 69 List<SerializedData> createData( |
| 66 Compiler compiler, | 70 Compiler compiler, |
| 67 {String outPath, | 71 {String outPath, |
| 68 bool prettyPrint, | 72 bool prettyPrint, |
| 69 int shardCount: 3}) { | 73 int shardCount: 3}) { |
| 70 Iterable<LibraryElement> libraries1 = compiler.libraryLoader.libraries; | 74 Iterable<LibraryElement> libraries1 = compiler.libraryLoader.libraries; |
| 71 if (shardCount < 1 || shardCount > libraries1.length) { | 75 if (shardCount < 1 || shardCount > libraries1.length) { |
| 72 shardCount = libraries1.length; | 76 shardCount = libraries1.length; |
| 73 } | 77 } |
| 74 List<List<LibraryElement>> librarySplits = <List<LibraryElement>>[]; | 78 List<List<LibraryElement>> librarySplits = <List<LibraryElement>>[]; |
| 75 int offset = 0; | 79 int offset = 0; |
| 76 int shardSize = (libraries1.length / shardCount).ceil(); | 80 int shardSize = (libraries1.length / shardCount).ceil(); |
| 77 for (int shard = 0; shard < shardCount; shard++) { | 81 for (int shard = 0; shard < shardCount; shard++) { |
| 78 List<LibraryElement> libraries = <LibraryElement>[]; | 82 List<LibraryElement> libraries = <LibraryElement>[]; |
| 79 for (int index = 0; index < shardSize; index++) { | 83 for (int index = 0; index < shardSize; index++) { |
| 80 if (offset + index < libraries1.length) { | 84 if (offset + index < libraries1.length) { |
| 81 libraries.add(libraries1.elementAt(offset + index)); | 85 libraries.add(libraries1.elementAt(offset + index)); |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 librarySplits.add(libraries); | 88 librarySplits.add(libraries); |
| 85 offset += shardSize; | 89 offset += shardSize; |
| 86 } | 90 } |
| 87 print(librarySplits.join('\n')); | 91 print(librarySplits.join('\n')); |
| 88 List<String> texts = <String>[]; | 92 List<SerializedData> data = <SerializedData>[]; |
| 89 for (int shard = 0; shard < shardCount; shard++) { | 93 for (int shard = 0; shard < shardCount; shard++) { |
| 90 List<LibraryElement> libraries = librarySplits[shard]; | 94 List<LibraryElement> libraries = librarySplits[shard]; |
| 91 Serializer serializer = | 95 Serializer serializer = |
| 92 compiler.serialization.createSerializer(libraries); | 96 compiler.serialization.createSerializer(libraries); |
| 93 String text = serializer.toText(const JsonSerializationEncoder()); | 97 String text = serializer.toText(const JsonSerializationEncoder()); |
| 94 String outText = text; | 98 String outText = text; |
| 95 if (prettyPrint) { | 99 if (prettyPrint) { |
| 96 outText = serializer.prettyPrint(); | 100 outText = serializer.prettyPrint(); |
| 97 } | 101 } |
| 98 if (outPath != null) { | 102 if (outPath != null) { |
| 99 String name = outPath; | 103 String name = outPath; |
| 100 String ext = ''; | 104 String ext = ''; |
| 101 int dotPos = outPath.lastIndexOf('.'); | 105 int dotPos = outPath.lastIndexOf('.'); |
| 102 if (dotPos != -1) { | 106 if (dotPos != -1) { |
| 103 name = outPath.substring(0, dotPos); | 107 name = outPath.substring(0, dotPos); |
| 104 ext = outPath.substring(dotPos); | 108 ext = outPath.substring(dotPos); |
| 105 } | 109 } |
| 106 new File('$name$shard$ext').writeAsStringSync(outText); | 110 new File('$name$shard$ext').writeAsStringSync(outText); |
| 107 } else if (prettyPrint) { | 111 } else if (prettyPrint) { |
| 108 print(outText); | 112 print(outText); |
| 109 } | 113 } |
| 110 texts.add(text); | 114 data.add(new SerializedData(Uri.parse('memory:out$shard.data'), text)); |
| 111 } | 115 } |
| 112 return texts; | 116 return data; |
| 113 } | 117 } |
| 114 | 118 |
| 115 void testEquivalence(List<String> data, Iterable<LibraryElement> libraries1) { | 119 Future testAnalysis( |
| 116 DeserializationContext deserializationContext = | 120 Compiler compiler1, |
| 117 new DeserializationContext(); | 121 List<SerializedData> data, |
| 118 for (String shardData in data) { | 122 Uri entryPoint) async { |
| 119 Deserializer deserializer = new Deserializer.fromText( | 123 Map<String, String> memorySourceFiles = <String, String>{}; |
| 120 deserializationContext, shardData, const JsonSerializationDecoder()); | 124 List<Uri> resolutionInputs = <Uri>[]; |
| 121 deserializationContext.deserializers.add(deserializer); | 125 for (int index = 0; index < data.length; index++) { |
| 126 SerializedData serializedData = data[index]; |
| 127 serializedData.expandMemorySourceFiles(memorySourceFiles); |
| 128 serializedData.expandUris(resolutionInputs); |
| 122 } | 129 } |
| 123 for (LibraryElement library1 in libraries1) { | 130 CompilationResult result = await runCompiler( |
| 131 entryPoint: entryPoint, |
| 132 memorySourceFiles: memorySourceFiles, |
| 133 resolutionInputs: resolutionInputs, |
| 134 options: [Flags.analyzeAll]); |
| 135 Compiler compiler2 = result.compiler; |
| 136 for (LibraryElement library1 in compiler1.libraryLoader.libraries) { |
| 124 LibraryElement library2 = | 137 LibraryElement library2 = |
| 125 deserializationContext.lookupLibrary(library1.canonicalUri); | 138 compiler2.libraryLoader.lookupLibrary(library1.canonicalUri); |
| 126 if (library2 == null) { | 139 if (library2 == null) { |
| 127 throw new ArgumentError('No library ${library1.canonicalUri} found.'); | 140 throw new ArgumentError('No library ${library1.canonicalUri} found.'); |
| 128 } | 141 } |
| 129 checkLibraryContent('library1', 'library2', 'library', library1, library2); | 142 checkLibraryContent('library1', 'library2', 'library', library1, library2); |
| 143 checkAllResolvedAsts(compiler1, compiler2); |
| 144 checkAllImpacts(compiler1, compiler2); |
| 130 } | 145 } |
| 131 } | 146 Expect.isFalse(compiler2.reporter.hasReportedError, "Unexpected errors"); |
| 132 | |
| 133 Future testAnalysis(List<String> data, Uri entryPoint) async { | |
| 134 Compiler compiler = compilerFor(entryPoint: entryPoint, | |
| 135 options: [Flags.analyzeAll]); | |
| 136 for (String shardData in data) { | |
| 137 compiler.serialization.deserializeFromText(shardData); | |
| 138 } | |
| 139 await compiler.run(entryPoint); | |
| 140 } | 147 } |
| OLD | NEW |