• 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_CPUPROFILE_ASYNC_TEST_H
17 #define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_ASYNC_TEST_H
18 
19 #include "tooling/test/client_utils/test_util.h"
20 
21 namespace panda::ecmascript::tooling::test {
22 class JsCpuprofileAsyncTest : public TestActions {
23 public:
JsCpuprofileAsyncTest()24     JsCpuprofileAsyncTest()
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 async_func.js
34             {SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN},
35             // break on start
36             {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
37             {SocketAction::SEND, "cpuprofile-enable"},
38             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
39             {SocketAction::SEND, "cpuprofile"},
40             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
41 
42             {SocketAction::SEND, "b " DEBUGGER_JS_DIR "async_func.js 18"},
43             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
44 
45             {SocketAction::SEND, "resume"},
46             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
47             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
48             {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
49 
50             {SocketAction::SEND, "resume"},
51             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
52             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
53             {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
54 
55             {SocketAction::SEND, "cpuprofile-stop"},
56             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE,
57                 [](auto recv, auto, auto) -> bool {
58                     std::unique_ptr<PtJson> json = PtJson::Parse(recv);
59                     Result ret;
60                     int id = 0;
61                     ret = json->GetInt("id", &id);
62                     if (ret != Result::SUCCESS) {
63                         return false;
64                     }
65 
66                     std::unique_ptr<PtJson> result = nullptr;
67                     ret = json->GetObject("result", &result);
68                     if (ret != Result::SUCCESS) {
69                         return false;
70                     }
71 
72                     std::unique_ptr<PtJson> profile = nullptr;
73                     ret = result->GetObject("profile", &profile);
74                     if (ret != Result::SUCCESS) {
75                         return false;
76                     }
77 
78                     return true;
79                 }},
80             {SocketAction::SEND, "cpuprofile-disable"},
81             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
82 
83             // reply success and run
84             {SocketAction::SEND, "success"},
85             {SocketAction::SEND, "resume"},
86             {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
87             {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
88         };
89     }
90 
GetEntryPoint()91     std::pair<std::string, std::string> GetEntryPoint() override
92     {
93         return {pandaFile_, entryPoint_};
94     }
95     ~JsCpuprofileAsyncTest() = default;
96 
97 private:
98     std::string pandaFile_ = DEBUGGER_ABC_DIR "async_func.abc";
99     std::string sourceFile_ = DEBUGGER_JS_DIR "async_func.js";
100     std::string entryPoint_ = "_GLOBAL::func_main_0";
101 };
102 
GetJsCpuprofileAsyncTest()103 std::unique_ptr<TestActions> GetJsCpuprofileAsyncTest()
104 {
105     return std::make_unique<JsCpuprofileAsyncTest>();
106 }
107 } // namespace panda::ecmascript::tooling::test
108 
109 #endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_ASYNC_TEST_H
110