• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "agent/debugger_impl.h"
17 #include "backend/js_pt_hooks.h"
18 #include "base/pt_types.h"
19 #include "base/pt_events.h"
20 #include "dispatcher.h"
21 
22 #include "ecmascript/debugger/js_debugger.h"
23 #include "ecmascript/js_array.h"
24 #include "ecmascript/js_tagged_value-inl.h"
25 #include "ecmascript/object_factory.h"
26 #include "ecmascript/tests/test_helper.h"
27 
28 using namespace panda::ecmascript;
29 using namespace panda::ecmascript::tooling;
30 
31 namespace panda::test {
32 class JSPtHooksTest : public testing::Test {
33 public:
34     using EntityId = panda_file::File::EntityId;
SetUpTestCase()35     static void SetUpTestCase()
36     {
37         GTEST_LOG_(INFO) << "SetUpTestCase";
38     }
39 
TearDownTestCase()40     static void TearDownTestCase()
41     {
42         GTEST_LOG_(INFO) << "TearDownCase";
43     }
44 
SetUp()45     void SetUp() override
46     {
47         TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope);
48     }
49 
TearDown()50     void TearDown() override
51     {
52         TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope);
53     }
54 
55 protected:
56     EcmaVM *ecmaVm {nullptr};
57     EcmaHandleScope *scope {nullptr};
58     JSThread *thread {nullptr};
59 };
60 
HWTEST_F_L0(JSPtHooksTest,BreakpointTest)61 HWTEST_F_L0(JSPtHooksTest, BreakpointTest)
62 {
63     auto debugger = std::make_unique<DebuggerImpl>(ecmaVm, nullptr, nullptr);
64     std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debugger.get());
65     EntityId methodId(0);
66     uint32_t bytecodeOffset = 0;
67     JSPtLocation ptLocation1(nullptr, methodId, bytecodeOffset);
68     jspthooks->Breakpoint(ptLocation1);
69     ASSERT_NE(jspthooks, nullptr);
70 }
71 
HWTEST_F_L0(JSPtHooksTest,LoadModuleTest)72 HWTEST_F_L0(JSPtHooksTest, LoadModuleTest)
73 {
74     auto debugger = std::make_unique<DebuggerImpl>(ecmaVm, nullptr, nullptr);
75     std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debugger.get());
76     jspthooks->LoadModule("pandafile/test.abc", "func_main_0");
77     ASSERT_NE(jspthooks, nullptr);
78 }
79 
HWTEST_F_L0(JSPtHooksTest,ExceptionTest)80 HWTEST_F_L0(JSPtHooksTest, ExceptionTest)
81 {
82     auto debugger = std::make_unique<DebuggerImpl>(ecmaVm, nullptr, nullptr);
83     std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debugger.get());
84     EntityId methodId(0);
85     uint32_t bytecodeOffset = 0;
86     JSPtLocation ptLocation2(nullptr, methodId, bytecodeOffset);
87     jspthooks->Exception(ptLocation2);
88     ASSERT_NE(jspthooks, nullptr);
89 }
90 
HWTEST_F_L0(JSPtHooksTest,SingleStepTest)91 HWTEST_F_L0(JSPtHooksTest, SingleStepTest)
92 {
93     auto debugger = std::make_unique<DebuggerImpl>(ecmaVm, nullptr, nullptr);
94     std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debugger.get());
95     EntityId methodId(0);
96     uint32_t bytecodeOffset = 0;
97     JSPtLocation ptLocation4(nullptr, methodId, bytecodeOffset);
98     ASSERT_NE(jspthooks, nullptr);
99 }
100 
HWTEST_F_L0(JSPtHooksTest,VmStartTest)101 HWTEST_F_L0(JSPtHooksTest, VmStartTest)
102 {
103     auto debugger = std::make_unique<DebuggerImpl>(ecmaVm, nullptr, nullptr);
104     std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debugger.get());
105     jspthooks->VmStart();
106     ASSERT_NE(jspthooks, nullptr);
107 }
108 
HWTEST_F_L0(JSPtHooksTest,VmDeathTest)109 HWTEST_F_L0(JSPtHooksTest, VmDeathTest)
110 {
111     auto debugger = std::make_unique<DebuggerImpl>(ecmaVm, nullptr, nullptr);
112     std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debugger.get());
113     jspthooks->VmDeath();
114     ASSERT_NE(jspthooks, nullptr);
115 }
116 }