Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: tests/compiler/dart2js/serialization/library_test.dart

Issue 2007573002: Support multiple serialization sources in DeserializerSystemImpl. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix test. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/serialization/task.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:io'; 8 import 'dart:io';
8 import '../memory_compiler.dart'; 9 import '../memory_compiler.dart';
9 import 'package:async_helper/async_helper.dart'; 10 import 'package:async_helper/async_helper.dart';
10 import 'package:compiler/src/commandline_options.dart'; 11 import 'package:compiler/src/commandline_options.dart';
11 import 'package:compiler/src/common/names.dart'; 12 import 'package:compiler/src/common/names.dart';
12 import 'package:compiler/src/compiler.dart'; 13 import 'package:compiler/src/compiler.dart';
13 import 'package:compiler/src/diagnostics/invariant.dart'; 14 import 'package:compiler/src/diagnostics/invariant.dart';
14 import 'package:compiler/src/elements/elements.dart'; 15 import 'package:compiler/src/elements/elements.dart';
15 import 'package:compiler/src/serialization/json_serializer.dart'; 16 import 'package:compiler/src/serialization/json_serializer.dart';
16 import 'package:compiler/src/serialization/serialization.dart'; 17 import 'package:compiler/src/serialization/serialization.dart';
(...skipping 23 matching lines...) Expand all
40 if (entryPoint != null) { 41 if (entryPoint != null) {
41 print("Multiple entrypoints are not supported."); 42 print("Multiple entrypoints are not supported.");
42 } 43 }
43 entryPoint = Uri.parse(arg); 44 entryPoint = Uri.parse(arg);
44 } 45 }
45 } 46 }
46 if (entryPoint == null) { 47 if (entryPoint == null) {
47 entryPoint = Uris.dart_core; 48 entryPoint = Uris.dart_core;
48 } 49 }
49 asyncTest(() async { 50 asyncTest(() async {
50 CompilationResult result = await runCompiler( 51 Compiler compiler = await compilerFor(
51 entryPoint: entryPoint, options: [Flags.analyzeAll]); 52 entryPoint: entryPoint, options: [Flags.analyzeAll]);
52 Compiler compiler = result.compiler; 53 compiler.serialization.supportSerialization = true;
53 testSerialization(compiler.libraryLoader.libraries, 54 await compiler.run(entryPoint);
54 outPath: outPath, 55 List<String> data =
55 prettyPrint: prettyPrint, 56 createData(compiler,
56 shardCount: shardCount); 57 outPath: outPath,
58 prettyPrint: prettyPrint,
59 shardCount: shardCount);
60 testEquivalence(data, compiler.libraryLoader.libraries);
61 await testAnalysis(data, entryPoint);
57 }); 62 });
58 } 63 }
59 64
60 void testSerialization(Iterable<LibraryElement> libraries1, 65 List<String> createData(
61 {String outPath, 66 Compiler compiler,
62 bool prettyPrint, 67 {String outPath,
63 int shardCount: 3}) { 68 bool prettyPrint,
69 int shardCount: 3}) {
70 Iterable<LibraryElement> libraries1 = compiler.libraryLoader.libraries;
64 if (shardCount < 1 || shardCount > libraries1.length) { 71 if (shardCount < 1 || shardCount > libraries1.length) {
65 shardCount = libraries1.length; 72 shardCount = libraries1.length;
66 } 73 }
67 List<List<LibraryElement>> librarySplits = <List<LibraryElement>>[]; 74 List<List<LibraryElement>> librarySplits = <List<LibraryElement>>[];
68 int offset = 0; 75 int offset = 0;
69 int shardSize = (libraries1.length / shardCount).ceil(); 76 int shardSize = (libraries1.length / shardCount).ceil();
70 for (int shard = 0; shard < shardCount; shard++) { 77 for (int shard = 0; shard < shardCount; shard++) {
71 List<LibraryElement> libraries = <LibraryElement>[]; 78 List<LibraryElement> libraries = <LibraryElement>[];
72 for (int index = 0; index < shardSize; index++) { 79 for (int index = 0; index < shardSize; index++) {
73 if (offset + index < libraries1.length) { 80 if (offset + index < libraries1.length) {
74 libraries.add(libraries1.elementAt(offset + index)); 81 libraries.add(libraries1.elementAt(offset + index));
75 } 82 }
76 } 83 }
77 librarySplits.add(libraries); 84 librarySplits.add(libraries);
78 offset += shardSize; 85 offset += shardSize;
79 } 86 }
80 print(librarySplits.join('\n')); 87 print(librarySplits.join('\n'));
81 List<String> texts = <String>[]; 88 List<String> texts = <String>[];
82 for (int shard = 0; shard < shardCount; shard++) { 89 for (int shard = 0; shard < shardCount; shard++) {
83 List<LibraryElement> libraries = librarySplits[shard]; 90 List<LibraryElement> libraries = librarySplits[shard];
84 Serializer serializer = new Serializer( 91 Serializer serializer =
85 shouldInclude: (e) => libraries.contains(e.library)); 92 compiler.serialization.createSerializer(libraries);
86 for (LibraryElement library in libraries) {
87 serializer.serialize(library);
88 }
89 String text = serializer.toText(const JsonSerializationEncoder()); 93 String text = serializer.toText(const JsonSerializationEncoder());
90 String outText = text; 94 String outText = text;
91 if (prettyPrint) { 95 if (prettyPrint) {
92 outText = serializer.prettyPrint(); 96 outText = serializer.prettyPrint();
93 } 97 }
94 if (outPath != null) { 98 if (outPath != null) {
95 String name = outPath; 99 String name = outPath;
96 String ext = ''; 100 String ext = '';
97 int dotPos = outPath.lastIndexOf('.'); 101 int dotPos = outPath.lastIndexOf('.');
98 if (dotPos != -1) { 102 if (dotPos != -1) {
99 name = outPath.substring(0, dotPos); 103 name = outPath.substring(0, dotPos);
100 ext = outPath.substring(dotPos); 104 ext = outPath.substring(dotPos);
101 } 105 }
102 new File('$name$shard$ext').writeAsStringSync(outText); 106 new File('$name$shard$ext').writeAsStringSync(outText);
103 } else if (prettyPrint) { 107 } else if (prettyPrint) {
104 print(outText); 108 print(outText);
105 } 109 }
106 texts.add(text); 110 texts.add(text);
107 } 111 }
112 return texts;
113 }
114
115 void testEquivalence(List<String> data, Iterable<LibraryElement> libraries1) {
108 DeserializationContext deserializationContext = 116 DeserializationContext deserializationContext =
109 new DeserializationContext(); 117 new DeserializationContext();
110 for (int shard = 0; shard < shardCount; shard++) { 118 for (String shardData in data) {
111 new Deserializer.fromText( 119 Deserializer deserializer = new Deserializer.fromText(
112 deserializationContext, texts[shard], const JsonSerializationDecoder()); 120 deserializationContext, shardData, const JsonSerializationDecoder());
121 deserializationContext.deserializers.add(deserializer);
113 } 122 }
114 List<LibraryElement> libraries2 = <LibraryElement>[];
115 for (LibraryElement library1 in libraries1) { 123 for (LibraryElement library1 in libraries1) {
116 LibraryElement library2 = 124 LibraryElement library2 =
117 deserializationContext.lookupLibrary(library1.canonicalUri); 125 deserializationContext.lookupLibrary(library1.canonicalUri);
118 if (library2 == null) { 126 if (library2 == null) {
119 throw new ArgumentError('No library ${library1.canonicalUri} found.'); 127 throw new ArgumentError('No library ${library1.canonicalUri} found.');
120 } 128 }
121 checkLibraryContent('library1', 'library2', 'library', library1, library2); 129 checkLibraryContent('library1', 'library2', 'library', library1, library2);
122 libraries2.add(library2);
123 } 130 }
131 }
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);
124 } 140 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/serialization/task.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698