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

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

Issue 751183003: Expose set_source service command for functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/service.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\",\"y\"]," 1067 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\",\"y\"],"
1068 "\"option_keys\":[],\"option_values\":[]}}", cid); 1068 "\"option_keys\":[],\"option_values\":[]}}", cid);
1069 1069
1070 // Invalid function subcommand with valid function id. 1070 // Invalid function subcommand with valid function id.
1071 service_msg = EvalF(lib, 1071 service_msg = EvalF(lib,
1072 "[0, port, ['classes', '%" Pd "', 'functions', 'b'," 1072 "[0, port, ['classes', '%" Pd "', 'functions', 'b',"
1073 "'x'], [], []]", cid); 1073 "'x'], [], []]", cid);
1074 Service::HandleIsolateMessage(isolate, service_msg); 1074 Service::HandleIsolateMessage(isolate, service_msg);
1075 handler.HandleNextMessage(); 1075 handler.HandleNextMessage();
1076 ExpectSubstringF(handler.msg(), 1076 ExpectSubstringF(handler.msg(),
1077 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub collection x\"," 1077 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub command x\","
1078 "\"request\":" 1078 "\"request\":"
1079 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"b\",\"x\"]," 1079 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"b\",\"x\"],"
1080 "\"option_keys\":[],\"option_values\":[]}}", cid); 1080 "\"option_keys\":[],\"option_values\":[]}}", cid);
1081 1081
1082 // Retained size of all instances of class B. 1082 // Retained size of all instances of class B.
1083 const Class& class_b = Class::Handle(GetClass(vmlib, "B")); 1083 const Class& class_b = Class::Handle(GetClass(vmlib, "B"));
1084 EXPECT(!class_b.IsNull()); 1084 EXPECT(!class_b.IsNull());
1085 const Instance& b0 = Instance::Handle(Instance::New(class_b)); 1085 const Instance& b0 = Instance::Handle(Instance::New(class_b));
1086 const Instance& b1 = Instance::Handle(Instance::New(class_b)); 1086 const Instance& b1 = Instance::Handle(Instance::New(class_b));
1087 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'retained']," 1087 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'retained'],"
(...skipping 25 matching lines...) Expand all
1113 // ... and if limit is 1, we one get one of them. 1113 // ... and if limit is 1, we one get one of them.
1114 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'instances']," 1114 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'instances'],"
1115 "['limit'], ['1']]", class_b.id()); 1115 "['limit'], ['1']]", class_b.id());
1116 Service::HandleIsolateMessage(isolate, service_msg); 1116 Service::HandleIsolateMessage(isolate, service_msg);
1117 handler.HandleNextMessage(); 1117 handler.HandleNextMessage();
1118 ExpectSubstringF(handler.msg(), "\"totalCount\":2"); 1118 ExpectSubstringF(handler.msg(), "\"totalCount\":2");
1119 ExpectSubstringF(handler.msg(), "\"sampleCount\":1"); 1119 ExpectSubstringF(handler.msg(), "\"sampleCount\":1");
1120 } 1120 }
1121 1121
1122 1122
1123 TEST_CASE(Service_SetSource) {
1124 const char* kScript =
1125 "var port;\n" // Set to our mock port by C++.
1126 "\n"
1127 "class A {\n"
1128 " a() { return 1; }\n"
1129 " b() { return 0; }\n"
1130 " c(String f) { return f.length; }\n"
1131 "}\n"
1132 "main() {\n"
1133 " var z = new A();\n"
1134 " return z.a();\n"
1135 "}\n"
1136 "runB() {\n"
1137 " var z = new A();\n"
1138 " return z.b();\n"
1139 "}\n"
1140 "runC() {\n"
1141 " var z = new A();\n"
1142 " return z.c();\n"
1143 "}\n";
1144
1145 Isolate* isolate = Isolate::Current();
1146 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1147 EXPECT_VALID(lib);
1148 Library& vmlib = Library::Handle();
1149 vmlib ^= Api::UnwrapHandle(lib);
1150 EXPECT(!vmlib.IsNull());
1151 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1152 EXPECT_VALID(result);
1153 const Class& class_a = Class::Handle(GetClass(vmlib, "A"));
1154 EXPECT(!class_a.IsNull());
1155 intptr_t cid = class_a.id();
1156
1157 // Build a mock message handler and wrap it in a dart port.
1158 ServiceTestMessageHandler handler;
1159 Dart_Port port_id = PortMap::CreatePort(&handler);
1160 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1161 EXPECT_VALID(port);
1162 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1163
1164 Array& service_msg = Array::Handle();
1165
1166 // Request the class A over the service.
1167 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "'], [], []]", cid);
1168 Service::HandleIsolateMessage(isolate, service_msg);
1169 handler.HandleNextMessage();
1170 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg());
1171 ExpectSubstringF(handler.msg(),
1172 "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid);
1173 ExpectSubstringF(handler.msg(), "\"allocationStats\":");
1174 ExpectSubstringF(handler.msg(), "\"tokenPos\":");
1175 ExpectSubstringF(handler.msg(), "\"endTokenPos\":");
1176
1177 // Request function 'b' from class A.
1178 service_msg = EvalF(lib,
1179 "[0, port, ['classes', '%" Pd "', 'functions', 'b'],"
1180 "[], []]", cid);
1181 Service::HandleIsolateMessage(isolate, service_msg);
1182 handler.HandleNextMessage();
1183 EXPECT_SUBSTRING("\"type\":\"Function\"", handler.msg());
1184 ExpectSubstringF(handler.msg(),
1185 "\"id\":\"classes\\/%" Pd "\\/functions\\/b\","
1186 "\"name\":\"b\",", cid);
1187
1188 // Invalid set source of function 'b' from class A.
1189 service_msg = EvalF(
1190 lib,
1191 "[0, port, ['classes', '%" Pd "', 'functions', 'b', 'set_source'],"
1192 "[], []]", cid);
1193 Service::HandleIsolateMessage(isolate, service_msg);
1194 handler.HandleNextMessage();
1195 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1196 EXPECT_SUBSTRING("set_source expects a 'source' option", handler.msg());
1197
1198 // Set source (with syntax error) of function 'b' from class A.
1199 service_msg = EvalF(
1200 lib,
1201 "[0, port, ['classes', '%" Pd "', 'functions', 'b', 'set_source'],"
1202 "['source'], ['b() { return 4 }']]", cid);
1203 Service::HandleIsolateMessage(isolate, service_msg);
1204 handler.HandleNextMessage();
1205 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1206
1207 // Set source of function 'b' from class A.
1208 service_msg = EvalF(
1209 lib,
1210 "[0, port, ['classes', '%" Pd "', 'functions', 'b', 'set_source'],"
1211 "['source'], ['b() { return 4; }']]", cid);
1212 Service::HandleIsolateMessage(isolate, service_msg);
1213 handler.HandleNextMessage();
1214 EXPECT_SUBSTRING("Success", handler.msg());
1215
1216 // Run function 'b' see that it is executing replaced code.
1217 result = Dart_Invoke(lib, NewString("runB"), 0, NULL);
1218 EXPECT_VALID(result);
1219 ASSERT(Dart_IsInteger(result));
1220 int64_t r;
1221 result = Dart_IntegerToInt64(result, &r);
1222 EXPECT_VALID(result);
1223 EXPECT_EQ(4, r);
1224
1225 // Set source of function 'c' from class A, changing its signature.
1226 service_msg = EvalF(
1227 lib,
1228 "[0, port, ['classes', '%" Pd "', 'functions', 'c', 'set_source'],"
1229 "['source'], ['c() { return 99; }']]", cid);
1230 Service::HandleIsolateMessage(isolate, service_msg);
1231 handler.HandleNextMessage();
1232 EXPECT_SUBSTRING("Success", handler.msg());
1233
1234 // Run function 'c' see that it is executing replaced code.
1235 result = Dart_Invoke(lib, NewString("runC"), 0, NULL);
1236 EXPECT_VALID(result);
1237 ASSERT(Dart_IsInteger(result));
1238 result = Dart_IntegerToInt64(result, &r);
1239 EXPECT_VALID(result);
1240 EXPECT_EQ(99, r);
1241 }
1242
1243
1123 TEST_CASE(Service_Types) { 1244 TEST_CASE(Service_Types) {
1124 const char* kScript = 1245 const char* kScript =
1125 "var port;\n" // Set to our mock port by C++. 1246 "var port;\n" // Set to our mock port by C++.
1126 "\n" 1247 "\n"
1127 "class A<T> { }\n" 1248 "class A<T> { }\n"
1128 "\n" 1249 "\n"
1129 "main() {\n" 1250 "main() {\n"
1130 " new A<A<bool>>();\n" 1251 " new A<A<bool>>();\n"
1131 "}"; 1252 "}";
1132 1253
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 service_msg = Eval(lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); 2316 service_msg = Eval(lib, "[0, port, ['profile'], ['tags'], ['hidden']]");
2196 Service::HandleIsolateMessage(isolate, service_msg); 2317 Service::HandleIsolateMessage(isolate, service_msg);
2197 handler.HandleNextMessage(); 2318 handler.HandleNextMessage();
2198 // Expect error. 2319 // Expect error.
2199 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 2320 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
2200 } 2321 }
2201 2322
2202 #endif // !defined(TARGET_ARCH_ARM64) 2323 #endif // !defined(TARGET_ARCH_ARM64)
2203 2324
2204 } // namespace dart 2325 } // namespace dart
OLDNEW
« 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