mirror of
https://gitee.com/openharmony/arkcompiler_toolchain
synced 2024-11-27 17:50:33 +00:00
!70 Add TracingImpl and ProfilerImpl testcases for tooling
Merge pull request !70 from hunili/master
This commit is contained in:
commit
360fa1ccb6
@ -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()) {
|
||||
|
@ -75,8 +75,6 @@ public:
|
||||
explicit Frontend(ProtocolChannel *channel) : channel_(channel) {}
|
||||
~Frontend() = default;
|
||||
|
||||
void ConsoleProfileFinished();
|
||||
void ConsoleProfileStarted();
|
||||
void PreciseCoverageDeltaUpdate();
|
||||
|
||||
private:
|
||||
|
@ -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" ]
|
||||
|
427
tooling/test/profiler_impl_test.cpp
Normal file
427
tooling/test/profiler_impl_test.cpp
Normal file
@ -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<ProfilerImpl>(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<ProfilerImpl>(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<ProfilerImpl>(ecmaVm, channel);
|
||||
DispatchResponse response = profiler->Start();
|
||||
std::unique_ptr<Profile> 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<ProfilerImpl>(ecmaVm, channel);
|
||||
std::unique_ptr<Profile> 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<ProfilerImpl>(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<ProfilerImpl>(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<ProfilerImpl>(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<ProfilerImpl>(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<ProfilerImpl>(ecmaVm, channel);
|
||||
std::string msg = std::string() + R"({"id":0,"method":"Debugger.requestMemoryDump","params":{}})";
|
||||
DispatchRequest request = DispatchRequest(msg);
|
||||
std::unique_ptr<StartPreciseCoverageParams> 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<ProfilerImpl>(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<ProfilerImpl>(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<ProfilerImpl>(ecmaVm, channel);
|
||||
DispatchResponse response = profiler->TakeTypeProfile();
|
||||
ASSERT_TRUE(response.GetMessage() == "TakeTypeProfile not support now");
|
||||
}
|
||||
|
||||
HWTEST_F_L0(ProfilerImplTest, DispatcherImplDispatch)
|
||||
{
|
||||
std::string result = "";
|
||||
std::function<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<ProfilerImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<ProfilerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = nullptr;
|
||||
auto frontend = std::make_unique<ProfilerImpl::Frontend>(channel);
|
||||
frontend->PreciseCoverageDeltaUpdate();
|
||||
ASSERT_TRUE(result == "");
|
||||
if (!channel) {
|
||||
channel = new ProtocolHandler(callback, ecmaVm);
|
||||
}
|
||||
auto frontend1 = std::make_unique<ProfilerImpl::Frontend>(channel);
|
||||
frontend1->PreciseCoverageDeltaUpdate();
|
||||
if (channel) {
|
||||
delete channel;
|
||||
channel = nullptr;
|
||||
}
|
||||
ASSERT_TRUE(result.find("Profile.PreciseCoverageDeltaUpdate") != std::string::npos);
|
||||
}
|
||||
} // namespace panda::test
|
273
tooling/test/tracing_impl_test.cpp
Normal file
273
tooling/test/tracing_impl_test.cpp
Normal file
@ -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<TracingImpl>(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<TracingImpl>(ecmaVm, channel);
|
||||
std::vector<std::string> 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<TracingImpl>(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<TracingImpl>(ecmaVm, channel);
|
||||
auto params = std::make_unique<RequestMemoryDumpParams>();
|
||||
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<TracingImpl>(ecmaVm, channel);
|
||||
auto params = std::make_unique<StartParams>();
|
||||
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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<TracingImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<TracingImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<TracingImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<TracingImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<TracingImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<TracingImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<TracingImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<TracingImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<TracingImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<TracingImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto tracing = std::make_unique<TracingImpl>(ecmaVm, channel);
|
||||
auto dispatcherImpl = std::make_unique<TracingImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = nullptr;
|
||||
auto frontend = std::make_unique<TracingImpl::Frontend>(channel);
|
||||
frontend->BufferUsage();
|
||||
ASSERT_TRUE(result == "");
|
||||
if (!channel) {
|
||||
channel = new ProtocolHandler(callback, ecmaVm);
|
||||
}
|
||||
auto frontend1 = std::make_unique<TracingImpl::Frontend>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = nullptr;
|
||||
auto frontend = std::make_unique<TracingImpl::Frontend>(channel);
|
||||
frontend->DataCollected();
|
||||
ASSERT_TRUE(result == "");
|
||||
if (!channel) {
|
||||
channel = new ProtocolHandler(callback, ecmaVm);
|
||||
}
|
||||
auto frontend1 = std::make_unique<TracingImpl::Frontend>(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<void(const void*, const std::string &)> callback =
|
||||
[&result]([[maybe_unused]]const void* ptr, const std::string &temp) { result = temp; };
|
||||
ProtocolChannel *channel = nullptr;
|
||||
auto frontend = std::make_unique<TracingImpl::Frontend>(channel);
|
||||
frontend->TracingComplete();
|
||||
ASSERT_TRUE(result == "");
|
||||
if (!channel) {
|
||||
channel = new ProtocolHandler(callback, ecmaVm);
|
||||
}
|
||||
auto frontend1 = std::make_unique<TracingImpl::Frontend>(channel);
|
||||
frontend1->TracingComplete();
|
||||
if (channel) {
|
||||
delete channel;
|
||||
channel = nullptr;
|
||||
}
|
||||
ASSERT_TRUE(result.find("Tracing.TracingComplete") != std::string::npos);
|
||||
}
|
||||
} // namespace panda::test
|
Loading…
Reference in New Issue
Block a user