mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:59:47 +00:00
[vm] Remove PortMap state concept, expose isolate main control ports in service
TEST=ci Change-Id: I18281c5ac05272596fe46baa75e8ec930f6099d4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318925 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
parent
1b8870bbb1
commit
0d44ee8452
|
@ -189,8 +189,7 @@ VM_UNIT_TEST_CASE(FfiCallbackMetadata_CreateAsyncFfiCallback) {
|
|||
|
||||
EXPECT_EQ(isolate->ffi_callback_list_head(), nullptr);
|
||||
|
||||
auto port1 =
|
||||
PortMap::CreatePort(new FakeMessageHandler(), PortMap::kLivePort);
|
||||
auto port1 = PortMap::CreatePort(new FakeMessageHandler());
|
||||
tramp1 = isolate->CreateAsyncFfiCallback(zone, func, port1);
|
||||
EXPECT_NE(tramp1, 0u);
|
||||
|
||||
|
@ -211,8 +210,7 @@ VM_UNIT_TEST_CASE(FfiCallbackMetadata_CreateAsyncFfiCallback) {
|
|||
EXPECT_EQ(e1->list_next(), nullptr);
|
||||
}
|
||||
|
||||
auto port2 =
|
||||
PortMap::CreatePort(new FakeMessageHandler(), PortMap::kLivePort);
|
||||
auto port2 = PortMap::CreatePort(new FakeMessageHandler());
|
||||
tramp2 = isolate->CreateAsyncFfiCallback(zone, func, port2);
|
||||
EXPECT_NE(tramp2, 0u);
|
||||
EXPECT_NE(tramp2, tramp1);
|
||||
|
@ -273,7 +271,7 @@ ISOLATE_UNIT_TEST_CASE(FfiCallbackMetadata_TrampolineRecycling) {
|
|||
const Code& code = Code::Handle(func.EnsureHasCode());
|
||||
EXPECT(!code.IsNull());
|
||||
|
||||
auto port = PortMap::CreatePort(new FakeMessageHandler(), PortMap::kLivePort);
|
||||
auto port = PortMap::CreatePort(new FakeMessageHandler());
|
||||
FfiCallbackMetadata::Metadata* list_head = nullptr;
|
||||
|
||||
// Allocate and free one callback at a time, and verify that we don't reuse
|
||||
|
@ -458,8 +456,7 @@ static void RunBigRandomMultithreadedTest(uint64_t seed) {
|
|||
sync_func, &list_head);
|
||||
} else {
|
||||
// 50% chance of creating an async callback.
|
||||
tramp.port =
|
||||
PortMap::CreatePort(new FakeMessageHandler(), PortMap::kLivePort);
|
||||
tramp.port = PortMap::CreatePort(new FakeMessageHandler());
|
||||
tramp.tramp = fcm->CreateAsyncFfiCallback(
|
||||
isolate, thread->zone(), async_func, tramp.port, &list_head);
|
||||
}
|
||||
|
|
|
@ -540,7 +540,7 @@ VM_UNIT_TEST_CASE(CleanupBequestNeverReceived) {
|
|||
EXPECT_EQ(parent, Dart_CurrentIsolate());
|
||||
{
|
||||
SendAndExitMessagesHandler handler(Isolate::Current());
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
EXPECT_EQ(PortMap::GetIsolate(port_id), Isolate::Current());
|
||||
Dart_ExitIsolate();
|
||||
|
||||
|
@ -570,7 +570,7 @@ VM_UNIT_TEST_CASE(ReceivesSendAndExitMessage) {
|
|||
Dart_Isolate parent = TestCase::CreateTestIsolate("parent");
|
||||
EXPECT_EQ(parent, Dart_CurrentIsolate());
|
||||
SendAndExitMessagesHandler handler(Isolate::Current());
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
EXPECT_EQ(PortMap::GetIsolate(port_id), Isolate::Current());
|
||||
Dart_ExitIsolate();
|
||||
|
||||
|
|
|
@ -1791,8 +1791,7 @@ Isolate* Isolate::InitIsolate(const char* name_prefix,
|
|||
// Setup the isolate message handler.
|
||||
result->message_handler_ = new IsolateMessageHandler(result);
|
||||
|
||||
result->set_main_port(
|
||||
PortMap::CreatePort(result->message_handler(), PortMap::kControlPort));
|
||||
result->set_main_port(PortMap::CreatePort(result->message_handler()));
|
||||
#if defined(DEBUG)
|
||||
// Verify that we are never reusing a live origin id.
|
||||
VerifyOriginId id_verifier(result->main_port());
|
||||
|
@ -3640,8 +3639,7 @@ bool Isolate::HasLivePorts() {
|
|||
}
|
||||
|
||||
ReceivePortPtr Isolate::CreateReceivePort(const String& debug_name) {
|
||||
Dart_Port port_id =
|
||||
PortMap::CreatePort(message_handler(), PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(message_handler());
|
||||
++open_ports_;
|
||||
++open_ports_keepalive_;
|
||||
return ReceivePort::New(port_id, debug_name);
|
||||
|
|
|
@ -186,7 +186,7 @@ ISOLATE_UNIT_TEST_CASE(Isolate_Ports) {
|
|||
EXPECT(port.is_open());
|
||||
EXPECT(port.keep_isolate_alive());
|
||||
EXPECT(port.Id() != ILLEGAL_PORT);
|
||||
EXPECT(PortMap::IsLivePort(port.Id()));
|
||||
EXPECT(PortMap::PortExists(port.Id()));
|
||||
EXPECT(isolate->HasLivePorts());
|
||||
|
||||
// Make port not keep isolate alive.
|
||||
|
@ -218,7 +218,7 @@ ISOLATE_UNIT_TEST_CASE(Isolate_Ports) {
|
|||
// Make port.
|
||||
port = isolate->CreateReceivePort(String::null_string());
|
||||
EXPECT_NE(0, port.Id());
|
||||
EXPECT(PortMap::IsLivePort(port.Id()));
|
||||
EXPECT(PortMap::PortExists(port.Id()));
|
||||
EXPECT(isolate->HasLivePorts());
|
||||
|
||||
// Make port not keep isolate alive.
|
||||
|
|
|
@ -229,9 +229,9 @@ VM_UNIT_TEST_CASE(MessageHandler_CloseAllPorts) {
|
|||
VM_UNIT_TEST_CASE(MessageHandler_HandleNextMessage) {
|
||||
TestMessageHandler handler;
|
||||
MessageHandlerTestPeer handler_peer(&handler);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler);
|
||||
handler_peer.PostMessage(BlankMessage(port1, Message::kNormalPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port2, Message::kOOBPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port2, Message::kNormalPriority));
|
||||
|
@ -255,9 +255,9 @@ VM_UNIT_TEST_CASE(MessageHandler_HandleNextMessage_ProcessOOBAfterError) {
|
|||
};
|
||||
handler.set_results(results);
|
||||
MessageHandlerTestPeer handler_peer(&handler);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler);
|
||||
handler_peer.PostMessage(BlankMessage(port1, Message::kNormalPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port2, Message::kOOBPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port3, Message::kOOBPriority));
|
||||
|
@ -282,10 +282,10 @@ VM_UNIT_TEST_CASE(MessageHandler_HandleNextMessage_Shutdown) {
|
|||
};
|
||||
handler.set_results(results);
|
||||
MessageHandlerTestPeer handler_peer(&handler);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port4 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port4 = PortMap::CreatePort(&handler);
|
||||
handler_peer.PostMessage(BlankMessage(port1, Message::kNormalPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port2, Message::kOOBPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port3, Message::kOOBPriority));
|
||||
|
@ -308,10 +308,10 @@ VM_UNIT_TEST_CASE(MessageHandler_HandleNextMessage_Shutdown) {
|
|||
VM_UNIT_TEST_CASE(MessageHandler_HandleOOBMessages) {
|
||||
TestMessageHandler handler;
|
||||
MessageHandlerTestPeer handler_peer(&handler);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port4 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port3 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port4 = PortMap::CreatePort(&handler);
|
||||
handler_peer.PostMessage(BlankMessage(port1, Message::kNormalPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port2, Message::kNormalPriority));
|
||||
handler_peer.PostMessage(BlankMessage(port3, Message::kOOBPriority));
|
||||
|
@ -349,11 +349,13 @@ VM_UNIT_TEST_CASE(MessageHandler_Run) {
|
|||
ThreadPool pool;
|
||||
MessageHandlerTestPeer handler_peer(&handler);
|
||||
|
||||
EXPECT(!PortMap::HasLivePorts(&handler));
|
||||
|
||||
handler.Run(&pool, TestStartFunction, TestEndFunction,
|
||||
reinterpret_cast<uword>(&handler));
|
||||
Dart_Port port = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
|
||||
EXPECT(!PortMap::HasPorts(&handler));
|
||||
Dart_Port port = PortMap::CreatePort(&handler);
|
||||
EXPECT(PortMap::HasPorts(&handler));
|
||||
|
||||
handler_peer.PostMessage(BlankMessage(port, Message::kNormalPriority));
|
||||
|
||||
// Wait for the first message to be handled.
|
||||
|
@ -372,7 +374,7 @@ VM_UNIT_TEST_CASE(MessageHandler_Run) {
|
|||
// Start a thread which sends more messages.
|
||||
Dart_Port ports[10];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ports[i] = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
ports[i] = PortMap::CreatePort(&handler);
|
||||
}
|
||||
ThreadStartInfo info;
|
||||
info.handler = &handler;
|
||||
|
@ -401,7 +403,7 @@ VM_UNIT_TEST_CASE(MessageHandler_Run) {
|
|||
PortMap::ClosePort(ports[i]);
|
||||
}
|
||||
PortMap::ClosePort(port);
|
||||
EXPECT(!PortMap::HasLivePorts(&handler));
|
||||
EXPECT(!PortMap::HasPorts(&handler));
|
||||
|
||||
// Must join the thread or the VM shutdown is racing with any VM state the
|
||||
// thread touched.
|
||||
|
|
|
@ -89,7 +89,7 @@ DART_EXPORT Dart_Port Dart_NewNativePort(const char* name,
|
|||
IsolateLeaveScope saver(Isolate::Current());
|
||||
|
||||
NativeMessageHandler* nmh = new NativeMessageHandler(name, handler);
|
||||
Dart_Port port_id = PortMap::CreatePort(nmh, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(nmh);
|
||||
if (port_id != ILLEGAL_PORT) {
|
||||
if (!nmh->Run(Dart::thread_pool(), nullptr, nullptr, 0)) {
|
||||
PortMap::ClosePort(port_id);
|
||||
|
|
|
@ -21,18 +21,6 @@ Mutex* PortMap::mutex_ = nullptr;
|
|||
PortSet<PortMap::Entry>* PortMap::ports_ = nullptr;
|
||||
Random* PortMap::prng_ = nullptr;
|
||||
|
||||
const char* PortMap::PortStateString(PortState kind) {
|
||||
switch (kind) {
|
||||
case kLivePort:
|
||||
return "live";
|
||||
case kControlPort:
|
||||
return "control";
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
Dart_Port PortMap::AllocatePort() {
|
||||
Dart_Port result;
|
||||
|
||||
|
@ -64,8 +52,7 @@ Dart_Port PortMap::AllocatePort() {
|
|||
return result;
|
||||
}
|
||||
|
||||
Dart_Port PortMap::CreatePort(MessageHandler* handler,
|
||||
PortState initial_state) {
|
||||
Dart_Port PortMap::CreatePort(MessageHandler* handler) {
|
||||
ASSERT(handler != nullptr);
|
||||
MutexLocker ml(mutex_);
|
||||
if (ports_ == nullptr) {
|
||||
|
@ -87,7 +74,6 @@ Dart_Port PortMap::CreatePort(MessageHandler* handler,
|
|||
Entry entry;
|
||||
entry.port = port;
|
||||
entry.handler = handler;
|
||||
entry.state = initial_state;
|
||||
ports_->Insert(entry);
|
||||
|
||||
if (FLAG_trace_isolates) {
|
||||
|
@ -181,20 +167,16 @@ bool PortMap::PostMessage(std::unique_ptr<Message> message,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PortMap::IsLivePort(Dart_Port id) {
|
||||
#if defined(TESTING)
|
||||
bool PortMap::PortExists(Dart_Port id) {
|
||||
MutexLocker ml(mutex_);
|
||||
if (ports_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto it = ports_->TryLookup(id);
|
||||
if (it == ports_->end()) {
|
||||
// Port does not exist.
|
||||
return false;
|
||||
}
|
||||
|
||||
PortState state = (*it).state;
|
||||
return (state == kLivePort || state == kControlPort);
|
||||
return it != ports_->end();
|
||||
}
|
||||
#endif // defined(TESTING)
|
||||
|
||||
Isolate* PortMap::GetIsolate(Dart_Port id) {
|
||||
MutexLocker ml(mutex_);
|
||||
|
@ -232,7 +214,7 @@ Dart_Port PortMap::GetOriginId(Dart_Port id) {
|
|||
}
|
||||
|
||||
#if defined(TESTING)
|
||||
bool PortMap::HasLivePorts(MessageHandler* handler) {
|
||||
bool PortMap::HasPorts(MessageHandler* handler) {
|
||||
MutexLocker ml(mutex_);
|
||||
if (ports_ == nullptr) {
|
||||
return false;
|
||||
|
@ -309,13 +291,11 @@ void PortMap::PrintPortsForMessageHandler(MessageHandler* handler,
|
|||
}
|
||||
for (auto& entry : *ports_) {
|
||||
if (entry.handler == handler) {
|
||||
if (entry.state == kLivePort) {
|
||||
JSONObject port(&ports);
|
||||
port.AddProperty("type", "_Port");
|
||||
port.AddPropertyF("name", "Isolate Port (%" Pd64 ")", entry.port);
|
||||
msg_handler = DartLibraryCalls::LookupHandler(entry.port);
|
||||
port.AddProperty("handler", msg_handler);
|
||||
}
|
||||
JSONObject port(&ports);
|
||||
port.AddProperty("type", "_Port");
|
||||
port.AddPropertyF("name", "Isolate Port (%" Pd64 ")", entry.port);
|
||||
msg_handler = DartLibraryCalls::LookupHandler(entry.port);
|
||||
port.AddProperty("handler", msg_handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -330,11 +310,9 @@ void PortMap::DebugDumpForMessageHandler(MessageHandler* handler) {
|
|||
Object& msg_handler = Object::Handle();
|
||||
for (auto& entry : *ports_) {
|
||||
if (entry.handler == handler) {
|
||||
if (entry.state == kLivePort) {
|
||||
OS::PrintErr("Live Port = %" Pd64 "\n", entry.port);
|
||||
msg_handler = DartLibraryCalls::LookupHandler(entry.port);
|
||||
OS::PrintErr("Handler = %s\n", msg_handler.ToCString());
|
||||
}
|
||||
OS::PrintErr("Port = %" Pd64 "\n", entry.port);
|
||||
msg_handler = DartLibraryCalls::LookupHandler(entry.port);
|
||||
OS::PrintErr("Handler = %s\n", msg_handler.ToCString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,18 +20,11 @@ class Isolate;
|
|||
class Message;
|
||||
class MessageHandler;
|
||||
class Mutex;
|
||||
class PortMapTestPeer;
|
||||
|
||||
class PortMap : public AllStatic {
|
||||
public:
|
||||
enum PortState {
|
||||
kUnusedEntry = 0,
|
||||
kLivePort = 1, // a regular port (has a ReceivePort)
|
||||
kControlPort = 2, // a special control port
|
||||
};
|
||||
|
||||
// Allocate a port for the provided handler and return its VM-global id.
|
||||
static Dart_Port CreatePort(MessageHandler* handler, PortState initial_state);
|
||||
static Dart_Port CreatePort(MessageHandler* handler);
|
||||
|
||||
// Close the port with id. All pending messages will be dropped.
|
||||
//
|
||||
|
@ -49,8 +42,6 @@ class PortMap : public AllStatic {
|
|||
static bool PostMessage(std::unique_ptr<Message> message,
|
||||
bool before_events = false);
|
||||
|
||||
// Returns whether a port can receive messages.
|
||||
static bool IsLivePort(Dart_Port id);
|
||||
|
||||
// Returns the owning Isolate for port 'id'.
|
||||
static Isolate* GetIsolate(Dart_Port id);
|
||||
|
@ -59,7 +50,8 @@ class PortMap : public AllStatic {
|
|||
static Dart_Port GetOriginId(Dart_Port id);
|
||||
|
||||
#if defined(TESTING)
|
||||
static bool HasLivePorts(MessageHandler* handler);
|
||||
static bool PortExists(Dart_Port id);
|
||||
static bool HasPorts(MessageHandler* handler);
|
||||
#endif
|
||||
|
||||
// Whether the destination port's isolate is a member of [isolate_group].
|
||||
|
@ -75,17 +67,12 @@ class PortMap : public AllStatic {
|
|||
static void DebugDumpForMessageHandler(MessageHandler* handler);
|
||||
|
||||
private:
|
||||
friend class dart::PortMapTestPeer;
|
||||
|
||||
struct Entry : public PortSet<Entry>::Entry {
|
||||
Entry() : handler(nullptr), state(kUnusedEntry) {}
|
||||
Entry() : handler(nullptr) {}
|
||||
|
||||
MessageHandler* handler;
|
||||
PortState state;
|
||||
};
|
||||
|
||||
static const char* PortStateString(PortState state);
|
||||
|
||||
// Allocate a new unique port.
|
||||
static Dart_Port AllocatePort();
|
||||
|
||||
|
|
|
@ -11,25 +11,6 @@
|
|||
|
||||
namespace dart {
|
||||
|
||||
// Provides private access to PortMap for testing.
|
||||
class PortMapTestPeer {
|
||||
public:
|
||||
static bool IsActivePort(Dart_Port port) {
|
||||
MutexLocker ml(PortMap::mutex_);
|
||||
auto it = PortMap::ports_->TryLookup(port);
|
||||
return it != PortMap::ports_->end();
|
||||
}
|
||||
|
||||
static bool IsLivePort(Dart_Port port) {
|
||||
MutexLocker ml(PortMap::mutex_);
|
||||
auto it = PortMap::ports_->TryLookup(port);
|
||||
if (it == PortMap::ports_->end()) {
|
||||
return false;
|
||||
}
|
||||
return (*it).state == PortMap::kLivePort;
|
||||
}
|
||||
};
|
||||
|
||||
class PortTestMessageHandler : public MessageHandler {
|
||||
public:
|
||||
PortTestMessageHandler() : notify_count(0) {}
|
||||
|
@ -43,59 +24,59 @@ class PortTestMessageHandler : public MessageHandler {
|
|||
|
||||
TEST_CASE(PortMap_CreateAndCloseOnePort) {
|
||||
PortTestMessageHandler handler;
|
||||
Dart_Port port = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port = PortMap::CreatePort(&handler);
|
||||
EXPECT_NE(0, port);
|
||||
EXPECT(PortMapTestPeer::IsActivePort(port));
|
||||
EXPECT(PortMap::PortExists(port));
|
||||
|
||||
PortMap::ClosePort(port);
|
||||
EXPECT(!PortMapTestPeer::IsActivePort(port));
|
||||
EXPECT(!PortMap::PortExists(port));
|
||||
}
|
||||
|
||||
TEST_CASE(PortMap_CreateAndCloseTwoPorts) {
|
||||
PortTestMessageHandler handler;
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
EXPECT(PortMapTestPeer::IsActivePort(port1));
|
||||
EXPECT(PortMapTestPeer::IsActivePort(port2));
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler);
|
||||
EXPECT(PortMap::PortExists(port1));
|
||||
EXPECT(PortMap::PortExists(port2));
|
||||
|
||||
// Uniqueness.
|
||||
EXPECT_NE(port1, port2);
|
||||
|
||||
PortMap::ClosePort(port1);
|
||||
EXPECT(!PortMapTestPeer::IsActivePort(port1));
|
||||
EXPECT(PortMapTestPeer::IsActivePort(port2));
|
||||
EXPECT(!PortMap::PortExists(port1));
|
||||
EXPECT(PortMap::PortExists(port2));
|
||||
|
||||
PortMap::ClosePort(port2);
|
||||
EXPECT(!PortMapTestPeer::IsActivePort(port1));
|
||||
EXPECT(!PortMapTestPeer::IsActivePort(port2));
|
||||
EXPECT(!PortMap::PortExists(port1));
|
||||
EXPECT(!PortMap::PortExists(port2));
|
||||
}
|
||||
|
||||
TEST_CASE(PortMap_ClosePorts) {
|
||||
PortTestMessageHandler handler;
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
EXPECT(PortMapTestPeer::IsActivePort(port1));
|
||||
EXPECT(PortMapTestPeer::IsActivePort(port2));
|
||||
Dart_Port port1 = PortMap::CreatePort(&handler);
|
||||
Dart_Port port2 = PortMap::CreatePort(&handler);
|
||||
EXPECT(PortMap::PortExists(port1));
|
||||
EXPECT(PortMap::PortExists(port2));
|
||||
|
||||
// Close all ports at once.
|
||||
PortMap::ClosePorts(&handler);
|
||||
EXPECT(!PortMapTestPeer::IsActivePort(port1));
|
||||
EXPECT(!PortMapTestPeer::IsActivePort(port2));
|
||||
EXPECT(!PortMap::PortExists(port1));
|
||||
EXPECT(!PortMap::PortExists(port2));
|
||||
}
|
||||
|
||||
TEST_CASE(PortMap_CreateManyPorts) {
|
||||
PortTestMessageHandler handler;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
Dart_Port port = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
EXPECT(PortMapTestPeer::IsActivePort(port));
|
||||
Dart_Port port = PortMap::CreatePort(&handler);
|
||||
EXPECT(PortMap::PortExists(port));
|
||||
PortMap::ClosePort(port);
|
||||
EXPECT(!PortMapTestPeer::IsActivePort(port));
|
||||
EXPECT(!PortMap::PortExists(port));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(PortMap_PostMessage) {
|
||||
PortTestMessageHandler handler;
|
||||
Dart_Port port = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port = PortMap::CreatePort(&handler);
|
||||
EXPECT_EQ(0, handler.notify_count);
|
||||
|
||||
const char* message = "msg";
|
||||
|
@ -112,7 +93,7 @@ TEST_CASE(PortMap_PostMessage) {
|
|||
|
||||
TEST_CASE(PortMap_PostIntegerMessage) {
|
||||
PortTestMessageHandler handler;
|
||||
Dart_Port port = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port = PortMap::CreatePort(&handler);
|
||||
EXPECT_EQ(0, handler.notify_count);
|
||||
|
||||
EXPECT(PortMap::PostMessage(
|
||||
|
@ -125,7 +106,7 @@ TEST_CASE(PortMap_PostIntegerMessage) {
|
|||
|
||||
TEST_CASE(PortMap_PostNullMessage) {
|
||||
PortTestMessageHandler handler;
|
||||
Dart_Port port = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port = PortMap::CreatePort(&handler);
|
||||
EXPECT_EQ(0, handler.notify_count);
|
||||
|
||||
EXPECT(PortMap::PostMessage(
|
||||
|
@ -139,7 +120,7 @@ TEST_CASE(PortMap_PostNullMessage) {
|
|||
TEST_CASE(PortMap_PostMessageClosedPort) {
|
||||
// Create a port id and make it invalid.
|
||||
PortTestMessageHandler handler;
|
||||
Dart_Port port = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port = PortMap::CreatePort(&handler);
|
||||
PortMap::ClosePort(port);
|
||||
|
||||
const char* message = "msg";
|
||||
|
|
|
@ -264,7 +264,7 @@ ISOLATE_UNIT_TEST_CASE(Service_Code) {
|
|||
|
||||
// Build a mock message handler and wrap it in a dart port.
|
||||
ServiceTestMessageHandler handler;
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
|
||||
{
|
||||
TransitionVMToNative transition(thread);
|
||||
|
@ -390,7 +390,7 @@ ISOLATE_UNIT_TEST_CASE(Service_PcDescriptors) {
|
|||
|
||||
// Build a mock message handler and wrap it in a dart port.
|
||||
ServiceTestMessageHandler handler;
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
|
||||
{
|
||||
TransitionVMToNative transition(thread);
|
||||
|
@ -461,7 +461,7 @@ ISOLATE_UNIT_TEST_CASE(Service_LocalVarDescriptors) {
|
|||
|
||||
// Build a mock message handler and wrap it in a dart port.
|
||||
ServiceTestMessageHandler handler;
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
|
||||
{
|
||||
TransitionVMToNative transition(thread);
|
||||
|
@ -522,7 +522,7 @@ ISOLATE_UNIT_TEST_CASE(Service_PersistentHandles) {
|
|||
|
||||
// Build a mock message handler and wrap it in a dart port.
|
||||
ServiceTestMessageHandler handler;
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
|
||||
{
|
||||
TransitionVMToNative transition(thread);
|
||||
|
@ -605,7 +605,7 @@ ISOLATE_UNIT_TEST_CASE(Service_EmbedderRootHandler) {
|
|||
|
||||
// Build a mock message handler and wrap it in a dart port.
|
||||
ServiceTestMessageHandler handler;
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
|
||||
{
|
||||
TransitionVMToNative transition(thread);
|
||||
|
@ -651,7 +651,7 @@ ISOLATE_UNIT_TEST_CASE(Service_EmbedderIsolateHandler) {
|
|||
|
||||
// Build a mock message handler and wrap it in a dart port.
|
||||
ServiceTestMessageHandler handler;
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
|
||||
{
|
||||
TransitionVMToNative transition(thread);
|
||||
|
@ -708,7 +708,7 @@ ISOLATE_UNIT_TEST_CASE(Service_Profile) {
|
|||
|
||||
// Build a mock message handler and wrap it in a dart port.
|
||||
ServiceTestMessageHandler handler;
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler, PortMap::kLivePort);
|
||||
Dart_Port port_id = PortMap::CreatePort(&handler);
|
||||
Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
|
||||
{
|
||||
TransitionVMToNative transition(thread);
|
||||
|
|
Loading…
Reference in a new issue