Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/unit_test.h" | 8 #include "vm/unit_test.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 // Only ia32 and x64 can run execution tests. | 12 // Only ia32 and x64 can run execution tests. |
| 13 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 13 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 14 | 14 |
| 15 static bool breakpoint_hit = false; | 15 static bool breakpoint_hit = false; |
| 16 static int breakpoint_hit_counter = 0; | 16 static int breakpoint_hit_counter = 0; |
| 17 static Dart_Handle script_lib = NULL; | 17 static Dart_Handle script_lib = NULL; |
| 18 | 18 |
| 19 static const bool verbose = true; | 19 static const bool verbose = true; |
| 20 | 20 |
| 21 #define EXPECT_NOT_ERROR(handle) \ | 21 #define EXPECT_NOT_ERROR(handle) \ |
|
Ivan Posva
2012/08/03 18:59:47
Please just remove the use of EXPECT_NOT_ERROR and
Kevin Millikin (Google)
2012/08/06 07:49:47
Done.
| |
| 22 if (Dart_IsError(handle)) { \ | 22 if (Dart_IsError(handle)) { \ |
| 23 OS::Print("Error: %s\n", Dart_GetError(handle)); \ | 23 OS::Print("Error: %s\n", Dart_GetError(handle)); \ |
| 24 } \ | 24 } \ |
| 25 EXPECT(!Dart_IsError(handle)); | 25 EXPECT_VALID(handle); |
| 26 | 26 |
| 27 | 27 |
| 28 static void LoadScript(const char* source) { | 28 static void LoadScript(const char* source) { |
| 29 script_lib = TestCase::LoadTestScript(source, NULL); | 29 script_lib = TestCase::LoadTestScript(source, NULL); |
| 30 EXPECT(!Dart_IsError(script_lib)); | 30 EXPECT_VALID(script_lib); |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 static void SetBreakpointAtEntry(const char* cname, const char* fname) { | 34 static void SetBreakpointAtEntry(const char* cname, const char* fname) { |
| 35 ASSERT(script_lib != NULL); | 35 ASSERT(script_lib != NULL); |
| 36 ASSERT(!Dart_IsError(script_lib)); | 36 ASSERT(!Dart_IsError(script_lib)); |
| 37 ASSERT(Dart_IsLibrary(script_lib)); | 37 ASSERT(Dart_IsLibrary(script_lib)); |
| 38 Dart_Breakpoint bpt; | 38 Dart_Breakpoint bpt; |
| 39 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib, | 39 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib, |
| 40 Dart_NewString(cname), | 40 Dart_NewString(cname), |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 "void main() { \n" | 277 "void main() { \n" |
| 278 " A.foo(); \n" | 278 " A.foo(); \n" |
| 279 "} \n"; | 279 "} \n"; |
| 280 | 280 |
| 281 LoadScript(kScriptChars); | 281 LoadScript(kScriptChars); |
| 282 Dart_SetBreakpointHandler(&TestBreakpointHandler); | 282 Dart_SetBreakpointHandler(&TestBreakpointHandler); |
| 283 SetBreakpointAtEntry("A", "foo"); | 283 SetBreakpointAtEntry("A", "foo"); |
| 284 | 284 |
| 285 breakpoint_hit = false; | 285 breakpoint_hit = false; |
| 286 Dart_Handle retval = Invoke("main"); | 286 Dart_Handle retval = Invoke("main"); |
| 287 EXPECT(!Dart_IsError(retval)); | 287 EXPECT_VALID(retval); |
| 288 EXPECT(breakpoint_hit == true); | 288 EXPECT(breakpoint_hit == true); |
| 289 } | 289 } |
| 290 | 290 |
| 291 | 291 |
| 292 void TestStepOutHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | 292 void TestStepOutHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
| 293 const char* expected_bpts[] = {"f1", "foo", "main"}; | 293 const char* expected_bpts[] = {"f1", "foo", "main"}; |
| 294 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); | 294 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); |
| 295 intptr_t trace_len; | 295 intptr_t trace_len; |
| 296 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 296 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
| 297 EXPECT_NOT_ERROR(res); | 297 EXPECT_NOT_ERROR(res); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 Dart_SetBreakpointHandler(&TestStepOutHandler); | 335 Dart_SetBreakpointHandler(&TestStepOutHandler); |
| 336 | 336 |
| 337 // Set a breakpoint in function f1, then repeatedly step out until | 337 // Set a breakpoint in function f1, then repeatedly step out until |
| 338 // we get to main. We should see one breakpoint each in f1, | 338 // we get to main. We should see one breakpoint each in f1, |
| 339 // foo, main, but not in f2. | 339 // foo, main, but not in f2. |
| 340 SetBreakpointAtEntry("", "f1"); | 340 SetBreakpointAtEntry("", "f1"); |
| 341 | 341 |
| 342 breakpoint_hit = false; | 342 breakpoint_hit = false; |
| 343 breakpoint_hit_counter = 0; | 343 breakpoint_hit_counter = 0; |
| 344 Dart_Handle retval = Invoke("main"); | 344 Dart_Handle retval = Invoke("main"); |
| 345 EXPECT(!Dart_IsError(retval)); | 345 EXPECT_VALID(retval); |
| 346 EXPECT(Dart_IsInteger(retval)); | 346 EXPECT(Dart_IsInteger(retval)); |
| 347 int64_t int_value = 0; | 347 int64_t int_value = 0; |
| 348 Dart_IntegerToInt64(retval, &int_value); | 348 Dart_IntegerToInt64(retval, &int_value); |
| 349 EXPECT_EQ(2, int_value); | 349 EXPECT_EQ(2, int_value); |
| 350 EXPECT(breakpoint_hit == true); | 350 EXPECT(breakpoint_hit == true); |
| 351 } | 351 } |
| 352 | 352 |
| 353 | 353 |
| 354 void TestStepIntoHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | 354 void TestStepIntoHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
| 355 const char* expected_bpts[] = { | 355 const char* expected_bpts[] = { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 Dart_SetBreakpointHandler(&TestStepIntoHandler); | 416 Dart_SetBreakpointHandler(&TestStepIntoHandler); |
| 417 | 417 |
| 418 // Set a breakpoint in function f1, then repeatedly step out until | 418 // Set a breakpoint in function f1, then repeatedly step out until |
| 419 // we get to main. We should see one breakpoint each in f1, | 419 // we get to main. We should see one breakpoint each in f1, |
| 420 // foo, main, but not in f2. | 420 // foo, main, but not in f2. |
| 421 SetBreakpointAtEntry("", "main"); | 421 SetBreakpointAtEntry("", "main"); |
| 422 | 422 |
| 423 breakpoint_hit = false; | 423 breakpoint_hit = false; |
| 424 breakpoint_hit_counter = 0; | 424 breakpoint_hit_counter = 0; |
| 425 Dart_Handle retval = Invoke("main"); | 425 Dart_Handle retval = Invoke("main"); |
| 426 EXPECT(!Dart_IsError(retval)); | 426 EXPECT_VALID(retval); |
| 427 EXPECT(Dart_IsInteger(retval)); | 427 EXPECT(Dart_IsInteger(retval)); |
| 428 int64_t int_value = 0; | 428 int64_t int_value = 0; |
| 429 Dart_IntegerToInt64(retval, &int_value); | 429 Dart_IntegerToInt64(retval, &int_value); |
| 430 EXPECT_EQ(7, int_value); | 430 EXPECT_EQ(7, int_value); |
| 431 EXPECT(breakpoint_hit == true); | 431 EXPECT(breakpoint_hit == true); |
| 432 } | 432 } |
| 433 | 433 |
| 434 | 434 |
| 435 static void StepIntoHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | 435 static void StepIntoHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
| 436 if (verbose) { | 436 if (verbose) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 459 "} \n"; | 459 "} \n"; |
| 460 | 460 |
| 461 LoadScript(kScriptChars); | 461 LoadScript(kScriptChars); |
| 462 Dart_SetBreakpointHandler(&StepIntoHandler); | 462 Dart_SetBreakpointHandler(&StepIntoHandler); |
| 463 | 463 |
| 464 SetBreakpointAtEntry("", "main"); | 464 SetBreakpointAtEntry("", "main"); |
| 465 | 465 |
| 466 breakpoint_hit = false; | 466 breakpoint_hit = false; |
| 467 breakpoint_hit_counter = 0; | 467 breakpoint_hit_counter = 0; |
| 468 Dart_Handle retval = Invoke("main"); | 468 Dart_Handle retval = Invoke("main"); |
| 469 EXPECT(!Dart_IsError(retval)); | 469 EXPECT_VALID(retval); |
| 470 EXPECT(Dart_IsInteger(retval)); | 470 EXPECT(Dart_IsInteger(retval)); |
| 471 int64_t int_value = 0; | 471 int64_t int_value = 0; |
| 472 Dart_IntegerToInt64(retval, &int_value); | 472 Dart_IntegerToInt64(retval, &int_value); |
| 473 EXPECT_EQ(101, int_value); | 473 EXPECT_EQ(101, int_value); |
| 474 EXPECT(breakpoint_hit == true); | 474 EXPECT(breakpoint_hit == true); |
| 475 } | 475 } |
| 476 | 476 |
| 477 | 477 |
| 478 TEST_CASE(Debug_DeoptimizeFunction) { | 478 TEST_CASE(Debug_DeoptimizeFunction) { |
| 479 const char* kScriptChars = | 479 const char* kScriptChars = |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 497 Dart_Handle res = Invoke("warmup"); | 497 Dart_Handle res = Invoke("warmup"); |
| 498 EXPECT_NOT_ERROR(res); | 498 EXPECT_NOT_ERROR(res); |
| 499 | 499 |
| 500 // Now set breakpoint in main and then step into optimized function foo. | 500 // Now set breakpoint in main and then step into optimized function foo. |
| 501 SetBreakpointAtEntry("", "main"); | 501 SetBreakpointAtEntry("", "main"); |
| 502 | 502 |
| 503 | 503 |
| 504 breakpoint_hit = false; | 504 breakpoint_hit = false; |
| 505 breakpoint_hit_counter = 0; | 505 breakpoint_hit_counter = 0; |
| 506 Dart_Handle retval = Invoke("main"); | 506 Dart_Handle retval = Invoke("main"); |
| 507 EXPECT(!Dart_IsError(retval)); | 507 EXPECT_VALID(retval); |
| 508 EXPECT(Dart_IsInteger(retval)); | 508 EXPECT(Dart_IsInteger(retval)); |
| 509 int64_t int_value = 0; | 509 int64_t int_value = 0; |
| 510 Dart_IntegerToInt64(retval, &int_value); | 510 Dart_IntegerToInt64(retval, &int_value); |
| 511 EXPECT_EQ(2 * 99, int_value); | 511 EXPECT_EQ(2 * 99, int_value); |
| 512 EXPECT(breakpoint_hit == true); | 512 EXPECT(breakpoint_hit == true); |
| 513 } | 513 } |
| 514 | 514 |
| 515 | 515 |
| 516 void TestSingleStepHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | 516 void TestSingleStepHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
| 517 const char* expected_bpts[] = { | 517 const char* expected_bpts[] = { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 EXPECT(Dart_IsInteger(res)); | 726 EXPECT(Dart_IsInteger(res)); |
| 727 int64_t bp_id = 0; | 727 int64_t bp_id = 0; |
| 728 Dart_IntegerToInt64(res, &bp_id); | 728 Dart_IntegerToInt64(res, &bp_id); |
| 729 | 729 |
| 730 // Function main() calls foo() 3 times. On the second iteration, the | 730 // Function main() calls foo() 3 times. On the second iteration, the |
| 731 // breakpoint is removed by the handler, so we expect the breakpoint | 731 // breakpoint is removed by the handler, so we expect the breakpoint |
| 732 // to fire twice only. | 732 // to fire twice only. |
| 733 bp_id_to_be_deleted = bp_id; | 733 bp_id_to_be_deleted = bp_id; |
| 734 breakpoint_hit_counter = 0; | 734 breakpoint_hit_counter = 0; |
| 735 Dart_Handle retval = Invoke("main"); | 735 Dart_Handle retval = Invoke("main"); |
| 736 EXPECT(!Dart_IsError(retval)); | 736 EXPECT_VALID(retval); |
| 737 EXPECT_EQ(2, breakpoint_hit_counter); | 737 EXPECT_EQ(2, breakpoint_hit_counter); |
| 738 } | 738 } |
| 739 | 739 |
| 740 | 740 |
| 741 static void InspectStaticFieldHandler(Dart_Breakpoint bpt, | 741 static void InspectStaticFieldHandler(Dart_Breakpoint bpt, |
| 742 Dart_StackTrace trace) { | 742 Dart_StackTrace trace) { |
| 743 ASSERT(script_lib != NULL); | 743 ASSERT(script_lib != NULL); |
| 744 ASSERT(!Dart_IsError(script_lib)); | 744 ASSERT(!Dart_IsError(script_lib)); |
| 745 ASSERT(Dart_IsLibrary(script_lib)); | 745 ASSERT(Dart_IsLibrary(script_lib)); |
| 746 Dart_Handle class_A = Dart_GetClass(script_lib, Dart_NewString("A")); | 746 Dart_Handle class_A = Dart_GetClass(script_lib, Dart_NewString("A")); |
| 747 EXPECT(!Dart_IsError(class_A)); | 747 EXPECT_VALID(class_A); |
| 748 | 748 |
| 749 const int expected_num_fields = 2; | 749 const int expected_num_fields = 2; |
| 750 struct { | 750 struct { |
| 751 const char* field_name; | 751 const char* field_name; |
| 752 const char* field_value; | 752 const char* field_value; |
| 753 } expected[] = { | 753 } expected[] = { |
| 754 // Expected values at first breakpoint. | 754 // Expected values at first breakpoint. |
| 755 { "bla", "yada yada yada"}, | 755 { "bla", "yada yada yada"}, |
| 756 { "u", "null" }, | 756 { "u", "null" }, |
| 757 // Expected values at second breakpoint. | 757 // Expected values at second breakpoint. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 " A.bla = 'silence is golden'; \n" | 809 " A.bla = 'silence is golden'; \n" |
| 810 " debugBreak(); \n" | 810 " debugBreak(); \n" |
| 811 " } \n"; | 811 " } \n"; |
| 812 | 812 |
| 813 LoadScript(kScriptChars); | 813 LoadScript(kScriptChars); |
| 814 Dart_SetBreakpointHandler(&InspectStaticFieldHandler); | 814 Dart_SetBreakpointHandler(&InspectStaticFieldHandler); |
| 815 SetBreakpointAtEntry("", "debugBreak"); | 815 SetBreakpointAtEntry("", "debugBreak"); |
| 816 | 816 |
| 817 breakpoint_hit_counter = 0; | 817 breakpoint_hit_counter = 0; |
| 818 Dart_Handle retval = Invoke("main"); | 818 Dart_Handle retval = Invoke("main"); |
| 819 EXPECT(!Dart_IsError(retval)); | 819 EXPECT_VALID(retval); |
| 820 } | 820 } |
| 821 | 821 |
| 822 | 822 |
| 823 TEST_CASE(Debug_InspectObject) { | 823 TEST_CASE(Debug_InspectObject) { |
| 824 const char* kScriptChars = | 824 const char* kScriptChars = |
| 825 " class A { \n" | 825 " class A { \n" |
| 826 " var a_field = 'a'; \n" | 826 " var a_field = 'a'; \n" |
| 827 " static var bla = 'yada yada yada'; \n" | 827 " static var bla = 'yada yada yada'; \n" |
| 828 " static var error = unresolvedName(); \n" | 828 " static var error = unresolvedName(); \n" |
| 829 " var d = 42.1; \n" | 829 " var d = 42.1; \n" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 list_as_string = Dart_ToString(lib_list); | 1042 list_as_string = Dart_ToString(lib_list); |
| 1043 list_cstr = ""; | 1043 list_cstr = ""; |
| 1044 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); | 1044 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); |
| 1045 EXPECT_SUBSTRING(TestCase::url(), list_cstr); | 1045 EXPECT_SUBSTRING(TestCase::url(), list_cstr); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 | 1048 |
| 1049 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1049 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 1050 | 1050 |
| 1051 } // namespace dart | 1051 } // namespace dart |
| OLD | NEW |