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

Unified Diff: runtime/vm/service_test.cc

Issue 100103011: Changes to support dprof and Observatory profiler UIs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
Index: runtime/vm/service_test.cc
diff --git a/runtime/vm/service_test.cc b/runtime/vm/service_test.cc
index f8a5e8c2bbf0c5c707f5b7217853160605f2c466..448075d9196b0a6df434a1699add7bba2077ca8a 100644
--- a/runtime/vm/service_test.cc
+++ b/runtime/vm/service_test.cc
@@ -72,7 +72,6 @@ static RawInstance* EvalF(Dart_Handle lib, const char* fmt, ...) {
}
-/*
static RawFunction* GetFunction(const Class& cls, const char* name) {
const Function& result = Function::Handle(cls.LookupDynamicFunction(
String::Handle(String::New(name))));
@@ -80,7 +79,7 @@ static RawFunction* GetFunction(const Class& cls, const char* name) {
return result.raw();
}
-
+/*
static RawFunction* GetStaticFunction(const Class& cls, const char* name) {
const Function& result = Function::Handle(cls.LookupStaticFunction(
String::Handle(String::New(name))));
@@ -358,4 +357,124 @@ TEST_CASE(Service_Classes) {
handler.msg());
}
+
+TEST_CASE(Service_Code) {
+ const char* kScript =
+ "var port;\n" // Set to our mock port by C++.
+ "\n"
+ "class A {\n"
+ " var a;\n"
+ " dynamic b() {}\n"
+ " dynamic c() {\n"
+ " var d = () { b(); };\n"
+ " return d;\n"
+ " }\n"
+ "}\n"
+ "main() {\n"
+ " var z = new A();\n"
+ " var x = z.c();\n"
+ " x();\n"
+ "}";
+
+ Isolate* isolate = Isolate::Current();
+ Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
+ EXPECT_VALID(h_lib);
+ Library& lib = Library::Handle();
+ lib ^= Api::UnwrapHandle(h_lib);
+ EXPECT(!lib.IsNull());
+ Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
+ EXPECT_VALID(result);
+ const Class& class_a = Class::Handle(GetClass(lib, "A"));
+ EXPECT(!class_a.IsNull());
+ const Function& function_c = Function::Handle(GetFunction(class_a, "c"));
+ EXPECT(!function_c.IsNull());
+ const Code& code_c = Code::Handle(function_c.CurrentCode());
+ EXPECT(!code_c.IsNull());
+ // Use the entry of the code object as it's reference.
+ uword entry = code_c.EntryPoint();
+ EXPECT_GT(code_c.Size(), 16);
+ uword last = entry + code_c.Size();
+
+ // 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(isolate, DartLibraryCalls::NewSendPort(port_id));
+ EXPECT_VALID(port);
+ EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
+
+ Instance& service_msg = Instance::Handle();
+
+ // Request an invalid code object.
+ service_msg = Eval(h_lib, "[port, ['code', '0'], [], []]");
+ Service::HandleServiceMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ EXPECT_STREQ(
+ "{\"type\":\"Error\",\"text\":\"Could not find code at 0\",\"message\":"
+ "{\"arguments\":[\"code\",\"0\"],"
+ "\"option_keys\":[],\"option_values\":[]}}", handler.msg());
+
+ // The following four tests check that a code object can be found
+ // inside the range: [code.EntryPoint(), code.EntryPoint() + code.Size()).
+ // Request code object at code.EntryPoint()
+ // Expect this to succeed as it is inside [entry, entry + size).
+ service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", entry);
+ Service::HandleServiceMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ {
+ // Only perform a partial match.
+ const intptr_t kBufferSize = 512;
+ char buffer[kBufferSize];
+ OS::SNPrint(buffer, kBufferSize-1,
+ "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry);
+ EXPECT_SUBSTRING(buffer, handler.msg());
+ }
+
+ // Request code object at code.EntryPoint() + 16.
+ // Expect this to succeed as it is inside [entry, entry + size).
+ uintptr_t address = entry + 16;
+ service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address);
+ Service::HandleServiceMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ {
+ // Only perform a partial match.
+ const intptr_t kBufferSize = 512;
+ char buffer[kBufferSize];
+ OS::SNPrint(buffer, kBufferSize-1,
+ "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry);
+ EXPECT_SUBSTRING(buffer, handler.msg());
+ }
+
+ // Request code object at code.EntryPoint() + code.Size() - 1.
+ // Expect this to succeed as it is inside [entry, entry + size).
+ address = last - 1;
+ service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address);
+ Service::HandleServiceMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ {
+ // Only perform a partial match.
+ const intptr_t kBufferSize = 512;
+ char buffer[kBufferSize];
+ OS::SNPrint(buffer, kBufferSize-1,
+ "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry);
+ EXPECT_SUBSTRING(buffer, handler.msg());
+ }
+
+ // Request code object at code.EntryPoint() + code.Size(). Expect this
+ // to fail as it's outside of [entry, entry + size).
+ address = last;
+ service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address);
+ Service::HandleServiceMessage(isolate, service_msg);
+ handler.HandleNextMessage();
+ {
+ const intptr_t kBufferSize = 1024;
+ char buffer[kBufferSize];
+ OS::SNPrint(buffer, kBufferSize-1,
+ "{\"type\":\"Error\",\"text\":\"Could not find code at %" Px "\","
+ "\"message\":{\"arguments\":[\"code\",\"%" Px "\"],"
+ "\"option_keys\":[],\"option_values\":[]}}", address, address);
+ EXPECT_STREQ(buffer, handler.msg());
+ }
+}
+
} // namespace dart
« runtime/vm/service.cc ('K') | « runtime/vm/service.cc ('k') | tools/tracemerge.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698