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

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

Issue 246173002: Revert "Mark private functions in dart:* that are native or constructors as not visible (omitted fr… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « tests/lib/lib.status ('k') | tests/lib/mirrors/invoke_natives_fuzz_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This test reflectively enumerates all the methods in the system and tries to
6 // invoke them will all nulls. This may result in Dart exceptions or hangs, but
7 // should never result in crashes or JavaScript exceptions.
8
9 library test.invoke_natives;
10
11 import 'dart:mirrors';
12 import 'dart:async';
13 import 'package:expect/expect.dart';
14
15 // Methods to be skipped, by qualified name.
16 var blacklist = [
17 // Don't recurse on this test.
18 'test.invoke_natives',
19
20 // Don't exit the test pre-maturely.
21 'dart.io.exit',
22
23 // Don't run blocking io calls.
24 new RegExp(r".*Sync$"),
25
26 // These prevent the test from exiting.
27 'dart.async._scheduleAsyncCallback',
28 'dart.async._setTimerFactoryClosure',
29
30 'dart.isolate._startIsolate',
31 'dart.io.sleep',
32 'dart.io.HttpServer.HttpServer.listenOn',
33
34 // These either cause the VM to segfault or throw uncatchable API errors.
35 // TODO(15274): Fix them and remove from blacklist.
36 'dart.io._IOService.dispatch',
37 new RegExp(r'.*_RandomAccessFile.*'),
38 'dart.io._StdIOUtils._socketType',
39 'dart.io._StdIOUtils._getStdioOutputStream',
40 'dart.io._Filter.newZLibInflateFilter',
41 'dart.io._Filter.newZLibDeflateFilter',
42 'dart.io._FileSystemWatcher._listenOnSocket',
43 ];
44
45 bool isBlacklisted(Symbol qualifiedSymbol) {
46 var qualifiedString = MirrorSystem.getName(qualifiedSymbol);
47 for (var pattern in blacklist) {
48 if (qualifiedString.contains(pattern)) return true;
49 }
50 return false;
51 }
52
53 class Task {
54 var name;
55 var action;
56 }
57 var queue = new List();
58
59 checkMethod(MethodMirror m, ObjectMirror target, [origin]) {
60 if (isBlacklisted(m.qualifiedName)) return;
61
62 var task = new Task();
63 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin';
64
65 if (m.isRegularMethod) {
66 task.action =
67 () => target.invoke(m.simpleName, new List(m.parameters.length));
68 } else if (m.isGetter) {
69 task.action =
70 () => target.getField(m.simpleName);
71 } else if (m.isSetter) {
72 task.action =
73 () => target.setField(m.simpleName, null);
74 } else if (m.isConstructor) {
75 return;
76 } else {
77 throw "Unexpected method kind";
78 }
79
80 queue.add(task);
81 }
82
83 checkInstance(instanceMirror, origin) {
84 ClassMirror klass = instanceMirror.type;
85 while (klass != null) {
86 instanceMirror.type.declarations.values
87 .where((d) => d is MethodMirror && !d.isStatic)
88 .forEach((m) => checkMethod(m, instanceMirror, origin));
89 klass = klass.superclass;
90 }
91 }
92
93 checkClass(classMirror) {
94 classMirror.declarations.values
95 .where((d) => d is MethodMirror && d.isStatic)
96 .forEach((m) => checkMethod(m, classMirror));
97
98 classMirror.declarations.values
99 .where((d) => d is MethodMirror && d.isConstructor)
100 .forEach((m) {
101 if (isBlacklisted(m.qualifiedName)) return;
102 var task = new Task();
103 task.name = MirrorSystem.getName(m.qualifiedName);
104
105 task.action = () {
106 var instance = classMirror.newInstance(m.constructorName,
107 new List(m.parameters.length));
108 checkInstance(instance, task.name);
109 };
110 queue.add(task);
111 });
112 }
113
114 checkLibrary(libraryMirror) {
115 print(libraryMirror.simpleName);
116 if (isBlacklisted(libraryMirror.qualifiedName)) return;
117
118 libraryMirror.declarations.values
119 .where((d) => d is ClassMirror)
120 .forEach(checkClass);
121
122 libraryMirror.declarations.values
123 .where((d) => d is MethodMirror)
124 .forEach((m) => checkMethod(m, libraryMirror));
125 }
126
127 var testZone;
128
129 doOneTask() {
130 if (queue.length == 0) {
131 print('Done');
132 return;
133 }
134
135 var task = queue.removeLast();
136 print(task.name);
137 try {
138 task.action();
139 } catch(e) {}
140
141 // Register the next task in a timer callback so as to yield to async code
142 // scheduled in the current task. This isn't necessary for the test itself,
143 // but is helpful when trying to figure out which function is responsible for
144 // a crash.
145 testZone.createTimer(Duration.ZERO, doOneTask);
146 }
147
148 main([args]) {
149 currentMirrorSystem().libraries.values.forEach(checkLibrary);
150
151 var valueObjects =
152 [true, false, null,
153 0, 0xEFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
154 "foo", 'blåbærgrød', 'Îñţérñåţîöñåļîžåţîờñ'];
155 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object'));
156
157 uncaughtErrorHandler(self, parent, zone, error, stack) {};
158 var zoneSpec =
159 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler);
160 testZone = Zone.current.fork(specification: zoneSpec);
161 testZone.createTimer(Duration.ZERO, doOneTask);
162 }
OLDNEW
« no previous file with comments | « tests/lib/lib.status ('k') | tests/lib/mirrors/invoke_natives_fuzz_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698