| 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 various basic values (nulls, ints, etc). This may result in | 6 // invoke them will 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; |
| 11 | 11 |
| 12 import 'dart:mirrors'; | 12 import 'dart:mirrors'; |
| 13 import 'dart:async'; | 13 import 'dart:async'; |
| 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 // Don't recurse on this test. | 17 // Don't recurse on this test. |
| 18 'test.invoke_natives', | 18 'test.invoke_natives', |
| 19 | 19 |
| 20 // Don't exit the test pre-maturely. | 20 // Don't exit the test pre-maturely. |
| 21 'dart.io.exit', | 21 'dart.io.exit', |
| 22 | 22 |
| 23 // Don't change the exit code, which may fool the test harness. |
| 24 'dart.io.exitCode', |
| 25 |
| 23 // Don't run blocking io calls. | 26 // Don't run blocking io calls. |
| 24 new RegExp(r".*Sync$"), | 27 new RegExp(r".*Sync$"), |
| 25 | 28 |
| 26 // These prevent the test from exiting. | 29 // These prevent the test from exiting. |
| 27 'dart.async._scheduleAsyncCallback', | |
| 28 'dart.async._setTimerFactoryClosure', | |
| 29 'dart.isolate._startMainIsolate', | |
| 30 'dart.isolate._startIsolate', | |
| 31 'dart.io.sleep', | 30 'dart.io.sleep', |
| 32 'dart.io.HttpServer.HttpServer.listenOn', | 31 'dart.io.HttpServer.HttpServer.listenOn', |
| 33 new RegExp(r'dart.io.*'), /// smi: ok | 32 new RegExp('dart\.io.*'), /// smi: ok |
| 34 | 33 |
| 35 // Runtime exceptions we can't catch because they occur too early in event | 34 // Runtime exceptions we can't catch because they occur too early in event |
| 36 // dispatch to be caught in a zone. | 35 // dispatch to be caught in a zone. |
| 37 'dart.isolate._isolateScheduleImmediate', | |
| 38 'dart.io._Timer._createTimer', /// smi: ok | 36 'dart.io._Timer._createTimer', /// smi: ok |
| 39 'dart.async.runZoned', /// string: ok | 37 'dart.async.runZoned', /// string: ok |
| 40 'dart.async._AsyncRun._scheduleImmediate', | |
| 41 'dart.async._ScheduleImmediate._closure', | 38 'dart.async._ScheduleImmediate._closure', |
| 42 'dart.async._asyncRunCallback', | |
| 43 'dart.async._rootHandleUncaughtError', | |
| 44 'dart.async._schedulePriorityAsyncCallback', | |
| 45 'dart.async._setScheduleImmediateClosure', | |
| 46 | 39 |
| 47 // These either cause the VM to segfault or throw uncatchable API errors. | 40 // These either cause the VM to segfault or throw uncatchable API errors. |
| 48 // TODO(15274): Fix them and remove from blacklist. | 41 // TODO(15274): Fix them and remove from blacklist. |
| 49 'dart.io._IOService.dispatch', | 42 'dart.io._IOService.dispatch', |
| 50 new RegExp(r'.*_RandomAccessFile.*'), | |
| 51 'dart.io._StdIOUtils._socketType', | 43 'dart.io._StdIOUtils._socketType', |
| 52 'dart.io._StdIOUtils._getStdioOutputStream', | 44 'dart.io._StdIOUtils._getStdioOutputStream', |
| 53 'dart.io._Filter.newZLibInflateFilter', | 45 'dart.io._Filter.newZLibInflateFilter', |
| 54 'dart.io._Filter.newZLibDeflateFilter', | 46 'dart.io._Filter.newZLibDeflateFilter', |
| 55 'dart.io._FileSystemWatcher._listenOnSocket', | 47 'dart.io._FileSystemWatcher._listenOnSocket', |
| 56 'dart.io.SystemEncoding.decode', | |
| 57 'dart.io.SystemEncoding.encode', | |
| 58 'dart.core.StringBuffer.toString', /// emptyarray: ok | |
| 59 | |
| 60 // See Object_toString and Issue 20583 | |
| 61 'dart.core.Error._objectToString', /// string: ok | |
| 62 ]; | 48 ]; |
| 63 | 49 |
| 64 bool isBlacklisted(Symbol qualifiedSymbol) { | 50 bool isBlacklisted(Symbol qualifiedSymbol) { |
| 65 var qualifiedString = MirrorSystem.getName(qualifiedSymbol); | 51 var qualifiedString = MirrorSystem.getName(qualifiedSymbol); |
| 66 for (var pattern in blacklist) { | 52 for (var pattern in blacklist) { |
| 67 if (qualifiedString.contains(pattern)) return true; | 53 if (qualifiedString.contains(pattern)) { |
| 54 print('Skipping $qualifiedString'); |
| 55 return true; |
| 56 } |
| 68 } | 57 } |
| 69 return false; | 58 return false; |
| 70 } | 59 } |
| 71 | 60 |
| 72 class Task { | 61 class Task { |
| 73 var name; | 62 var name; |
| 74 var action; | 63 var action; |
| 75 } | 64 } |
| 76 var queue = new List(); | 65 var queue = new List(); |
| 77 | 66 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 150 |
| 162 // Register the next task in a timer callback so as to yield to async code | 151 // Register the next task in a timer callback so as to yield to async code |
| 163 // scheduled in the current task. This isn't necessary for the test itself, | 152 // scheduled in the current task. This isn't necessary for the test itself, |
| 164 // but is helpful when trying to figure out which function is responsible for | 153 // but is helpful when trying to figure out which function is responsible for |
| 165 // a crash. | 154 // a crash. |
| 166 testZone.createTimer(Duration.ZERO, doOneTask); | 155 testZone.createTimer(Duration.ZERO, doOneTask); |
| 167 } | 156 } |
| 168 | 157 |
| 169 var fuzzArgument; | 158 var fuzzArgument; |
| 170 | 159 |
| 171 main([args]) { | 160 main() { |
| 172 fuzzArgument = null; | 161 fuzzArgument = null; |
| 173 fuzzArgument = 1; /// smi: ok | 162 fuzzArgument = 1; /// smi: ok |
| 174 fuzzArgument = false; /// false: ok | 163 fuzzArgument = false; /// false: ok |
| 175 fuzzArgument = 'string'; /// string: ok | 164 fuzzArgument = 'string'; /// string: ok |
| 176 fuzzArgument = new List(0); /// emptyarray: ok | 165 fuzzArgument = new List(0); /// emptyarray: ok |
| 177 | 166 |
| 167 print('Fuzzing with $fuzzArgument'); |
| 168 |
| 178 currentMirrorSystem().libraries.values.forEach(checkLibrary); | 169 currentMirrorSystem().libraries.values.forEach(checkLibrary); |
| 179 | 170 |
| 180 var valueObjects = | 171 var valueObjects = |
| 181 [true, false, null, | 172 [true, false, null, [], {}, dynamic, |
| 182 0, 0xEFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF, | 173 0, 0xEFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 3.14159, |
| 183 "foo", 'blåbærgrød', 'Îñţérñåţîöñåļîžåţîờñ', "𝄞", #symbol]; | 174 "foo", 'blåbærgrød', 'Îñţérñåţîöñåļîžåţîờñ', "𝄞", #symbol]; |
| 184 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object')); | 175 valueObjects.forEach((v) => checkInstance(reflect(v), 'value object')); |
| 185 | 176 |
| 186 uncaughtErrorHandler(self, parent, zone, error, stack) {}; | 177 uncaughtErrorHandler(self, parent, zone, error, stack) {}; |
| 187 var zoneSpec = | 178 var zoneSpec = |
| 188 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); | 179 new ZoneSpecification(handleUncaughtError: uncaughtErrorHandler); |
| 189 testZone = Zone.current.fork(specification: zoneSpec); | 180 testZone = Zone.current.fork(specification: zoneSpec); |
| 190 testZone.createTimer(Duration.ZERO, doOneTask); | 181 testZone.createTimer(Duration.ZERO, doOneTask); |
| 191 } | 182 } |
| OLD | NEW |