Chromium Code Reviews| 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 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 |
|
regis
2014/09/22 16:20:43
It's not just all nulls anymore.
rmacnak
2014/09/22 22:42:12
Updated
| |
| 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'; | |
| 14 | 13 |
| 15 // Methods to be skipped, by qualified name. | 14 // Methods to be skipped, by qualified name. |
| 16 var blacklist = [ | 15 var blacklist = [ |
| 17 // Don't recurse on this test. | 16 // Don't recurse on this test. |
| 18 'test.invoke_natives', | 17 'test.invoke_natives', |
| 19 | 18 |
| 20 // Don't exit the test pre-maturely. | 19 // Don't exit the test pre-maturely. |
| 21 'dart.io.exit', | 20 'dart.io.exit', |
| 22 | 21 |
| 23 // Don't run blocking io calls. | 22 // Don't run blocking io calls. |
| 24 new RegExp(r".*Sync$"), | 23 new RegExp(r".*Sync$"), |
| 25 | 24 |
| 26 // These prevent the test from exiting. | 25 // These prevent the test from exiting. |
| 27 'dart.async._scheduleAsyncCallback', | 26 'dart.async._scheduleAsyncCallback', |
| 28 'dart.async._setTimerFactoryClosure', | 27 'dart.async._setTimerFactoryClosure', |
| 29 | |
| 30 'dart.isolate._startMainIsolate', | 28 'dart.isolate._startMainIsolate', |
| 31 'dart.isolate._startIsolate', | 29 'dart.isolate._startIsolate', |
| 32 'dart.io.sleep', | 30 'dart.io.sleep', |
| 33 'dart.io.HttpServer.HttpServer.listenOn', | 31 'dart.io.HttpServer.HttpServer.listenOn', |
| 32 new RegExp(r'dart.io.*'), /// smi: ok | |
| 33 | |
| 34 // Runtime exceptions we can't catch. | |
| 35 'dart.isolate._isolateScheduleImmediate', | |
| 36 'dart.io._Timer._createTimer', /// smi: ok | |
| 34 | 37 |
| 35 // These either cause the VM to segfault or throw uncatchable API errors. | 38 // These either cause the VM to segfault or throw uncatchable API errors. |
| 36 // TODO(15274): Fix them and remove from blacklist. | 39 // TODO(15274): Fix them and remove from blacklist. |
| 37 'dart.io._IOService.dispatch', | 40 'dart.io._IOService.dispatch', |
| 38 new RegExp(r'.*_RandomAccessFile.*'), | 41 new RegExp(r'.*_RandomAccessFile.*'), |
| 39 'dart.io._StdIOUtils._socketType', | 42 'dart.io._StdIOUtils._socketType', |
| 40 'dart.io._StdIOUtils._getStdioOutputStream', | 43 'dart.io._StdIOUtils._getStdioOutputStream', |
| 41 'dart.io._Filter.newZLibInflateFilter', | 44 'dart.io._Filter.newZLibInflateFilter', |
| 42 'dart.io._Filter.newZLibDeflateFilter', | 45 'dart.io._Filter.newZLibDeflateFilter', |
| 43 'dart.io._FileSystemWatcher._listenOnSocket', | 46 'dart.io._FileSystemWatcher._listenOnSocket', |
| 44 'dart.io.SystemEncoding.decode', | 47 'dart.io.SystemEncoding.decode', |
| 45 'dart.io.SystemEncoding.encode', | 48 'dart.io.SystemEncoding.encode', |
| 46 'dart.core._Bigint._mulAdd', // TODO(regis): Is this an intrinsic issue? | 49 'dart.core.StringBuffer.toString', /// emptyarray: ok |
| 47 ]; | 50 ]; |
| 48 | 51 |
| 49 bool isBlacklisted(Symbol qualifiedSymbol) { | 52 bool isBlacklisted(Symbol qualifiedSymbol) { |
| 50 var qualifiedString = MirrorSystem.getName(qualifiedSymbol); | 53 var qualifiedString = MirrorSystem.getName(qualifiedSymbol); |
| 51 for (var pattern in blacklist) { | 54 for (var pattern in blacklist) { |
| 52 if (qualifiedString.contains(pattern)) return true; | 55 if (qualifiedString.contains(pattern)) return true; |
| 53 } | 56 } |
| 54 return false; | 57 return false; |
| 55 } | 58 } |
| 56 | 59 |
| 57 class Task { | 60 class Task { |
| 58 var name; | 61 var name; |
| 59 var action; | 62 var action; |
| 60 } | 63 } |
| 61 var queue = new List(); | 64 var queue = new List(); |
| 62 | 65 |
| 63 checkMethod(MethodMirror m, ObjectMirror target, [origin]) { | 66 checkMethod(MethodMirror m, ObjectMirror target, [origin]) { |
| 64 if (isBlacklisted(m.qualifiedName)) return; | 67 if (isBlacklisted(m.qualifiedName)) return; |
| 65 | 68 |
| 66 var task = new Task(); | 69 var task = new Task(); |
| 67 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin'; | 70 task.name = '${MirrorSystem.getName(m.qualifiedName)} from $origin'; |
| 68 | 71 |
| 69 if (m.isRegularMethod) { | 72 if (m.isRegularMethod) { |
| 70 task.action = | 73 task.action = |
| 71 () => target.invoke(m.simpleName, new List(m.parameters.length)); | 74 () => target.invoke(m.simpleName, |
| 75 new List.filled(m.parameters.length, fuzzArgument)); | |
| 72 } else if (m.isGetter) { | 76 } else if (m.isGetter) { |
| 73 task.action = | 77 task.action = |
| 74 () => target.getField(m.simpleName); | 78 () => target.getField(m.simpleName); |
| 75 } else if (m.isSetter) { | 79 } else if (m.isSetter) { |
| 76 task.action = | 80 task.action = |
| 77 () => target.setField(m.simpleName, null); | 81 () => target.setField(m.simpleName, null); |
| 78 } else if (m.isConstructor) { | 82 } else if (m.isConstructor) { |
| 79 return; | 83 return; |
| 80 } else { | 84 } else { |
| 81 throw "Unexpected method kind"; | 85 throw "Unexpected method kind"; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 100 .forEach((m) => checkMethod(m, classMirror)); | 104 .forEach((m) => checkMethod(m, classMirror)); |
| 101 | 105 |
| 102 classMirror.declarations.values | 106 classMirror.declarations.values |
| 103 .where((d) => d is MethodMirror && d.isConstructor) | 107 .where((d) => d is MethodMirror && d.isConstructor) |
| 104 .forEach((m) { | 108 .forEach((m) { |
| 105 if (isBlacklisted(m.qualifiedName)) return; | 109 if (isBlacklisted(m.qualifiedName)) return; |
| 106 var task = new Task(); | 110 var task = new Task(); |
| 107 task.name = MirrorSystem.getName(m.qualifiedName); | 111 task.name = MirrorSystem.getName(m.qualifiedName); |
| 108 | 112 |
| 109 task.action = () { | 113 task.action = () { |
| 110 var instance = classMirror.newInstance(m.constructorName, | 114 var instance = classMirror.newInstance( |
| 111 new List(m.parameters.length)); | 115 m.constructorName, |
| 116 new List.filled(m.parameters.length, fuzzArgument)); | |
| 112 checkInstance(instance, task.name); | 117 checkInstance(instance, task.name); |
| 113 }; | 118 }; |
| 114 queue.add(task); | 119 queue.add(task); |
| 115 }); | 120 }); |
| 116 } | 121 } |
| 117 | 122 |
| 118 checkLibrary(libraryMirror) { | 123 checkLibrary(libraryMirror) { |
| 119 print(libraryMirror.simpleName); | 124 print(libraryMirror.simpleName); |
| 120 if (isBlacklisted(libraryMirror.qualifiedName)) return; | 125 if (isBlacklisted(libraryMirror.qualifiedName)) return; |
| 121 | 126 |
| 122 libraryMirror.declarations.values | 127 libraryMirror.declarations.values |
| 123 .where((d) => d is ClassMirror) | 128 .where((d) => d is ClassMirror) |
| 124 .forEach(checkClass); | 129 .forEach(checkClass); |
| 125 | 130 |
| 126 libraryMirror.declarations.values | 131 libraryMirror.declarations.values |
| 127 .where((d) => d is MethodMirror) | 132 .where((d) => d is MethodMirror) |
| 128 .forEach((m) => checkMethod(m, libraryMirror)); | 133 .forEach((m) => checkMethod(m, libraryMirror)); |
| 129 } | 134 } |
| 130 | 135 |
| 131 var testZone; | 136 var testZone; |
| 132 | 137 |
| 133 doOneTask() { | 138 doOneTask() { |
| 134 if (queue.length == 0) { | 139 if (queue.length == 0) { |
| 135 print('Done'); | 140 print('Done'); |
| 136 return; | 141 return; |
| 137 } | 142 } |
| 138 | 143 |
| 139 var task = queue.removeLast(); | 144 var task = queue.removeLast(); |
| 140 print(task.name); | 145 //print(task.name); |
|
regis
2014/09/22 16:20:43
Remove commented out line?
rmacnak
2014/09/22 22:42:12
Uncommenting so this is on for the bot.
| |
| 141 try { | 146 try { |
| 142 task.action(); | 147 task.action(); |
| 143 } catch(e) {} | 148 } catch(e) {} |
| 144 | 149 |
| 145 // Register the next task in a timer callback so as to yield to async code | 150 // Register the next task in a timer callback so as to yield to async code |
| 146 // scheduled in the current task. This isn't necessary for the test itself, | 151 // scheduled in the current task. This isn't necessary for the test itself, |
| 147 // but is helpful when trying to figure out which function is responsible for | 152 // but is helpful when trying to figure out which function is responsible for |
| 148 // a crash. | 153 // a crash. |
| 149 testZone.createTimer(Duration.ZERO, doOneTask); | 154 testZone.createTimer(Duration.ZERO, doOneTask); |
| 150 } | 155 } |
| 151 | 156 |
| 157 var fuzzArgument; | |
| 158 | |
| 152 main([args]) { | 159 main([args]) { |
| 160 fuzzArgument = null; | |
| 161 fuzzArgument = 1; /// smi: ok | |
| 162 fuzzArgument = false; /// false: ok | |
| 163 fuzzArgument = 'string'; /// string: ok | |
| 164 fuzzArgument = new List(0); /// emptyarray: ok | |
|
regis
2014/09/22 16:20:43
Do I understand correctly that we can now name mul
rmacnak
2014/09/22 22:42:12
Yep
| |
| 165 | |
| 153 currentMirrorSystem().libraries.values.forEach(checkLibrary); | 166 currentMirrorSystem().libraries.values.forEach(checkLibrary); |
| 154 | 167 |
| 155 var valueObjects = | 168 var valueObjects = |
| 156 [true, false, null, | 169 [true, false, null, |
| 157 0, 0xEFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF, | 170 0, 0xEFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF, |
| 158 "foo", 'blåbærgrød', 'Îñţérñåţîöñåļîžåţîờñ']; | 171 "foo", 'blåbærgrød', 'Îñţérñåţîöñåļîžåţîờñ', "𝄞", #symbol]; |
| 159 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object')); | 172 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object')); |
| 160 | 173 |
| 161 uncaughtErrorHandler(self, parent, zone, error, stack) {}; | 174 uncaughtErrorHandler(self, parent, zone, error, stack) {}; |
| 162 var zoneSpec = | 175 var zoneSpec = |
| 163 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); | 176 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); |
| 164 testZone = Zone.current.fork(specification: zoneSpec); | 177 testZone = Zone.current.fork(specification: zoneSpec); |
| 165 testZone.createTimer(Duration.ZERO, doOneTask); | 178 testZone.createTimer(Duration.ZERO, doOneTask); |
| 166 } | 179 } |
| OLD | NEW |