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

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

Issue 13009004: Added EXPECT_TRUE macro, updated debugger unit tests to use it for (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | « no previous file | runtime/vm/unit_test.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/thread.h" 8 #include "vm/thread.h"
9 #include "vm/unit_test.h" 9 #include "vm/unit_test.h"
10 10
(...skipping 16 matching lines...) Expand all
27 27
28 static void SetBreakpointAtEntry(const char* cname, const char* fname) { 28 static void SetBreakpointAtEntry(const char* cname, const char* fname) {
29 ASSERT(script_lib != NULL); 29 ASSERT(script_lib != NULL);
30 ASSERT(!Dart_IsError(script_lib)); 30 ASSERT(!Dart_IsError(script_lib));
31 ASSERT(Dart_IsLibrary(script_lib)); 31 ASSERT(Dart_IsLibrary(script_lib));
32 Dart_Breakpoint bpt; 32 Dart_Breakpoint bpt;
33 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib, 33 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib,
34 NewString(cname), 34 NewString(cname),
35 NewString(fname), 35 NewString(fname),
36 &bpt); 36 &bpt);
37 EXPECT_VALID(res); 37 EXPECT_TRUE(res);
38 } 38 }
39 39
40 40
41 static Dart_Handle Invoke(const char* func_name) { 41 static Dart_Handle Invoke(const char* func_name) {
42 ASSERT(script_lib != NULL); 42 ASSERT(script_lib != NULL);
43 ASSERT(!Dart_IsError(script_lib)); 43 ASSERT(!Dart_IsError(script_lib));
44 ASSERT(Dart_IsLibrary(script_lib)); 44 ASSERT(Dart_IsLibrary(script_lib));
45 return Dart_Invoke(script_lib, NewString(func_name), 0, NULL); 45 return Dart_Invoke(script_lib, NewString(func_name), 0, NULL);
46 } 46 }
47 47
48 48
49 static char const* ToCString(Dart_Handle str) { 49 static char const* ToCString(Dart_Handle str) {
50 EXPECT(Dart_IsString(str)); 50 EXPECT(Dart_IsString(str));
51 char const* c_str = NULL; 51 char const* c_str = NULL;
52 Dart_StringToCString(str, &c_str); 52 Dart_StringToCString(str, &c_str);
53 return c_str; 53 return c_str;
54 } 54 }
55 55
56 56
57 static char const* BreakpointInfo(Dart_StackTrace trace) { 57 static char const* BreakpointInfo(Dart_StackTrace trace) {
58 static char info_str[128]; 58 static char info_str[128];
59 Dart_ActivationFrame frame; 59 Dart_ActivationFrame frame;
60 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame); 60 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame);
61 EXPECT_VALID(res); 61 EXPECT_TRUE(res);
62 Dart_Handle func_name; 62 Dart_Handle func_name;
63 Dart_Handle url; 63 Dart_Handle url;
64 intptr_t line_number = 0; 64 intptr_t line_number = 0;
65 intptr_t library_id = 0; 65 intptr_t library_id = 0;
66 res = Dart_ActivationFrameInfo( 66 res = Dart_ActivationFrameInfo(
67 frame, &func_name, &url, &line_number, &library_id); 67 frame, &func_name, &url, &line_number, &library_id);
68 EXPECT_VALID(res); 68 EXPECT_TRUE(res);
69 OS::SNPrint(info_str, sizeof(info_str), "function %s (%s:%"Pd")", 69 OS::SNPrint(info_str, sizeof(info_str), "function %s (%s:%"Pd")",
70 ToCString(func_name), ToCString(url), line_number); 70 ToCString(func_name), ToCString(url), line_number);
71 return info_str; 71 return info_str;
72 } 72 }
73 73
74 74
75 static void PrintValue(Dart_Handle value, bool expand); 75 static void PrintValue(Dart_Handle value, bool expand);
76 76
77 77
78 static void PrintObjectList(Dart_Handle list, const char* prefix, bool expand) { 78 static void PrintObjectList(Dart_Handle list, const char* prefix, bool expand) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } else { 126 } else {
127 PrintObject(value, expand); 127 PrintObject(value, expand);
128 } 128 }
129 } 129 }
130 130
131 131
132 static void PrintActivationFrame(Dart_ActivationFrame frame) { 132 static void PrintActivationFrame(Dart_ActivationFrame frame) {
133 Dart_Handle func_name; 133 Dart_Handle func_name;
134 Dart_Handle res; 134 Dart_Handle res;
135 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); 135 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL);
136 EXPECT_VALID(res); 136 EXPECT_TRUE(res);
137 EXPECT(Dart_IsString(func_name)); 137 EXPECT(Dart_IsString(func_name));
138 const char* func_name_chars; 138 const char* func_name_chars;
139 Dart_StringToCString(func_name, &func_name_chars); 139 Dart_StringToCString(func_name, &func_name_chars);
140 OS::Print(" function %s\n", func_name_chars); 140 OS::Print(" function %s\n", func_name_chars);
141 Dart_Handle locals = Dart_GetLocalVariables(frame); 141 Dart_Handle locals = Dart_GetLocalVariables(frame);
142 EXPECT_VALID(locals); 142 EXPECT_VALID(locals);
143 intptr_t list_length = 0; 143 intptr_t list_length = 0;
144 Dart_Handle ret = Dart_ListLength(locals, &list_length); 144 Dart_Handle ret = Dart_ListLength(locals, &list_length);
145 EXPECT_VALID(ret); 145 EXPECT_VALID(ret);
146 for (int i = 0; i + 1 < list_length; i += 2) { 146 for (int i = 0; i + 1 < list_length; i += 2) {
147 Dart_Handle name_handle = Dart_ListGetAt(locals, i); 147 Dart_Handle name_handle = Dart_ListGetAt(locals, i);
148 EXPECT_VALID(name_handle); 148 EXPECT_VALID(name_handle);
149 EXPECT(Dart_IsString(name_handle)); 149 EXPECT(Dart_IsString(name_handle));
150 OS::Print(" local var %s = ", ToCString(name_handle)); 150 OS::Print(" local var %s = ", ToCString(name_handle));
151 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1); 151 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1);
152 EXPECT_VALID(value_handle); 152 EXPECT_VALID(value_handle);
153 PrintValue(value_handle, true); 153 PrintValue(value_handle, true);
154 OS::Print("\n"); 154 OS::Print("\n");
155 } 155 }
156 } 156 }
157 157
158 158
159 static void PrintStackTrace(Dart_StackTrace trace) { 159 static void PrintStackTrace(Dart_StackTrace trace) {
160 intptr_t trace_len; 160 intptr_t trace_len;
161 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 161 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
162 EXPECT_VALID(res); 162 EXPECT_TRUE(res);
163 for (int i = 0; i < trace_len; i++) { 163 for (int i = 0; i < trace_len; i++) {
164 Dart_ActivationFrame frame; 164 Dart_ActivationFrame frame;
165 res = Dart_GetActivationFrame(trace, i, &frame); 165 res = Dart_GetActivationFrame(trace, i, &frame);
166 EXPECT_VALID(res); 166 EXPECT_TRUE(res);
167 PrintActivationFrame(frame); 167 PrintActivationFrame(frame);
168 } 168 }
169 } 169 }
170 170
171 171
172 static void VerifyListEquals(Dart_Handle expected, 172 static void VerifyListEquals(Dart_Handle expected,
173 Dart_Handle got, 173 Dart_Handle got,
174 bool skip_null_expects) { 174 bool skip_null_expects) {
175 EXPECT(Dart_IsList(expected)); 175 EXPECT(Dart_IsList(expected));
176 EXPECT(Dart_IsList(got)); 176 EXPECT(Dart_IsList(got));
(...skipping 18 matching lines...) Expand all
195 } 195 }
196 196
197 197
198 static void VerifyStackFrame(Dart_ActivationFrame frame, 198 static void VerifyStackFrame(Dart_ActivationFrame frame,
199 const char* expected_name, 199 const char* expected_name,
200 Dart_Handle expected_locals, 200 Dart_Handle expected_locals,
201 bool skip_null_expects) { 201 bool skip_null_expects) {
202 Dart_Handle func_name; 202 Dart_Handle func_name;
203 Dart_Handle res; 203 Dart_Handle res;
204 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); 204 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL);
205 EXPECT_VALID(res); 205 EXPECT_TRUE(res);
206 EXPECT(Dart_IsString(func_name)); 206 EXPECT(Dart_IsString(func_name));
207 const char* func_name_chars; 207 const char* func_name_chars;
208 Dart_StringToCString(func_name, &func_name_chars); 208 Dart_StringToCString(func_name, &func_name_chars);
209 if (expected_name != NULL) { 209 if (expected_name != NULL) {
210 EXPECT_SUBSTRING(expected_name, func_name_chars); 210 EXPECT_SUBSTRING(expected_name, func_name_chars);
211 } 211 }
212 212
213 if (!Dart_IsNull(expected_locals)) { 213 if (!Dart_IsNull(expected_locals)) {
214 Dart_Handle locals = Dart_GetLocalVariables(frame); 214 Dart_Handle locals = Dart_GetLocalVariables(frame);
215 EXPECT_VALID(locals); 215 EXPECT_VALID(locals);
216 VerifyListEquals(expected_locals, locals, skip_null_expects); 216 VerifyListEquals(expected_locals, locals, skip_null_expects);
217 } 217 }
218 } 218 }
219 219
220 220
221 static void VerifyStackTrace(Dart_StackTrace trace, 221 static void VerifyStackTrace(Dart_StackTrace trace,
222 const char* func_names[], 222 const char* func_names[],
223 Dart_Handle local_vars[], 223 Dart_Handle local_vars[],
224 int expected_frames, 224 int expected_frames,
225 bool skip_null_expects) { 225 bool skip_null_expects) {
226 intptr_t trace_len; 226 intptr_t trace_len;
227 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 227 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
228 EXPECT_VALID(res); 228 EXPECT_TRUE(res);
229 for (int i = 0; i < trace_len; i++) { 229 for (int i = 0; i < trace_len; i++) {
230 Dart_ActivationFrame frame; 230 Dart_ActivationFrame frame;
231 res = Dart_GetActivationFrame(trace, i, &frame); 231 res = Dart_GetActivationFrame(trace, i, &frame);
232 EXPECT_VALID(res); 232 EXPECT_TRUE(res);
233 if (i < expected_frames) { 233 if (i < expected_frames) {
234 VerifyStackFrame(frame, func_names[i], local_vars[i], skip_null_expects); 234 VerifyStackFrame(frame, func_names[i], local_vars[i], skip_null_expects);
235 } else { 235 } else {
236 VerifyStackFrame(frame, NULL, Dart_Null(), skip_null_expects); 236 VerifyStackFrame(frame, NULL, Dart_Null(), skip_null_expects);
237 } 237 }
238 } 238 }
239 } 239 }
240 240
241 241
242 void TestBreakpointHandler(Dart_IsolateId isolate_id, 242 void TestBreakpointHandler(Dart_IsolateId isolate_id,
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 1545
1546 Dart_Handle retval = Invoke("main"); 1546 Dart_Handle retval = Invoke("main");
1547 EXPECT(Dart_IsError(retval)); 1547 EXPECT(Dart_IsError(retval));
1548 EXPECT(Dart_IsUnhandledExceptionError(retval)); 1548 EXPECT(Dart_IsUnhandledExceptionError(retval));
1549 EXPECT_EQ(1, breakpoint_hit_counter); 1549 EXPECT_EQ(1, breakpoint_hit_counter);
1550 } 1550 }
1551 1551
1552 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1552 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1553 1553
1554 } // namespace dart 1554 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698