diff --git a/tooling/test/BUILD.gn b/tooling/test/BUILD.gn index eb83066bf67456c0ac6d95ba5f47323355e2ec4e..e865c06c6845284403bc52949fe3148e2c55172f 100644 --- a/tooling/test/BUILD.gn +++ b/tooling/test/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") import("//arkcompiler/ets_frontend/ts2panda/ts2abc_config.gni") import("//arkcompiler/ets_runtime/js_runtime_config.gni") import("//arkcompiler/toolchain/test/test_helper.gni") @@ -47,7 +48,7 @@ test_js_files = [ ] foreach(file, test_js_files) { - ts2abc_gen_abc("gen_${file}_abc") { + es2abc_gen_abc("gen_${file}_abc") { test_js = "${test_js_path}${file}.js" test_abc = "$target_out_dir/${file}.abc" @@ -112,16 +113,16 @@ source_set("jsdebugtest_set") { [ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include" ] } } - - deps = [ - "//arkcompiler/ets_runtime:libark_jsruntime_test", - "//arkcompiler/toolchain/tooling:libark_ecma_debugger_test", - ] } ohos_shared_library("jsdebugtest") { deps = [ ":jsdebugtest_set" ] + deps += [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_test", + ] + if (is_ohos && is_standard_system) { if (enable_hilog) { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] diff --git a/tooling/test/testcases/js_breakpoint_arrow_test.h b/tooling/test/testcases/js_breakpoint_arrow_test.h index a8d24325e62b1f92d249c132198452ebc8cc974f..b2d75da8d7a9606a8f17e7376326dbae7b139bdd 100644 --- a/tooling/test/testcases/js_breakpoint_arrow_test.h +++ b/tooling/test/testcases/js_breakpoint_arrow_test.h @@ -23,12 +23,6 @@ class JsBreakpointArrowTest : public TestEvents { public: JsBreakpointArrowTest() { - vmStart = [this] { - location_ = TestUtil::GetLocation(18, 0, pandaFile_.c_str()); // 18: breakpointer line - ASSERT_TRUE(location_.GetMethodId().IsValid()); - return true; - }; - breakpoint = [this](const JSPtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); @@ -38,6 +32,8 @@ public: }; loadModule = [this](std::string_view moduleName) { + location_ = TestUtil::GetLocation(18, 0, pandaFile_.c_str()); // 18: breakpointer line + ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); diff --git a/tooling/test/testcases/js_breakpoint_async_test.h b/tooling/test/testcases/js_breakpoint_async_test.h index 3a2f94d1ec66e8b3032d3fd47e113c29a9712130..129afdd50287fca090a211902f3e13558beb3479 100644 --- a/tooling/test/testcases/js_breakpoint_async_test.h +++ b/tooling/test/testcases/js_breakpoint_async_test.h @@ -23,12 +23,6 @@ class JsBreakpointAsyncTest : public TestEvents { public: JsBreakpointAsyncTest() { - vmStart = [this] { - location_ = TestUtil::GetLocation(18, 0, pandaFile_.c_str()); // 18: breakpointer line - ASSERT_TRUE(location_.GetMethodId().IsValid()); - return true; - }; - breakpoint = [this](const JSPtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); @@ -38,6 +32,8 @@ public: }; loadModule = [this](std::string_view moduleName) { + location_ = TestUtil::GetLocation(18, 0, pandaFile_.c_str()); // 18: breakpointer line + ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); diff --git a/tooling/test/testcases/js_breakpoint_test.h b/tooling/test/testcases/js_breakpoint_test.h index 7c6c8e5434dccccbb247271986a05b3a7b26109d..489dd5904b32b788856d6232ba7e3e036f064c00 100644 --- a/tooling/test/testcases/js_breakpoint_test.h +++ b/tooling/test/testcases/js_breakpoint_test.h @@ -23,12 +23,6 @@ class JsBreakpointTest : public TestEvents { public: JsBreakpointTest() { - vmStart = [this] { - location_ = TestUtil::GetLocation(22, 0, pandaFile_.c_str()); // 22: breakpointer line - ASSERT_TRUE(location_.GetMethodId().IsValid()); - return true; - }; - breakpoint = [this](const JSPtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); @@ -38,6 +32,8 @@ public: }; loadModule = [this](std::string_view moduleName) { + location_ = TestUtil::GetLocation(22, 0, pandaFile_.c_str()); // 22: breakpointer line + ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); diff --git a/tooling/test/testcases/js_exception_test.h b/tooling/test/testcases/js_exception_test.h index cc5415c91416d757bce3fbc985430001a1e79837..3c204b2a10cd23a1cd4b2d3a4ace56ff6a7498d0 100644 --- a/tooling/test/testcases/js_exception_test.h +++ b/tooling/test/testcases/js_exception_test.h @@ -23,12 +23,6 @@ class JsExceptionTest : public TestEvents { public: JsExceptionTest() { - vmStart = [this] { - location_ = TestUtil::GetLocation(22, 0, pandaFile_.c_str()); // 22:breakpointer line - ASSERT_TRUE(location_.GetMethodId().IsValid()); - return true; - }; - breakpoint = [this](const JSPtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); @@ -61,6 +55,8 @@ public: }; loadModule = [this](std::string_view moduleName) { + location_ = TestUtil::GetLocation(22, 0, pandaFile_.c_str()); // 22:breakpointer line + ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); diff --git a/tooling/test/testcases/js_range_error_test.h b/tooling/test/testcases/js_range_error_test.h index 2bfc1d46bfe0c1ad488bca8695145bd575dce588..ac35820311b8e725bc4a730e3a884d53a27c0ff3 100644 --- a/tooling/test/testcases/js_range_error_test.h +++ b/tooling/test/testcases/js_range_error_test.h @@ -23,12 +23,6 @@ class JsRangeErrorTest : public TestEvents { public: JsRangeErrorTest() { - vmStart = [this] { - location_ = TestUtil::GetLocation(20, 0, pandaFile_.c_str()); // 20: breakpointer line - ASSERT_TRUE(location_.GetMethodId().IsValid()); - return true; - }; - breakpoint = [this](const JSPtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); @@ -61,6 +55,8 @@ public: }; loadModule = [this](std::string_view moduleName) { + location_ = TestUtil::GetLocation(20, 0, pandaFile_.c_str()); // 20: breakpointer line + ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); diff --git a/tooling/test/testcases/js_single_step_test.h b/tooling/test/testcases/js_single_step_test.h index 5a64e9b06fd770b3bdb5ef31a8a41c29aef3fa8f..2b35dab6987242598a839f5563023eb98a6e3db6 100644 --- a/tooling/test/testcases/js_single_step_test.h +++ b/tooling/test/testcases/js_single_step_test.h @@ -23,12 +23,6 @@ class JsSingleStepTest : public TestEvents { public: JsSingleStepTest() { - vmStart = [this] { - locationStart_ = TestUtil::GetLocation(19, 0, pandaFile_.c_str()); // 19: line number - locationEnd_ = TestUtil::GetLocation(22, 0, pandaFile_.c_str()); // 22: line number - return true; - }; - vmDeath = [this]() { ASSERT_NE(stepCounter_, 0); // 0: step counter ASSERT_EQ(breakpointCounter_, 2); // 2: break point counter @@ -36,6 +30,8 @@ public: }; loadModule = [this](std::string_view moduleName) { + locationStart_ = TestUtil::GetLocation(19, 0, pandaFile_.c_str()); // 19: line number + locationEnd_ = TestUtil::GetLocation(22, 0, pandaFile_.c_str()); // 22: line number TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); auto condFuncRef = FunctionRef::Undefined(vm_); diff --git a/tooling/test/testcases/js_step_into_test.h b/tooling/test/testcases/js_step_into_test.h index ba0c2dd74a646d74c33b3bd350449f18e1c0a7a3..31e9afff0464a8559c645d7b9571235454e4d4b3 100644 --- a/tooling/test/testcases/js_step_into_test.h +++ b/tooling/test/testcases/js_step_into_test.h @@ -23,18 +23,6 @@ class JsStepIntoTest : public TestEvents { public: JsStepIntoTest() { - vmStart = [this] { - // line number for breakpoint array - size_t breakpoint[POINTER_SIZE][LINE_COLUMN] = - {{84, 0}, {87, 0}, {27, 0}, {79, 0}, {42, 0}, {38, 0}, {56, 0}, {60, 0}, {96, 0}, {54, 0}}; - // line number for stepinto array - size_t stepInto[STEP_SIZE][LINE_COLUMN] = - {{85, 5}, {23, 0}, {73, 0}, {80, 0}, {36, 0}, {43, 0}, {50, 0}, {61, 0}, {97, 15}}; - SetJSPtLocation(breakpoint[0], POINTER_SIZE, pointerLocations_); - SetJSPtLocation(stepInto[0], STEP_SIZE, stepLocations_); - return true; - }; - vmDeath = [this]() { ASSERT_EQ(breakpointCounter_, pointerLocations_.size()); ASSERT_EQ(stepCompleteCounter_, stepLocations_.size()); @@ -42,6 +30,15 @@ public: }; loadModule = [this](std::string_view moduleName) { + // line number for breakpoint array + size_t breakpoint[POINTER_SIZE][LINE_COLUMN] = + {{84, 0}, {87, 0}, {27, 0}, {79, 0}, {42, 0}, {38, 0}, {56, 0}, {60, 0}, {96, 0}, {54, 0}}; + // line number for stepinto array + // 35 -> 36; 49 -> 50 + size_t stepInto[STEP_SIZE][LINE_COLUMN] = + {{85, 5}, {23, 0}, {73, 0}, {80, 0}, {35, 0}, {43, 0}, {49, 0}, {61, 0}, {97, 15}}; + SetJSPtLocation(breakpoint[0], POINTER_SIZE, pointerLocations_); + SetJSPtLocation(stepInto[0], STEP_SIZE, stepLocations_); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); debugger_->NotifyScriptParsed(0, moduleName.data()); diff --git a/tooling/test/testcases/js_step_out_test.h b/tooling/test/testcases/js_step_out_test.h index de1d65db20919b5eb3ab2ee7a9ae419f08bb93ed..4d15728ab1a6506b6d3cb71741bbf659f7b235c5 100644 --- a/tooling/test/testcases/js_step_out_test.h +++ b/tooling/test/testcases/js_step_out_test.h @@ -23,16 +23,6 @@ class JsStepOutTest : public TestEvents { public: JsStepOutTest() { - vmStart = [this] { - // 74、36: line number for breakpoint array - size_t breakpoint[5][2] = {{74, 0}, {36, 0}, {50, 0}, {61, 0}, {96, 0}}; - // 28: line number for stepinto array - size_t stepOut[4][2] = {{28, 0}, {43, 0}, {57, 0}, {88, 5}}; - SetJSPtLocation(breakpoint[0], POINTER_SIZE, pointerLocations_); - SetJSPtLocation(stepOut[0], STEP_SIZE, stepLocations_); - return true; - }; - vmDeath = [this]() { ASSERT_EQ(breakpointCounter_, pointerLocations_.size()); // size: break point counter ASSERT_EQ(stepCompleteCounter_, stepLocations_.size()); // size: step complete counter @@ -40,6 +30,12 @@ public: }; loadModule = [this](std::string_view moduleName) { + // 74、36: line number for breakpoint array + size_t breakpoint[5][2] = {{74, 0}, {36, 0}, {50, 0}, {61, 0}, {96, 0}}; + // 28: line number for stepinto array + size_t stepOut[4][2] = {{28, 0}, {43, 0}, {57, 0}, {88, 5}}; + SetJSPtLocation(breakpoint[0], POINTER_SIZE, pointerLocations_); + SetJSPtLocation(stepOut[0], STEP_SIZE, stepLocations_); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); debugger_->NotifyScriptParsed(0, moduleName.data()); diff --git a/tooling/test/testcases/js_step_over_test.h b/tooling/test/testcases/js_step_over_test.h index e2718db36fd86e447b0dc2a90e309794612600b2..6c93ed5bd7f0ab46c061b1f75f78a71058d1f74a 100644 --- a/tooling/test/testcases/js_step_over_test.h +++ b/tooling/test/testcases/js_step_over_test.h @@ -23,16 +23,6 @@ class JsStepOverTest : public TestEvents { public: JsStepOverTest() { - vmStart = [this] { - // 24、27: line number for breakpoint array - size_t breakpoint[8][2] = {{24, 0}, {27, 0}, {36, 0}, {50, 0}, {60, 0}, {90, 0}, {96, 0}, {54, 0}}; - // 25、28: line number for stepinto array - size_t stepOver[7][2] = {{25, 5}, {28, 0}, {37, 0}, {51, 0}, {61, 0}, {91, 5}, {97, 15}}; - SetJSPtLocation(breakpoint[0], POINTER_SIZE, pointerLocations_); - SetJSPtLocation(stepOver[0], STEP_SIZE, stepLocations_); - return true; - }; - vmDeath = [this]() { ASSERT_EQ(breakpointCounter_, pointerLocations_.size()); // size: break point counter ASSERT_EQ(stepCompleteCounter_, stepLocations_.size()); // size: step complete counter @@ -40,6 +30,12 @@ public: }; loadModule = [this](std::string_view moduleName) { + // 24、27: line number for breakpoint array + size_t breakpoint[8][2] = {{24, 0}, {27, 0}, {36, 0}, {50, 0}, {60, 0}, {90, 0}, {96, 0}, {54, 0}}; + // 25、28: line number for stepinto array + size_t stepOver[7][2] = {{25, 5}, {28, 0}, {37, 0}, {51, 0}, {61, 0}, {91, 5}, {97, 15}}; + SetJSPtLocation(breakpoint[0], POINTER_SIZE, pointerLocations_); + SetJSPtLocation(stepOver[0], STEP_SIZE, stepLocations_); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); debugger_->NotifyScriptParsed(0, moduleName.data()); diff --git a/tooling/test/testcases/js_syntax_exception_test.h b/tooling/test/testcases/js_syntax_exception_test.h index 9eeee16d825e2b2dfd916b817f6dcac065b79b36..7d9bdfefdd6307b5f1f1d0fdc5fe1b754a77f31d 100644 --- a/tooling/test/testcases/js_syntax_exception_test.h +++ b/tooling/test/testcases/js_syntax_exception_test.h @@ -23,12 +23,6 @@ class JsSyntaxExceptionTest : public TestEvents { public: JsSyntaxExceptionTest() { - vmStart = [this] { - location_ = TestUtil::GetLocation(27, 0, pandaFile_.c_str()); // 27: breakpointer line - ASSERT_TRUE(location_.GetMethodId().IsValid()); - return true; - }; - breakpoint = [this](const JSPtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); @@ -61,6 +55,8 @@ public: }; loadModule = [this](std::string_view moduleName) { + location_ = TestUtil::GetLocation(27, 0, pandaFile_.c_str()); // 27: breakpointer line + ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); diff --git a/tooling/test/testcases/js_throw_exception_test.h b/tooling/test/testcases/js_throw_exception_test.h index a290e0c11ccf9578a767156af2caac7261584108..a8df974216a50dc001fefbf7283d6b1a99ec5b89 100644 --- a/tooling/test/testcases/js_throw_exception_test.h +++ b/tooling/test/testcases/js_throw_exception_test.h @@ -23,14 +23,6 @@ class JsThrowExceptionTest : public TestEvents { public: JsThrowExceptionTest() { - vmStart = [this] { - location_ = TestUtil::GetLocation(28, 0, pandaFile_.c_str()); // 28: breakpointer line - std::cout<<"vmStart1"<NotifyScriptParsed(0, pandaFile_)); diff --git a/tooling/test/utils/test_extractor.cpp b/tooling/test/utils/test_extractor.cpp index c1d1412c5d0ef483e88409a7c0febdda6e417262..4477c17d5a935cc419f4cd733b515aa07389358b 100644 --- a/tooling/test/utils/test_extractor.cpp +++ b/tooling/test/utils/test_extractor.cpp @@ -35,13 +35,13 @@ std::pair TestExtractor::GetBreakpointAddress(const SourceLo retOffset = jsLocation.GetBytecodeOffset(); return true; }; - MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, sourceLocation.path); + MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, ""); return {retId, retOffset}; } -SourceLocation TestExtractor::GetSourceLocation(EntityId methodId, uint32_t bytecodeOffset) +SourceLocation TestExtractor::GetSourceLocation(const JSPandaFile *file, EntityId methodId, uint32_t bytecodeOffset) { - SourceLocation location {GetSourceFile(methodId), 0, 0}; + SourceLocation location {file, 0, 0}; auto callbackLineFunc = [&location](int32_t line) -> bool { location.line = line; return true; diff --git a/tooling/test/utils/test_extractor.h b/tooling/test/utils/test_extractor.h index 2080a2e49ec14efbdf1df4155a8f9a8f0eaadf1a..5fc1110d4ccc070fc6bffd4f59aeb5d42fd4351a 100644 --- a/tooling/test/utils/test_extractor.h +++ b/tooling/test/utils/test_extractor.h @@ -23,18 +23,13 @@ using EntityId = panda_file::File::EntityId; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) struct SourceLocation { - std::string path; // NOLINT(misc-non-private-member-variables-in-classes) - int32_t line; // NOLINT(misc-non-private-member-variables-in-classes) + const JSPandaFile *file; + int32_t line; int32_t column; bool operator==(const SourceLocation &other) const { - return path == other.path && line == other.line && column == other.column; - } - - bool IsValid() const - { - return !path.empty(); + return file == other.file && line == other.line && column == other.column; } }; @@ -45,7 +40,7 @@ public: std::pair GetBreakpointAddress(const SourceLocation &sourceLocation); - SourceLocation GetSourceLocation(EntityId methodId, uint32_t bytecodeOffset); + SourceLocation GetSourceLocation(const JSPandaFile *file, EntityId methodId, uint32_t bytecodeOffset); }; } // namespace panda::ecmascript::tooling::test diff --git a/tooling/test/utils/test_hooks.h b/tooling/test/utils/test_hooks.h index 89165e19cc9a63b6e8395c04691091271c5a5ebe..f791b7f0d690342c9f249fba6e710cec55dc8e56 100644 --- a/tooling/test/utils/test_hooks.h +++ b/tooling/test/utils/test_hooks.h @@ -97,7 +97,7 @@ public: void PendingJobEntry() override {} - void NativeCalling(const void *nativeAddress) override {} + void NativeCalling([[maybe_unused]] const void *nativeAddress) override {} void TerminateTest() { diff --git a/tooling/test/utils/test_util.h b/tooling/test/utils/test_util.h index 893e04d33a31e486159449ee33f1a282767fd627..19955a33694eb2650a6b73ad760cb77328d7fea3 100644 --- a/tooling/test/utils/test_util.h +++ b/tooling/test/utils/test_util.h @@ -131,23 +131,25 @@ public: static JSPtLocation GetLocation(int32_t line, int32_t column, const char *pandaFile) { - auto jsPandaFile = ::panda::ecmascript::JSPandaFileManager::GetInstance()->OpenJSPandaFile(pandaFile); + auto jsPandaFile = ::panda::ecmascript::JSPandaFileManager::GetInstance()->FindJSPandaFile(pandaFile); if (jsPandaFile == nullptr) { - return JSPtLocation(nullptr, EntityId(0), 0); + LOG_DEBUGGER(FATAL) << "cannot find: " << pandaFile; + UNREACHABLE(); } TestExtractor extractor(jsPandaFile); - auto [id, offset] = extractor.GetBreakpointAddress({nullptr, line, column}); + auto [id, offset] = extractor.GetBreakpointAddress({jsPandaFile, line, column}); return JSPtLocation(jsPandaFile, id, offset); } static SourceLocation GetSourceLocation(const JSPtLocation &location, const char *pandaFile) { - auto jsPandaFile = ::panda::ecmascript::JSPandaFileManager::GetInstance()->OpenJSPandaFile(pandaFile); + auto jsPandaFile = ::panda::ecmascript::JSPandaFileManager::GetInstance()->FindJSPandaFile(pandaFile); if (jsPandaFile == nullptr) { - return SourceLocation(); + LOG_DEBUGGER(FATAL) << "cannot find: " << pandaFile; + UNREACHABLE(); } TestExtractor extractor(jsPandaFile); - return extractor.GetSourceLocation(location.GetMethodId(), location.GetBytecodeOffset()); + return extractor.GetSourceLocation(jsPandaFile, location.GetMethodId(), location.GetBytecodeOffset()); } static bool SuspendUntilContinue(DebugEvent reason, JSPtLocation location = JSPtLocation(nullptr, EntityId(0), 0))