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

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

Issue 241993004: Mark private functions in dart:* that are native or constructors is not visible (omitted from stack… (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
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 will all nulls. This may result in Dart exceptions or hangs, but 6 // invoke them will all nulls. This may result in Dart exceptions or hangs, but
7 // should never result in crashes or JavaScript exceptions. 7 // should never result in crashes or JavaScript exceptions.
8 8
9 library test.invoke_natives; 9 library test.invoke_natives;
10 10
11 import 'dart:mirrors'; 11 import 'dart:mirrors';
12 import 'dart:async'; 12 import 'dart:async';
13 import 'package:expect/expect.dart'; 13 import 'package:expect/expect.dart';
14 14
15 // Methods to be skipped, by qualified name. 15 // Methods to be skipped, by qualified name.
16 var blacklist = [ 16 var blacklist = [
17 // These prevent the test from exiting, typically by spawning another isolate. 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.
18 'dart.async._scheduleAsyncCallback', 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.
19 'dart.io._IOService.dispatch', 36 'dart.io._IOService.dispatch',
20 'dart.isolate.RawReceivePort.RawReceivePort', 37 new RegExp(r'.*_RandomAccessFile.*'),
21 'dart.isolate.ReceivePort.ReceivePort', 38 'dart.io._StdIOUtils._socketType',
22 'dart.isolate.ReceivePort.ReceivePort.fromRawReceivePort', 39 'dart.io._StdIOUtils._getStdioOutputStream',
23 'dart.isolate.ReceivePort.sendPort', 40 'dart.io._Filter.newZLibInflateFilter',
24 'dart.isolate.ReceivePort.close', 41 'dart.io._Filter.newZLibDeflateFilter',
25 'dart.isolate.ReceivePort.listen', 42 'dart.io._FileSystemWatcher._listenOnSocket',
26 'dart.isolate.RawReceivePort.sendPort', 43 ];
27 'dart.isolate.RawReceivePort.close',
28 'dart.isolate.RawReceivePort.handler=',
29 44
30 // These "crash" the VM (throw uncatchable API errors). 45 bool isBlacklisted(Symbol qualifiedSymbol) {
31 // TODO(15274): Fill in this list to make the test pass and provide coverage 46 var qualifiedString = MirrorSystem.getName(qualifiedSymbol);
32 // against addition of new natives. 47 for (var pattern in blacklist) {
33 ]; 48 if (qualifiedString.contains(pattern)) return true;
49 }
50 return false;
51 }
34 52
35 class Task { 53 class Task {
36 var name; 54 var name;
37 var action; 55 var action;
38 } 56 }
39 var queue = new List(); 57 var queue = new List();
40 58
41 checkMethod(MethodMirror m, ObjectMirror target, [origin]) { 59 checkMethod(MethodMirror m, ObjectMirror target, [origin]) {
42 if (blacklist.contains(MirrorSystem.getName(m.qualifiedName))) return; 60 if (isBlacklisted(m.qualifiedName)) return;
43 61
44 var task = new Task(); 62 var task = new Task();
45 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin'; 63 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin';
46 64
47 if (m.isRegularMethod) { 65 if (m.isRegularMethod) {
48 task.action = 66 task.action =
49 () => target.invoke(m.simpleName, new List(m.parameters.length)); 67 () => target.invoke(m.simpleName, new List(m.parameters.length));
50 } else if (m.isGetter) { 68 } else if (m.isGetter) {
51 task.action = 69 task.action =
52 () => target.getField(m.simpleName); 70 () => target.getField(m.simpleName);
53 } else if (m.isSetter) { 71 } else if (m.isSetter) {
54 task.action = 72 task.action =
55 () => target.setField(m.simpleName, null); 73 () => target.setField(m.simpleName, null);
56 } else if (m.isConstructor) { 74 } else if (m.isConstructor) {
57 return; 75 return;
58 } else { 76 } else {
59 throw "Unexpected method kind"; 77 throw "Unexpected method kind";
60 } 78 }
61 79
62 queue.add(task); 80 queue.add(task);
63 } 81 }
64 82
65 checkInstance(instanceMirror, origin) { 83 checkInstance(instanceMirror, origin) {
66 instanceMirror.type.declarations.values 84 ClassMirror klass = instanceMirror.type;
67 .where((d) => d is MethodMirror) 85 while (klass != null) {
68 .forEach((m) => checkMethod(m, instanceMirror, origin)); 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 }
69 } 91 }
70 92
71 checkClass(classMirror) { 93 checkClass(classMirror) {
72 classMirror.declarations.values 94 classMirror.declarations.values
73 .where((d) => d is MethodMirror) 95 .where((d) => d is MethodMirror && d.isStatic)
74 .forEach((m) => checkMethod(m, classMirror)); 96 .forEach((m) => checkMethod(m, classMirror));
75 97
76 classMirror.declarations.values 98 classMirror.declarations.values
77 .where((d) => d is MethodMirror) 99 .where((d) => d is MethodMirror && d.isConstructor)
78 .forEach((m) { 100 .forEach((m) {
79 if (blacklist.contains(MirrorSystem.getName(m.qualifiedName))) return; 101 if (isBlacklisted(m.qualifiedName)) return;
80 if (!m.isConstructor) return;
81 var task = new Task(); 102 var task = new Task();
82 task.name = MirrorSystem.getName(m.qualifiedName); 103 task.name = MirrorSystem.getName(m.qualifiedName);
83 104
84 task.action = () { 105 task.action = () {
85 var instance = classMirror.newInstance(m.constructorName, 106 var instance = classMirror.newInstance(m.constructorName,
86 new List(m.parameters.length)); 107 new List(m.parameters.length));
87 checkInstance(instance, task.name); 108 checkInstance(instance, task.name);
88 }; 109 };
89 queue.add(task); 110 queue.add(task);
90 }); 111 });
91 } 112 }
92 113
93 checkLibrary(libraryMirror) { 114 checkLibrary(libraryMirror) {
94 // Don't recurse on this test. 115 print(libraryMirror.simpleName);
95 if (libraryMirror.simpleName == #test.invoke_natives) return; 116 if (isBlacklisted(libraryMirror.qualifiedName)) return;
96 117
97 libraryMirror.declarations.values 118 libraryMirror.declarations.values
98 .where((d) => d is ClassMirror) 119 .where((d) => d is ClassMirror)
99 .forEach(checkClass); 120 .forEach(checkClass);
100 121
101 libraryMirror.declarations.values 122 libraryMirror.declarations.values
102 .where((d) => d is MethodMirror) 123 .where((d) => d is MethodMirror)
103 .forEach((m) => checkMethod(m, libraryMirror)); 124 .forEach((m) => checkMethod(m, libraryMirror));
104 } 125 }
105 126
106 var testZone; 127 var testZone;
107 var debug = true;
108 128
109 doOneTask() { 129 doOneTask() {
110 if (queue.length == 0) { 130 if (queue.length == 0) {
111 if (debug) print('Done'); 131 print('Done');
112 return; 132 return;
113 } 133 }
114 134
115 var task = queue.removeLast(); 135 var task = queue.removeLast();
116 if (debug) print(task.name); 136 print(task.name);
117 try { 137 try {
118 task.action(); 138 task.action();
119 } catch(e) {} 139 } catch(e) {}
140
120 // Register the next task in a timer callback so as to yield to async code 141 // Register the next task in a timer callback so as to yield to async code
121 // scheduled in the current task. This isn't necessary for the test itself, 142 // scheduled in the current task. This isn't necessary for the test itself,
122 // but is helpful when trying to figure out which function is responsible for 143 // but is helpful when trying to figure out which function is responsible for
123 // a crash. 144 // a crash.
124 testZone.createTimer(Duration.ZERO, doOneTask); 145 testZone.createTimer(Duration.ZERO, doOneTask);
125 } 146 }
126 147
127 main() { 148 main([args]) {
128 currentMirrorSystem().libraries.values.forEach(checkLibrary); 149 currentMirrorSystem().libraries.values.forEach(checkLibrary);
129 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
130 uncaughtErrorHandler(self, parent, zone, error, stack) {}; 157 uncaughtErrorHandler(self, parent, zone, error, stack) {};
131 var zoneSpec = 158 var zoneSpec =
132 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); 159 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler);
133 testZone = Zone.current.fork(specification: zoneSpec); 160 testZone = Zone.current.fork(specification: zoneSpec);
134 testZone.createTimer(Duration.ZERO, doOneTask); 161 testZone.createTimer(Duration.ZERO, doOneTask);
135 } 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