• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_STEP_INTO_TEST_H
17 #define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_STEP_INTO_TEST_H
18 
19 #include "test/utils/test_util.h"
20 
21 namespace panda::ecmascript::tooling::test {
22 class JsStepIntoTest : public TestEvents {
23 public:
JsStepIntoTest()24     JsStepIntoTest()
25     {
26         vmDeath = [this]() {
27             ASSERT_EQ(breakpointCounter_, pointerLocations_.size());
28             ASSERT_EQ(stepCompleteCounter_, stepLocations_.size());
29             return true;
30         };
31 
32         loadModule = [this](std::string_view moduleName) {
33             // line number for breakpoint array
34             size_t breakpoint[POINTER_SIZE][LINE_COLUMN] =
35                 {{84, 0}, {87, 0}, {27, 0}, {79, 0}, {42, 0}, {38, 0}, {56, 0}, {60, 0}, {96, 0}, {54, 0}};
36             // line number for stepinto array
37             size_t stepInto[STEP_SIZE][LINE_COLUMN] =
38                 {{85, 5}, {23, 0}, {73, 0}, {80, 0}, {36, 0}, {43, 0}, {50, 0}, {61, 0}, {97, 15}};
39             SetJSPtLocation(breakpoint[0], POINTER_SIZE, pointerLocations_);
40             SetJSPtLocation(stepInto[0], STEP_SIZE, stepLocations_);
41             TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE);
42             ASSERT_EQ(moduleName, pandaFile_);
43             debugger_->NotifyScriptParsed(0, moduleName.data());
44             auto condFuncRef = FunctionRef::Undefined(vm_);
45             for (auto &iter : pointerLocations_) {
46                 auto ret = debugInterface_->SetBreakpoint(iter, condFuncRef);
47                 ASSERT_TRUE(ret);
48             }
49             return true;
50         };
51 
52         breakpoint = [this](const JSPtLocation &location) {
53             ASSERT_TRUE(location.GetMethodId().IsValid());
54             ASSERT_LOCATION_EQ(location, pointerLocations_.at(breakpointCounter_));
55             ++breakpointCounter_;
56             TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location);
57             debugger_->StepInto(StepIntoParams());
58             return true;
59         };
60 
61         singleStep = [this](const JSPtLocation &location) {
62             if (debugger_->NotifySingleStep(location)) {
63                 ASSERT_TRUE(location.GetMethodId().IsValid());
64                 ASSERT_LOCATION_EQ(location, stepLocations_.at(stepCompleteCounter_));
65                 stepCompleteCounter_++;
66                 TestUtil::SuspendUntilContinue(DebugEvent::STEP_COMPLETE, location);
67                 return true;
68             }
69             return false;
70         };
71 
72         scenario = [this]() {
73             TestUtil::WaitForLoadModule();
74             TestUtil::Continue();
75             size_t index = 0;
76             while (index < POINTER_SIZE) {
77                 TestUtil::WaitForBreakpoint(pointerLocations_.at(index));
78                 TestUtil::Continue();
79                 if (index < STEP_SIZE) {
80                     TestUtil::WaitForStepComplete(stepLocations_.at(index));
81                     TestUtil::Continue();
82                 }
83                 ++index;
84             }
85             ASSERT_EXITED();
86             return true;
87         };
88     }
89 
GetEntryPoint()90     std::pair<std::string, std::string> GetEntryPoint() override
91     {
92         return {pandaFile_, entryPoint_};
93     }
94 
95 private:
96     static constexpr size_t LINE_COLUMN = 2;
97     static constexpr size_t POINTER_SIZE = 10;
98     static constexpr size_t STEP_SIZE = 9;
99 
100     std::string pandaFile_ = DEBUGGER_ABC_DIR "step.abc";
101     std::string entryPoint_ = "_GLOBAL::func_main_0";
102     size_t breakpointCounter_ = 0;
103     size_t stepCompleteCounter_ = 0;
104     std::vector<JSPtLocation> pointerLocations_;
105     std::vector<JSPtLocation> stepLocations_;
106 
SetJSPtLocation(size_t * arr,size_t number,std::vector<JSPtLocation> & locations)107     void SetJSPtLocation(size_t *arr, size_t number, std::vector<JSPtLocation> &locations)
108     {
109         for (size_t i = 0; i < number; i++) {
110             JSPtLocation location =
111                 TestUtil::GetLocation(arr[i * LINE_COLUMN], arr[i * LINE_COLUMN + 1], pandaFile_.c_str());
112             locations.push_back(location);
113         }
114     };
115 };
116 
GetJsStepIntoTest()117 std::unique_ptr<TestEvents> GetJsStepIntoTest()
118 {
119     return std::make_unique<JsStepIntoTest>();
120 }
121 }  // namespace panda::ecmascript::tooling::test
122 
123 #endif  // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_STEP_INTO_TEST_H
124