| Index: tests/standalone/io/file_fuzz_test.dart
|
| diff --git a/tests/standalone/io/file_fuzz_test.dart b/tests/standalone/io/file_fuzz_test.dart
|
| index 47a6519654d62b3c6a1dba656c1a129f43e129c6..efee40a6934098663797000dc848207d6c9275c0 100644
|
| --- a/tests/standalone/io/file_fuzz_test.dart
|
| +++ b/tests/standalone/io/file_fuzz_test.dart
|
| @@ -6,20 +6,60 @@
|
| // passes if the VM does not crash.
|
|
|
| #import('dart:io');
|
| +#import('dart:isolate');
|
|
|
| final typeMapping = const {
|
| + 'null': null,
|
| 'int': 0,
|
| + 'bigint': 18446744073709551617,
|
| 'String': 'a',
|
| 'FileMode': FileMode.READ,
|
| 'num': 0.50,
|
| - 'List<int>': const [1, 2, 3]
|
| + 'List<int>': const [1, 2, 3],
|
| + 'Map<String, int>': const { "a": 23 }
|
| };
|
|
|
| +typePermutations(int argCount) {
|
| + var result = [];
|
| + if (argCount == 2) {
|
| + typeMapping.forEach((k, v) {
|
| + typeMapping.forEach((k2, v2) {
|
| + result.add([v, v2]);
|
| + });
|
| + });
|
| + } else {
|
| + Expect.isTrue(argCount == 3);
|
| + typeMapping.forEach((k, v) {
|
| + typeMapping.forEach((k2, v2) {
|
| + typeMapping.forEach((k3, v3) {
|
| + result.add([v, v2, v3]);
|
| + });
|
| + });
|
| + });
|
| + }
|
| + return result;
|
| +}
|
| +
|
| +// Perform sync operation and ignore all exceptions.
|
| doItSync(Function f) {
|
| - // Ignore all exceptions.
|
| try { f(); } catch (var e) {}
|
| }
|
|
|
| +// Perform async operation and transform the future for the operation
|
| +// into a future that never fails by treating errors as normal
|
| +// completion.
|
| +Future doItAsync(Function f) {
|
| + // Ignore value and errors.
|
| + var completer = new Completer();
|
| + var future = f();
|
| + future.handleException((e) {
|
| + completer.complete(true);
|
| + return true;
|
| + });
|
| + future.then((v) => completer.complete(true));
|
| + return completer.future;
|
| +}
|
| +
|
| fuzzSyncMethods() {
|
| typeMapping.forEach((k, v) {
|
| doItSync(() {
|
| @@ -32,6 +72,8 @@ fuzzSyncMethods() {
|
| doItSync(f.fullPathSync);
|
| doItSync(() => f.openInputStream().onError = (e) => null);
|
| doItSync(f.readAsBytesSync);
|
| + doItSync(f.readAsTextSync);
|
| + doItSync(f.readAsLinesSync);
|
| typeMapping.forEach((k2, v2) {
|
| doItSync(() => f.openSync(v2));
|
| doItSync(() => f.openOutputStream(v2).onError = (e) => null);
|
| @@ -42,6 +84,59 @@ fuzzSyncMethods() {
|
| });
|
| }
|
|
|
| +fuzzAsyncMethods() {
|
| + var port = new ReceivePort();
|
| + var futures = [];
|
| + typeMapping.forEach((k, v) {
|
| + doItSync(() {
|
| + var f = new File(v);
|
| + futures.add(doItAsync(f.exists));
|
| + futures.add(doItAsync(f.delete));
|
| + futures.add(doItAsync(f.directory));
|
| + futures.add(doItAsync(f.length));
|
| + futures.add(doItAsync(f.open));
|
| + futures.add(doItAsync(f.fullPath));
|
| + futures.add(doItAsync(f.readAsBytes));
|
| + futures.add(doItAsync(f.readAsLines));
|
| + futures.add(doItAsync(f.readAsText));
|
| + typeMapping.forEach((k2, v2) {
|
| + futures.add(doItAsync(() => f.open(v2)));
|
| + futures.add(doItAsync(() => f.readAsText(v2)));
|
| + futures.add(doItAsync(() => f.readAsLines(v2)));
|
| + });
|
| + });
|
| + });
|
| + Futures.wait(futures).then((ignore) => port.close());
|
| +}
|
| +
|
| +
|
| +// TODO(ager): Finish implementation.
|
| +fuzzSyncRandomAccessMethods() {
|
| + var d = new Directory('');
|
| + var temp = d.createTempSync();
|
| + var file = new File('${temp.path}/x');
|
| + file.createSync();
|
| + var modes = [ FileMode.READ, FileMode.WRITE, FileMode.APPEND ];
|
| + for (var m in modes) {
|
| + var opened = file.openSync(m);
|
| + typeMapping.forEach((k, v) {
|
| + doItSync(() => opened.setPositionSync(v));
|
| + doItSync(() => opened.writeByteSync(v));
|
| + });
|
| + for (var p in typePermutations(2)) {
|
| + doItSync(() => opened.writeStringSync(p[0], p[1]));
|
| + }
|
| + for (var p in typePermutations(3)) {
|
| + doItSync(() => opened.readListSync(p[0], p[1], p[2]));
|
| + doItSync(() => opened.writeList(p[0], p[1], p[2]));
|
| + }
|
| + opened.closeSync();
|
| + }
|
| + temp.deleteRecursivelySync();
|
| +}
|
| +
|
| main() {
|
| fuzzSyncMethods();
|
| + fuzzAsyncMethods();
|
| + fuzzSyncRandomAccessMethods();
|
| }
|
|
|