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

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

Issue 113513004: Handle vmservice messages while at breakpoint. (Closed) Base URL: http://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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "include/dart_debugger_api.h"
6 #include "vm/dart_api_impl.h"
7 #include "vm/debugger.h"
8 #include "vm/globals.h"
9 #include "vm/message_handler.h"
10 #include "vm/os.h"
11 #include "vm/port.h"
12 #include "vm/service.h"
13 #include "vm/unit_test.h"
14
15 namespace dart {
16
17 class ServiceTestMessageHandler : public MessageHandler {
18 public:
19 ServiceTestMessageHandler() : _msg(NULL) {}
20
21 ~ServiceTestMessageHandler() {
22 free(_msg);
23 }
24
25 bool HandleMessage(Message* message) {
26 if (_msg != NULL) {
27 free(_msg);
28 }
29
30 // Parse the message.
31 SnapshotReader reader(message->data(), message->len(),
32 Snapshot::kMessage, Isolate::Current());
33 const Object& response_obj = Object::Handle(reader.ReadObject());
34 String& response = String::Handle();
35 response ^= response_obj.raw();
36 _msg = strdup(response.ToCString());
37 return true;
38 }
39
40 const char* msg() const { return _msg; }
41
42 private:
43 char* _msg;
44 };
45
46
47 static RawInstance* Eval(Dart_Handle lib, const char* expr) {
48 Dart_Handle result = Dart_EvaluateExpr(lib, NewString(expr));
49 EXPECT_VALID(result);
50 Isolate* isolate = Isolate::Current();
51 const Instance& instance = Api::UnwrapInstanceHandle(isolate, result);
52 return instance.raw();
53 }
54
55
56 TEST_CASE(Service_DebugBreakpoints) {
57 Isolate* isolate = Isolate::Current();
58 Dart_Handle lib = TestCase::LoadTestScript("main() {\n}\n", NULL);
59 EXPECT_VALID(lib);
60 ServiceTestMessageHandler handler;
61 Dart_Port port = PortMap::CreatePort(&handler);
62 Instance& service_msg = Instance::Handle();
63
64 // Add a breakpoint.
65 const String& url = String::Handle(String::New(TestCase::url()));
66 isolate->debugger()->SetBreakpointAtLine(url, 1);
67
68 // Get the breakpoint list.
69 service_msg = Eval(lib, "[['debug', 'breakpoints'], [], []]");
70 Service::HandleServiceMessage(isolate, port, service_msg);
71 handler.HandleNextMessage();
72 EXPECT_STREQ(
73 "{\"type\":\"BreakpointList\",\"breakpoints\":[{"
74 "\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true,"
75 "\"resolved\":false,"
76 "\"location\":{\"type\":\"Location\",\"libId\":12,"
77 "\"script\":\"dart:test-lib\",\"tokenPos\":0}}]}",
78 handler.msg());
79
80 // Individual breakpoint.
81 service_msg = Eval(lib, "[['debug', 'breakpoints', '1'], [], []]");
82 Service::HandleServiceMessage(isolate, port, service_msg);
83 handler.HandleNextMessage();
84 EXPECT_STREQ(
85 "{\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true,"
86 "\"resolved\":false,"
87 "\"location\":{\"type\":\"Location\",\"libId\":12,"
88 "\"script\":\"dart:test-lib\",\"tokenPos\":0}}",
89 handler.msg());
90
91 // Missing sub-command.
92 service_msg = Eval(lib, "[['debug'], [], []]");
93 Service::HandleServiceMessage(isolate, port, service_msg);
94 handler.HandleNextMessage();
95 EXPECT_STREQ(
96 "{\"type\":\"Error\","
97 "\"text\":\"Must specify a subcommand\","
98 "\"message\":{\"arguments\":[\"debug\"],\"option_keys\":[],"
99 "\"option_values\":[]}}",
100 handler.msg());
101
102 // Unrecognized breakpoint.
103 service_msg = Eval(lib, "[['debug', 'breakpoints', '1111'], [], []]");
104 Service::HandleServiceMessage(isolate, port, service_msg);
105 handler.HandleNextMessage();
106 EXPECT_STREQ("{\"type\":\"Error\","
107 "\"text\":\"Unrecognized breakpoint id 1111\","
108 "\"message\":{"
109 "\"arguments\":[\"debug\",\"breakpoints\",\"1111\"],"
110 "\"option_keys\":[],\"option_values\":[]}}",
111 handler.msg());
112
113 // Command too long.
114 service_msg =
115 Eval(lib, "[['debug', 'breakpoints', '1111', 'green'], [], []]");
116 Service::HandleServiceMessage(isolate, port, service_msg);
117 handler.HandleNextMessage();
118 EXPECT_STREQ("{\"type\":\"Error\",\"text\":\"Command too long\","
119 "\"message\":{\"arguments\":[\"debug\",\"breakpoints\","
120 "\"1111\",\"green\"],"
121 "\"option_keys\":[],\"option_values\":[]}}",
122 handler.msg());
123
124 // Unrecognized subcommand.
125 service_msg =
126 Eval(lib, "[['debug', 'nosferatu'], [], []]");
127 Service::HandleServiceMessage(isolate, port, service_msg);
128 handler.HandleNextMessage();
129 EXPECT_STREQ("{\"type\":\"Error\","
130 "\"text\":\"Unrecognized subcommand 'nosferatu'\","
131 "\"message\":{\"arguments\":[\"debug\",\"nosferatu\"],"
132 "\"option_keys\":[],\"option_values\":[]}}",
133 handler.msg());
134 }
135
136 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698