• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_ACCELERATE_LAUNCH_TEST_H
17 #define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_ACCELERATE_LAUNCH_TEST_H
18 
19 #include "tooling/test/client_utils/test_util.h"
20 
21 namespace panda::ecmascript::tooling::test {
22 class JsAccelerateLaunchTest : public TestActions {
23 public:
JsAccelerateLaunchTest()24     JsAccelerateLaunchTest()
25     {
26         testAction = {
27             // Enable Accelerate Launch Mode
28             {SocketAction::SEND, "enable-acc"},
29             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
30             {SocketAction::SEND, "runtime-enable"},
31             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
32             // Debugger.saveAllPossibleBreakpoints
33             {SocketAction::SEND, "b-new " DEBUGGER_JS_DIR "sample.js 22"},
34             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
35             {SocketAction::SEND, "run"},
36             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
37             // load sample.js
38             {SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN},
39             {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
40             {SocketAction::SEND, "resume"},
41             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
42             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
43             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this] (auto recv, auto, auto) -> bool {
44                 std::unique_ptr<PtJson> json = PtJson::Parse(recv);
45                 Result ret;
46                 std::string method;
47                 ret = json->GetString("method", &method);
48                 if (ret != Result::SUCCESS || method != "Debugger.paused") {
49                     return false;
50                 }
51 
52                 std::unique_ptr<PtJson> params = nullptr;
53                 ret = json->GetObject("params", &params);
54                 if (ret != Result::SUCCESS) {
55                     return false;
56                 }
57 
58                 std::unique_ptr<PtJson> hitBreakpoints = nullptr;
59                 ret = params->GetArray("hitBreakpoints", &hitBreakpoints);
60                 if (ret != Result::SUCCESS) {
61                     return false;
62                 }
63 
64                 std::string breakpoint;
65                 breakpoint = hitBreakpoints->Get(0)->GetString();
66                 if (ret != Result::SUCCESS || breakpoint.find(sourceFile_) == std::string::npos ||
67                     breakpoint.find("21") == std::string::npos) {
68                     return false;
69                 }
70                 return true;
71             }},
72             {SocketAction::SEND, "b " DEBUGGER_JS_DIR "sample.js 23"},
73             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
74             {SocketAction::SEND, "resume"},
75             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
76             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
77             {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this] (auto recv, auto, auto) -> bool {
78                 std::unique_ptr<PtJson> json = PtJson::Parse(recv);
79                 Result ret;
80                 std::string method;
81                 ret = json->GetString("method", &method);
82                 if (ret != Result::SUCCESS || method != "Debugger.paused") {
83                     return false;
84                 }
85 
86                 std::unique_ptr<PtJson> params = nullptr;
87                 ret = json->GetObject("params", &params);
88                 if (ret != Result::SUCCESS) {
89                     return false;
90                 }
91 
92                 std::unique_ptr<PtJson> hitBreakpoints = nullptr;
93                 ret = params->GetArray("hitBreakpoints", &hitBreakpoints);
94                 if (ret != Result::SUCCESS) {
95                     return false;
96                 }
97 
98                 std::string breakpoint;
99                 breakpoint = hitBreakpoints->Get(0)->GetString();
100                 if (ret != Result::SUCCESS || breakpoint.find(sourceFile_) == std::string::npos ||
101                     breakpoint.find("22") == std::string::npos) {
102                     return false;
103                 }
104                 return true;
105             }},
106             {SocketAction::SEND, "success"},
107             {SocketAction::SEND, "resume"},
108             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
109             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
110         };
111     }
112 
GetEntryPoint()113     std::pair<std::string, std::string> GetEntryPoint() override
114     {
115         return {pandaFile_, entryPoint_};
116     }
117     ~JsAccelerateLaunchTest() = default;
118 
119 private:
120     std::string pandaFile_ = DEBUGGER_ABC_DIR "sample.abc";
121     std::string sourceFile_ = DEBUGGER_JS_DIR "sample.js";
122     std::string entryPoint_ = "_GLOBAL::func_main_0";
123 };
124 
GetJsAccelerateLaunchTest()125 std::unique_ptr<TestActions> GetJsAccelerateLaunchTest()
126 {
127     return std::make_unique<JsAccelerateLaunchTest>();
128 }
129 }  // namespace panda::ecmascript::tooling::test
130 
131 #endif  // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_ACCELERATE_LAUNCH_TEST_H
132