mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
Coverage supplement
Supplement the coverage of the debugger dfx/cpu_profiler Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAMW7G Signed-off-by: swx1282997 <shiminnan@huawei.com>
This commit is contained in:
parent
f87fd7f329
commit
be63bae64f
2
BUILD.gn
2
BUILD.gn
@ -101,6 +101,7 @@ group("ark_js_unittest") {
|
||||
"ecmascript/builtins/tests:unittest",
|
||||
"ecmascript/containers/tests:unittest",
|
||||
"ecmascript/debugger/tests:unittest",
|
||||
"ecmascript/dfx/cpu_profiler/tests:unittest",
|
||||
"ecmascript/dfx/hprof/tests:unittest",
|
||||
"ecmascript/dfx/stackinfo/tests:unittest",
|
||||
"ecmascript/extractortool/tests:unittest",
|
||||
@ -139,6 +140,7 @@ group("ark_unittest") {
|
||||
"ecmascript/base/tests:host_unittest",
|
||||
"ecmascript/builtins/tests:host_unittest",
|
||||
"ecmascript/containers/tests:host_unittest",
|
||||
"ecmascript/dfx/cpu_profiler/tests:host_unittest",
|
||||
"ecmascript/dfx/hprof/tests:host_unittest",
|
||||
"ecmascript/dfx/stackinfo/tests:host_unittest",
|
||||
"ecmascript/extractortool/tests:host_unittest",
|
||||
|
@ -55,6 +55,8 @@ private:
|
||||
std::stack<std::vector<std::tuple<JSHandle<JSTaggedValue>, uint16_t, JSHandle<JSTaggedValue>>>> modifiedLexVar_;
|
||||
std::stack<uint32_t> promiseQueueSizeRecord_;
|
||||
std::stack<std::tuple<JSPandaFile*, panda_file::File::EntityId>> methodInfo_;
|
||||
|
||||
friend class DropframeManagerFriendTest;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -188,6 +188,8 @@ private:
|
||||
|
||||
CUnorderedSet<JSBreakpoint, HashJSBreakpoint> breakpoints_ {};
|
||||
CUnorderedSet<JSBreakpoint, HashJSBreakpoint> smartBreakpoints_ {};
|
||||
|
||||
friend class JsDebuggerFriendTest;
|
||||
};
|
||||
} // namespace panda::ecmascript::tooling
|
||||
|
||||
|
@ -41,12 +41,14 @@ foreach(file, test_js_files) {
|
||||
}
|
||||
}
|
||||
|
||||
host_unittest_action("HotReloadManagerTest") {
|
||||
host_unittest_action("RuntimeDebuggerTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
# test file
|
||||
"dropframe_manager_test.cpp",
|
||||
"hot_reload_manager_test.cpp",
|
||||
"js_debugger_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
@ -87,12 +89,12 @@ group("unittest") {
|
||||
testonly = true
|
||||
|
||||
# deps file
|
||||
deps = [ ":HotReloadManagerTest" ]
|
||||
deps = [ ":RuntimeDebuggerTest" ]
|
||||
}
|
||||
|
||||
group("host_unittest") {
|
||||
testonly = true
|
||||
|
||||
# deps file
|
||||
deps = [ ":HotReloadManagerTestAction" ]
|
||||
deps = [ ":RuntimeDebuggerTestAction" ]
|
||||
}
|
||||
|
173
ecmascript/debugger/tests/dropframe_manager_test.cpp
Normal file
173
ecmascript/debugger/tests/dropframe_manager_test.cpp
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "ecmascript/tests/test_helper.h"
|
||||
#include "ecmascript/debugger/dropframe_manager.h"
|
||||
#include "ecmascript/jspandafile/js_pandafile_manager.h"
|
||||
#include "assembler/assembly-parser.h"
|
||||
|
||||
using namespace panda::ecmascript;
|
||||
using namespace panda::ecmascript::tooling;
|
||||
using namespace panda::panda_file;
|
||||
using namespace panda::pandasm;
|
||||
|
||||
namespace panda::ecmascript::tooling {
|
||||
class DropframeManagerFriendTest {
|
||||
public:
|
||||
std::vector<std::tuple<JSHandle<JSTaggedValue>, uint16_t,
|
||||
JSHandle<JSTaggedValue>>> GetLexModifyRecordOfTopFrameTest ()
|
||||
{
|
||||
return manager.GetLexModifyRecordOfTopFrame();
|
||||
}
|
||||
|
||||
void NewLexModifyRecordLevelTest()
|
||||
{
|
||||
manager.NewLexModifyRecordLevel();
|
||||
}
|
||||
|
||||
uint32_t GetLexModifyRecordLevelTest()
|
||||
{
|
||||
return manager.GetLexModifyRecordLevel();
|
||||
}
|
||||
|
||||
void RemoveLexModifyRecordOfTopFrameTest(JSThread *thread)
|
||||
{
|
||||
manager.RemoveLexModifyRecordOfTopFrame(thread);
|
||||
}
|
||||
|
||||
void PopMethodInfoTest()
|
||||
{
|
||||
manager.PopMethodInfo();
|
||||
}
|
||||
|
||||
void PushMethodInfoTest(std::tuple<JSPandaFile*, panda_file::File::EntityId> methodInfo)
|
||||
{
|
||||
manager.PushMethodInfo(methodInfo);
|
||||
}
|
||||
|
||||
bool CheckExitMethodInfoTest(std::tuple<JSPandaFile*, panda_file::File::EntityId> methodInfo)
|
||||
{
|
||||
return manager.CheckExitMethodInfo(methodInfo);
|
||||
}
|
||||
|
||||
void MergeLexModifyRecordOfTopFrameTest(JSThread *thread)
|
||||
{
|
||||
manager.MergeLexModifyRecordOfTopFrame(thread);
|
||||
}
|
||||
|
||||
private:
|
||||
DropframeManager manager;
|
||||
};
|
||||
}
|
||||
|
||||
namespace panda::test {
|
||||
class DropframeManagerTest : 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);
|
||||
}
|
||||
|
||||
EcmaVM *ecmaVm {nullptr};
|
||||
EcmaHandleScope *scope {nullptr};
|
||||
JSThread *thread {nullptr};
|
||||
};
|
||||
|
||||
HWTEST_F_L0(DropframeManagerTest, GetLexModifyRecordOfTopFrameTest)
|
||||
{
|
||||
DropframeManagerFriendTest manager;
|
||||
manager.GetLexModifyRecordOfTopFrameTest();
|
||||
uint32_t result = manager.GetLexModifyRecordLevelTest();
|
||||
EXPECT_FALSE(result);
|
||||
|
||||
manager.NewLexModifyRecordLevelTest();
|
||||
manager.GetLexModifyRecordOfTopFrameTest();
|
||||
result = manager.GetLexModifyRecordLevelTest();
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DropframeManagerTest, RemoveLexModifyRecordOfTopFrameTest)
|
||||
{
|
||||
DropframeManagerFriendTest manager;
|
||||
JSThread *thread = ecmaVm->GetJSThread();
|
||||
uint32_t result = manager.GetLexModifyRecordLevelTest();
|
||||
manager.RemoveLexModifyRecordOfTopFrameTest(thread);
|
||||
EXPECT_FALSE(result);
|
||||
|
||||
manager.NewLexModifyRecordLevelTest();
|
||||
result = manager.GetLexModifyRecordLevelTest();
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
manager.RemoveLexModifyRecordOfTopFrameTest(thread);
|
||||
result = manager.GetLexModifyRecordLevelTest();
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DropframeManagerTest, PopMethodInfoTest)
|
||||
{
|
||||
DropframeManagerFriendTest manager;
|
||||
Parser parser;
|
||||
const char *filename = "__PandaFileTranslatorTest2.pa";
|
||||
const char *data = R"(
|
||||
.function any func_main_0(any a0, any a1, any a2) {
|
||||
ldai 1
|
||||
return
|
||||
}
|
||||
)";
|
||||
auto res = parser.Parse(data);
|
||||
JSPandaFileManager *pfManager = JSPandaFileManager::GetInstance();
|
||||
std::unique_ptr<const File> pfPtr = pandasm::AsmEmitter::Emit(res.Value());
|
||||
std::shared_ptr<JSPandaFile> pf = pfManager->NewJSPandaFile(pfPtr.release(), CString(filename));
|
||||
const panda_file::File *testpf = pf.get()->GetPandaFile();
|
||||
CString descriptor = "example_descriptor";
|
||||
JSPandaFile* jspandaFilePtr = new JSPandaFile(testpf, descriptor);
|
||||
|
||||
panda_file::File::EntityId entityId(42);
|
||||
std::tuple<JSPandaFile*, panda_file::File::EntityId> methodInfo(jspandaFilePtr, entityId);
|
||||
|
||||
manager.PopMethodInfoTest();
|
||||
manager.PushMethodInfoTest(methodInfo);
|
||||
bool result = manager.CheckExitMethodInfoTest(methodInfo);
|
||||
EXPECT_EQ(result, true);
|
||||
|
||||
manager.PopMethodInfoTest();
|
||||
result = manager.CheckExitMethodInfoTest(methodInfo);
|
||||
EXPECT_EQ(result, false);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DropframeManagerTest, MergeLexModifyRecordOfTopFrameEmptyTest)
|
||||
{
|
||||
DropframeManagerFriendTest manager;
|
||||
JSThread *thread = ecmaVm->GetJSThread();
|
||||
manager.MergeLexModifyRecordOfTopFrameTest(thread);
|
||||
uint32_t result = manager.GetLexModifyRecordLevelTest();
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
} // namespace panda::test
|
142
ecmascript/debugger/tests/js_debugger_test.cpp
Normal file
142
ecmascript/debugger/tests/js_debugger_test.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "ecmascript/tests/test_helper.h"
|
||||
#include "ecmascript/debugger/js_debugger.h"
|
||||
#include "ecmascript/jspandafile/js_pandafile_manager.h"
|
||||
#include "assembler/assembly-parser.h"
|
||||
|
||||
using namespace panda::ecmascript;
|
||||
using namespace panda::ecmascript::tooling;
|
||||
using namespace panda::panda_file;
|
||||
using namespace panda::pandasm;
|
||||
|
||||
namespace panda::ecmascript::tooling {
|
||||
class JsDebuggerFriendTest {
|
||||
public:
|
||||
explicit JsDebuggerFriendTest(const EcmaVM* vm) : jsDebugger_(vm) {}
|
||||
|
||||
bool HandleStepTest(JSHandle<Method> method, uint32_t bcOffset)
|
||||
{
|
||||
return jsDebugger_.HandleStep(method, bcOffset);
|
||||
}
|
||||
|
||||
bool HandleNativeOutTest()
|
||||
{
|
||||
return jsDebugger_.HandleNativeOut();
|
||||
}
|
||||
|
||||
bool HandleBreakpointTest(JSHandle<Method> method, uint32_t bcOffset)
|
||||
{
|
||||
return jsDebugger_.HandleBreakpoint(method, bcOffset);
|
||||
}
|
||||
|
||||
bool IsBreakpointCondSatisfiedTest(std::optional<JSBreakpoint> breakpoint) const
|
||||
{
|
||||
return jsDebugger_.IsBreakpointCondSatisfied(breakpoint);
|
||||
}
|
||||
|
||||
private:
|
||||
JSDebugger jsDebugger_;
|
||||
};
|
||||
}
|
||||
|
||||
namespace panda::test {
|
||||
class JsDebuggerTest : 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);
|
||||
}
|
||||
|
||||
EcmaVM *ecmaVm {nullptr};
|
||||
EcmaHandleScope *scope {nullptr};
|
||||
JSThread *thread {nullptr};
|
||||
};
|
||||
|
||||
HWTEST_F_L0(JsDebuggerTest, SetSmartBreakpointTest)
|
||||
{
|
||||
JSDebugger debugger(ecmaVm);
|
||||
Parser parser;
|
||||
const char *filename = "__PandaFileTranslatorTest2.pa";
|
||||
const char *data = R"(
|
||||
.function any func_main_0(any a0, any a1, any a2) {
|
||||
ldai 1
|
||||
return
|
||||
}
|
||||
)";
|
||||
auto res = parser.Parse(data);
|
||||
JSPandaFileManager *pfManager = JSPandaFileManager::GetInstance();
|
||||
std::unique_ptr<const File> pfPtr = pandasm::AsmEmitter::Emit(res.Value());
|
||||
std::shared_ptr<JSPandaFile> pf = pfManager->NewJSPandaFile(pfPtr.release(), CString(filename));
|
||||
const panda_file::File *testpf = pf.get()->GetPandaFile();
|
||||
CString descriptor = "example_descriptor";
|
||||
std::shared_ptr<JSPandaFile> jspandaFilePtr = std::make_shared<JSPandaFile>(testpf, descriptor);
|
||||
pfManager->AddJSPandaFile(jspandaFilePtr);
|
||||
JSPandaFile* jspandaFilePtrTest = new JSPandaFile(testpf, descriptor);
|
||||
panda_file::File::EntityId entityId(42);
|
||||
|
||||
JSPtLocation location(jspandaFilePtrTest, entityId, 60, "sourceFile.js");
|
||||
bool result = debugger.RemoveBreakpoint(location);
|
||||
EXPECT_EQ(result, false);
|
||||
result = debugger.SetSmartBreakpoint(location);
|
||||
EXPECT_EQ(result, false);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsDebuggerTest, JsDebuggerHooksNullTest)
|
||||
{
|
||||
JSHandle<Method> methodHandle;
|
||||
uint32_t bcOffsetTest = 42;
|
||||
JSHandle<JSTaggedValue> envHandle;
|
||||
JSDebugger debugger(ecmaVm);
|
||||
debugger.MethodEntry(methodHandle, envHandle);
|
||||
|
||||
bool result = debugger.HandleDebuggerStmt(methodHandle, bcOffsetTest);
|
||||
EXPECT_EQ(result, false);
|
||||
|
||||
JsDebuggerFriendTest debuggerFriend(ecmaVm);
|
||||
result = debuggerFriend.HandleNativeOutTest();
|
||||
EXPECT_EQ(result, false);
|
||||
|
||||
result = debuggerFriend.HandleBreakpointTest(methodHandle, bcOffsetTest);
|
||||
EXPECT_EQ(result, false);
|
||||
|
||||
result = debuggerFriend.HandleStepTest(methodHandle, bcOffsetTest);
|
||||
EXPECT_EQ(result, false);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsDebuggerTest, JsDebuggerBreakpointNullTest)
|
||||
{
|
||||
JsDebuggerFriendTest debuggerFriend(ecmaVm);
|
||||
std::optional<ecmascript::tooling::JSBreakpoint> breakpoint;
|
||||
bool result = debuggerFriend.IsBreakpointCondSatisfiedTest(breakpoint);
|
||||
EXPECT_EQ(result, false);
|
||||
}
|
||||
} // namespace panda::test
|
@ -216,6 +216,8 @@ private:
|
||||
SourceMapTranslateCallback sourceMapTranslateCallback_ {nullptr};
|
||||
int traceEventNodePos_ = 0;
|
||||
uint32_t traceEventSamplePos_ = 0;
|
||||
|
||||
friend class SamplesRecordFriendTest;
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
#endif // ECMASCRIPT_DFX_CPU_PROFILER_SAMPLES_RECORD_H
|
||||
|
51
ecmascript/dfx/cpu_profiler/tests/BUILD.gn
Normal file
51
ecmascript/dfx/cpu_profiler/tests/BUILD.gn
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("//arkcompiler/ets_runtime/js_runtime_config.gni")
|
||||
import("//arkcompiler/ets_runtime/test/test_helper.gni")
|
||||
|
||||
module_output_path = "arkcompiler/ets_runtime"
|
||||
|
||||
host_unittest_action("CpuProfilerTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
# test file
|
||||
"samples_record_test.cpp",
|
||||
]
|
||||
|
||||
configs = [ "../../../../:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_third_party_root/icu/icu4c:shared_icui18n",
|
||||
"$ark_third_party_root/icu/icu4c:shared_icuuc",
|
||||
"../../../../:libark_jsruntime_test",
|
||||
]
|
||||
|
||||
# hiviewdfx libraries
|
||||
external_deps = hiviewdfx_ext_deps
|
||||
deps += hiviewdfx_deps
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":CpuProfilerTest" ]
|
||||
}
|
||||
|
||||
group("host_unittest") {
|
||||
testonly = true
|
||||
deps = [ ":CpuProfilerTestAction" ]
|
||||
if (is_mac) {
|
||||
deps -= [ ":CpuProfilerTestAction" ]
|
||||
}
|
||||
}
|
295
ecmascript/dfx/cpu_profiler/tests/samples_record_test.cpp
Normal file
295
ecmascript/dfx/cpu_profiler/tests/samples_record_test.cpp
Normal file
@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <cstdio>
|
||||
|
||||
#include "ecmascript/dfx/cpu_profiler/samples_record.h"
|
||||
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
|
||||
#include "ecmascript/tests/test_helper.h"
|
||||
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace panda::ecmascript {
|
||||
class SamplesRecordFriendTest {
|
||||
public:
|
||||
SamplesRecordFriendTest() : samples_record() {}
|
||||
|
||||
std::string AddRunningStateTest(char *functionName, RunningState state, kungfu::DeoptType type)
|
||||
{
|
||||
return samples_record.AddRunningState(functionName, state, type);
|
||||
}
|
||||
|
||||
void SetEnableVMTag(bool flag)
|
||||
{
|
||||
samples_record.SetEnableVMTag(flag);
|
||||
}
|
||||
|
||||
void StatisticStateTimeTest(int timeDelta, RunningState state)
|
||||
{
|
||||
samples_record.StatisticStateTime(timeDelta, state);
|
||||
}
|
||||
|
||||
bool PushNapiStackInfoTest(const FrameInfoTemp &frameInfoTemp)
|
||||
{
|
||||
return samples_record.PushNapiStackInfo(frameInfoTemp);
|
||||
}
|
||||
|
||||
void NapiFrameInfoTempToMapTest()
|
||||
{
|
||||
samples_record.NapiFrameInfoTempToMap();
|
||||
}
|
||||
|
||||
void TranslateUrlPositionBySourceMapTest(struct FrameInfo &codeEntry)
|
||||
{
|
||||
samples_record.TranslateUrlPositionBySourceMap(codeEntry);
|
||||
}
|
||||
|
||||
void sourceMapTranslateCallbackTest(SourceMapTranslateCallback sourceMapTranslateCallback_)
|
||||
{
|
||||
samples_record.sourceMapTranslateCallback_ = sourceMapTranslateCallback_;
|
||||
}
|
||||
|
||||
std::unique_ptr<ProfileInfo> GetProfileInfoTest()
|
||||
{
|
||||
return std::move(samples_record.profileInfo_);
|
||||
}
|
||||
|
||||
private:
|
||||
SamplesRecord samples_record;
|
||||
};
|
||||
}
|
||||
|
||||
namespace panda::test {
|
||||
class SamplesRecordTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "SetUpTestCase";
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "TearDownCase";
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
|
||||
instance->SetEnableForceGC(false);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
TestHelper::DestroyEcmaVMWithScope(instance, scope);
|
||||
}
|
||||
|
||||
EcmaVM *instance {nullptr};
|
||||
EcmaHandleScope *scope {nullptr};
|
||||
JSThread *thread {nullptr};
|
||||
};
|
||||
|
||||
HWTEST_F_L0(SamplesRecordTest, AddRunningStateTest)
|
||||
{
|
||||
SamplesRecordFriendTest samplesRecord;
|
||||
char funcName[] = "testFunction";
|
||||
std::string result = samplesRecord.AddRunningStateTest(funcName, RunningState::AINT_D,
|
||||
kungfu::DeoptType::NONE);
|
||||
EXPECT_EQ(result, "testFunction(AINT-D)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::GC,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(GC)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::CINT,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::AINT,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::AOT,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::BUILTIN,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(BUILTIN)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::NAPI,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(NAPI)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::ARKUI_ENGINE,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(ARKUI_ENGINE)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::RUNTIME,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::JIT,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(JIT)");
|
||||
|
||||
samplesRecord.SetEnableVMTag(true);
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::CINT,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(CINT)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::AINT,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(AINT)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::AOT,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(AOT)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::RUNTIME,
|
||||
kungfu::DeoptType::NOTDOUBLE1);
|
||||
EXPECT_EQ(result, "testFunction(RUNTIME)");
|
||||
|
||||
result = samplesRecord.AddRunningStateTest(funcName, RunningState::AINT_D,
|
||||
kungfu::DeoptType::NOTINT1);
|
||||
EXPECT_EQ(result, "testFunction(AINT-D)(DEOPT:NotInt1)");
|
||||
}
|
||||
|
||||
HWTEST_F_L0(SamplesRecordTest, StatisticStateTimeTest)
|
||||
{
|
||||
SamplesRecordFriendTest samplesRecord;
|
||||
samplesRecord.StatisticStateTimeTest(100, RunningState::AINT_D);
|
||||
samplesRecord.StatisticStateTimeTest(101, RunningState::GC);
|
||||
samplesRecord.StatisticStateTimeTest(102, RunningState::CINT);
|
||||
samplesRecord.StatisticStateTimeTest(103, RunningState::AINT);
|
||||
samplesRecord.StatisticStateTimeTest(104, RunningState::AOT);
|
||||
samplesRecord.StatisticStateTimeTest(105, RunningState::BUILTIN);
|
||||
samplesRecord.StatisticStateTimeTest(106, RunningState::NAPI);
|
||||
samplesRecord.StatisticStateTimeTest(107, RunningState::ARKUI_ENGINE);
|
||||
samplesRecord.StatisticStateTimeTest(108, RunningState::RUNTIME);
|
||||
samplesRecord.StatisticStateTimeTest(109, RunningState::JIT);
|
||||
|
||||
std::unique_ptr<ProfileInfo> profileInfo = samplesRecord.GetProfileInfoTest();
|
||||
EXPECT_EQ(profileInfo->asmInterpreterDeoptTime, 100);
|
||||
EXPECT_EQ(profileInfo->gcTime, 101);
|
||||
EXPECT_EQ(profileInfo->cInterpreterTime, 102);
|
||||
EXPECT_EQ(profileInfo->asmInterpreterTime, 103);
|
||||
EXPECT_EQ(profileInfo->aotTime, 104);
|
||||
EXPECT_EQ(profileInfo->builtinTime, 105);
|
||||
EXPECT_EQ(profileInfo->napiTime, 106);
|
||||
EXPECT_EQ(profileInfo->arkuiEngineTime, 107);
|
||||
EXPECT_EQ(profileInfo->runtimeTime, 108);
|
||||
EXPECT_EQ(profileInfo->jitTime, 109);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(SamplesRecordTest, PushStackTest)
|
||||
{
|
||||
SamplesRecord record;
|
||||
MethodKey key;
|
||||
|
||||
for (size_t i = 0; i < MAX_STACK_SIZE; ++i) {
|
||||
key.lineNumber = static_cast<int>(i);
|
||||
EXPECT_TRUE(record.PushFrameStack(key));
|
||||
}
|
||||
EXPECT_FALSE(record.PushFrameStack(key));
|
||||
|
||||
for (size_t i = 0; i < MAX_STACK_SIZE; ++i) {
|
||||
key.lineNumber = static_cast<int>(i);
|
||||
EXPECT_TRUE(record.PushNapiFrameStack(key));
|
||||
}
|
||||
EXPECT_FALSE(record.PushNapiFrameStack(key));
|
||||
|
||||
FrameInfoTemp frameInfoTemp;
|
||||
for (size_t i = 0; i < MAX_STACK_SIZE; ++i) {
|
||||
frameInfoTemp.lineNumber = static_cast<int>(i);
|
||||
EXPECT_TRUE(record.PushStackInfo(frameInfoTemp));
|
||||
}
|
||||
EXPECT_FALSE(record.PushStackInfo(frameInfoTemp));
|
||||
|
||||
for (size_t i = 0; i < MAX_STACK_SIZE; ++i) {
|
||||
frameInfoTemp.lineNumber = static_cast<int>(i);
|
||||
EXPECT_TRUE(record.PushNapiStackInfo(frameInfoTemp));
|
||||
}
|
||||
EXPECT_FALSE(record.PushNapiStackInfo(frameInfoTemp));
|
||||
}
|
||||
|
||||
HWTEST_F_L0(SamplesRecordTest, GetModuleNameTest)
|
||||
{
|
||||
SamplesRecord record;
|
||||
|
||||
char input1[] = "/path/to/module@version";
|
||||
EXPECT_EQ(record.GetModuleName(input1), "module");
|
||||
|
||||
char input2[] = "/path/to/module";
|
||||
EXPECT_EQ(record.GetModuleName(input2), "");
|
||||
|
||||
char input3[] = "module@version";
|
||||
EXPECT_EQ(record.GetModuleName(input3), "");
|
||||
}
|
||||
|
||||
HWTEST_F_L0(SamplesRecordTest, NapiFrameInfoTempToMapTest)
|
||||
{
|
||||
SamplesRecordFriendTest samplesRecord;
|
||||
samplesRecord.NapiFrameInfoTempToMapTest();
|
||||
FrameInfoTemp frameInfoTemp;
|
||||
frameInfoTemp.lineNumber = static_cast<int>(5);
|
||||
samplesRecord.PushNapiStackInfoTest(frameInfoTemp);
|
||||
samplesRecord.NapiFrameInfoTempToMapTest();
|
||||
}
|
||||
|
||||
HWTEST_F_L0(SamplesRecordTest, TranslateUrlPositionBySourceMapTest)
|
||||
{
|
||||
SamplesRecordFriendTest samplesRecord;
|
||||
FrameInfo entry1;
|
||||
SourceMapTranslateCallback sourceMapTranslateCallback_ = [](const std::string&, int, int) { return true; };
|
||||
samplesRecord.sourceMapTranslateCallbackTest(sourceMapTranslateCallback_);
|
||||
samplesRecord.TranslateUrlPositionBySourceMapTest(entry1);
|
||||
EXPECT_EQ(entry1.url, "");
|
||||
|
||||
FrameInfo entry2;
|
||||
entry2.url = "some_url.js";
|
||||
sourceMapTranslateCallback_ = [](const std::string&, int, int) { return true; };
|
||||
samplesRecord.sourceMapTranslateCallbackTest(sourceMapTranslateCallback_);
|
||||
samplesRecord.TranslateUrlPositionBySourceMapTest(entry2);
|
||||
EXPECT_EQ(entry2.url, "some_url.js");
|
||||
|
||||
FrameInfo entry3;
|
||||
entry3.url = "path/to/_.js";
|
||||
sourceMapTranslateCallback_ = [](const std::string&, int, int) { return false; };
|
||||
samplesRecord.sourceMapTranslateCallbackTest(sourceMapTranslateCallback_);
|
||||
samplesRecord.TranslateUrlPositionBySourceMapTest(entry3);
|
||||
EXPECT_EQ(entry3.url, "path/to/_.js");
|
||||
|
||||
FrameInfo entry4;
|
||||
entry4.url = "entry/some_key.ets";
|
||||
sourceMapTranslateCallback_ = [](const std::string&, int, int) { return false; };
|
||||
samplesRecord.sourceMapTranslateCallbackTest(sourceMapTranslateCallback_);
|
||||
samplesRecord.TranslateUrlPositionBySourceMapTest(entry4);
|
||||
EXPECT_EQ(entry4.url, JS_PATH + "some_key.js");
|
||||
|
||||
FrameInfo entry5;
|
||||
entry5.url = "entry/some_key.other";
|
||||
sourceMapTranslateCallback_ = [](const std::string&, int, int) { return false; };
|
||||
samplesRecord.sourceMapTranslateCallbackTest(sourceMapTranslateCallback_);
|
||||
samplesRecord.TranslateUrlPositionBySourceMapTest(entry5);
|
||||
EXPECT_EQ(entry5.url, "entry/some_key.other");
|
||||
|
||||
FrameInfo entry6;
|
||||
entry6.url = "other/path.js";
|
||||
sourceMapTranslateCallback_ = [](const std::string&, int, int) { return false; };
|
||||
samplesRecord.sourceMapTranslateCallbackTest(sourceMapTranslateCallback_);
|
||||
samplesRecord.TranslateUrlPositionBySourceMapTest(entry6);
|
||||
EXPECT_EQ(entry6.url, "other/path.js");
|
||||
}
|
||||
} // namespace panda::test
|
@ -804,7 +804,7 @@
|
||||
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="HotReloadManagerTest">
|
||||
<target name="RuntimeDebuggerTest">
|
||||
<preparer>
|
||||
<option name="push" value="obj/arkcompiler/ets_runtime/ecmascript/debugger/tests/single_file/base/index.abc -> /data/test/single_file/base/" src="out"/>
|
||||
<option name="push" value="obj/arkcompiler/ets_runtime/ecmascript/debugger/tests/single_file/patch/index.abc -> /data/test/single_file/patch/" src="out"/>
|
||||
@ -1991,6 +1991,11 @@
|
||||
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="CpuProfilerTest">
|
||||
<preparer>
|
||||
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="ThreadTerminationTest">
|
||||
<preparer>
|
||||
<option name="push" value="obj/arkcompiler/ets_runtime/test/executiontest/termination_1.abc -> /data/test" src="out"/>
|
||||
|
Loading…
Reference in New Issue
Block a user