Chromium Code Reviews| Index: runtime/vm/debugger_test.cc |
| diff --git a/runtime/vm/debugger_test.cc b/runtime/vm/debugger_test.cc |
| index c715c3df2fd1d2512baec61190725c349a2127c8..3440d2054fe875ef186442ea2b4b07239c02eec4 100644 |
| --- a/runtime/vm/debugger_test.cc |
| +++ b/runtime/vm/debugger_test.cc |
| @@ -2,9 +2,10 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| +#include "vm/debugger.h" |
| +#include "bin/dartutils.h" |
| #include "vm/dart_api_impl.h" |
| #include "vm/dart_api_message.h" |
| -#include "vm/debugger.h" |
| #include "vm/message.h" |
| #include "vm/unit_test.h" |
| @@ -18,6 +19,7 @@ DECLARE_FLAG(bool, prune_dead_locals); |
| DECLARE_FLAG(bool, remove_script_timestamps_for_test); |
| DECLARE_FLAG(bool, trace_rewind); |
| DECLARE_FLAG(int, optimization_counter_threshold); |
| +DECLARE_FLAG(bool, use_dart_frontend); |
| // Search for the formatted string in buffer. |
| // |
| @@ -38,6 +40,41 @@ static void ExpectSubstringF(const char* buff, const char* fmt, ...) { |
| EXPECT_SUBSTRING(buffer, buff); |
| } |
| +static Dart_Handle LoadTestScript(const char* kScriptChars) { |
| + static const char* SCRIPT_FILENAME = "file:///untitled.dart"; |
| + if (!FLAG_use_dart_frontend) { |
| + Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| + EXPECT_VALID(lib); |
| + return lib; |
| + } |
| + |
| + // clang-format off |
| + Dart_SourceFile sourcefiles[] = { |
| + { |
| + SCRIPT_FILENAME, kScriptChars, |
| + }, |
| + { |
| + "file:///.packages", "untitled:/" |
| + }}; |
| + // clang-format on |
| + |
| + Dart_KernelCompilationResult compilation_result = Dart_CompileSourcesToKernel( |
| + SCRIPT_FILENAME, sizeof(sourcefiles) / sizeof(Dart_SourceFile), |
| + sourcefiles); |
| + EXPECT(compilation_result.status == Dart_KernelCompilationStatus_Ok) |
| + if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { |
| + OS::PrintErr("Compilation failed %s", compilation_result.error); |
| + } |
| + const uint8_t* kernel_file = compilation_result.kernel; |
| + intptr_t kernel_length = compilation_result.kernel_size; |
| + EXPECT(kernel_file != NULL); |
| + void* kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); |
| + EXPECT(kernel_program != NULL); |
| + Dart_Handle lib = Dart_LoadKernel(kernel_program); |
| + EXPECT_VALID(lib); |
| + return lib; |
| +} |
|
siva
2017/05/15 04:34:26
Can this be captures in TestCase::LoadTestScript s
|
| + |
| TEST_CASE(Debugger_GetBreakpointsById) { |
| const char* kScriptChars = |
| "main() {\n" |
| @@ -47,8 +84,7 @@ TEST_CASE(Debugger_GetBreakpointsById) { |
| " return x.toString();\n" |
| "}\n"; |
| SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); |
| - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| - EXPECT_VALID(lib); |
| + LoadTestScript(kScriptChars); |
| Isolate* isolate = Isolate::Current(); |
| Debugger* debugger = isolate->debugger(); |
| @@ -80,8 +116,7 @@ TEST_CASE(Debugger_RemoveBreakpoint) { |
| " return x.toString();\n" |
| "}\n"; |
| SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); |
| - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| - EXPECT_VALID(lib); |
| + LoadTestScript(kScriptChars); |
| Isolate* isolate = Isolate::Current(); |
| Debugger* debugger = isolate->debugger(); |
| @@ -119,8 +154,7 @@ TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { |
| " return x.toString();\n" |
| "}\n"; |
| SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); |
| - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| - EXPECT_VALID(lib); |
| + Dart_Handle lib = LoadTestScript(kScriptChars); |
| Library& vmlib = Library::Handle(); |
| vmlib ^= Api::UnwrapHandle(lib); |
| EXPECT(!vmlib.IsNull()); |
| @@ -198,8 +232,7 @@ TEST_CASE(Debugger_PauseEvent) { |
| " x.write('too');\n" |
| " return x.toString();\n" |
| "}\n"; |
| - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| - EXPECT_VALID(lib); |
| + Dart_Handle lib = LoadTestScript(kScriptChars); |
| Isolate* isolate = Isolate::Current(); |
| Debugger* debugger = isolate->debugger(); |
| @@ -365,8 +398,7 @@ TEST_CASE(Debugger_RewindOneFrame_Unoptimized) { |
| " msg.write('exit(main) ');\n" |
| " return msg.toString();\n" |
| "}\n"; |
| - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| - EXPECT_VALID(lib); |
| + Dart_Handle lib = LoadTestScript(kScriptChars); |
| Dart_SetPausedEventHandler(RewindOnce); |
| Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| @@ -410,8 +442,7 @@ TEST_CASE(Debugger_RewindTwoFrames_Unoptimized) { |
| " msg.write('exit(main) ');\n" |
| " return msg.toString();\n" |
| "}\n"; |
| - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| - EXPECT_VALID(lib); |
| + Dart_Handle lib = LoadTestScript(kScriptChars); |
| Dart_SetPausedEventHandler(RewindOnce); |
| Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| @@ -491,8 +522,7 @@ TEST_CASE(Debugger_Rewind_Optimized) { |
| " }\n" |
| " return msg.toString();\n" |
| "}\n"; |
| - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| - EXPECT_VALID(lib); |
| + Dart_Handle lib = LoadTestScript(kScriptChars); |
| Dart_SetPausedEventHandler(RewindOnce); |
| Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |