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

Unified Diff: runtime/vm/port_test.cc

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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/port.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/port_test.cc
===================================================================
--- runtime/vm/port_test.cc (revision 3743)
+++ runtime/vm/port_test.cc (working copy)
@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
#include "platform/assert.h"
-#include "vm/message_queue.h"
+#include "vm/message.h"
#include "vm/os.h"
#include "vm/port.h"
#include "vm/unit_test.h"
@@ -29,22 +29,21 @@
};
-// Intercept the post message callback and just store a copy of the message.
-static int notify_count = 0;
-static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) {
- notify_count++;
-}
+class TestMessageHandler : public MessageHandler {
+ public:
+ TestMessageHandler() : notify_count(0) {}
+ void MessageNotify(Message::Priority priority) {
+ notify_count++;
+ }
-static void InitPortMapTest() {
- Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback);
- notify_count = 0;
-}
+ int notify_count;
+};
TEST_CASE(PortMap_CreateAndCloseOnePort) {
- InitPortMapTest();
- intptr_t port = PortMap::CreatePort();
+ TestMessageHandler handler;
+ intptr_t port = PortMap::CreatePort(&handler);
EXPECT_NE(0, port);
EXPECT(PortMapTestPeer::IsActivePort(port));
@@ -54,9 +53,9 @@
TEST_CASE(PortMap_CreateAndCloseTwoPorts) {
- InitPortMapTest();
- Dart_Port port1 = PortMap::CreatePort();
- Dart_Port port2 = PortMap::CreatePort();
+ TestMessageHandler handler;
+ Dart_Port port1 = PortMap::CreatePort(&handler);
+ Dart_Port port2 = PortMap::CreatePort(&handler);
EXPECT(PortMapTestPeer::IsActivePort(port1));
EXPECT(PortMapTestPeer::IsActivePort(port2));
@@ -74,23 +73,23 @@
TEST_CASE(PortMap_ClosePorts) {
- InitPortMapTest();
- Dart_Port port1 = PortMap::CreatePort();
- Dart_Port port2 = PortMap::CreatePort();
+ TestMessageHandler handler;
+ Dart_Port port1 = PortMap::CreatePort(&handler);
+ Dart_Port port2 = PortMap::CreatePort(&handler);
EXPECT(PortMapTestPeer::IsActivePort(port1));
EXPECT(PortMapTestPeer::IsActivePort(port2));
// Close all ports at once.
- PortMap::ClosePorts();
+ PortMap::ClosePorts(&handler);
EXPECT(!PortMapTestPeer::IsActivePort(port1));
EXPECT(!PortMapTestPeer::IsActivePort(port2));
}
TEST_CASE(PortMap_CreateManyPorts) {
- InitPortMapTest();
+ TestMessageHandler handler;
for (int i = 0; i < 32; i++) {
- Dart_Port port = PortMap::CreatePort();
+ Dart_Port port = PortMap::CreatePort(&handler);
EXPECT(PortMapTestPeer::IsActivePort(port));
PortMap::ClosePort(port);
EXPECT(!PortMapTestPeer::IsActivePort(port));
@@ -99,8 +98,8 @@
TEST_CASE(PortMap_SetLive) {
- InitPortMapTest();
- intptr_t port = PortMap::CreatePort();
+ TestMessageHandler handler;
+ intptr_t port = PortMap::CreatePort(&handler);
EXPECT_NE(0, port);
EXPECT(PortMapTestPeer::IsActivePort(port));
EXPECT(!PortMapTestPeer::IsLivePort(port));
@@ -116,26 +115,24 @@
TEST_CASE(PortMap_PostMessage) {
- InitPortMapTest();
- Dart_Port port = PortMap::CreatePort();
+ TestMessageHandler handler;
+ Dart_Port port = PortMap::CreatePort(&handler);
+ EXPECT_EQ(0, handler.notify_count);
+
EXPECT(PortMap::PostMessage(new Message(
port, 0, reinterpret_cast<uint8_t*>(strdup("msg")),
Message::kNormalPriority)));
// Check that the message notify callback was called.
- EXPECT_EQ(1, notify_count);
- PortMap::ClosePorts();
+ EXPECT_EQ(1, handler.notify_count);
+ PortMap::ClosePorts(&handler);
}
TEST_CASE(PortMap_PostMessageInvalidPort) {
- InitPortMapTest();
EXPECT(!PortMap::PostMessage(new Message(
0, 0, reinterpret_cast<uint8_t*>(strdup("msg")),
Message::kNormalPriority)));
-
- // Check that the message notifycallback was not called.
- EXPECT_STREQ(0, notify_count);
}
@@ -157,19 +154,19 @@
static Message* NextMessage() {
Isolate* isolate = Isolate::Current();
- Message* result = isolate->message_queue()->Dequeue(0);
+ Message* result = isolate->message_handler()->queue()->Dequeue(0);
return result;
}
void ThreadedPort_start(uword parameter) {
- // We only need an isolate here because the MutexLocker in
- // PortMap::CreatePort expects it, we don't need to initialize
- // the isolate as it does not run any dart code.
- Dart::CreateIsolate(NULL);
+ // TODO(turnidge): We only use the isolate to get access to its
+ // message handler. I should rewrite this test to use a
+ // TestMessageHandler instead.
+ Isolate* isolate = Dart::CreateIsolate(NULL);
intptr_t remote = parameter;
- intptr_t local = PortMap::CreatePort();
+ intptr_t local = PortMap::CreatePort(isolate->message_handler());
PortMap::PostMessage(new Message(
remote, 0, AllocIntData(local), Message::kNormalPriority));
@@ -194,7 +191,7 @@
TEST_CASE(ThreadedPort) {
- intptr_t local = PortMap::CreatePort();
+ intptr_t local = PortMap::CreatePort(Isolate::Current()->message_handler());
Thread* thr = new Thread(ThreadedPort_start, local);
EXPECT(thr != NULL);
« no previous file with comments | « runtime/vm/port.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698