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

Unified Diff: runtime/vm/service_test.cc

Issue 1719313002: Add persistent handles to service protocol and Observatory UI (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/service_test.cc
diff --git a/runtime/vm/service_test.cc b/runtime/vm/service_test.cc
index de6cf730e2e5d0e0b775e07005d8a5b07cd74909..b211fb75d60d974b279b5dc8169b47a2213fe483 100644
--- a/runtime/vm/service_test.cc
+++ b/runtime/vm/service_test.cc
@@ -440,6 +440,81 @@ TEST_CASE(Service_LocalVarDescriptors) {
}
+
+static void WeakHandleFinalizer(void* isolate_callback_data,
+ Dart_WeakPersistentHandle handle,
+ void* peer) {
+}
+
+
+TEST_CASE(Service_PersistentHandles) {
+ const char* kScript =
+ "var port;\n" // Set to our mock port by C++.
+ "\n"
+ "class A {\n"
+ " var a;\n"
+ "}\n"
+ "var global = new A();\n"
+ "main() {\n"
+ " return global;\n"
+ "}";
+
+ Isolate* isolate = thread->isolate();
+ isolate->set_is_runnable(true);
+ Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(lib);
+ Library& vmlib = Library::Handle();
+ vmlib ^= Api::UnwrapHandle(lib);
+ EXPECT(!vmlib.IsNull());
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+
+ // Create a persistent handle to global.
+ Dart_PersistentHandle persistent_handle = Dart_NewPersistentHandle(result);
+
+ // Create a weak persistent handle to global.
+ Dart_WeakPersistentHandle weak_persistent_handle =
+ Dart_NewWeakPersistentHandle(result,
+ reinterpret_cast<void*>(0xdeadbeef),
+ 128,
+ WeakHandleFinalizer);
+
+ // Build a mock message handler and wrap it in a dart port.
+ ServiceTestMessageHandler handler;
+ Dart_Port port_id = PortMap::CreatePort(&handler);
+ Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
+ EXPECT_VALID(port);
+ EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
+
+ Array& service_msg = Array::Handle();
+
+ // Get persistent handles.
+ service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]");
+ Service::HandleIsolateMessage(isolate, service_msg);
+ EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
+ // Look for a heart beat.
+ EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg());
+ EXPECT_SUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg());
+ EXPECT_SUBSTRING("\"name\":\"A\"", handler.msg());
+ EXPECT_SUBSTRING("\"externalSize\":\"128\"", handler.msg());
+
+ // Delete persistent handles.
+ Dart_DeletePersistentHandle(persistent_handle);
+ Dart_DeleteWeakPersistentHandle(Dart_CurrentIsolate(),
+ weak_persistent_handle);
+
+ // Get persistent handles (again).
+ service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]");
+ Service::HandleIsolateMessage(isolate, service_msg);
+ EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
+ EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg());
+ // Verify that old persistent handles are not present.
+ EXPECT_NOTSUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg());
+ EXPECT_NOTSUBSTRING("\"name\":\"A\"", handler.msg());
+ EXPECT_NOTSUBSTRING("\"externalSize\":\"128\"", handler.msg());
+}
+
+
TEST_CASE(Service_Address) {
const char* kScript =
"var port;\n" // Set to our mock port by C++.
« no previous file with comments | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698