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

Side by Side Diff: tests/lib/mirrors/invocation_fuzz_test.dart

Issue 2768073002: Format all multitests (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // This test reflectively enumerates all the methods in the system and tries to 5 // This test reflectively enumerates all the methods in the system and tries to
6 // invoke them with various basic values (nulls, ints, etc). This may result in 6 // invoke them with various basic values (nulls, ints, etc). This may result in
7 // Dart exceptions or hangs, but should never result in crashes or JavaScript 7 // Dart exceptions or hangs, but should never result in crashes or JavaScript
8 // exceptions. 8 // exceptions.
9 9
10 library test.invoke_natives; 10 library test.invoke_natives;
(...skipping 20 matching lines...) Expand all
31 31
32 // Don't run blocking io calls. 32 // Don't run blocking io calls.
33 new RegExp(r".*Sync$"), 33 new RegExp(r".*Sync$"),
34 34
35 // These prevent the test from exiting. 35 // These prevent the test from exiting.
36 'dart.io.sleep', 36 'dart.io.sleep',
37 'dart.io.HttpServer.HttpServer.listenOn', 37 'dart.io.HttpServer.HttpServer.listenOn',
38 38
39 // These either cause the VM to segfault or throw uncatchable API errors. 39 // These either cause the VM to segfault or throw uncatchable API errors.
40 // TODO(15274): Fix them and remove from blacklist. 40 // TODO(15274): Fix them and remove from blacklist.
41 'dart.io.SystemEncoding.decode', // Windows only 41 'dart.io.SystemEncoding.decode', // Windows only
42 'dart.io.SystemEncoding.encode', // Windows only 42 'dart.io.SystemEncoding.encode', // Windows only
43 43
44 // These construct an object with an uninitialized native field. 44 // These construct an object with an uninitialized native field.
45 // TODO(23869): We could make this safer, but making the failure non-fatal 45 // TODO(23869): We could make this safer, but making the failure non-fatal
46 // would we worthless aside from this test. 46 // would we worthless aside from this test.
47 'dart.io.X509Certificate.X509Certificate._', 47 'dart.io.X509Certificate.X509Certificate._',
48 'dart.io._X509Impl._X509Impl', 48 'dart.io._X509Impl._X509Impl',
49 49
50 // Don't call private methods in dart.async as they may circumvent the zoned 50 // Don't call private methods in dart.async as they may circumvent the zoned
51 // error handling below. 51 // error handling below.
52 new RegExp(r"^dart\.async\._.*$"), 52 new RegExp(r"^dart\.async\._.*$"),
53 53
54 'dart._internal.fatal', 54 'dart._internal.fatal',
55 ]; 55 ];
56 56
57 bool isBlacklisted(Symbol qualifiedSymbol) { 57 bool isBlacklisted(Symbol qualifiedSymbol) {
58 var qualifiedString = MirrorSystem.getName(qualifiedSymbol); 58 var qualifiedString = MirrorSystem.getName(qualifiedSymbol);
59 for (var pattern in blacklist) { 59 for (var pattern in blacklist) {
60 if (qualifiedString.contains(pattern)) { 60 if (qualifiedString.contains(pattern)) {
61 print('Skipping $qualifiedString'); 61 print('Skipping $qualifiedString');
62 return true; 62 return true;
63 } 63 }
64 } 64 }
65 return false; 65 return false;
66 } 66 }
67 67
68 class Task { 68 class Task {
69 var name; 69 var name;
70 var action; 70 var action;
71 } 71 }
72
72 var queue = new List(); 73 var queue = new List();
73 74
74 checkMethod(MethodMirror m, ObjectMirror target, [origin]) { 75 checkMethod(MethodMirror m, ObjectMirror target, [origin]) {
75 if (isBlacklisted(m.qualifiedName)) return; 76 if (isBlacklisted(m.qualifiedName)) return;
76 77
77 var task = new Task(); 78 var task = new Task();
78 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin'; 79 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin';
79 80
80 if (m.isRegularMethod) { 81 if (m.isRegularMethod) {
81 task.action = 82 task.action = () => target.invoke(
82 () => target.invoke(m.simpleName, 83 m.simpleName, new List.filled(m.parameters.length, fuzzArgument));
83 new List.filled(m.parameters.length, fuzzArgument));
84 } else if (m.isGetter) { 84 } else if (m.isGetter) {
85 task.action = 85 task.action = () => target.getField(m.simpleName);
86 () => target.getField(m.simpleName);
87 } else if (m.isSetter) { 86 } else if (m.isSetter) {
88 task.action = 87 task.action = () => target.setField(m.simpleName, null);
89 () => target.setField(m.simpleName, null);
90 } else if (m.isConstructor) { 88 } else if (m.isConstructor) {
91 return; 89 return;
92 } else { 90 } else {
93 throw "Unexpected method kind"; 91 throw "Unexpected method kind";
94 } 92 }
95 93
96 queue.add(task); 94 queue.add(task);
97 } 95 }
98 96
99 checkField(VariableMirror v, ObjectMirror target, [origin]) { 97 checkField(VariableMirror v, ObjectMirror target, [origin]) {
(...skipping 26 matching lines...) Expand all
126 .forEach((m) => checkMethod(m, classMirror)); 124 .forEach((m) => checkMethod(m, classMirror));
127 125
128 classMirror.declarations.values 126 classMirror.declarations.values
129 .where((d) => d is MethodMirror && d.isConstructor) 127 .where((d) => d is MethodMirror && d.isConstructor)
130 .forEach((m) { 128 .forEach((m) {
131 if (isBlacklisted(m.qualifiedName)) return; 129 if (isBlacklisted(m.qualifiedName)) return;
132 var task = new Task(); 130 var task = new Task();
133 task.name = MirrorSystem.getName(m.qualifiedName); 131 task.name = MirrorSystem.getName(m.qualifiedName);
134 132
135 task.action = () { 133 task.action = () {
136 var instance = classMirror.newInstance( 134 var instance = classMirror.newInstance(m.constructorName,
137 m.constructorName,
138 new List.filled(m.parameters.length, fuzzArgument)); 135 new List.filled(m.parameters.length, fuzzArgument));
139 checkInstance(instance, task.name); 136 checkInstance(instance, task.name);
140 }; 137 };
141 queue.add(task); 138 queue.add(task);
142 }); 139 });
143 } 140 }
144 141
145 checkLibrary(libraryMirror) { 142 checkLibrary(libraryMirror) {
146 print(libraryMirror.simpleName); 143 print(libraryMirror.simpleName);
147 if (isBlacklisted(libraryMirror.qualifiedName)) return; 144 if (isBlacklisted(libraryMirror.qualifiedName)) return;
(...skipping 12 matching lines...) Expand all
160 doOneTask() { 157 doOneTask() {
161 if (queue.length == 0) { 158 if (queue.length == 0) {
162 print('Done'); 159 print('Done');
163 return; 160 return;
164 } 161 }
165 162
166 var task = queue.removeLast(); 163 var task = queue.removeLast();
167 print(task.name); 164 print(task.name);
168 try { 165 try {
169 task.action(); 166 task.action();
170 } catch(e) {} 167 } catch (e) {}
171 168
172 // Register the next task in a timer callback so as to yield to async code 169 // Register the next task in a timer callback so as to yield to async code
173 // scheduled in the current task. This isn't necessary for the test itself, 170 // scheduled in the current task. This isn't necessary for the test itself,
174 // but is helpful when trying to figure out which function is responsible for 171 // but is helpful when trying to figure out which function is responsible for
175 // a crash. 172 // a crash.
176 testZone.createTimer(Duration.ZERO, doOneTask); 173 testZone.createTimer(Duration.ZERO, doOneTask);
177 } 174 }
178 175
179 var fuzzArgument; 176 var fuzzArgument;
180 177
181 main() { 178 main() {
182 fuzzArgument = null; 179 fuzzArgument = null;
183 fuzzArgument = 1; // //# smi: ok 180 fuzzArgument = 1; // //# smi: ok
184 fuzzArgument = false; // //# false: ok 181 fuzzArgument = false; // //# false: ok
185 fuzzArgument = 'string'; // //# string: ok 182 fuzzArgument = 'string'; // //# string: ok
186 fuzzArgument = new List(0); // //# emptyarray: ok 183 fuzzArgument = new List(0); // //# emptyarray: ok
187 184
188 print('Fuzzing with $fuzzArgument'); 185 print('Fuzzing with $fuzzArgument');
189 186
190 currentMirrorSystem().libraries.values.forEach(checkLibrary); 187 currentMirrorSystem().libraries.values.forEach(checkLibrary);
191 188
192 var valueObjects = 189 var valueObjects = [
193 [true, false, null, [], {}, dynamic, 190 true,
194 0, 0xEFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 3.14159, () {}, 191 false,
195 "foo", 'blåbærgrød', 'Îñţérñåţîöñåļîžåţîờñ', "\u{1D11E}", #symbol]; 192 null,
193 [],
194 {},
195 dynamic,
196 0,
197 0xEFFFFFF,
198 0xFFFFFFFF,
199 0xFFFFFFFFFFFFFFFF,
200 3.14159,
201 () {},
202 "foo",
203 'blåbærgrød',
204 'Îñţérñåţîöñåļîžåţîờñ',
205 "\u{1D11E}",
206 #symbol
207 ];
196 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object')); 208 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object'));
197 209
198 uncaughtErrorHandler(self, parent, zone, error, stack) {}; 210 uncaughtErrorHandler(self, parent, zone, error, stack) {}
211 ;
199 var zoneSpec = 212 var zoneSpec =
200 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); 213 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler);
201 testZone = Zone.current.fork(specification: zoneSpec); 214 testZone = Zone.current.fork(specification: zoneSpec);
202 testZone.createTimer(Duration.ZERO, doOneTask); 215 testZone.createTimer(Duration.ZERO, doOneTask);
203 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698