Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, 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 | |
| 7 #include "vm/assert.h" | |
| 8 #include "vm/unit_test.h" | |
| 9 | |
| 10 namespace dart { | |
| 11 | |
| 12 #if defined(TARGET_ARCH_IA32) // Only ia32 can run execution tests. | |
| 13 | |
| 14 | |
| 15 static bool breakpoint_hit = false; | |
| 16 | |
| 17 static const bool verbose = false; | |
| 18 | |
| 19 #define BARK_IF_ERROR(handle) \ | |
| 20 if (Dart_IsError(handle)) { \ | |
| 21 printf("Error: %s\n", Dart_GetError(handle)); \ | |
| 22 } | |
| 23 | |
| 24 | |
| 25 void TestBreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | |
| 26 const char* expected_trace[] = {"A.foo", "main"}; | |
| 27 const intptr_t expected_trace_length = 2; | |
| 28 breakpoint_hit = true; | |
| 29 intptr_t trace_len; | |
| 30 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | |
| 31 BARK_IF_ERROR(res); | |
| 32 EXPECT_EQ(expected_trace_length, trace_len); | |
| 33 for (int i = 0; i < trace_len; i++) { | |
| 34 Dart_ActivationFrame frame; | |
| 35 res = Dart_GetActivationFrame(trace, i, &frame); | |
| 36 BARK_IF_ERROR(res); | |
|
siva
2011/12/09 02:20:04
EXPECT(!Dart_IsError(res)); ?
hausner
2011/12/13 00:14:59
Done.
| |
| 37 Dart_Handle func_name; | |
| 38 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL); | |
| 39 BARK_IF_ERROR(res); | |
|
siva
2011/12/09 02:20:04
EXPECT(!Dart_IsError(res)); ?
hausner
2011/12/13 00:14:59
Done.
| |
| 40 EXPECT(Dart_IsString(func_name)); | |
| 41 const char* name_chars; | |
| 42 Dart_StringToCString(func_name, &name_chars); | |
| 43 EXPECT_STREQ(expected_trace[i], name_chars); | |
| 44 if (verbose) printf(" >> %d: %s\n", i, name_chars); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 | |
| 49 UNIT_TEST_CASE(Breakpoint) { | |
| 50 const char* kScriptChars = | |
| 51 "void moo(s) { }\n" | |
| 52 "class A {\n" | |
| 53 " static void foo() {\n" | |
| 54 " moo('good news');\n" | |
| 55 " }\n" | |
| 56 "}\n" | |
| 57 "void main() {\n" | |
| 58 " A.foo();\n" | |
| 59 "}\n"; | |
| 60 | |
| 61 TestIsolateScope __test_isolate__; | |
| 62 | |
| 63 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 64 EXPECT(!Dart_IsError(lib)); | |
| 65 | |
| 66 Dart_SetBreakpointHandler(&TestBreakpointHandler); | |
| 67 | |
| 68 Dart_Handle c_name = Dart_NewString("A"); | |
| 69 Dart_Handle f_name = Dart_NewString("foo"); | |
| 70 Dart_Breakpoint bpt; | |
| 71 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); | |
| 72 BARK_IF_ERROR(res); | |
|
siva
2011/12/09 02:20:04
Is this BARK stuff here for debugging purposes? :-
hausner
2011/12/13 00:14:59
I'd like to keep it since it prints the error mess
| |
| 73 EXPECT(!Dart_IsError(res)); | |
| 74 | |
| 75 breakpoint_hit = false; | |
| 76 Dart_Handle retval = Dart_InvokeStatic(lib, | |
| 77 Dart_NewString(""), | |
| 78 Dart_NewString("main"), | |
| 79 0, | |
| 80 NULL); | |
| 81 EXPECT(!Dart_IsError(retval)); | |
| 82 EXPECT(breakpoint_hit == true); | |
| 83 } | |
| 84 | |
| 85 #endif // TARGET_ARCH_IA32. | |
| 86 | |
| 87 } // namespace dart | |
| OLD | NEW |