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

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

Issue 145323002: Post-meetup feature extravaganza. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/service/running_isolates.dart ('k') | runtime/vm/timer.h » ('j') | 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 "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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 82
83 static RawClass* GetClass(const Library& lib, const char* name) { 83 static RawClass* GetClass(const Library& lib, const char* name) {
84 const Class& cls = Class::Handle( 84 const Class& cls = Class::Handle(
85 lib.LookupClass(String::Handle(Symbols::New(name)))); 85 lib.LookupClass(String::Handle(Symbols::New(name))));
86 EXPECT(!cls.IsNull()); // No ambiguity error expected. 86 EXPECT(!cls.IsNull()); // No ambiguity error expected.
87 return cls.raw(); 87 return cls.raw();
88 } 88 }
89 89
90 90
91 TEST_CASE(Service_Isolate) {
92 const char* kScript =
93 "var port;\n" // Set to our mock port by C++.
94 "\n"
95 "main() {\n"
96 "}";
97
98 Isolate* isolate = Isolate::Current();
99 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
100 EXPECT_VALID(lib);
101
102 // Build a mock message handler and wrap it in a dart port.
103 ServiceTestMessageHandler handler;
104 Dart_Port port_id = PortMap::CreatePort(&handler);
105 Dart_Handle port =
106 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id));
107 EXPECT_VALID(port);
108 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
109
110 Instance& service_msg = Instance::Handle();
111
112 // Get the isolate summary.
113 service_msg = Eval(lib, "[port, [], [], []]");
114 Service::HandleIsolateMessage(isolate, service_msg);
115 handler.HandleNextMessage();
116
117 JSONReader reader(handler.msg());
118
119 const int kBufferSize = 128;
120 char buffer[kBufferSize];
121
122 // Check that the response string is somewhat sane.
123
124 // type
125 EXPECT(reader.Seek("type"));
126 EXPECT_EQ(reader.Type(), JSONReader::kString);
127 reader.GetDecodedValueChars(buffer, kBufferSize);
128 EXPECT_STREQ("Isolate", buffer);
129
130 // id
131 EXPECT(reader.Seek("id"));
132 EXPECT_EQ(reader.Type(), JSONReader::kString);
133 reader.GetDecodedValueChars(buffer, kBufferSize);
134 EXPECT_SUBSTRING("isolates/", buffer);
135
136 // heap
137 EXPECT(reader.Seek("heap"));
138 EXPECT_EQ(reader.Type(), JSONReader::kObject);
139
140 // timers
141 EXPECT(reader.Seek("timers"));
142 EXPECT_EQ(reader.Type(), JSONReader::kArray);
143 }
144
145
146 TEST_CASE(Service_StackTrace) {
147 // TODO(turnidge): Extend this test to cover a non-trivial stack trace.
148 const char* kScript =
149 "var port;\n" // Set to our mock port by C++.
150 "\n"
151 "main() {\n"
152 "}";
153
154 Isolate* isolate = Isolate::Current();
155 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
156 EXPECT_VALID(lib);
157
158 // Build a mock message handler and wrap it in a dart port.
159 ServiceTestMessageHandler handler;
160 Dart_Port port_id = PortMap::CreatePort(&handler);
161 Dart_Handle port =
162 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id));
163 EXPECT_VALID(port);
164 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
165
166 Instance& service_msg = Instance::Handle();
167
168 // Get the stacktrace.
169 service_msg = Eval(lib, "[port, ['stacktrace'], [], []]");
170 Service::HandleIsolateMessage(isolate, service_msg);
171 handler.HandleNextMessage();
172 EXPECT_STREQ(
173 "{\"type\":\"StackTrace\",\"members\":[]}",
174 handler.msg());
175
176 // Malformed request.
177 service_msg = Eval(lib, "[port, ['stacktrace', 'jamboree'], [], []]");
178 Service::HandleIsolateMessage(isolate, service_msg);
179 handler.HandleNextMessage();
180 EXPECT_STREQ(
181 "{\"type\":\"Error\",\"text\":\"Command too long\","
182 "\"message\":{\"arguments\":[\"stacktrace\",\"jamboree\"],"
183 "\"option_keys\":[],\"option_values\":[]}}",
184 handler.msg());
185 }
186
187
91 TEST_CASE(Service_DebugBreakpoints) { 188 TEST_CASE(Service_DebugBreakpoints) {
92 const char* kScript = 189 const char* kScript =
93 "var port;\n" // Set to our mock port by C++. 190 "var port;\n" // Set to our mock port by C++.
94 "\n" 191 "\n"
95 "main() {\n" // We set breakpoint here. 192 "main() {\n" // We set breakpoint here.
96 "}"; 193 "}";
97 194
98 Isolate* isolate = Isolate::Current(); 195 Isolate* isolate = Isolate::Current();
99 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 196 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
100 EXPECT_VALID(lib); 197 EXPECT_VALID(lib);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 "\"option_keys\":[],\"option_values\":[]}}", address, address); 555 "\"option_keys\":[],\"option_values\":[]}}", address, address);
459 EXPECT_STREQ(buffer, handler.msg()); 556 EXPECT_STREQ(buffer, handler.msg());
460 } 557 }
461 } 558 }
462 559
463 560
464 TEST_CASE(Service_Cpu) { 561 TEST_CASE(Service_Cpu) {
465 const char* kScript = 562 const char* kScript =
466 "var port;\n" // Set to our mock port by C++. 563 "var port;\n" // Set to our mock port by C++.
467 "\n" 564 "\n"
468 "main() {\n" // We set breakpoint here. 565 "main() {\n"
469 "}"; 566 "}";
470 567
471 Isolate* isolate = Isolate::Current(); 568 Isolate* isolate = Isolate::Current();
472 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 569 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
473 EXPECT_VALID(lib); 570 EXPECT_VALID(lib);
474 571
475 // Build a mock message handler and wrap it in a dart port. 572 // Build a mock message handler and wrap it in a dart port.
476 ServiceTestMessageHandler handler; 573 ServiceTestMessageHandler handler;
477 Dart_Port port_id = PortMap::CreatePort(&handler); 574 Dart_Port port_id = PortMap::CreatePort(&handler);
478 Dart_Handle port = 575 Dart_Handle port =
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 handler.HandleNextMessage(); 619 handler.HandleNextMessage();
523 EXPECT_SUBSTRING( 620 EXPECT_SUBSTRING(
524 "{\"source\":\"dart:test-lib\",\"script\":{" 621 "{\"source\":\"dart:test-lib\",\"script\":{"
525 "\"type\":\"@Script\",\"id\":\"scripts\\/dart%3Atest-lib\"," 622 "\"type\":\"@Script\",\"id\":\"scripts\\/dart%3Atest-lib\","
526 "\"name\":\"dart:test-lib\",\"user_name\":\"dart:test-lib\"," 623 "\"name\":\"dart:test-lib\",\"user_name\":\"dart:test-lib\","
527 "\"kind\":\"script\"},\"hits\":" 624 "\"kind\":\"script\"},\"hits\":"
528 "[3,0,3,1,5,1,5,1,5,1,6,1,6,1]}", handler.msg()); 625 "[3,0,3,1,5,1,5,1,5,1,6,1,6,1]}", handler.msg());
529 } 626 }
530 627
531 } // namespace dart 628 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service/running_isolates.dart ('k') | runtime/vm/timer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698