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

Side by Side Diff: runtime/vm/snapshot_test.dart

Issue 9652001: SendPort + ReceivePort changes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | samples/isolate_html/IsolateSample.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #import("dart:isolate"); 5 #import("dart:isolate");
6 6
7 class Fields { 7 class Fields {
8 Fields(int i, int j) : fld1 = i, fld2 = j, fld5 = true {} 8 Fields(int i, int j) : fld1 = i, fld2 = j, fld5 = true {}
9 int fld1; 9 int fld1;
10 final int fld2; 10 final int fld2;
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 class IsolateExitHandlerTest extends Isolate { 1232 class IsolateExitHandlerTest extends Isolate {
1233 static int counter; 1233 static int counter;
1234 1234
1235 IsolateExitHandlerTest() : super.heavy(); 1235 IsolateExitHandlerTest() : super.heavy();
1236 1236
1237 static void testMain() { 1237 static void testMain() {
1238 Isolate.setExitHandler(() { 1238 Isolate.setExitHandler(() {
1239 Expect.equals(1, counter); 1239 Expect.equals(1, counter);
1240 }); 1240 });
1241 new IsolateExitHandlerTest().spawn().then((SendPort p) { 1241 new IsolateExitHandlerTest().spawn().then((SendPort p) {
1242 p.call("bar").receive((msg, replyTo) { 1242 p.call("bar").then((msg) {
1243 counter++; 1243 counter++;
1244 }); 1244 });
1245 }); 1245 });
1246 } 1246 }
1247 1247
1248 void main() { 1248 void main() {
1249 bool encounteredException = false; 1249 bool encounteredException = false;
1250 try { 1250 try {
1251 Isolate.setExitHandler(() { 1251 Isolate.setExitHandler(() {
1252 Expect.equals(true, false); 1252 Expect.equals(true, false);
(...skipping 21 matching lines...) Expand all
1274 class SpawnTest { 1274 class SpawnTest {
1275 1275
1276 static void testMain() { 1276 static void testMain() {
1277 spawnIsolate(); 1277 spawnIsolate();
1278 } 1278 }
1279 1279
1280 static void spawnIsolate() { 1280 static void spawnIsolate() {
1281 IsolateTestFramework.waitForDone(); 1281 IsolateTestFramework.waitForDone();
1282 SpawnedIsolate isolate = new SpawnedIsolate(); 1282 SpawnedIsolate isolate = new SpawnedIsolate();
1283 isolate.spawn().then((SendPort port) { 1283 isolate.spawn().then((SendPort port) {
1284 port.call(42).receive((message, replyTo) { 1284 port.call(42).then((message) {
1285 Expect.equals(42, message); 1285 Expect.equals(42, message);
1286 IsolateTestFramework.done(); 1286 IsolateTestFramework.done();
1287 }); 1287 });
1288 }); 1288 });
1289 } 1289 }
1290 } 1290 }
1291 1291
1292 class SpawnedIsolate extends Isolate { 1292 class SpawnedIsolate extends Isolate {
1293 1293
1294 SpawnedIsolate() : super() { } 1294 SpawnedIsolate() : super() { }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 this.port.receive((ignoredMessage, reply) { 1332 this.port.receive((ignoredMessage, reply) {
1333 reply.send(field, null); 1333 reply.send(field, null);
1334 this.port.close(); 1334 this.port.close();
1335 IsolateTestFramework.done(); 1335 IsolateTestFramework.done();
1336 }); 1336 });
1337 } 1337 }
1338 1338
1339 static void testMain() { 1339 static void testMain() {
1340 ConstructorTest test = new ConstructorTest(); 1340 ConstructorTest test = new ConstructorTest();
1341 test.spawn().then((SendPort port) { 1341 test.spawn().then((SendPort port) {
1342 ReceivePort reply = port.call("ignored"); 1342 port.call("ignored").then((message) {
1343 reply.receive((message, replyPort) {
1344 Expect.equals(499, message); 1343 Expect.equals(499, message);
1345 }); 1344 });
1346 }); 1345 });
1347 } 1346 }
1348 } 1347 }
1349 1348
1350 // Dart test program for testing isolate communication with 1349 // Dart test program for testing isolate communication with
1351 // simple messages. 1350 // simple messages.
1352 // ImportOptions=IsolateTestFramework 1351 // ImportOptions=IsolateTestFramework
1353 1352
(...skipping 23 matching lines...) Expand all
1377 1376
1378 // --------------------------------------------------------------------------- 1377 // ---------------------------------------------------------------------------
1379 // Request-reply test. 1378 // Request-reply test.
1380 // --------------------------------------------------------------------------- 1379 // ---------------------------------------------------------------------------
1381 1380
1382 class RequestReplyTest { 1381 class RequestReplyTest {
1383 1382
1384 static void test() { 1383 static void test() {
1385 testCall(); 1384 testCall();
1386 testSend(); 1385 testSend();
1387 testSendSingleShot();
1388 } 1386 }
1389 1387
1390 static void testCall() { 1388 static void testCall() {
1391 IsolateTest.waitForDone(); 1389 IsolateTest.waitForDone();
1392 new RequestReplyIsolate().spawn().then((SendPort port) { 1390 new RequestReplyIsolate().spawn().then((SendPort port) {
1393 port.call(42).receive((message, replyTo) { 1391 port.call(42).then((message) {
1394 Expect.equals(42 + 87, message); 1392 Expect.equals(42 + 87, message);
1395 IsolateTest.done(); 1393 IsolateTest.done();
1396 }); 1394 });
1397 }); 1395 });
1398 } 1396 }
1399 1397
1400 static void testSend() { 1398 static void testSend() {
1401 IsolateTest.waitForDone(); 1399 IsolateTest.waitForDone();
1402 new RequestReplyIsolate().spawn().then((SendPort port) { 1400 new RequestReplyIsolate().spawn().then((SendPort port) {
1403 ReceivePort reply = new ReceivePort(); 1401 ReceivePort reply = new ReceivePort();
1404 port.send(99, reply.toSendPort()); 1402 port.send(99, reply.toSendPort());
1405 reply.receive((message, replyTo) { 1403 reply.receive((message, replyTo) {
1406 Expect.equals(99 + 87, message); 1404 Expect.equals(99 + 87, message);
1407 reply.close(); 1405 reply.close();
1408 IsolateTest.done(); 1406 IsolateTest.done();
1409 }); 1407 });
1410 }); 1408 });
1411 } 1409 }
1412
1413 static void testSendSingleShot() {
1414 IsolateTest.waitForDone();
1415 new RequestReplyIsolate().spawn().then((SendPort port) {
1416 ReceivePort reply = new ReceivePort.singleShot();
1417 port.send(99, reply.toSendPort());
1418 reply.receive((message, replyTo) {
1419 Expect.equals(99 + 87, message);
1420 IsolateTest.done();
1421 });
1422 });
1423 }
1424
1425 } 1410 }
1426 1411
1427 1412
1428 class RequestReplyIsolate extends Isolate { 1413 class RequestReplyIsolate extends Isolate {
1429 1414
1430 RequestReplyIsolate() : super() { } 1415 RequestReplyIsolate() : super() { }
1431 1416
1432 void main() { 1417 void main() {
1433 this.port.receive((message, SendPort replyTo) { 1418 this.port.receive((message, SendPort replyTo) {
1434 replyTo.send(message + 87, null); 1419 replyTo.send(message + 87, null);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 1502
1518 static String state; 1503 static String state;
1519 1504
1520 static void test() { 1505 static void test() {
1521 IsolateTest.waitForDone(); 1506 IsolateTest.waitForDone();
1522 Expect.equals(null, state); 1507 Expect.equals(null, state);
1523 state = "foo"; 1508 state = "foo";
1524 Expect.equals("foo", state); 1509 Expect.equals("foo", state);
1525 1510
1526 new StaticStateIsolate().spawn().then((SendPort remote) { 1511 new StaticStateIsolate().spawn().then((SendPort remote) {
1527 remote.call("bar").receive((reply, replyTo) { 1512 remote.call("bar").then((reply) {
1528 Expect.equals("foo", state); 1513 Expect.equals("foo", state);
1529 Expect.equals(null, reply); 1514 Expect.equals(null, reply);
1530 1515
1531 state = "baz"; 1516 state = "baz";
1532 remote.call("exit").receive((reply, replyTo) { 1517 remote.call("exit").then((reply) {
1533 Expect.equals("baz", state); 1518 Expect.equals("baz", state);
1534 Expect.equals("bar", reply); 1519 Expect.equals("bar", reply);
1535 IsolateTest.done(); 1520 IsolateTest.done();
1536 }); 1521 });
1537 }); 1522 });
1538 }); 1523 });
1539 } 1524 }
1540 1525
1541 } 1526 }
1542 1527
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 IsolateTestFramework.waitForDone(); 1568 IsolateTestFramework.waitForDone();
1584 new LogIsolate().spawn().then((SendPort remote) { 1569 new LogIsolate().spawn().then((SendPort remote) {
1585 1570
1586 remote.send(1, null); 1571 remote.send(1, null);
1587 remote.send("Hello", null); 1572 remote.send("Hello", null);
1588 remote.send("World", null); 1573 remote.send("World", null);
1589 remote.send(const [null, 1, 2, 3, 4], null); 1574 remote.send(const [null, 1, 2, 3, 4], null);
1590 remote.send(const [1, 2.0, true, false, 0xffffffffff], null); 1575 remote.send(const [1, 2.0, true, false, 0xffffffffff], null);
1591 remote.send(const ["Hello", "World", 0xffffffffff], null); 1576 remote.send(const ["Hello", "World", 0xffffffffff], null);
1592 // Shutdown the LogRunner. 1577 // Shutdown the LogRunner.
1593 remote.call(-1).receive((int message, SendPort replyTo) { 1578 remote.call(-1).then((int message) {
1594 Expect.equals(6, message); 1579 Expect.equals(6, message);
1595 }); 1580 });
1596 IsolateTestFramework.done(); 1581 IsolateTestFramework.done();
1597 }); 1582 });
1598 } 1583 }
1599 } 1584 }
1600 1585
1601 1586
1602 class LogIsolate extends Isolate { 1587 class LogIsolate extends Isolate {
1603 LogIsolate() : super() { } 1588 LogIsolate() : super() { }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 } 1702 }
1718 1703
1719 class PingPongClient { 1704 class PingPongClient {
1720 static void test() { 1705 static void test() {
1721 IsolateTestFramework.waitForDone(); 1706 IsolateTestFramework.waitForDone();
1722 new PingPongServer().spawn().then((SendPort remote) { 1707 new PingPongServer().spawn().then((SendPort remote) {
1723 1708
1724 // Send objects and receive them back. 1709 // Send objects and receive them back.
1725 for (int i = 0; i < MessageTest.elms.length; i++) { 1710 for (int i = 0; i < MessageTest.elms.length; i++) {
1726 var sentObject = MessageTest.elms[i]; 1711 var sentObject = MessageTest.elms[i];
1727 remote.call(sentObject).receive( 1712 remote.call(sentObject).then((var receivedObject) {
1728 (var receivedObject, SendPort replyTo) { 1713 MessageTest.VerifyObject(i, receivedObject);
1729 MessageTest.VerifyObject(i, receivedObject); 1714 });
1730 });
1731 } 1715 }
1732 1716
1733 // Send recursive objects and receive them back. 1717 // Send recursive objects and receive them back.
1734 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; 1718 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
1735 List local_list2 = [null, local_list1, local_list1 ]; 1719 List local_list2 = [null, local_list1, local_list1 ];
1736 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; 1720 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
1737 List sendObject = new List(5); 1721 List sendObject = new List(5);
1738 sendObject[0] = local_list1; 1722 sendObject[0] = local_list1;
1739 sendObject[1] = sendObject; 1723 sendObject[1] = sendObject;
1740 sendObject[2] = local_list2; 1724 sendObject[2] = local_list2;
1741 sendObject[3] = sendObject; 1725 sendObject[3] = sendObject;
1742 sendObject[4] = local_list3; 1726 sendObject[4] = local_list3;
1743 remote.call(sendObject).receive( 1727 remote.call(sendObject).then((var replyObject) {
1744 (var replyObject, SendPort replyTo) { 1728 Expect.equals(true, sendObject is List);
1745 Expect.equals(true, sendObject is List); 1729 Expect.equals(true, replyObject is List);
1746 Expect.equals(true, replyObject is List); 1730 Expect.equals(sendObject.length, replyObject.length);
1747 Expect.equals(sendObject.length, replyObject.length); 1731 Expect.equals(true, replyObject[1] === replyObject);
1748 Expect.equals(true, replyObject[1] === replyObject); 1732 Expect.equals(true, replyObject[3] === replyObject);
1749 Expect.equals(true, replyObject[3] === replyObject); 1733 Expect.equals(true, replyObject[0] === replyObject[2][1]);
1750 Expect.equals(true, replyObject[0] === replyObject[2][1]); 1734 Expect.equals(true, replyObject[0] === replyObject[2][2]);
1751 Expect.equals(true, replyObject[0] === replyObject[2][2]); 1735 Expect.equals(true, replyObject[2] === replyObject[4][0]);
1752 Expect.equals(true, replyObject[2] === replyObject[4][0]); 1736 Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
1753 Expect.equals(true, replyObject[0][0] === replyObject[0][2]); 1737 // Bigint literals are not canonicalized so do a == check.
1754 // Bigint literals are not canonicalized so do a == check. 1738 Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
1755 Expect.equals(true, replyObject[0][3] == replyObject[4][4]); 1739 });
1756 });
1757 1740
1758 // Shutdown the MessageServer. 1741 // Shutdown the MessageServer.
1759 remote.call(-1).receive( 1742 remote.call(-1).then((int message) {
1760 (int message, SendPort replyTo) { 1743 Expect.equals(MessageTest.elms.length + 1, message);
1761 Expect.equals(MessageTest.elms.length + 1, message); 1744 IsolateTestFramework.done();
1762 IsolateTestFramework.done(); 1745 });
1763 });
1764 }); 1746 });
1765 } 1747 }
1766 } 1748 }
1767 1749
1768 class PingPongServer extends Isolate { 1750 class PingPongServer extends Isolate {
1769 PingPongServer() : super() {} 1751 PingPongServer() : super() {}
1770 1752
1771 void main() { 1753 void main() {
1772 print("Starting server."); 1754 print("Starting server.");
1773 int count = 0; 1755 int count = 0;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 1835
1854 1836
1855 class LineProcessorClient { 1837 class LineProcessorClient {
1856 1838
1857 LineProcessorClient(MandelbrotState this._state, int this._id) { 1839 LineProcessorClient(MandelbrotState this._state, int this._id) {
1858 _out = new LineProcessor().spawn(); 1840 _out = new LineProcessor().spawn();
1859 } 1841 }
1860 1842
1861 void processLine(int y) { 1843 void processLine(int y) {
1862 _out.then((SendPort p) { 1844 _out.then((SendPort p) {
1863 p.call(y).receive((List<int> message, SendPort replyTo) { 1845 p.call(y).then((List<int> message) {
1864 _state.notifyProcessedLine(this, y, message); 1846 _state.notifyProcessedLine(this, y, message);
1865 }); 1847 });
1866 }); 1848 });
1867 } 1849 }
1868 1850
1869 void shutdown() { 1851 void shutdown() {
1870 _out.then((SendPort p) { 1852 _out.then((SendPort p) {
1871 p.send(MandelIsolateTest.TERMINATION_MESSAGE, null); 1853 p.send(MandelIsolateTest.TERMINATION_MESSAGE, null);
1872 }); 1854 });
1873 } 1855 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 1907
1926 // Dart test program for testing that isolates are spawned. 1908 // Dart test program for testing that isolates are spawned.
1927 // ImportOptions=IsolateTestFramework 1909 // ImportOptions=IsolateTestFramework
1928 1910
1929 class IsolateNegativeTest extends Isolate { 1911 class IsolateNegativeTest extends Isolate {
1930 IsolateNegativeTest() : super(); 1912 IsolateNegativeTest() : super();
1931 1913
1932 static void testMain() { 1914 static void testMain() {
1933 IsolateTestFramework.waitForDone(); 1915 IsolateTestFramework.waitForDone();
1934 new IsolateNegativeTest().spawn().then((SendPort port) { 1916 new IsolateNegativeTest().spawn().then((SendPort port) {
1935 port.call("foo").receive((message, replyTo) { 1917 port.call("foo").then((message) {
1936 Expect.equals(true, false); // <=-------- Should fail here. 1918 Expect.equals(true, false); // <=-------- Should fail here.
1937 IsolateTestFramework.done(); 1919 IsolateTestFramework.done();
1938 }); 1920 });
1939 }); 1921 });
1940 } 1922 }
1941 1923
1942 void main() { 1924 void main() {
1943 this.port.receive((ignored, replyTo) { 1925 this.port.receive((ignored, replyTo) {
1944 replyTo.send("foo", null); 1926 replyTo.send("foo", null);
1945 }); 1927 });
1946 } 1928 }
1947 } 1929 }
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | samples/isolate_html/IsolateSample.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698