Revert "[gardening] mark sample_extension_test as error"

This reverts commit 679108ea7b.

Revert "Update 'samples/sample_extension' to Dart 2"

This reverts commit fba5a58b47.

Reason for revert: Broken app-kernel and app-reload bots

TBR=asiva@google.com,kathyw@google.com

Change-Id: I690694ec974fa316b25934a1f0f62b5e665a28ba
Reviewed-on: https://dart-review.googlesource.com/c/86800
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2018-12-10 19:37:33 +00:00 committed by commit-bot@chromium.org
parent 3875d8bfa2
commit 49142b49e7
6 changed files with 70 additions and 58 deletions

View file

@ -13,25 +13,30 @@ class RandomArray {
static SendPort _port;
Future<List<int>> randomArray(int seed, int length) {
var completer = Completer<List<int>>();
var replyPort = RawReceivePort();
var args = List<Object>(3);
var completer = new Completer();
var replyPort = new RawReceivePort();
var args = new List(3);
args[0] = seed;
args[1] = length;
args[2] = replyPort.sendPort;
_servicePort.send(args);
replyPort.handler = (List<int> result) {
replyPort.handler = (result) {
replyPort.close();
if (result != null) {
completer.complete(result);
} else {
completer.completeError(Exception('Random array creation failed'));
completer.completeError(new Exception("Random array creation failed"));
}
};
return completer.future;
}
SendPort get _servicePort => _port ??= _newServicePort();
SendPort get _servicePort {
if (_port == null) {
_port = _newServicePort();
}
return _port;
}
SendPort _newServicePort() native 'RandomArray_ServicePort';
SendPort _newServicePort() native "RandomArray_ServicePort";
}

View file

@ -7,6 +7,6 @@ library sample_synchronous_extension;
import 'dart-ext:sample_extension';
// The simplest way to call native code: top-level functions.
int systemRand() native 'SystemRand';
int noScopeSystemRand() native 'NoScopeSystemRand';
bool systemSrand(int seed) native 'SystemSrand';
int systemRand() native "SystemRand";
int noScopeSystemRand() native "NoScopeSystemRand";
bool systemSrand(int seed) native "SystemSrand";

View file

@ -6,6 +6,7 @@
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
import "package:expect/expect.dart";
import "package:path/path.dart";
@ -44,6 +45,7 @@ Future run(String program, List<String> arguments) async {
}
Future testNativeExtensions(String snapshotKind) async {
String buildDirectory = dirname(Platform.executable);
Directory tempDirectory =
Directory.systemTemp.createTempSync('sample_extension_');
try {
@ -71,14 +73,14 @@ Future testNativeExtensions(String snapshotKind) async {
snapshot = script;
} else {
snapshot = join(testDirectory, "$test.snapshot");
List<String> args = List<String>.from(Platform.executableArguments);
List<String> args = new List<String>.from(Platform.executableArguments);
args.add('--snapshot=$snapshot');
args.add('--snapshot-kind=$snapshotKind');
args.add(script);
await run(Platform.executable, args);
}
List<String> args = List<String>.from(Platform.executableArguments);
List<String> args = new List<String>.from(Platform.executableArguments);
args.add(snapshot);
await run(Platform.executable, args);
}

View file

@ -7,15 +7,17 @@ library test_sample_extension;
import 'sample_asynchronous_extension.dart';
void check(bool condition, String message) {
if (!condition) throw StateError(message);
if (!condition) {
throw new StateError(message);
}
}
void main() {
RandomArray r = RandomArray();
RandomArray r = new RandomArray();
r.randomArray(17, 100).then((list_100) {
r.randomArray(17, 200).then((list_200) {
for (var i = 0; i < 100; ++i) {
check(list_100[i] == list_200[i], 'list_100[i] == list_200[i]');
check(list_100[i] == list_200[i], "list_100[i] == list_200[i]");
}
});
});
@ -25,26 +27,32 @@ void main() {
r.randomArray(19, 256000).then(checkNormal);
}
void checkNormal(List<int> l) {
void checkNormal(List l) {
// Count how many times each byte value occurs. Assert that the counts
// are all within a reasonable (six-sigma) range.
final counts = List<int>.filled(256, 0);
for (var e in l) counts[e]++;
RandomArray().randomArray(18, 256000).then(checkCorrelation(counts));
List counts = new List<int>.filled(256, 0);
for (var e in l) {
counts[e]++;
}
new RandomArray().randomArray(18, 256000).then(checkCorrelation(counts));
}
void Function(List<int>) checkCorrelation(List<int> counts) => (l) {
final counts_2 = List<int>.filled(256, 0);
for (var e in l) counts_2[e]++;
var product = 0;
for (var i = 0; i < 256; ++i) {
check(counts[i] < 1200, 'counts[i] < 1200');
check(counts_2[i] < 1200, 'counts_2[i] < 1200');
check(counts[i] > 800, 'counts[i] > 800');
check(counts[i] > 800, 'counts[i] > 800');
Function checkCorrelation(List counts) {
return (List l) {
List counts_2 = new List<int>.filled(256, 0);
for (var e in l) {
counts_2[e]++;
}
var product = 0;
for (var i = 0; i < 256; ++i) {
check(counts[i] < 1200, "counts[i] < 1200");
check(counts_2[i] < 1200, "counts_2[i] < 1200");
check(counts[i] > 800, "counts[i] > 800");
check(counts[i] > 800, "counts[i] > 800");
product += counts[i] * counts_2[i];
}
check(product < 256000000 * 1.001, 'product < 256000000 * 1.001');
check(product > 256000000 * 0.999, 'product > 256000000 * 0.999');
};
product += counts[i] * counts_2[i];
}
check(product < 256000000 * 1.001, "product < 256000000 * 1.001");
check(product > 256000000 * 0.999, "product > 256000000 * 0.999");
};
}

View file

@ -7,8 +7,9 @@ library test_sample_extension;
import 'sample_synchronous_extension.dart';
void check(bool condition, String message) {
if (!condition) throw StateError(message);
print('$message - passed');
if (!condition) {
throw new StateError(message);
}
}
void checkSystemRand() {
@ -16,17 +17,17 @@ void checkSystemRand() {
var x1 = systemRand();
var x2 = systemRand();
var x3 = systemRand();
check(x1 != x2, 'x1 != x2');
check(x1 != x3, 'x1 != x3');
check(x2 != x3, 'x2 != x3');
check(x1 != x2, "x1 != x2");
check(x1 != x3, "x1 != x3");
check(x2 != x3, "x2 != x3");
systemSrand(17);
check(x1 == systemRand(), 'x1 == systemRand()');
check(x2 == systemRand(), 'x2 == systemRand()');
check(x3 == systemRand(), 'x3 == systemRand()');
check(x1 == systemRand(), "x1 == systemRand()");
check(x2 == systemRand(), "x2 == systemRand()");
check(x3 == systemRand(), "x3 == systemRand()");
systemSrand(18);
check(x1 != systemRand(), 'x1 != systemRand()');
check(x2 != systemRand(), 'x2 != systemRand()');
check(x3 != systemRand(), 'x3 != systemRand()');
check(x1 != systemRand(), "x1 != systemRand()");
check(x2 != systemRand(), "x2 != systemRand()");
check(x3 != systemRand(), "x3 != systemRand()");
}
void checkNoScopeSystemRand() {
@ -34,17 +35,17 @@ void checkNoScopeSystemRand() {
var x1 = noScopeSystemRand();
var x2 = noScopeSystemRand();
var x3 = noScopeSystemRand();
check(x1 != x2, 'x1 != x2');
check(x1 != x3, 'x1 != x3');
check(x2 != x3, 'x2 != x3');
check(x1 != x2, "x1 != x2");
check(x1 != x3, "x1 != x3");
check(x2 != x3, "x2 != x3");
systemSrand(17);
check(x1 == noScopeSystemRand(), 'x1 == noScopeSystemRand()');
check(x2 == noScopeSystemRand(), 'x2 == noScopeSystemRand()');
check(x3 == noScopeSystemRand(), 'x3 == noScopeSystemRand()');
check(x1 == noScopeSystemRand(), "x1 == noScopeSystemRand()");
check(x2 == noScopeSystemRand(), "x2 == noScopeSystemRand()");
check(x3 == noScopeSystemRand(), "x3 == noScopeSystemRand()");
systemSrand(18);
check(x1 != noScopeSystemRand(), 'x1 != noScopeSystemRand()');
check(x2 != noScopeSystemRand(), 'x2 != noScopeSystemRand()');
check(x3 != noScopeSystemRand(), 'x3 != noScopeSystemRand()');
check(x1 != noScopeSystemRand(), "x1 != noScopeSystemRand()");
check(x2 != noScopeSystemRand(), "x2 != noScopeSystemRand()");
check(x3 != noScopeSystemRand(), "x3 != noScopeSystemRand()");
}
void main() {

View file

@ -26,14 +26,10 @@ sample_extension/test/sample_extension_app_snapshot_test: Pass, RuntimeError # I
[ !$preview_dart_2 && ($runtime == dart_precompiled || $runtime == vm) ]
*: SkipByDesign # Deprecating all Dart1 modes of execution
[ $compiler == app_jitk || $compiler == dartkb || $compiler == dartkp ]
[ $compiler == app_jitk || $compiler == dartk || $compiler == dartkb || $compiler == dartkp ]
sample_extension/test/sample_extension_app_snapshot_test: RuntimeError
sample_extension/test/sample_extension_test: RuntimeError
[ $compiler == dartk ]
sample_extension/test/sample_extension_app_snapshot_test: RuntimeError
sample_extension/test/sample_extension_test: Pass, RuntimeError # See https://github.com/dart-lang/sdk/pull/33711#issuecomment-445761112
# Skip tests that use dart:io
[ $runtime == d8 || $browser ]
sample_extension/*: Skip