OLD | NEW |
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 Loading... |
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 | 54 |
55 bool isBlacklisted(Symbol qualifiedSymbol) { | 55 bool isBlacklisted(Symbol qualifiedSymbol) { |
56 var qualifiedString = MirrorSystem.getName(qualifiedSymbol); | 56 var qualifiedString = MirrorSystem.getName(qualifiedSymbol); |
57 for (var pattern in blacklist) { | 57 for (var pattern in blacklist) { |
58 if (qualifiedString.contains(pattern)) { | 58 if (qualifiedString.contains(pattern)) { |
59 print('Skipping $qualifiedString'); | 59 print('Skipping $qualifiedString'); |
60 return true; | 60 return true; |
61 } | 61 } |
62 } | 62 } |
63 return false; | 63 return false; |
64 } | 64 } |
65 | 65 |
66 class Task { | 66 class Task { |
67 var name; | 67 var name; |
68 var action; | 68 var action; |
69 } | 69 } |
| 70 |
70 var queue = new List(); | 71 var queue = new List(); |
71 | 72 |
72 checkMethod(MethodMirror m, ObjectMirror target, [origin]) { | 73 checkMethod(MethodMirror m, ObjectMirror target, [origin]) { |
73 if (isBlacklisted(m.qualifiedName)) return; | 74 if (isBlacklisted(m.qualifiedName)) return; |
74 | 75 |
75 var task = new Task(); | 76 var task = new Task(); |
76 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin'; | 77 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin'; |
77 | 78 |
78 if (m.isRegularMethod) { | 79 if (m.isRegularMethod) { |
79 task.action = | 80 task.action = () => target.invoke( |
80 () => target.invoke(m.simpleName, | 81 m.simpleName, new List.filled(m.parameters.length, fuzzArgument)); |
81 new List.filled(m.parameters.length, fuzzArgument)); | |
82 } else if (m.isGetter) { | 82 } else if (m.isGetter) { |
83 task.action = | 83 task.action = () => target.getField(m.simpleName); |
84 () => target.getField(m.simpleName); | |
85 } else if (m.isSetter) { | 84 } else if (m.isSetter) { |
86 task.action = | 85 task.action = () => target.setField(m.simpleName, null); |
87 () => target.setField(m.simpleName, null); | |
88 } else if (m.isConstructor) { | 86 } else if (m.isConstructor) { |
89 return; | 87 return; |
90 } else { | 88 } else { |
91 throw "Unexpected method kind"; | 89 throw "Unexpected method kind"; |
92 } | 90 } |
93 | 91 |
94 queue.add(task); | 92 queue.add(task); |
95 } | 93 } |
96 | 94 |
97 checkInstance(instanceMirror, origin) { | 95 checkInstance(instanceMirror, origin) { |
(...skipping 12 matching lines...) Expand all Loading... |
110 .forEach((m) => checkMethod(m, classMirror)); | 108 .forEach((m) => checkMethod(m, classMirror)); |
111 | 109 |
112 classMirror.declarations.values | 110 classMirror.declarations.values |
113 .where((d) => d is MethodMirror && d.isConstructor) | 111 .where((d) => d is MethodMirror && d.isConstructor) |
114 .forEach((m) { | 112 .forEach((m) { |
115 if (isBlacklisted(m.qualifiedName)) return; | 113 if (isBlacklisted(m.qualifiedName)) return; |
116 var task = new Task(); | 114 var task = new Task(); |
117 task.name = MirrorSystem.getName(m.qualifiedName); | 115 task.name = MirrorSystem.getName(m.qualifiedName); |
118 | 116 |
119 task.action = () { | 117 task.action = () { |
120 var instance = classMirror.newInstance( | 118 var instance = classMirror.newInstance(m.constructorName, |
121 m.constructorName, | |
122 new List.filled(m.parameters.length, fuzzArgument)); | 119 new List.filled(m.parameters.length, fuzzArgument)); |
123 checkInstance(instance, task.name); | 120 checkInstance(instance, task.name); |
124 }; | 121 }; |
125 queue.add(task); | 122 queue.add(task); |
126 }); | 123 }); |
127 } | 124 } |
128 | 125 |
129 checkLibrary(libraryMirror) { | 126 checkLibrary(libraryMirror) { |
130 print(libraryMirror.simpleName); | 127 print(libraryMirror.simpleName); |
131 if (isBlacklisted(libraryMirror.qualifiedName)) return; | 128 if (isBlacklisted(libraryMirror.qualifiedName)) return; |
(...skipping 12 matching lines...) Expand all Loading... |
144 doOneTask() { | 141 doOneTask() { |
145 if (queue.length == 0) { | 142 if (queue.length == 0) { |
146 print('Done'); | 143 print('Done'); |
147 return; | 144 return; |
148 } | 145 } |
149 | 146 |
150 var task = queue.removeLast(); | 147 var task = queue.removeLast(); |
151 print(task.name); | 148 print(task.name); |
152 try { | 149 try { |
153 task.action(); | 150 task.action(); |
154 } catch(e) {} | 151 } catch (e) {} |
155 | 152 |
156 // Register the next task in a timer callback so as to yield to async code | 153 // Register the next task in a timer callback so as to yield to async code |
157 // scheduled in the current task. This isn't necessary for the test itself, | 154 // scheduled in the current task. This isn't necessary for the test itself, |
158 // but is helpful when trying to figure out which function is responsible for | 155 // but is helpful when trying to figure out which function is responsible for |
159 // a crash. | 156 // a crash. |
160 testZone.createTimer(Duration.ZERO, doOneTask); | 157 testZone.createTimer(Duration.ZERO, doOneTask); |
161 } | 158 } |
162 | 159 |
163 var fuzzArgument; | 160 var fuzzArgument; |
164 | 161 |
165 main() { | 162 main() { |
166 fuzzArgument = null; | 163 fuzzArgument = null; |
167 fuzzArgument = 1; // //# smi: ok | 164 fuzzArgument = 1; // //# smi: ok |
168 fuzzArgument = false; // //# false: ok | 165 fuzzArgument = false; // //# false: ok |
169 fuzzArgument = 'string'; // //# string: ok | 166 fuzzArgument = 'string'; // //# string: ok |
170 fuzzArgument = new List(0); // //# emptyarray: ok | 167 fuzzArgument = new List(0); // //# emptyarray: ok |
171 | 168 |
172 print('Fuzzing with $fuzzArgument'); | 169 print('Fuzzing with $fuzzArgument'); |
173 | 170 |
174 currentMirrorSystem().libraries.values.forEach(checkLibrary); | 171 currentMirrorSystem().libraries.values.forEach(checkLibrary); |
175 | 172 |
176 var valueObjects = | 173 var valueObjects = [ |
177 [true, false, null, [], {}, dynamic, | 174 true, |
178 0, 0xEFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 3.14159, | 175 false, |
179 "foo", 'blåbærgrød', 'Îñţérñåţîöñåļîžåţîờñ', "\u{1D11E}", #symbol]; | 176 null, |
| 177 [], |
| 178 {}, |
| 179 dynamic, |
| 180 0, |
| 181 0xEFFFFFF, |
| 182 0xFFFFFFFF, |
| 183 0xFFFFFFFFFFFFFFFF, |
| 184 3.14159, |
| 185 "foo", |
| 186 'blåbærgrød', |
| 187 'Îñţérñåţîöñåļîžåţîờñ', |
| 188 "\u{1D11E}", |
| 189 #symbol |
| 190 ]; |
180 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object')); | 191 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object')); |
181 | 192 |
182 uncaughtErrorHandler(self, parent, zone, error, stack) {}; | 193 uncaughtErrorHandler(self, parent, zone, error, stack) {} |
| 194 ; |
183 var zoneSpec = | 195 var zoneSpec = |
184 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); | 196 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); |
185 testZone = Zone.current.fork(specification: zoneSpec); | 197 testZone = Zone.current.fork(specification: zoneSpec); |
186 testZone.createTimer(Duration.ZERO, doOneTask); | 198 testZone.createTimer(Duration.ZERO, doOneTask); |
187 } | 199 } |
OLD | NEW |