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

Side by Side Diff: runtime/vm/port_test.cc

Issue 456983002: Refactor isolate startup code in preparation for making isolate spawning more truly non-blocking. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 4 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/port.cc ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/lockers.h" 6 #include "vm/lockers.h"
7 #include "vm/message_handler.h" 7 #include "vm/message_handler.h"
8 #include "vm/os.h" 8 #include "vm/os.h"
9 #include "vm/port.h" 9 #include "vm/port.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 // Provides private access to PortMap for testing. 14 // Provides private access to PortMap for testing.
15 class PortMapTestPeer { 15 class PortMapTestPeer {
16 public: 16 public:
17 static bool IsActivePort(Dart_Port port) { 17 static bool IsActivePort(Dart_Port port) {
18 MutexLocker ml(PortMap::mutex_); 18 MutexLocker ml(PortMap::mutex_);
19 return (PortMap::FindPort(port) >= 0); 19 return (PortMap::FindPort(port) >= 0);
20 } 20 }
21 21
22 static bool IsLivePort(Dart_Port port) { 22 static bool IsLivePort(Dart_Port port) {
23 MutexLocker ml(PortMap::mutex_); 23 MutexLocker ml(PortMap::mutex_);
24 intptr_t index = PortMap::FindPort(port); 24 intptr_t index = PortMap::FindPort(port);
25 if (index < 0) { 25 if (index < 0) {
26 return false; 26 return false;
27 } 27 }
28 return PortMap::map_[index].live; 28 return PortMap::map_[index].state == PortMap::kLivePort;
29 } 29 }
30 }; 30 };
31 31
32 32
33 class PortTestMessageHandler : public MessageHandler { 33 class PortTestMessageHandler : public MessageHandler {
34 public: 34 public:
35 PortTestMessageHandler() : notify_count(0) {} 35 PortTestMessageHandler() : notify_count(0) {}
36 36
37 void MessageNotify(Message::Priority priority) { 37 void MessageNotify(Message::Priority priority) {
38 notify_count++; 38 notify_count++;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 PortTestMessageHandler handler; 93 PortTestMessageHandler handler;
94 for (int i = 0; i < 32; i++) { 94 for (int i = 0; i < 32; i++) {
95 Dart_Port port = PortMap::CreatePort(&handler); 95 Dart_Port port = PortMap::CreatePort(&handler);
96 EXPECT(PortMapTestPeer::IsActivePort(port)); 96 EXPECT(PortMapTestPeer::IsActivePort(port));
97 PortMap::ClosePort(port); 97 PortMap::ClosePort(port);
98 EXPECT(!PortMapTestPeer::IsActivePort(port)); 98 EXPECT(!PortMapTestPeer::IsActivePort(port));
99 } 99 }
100 } 100 }
101 101
102 102
103 TEST_CASE(PortMap_SetLive) { 103 TEST_CASE(PortMap_SetPortState) {
104 PortTestMessageHandler handler; 104 PortTestMessageHandler handler;
105
106 // Regular port.
105 Dart_Port port = PortMap::CreatePort(&handler); 107 Dart_Port port = PortMap::CreatePort(&handler);
106 EXPECT_NE(0, port); 108 EXPECT_NE(0, port);
107 EXPECT(PortMapTestPeer::IsActivePort(port)); 109 EXPECT(PortMapTestPeer::IsActivePort(port));
108 EXPECT(!PortMapTestPeer::IsLivePort(port)); 110 EXPECT(!PortMapTestPeer::IsLivePort(port));
109 111
110 PortMap::SetLive(port); 112 PortMap::SetPortState(port, PortMap::kLivePort);
111 EXPECT(PortMapTestPeer::IsActivePort(port)); 113 EXPECT(PortMapTestPeer::IsActivePort(port));
112 EXPECT(PortMapTestPeer::IsLivePort(port)); 114 EXPECT(PortMapTestPeer::IsLivePort(port));
113 115
114 PortMap::ClosePort(port); 116 PortMap::ClosePort(port);
115 EXPECT(!PortMapTestPeer::IsActivePort(port)); 117 EXPECT(!PortMapTestPeer::IsActivePort(port));
116 EXPECT(!PortMapTestPeer::IsLivePort(port)); 118 EXPECT(!PortMapTestPeer::IsLivePort(port));
119
120 // Control port.
121 port = PortMap::CreatePort(&handler);
122 EXPECT_NE(0, port);
123 EXPECT(PortMapTestPeer::IsActivePort(port));
124 EXPECT(!PortMapTestPeer::IsLivePort(port));
125
126 PortMap::SetPortState(port, PortMap::kControlPort);
127 EXPECT(PortMapTestPeer::IsActivePort(port));
128 EXPECT(!PortMapTestPeer::IsLivePort(port));
129
130 PortMap::ClosePort(port);
131 EXPECT(!PortMapTestPeer::IsActivePort(port));
132 EXPECT(!PortMapTestPeer::IsLivePort(port));
117 } 133 }
118 134
119 135
120 TEST_CASE(PortMap_PostMessage) { 136 TEST_CASE(PortMap_PostMessage) {
121 PortTestMessageHandler handler; 137 PortTestMessageHandler handler;
122 Dart_Port port = PortMap::CreatePort(&handler); 138 Dart_Port port = PortMap::CreatePort(&handler);
123 EXPECT_EQ(0, handler.notify_count); 139 EXPECT_EQ(0, handler.notify_count);
124 140
125 const char* message = "msg"; 141 const char* message = "msg";
126 intptr_t message_len = strlen(message) + 1; 142 intptr_t message_len = strlen(message) + 1;
(...skipping 16 matching lines...) Expand all
143 159
144 const char* message = "msg"; 160 const char* message = "msg";
145 intptr_t message_len = strlen(message) + 1; 161 intptr_t message_len = strlen(message) + 1;
146 162
147 EXPECT(!PortMap::PostMessage(new Message( 163 EXPECT(!PortMap::PostMessage(new Message(
148 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len, 164 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len,
149 Message::kNormalPriority))); 165 Message::kNormalPriority)));
150 } 166 }
151 167
152 } // namespace dart 168 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/port.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698