• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_TESTCASES_JS_STEPINTO_RECURSION_TEST_H
17 #define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_STEPINTO_RECURSION_TEST_H
18 
19 #include "tooling/test/client_utils/test_util.h"
20 
21 namespace panda::ecmascript::tooling::test {
22 class JsStepintoRecursionTest : public TestActions {
23 public:
JsStepintoRecursionTest()24     JsStepintoRecursionTest()
25     {
26         testAction = {
27             {SocketAction::SEND, "enable"},
28             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
29             {SocketAction::SEND, "runtime-enable"},
30             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
31             {SocketAction::SEND, "run"},
32             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
33             // load common_func.js
34             {SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN},
35             // break on start
36             {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
37             // set first breakpoint
38             {SocketAction::SEND, "b " DEBUGGER_JS_DIR "common_func.js 67"},
39             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE,
40                 [](auto recv, auto, auto) -> bool {
41                     std::unique_ptr<PtJson> json = PtJson::Parse(recv);
42                     DebuggerClient debuggerClient(0);
43                     debuggerClient.RecvReply(std::move(json));
44                     return true;
45                 }},
46 
47             // hit breakpoint after resume first time
48             {SocketAction::SEND, "resume"},
49             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
50             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
51             {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
52 
53             {SocketAction::SEND, "si"},
54             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
55             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
56             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
57                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 57); }},
58             {SocketAction::SEND, "si"},
59             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
60             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
61             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
62                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 60); }},
63             {SocketAction::SEND, "si"},
64             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
65             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
66             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
67                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 57); }},
68             {SocketAction::SEND, "si"},
69             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
70             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
71             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
72                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 60); }},
73             {SocketAction::SEND, "si"},
74             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
75             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
76             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
77                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 57); }},
78             {SocketAction::SEND, "si"},
79             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
80             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
81             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
82                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 60); }},
83             {SocketAction::SEND, "si"},
84             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
85             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
86             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
87                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 57); }},
88             {SocketAction::SEND, "si"},
89             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
90             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
91             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
92                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 58); }},
93             {SocketAction::SEND, "si"},
94             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
95             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
96             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
97                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 61); }},
98             {SocketAction::SEND, "si"},
99             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
100             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
101             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
102                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 60); }},
103             {SocketAction::SEND, "si"},
104             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
105             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
106             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
107                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 61); }},
108             {SocketAction::SEND, "si"},
109             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
110             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
111             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE,
112                 [this](auto recv, auto, auto) -> bool { return RecvStepintoInfo(recv, "factorial", 60); }},
113 
114             {SocketAction::SEND, "delete 1"},
115             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
116             {SocketAction::SEND, "resume"},
117             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
118             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
119             {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
120 
121             // reply success and run
122             {SocketAction::SEND, "success"},
123             {SocketAction::SEND, "resume"},
124             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
125             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
126         };
127     }
128 
RecvStepintoInfo(std::string recv,std::string funcName,int lineNumber)129     bool RecvStepintoInfo(std::string recv, std::string funcName, int lineNumber)
130     {
131         std::unique_ptr<PtJson> json = PtJson::Parse(recv);
132         Result ret;
133         std::string method = "";
134         ret = json->GetString("method", &method);
135         if (ret != Result::SUCCESS || method != "Debugger.paused") {
136             return false;
137         }
138 
139         std::unique_ptr<PtJson> params = nullptr;
140         ret = json->GetObject("params", &params);
141         if (ret != Result::SUCCESS) {
142             return false;
143         }
144 
145         std::unique_ptr<PtJson> callFrames = nullptr;
146         ret = params->GetArray("callFrames", &callFrames);
147         if (ret != Result::SUCCESS) {
148             return false;
149         }
150 
151         std::string functionName = "";
152         ret = callFrames->Get(0)->GetString("functionName", &functionName);
153         if (ret != Result::SUCCESS || functionName != funcName) {
154             return false;
155         }
156 
157         std::unique_ptr<PtJson> location = nullptr;
158         ret = callFrames->Get(0)->GetObject("location", &location);
159         if (ret != Result::SUCCESS) {
160             return false;
161         }
162 
163         int lineNum = 0;
164         ret = location->GetInt("lineNumber", &lineNum);
165         if (ret != Result::SUCCESS || lineNum != lineNumber) {
166             return false;
167         }
168 
169         DebuggerClient debuggerClient(0);
170         debuggerClient.PausedReply(std::move(json));
171         return true;
172     }
173 
GetEntryPoint()174     std::pair<std::string, std::string> GetEntryPoint() override
175     {
176         return {pandaFile_, entryPoint_};
177     }
178     ~JsStepintoRecursionTest() = default;
179 
180 private:
181     std::string pandaFile_ = DEBUGGER_ABC_DIR "common_func.abc";
182     std::string sourceFile_ = DEBUGGER_JS_DIR "common_func.js";
183     std::string entryPoint_ = "_GLOBAL::func_main_0";
184 };
185 
GetJsStepintoRecursionTest()186 std::unique_ptr<TestActions> GetJsStepintoRecursionTest()
187 {
188     return std::make_unique<JsStepintoRecursionTest>();
189 }
190 } // namespace panda::ecmascript::tooling::test
191 
192 #endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_STEPINTO_RECURSION_TEST_H
193