diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 7d0e3654f47122243847dc7ad7ce7fa86f683020..49706ee58a9dd8d707622bf823259c6e9e226909 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -47,6 +47,26 @@ public: { return debuggerImpl_->DecodeAndCheckBase64(src, dest); } + + void BreakpointResolved(const EcmaVM *vm) + { + debuggerImpl_->frontend_.BreakpointResolved(vm); + } + + void NativeCalling(const EcmaVM *vm, const tooling::NativeCalling &nativeCalling) + { + debuggerImpl_->frontend_.NativeCalling(vm, nativeCalling); + } + + void MixedStack(const EcmaVM *vm, const tooling::MixedStack &mixedStack) + { + debuggerImpl_->frontend_.MixedStack(vm, mixedStack); + } + + void ScriptFailedToParse(const EcmaVM *vm) + { + debuggerImpl_->frontend_.ScriptFailedToParse(vm); + } private: std::unique_ptr debuggerImpl_; }; @@ -1845,4 +1865,122 @@ HWTEST_F_L0(DebuggerImplTest, ConvertToLocal__001) taggedValue = debugger->ConvertToLocal("1"); ASSERT_TRUE(!taggedValue.IsEmpty()); } + +HWTEST_F_L0(DebuggerImplTest, BreakpointResolved__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + + auto debugger = std::make_unique(debuggerImpl); + debugger->BreakpointResolved(ecmaVm); + EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode() && protocolChannel != nullptr); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NativeCalling__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + + auto debugger = std::make_unique(debuggerImpl); + tooling::NativeCalling nativeCalling; + debugger->NativeCalling(ecmaVm, nativeCalling); + EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode() && protocolChannel != nullptr); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, MixedStack__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + + auto debugger = std::make_unique(debuggerImpl); + tooling::MixedStack mixedStack; + debugger->MixedStack(ecmaVm, mixedStack); + EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode() && protocolChannel != nullptr); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, ScriptFailedToParse__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + + auto debugger = std::make_unique(debuggerImpl); + debugger->ScriptFailedToParse(ecmaVm); + EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode() && protocolChannel != nullptr); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, SendableScriptParsed__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + // DebuggerImpl::NotifyScriptParsed -- fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH + std::string strFilename = ""; + EXPECT_FALSE(debuggerImpl->SendableScriptParsed("","",strFilename, "")); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints -- params == nullptr + std::string msg = ""; + DispatchRequest request(msg); + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":-1,"result":{"code":1,"message":"Unknown method: "}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} } // namespace panda::test diff --git a/tooling/test/heapprofiler_impl_test.cpp b/tooling/test/heapprofiler_impl_test.cpp index 80a2cb45b9e80568ad0368d76c6d6e15afcc2ee4..16fc9e4a38206d3b1478975e3fb6d8b778edba2d 100644 --- a/tooling/test/heapprofiler_impl_test.cpp +++ b/tooling/test/heapprofiler_impl_test.cpp @@ -570,4 +570,138 @@ HWTEST_F_L0(HeapProfilerImplTest, ReportHeapSnapshotProgress) heapprofiler->ReportHeapSnapshotProgress(0, 0); ASSERT_TRUE(result == ""); } + +HWTEST_F_L0(HeapProfilerImplTest, DispatchGetSamplingProfile) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.getSamplingProfile","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->GetSamplingProfile(request); + ASSERT_TRUE(result.find("GetSamplingProfile fail") != std::string::npos); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, DispatchStartSampling) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.startSampling","params":{ + "samplingInterval":"Test"}})"; + DispatchRequest request(msg); + dispatcherImpl->Dispatch(request); + dispatcherImpl->StartSampling(request); + ASSERT_TRUE(result.find("wrong params") != std::string::npos); + msg = std::string() + R"({"id":0,"method":"HeapProfiler.startSampling","params":{"samplingInterval":1000}})"; + DispatchRequest request1(msg); + dispatcherImpl->StartSampling(request1); + + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest,DispatchStopSampling) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.stopSampling","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->StopSampling(request); + dispatcherImpl->Dispatch(request); + ASSERT_TRUE(result.find("StopSampling fail") != std::string::npos); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, DispatchTakeHeapSnapshot) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.takeHeapSnapshot","params":{ + "reportProgress":10, + "treatGlobalObjectsAsRoots":10, + "captureNumericValue":10}})"; + DispatchRequest request(msg); + dispatcherImpl->TakeHeapSnapshot(request); + ASSERT_TRUE(result.find("wrong params") != std::string::npos); + msg = std::string() + R"({"id":0,"method":"HeapProfiler.takeHeapSnapshot","params":{ + "reportProgress":true, + "treatGlobalObjectsAsRoots":true, + "captureNumericValue":true}})"; + DispatchRequest request1(msg); + dispatcherImpl->TakeHeapSnapshot(request1); + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, DispatchStartTrackingHeapObjects) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = ""; + msg += R"({"id":0,"method":"HeapProfiler.StartTrackingHeapObjects","params":{"trackAllocations":0}})"; + DispatchRequest request1(msg); + dispatcherImpl->StartTrackingHeapObjects(request1); + ASSERT_TRUE(result == "{\"id\":0,\"result\":{\"code\":1,\"message\":\"wrong params\"}}"); + dispatcherImpl->Dispatch(request1); + ASSERT_FALSE(result == "{\"id\":0,\"result\":{\"code\":1,\"message\":\"wrong params\"}}"); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, DispatchStopTrackingHeapObjects) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = ""; + msg += R"({"id":0,"method":"HeapProfiler.StopTrackingHeapObjects","params":{"reportProgress":0}})"; + DispatchRequest request1(msg); + dispatcherImpl->StopTrackingHeapObjects(request1); + ASSERT_TRUE(result == "{\"id\":0,\"result\":{\"code\":1,\"message\":\"wrong params\"}}"); + dispatcherImpl->Dispatch(request1); + ASSERT_FALSE(result == "{\"id\":0,\"result\":{\"code\":1,\"message\":\"wrong params\"}}"); + if (channel) { + delete channel; + channel = nullptr; + } +} } // namespace panda::test