OLD | NEW |
---|---|
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 "vm/debugger.h" | |
6 #include "bin/dartutils.h" | |
5 #include "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
6 #include "vm/dart_api_message.h" | 8 #include "vm/dart_api_message.h" |
7 #include "vm/debugger.h" | |
8 #include "vm/message.h" | 9 #include "vm/message.h" |
9 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
10 | 11 |
11 namespace dart { | 12 namespace dart { |
12 | 13 |
13 #ifndef PRODUCT | 14 #ifndef PRODUCT |
14 | 15 |
15 DECLARE_FLAG(bool, background_compilation); | 16 DECLARE_FLAG(bool, background_compilation); |
16 DECLARE_FLAG(bool, enable_inlining_annotations); | 17 DECLARE_FLAG(bool, enable_inlining_annotations); |
17 DECLARE_FLAG(bool, prune_dead_locals); | 18 DECLARE_FLAG(bool, prune_dead_locals); |
18 DECLARE_FLAG(bool, remove_script_timestamps_for_test); | 19 DECLARE_FLAG(bool, remove_script_timestamps_for_test); |
19 DECLARE_FLAG(bool, trace_rewind); | 20 DECLARE_FLAG(bool, trace_rewind); |
20 DECLARE_FLAG(int, optimization_counter_threshold); | 21 DECLARE_FLAG(int, optimization_counter_threshold); |
22 DECLARE_FLAG(bool, use_dart_frontend); | |
21 | 23 |
22 // Search for the formatted string in buffer. | 24 // Search for the formatted string in buffer. |
23 // | 25 // |
24 // TODO(turnidge): This function obscures the line number of failing | 26 // TODO(turnidge): This function obscures the line number of failing |
25 // EXPECTs. Rework this. | 27 // EXPECTs. Rework this. |
26 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { | 28 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { |
27 va_list args; | 29 va_list args; |
28 va_start(args, fmt); | 30 va_start(args, fmt); |
29 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); | 31 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); |
30 va_end(args); | 32 va_end(args); |
31 | 33 |
32 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); | 34 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); |
33 va_list args2; | 35 va_list args2; |
34 va_start(args2, fmt); | 36 va_start(args2, fmt); |
35 OS::VSNPrint(buffer, (len + 1), fmt, args2); | 37 OS::VSNPrint(buffer, (len + 1), fmt, args2); |
36 va_end(args2); | 38 va_end(args2); |
37 | 39 |
38 EXPECT_SUBSTRING(buffer, buff); | 40 EXPECT_SUBSTRING(buffer, buff); |
39 } | 41 } |
40 | 42 |
43 static Dart_Handle LoadTestScript(const char* kScriptChars) { | |
44 static const char* SCRIPT_FILENAME = "file:///untitled.dart"; | |
45 if (!FLAG_use_dart_frontend) { | |
46 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
47 EXPECT_VALID(lib); | |
48 return lib; | |
49 } | |
50 | |
51 // clang-format off | |
52 Dart_SourceFile sourcefiles[] = { | |
53 { | |
54 SCRIPT_FILENAME, kScriptChars, | |
55 }, | |
56 { | |
57 "file:///.packages", "untitled:/" | |
58 }}; | |
59 // clang-format on | |
60 | |
61 Dart_KernelCompilationResult compilation_result = Dart_CompileSourcesToKernel( | |
62 SCRIPT_FILENAME, sizeof(sourcefiles) / sizeof(Dart_SourceFile), | |
63 sourcefiles); | |
64 EXPECT(compilation_result.status == Dart_KernelCompilationStatus_Ok) | |
65 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { | |
66 OS::PrintErr("Compilation failed %s", compilation_result.error); | |
67 } | |
68 const uint8_t* kernel_file = compilation_result.kernel; | |
69 intptr_t kernel_length = compilation_result.kernel_size; | |
70 EXPECT(kernel_file != NULL); | |
71 void* kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | |
72 EXPECT(kernel_program != NULL); | |
73 Dart_Handle lib = Dart_LoadKernel(kernel_program); | |
74 EXPECT_VALID(lib); | |
75 return lib; | |
76 } | |
siva
2017/05/15 04:34:26
Can this be captures in TestCase::LoadTestScript s
| |
77 | |
41 TEST_CASE(Debugger_GetBreakpointsById) { | 78 TEST_CASE(Debugger_GetBreakpointsById) { |
42 const char* kScriptChars = | 79 const char* kScriptChars = |
43 "main() {\n" | 80 "main() {\n" |
44 " var x = new StringBuffer();\n" | 81 " var x = new StringBuffer();\n" |
45 " x.add('won');\n" | 82 " x.add('won');\n" |
46 " x.add('too');\n" | 83 " x.add('too');\n" |
47 " return x.toString();\n" | 84 " return x.toString();\n" |
48 "}\n"; | 85 "}\n"; |
49 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); | 86 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); |
50 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 87 LoadTestScript(kScriptChars); |
51 EXPECT_VALID(lib); | |
52 | 88 |
53 Isolate* isolate = Isolate::Current(); | 89 Isolate* isolate = Isolate::Current(); |
54 Debugger* debugger = isolate->debugger(); | 90 Debugger* debugger = isolate->debugger(); |
55 | 91 |
56 // Test with one loaded breakpoint, one latent breakpoint. | 92 // Test with one loaded breakpoint, one latent breakpoint. |
57 Dart_Handle url = NewString(TestCase::url()); | 93 Dart_Handle url = NewString(TestCase::url()); |
58 Dart_Handle result = Dart_SetBreakpoint(url, 2); | 94 Dart_Handle result = Dart_SetBreakpoint(url, 2); |
59 EXPECT_VALID(result); | 95 EXPECT_VALID(result); |
60 EXPECT(Dart_IsInteger(result)); | 96 EXPECT(Dart_IsInteger(result)); |
61 int64_t bp_id1 = 0; | 97 int64_t bp_id1 = 0; |
(...skipping 11 matching lines...) Expand all Loading... | |
73 | 109 |
74 TEST_CASE(Debugger_RemoveBreakpoint) { | 110 TEST_CASE(Debugger_RemoveBreakpoint) { |
75 const char* kScriptChars = | 111 const char* kScriptChars = |
76 "main() {\n" | 112 "main() {\n" |
77 " var x = new StringBuffer();\n" | 113 " var x = new StringBuffer();\n" |
78 " x.add('won');\n" | 114 " x.add('won');\n" |
79 " x.add('too');\n" | 115 " x.add('too');\n" |
80 " return x.toString();\n" | 116 " return x.toString();\n" |
81 "}\n"; | 117 "}\n"; |
82 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); | 118 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); |
83 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 119 LoadTestScript(kScriptChars); |
84 EXPECT_VALID(lib); | |
85 | 120 |
86 Isolate* isolate = Isolate::Current(); | 121 Isolate* isolate = Isolate::Current(); |
87 Debugger* debugger = isolate->debugger(); | 122 Debugger* debugger = isolate->debugger(); |
88 | 123 |
89 // Test with one loaded breakpoint, one latent breakpoint. | 124 // Test with one loaded breakpoint, one latent breakpoint. |
90 Dart_Handle url = NewString(TestCase::url()); | 125 Dart_Handle url = NewString(TestCase::url()); |
91 Dart_Handle result = Dart_SetBreakpoint(url, 2); | 126 Dart_Handle result = Dart_SetBreakpoint(url, 2); |
92 EXPECT_VALID(result); | 127 EXPECT_VALID(result); |
93 EXPECT(Dart_IsInteger(result)); | 128 EXPECT(Dart_IsInteger(result)); |
94 int64_t bp_id1 = 0; | 129 int64_t bp_id1 = 0; |
(...skipping 17 matching lines...) Expand all Loading... | |
112 | 147 |
113 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { | 148 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { |
114 const char* kScriptChars = | 149 const char* kScriptChars = |
115 "main() {\n" | 150 "main() {\n" |
116 " var x = new StringBuffer();\n" | 151 " var x = new StringBuffer();\n" |
117 " x.add('won');\n" | 152 " x.add('won');\n" |
118 " x.add('too');\n" | 153 " x.add('too');\n" |
119 " return x.toString();\n" | 154 " return x.toString();\n" |
120 "}\n"; | 155 "}\n"; |
121 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); | 156 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); |
122 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 157 Dart_Handle lib = LoadTestScript(kScriptChars); |
123 EXPECT_VALID(lib); | |
124 Library& vmlib = Library::Handle(); | 158 Library& vmlib = Library::Handle(); |
125 vmlib ^= Api::UnwrapHandle(lib); | 159 vmlib ^= Api::UnwrapHandle(lib); |
126 EXPECT(!vmlib.IsNull()); | 160 EXPECT(!vmlib.IsNull()); |
127 const String& private_key = String::Handle(vmlib.private_key()); | 161 const String& private_key = String::Handle(vmlib.private_key()); |
128 | 162 |
129 Isolate* isolate = Isolate::Current(); | 163 Isolate* isolate = Isolate::Current(); |
130 Debugger* debugger = isolate->debugger(); | 164 Debugger* debugger = isolate->debugger(); |
131 | 165 |
132 // Empty case. | 166 // Empty case. |
133 { | 167 { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 | 225 |
192 | 226 |
193 TEST_CASE(Debugger_PauseEvent) { | 227 TEST_CASE(Debugger_PauseEvent) { |
194 const char* kScriptChars = | 228 const char* kScriptChars = |
195 "main() {\n" | 229 "main() {\n" |
196 " var x = new StringBuffer();\n" | 230 " var x = new StringBuffer();\n" |
197 " x.write('won');\n" | 231 " x.write('won');\n" |
198 " x.write('too');\n" | 232 " x.write('too');\n" |
199 " return x.toString();\n" | 233 " return x.toString();\n" |
200 "}\n"; | 234 "}\n"; |
201 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 235 Dart_Handle lib = LoadTestScript(kScriptChars); |
202 EXPECT_VALID(lib); | |
203 | 236 |
204 Isolate* isolate = Isolate::Current(); | 237 Isolate* isolate = Isolate::Current(); |
205 Debugger* debugger = isolate->debugger(); | 238 Debugger* debugger = isolate->debugger(); |
206 | 239 |
207 // No pause event. | 240 // No pause event. |
208 EXPECT(!debugger->IsPaused()); | 241 EXPECT(!debugger->IsPaused()); |
209 EXPECT(debugger->PauseEvent() == NULL); | 242 EXPECT(debugger->PauseEvent() == NULL); |
210 | 243 |
211 saw_paused_event = false; | 244 saw_paused_event = false; |
212 Dart_SetPausedEventHandler(InspectPausedEvent); | 245 Dart_SetPausedEventHandler(InspectPausedEvent); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 " debugger();\n" | 391 " debugger();\n" |
359 " msg.write('exit(foo) ');\n" | 392 " msg.write('exit(foo) ');\n" |
360 "}\n" | 393 "}\n" |
361 "\n" | 394 "\n" |
362 "main() {\n" | 395 "main() {\n" |
363 " msg.write('enter(main) ');\n" | 396 " msg.write('enter(main) ');\n" |
364 " foo();\n" | 397 " foo();\n" |
365 " msg.write('exit(main) ');\n" | 398 " msg.write('exit(main) ');\n" |
366 " return msg.toString();\n" | 399 " return msg.toString();\n" |
367 "}\n"; | 400 "}\n"; |
368 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 401 Dart_Handle lib = LoadTestScript(kScriptChars); |
369 EXPECT_VALID(lib); | |
370 | 402 |
371 Dart_SetPausedEventHandler(RewindOnce); | 403 Dart_SetPausedEventHandler(RewindOnce); |
372 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 404 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
373 const char* result_cstr; | 405 const char* result_cstr; |
374 EXPECT_VALID(result); | 406 EXPECT_VALID(result); |
375 EXPECT(Dart_IsString(result)); | 407 EXPECT(Dart_IsString(result)); |
376 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 408 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
377 EXPECT_STREQ("enter(main) enter(foo) enter(foo) exit(foo) exit(main) ", | 409 EXPECT_STREQ("enter(main) enter(foo) enter(foo) exit(foo) exit(main) ", |
378 result_cstr); | 410 result_cstr); |
379 EXPECT(saw_paused_event); | 411 EXPECT(saw_paused_event); |
(...skipping 23 matching lines...) Expand all Loading... | |
403 " foo();\n" | 435 " foo();\n" |
404 " msg.write('exit(bar) ');\n" | 436 " msg.write('exit(bar) ');\n" |
405 "}\n" | 437 "}\n" |
406 "\n" | 438 "\n" |
407 "main() {\n" | 439 "main() {\n" |
408 " msg.write('enter(main) ');\n" | 440 " msg.write('enter(main) ');\n" |
409 " bar();\n" | 441 " bar();\n" |
410 " msg.write('exit(main) ');\n" | 442 " msg.write('exit(main) ');\n" |
411 " return msg.toString();\n" | 443 " return msg.toString();\n" |
412 "}\n"; | 444 "}\n"; |
413 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 445 Dart_Handle lib = LoadTestScript(kScriptChars); |
414 EXPECT_VALID(lib); | |
415 | 446 |
416 Dart_SetPausedEventHandler(RewindOnce); | 447 Dart_SetPausedEventHandler(RewindOnce); |
417 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 448 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
418 const char* result_cstr; | 449 const char* result_cstr; |
419 EXPECT_VALID(result); | 450 EXPECT_VALID(result); |
420 EXPECT(Dart_IsString(result)); | 451 EXPECT(Dart_IsString(result)); |
421 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 452 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
422 EXPECT_STREQ( | 453 EXPECT_STREQ( |
423 "enter(main) enter(bar) enter(foo) enter(bar) enter(foo) " | 454 "enter(main) enter(bar) enter(foo) enter(bar) enter(foo) " |
424 "exit(foo) exit(bar) exit(main) ", | 455 "exit(foo) exit(bar) exit(main) ", |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 " return result;\n" | 515 " return result;\n" |
485 "}\n" | 516 "}\n" |
486 "\n" | 517 "\n" |
487 "main() {\n" | 518 "main() {\n" |
488 " for (i = 0; i < 20; i++) {\n" | 519 " for (i = 0; i < 20; i++) {\n" |
489 " msg.clear();\n" | 520 " msg.clear();\n" |
490 " if (bar1()) break;\n;" | 521 " if (bar1()) break;\n;" |
491 " }\n" | 522 " }\n" |
492 " return msg.toString();\n" | 523 " return msg.toString();\n" |
493 "}\n"; | 524 "}\n"; |
494 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 525 Dart_Handle lib = LoadTestScript(kScriptChars); |
495 EXPECT_VALID(lib); | |
496 | 526 |
497 Dart_SetPausedEventHandler(RewindOnce); | 527 Dart_SetPausedEventHandler(RewindOnce); |
498 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 528 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
499 const char* result_cstr; | 529 const char* result_cstr; |
500 EXPECT_VALID(result); | 530 EXPECT_VALID(result); |
501 EXPECT(Dart_IsString(result)); | 531 EXPECT(Dart_IsString(result)); |
502 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 532 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
503 EXPECT_STREQ( | 533 EXPECT_STREQ( |
504 "enter(bar1) enter(bar2) enter(bar3) enter(foo) " | 534 "enter(bar1) enter(bar2) enter(bar3) enter(foo) " |
505 "enter(bar3) enter(foo) " | 535 "enter(bar3) enter(foo) " |
506 "exit(foo) exit(bar3) exit(bar2) exit(bar1) ", | 536 "exit(foo) exit(bar3) exit(bar2) exit(bar1) ", |
507 result_cstr); | 537 result_cstr); |
508 EXPECT(saw_paused_event); | 538 EXPECT(saw_paused_event); |
509 } | 539 } |
510 | 540 |
511 #endif // !PRODUCT | 541 #endif // !PRODUCT |
512 | 542 |
513 } // namespace dart | 543 } // namespace dart |
OLD | NEW |