| OLD | NEW |
| 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 "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
| 6 #include "vm/dart_api_impl.h" | 6 #include "vm/dart_api_impl.h" |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/message_handler.h" | 10 #include "vm/message_handler.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 108 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 109 | 109 |
| 110 Instance& service_msg = Instance::Handle(); | 110 Instance& service_msg = Instance::Handle(); |
| 111 | 111 |
| 112 // Add a breakpoint. | 112 // Add a breakpoint. |
| 113 const String& url = String::Handle(String::New(TestCase::url())); | 113 const String& url = String::Handle(String::New(TestCase::url())); |
| 114 isolate->debugger()->SetBreakpointAtLine(url, 3); | 114 isolate->debugger()->SetBreakpointAtLine(url, 3); |
| 115 | 115 |
| 116 // Get the breakpoint list. | 116 // Get the breakpoint list. |
| 117 service_msg = Eval(lib, "[port, ['debug', 'breakpoints'], [], []]"); | 117 service_msg = Eval(lib, "[port, ['debug', 'breakpoints'], [], []]"); |
| 118 Service::HandleServiceMessage(isolate, service_msg); | 118 Service::HandleIsolateMessage(isolate, service_msg); |
| 119 handler.HandleNextMessage(); | 119 handler.HandleNextMessage(); |
| 120 EXPECT_STREQ( | 120 EXPECT_STREQ( |
| 121 "{\"type\":\"BreakpointList\",\"breakpoints\":[{" | 121 "{\"type\":\"BreakpointList\",\"breakpoints\":[{" |
| 122 "\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true," | 122 "\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true," |
| 123 "\"resolved\":false," | 123 "\"resolved\":false," |
| 124 "\"location\":{\"type\":\"Location\"," | 124 "\"location\":{\"type\":\"Location\"," |
| 125 "\"script\":\"dart:test-lib\",\"tokenPos\":5}}]}", | 125 "\"script\":\"dart:test-lib\",\"tokenPos\":5}}]}", |
| 126 handler.msg()); | 126 handler.msg()); |
| 127 | 127 |
| 128 // Individual breakpoint. | 128 // Individual breakpoint. |
| 129 service_msg = Eval(lib, "[port, ['debug', 'breakpoints', '1'], [], []]"); | 129 service_msg = Eval(lib, "[port, ['debug', 'breakpoints', '1'], [], []]"); |
| 130 Service::HandleServiceMessage(isolate, service_msg); | 130 Service::HandleIsolateMessage(isolate, service_msg); |
| 131 handler.HandleNextMessage(); | 131 handler.HandleNextMessage(); |
| 132 EXPECT_STREQ( | 132 EXPECT_STREQ( |
| 133 "{\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true," | 133 "{\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true," |
| 134 "\"resolved\":false," | 134 "\"resolved\":false," |
| 135 "\"location\":{\"type\":\"Location\"," | 135 "\"location\":{\"type\":\"Location\"," |
| 136 "\"script\":\"dart:test-lib\",\"tokenPos\":5}}", | 136 "\"script\":\"dart:test-lib\",\"tokenPos\":5}}", |
| 137 handler.msg()); | 137 handler.msg()); |
| 138 | 138 |
| 139 // Missing sub-command. | 139 // Missing sub-command. |
| 140 service_msg = Eval(lib, "[port, ['debug'], [], []]"); | 140 service_msg = Eval(lib, "[port, ['debug'], [], []]"); |
| 141 Service::HandleServiceMessage(isolate, service_msg); | 141 Service::HandleIsolateMessage(isolate, service_msg); |
| 142 handler.HandleNextMessage(); | 142 handler.HandleNextMessage(); |
| 143 EXPECT_STREQ( | 143 EXPECT_STREQ( |
| 144 "{\"type\":\"Error\"," | 144 "{\"type\":\"Error\"," |
| 145 "\"text\":\"Must specify a subcommand\"," | 145 "\"text\":\"Must specify a subcommand\"," |
| 146 "\"message\":{\"arguments\":[\"debug\"],\"option_keys\":[]," | 146 "\"message\":{\"arguments\":[\"debug\"],\"option_keys\":[]," |
| 147 "\"option_values\":[]}}", | 147 "\"option_values\":[]}}", |
| 148 handler.msg()); | 148 handler.msg()); |
| 149 | 149 |
| 150 // Unrecognized breakpoint. | 150 // Unrecognized breakpoint. |
| 151 service_msg = Eval(lib, "[port, ['debug', 'breakpoints', '1111'], [], []]"); | 151 service_msg = Eval(lib, "[port, ['debug', 'breakpoints', '1111'], [], []]"); |
| 152 Service::HandleServiceMessage(isolate, service_msg); | 152 Service::HandleIsolateMessage(isolate, service_msg); |
| 153 handler.HandleNextMessage(); | 153 handler.HandleNextMessage(); |
| 154 EXPECT_STREQ("{\"type\":\"Error\"," | 154 EXPECT_STREQ("{\"type\":\"Error\"," |
| 155 "\"text\":\"Unrecognized breakpoint id 1111\"," | 155 "\"text\":\"Unrecognized breakpoint id 1111\"," |
| 156 "\"message\":{" | 156 "\"message\":{" |
| 157 "\"arguments\":[\"debug\",\"breakpoints\",\"1111\"]," | 157 "\"arguments\":[\"debug\",\"breakpoints\",\"1111\"]," |
| 158 "\"option_keys\":[],\"option_values\":[]}}", | 158 "\"option_keys\":[],\"option_values\":[]}}", |
| 159 handler.msg()); | 159 handler.msg()); |
| 160 | 160 |
| 161 // Command too long. | 161 // Command too long. |
| 162 service_msg = | 162 service_msg = |
| 163 Eval(lib, "[port, ['debug', 'breakpoints', '1111', 'green'], [], []]"); | 163 Eval(lib, "[port, ['debug', 'breakpoints', '1111', 'green'], [], []]"); |
| 164 Service::HandleServiceMessage(isolate, service_msg); | 164 Service::HandleIsolateMessage(isolate, service_msg); |
| 165 handler.HandleNextMessage(); | 165 handler.HandleNextMessage(); |
| 166 EXPECT_STREQ("{\"type\":\"Error\",\"text\":\"Command too long\"," | 166 EXPECT_STREQ("{\"type\":\"Error\",\"text\":\"Command too long\"," |
| 167 "\"message\":{\"arguments\":[\"debug\",\"breakpoints\"," | 167 "\"message\":{\"arguments\":[\"debug\",\"breakpoints\"," |
| 168 "\"1111\",\"green\"]," | 168 "\"1111\",\"green\"]," |
| 169 "\"option_keys\":[],\"option_values\":[]}}", | 169 "\"option_keys\":[],\"option_values\":[]}}", |
| 170 handler.msg()); | 170 handler.msg()); |
| 171 | 171 |
| 172 // Unrecognized subcommand. | 172 // Unrecognized subcommand. |
| 173 service_msg = Eval(lib, "[port, ['debug', 'nosferatu'], [], []]"); | 173 service_msg = Eval(lib, "[port, ['debug', 'nosferatu'], [], []]"); |
| 174 Service::HandleServiceMessage(isolate, service_msg); | 174 Service::HandleIsolateMessage(isolate, service_msg); |
| 175 handler.HandleNextMessage(); | 175 handler.HandleNextMessage(); |
| 176 EXPECT_STREQ("{\"type\":\"Error\"," | 176 EXPECT_STREQ("{\"type\":\"Error\"," |
| 177 "\"text\":\"Unrecognized subcommand 'nosferatu'\"," | 177 "\"text\":\"Unrecognized subcommand 'nosferatu'\"," |
| 178 "\"message\":{\"arguments\":[\"debug\",\"nosferatu\"]," | 178 "\"message\":{\"arguments\":[\"debug\",\"nosferatu\"]," |
| 179 "\"option_keys\":[],\"option_values\":[]}}", | 179 "\"option_keys\":[],\"option_values\":[]}}", |
| 180 handler.msg()); | 180 handler.msg()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 | 183 |
| 184 TEST_CASE(Service_Classes) { | 184 TEST_CASE(Service_Classes) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 Dart_Port port_id = PortMap::CreatePort(&handler); | 216 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 217 Dart_Handle port = | 217 Dart_Handle port = |
| 218 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); | 218 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
| 219 EXPECT_VALID(port); | 219 EXPECT_VALID(port); |
| 220 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | 220 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
| 221 | 221 |
| 222 Instance& service_msg = Instance::Handle(); | 222 Instance& service_msg = Instance::Handle(); |
| 223 | 223 |
| 224 // Request an invalid class id. | 224 // Request an invalid class id. |
| 225 service_msg = Eval(h_lib, "[port, ['classes', '999999'], [], []]"); | 225 service_msg = Eval(h_lib, "[port, ['classes', '999999'], [], []]"); |
| 226 Service::HandleServiceMessage(isolate, service_msg); | 226 Service::HandleIsolateMessage(isolate, service_msg); |
| 227 handler.HandleNextMessage(); | 227 handler.HandleNextMessage(); |
| 228 EXPECT_STREQ( | 228 EXPECT_STREQ( |
| 229 "{\"type\":\"Error\",\"text\":\"999999 is not a valid class id.\"," | 229 "{\"type\":\"Error\",\"text\":\"999999 is not a valid class id.\"," |
| 230 "\"message\":{\"arguments\":[\"classes\",\"999999\"]," | 230 "\"message\":{\"arguments\":[\"classes\",\"999999\"]," |
| 231 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 231 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); |
| 232 | 232 |
| 233 // Request the class A over the service. | 233 // Request the class A over the service. |
| 234 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid); | 234 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid); |
| 235 Service::HandleServiceMessage(isolate, service_msg); | 235 Service::HandleIsolateMessage(isolate, service_msg); |
| 236 handler.HandleNextMessage(); | 236 handler.HandleNextMessage(); |
| 237 EXPECT_STREQ( | 237 EXPECT_STREQ( |
| 238 "{\"type\":\"Class\",\"id\":\"classes\\/1009\",\"name\":\"A\"," | 238 "{\"type\":\"Class\",\"id\":\"classes\\/1009\",\"name\":\"A\"," |
| 239 "\"user_name\":\"A\",\"implemented\":false,\"abstract\":false," | 239 "\"user_name\":\"A\",\"implemented\":false,\"abstract\":false," |
| 240 "\"patch\":false,\"finalized\":true,\"const\":false,\"super\":" | 240 "\"patch\":false,\"finalized\":true,\"const\":false,\"super\":" |
| 241 "{\"type\":\"@Class\",\"id\":\"classes\\/35\",\"name\":\"Object\"," | 241 "{\"type\":\"@Class\",\"id\":\"classes\\/35\",\"name\":\"Object\"," |
| 242 "\"user_name\":\"Object\"},\"library\":{\"type\":\"@Library\",\"id\":" | 242 "\"user_name\":\"Object\"},\"library\":{\"type\":\"@Library\",\"id\":" |
| 243 "\"libraries\\/12\",\"name\":\"\",\"user_name\":\"dart:test-lib\"}," | 243 "\"libraries\\/12\",\"name\":\"\",\"user_name\":\"dart:test-lib\"}," |
| 244 "\"fields\":[{\"type\":\"@Field\",\"id\":\"classes\\/1009\\/fields\\/0\"," | 244 "\"fields\":[{\"type\":\"@Field\",\"id\":\"classes\\/1009\\/fields\\/0\"," |
| 245 "\"name\":\"a\",\"user_name\":\"a\",\"owner\":{\"type\":\"@Class\"," | 245 "\"name\":\"a\",\"user_name\":\"a\",\"owner\":{\"type\":\"@Class\"," |
| 246 "\"id\":\"classes\\/1009\",\"name\":\"A\",\"user_name\":\"A\"}," | 246 "\"id\":\"classes\\/1009\",\"name\":\"A\",\"user_name\":\"A\"}," |
| 247 "\"declared_type\":{\"type\":\"@Class\",\"id\":\"classes\\/106\"," | 247 "\"declared_type\":{\"type\":\"@Class\",\"id\":\"classes\\/106\"," |
| 248 "\"name\":\"dynamic\",\"user_name\":\"dynamic\"},\"static\":false," | 248 "\"name\":\"dynamic\",\"user_name\":\"dynamic\"},\"static\":false," |
| 249 "\"final\":false,\"const\":false}],\"functions\":[" | 249 "\"final\":false,\"const\":false}],\"functions\":[" |
| 250 "{\"type\":\"@Function\",\"id\":\"classes\\/1009\\/functions\\/0\"," | 250 "{\"type\":\"@Function\",\"id\":\"classes\\/1009\\/functions\\/0\"," |
| 251 "\"name\":\"get:a\",\"user_name\":\"A.a\"},{\"type\":\"@Function\"," | 251 "\"name\":\"get:a\",\"user_name\":\"A.a\"},{\"type\":\"@Function\"," |
| 252 "\"id\":\"classes\\/1009\\/functions\\/1\",\"name\":\"set:a\"," | 252 "\"id\":\"classes\\/1009\\/functions\\/1\",\"name\":\"set:a\"," |
| 253 "\"user_name\":\"A.a=\"},{\"type\":\"@Function\",\"id\":" | 253 "\"user_name\":\"A.a=\"},{\"type\":\"@Function\",\"id\":" |
| 254 "\"classes\\/1009\\/functions\\/2\",\"name\":\"b\",\"user_name\":\"A.b\"}" | 254 "\"classes\\/1009\\/functions\\/2\",\"name\":\"b\",\"user_name\":\"A.b\"}" |
| 255 ",{\"type\":\"@Function\",\"id\":\"classes\\/1009\\/functions\\/3\"," | 255 ",{\"type\":\"@Function\",\"id\":\"classes\\/1009\\/functions\\/3\"," |
| 256 "\"name\":\"c\",\"user_name\":\"A.c\"},{\"type\":\"@Function\",\"id\":" | 256 "\"name\":\"c\",\"user_name\":\"A.c\"},{\"type\":\"@Function\",\"id\":" |
| 257 "\"classes\\/1009\\/functions\\/4\",\"name\":\"A.\",\"user_name\":" | 257 "\"classes\\/1009\\/functions\\/4\",\"name\":\"A.\",\"user_name\":" |
| 258 "\"A.A\"}]}", | 258 "\"A.A\"}]}", |
| 259 handler.msg()); | 259 handler.msg()); |
| 260 | 260 |
| 261 // Request function 0 from class A. | 261 // Request function 0 from class A. |
| 262 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '0']," | 262 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '0']," |
| 263 "[], []]", cid); | 263 "[], []]", cid); |
| 264 Service::HandleServiceMessage(isolate, service_msg); | 264 Service::HandleIsolateMessage(isolate, service_msg); |
| 265 handler.HandleNextMessage(); | 265 handler.HandleNextMessage(); |
| 266 EXPECT_STREQ( | 266 EXPECT_STREQ( |
| 267 "{\"type\":\"Function\",\"id\":\"classes\\/1009\\/functions\\/0\",\"name\":" | 267 "{\"type\":\"Function\",\"id\":\"classes\\/1009\\/functions\\/0\",\"name\":" |
| 268 "\"get:a\",\"user_name\":\"A.a\",\"is_static\":false,\"is_const\":false," | 268 "\"get:a\",\"user_name\":\"A.a\",\"is_static\":false,\"is_const\":false," |
| 269 "\"is_optimizable\":true,\"is_inlinable\":false,\"kind\":" | 269 "\"is_optimizable\":true,\"is_inlinable\":false,\"kind\":" |
| 270 "\"kImplicitGetter\",\"unoptimized_code\":{\"type\":\"null\"}," | 270 "\"kImplicitGetter\",\"unoptimized_code\":{\"type\":\"null\"}," |
| 271 "\"usage_counter\":0,\"optimized_call_site_count\":0,\"code\":" | 271 "\"usage_counter\":0,\"optimized_call_site_count\":0,\"code\":" |
| 272 "{\"type\":\"null\"},\"deoptimizations\":0}", handler.msg()); | 272 "{\"type\":\"null\"},\"deoptimizations\":0}", handler.msg()); |
| 273 | 273 |
| 274 // Request field 0 from class A. | 274 // Request field 0 from class A. |
| 275 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '0']," | 275 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '0']," |
| 276 "[], []]", cid); | 276 "[], []]", cid); |
| 277 Service::HandleServiceMessage(isolate, service_msg); | 277 Service::HandleIsolateMessage(isolate, service_msg); |
| 278 handler.HandleNextMessage(); | 278 handler.HandleNextMessage(); |
| 279 EXPECT_STREQ( | 279 EXPECT_STREQ( |
| 280 "{\"type\":\"Field\",\"id\":\"classes\\/1009\\/fields\\/0\",\"name\":\"a\"," | 280 "{\"type\":\"Field\",\"id\":\"classes\\/1009\\/fields\\/0\",\"name\":\"a\"," |
| 281 "\"user_name\":\"a\",\"owner\":{\"type\":\"@Class\",\"id\":" | 281 "\"user_name\":\"a\",\"owner\":{\"type\":\"@Class\",\"id\":" |
| 282 "\"classes\\/1009\",\"name\":\"A\",\"user_name\":\"A\"},\"declared_type\":" | 282 "\"classes\\/1009\",\"name\":\"A\",\"user_name\":\"A\"},\"declared_type\":" |
| 283 "{\"type\":\"@Class\",\"id\":\"classes\\/106\",\"name\":\"dynamic\"," | 283 "{\"type\":\"@Class\",\"id\":\"classes\\/106\",\"name\":\"dynamic\"," |
| 284 "\"user_name\":\"dynamic\"},\"static\":false,\"final\":false,\"const\":" | 284 "\"user_name\":\"dynamic\"},\"static\":false,\"final\":false,\"const\":" |
| 285 "false,\"guard_nullable\":true,\"guard_class\":{\"type\":\"@Class\"," | 285 "false,\"guard_nullable\":true,\"guard_class\":{\"type\":\"@Class\"," |
| 286 "\"id\":\"classes\\/105\",\"name\":\"Null\",\"user_name\":\"Null\"}," | 286 "\"id\":\"classes\\/105\",\"name\":\"Null\",\"user_name\":\"Null\"}," |
| 287 "\"guard_length\":\"variable\"}", handler.msg()); | 287 "\"guard_length\":\"variable\"}", handler.msg()); |
| 288 | 288 |
| 289 // Invalid sub command. | 289 // Invalid sub command. |
| 290 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'huh', '0']," | 290 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'huh', '0']," |
| 291 "[], []]", cid); | 291 "[], []]", cid); |
| 292 Service::HandleServiceMessage(isolate, service_msg); | 292 Service::HandleIsolateMessage(isolate, service_msg); |
| 293 handler.HandleNextMessage(); | 293 handler.HandleNextMessage(); |
| 294 EXPECT_STREQ( | 294 EXPECT_STREQ( |
| 295 "{\"type\":\"Error\",\"text\":\"Invalid sub collection huh\",\"message\":" | 295 "{\"type\":\"Error\",\"text\":\"Invalid sub collection huh\",\"message\":" |
| 296 "{\"arguments\":[\"classes\",\"1009\",\"huh\",\"0\"],\"option_keys\":[]," | 296 "{\"arguments\":[\"classes\",\"1009\",\"huh\",\"0\"],\"option_keys\":[]," |
| 297 "\"option_values\":[]}}", handler.msg()); | 297 "\"option_values\":[]}}", handler.msg()); |
| 298 | 298 |
| 299 // Invalid field request. | 299 // Invalid field request. |
| 300 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9']," | 300 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9']," |
| 301 "[], []]", cid); | 301 "[], []]", cid); |
| 302 Service::HandleServiceMessage(isolate, service_msg); | 302 Service::HandleIsolateMessage(isolate, service_msg); |
| 303 handler.HandleNextMessage(); | 303 handler.HandleNextMessage(); |
| 304 EXPECT_STREQ( | 304 EXPECT_STREQ( |
| 305 "{\"type\":\"Error\",\"text\":\"Field 9 not found\"," | 305 "{\"type\":\"Error\",\"text\":\"Field 9 not found\"," |
| 306 "\"message\":{\"arguments\":[\"classes\",\"1009\",\"fields\",\"9\"]," | 306 "\"message\":{\"arguments\":[\"classes\",\"1009\",\"fields\",\"9\"]," |
| 307 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 307 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); |
| 308 | 308 |
| 309 // Invalid function request. | 309 // Invalid function request. |
| 310 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9']," | 310 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9']," |
| 311 "[], []]", cid); | 311 "[], []]", cid); |
| 312 Service::HandleServiceMessage(isolate, service_msg); | 312 Service::HandleIsolateMessage(isolate, service_msg); |
| 313 handler.HandleNextMessage(); | 313 handler.HandleNextMessage(); |
| 314 EXPECT_STREQ( | 314 EXPECT_STREQ( |
| 315 "{\"type\":\"Error\",\"text\":\"Function 9 not found\"," | 315 "{\"type\":\"Error\",\"text\":\"Function 9 not found\"," |
| 316 "\"message\":{\"arguments\":[\"classes\",\"1009\",\"functions\",\"9\"]," | 316 "\"message\":{\"arguments\":[\"classes\",\"1009\",\"functions\",\"9\"]," |
| 317 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 317 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); |
| 318 | 318 |
| 319 | 319 |
| 320 // Invalid field subcommand. | 320 // Invalid field subcommand. |
| 321 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9', 'x']" | 321 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9', 'x']" |
| 322 ",[], []]", cid); | 322 ",[], []]", cid); |
| 323 Service::HandleServiceMessage(isolate, service_msg); | 323 Service::HandleIsolateMessage(isolate, service_msg); |
| 324 handler.HandleNextMessage(); | 324 handler.HandleNextMessage(); |
| 325 EXPECT_STREQ( | 325 EXPECT_STREQ( |
| 326 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" | 326 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" |
| 327 "{\"arguments\":[\"classes\",\"1009\",\"fields\",\"9\",\"x\"]," | 327 "{\"arguments\":[\"classes\",\"1009\",\"fields\",\"9\",\"x\"]," |
| 328 "\"option_keys\":[],\"option_values\":[]}}", | 328 "\"option_keys\":[],\"option_values\":[]}}", |
| 329 handler.msg()); | 329 handler.msg()); |
| 330 | 330 |
| 331 // Invalid function request. | 331 // Invalid function request. |
| 332 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9'," | 332 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9'," |
| 333 "'x'], [], []]", cid); | 333 "'x'], [], []]", cid); |
| 334 Service::HandleServiceMessage(isolate, service_msg); | 334 Service::HandleIsolateMessage(isolate, service_msg); |
| 335 handler.HandleNextMessage(); | 335 handler.HandleNextMessage(); |
| 336 EXPECT_STREQ( | 336 EXPECT_STREQ( |
| 337 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" | 337 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" |
| 338 "{\"arguments\":[\"classes\",\"1009\",\"functions\",\"9\",\"x\"]," | 338 "{\"arguments\":[\"classes\",\"1009\",\"functions\",\"9\",\"x\"]," |
| 339 "\"option_keys\":[],\"option_values\":[]}}", | 339 "\"option_keys\":[],\"option_values\":[]}}", |
| 340 handler.msg()); | 340 handler.msg()); |
| 341 } | 341 } |
| 342 | 342 |
| 343 | 343 |
| 344 TEST_CASE(Service_Code) { | 344 TEST_CASE(Service_Code) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 Dart_Port port_id = PortMap::CreatePort(&handler); | 383 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 384 Dart_Handle port = | 384 Dart_Handle port = |
| 385 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); | 385 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
| 386 EXPECT_VALID(port); | 386 EXPECT_VALID(port); |
| 387 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | 387 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
| 388 | 388 |
| 389 Instance& service_msg = Instance::Handle(); | 389 Instance& service_msg = Instance::Handle(); |
| 390 | 390 |
| 391 // Request an invalid code object. | 391 // Request an invalid code object. |
| 392 service_msg = Eval(h_lib, "[port, ['code', '0'], [], []]"); | 392 service_msg = Eval(h_lib, "[port, ['code', '0'], [], []]"); |
| 393 Service::HandleServiceMessage(isolate, service_msg); | 393 Service::HandleIsolateMessage(isolate, service_msg); |
| 394 handler.HandleNextMessage(); | 394 handler.HandleNextMessage(); |
| 395 EXPECT_STREQ( | 395 EXPECT_STREQ( |
| 396 "{\"type\":\"Error\",\"text\":\"Could not find code at 0\",\"message\":" | 396 "{\"type\":\"Error\",\"text\":\"Could not find code at 0\",\"message\":" |
| 397 "{\"arguments\":[\"code\",\"0\"]," | 397 "{\"arguments\":[\"code\",\"0\"]," |
| 398 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 398 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); |
| 399 | 399 |
| 400 // The following four tests check that a code object can be found | 400 // The following four tests check that a code object can be found |
| 401 // inside the range: [code.EntryPoint(), code.EntryPoint() + code.Size()). | 401 // inside the range: [code.EntryPoint(), code.EntryPoint() + code.Size()). |
| 402 // Request code object at code.EntryPoint() | 402 // Request code object at code.EntryPoint() |
| 403 // Expect this to succeed as it is inside [entry, entry + size). | 403 // Expect this to succeed as it is inside [entry, entry + size). |
| 404 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", entry); | 404 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", entry); |
| 405 Service::HandleServiceMessage(isolate, service_msg); | 405 Service::HandleIsolateMessage(isolate, service_msg); |
| 406 handler.HandleNextMessage(); | 406 handler.HandleNextMessage(); |
| 407 { | 407 { |
| 408 // Only perform a partial match. | 408 // Only perform a partial match. |
| 409 const intptr_t kBufferSize = 512; | 409 const intptr_t kBufferSize = 512; |
| 410 char buffer[kBufferSize]; | 410 char buffer[kBufferSize]; |
| 411 OS::SNPrint(buffer, kBufferSize-1, | 411 OS::SNPrint(buffer, kBufferSize-1, |
| 412 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | 412 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); |
| 413 EXPECT_SUBSTRING(buffer, handler.msg()); | 413 EXPECT_SUBSTRING(buffer, handler.msg()); |
| 414 } | 414 } |
| 415 | 415 |
| 416 // Request code object at code.EntryPoint() + 16. | 416 // Request code object at code.EntryPoint() + 16. |
| 417 // Expect this to succeed as it is inside [entry, entry + size). | 417 // Expect this to succeed as it is inside [entry, entry + size). |
| 418 uintptr_t address = entry + 16; | 418 uintptr_t address = entry + 16; |
| 419 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | 419 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); |
| 420 Service::HandleServiceMessage(isolate, service_msg); | 420 Service::HandleIsolateMessage(isolate, service_msg); |
| 421 handler.HandleNextMessage(); | 421 handler.HandleNextMessage(); |
| 422 { | 422 { |
| 423 // Only perform a partial match. | 423 // Only perform a partial match. |
| 424 const intptr_t kBufferSize = 512; | 424 const intptr_t kBufferSize = 512; |
| 425 char buffer[kBufferSize]; | 425 char buffer[kBufferSize]; |
| 426 OS::SNPrint(buffer, kBufferSize-1, | 426 OS::SNPrint(buffer, kBufferSize-1, |
| 427 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | 427 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); |
| 428 EXPECT_SUBSTRING(buffer, handler.msg()); | 428 EXPECT_SUBSTRING(buffer, handler.msg()); |
| 429 } | 429 } |
| 430 | 430 |
| 431 // Request code object at code.EntryPoint() + code.Size() - 1. | 431 // Request code object at code.EntryPoint() + code.Size() - 1. |
| 432 // Expect this to succeed as it is inside [entry, entry + size). | 432 // Expect this to succeed as it is inside [entry, entry + size). |
| 433 address = last - 1; | 433 address = last - 1; |
| 434 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | 434 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); |
| 435 Service::HandleServiceMessage(isolate, service_msg); | 435 Service::HandleIsolateMessage(isolate, service_msg); |
| 436 handler.HandleNextMessage(); | 436 handler.HandleNextMessage(); |
| 437 { | 437 { |
| 438 // Only perform a partial match. | 438 // Only perform a partial match. |
| 439 const intptr_t kBufferSize = 512; | 439 const intptr_t kBufferSize = 512; |
| 440 char buffer[kBufferSize]; | 440 char buffer[kBufferSize]; |
| 441 OS::SNPrint(buffer, kBufferSize-1, | 441 OS::SNPrint(buffer, kBufferSize-1, |
| 442 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | 442 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); |
| 443 EXPECT_SUBSTRING(buffer, handler.msg()); | 443 EXPECT_SUBSTRING(buffer, handler.msg()); |
| 444 } | 444 } |
| 445 | 445 |
| 446 // Request code object at code.EntryPoint() + code.Size(). Expect this | 446 // Request code object at code.EntryPoint() + code.Size(). Expect this |
| 447 // to fail as it's outside of [entry, entry + size). | 447 // to fail as it's outside of [entry, entry + size). |
| 448 address = last; | 448 address = last; |
| 449 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | 449 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); |
| 450 Service::HandleServiceMessage(isolate, service_msg); | 450 Service::HandleIsolateMessage(isolate, service_msg); |
| 451 handler.HandleNextMessage(); | 451 handler.HandleNextMessage(); |
| 452 { | 452 { |
| 453 const intptr_t kBufferSize = 1024; | 453 const intptr_t kBufferSize = 1024; |
| 454 char buffer[kBufferSize]; | 454 char buffer[kBufferSize]; |
| 455 OS::SNPrint(buffer, kBufferSize-1, | 455 OS::SNPrint(buffer, kBufferSize-1, |
| 456 "{\"type\":\"Error\",\"text\":\"Could not find code at %" Px "\"," | 456 "{\"type\":\"Error\",\"text\":\"Could not find code at %" Px "\"," |
| 457 "\"message\":{\"arguments\":[\"code\",\"%" Px "\"]," | 457 "\"message\":{\"arguments\":[\"code\",\"%" Px "\"]," |
| 458 "\"option_keys\":[],\"option_values\":[]}}", address, address); | 458 "\"option_keys\":[],\"option_values\":[]}}", address, address); |
| 459 EXPECT_STREQ(buffer, handler.msg()); | 459 EXPECT_STREQ(buffer, handler.msg()); |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 |
| 464 TEST_CASE(Service_Cpu) { |
| 465 const char* kScript = |
| 466 "var port;\n" // Set to our mock port by C++. |
| 467 "\n" |
| 468 "main() {\n" // We set breakpoint here. |
| 469 "}"; |
| 470 |
| 471 Isolate* isolate = Isolate::Current(); |
| 472 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 473 EXPECT_VALID(lib); |
| 474 |
| 475 // Build a mock message handler and wrap it in a dart port. |
| 476 ServiceTestMessageHandler handler; |
| 477 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 478 Dart_Handle port = |
| 479 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
| 480 EXPECT_VALID(port); |
| 481 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 482 |
| 483 Instance& service_msg = Instance::Handle(); |
| 484 service_msg = Eval(lib, "[port, ['cpu'], [], []]"); |
| 485 |
| 486 Service::HandleRootMessage(service_msg); |
| 487 handler.HandleNextMessage(); |
| 488 EXPECT_SUBSTRING("\"type\":\"CPU\"", handler.msg()); |
| 489 } |
| 490 |
| 463 } // namespace dart | 491 } // namespace dart |
| OLD | NEW |