From 18ec95e3b221eafd21ceea49ea0847958b6ca0d0 Mon Sep 17 00:00:00 2001 From: lihucheng Date: Mon, 7 Nov 2022 09:03:18 +0800 Subject: [PATCH] Add TracingImpl and ProfilerImpl testcases for tooling issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/I5ZPIC Signed-off-by: lihucheng --- tooling/agent/profiler_impl.cpp | 20 -- tooling/agent/profiler_impl.h | 2 - tooling/test/BUILD.gn | 2 + tooling/test/profiler_impl_test.cpp | 427 ++++++++++++++++++++++++++++ tooling/test/tracing_impl_test.cpp | 273 ++++++++++++++++++ 5 files changed, 702 insertions(+), 22 deletions(-) create mode 100644 tooling/test/profiler_impl_test.cpp create mode 100644 tooling/test/tracing_impl_test.cpp diff --git a/tooling/agent/profiler_impl.cpp b/tooling/agent/profiler_impl.cpp index d82dd4da..c537181e 100644 --- a/tooling/agent/profiler_impl.cpp +++ b/tooling/agent/profiler_impl.cpp @@ -142,26 +142,6 @@ bool ProfilerImpl::Frontend::AllowNotify() const return channel_ != nullptr; } -void ProfilerImpl::Frontend::ConsoleProfileFinished() -{ - if (!AllowNotify()) { - return; - } - - tooling::ConsoleProfileFinished consoleProfileFinished; - channel_->SendNotification(consoleProfileFinished); -} - -void ProfilerImpl::Frontend::ConsoleProfileStarted() -{ - if (!AllowNotify()) { - return; - } - - tooling::ConsoleProfileStarted consoleProfileStarted; - channel_->SendNotification(consoleProfileStarted); -} - void ProfilerImpl::Frontend::PreciseCoverageDeltaUpdate() { if (!AllowNotify()) { diff --git a/tooling/agent/profiler_impl.h b/tooling/agent/profiler_impl.h index ec165dee..0aa224ad 100644 --- a/tooling/agent/profiler_impl.h +++ b/tooling/agent/profiler_impl.h @@ -75,8 +75,6 @@ public: explicit Frontend(ProtocolChannel *channel) : channel_(channel) {} ~Frontend() = default; - void ConsoleProfileFinished(); - void ConsoleProfileStarted(); void PreciseCoverageDeltaUpdate(); private: diff --git a/tooling/test/BUILD.gn b/tooling/test/BUILD.gn index c4da48d6..2a21da8c 100644 --- a/tooling/test/BUILD.gn +++ b/tooling/test/BUILD.gn @@ -175,8 +175,10 @@ host_unittest_action("DebuggerTest") { "debugger_script_test.cpp", "debugger_types_test.cpp", "js_pt_hooks_test.cpp", + "profiler_impl_test.cpp", "pt_base64_test.cpp", "pt_json_test.cpp", + "tracing_impl_test.cpp", ] configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] diff --git a/tooling/test/profiler_impl_test.cpp b/tooling/test/profiler_impl_test.cpp new file mode 100644 index 00000000..f1708ad7 --- /dev/null +++ b/tooling/test/profiler_impl_test.cpp @@ -0,0 +1,427 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "agent/profiler_impl.h" +#include "ecmascript/tests/test_helper.h" +#include "protocol_handler.h" + +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +namespace panda::test { +class ProfilerImplTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope); + } + +protected: + EcmaVM *ecmaVm {nullptr}; + EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +HWTEST_F_L0(ProfilerImplTest, Disable) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->Disable(); + ASSERT_TRUE(response.GetMessage() == ""); + ASSERT_TRUE(response.IsOk()); +} + +HWTEST_F_L0(ProfilerImplTest, Enable) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->Enable(); + ASSERT_TRUE(response.GetMessage() == ""); + ASSERT_TRUE(response.IsOk()); +} + + +HWTEST_F_L0(ProfilerImplTest, Start) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->Start(); + std::unique_ptr profile; + DispatchResponse response1 = profiler->Stop(&profile); + ASSERT_TRUE(response.IsOk()); + ASSERT_TRUE(response1.IsOk()); + ASSERT_TRUE(profile); +} + +HWTEST_F_L0(ProfilerImplTest, Stop) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + std::unique_ptr profile; + DispatchResponse response = profiler->Stop(&profile); + ASSERT_TRUE(response.GetMessage().find("Stop is failure") != std::string::npos); + ASSERT_TRUE(!response.IsOk()); +} + +HWTEST_F_L0(ProfilerImplTest, SetSamplingInterval) +{ + ProtocolChannel *channel = nullptr; + SetSamplingIntervalParams params; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->SetSamplingInterval(params); + ASSERT_TRUE(response.GetMessage() == ""); + ASSERT_TRUE(response.IsOk()); +} + +HWTEST_F_L0(ProfilerImplTest, GetBestEffortCoverage) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->GetBestEffortCoverage(); + ASSERT_TRUE(response.GetMessage() == "GetBestEffortCoverage not support now"); +} + +HWTEST_F_L0(ProfilerImplTest, StopPreciseCoverage) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->StopPreciseCoverage(); + ASSERT_TRUE(response.GetMessage() == "StopPreciseCoverage not support now"); +} + +HWTEST_F_L0(ProfilerImplTest, TakePreciseCoverage) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->TakePreciseCoverage(); + ASSERT_TRUE(response.GetMessage() == "TakePreciseCoverage not support now"); +} + +HWTEST_F_L0(ProfilerImplTest, StartPreciseCoverage) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + std::string msg = std::string() + R"({"id":0,"method":"Debugger.requestMemoryDump","params":{}})"; + DispatchRequest request = DispatchRequest(msg); + std::unique_ptr params = StartPreciseCoverageParams::Create(request.GetParams()); + DispatchResponse response = profiler->StartPreciseCoverage(*params); + ASSERT_TRUE(response.GetMessage() == "StartPreciseCoverage not support now"); +} + +HWTEST_F_L0(ProfilerImplTest, StartTypeProfile) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->StartTypeProfile(); + ASSERT_TRUE(response.GetMessage() == "StartTypeProfile not support now"); +} + +HWTEST_F_L0(ProfilerImplTest, StopTypeProfile) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->StopTypeProfile(); + ASSERT_TRUE(response.GetMessage() == "StopTypeProfile not support now"); +} + +HWTEST_F_L0(ProfilerImplTest, TakeTypeProfile) +{ + ProtocolChannel *channel = nullptr; + auto profiler = std::make_unique(ecmaVm, channel); + DispatchResponse response = profiler->TakeTypeProfile(); + ASSERT_TRUE(response.GetMessage() == "TakeTypeProfile not support now"); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplDispatch) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->Dispatch(request); + ASSERT_TRUE(result.find("Unknown method: Test") != std::string::npos); + msg = std::string() + R"({"id":0,"method":"Debugger.disable","params":{}})"; + DispatchRequest request1 = DispatchRequest(msg); + dispatcherImpl->Dispatch(request1); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplEnable) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->Enable(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplDisable) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->Disable(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplStart) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->Start(request); + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); + dispatcherImpl->Stop(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("\"id\":0") != std::string::npos); + ASSERT_TRUE(result.find("\"profile\"") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplStop) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->Stop(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("Stop is failure") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplSetSamplingInterval) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->SetSamplingInterval(request); + ASSERT_TRUE(result.find("wrong params") != std::string::npos); + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"interval":24}})"; + DispatchRequest request1(msg); + dispatcherImpl->SetSamplingInterval(request1); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplGetBestEffortCoverage) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->GetBestEffortCoverage(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("GetBestEffortCoverage not support now") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplStopPreciseCoverage) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->StopPreciseCoverage(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("StopPreciseCoverage not support now") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplTakePreciseCoverage) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->TakePreciseCoverage(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("TakePreciseCoverage not support now") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplStartPreciseCoverage) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->StartPreciseCoverage(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("StartPreciseCoverage not support now") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplStartTypeProfile) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->StartTypeProfile(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("StartTypeProfile not support now") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplStopTypeProfile) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->StopTypeProfile(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("StopTypeProfile not support now") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplTakeTypeProfile) +{ + 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":"Debugger.Test","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->TakeTypeProfile(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("TakeTypeProfile not support now") != std::string::npos); +} + +HWTEST_F_L0(ProfilerImplTest, FrontendPreciseCoverageDeltaUpdate) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; }; + ProtocolChannel *channel = nullptr; + auto frontend = std::make_unique(channel); + frontend->PreciseCoverageDeltaUpdate(); + ASSERT_TRUE(result == ""); + if (!channel) { + channel = new ProtocolHandler(callback, ecmaVm); + } + auto frontend1 = std::make_unique(channel); + frontend1->PreciseCoverageDeltaUpdate(); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("Profile.PreciseCoverageDeltaUpdate") != std::string::npos); +} +} // namespace panda::test diff --git a/tooling/test/tracing_impl_test.cpp b/tooling/test/tracing_impl_test.cpp new file mode 100644 index 00000000..a30c0e22 --- /dev/null +++ b/tooling/test/tracing_impl_test.cpp @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "agent/tracing_impl.h" +#include "ecmascript/tests/test_helper.h" +#include "protocol_handler.h" + +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +namespace panda::test { +class TracingImplTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope); + } + +protected: + EcmaVM *ecmaVm {nullptr}; + EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +HWTEST_F_L0(TracingImplTest, EndTest) +{ + ProtocolChannel *channel = nullptr; + auto tracing = std::make_unique(ecmaVm, channel); + DispatchResponse response = tracing->End(); + ASSERT_TRUE(response.GetMessage() == "End not support now."); +} + +HWTEST_F_L0(TracingImplTest, GetCategoriesTest) +{ + ProtocolChannel *channel = nullptr; + auto tracing = std::make_unique(ecmaVm, channel); + std::vector categories = {}; + DispatchResponse response = tracing->GetCategories(categories); + ASSERT_TRUE(response.GetMessage() == "GetCategories not support now."); +} + +HWTEST_F_L0(TracingImplTest, RecordClockSyncMarkerTest) +{ + ProtocolChannel *channel = nullptr; + auto tracing = std::make_unique(ecmaVm, channel); + std::string syncId; + DispatchResponse response = tracing->RecordClockSyncMarker(syncId); + ASSERT_TRUE(response.GetMessage() == "RecordClockSyncMarker not support now."); +} + +HWTEST_F_L0(TracingImplTest, RequestMemoryDumpTest) +{ + ProtocolChannel *channel = nullptr; + auto tracing = std::make_unique(ecmaVm, channel); + auto params = std::make_unique(); + std::string dumpGuid; + bool success = false; + DispatchResponse response = tracing->RequestMemoryDump(std::move(params), dumpGuid, success); + ASSERT_TRUE(response.GetMessage() == "RequestMemoryDump not support now."); +} + +HWTEST_F_L0(TracingImplTest, StartTest) +{ + ProtocolChannel *channel = nullptr; + auto tracing = std::make_unique(ecmaVm, channel); + auto params = std::make_unique(); + DispatchResponse response = tracing->Start(std::move(params)); + ASSERT_TRUE(response.GetMessage() == "Start not support now."); +} + +HWTEST_F_L0(TracingImplTest, DispatcherImplDispatchTest) +{ + 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":"Debugger.Test","params":{}})";; + DispatchRequest request(msg); + dispatcherImpl->Dispatch(request); + ASSERT_TRUE(result.find("Unknown method: Test") != std::string::npos); + msg = std::string() + R"({"id":0,"method":"Debugger.end","params":{}})"; + DispatchRequest request1 = DispatchRequest(msg); + dispatcherImpl->Dispatch(request1); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("End not support now.") != std::string::npos); +} + +HWTEST_F_L0(TracingImplTest, DispatcherImplEndTest) +{ + 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":"Debugger.end","params":{}})"; + DispatchRequest request = DispatchRequest(msg); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("End not support now.") != std::string::npos); +} + +HWTEST_F_L0(TracingImplTest, DispatcherImplGetCategoriesTest) +{ + 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":"Debugger.getCategories","params":{}})"; + DispatchRequest request = DispatchRequest(msg); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("GetCategories not support now") != std::string::npos); +} + +HWTEST_F_L0(TracingImplTest, DispatcherImplRecordClockSyncMarkerTest) +{ + 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":"Debugger.recordClockSyncMarker","params":{}})"; + DispatchRequest request = DispatchRequest(msg); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("RecordClockSyncMarker not support now.") != std::string::npos); +} + +HWTEST_F_L0(TracingImplTest, DispatcherImplRequestMemoryDumpTest) +{ + 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":"Debugger.requestMemoryDump","params":{}})"; + DispatchRequest request = DispatchRequest(msg); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("RequestMemoryDump not support now.") != std::string::npos); +} + +HWTEST_F_L0(TracingImplTest, DispatcherImplStartDumpTest) +{ + 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":"Debugger.start","params":{}})"; + DispatchRequest request = DispatchRequest(msg); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("Start not support now.") != std::string::npos); +} + +HWTEST_F_L0(TracingImplTest, FrontendBufferUsageTest) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; }; + ProtocolChannel *channel = nullptr; + auto frontend = std::make_unique(channel); + frontend->BufferUsage(); + ASSERT_TRUE(result == ""); + if (!channel) { + channel = new ProtocolHandler(callback, ecmaVm); + } + auto frontend1 = std::make_unique(channel); + frontend1->BufferUsage(); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("Tracing.BufferUsage") != std::string::npos); +} + + +HWTEST_F_L0(TracingImplTest, FrontendDataCollectedTest) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; }; + ProtocolChannel *channel = nullptr; + auto frontend = std::make_unique(channel); + frontend->DataCollected(); + ASSERT_TRUE(result == ""); + if (!channel) { + channel = new ProtocolHandler(callback, ecmaVm); + } + auto frontend1 = std::make_unique(channel); + frontend1->DataCollected(); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("Tracing.DataCollected") != std::string::npos); +} + +HWTEST_F_L0(TracingImplTest, FrontendTracingCompleteTest) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; }; + ProtocolChannel *channel = nullptr; + auto frontend = std::make_unique(channel); + frontend->TracingComplete(); + ASSERT_TRUE(result == ""); + if (!channel) { + channel = new ProtocolHandler(callback, ecmaVm); + } + auto frontend1 = std::make_unique(channel); + frontend1->TracingComplete(); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result.find("Tracing.TracingComplete") != std::string::npos); +} +} // namespace panda::test \ No newline at end of file -- Gitee