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

Unified Diff: runtime/vm/snapshot_test.dart

Issue 10837070: Remove old isolate API and update all code in the repository to use (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/isolate_test.cc ('k') | samples/chat/README » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/snapshot_test.dart
diff --git a/runtime/vm/snapshot_test.dart b/runtime/vm/snapshot_test.dart
index 91e03e7667c800e13ed403845ccd02420cbb119b..89177bf2a7499e1bb3dfb1e10c44f3c6b5f4d6b8 100644
--- a/runtime/vm/snapshot_test.dart
+++ b/runtime/vm/snapshot_test.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -1101,10 +1101,8 @@ class PingPongGame {
_pong = null,
_warmedup = false,
_iterations = 0 {
- new Pong().spawn().then((SendPort port) {
- _pong = port;
- play();
- });
+ SendPort _pong = spawnFunction(pong);
+ play();
}
void startRound() {
@@ -1159,25 +1157,16 @@ class PingPongGame {
int _iterations;
}
-class Pong extends Isolate {
-
- // TODO(hpayer): can be removed as soon as we have default constructors
- Pong() : super() { }
-
- void main() {
- this.port.receive((message, SendPort replyTo) {
- if (message == Benchmark1.INIT_MESSAGE) {
- _reply = replyTo;
- _reply.send(message, null);
- } else if (message == Benchmark1.TERMINATION_MESSAGE) {
- this.port.close();
- } else {
- _reply.send(message, null);
- }
- });
- }
-
- SendPort _reply;
+void pong() {
+ port.receive((message, SendPort replyTo) {
+ if (message == Benchmark1.INIT_MESSAGE) {
+ replyTo.send(message, null);
+ } else if (message == Benchmark1.TERMINATION_MESSAGE) {
+ port.close();
+ } else {
+ replyTo.send(message, null);
+ }
+ });
}
@@ -1189,469 +1178,59 @@ class ManyGenericInstanceofTest {
}
}
-// Dart test program for testing that exceptions in other isolates bring down
-// the program.
-// ImportOptions=IsolateTestFramework
-
-class Isolate2NegativeTest extends Isolate {
- Isolate2NegativeTest() : super();
-
- static void testMain() {
- // We will never call 'done'. This test fails with a timeout.
- IsolateTestFramework.waitForDone();
- new Isolate2NegativeTest().spawn();
- }
-
- void main() {
- throw "foo";
- }
-}
-
-
-class IsolateTestFramework {
- static void waitForDone() {
- // By keeping an open receive port we keep the isolate alive. This way we
- // can wait for other isolates to finish before terminating the main
- // isolate.
- _port = new ReceivePort();
- if (waitForDoneCallback !== null) waitForDoneCallback();
- }
- static void done() {
- _port.close();
- if (doneCallback !== null) doneCallback();
- }
-
- static Function waitForDoneCallback;
- static Function doneCallback;
- static ReceivePort _port;
-}
-
-// Dart test program for testing that the exit-handler is executed at the end.
-
-
-class IsolateExitHandlerTest extends Isolate {
- static int counter;
-
- IsolateExitHandlerTest() : super.heavy();
-
- static void testMain() {
- Isolate.setExitHandler(() {
- Expect.equals(1, counter);
- });
- new IsolateExitHandlerTest().spawn().then((SendPort p) {
- p.call("bar").then((msg) {
- counter++;
- });
- });
- }
-
- void main() {
- bool encounteredException = false;
- try {
- Isolate.setExitHandler(() {
- Expect.equals(true, false);
- });
- } catch(var e) {
- encounteredException = true;
- }
- Expect.equals(true, encounteredException);
-
- this.port.receive((ignored, replyTo) {
- replyTo.send("foo", null);
- this.port.close();
- });
- }
-}
-
-
// ---------------------------------------------------------------------------
// THE REST OF THIS FILE COULD BE AUTOGENERATED
// ---------------------------------------------------------------------------
-
-// ImportOptions=IsolateTestFramework
-
-class SpawnTest {
-
- static void testMain() {
- spawnIsolate();
- }
-
- static void spawnIsolate() {
- IsolateTestFramework.waitForDone();
- SpawnedIsolate isolate = new SpawnedIsolate();
- isolate.spawn().then((SendPort port) {
- port.call(42).then((message) {
- Expect.equals(42, message);
- IsolateTestFramework.done();
- });
- });
- }
-}
-
-class SpawnedIsolate extends Isolate {
-
- SpawnedIsolate() : super() { }
-
- void main() {
- this.port.receive((message, SendPort replyTo) {
- Expect.equals(42, message);
- replyTo.send(42, null);
- this.port.close();
- });
- }
-
-}
-
-// Dart test program for testing that the exit-handler is executed.
-
-
-class IsolateExitHandlerNegativeTest extends Isolate {
- IsolateExitHandlerNegativeTest() : super.heavy();
-
- static void testMain() {
- Isolate.setExitHandler(() {
- Expect.equals(true, false); // <=-------- Should fail here.
- });
- new IsolateExitHandlerNegativeTest().spawn();
- }
-
- void main() {
- this.port.close();
- }
-}
-
-// ImportOptions=IsolateTestFramework
-
-class ConstructorTest extends Isolate {
- final int field;
- ConstructorTest() : super(), field = 499;
-
- void main() {
- IsolateTestFramework.waitForDone();
- this.port.receive((ignoredMessage, reply) {
- reply.send(field, null);
- this.port.close();
- IsolateTestFramework.done();
- });
- }
-
- static void testMain() {
- ConstructorTest test = new ConstructorTest();
- test.spawn().then((SendPort port) {
- port.call("ignored").then((message) {
- Expect.equals(499, message);
- });
- });
- }
-}
-
-// Dart test program for testing isolate communication with
-// simple messages.
-// ImportOptions=IsolateTestFramework
-
-class IsolateTest {
-
- static void testMain() {
- _waitingForDoneCount = 0;
- IsolateTestFramework.waitForDone();
- RequestReplyTest.test();
- CountTest.test();
- StaticStateTest.test();
- }
-
- static void waitForDone() {
- _waitingForDoneCount++;
- }
-
- static void done() {
- if (--_waitingForDoneCount == 0) {
- IsolateTestFramework.done();
- }
- }
-
- static int _waitingForDoneCount;
-}
-
-
// ---------------------------------------------------------------------------
-// Request-reply test.
+// tests/isolate/spawn_test.dart
// ---------------------------------------------------------------------------
-class RequestReplyTest {
-
- static void test() {
- testCall();
- testSend();
- }
-
- static void testCall() {
- IsolateTest.waitForDone();
- new RequestReplyIsolate().spawn().then((SendPort port) {
- port.call(42).then((message) {
- Expect.equals(42 + 87, message);
- IsolateTest.done();
- });
- });
- }
-
- static void testSend() {
- IsolateTest.waitForDone();
- new RequestReplyIsolate().spawn().then((SendPort port) {
- ReceivePort reply = new ReceivePort();
- port.send(99, reply.toSendPort());
- reply.receive((message, replyTo) {
- Expect.equals(99 + 87, message);
- reply.close();
- IsolateTest.done();
- });
- });
- }
+spawn_test_main() {
+ test("spawn a new isolate", () {
+ SendPort port = spawnFunction(entry);
+ port.call(42).then(expectAsync1((message) {
+ Expect.equals(42, message);
+ }));
+ });
}
-
-class RequestReplyIsolate extends Isolate {
-
- RequestReplyIsolate() : super() { }
-
- void main() {
- this.port.receive((message, SendPort replyTo) {
- replyTo.send(message + 87, null);
- this.port.close();
- });
- }
-
+void entry() {
+ port.receive((message, SendPort replyTo) {
+ Expect.equals(42, message);
+ replyTo.send(42, null);
+ port.close();
+ });
}
-
// ---------------------------------------------------------------------------
-// Simple counting test.
+// tests/isolate/isolate_negative_test.dart
// ---------------------------------------------------------------------------
-class CountTest {
-
- static int count;
-
- static void test() {
- IsolateTest.waitForDone();
- print("Hello ");
- new CountIsolate().spawn().then((SendPort remote) {
- ReceivePort local = new ReceivePort();
- SendPort reply = local.toSendPort();
-
- local.receive((int message, SendPort replyTo) {
- if (message == -1) {
- Expect.equals(11, count);
- // Close the only ReceivePort to terminate the isolate after the
- // callback returns.
- local.close();
- print("IsolateTest exiting.");
- IsolateTest.done();
- return;
- }
- Expect.equals((count - 1) * 2, message);
- print("IsolateTest: $message");
- remote.send(count++, reply);
- if (count == 10) {
- remote.send(-1, reply);
- }
- });
-
- print("!");
- count = 0;
- remote.send(count++, reply);
- });
- }
+void isolate_negative_entry() {
+ port.receive((ignored, replyTo) {
+ replyTo.send("foo", null);
+ });
}
-
-class CountIsolate extends Isolate {
-
- CountIsolate() : super() { }
-
- void main() {
- print("World");
- int count = 0;
-
- this.port.receive((int message, SendPort replyTo) {
- print("Remote: $message");
- if (message == -1) {
- Expect.equals(10, count);
- replyTo.send(-1, null);
- // Close the only ReceivePort to terminate the isolate after the
- // callback returns.
- this.port.close();
- print("RemoteRunner exiting.");
- return;
- }
-
- Expect.equals(count, message);
- count++;
- replyTo.send(message * 2, null);
- });
- }
-}
-
-
-
-// ---------------------------------------------------------------------------
-// State state test.
-// ---------------------------------------------------------------------------
-
-class StaticStateTest {
-
- static String state;
-
- static void test() {
- IsolateTest.waitForDone();
- Expect.equals(null, state);
- state = "foo";
- Expect.equals("foo", state);
-
- new StaticStateIsolate().spawn().then((SendPort remote) {
- remote.call("bar").then((reply) {
- Expect.equals("foo", state);
- Expect.equals(null, reply);
-
- state = "baz";
- remote.call("exit").then((reply) {
- Expect.equals("baz", state);
- Expect.equals("bar", reply);
- IsolateTest.done();
- });
- });
- });
- }
-
-}
-
-
-class StaticStateIsolate extends Isolate {
-
- StaticStateIsolate() : super() { }
-
- void main() {
- Expect.equals(null, StaticStateTest.state);
- this.port.receive((var message, SendPort replyTo) {
- String old = StaticStateTest.state;
- StaticStateTest.state = message;
- replyTo.send(old, null);
- if (message == "exit") {
- this.port.close();
- return;
- }
- });
- }
-
-}
-
-
-// Dart test program for testing isolate communication with
-// complex messages.
-// ImportOptions=IsolateTestFramework
-
-
-class IsolateComplexMessagesTest {
-
- static void testMain() {
- LogClient.test();
- }
+isolate_negative_test_main() {
+ test("ensure isolate code is executed", () {
+ SendPort port = spawnFunction(isolate_negative_entry);
+ port.call("foo").then(expectAsync1((message) {
+ Expect.equals(true, "Expected fail"); // <=-------- Should fail here.
+ }));
+ });
}
-
// ---------------------------------------------------------------------------
-// Log server test.
+// tests/isolate/message_test.dart
// ---------------------------------------------------------------------------
-class LogClient {
- static void test() {
- IsolateTestFramework.waitForDone();
- new LogIsolate().spawn().then((SendPort remote) {
-
- remote.send(1, null);
- remote.send("Hello", null);
- remote.send("World", null);
- remote.send(const [null, 1, 2, 3, 4], null);
- remote.send(const [1, 2.0, true, false, 0xffffffffff], null);
- remote.send(const ["Hello", "World", 0xffffffffff], null);
- // Shutdown the LogRunner.
- remote.call(-1).then((int message) {
- Expect.equals(6, message);
- });
- IsolateTestFramework.done();
- });
- }
-}
-
-
-class LogIsolate extends Isolate {
- LogIsolate() : super() { }
-
- void main() {
- print("Starting log server.");
-
- int count = 0;
-
- this.port.receive((var message, SendPort replyTo) {
- if (message == -1) {
- this.port.close();
- print("Stopping log server.");
- replyTo.send(count, null);
- } else {
- print("Log ($count) $message");
- switch (count) {
- case 0:
- Expect.equals(1, message);
- break;
- case 1:
- Expect.equals("Hello", message);
- break;
- case 2:
- Expect.equals("World", message);
- break;
- case 3:
- Expect.equals(5, message.length);
- Expect.equals(null, message[0]);
- Expect.equals(1, message[1]);
- Expect.equals(2, message[2]);
- Expect.equals(3, message[3]);
- Expect.equals(4, message[4]);
- break;
- case 4:
- Expect.equals(5, message.length);
- Expect.equals(1, message[0]);
- Expect.equals(2.0, message[1]);
- Expect.equals(true, message[2]);
- Expect.equals(false, message[3]);
- Expect.equals(0xffffffffff, message[4]);
- break;
- case 5:
- Expect.equals(3, message.length);
- Expect.equals("Hello", message[0]);
- Expect.equals("World", message[1]);
- Expect.equals(0xffffffffff, message[2]);
- break;
- }
- count++;
- }
- });
- }
-}
-
-
-// Dart test program for testing serialization of messages.
-// VMOptions=--enable_type_checks --enable_asserts
-// ImportOptions=IsolateTestFramework
-
// ---------------------------------------------------------------------------
// Message passing test.
// ---------------------------------------------------------------------------
class MessageTest {
- static void testMain() {
- PingPongClient.test();
- }
-
static final List list1 = const ["Hello", "World", "Hello", 0xfffffffffff];
static final List list2 = const [null, list1, list1, list1, list1];
static final List list3 = const [list2, 2.0, true, false, 0xfffffffffff];
@@ -1701,107 +1280,175 @@ class MessageTest {
}
}
-class PingPongClient {
- static void test() {
- IsolateTestFramework.waitForDone();
- new PingPongServer().spawn().then((SendPort remote) {
-
- // Send objects and receive them back.
- for (int i = 0; i < MessageTest.elms.length; i++) {
- var sentObject = MessageTest.elms[i];
- remote.call(sentObject).then((var receivedObject) {
- MessageTest.VerifyObject(i, receivedObject);
- });
+pingPong() {
+ int count = 0;
+ port.receive((var message, SendPort replyTo) {
+ if (message == -1) {
+ port.close();
+ replyTo.send(count, null);
+ } else {
+ // Check if the received object is correct.
+ if (count < MessageTest.elms.length) {
+ MessageTest.VerifyObject(count, message);
}
+ // Bounce the received object back so that the sender
+ // can make sure that the object matches.
+ replyTo.send(message, null);
+ count++;
+ }
+ });
+}
+
+message_test_main() {
+ test("send objects and receive them back", () {
+ SendPort remote = spawnFunction(pingPong);
+ // Send objects and receive them back.
+ for (int i = 0; i < MessageTest.elms.length; i++) {
+ var sentObject = MessageTest.elms[i];
+ // TODO(asiva): remove this local var idx once thew new for-loop
+ // semantics for closures is implemented.
+ var idx = i;
+ remote.call(sentObject).then(expectAsync1((var receivedObject) {
+ MessageTest.VerifyObject(idx, receivedObject);
+ }));
+ }
- // Send recursive objects and receive them back.
- List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
- List local_list2 = [null, local_list1, local_list1 ];
- List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
- List sendObject = new List(5);
- sendObject[0] = local_list1;
- sendObject[1] = sendObject;
- sendObject[2] = local_list2;
- sendObject[3] = sendObject;
- sendObject[4] = local_list3;
- remote.call(sendObject).then((var replyObject) {
- Expect.equals(true, sendObject is List);
- Expect.equals(true, replyObject is List);
- Expect.equals(sendObject.length, replyObject.length);
- Expect.equals(true, replyObject[1] === replyObject);
- Expect.equals(true, replyObject[3] === replyObject);
- Expect.equals(true, replyObject[0] === replyObject[2][1]);
- Expect.equals(true, replyObject[0] === replyObject[2][2]);
- Expect.equals(true, replyObject[2] === replyObject[4][0]);
- Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
- // Bigint literals are not canonicalized so do a == check.
- Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
- });
-
- // Shutdown the MessageServer.
- remote.call(-1).then((int message) {
- Expect.equals(MessageTest.elms.length + 1, message);
- IsolateTestFramework.done();
- });
+ // Send recursive objects and receive them back.
+ List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
+ List local_list2 = [null, local_list1, local_list1 ];
+ List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
+ List sendObject = new List(5);
+ sendObject[0] = local_list1;
+ sendObject[1] = sendObject;
+ sendObject[2] = local_list2;
+ sendObject[3] = sendObject;
+ sendObject[4] = local_list3;
+ remote.call(sendObject).then((var replyObject) {
+ Expect.equals(true, sendObject is List);
+ Expect.equals(true, replyObject is List);
+ Expect.equals(sendObject.length, replyObject.length);
+ Expect.equals(true, replyObject[1] === replyObject);
+ Expect.equals(true, replyObject[3] === replyObject);
+ Expect.equals(true, replyObject[0] === replyObject[2][1]);
+ Expect.equals(true, replyObject[0] === replyObject[2][2]);
+ Expect.equals(true, replyObject[2] === replyObject[4][0]);
+ Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
+ // Bigint literals are not canonicalized so do a == check.
+ Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
});
- }
+
+ // Shutdown the MessageServer.
+ remote.call(-1).then(expectAsync1((int message) {
+ Expect.equals(MessageTest.elms.length + 1, message);
+ }));
+ });
}
-class PingPongServer extends Isolate {
- PingPongServer() : super() {}
+// ---------------------------------------------------------------------------
+// tests/isolate/request_reply_test.dart
+// ---------------------------------------------------------------------------
- void main() {
- print("Starting server.");
- int count = 0;
- this.port.receive(
- (var message, SendPort replyTo) {
- if (message == -1) {
- this.port.close();
- print("Stopping server.");
- replyTo.send(count, null);
- } else {
- // Check if the received object is correct.
- if (count < MessageTest.elms.length) {
- MessageTest.VerifyObject(count, message);
- }
- // Bounce the received object back so that the sender
- // can make sure that the object matches.
- replyTo.send(message, null);
- count++;
- }
- });
- }
+void request_reply_entry() {
+ port.receive((message, SendPort replyTo) {
+ replyTo.send(message + 87);
+ port.close();
+ });
}
+void request_reply_main() {
+ test("call", () {
+ SendPort port = spawnFunction(request_reply_entry);
+ port.call(42).then(expectAsync1((message) {
+ Expect.equals(42 + 87, message);
+ }));
+ });
+
+ test("send", () {
+ SendPort port = spawnFunction(request_reply_entry);
+ ReceivePort reply = new ReceivePort();
+ port.send(99, reply.toSendPort());
+ reply.receive(expectAsync2((message, replyTo) {
+ Expect.equals(99 + 87, message);
+ reply.close();
+ }));
+ });
+}
-// ImportOptions=IsolateTestFramework
+// ---------------------------------------------------------------------------
+// tests/isolate/count_test.dart
+// ---------------------------------------------------------------------------
-class MandelIsolateTest {
+void countMessages() {
+ int count = 0;
+ port.receive((int message, SendPort replyTo) {
+ if (message == -1) {
+ Expect.equals(10, count);
+ replyTo.send(-1, null);
+ port.close();
+ return;
+ }
+ Expect.equals(count, message);
+ count++;
+ replyTo.send(message * 2, null);
+ });
+}
- static final TERMINATION_MESSAGE = -1;
- static final N = 100;
- static final ISOLATES = 20;
+void count_main() {
+ test("count 10 consecutive messages", () {
+ int count = 0;
+ SendPort remote = spawnFunction(countMessages);
+ ReceivePort local = new ReceivePort();
+ SendPort reply = local.toSendPort();
- static void testMain() {
- IsolateTestFramework.waitForDone();
+ local.receive(expectAsync2((int message, SendPort replyTo) {
+ if (message == -1) {
+ Expect.equals(11, count);
+ local.close();
+ return;
+ }
+
+ Expect.equals((count - 1) * 2, message);
+ remote.send(count++, reply);
+ if (count == 10) {
+ remote.send(-1, reply);
+ }
+ }, count: 11));
+ remote.send(count++, reply);
+ });
+}
+
+
+// ---------------------------------------------------------------------------
+// tests/isolate/mandel_isolate_test.dart
+// ---------------------------------------------------------------------------
+
+final TERMINATION_MESSAGE = -1;
+final N = 100;
+final ISOLATES = 20;
+
+mandel_main() {
+ test("Render Mandelbrot in parallel", () {
final state = new MandelbrotState();
+ state._validated.future.then(expectAsync1((result) {
+ expect(result, isTrue);
+ }));
for (int i = 0; i < Math.min(ISOLATES, N); i++) state.startClient(i);
- }
-
+ });
}
class MandelbrotState {
MandelbrotState() {
- _result = new List<List<int>>(MandelIsolateTest.N);
- _lineProcessedBy = new List<LineProcessorClient>(MandelIsolateTest.N);
+ _result = new List<List<int>>(N);
+ _lineProcessedBy = new List<LineProcessorClient>(N);
_sent = 0;
- _missing = MandelIsolateTest.N;
+ _missing = N;
+ _validated = new Completer<bool>();
}
void startClient(int id) {
- assert(_sent < MandelIsolateTest.N);
+ assert(_sent < N);
final client = new LineProcessorClient(this, id);
client.processLine(_sent++);
}
@@ -1811,119 +1458,100 @@ class MandelbrotState {
_result[y] = line;
_lineProcessedBy[y] = client;
- if (_sent != MandelIsolateTest.N) {
+ if (_sent != N) {
client.processLine(_sent++);
} else {
client.shutdown();
}
// If all lines have been computed, validate the result.
- if (--_missing == 0) _validateResult();
+ if (--_missing == 0) {
+ _printResult();
+ _validateResult();
+ }
}
void _validateResult() {
// TODO(ngeoffray): Implement this.
- IsolateTestFramework.done();
+ _validated.complete(true);
+ }
+
+ void _printResult() {
+ var output = new StringBuffer();
+ for (int i = 0; i < _result.length; i++) {
+ List<int> line = _result[i];
+ for (int j = 0; j < line.length; j++) {
+ if (line[j] < 10) output.add("0");
+ output.add(line[j]);
+ }
+ output.add("\n");
+ }
+ // print(output);
}
List<List<int>> _result;
List<LineProcessorClient> _lineProcessedBy;
int _sent;
int _missing;
-
+ Completer<bool> _validated;
}
class LineProcessorClient {
LineProcessorClient(MandelbrotState this._state, int this._id) {
- _out = new LineProcessor().spawn();
+ _port = spawnFunction(processLines);
}
void processLine(int y) {
- _out.then((SendPort p) {
- p.call(y).then((List<int> message) {
- _state.notifyProcessedLine(this, y, message);
- });
+ _port.call(y).then((List<int> message) {
+ _state.notifyProcessedLine(this, y, message);
});
}
void shutdown() {
- _out.then((SendPort p) {
- p.send(MandelIsolateTest.TERMINATION_MESSAGE, null);
- });
+ _port.send(TERMINATION_MESSAGE, null);
}
MandelbrotState _state;
int _id;
- Future<SendPort> _out;
-
+ SendPort _port;
}
+List<int> processLine(int y) {
+ double inverseN = 2.0 / N;
+ double Civ = y * inverseN - 1.0;
+ List<int> result = new List<int>(N);
+ for (int x = 0; x < N; x++) {
+ double Crv = x * inverseN - 1.5;
-class LineProcessor extends Isolate {
-
- LineProcessor() : super() { }
-
- void main() {
- this.port.receive((message, SendPort replyTo) {
- if (message == MandelIsolateTest.TERMINATION_MESSAGE) {
- assert(replyTo === null);
- this.port.close();
- } else {
- replyTo.send(_processLine(message), null);
- }
- });
- }
-
- static List<int> _processLine(int y) {
- double inverseN = 2.0 / MandelIsolateTest.N;
- double Civ = y * inverseN - 1.0;
- List<int> result = new List<int>(MandelIsolateTest.N);
- for (int x = 0; x < MandelIsolateTest.N; x++) {
- double Crv = x * inverseN - 1.5;
-
- double Zrv = Crv;
- double Ziv = Civ;
+ double Zrv = Crv;
+ double Ziv = Civ;
- double Trv = Crv * Crv;
- double Tiv = Civ * Civ;
+ double Trv = Crv * Crv;
+ double Tiv = Civ * Civ;
- int i = 49;
- do {
- Ziv = (Zrv * Ziv) + (Zrv * Ziv) + Civ;
- Zrv = Trv - Tiv + Crv;
+ int i = 49;
+ do {
+ Ziv = (Zrv * Ziv) + (Zrv * Ziv) + Civ;
+ Zrv = Trv - Tiv + Crv;
- Trv = Zrv * Zrv;
- Tiv = Ziv * Ziv;
- } while (((Trv + Tiv) <= 4.0) && (--i > 0));
+ Trv = Zrv * Zrv;
+ Tiv = Ziv * Ziv;
+ } while (((Trv + Tiv) <= 4.0) && (--i > 0));
- result[x] = i;
- }
- return result;
+ result[x] = i;
}
-
+ return result;
}
-// Dart test program for testing that isolates are spawned.
-// ImportOptions=IsolateTestFramework
-
-class IsolateNegativeTest extends Isolate {
- IsolateNegativeTest() : super();
-
- static void testMain() {
- IsolateTestFramework.waitForDone();
- new IsolateNegativeTest().spawn().then((SendPort port) {
- port.call("foo").then((message) {
- Expect.equals(true, false); // <=-------- Should fail here.
- IsolateTestFramework.done();
- });
- });
- }
-
- void main() {
- this.port.receive((ignored, replyTo) {
- replyTo.send("foo", null);
- });
- }
+void processLines() {
+ port.receive((message, SendPort replyTo) {
+ if (message == TERMINATION_MESSAGE) {
+ assert(replyTo == null);
+ port.close();
+ } else {
+ replyTo.send(processLine(message), null);
+ }
+ });
}
« no previous file with comments | « runtime/vm/isolate_test.cc ('k') | samples/chat/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698