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

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

Issue 2572563004: Improve the casing of Stackmap and Stacktrace. (Closed)
Patch Set: Build fixes Created 4 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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.cc » ('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 "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "vm/compiler.h" 6 #include "vm/compiler.h"
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 EXPECT_STREQ( 52 EXPECT_STREQ(
53 "Unhandled exception:\n" 53 "Unhandled exception:\n"
54 "Exception: bad news\n" 54 "Exception: bad news\n"
55 "#0 testMain (test-lib:2:3)", 55 "#0 testMain (test-lib:2:3)",
56 Dart_GetError(exception)); 56 Dart_GetError(exception));
57 57
58 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); 58 EXPECT(Dart_IsError(Dart_ErrorGetException(instance)));
59 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); 59 EXPECT(Dart_IsError(Dart_ErrorGetException(error)));
60 EXPECT_VALID(Dart_ErrorGetException(exception)); 60 EXPECT_VALID(Dart_ErrorGetException(exception));
61 61
62 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); 62 EXPECT(Dart_IsError(Dart_ErrorGetStackTrace(instance)));
63 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); 63 EXPECT(Dart_IsError(Dart_ErrorGetStackTrace(error)));
64 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); 64 EXPECT_VALID(Dart_ErrorGetStackTrace(exception));
65 } 65 }
66 66
67 67
68 TEST_CASE(StacktraceInfo) { 68 TEST_CASE(StackTraceInfo) {
69 const char* kScriptChars = 69 const char* kScriptChars =
70 "bar() => throw new Error();\n" 70 "bar() => throw new Error();\n"
71 "foo() => bar();\n" 71 "foo() => bar();\n"
72 "testMain() => foo();\n"; 72 "testMain() => foo();\n";
73 73
74 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 74 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
75 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 75 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
76 76
77 EXPECT(Dart_IsError(error)); 77 EXPECT(Dart_IsError(error));
78 78
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 EXPECT_EQ(15, column_number); 129 EXPECT_EQ(15, column_number);
130 130
131 // Out-of-bounds frames. 131 // Out-of-bounds frames.
132 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); 132 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame);
133 EXPECT(Dart_IsError(result)); 133 EXPECT(Dart_IsError(result));
134 result = Dart_GetActivationFrame(stacktrace, -1, &frame); 134 result = Dart_GetActivationFrame(stacktrace, -1, &frame);
135 EXPECT(Dart_IsError(result)); 135 EXPECT(Dart_IsError(result));
136 } 136 }
137 137
138 138
139 TEST_CASE(DeepStacktraceInfo) { 139 TEST_CASE(DeepStackTraceInfo) {
140 const char* kScriptChars = 140 const char* kScriptChars =
141 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n" 141 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n"
142 "testMain() => foo(50);\n"; 142 "testMain() => foo(50);\n";
143 143
144 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 144 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
145 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 145 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
146 146
147 EXPECT(Dart_IsError(error)); 147 EXPECT(Dart_IsError(error));
148 148
149 Dart_StackTrace stacktrace; 149 Dart_StackTrace stacktrace;
150 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); 150 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace);
151 EXPECT_VALID(result); 151 EXPECT_VALID(result);
152 152
153 intptr_t frame_count = 0; 153 intptr_t frame_count = 0;
154 result = Dart_StackTraceLength(stacktrace, &frame_count); 154 result = Dart_StackTraceLength(stacktrace, &frame_count);
155 EXPECT_VALID(result); 155 EXPECT_VALID(result);
156 EXPECT_EQ(51, frame_count); 156 EXPECT_EQ(51, frame_count);
157 // Test something bigger than the preallocated size to verify nothing was 157 // Test something bigger than the preallocated size to verify nothing was
158 // truncated. 158 // truncated.
159 EXPECT(51 > Stacktrace::kPreallocatedStackdepth); 159 EXPECT(51 > StackTrace::kPreallocatedStackdepth);
160 160
161 Dart_Handle function_name; 161 Dart_Handle function_name;
162 Dart_Handle script_url; 162 Dart_Handle script_url;
163 intptr_t line_number = 0; 163 intptr_t line_number = 0;
164 intptr_t column_number = 0; 164 intptr_t column_number = 0;
165 const char* cstr = ""; 165 const char* cstr = "";
166 166
167 // Top frame at positioned at throw. 167 // Top frame at positioned at throw.
168 Dart_ActivationFrame frame; 168 Dart_ActivationFrame frame;
169 result = Dart_GetActivationFrame(stacktrace, 0, &frame); 169 result = Dart_GetActivationFrame(stacktrace, 0, &frame);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 EXPECT_EQ(15, column_number); 208 EXPECT_EQ(15, column_number);
209 209
210 // Out-of-bounds frames. 210 // Out-of-bounds frames.
211 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); 211 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame);
212 EXPECT(Dart_IsError(result)); 212 EXPECT(Dart_IsError(result));
213 result = Dart_GetActivationFrame(stacktrace, -1, &frame); 213 result = Dart_GetActivationFrame(stacktrace, -1, &frame);
214 EXPECT(Dart_IsError(result)); 214 EXPECT(Dart_IsError(result));
215 } 215 }
216 216
217 217
218 TEST_CASE(StackOverflowStacktraceInfo) { 218 TEST_CASE(StackOverflowStackTraceInfo) {
219 const char* kScriptChars = 219 const char* kScriptChars =
220 "class C {\n" 220 "class C {\n"
221 " static foo() => foo();\n" 221 " static foo() => foo();\n"
222 "}\n" 222 "}\n"
223 "testMain() => C.foo();\n"; 223 "testMain() => C.foo();\n";
224 224
225 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 225 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
226 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 226 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
227 227
228 EXPECT(Dart_IsError(error)); 228 EXPECT(Dart_IsError(error));
229 229
230 Dart_StackTrace stacktrace; 230 Dart_StackTrace stacktrace;
231 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); 231 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace);
232 EXPECT_VALID(result); 232 EXPECT_VALID(result);
233 233
234 intptr_t frame_count = 0; 234 intptr_t frame_count = 0;
235 result = Dart_StackTraceLength(stacktrace, &frame_count); 235 result = Dart_StackTraceLength(stacktrace, &frame_count);
236 EXPECT_VALID(result); 236 EXPECT_VALID(result);
237 EXPECT_EQ(Stacktrace::kPreallocatedStackdepth - 1, frame_count); 237 EXPECT_EQ(StackTrace::kPreallocatedStackdepth - 1, frame_count);
238 238
239 Dart_Handle function_name; 239 Dart_Handle function_name;
240 Dart_Handle script_url; 240 Dart_Handle script_url;
241 intptr_t line_number = 0; 241 intptr_t line_number = 0;
242 intptr_t column_number = 0; 242 intptr_t column_number = 0;
243 const char* cstr = ""; 243 const char* cstr = "";
244 244
245 // Top frame at recursive call. 245 // Top frame at recursive call.
246 Dart_ActivationFrame frame; 246 Dart_ActivationFrame frame;
247 result = Dart_GetActivationFrame(stacktrace, 0, &frame); 247 result = Dart_GetActivationFrame(stacktrace, 0, &frame);
248 EXPECT_VALID(result); 248 EXPECT_VALID(result);
249 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url, 249 result = Dart_ActivationFrameInfo(frame, &function_name, &script_url,
250 &line_number, &column_number); 250 &line_number, &column_number);
251 EXPECT_VALID(result); 251 EXPECT_VALID(result);
252 Dart_StringToCString(function_name, &cstr); 252 Dart_StringToCString(function_name, &cstr);
253 EXPECT_STREQ("C.foo", cstr); 253 EXPECT_STREQ("C.foo", cstr);
254 Dart_StringToCString(script_url, &cstr); 254 Dart_StringToCString(script_url, &cstr);
255 EXPECT_STREQ("test-lib", cstr); 255 EXPECT_STREQ("test-lib", cstr);
256 EXPECT_EQ(2, line_number); 256 EXPECT_EQ(2, line_number);
257 EXPECT_EQ(13, column_number); 257 EXPECT_EQ(13, column_number);
258 258
259 // Out-of-bounds frames. 259 // Out-of-bounds frames.
260 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); 260 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame);
261 EXPECT(Dart_IsError(result)); 261 EXPECT(Dart_IsError(result));
262 result = Dart_GetActivationFrame(stacktrace, -1, &frame); 262 result = Dart_GetActivationFrame(stacktrace, -1, &frame);
263 EXPECT(Dart_IsError(result)); 263 EXPECT(Dart_IsError(result));
264 } 264 }
265 265
266 266
267 TEST_CASE(OutOfMemoryStacktraceInfo) { 267 TEST_CASE(OutOfMemoryStackTraceInfo) {
268 const char* kScriptChars = 268 const char* kScriptChars =
269 "var number_of_ints = 134000000;\n" 269 "var number_of_ints = 134000000;\n"
270 "testMain() {\n" 270 "testMain() {\n"
271 " new List<int>(number_of_ints)\n" 271 " new List<int>(number_of_ints)\n"
272 "}\n"; 272 "}\n";
273 273
274 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 274 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
275 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 275 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
276 276
277 EXPECT(Dart_IsError(error)); 277 EXPECT(Dart_IsError(error));
278 278
279 Dart_StackTrace stacktrace; 279 Dart_StackTrace stacktrace;
280 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); 280 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace);
281 EXPECT(Dart_IsError(result)); // No Stacktrace for OutOfMemory. 281 EXPECT(Dart_IsError(result)); // No StackTrace for OutOfMemory.
282 } 282 }
283 283
284 284
285 void CurrentStackTraceNative(Dart_NativeArguments args) { 285 void CurrentStackTraceNative(Dart_NativeArguments args) {
286 Dart_EnterScope(); 286 Dart_EnterScope();
287 287
288 Dart_StackTrace stacktrace; 288 Dart_StackTrace stacktrace;
289 Dart_Handle result = Dart_GetStackTrace(&stacktrace); 289 Dart_Handle result = Dart_GetStackTrace(&stacktrace);
290 EXPECT_VALID(result); 290 EXPECT_VALID(result);
291 291
292 intptr_t frame_count = 0; 292 intptr_t frame_count = 0;
293 result = Dart_StackTraceLength(stacktrace, &frame_count); 293 result = Dart_StackTraceLength(stacktrace, &frame_count);
294 EXPECT_VALID(result); 294 EXPECT_VALID(result);
295 EXPECT_EQ(52, frame_count); 295 EXPECT_EQ(52, frame_count);
296 // Test something bigger than the preallocated size to verify nothing was 296 // Test something bigger than the preallocated size to verify nothing was
297 // truncated. 297 // truncated.
298 EXPECT(52 > Stacktrace::kPreallocatedStackdepth); 298 EXPECT(52 > StackTrace::kPreallocatedStackdepth);
299 299
300 Dart_Handle function_name; 300 Dart_Handle function_name;
301 Dart_Handle script_url; 301 Dart_Handle script_url;
302 intptr_t line_number = 0; 302 intptr_t line_number = 0;
303 intptr_t column_number = 0; 303 intptr_t column_number = 0;
304 const char* cstr = ""; 304 const char* cstr = "";
305 305
306 // Top frame is inspectStack(). 306 // Top frame is inspectStack().
307 Dart_ActivationFrame frame; 307 Dart_ActivationFrame frame;
308 result = Dart_GetActivationFrame(stacktrace, 0, &frame); 308 result = Dart_GetActivationFrame(stacktrace, 0, &frame);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 static Dart_NativeFunction CurrentStackTraceNativeLookup( 373 static Dart_NativeFunction CurrentStackTraceNativeLookup(
374 Dart_Handle name, 374 Dart_Handle name,
375 int argument_count, 375 int argument_count,
376 bool* auto_setup_scope) { 376 bool* auto_setup_scope) {
377 ASSERT(auto_setup_scope != NULL); 377 ASSERT(auto_setup_scope != NULL);
378 *auto_setup_scope = true; 378 *auto_setup_scope = true;
379 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative); 379 return reinterpret_cast<Dart_NativeFunction>(&CurrentStackTraceNative);
380 } 380 }
381 381
382 382
383 TEST_CASE(CurrentStacktraceInfo) { 383 TEST_CASE(CurrentStackTraceInfo) {
384 const char* kScriptChars = 384 const char* kScriptChars =
385 "inspectStack() native 'CurrentStackTraceNatve';\n" 385 "inspectStack() native 'CurrentStackTraceNatve';\n"
386 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n" 386 "foo(n) => n == 1 ? inspectStack() : foo(n-1);\n"
387 "testMain() => foo(50);\n"; 387 "testMain() => foo(50);\n";
388 388
389 Dart_Handle lib = 389 Dart_Handle lib =
390 TestCase::LoadTestScript(kScriptChars, &CurrentStackTraceNativeLookup); 390 TestCase::LoadTestScript(kScriptChars, &CurrentStackTraceNativeLookup);
391 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 391 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
392 EXPECT_VALID(result); 392 EXPECT_VALID(result);
393 EXPECT(Dart_IsInteger(result)); 393 EXPECT(Dart_IsInteger(result));
(...skipping 9513 matching lines...) Expand 10 before | Expand all | Expand 10 after
9907 EXPECT_VALID(result); 9907 EXPECT_VALID(result);
9908 result = Dart_FinalizeLoading(false); 9908 result = Dart_FinalizeLoading(false);
9909 EXPECT_VALID(result); 9909 EXPECT_VALID(result);
9910 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); 9910 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL);
9911 EXPECT(Dart_IsError(result)); 9911 EXPECT(Dart_IsError(result));
9912 } 9912 }
9913 9913
9914 #endif // !PRODUCT 9914 #endif // !PRODUCT
9915 9915
9916 } // namespace dart 9916 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698