/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_STEPOVER_LOOP_TEST_H #define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_STEPOVER_LOOP_TEST_H #include "tooling/test/client_utils/test_util.h" namespace panda::ecmascript::tooling::test { class JsStepoverLoopTest : public TestActions { public: JsStepoverLoopTest() { testAction = { {SocketAction::SEND, "enable"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::SEND, "runtime-enable"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::SEND, "run"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, // load common_func.js {SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN}, // break on start {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, // set first breakpoint {SocketAction::SEND, "b " DEBUGGER_JS_DIR "common_func.js 27"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [](auto recv, auto, auto) -> bool { std::unique_ptr json = PtJson::Parse(recv); DebuggerClient debuggerClient(0); debuggerClient.RecvReply(std::move(json)); return true; }}, // hit breakpoint after resume first time {SocketAction::SEND, "resume"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "for_loop", 27); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "for_loop", 28); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "for_loop", 26); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "for_loop", 27); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "for_loop", 28); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "for_loop", 26); }}, {SocketAction::SEND, "delete 1"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::SEND, "b " DEBUGGER_JS_DIR "common_func.js 35"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [](auto recv, auto, auto) -> bool { std::unique_ptr json = PtJson::Parse(recv); DebuggerClient debuggerClient(0); debuggerClient.RecvReply(std::move(json)); return true; }}, {SocketAction::SEND, "resume"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 35); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 36); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 37); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 38); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 35); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 36); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 37); }}, {SocketAction::SEND, "sov"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvStepoverInfo(recv, "while_loop", 38); }}, {SocketAction::SEND, "delete 1"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::SEND, "resume"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, // reply success and run {SocketAction::SEND, "success"}, {SocketAction::SEND, "resume"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, }; } bool RecvStepoverInfo(std::string recv, std::string funcName, int lineNumber) { std::unique_ptr json = PtJson::Parse(recv); Result ret; std::string method = ""; ret = json->GetString("method", &method); if (ret != Result::SUCCESS || method != "Debugger.paused") { return false; } std::unique_ptr params = nullptr; ret = json->GetObject("params", ¶ms); if (ret != Result::SUCCESS) { return false; } std::unique_ptr callFrames = nullptr; ret = params->GetArray("callFrames", &callFrames); if (ret != Result::SUCCESS) { return false; } std::string functionName = ""; ret = callFrames->Get(0)->GetString("functionName", &functionName); if (ret != Result::SUCCESS || functionName != funcName) { return false; } std::unique_ptr location = nullptr; ret = callFrames->Get(0)->GetObject("location", &location); if (ret != Result::SUCCESS) { return false; } int lineNum = 0; ret = location->GetInt("lineNumber", &lineNum); if (ret != Result::SUCCESS || lineNum != lineNumber) { return false; } DebuggerClient debuggerClient(0); debuggerClient.PausedReply(std::move(json)); return true; } std::pair GetEntryPoint() override { return {pandaFile_, entryPoint_}; } ~JsStepoverLoopTest() = default; private: std::string pandaFile_ = DEBUGGER_ABC_DIR "common_func.abc"; std::string sourceFile_ = DEBUGGER_JS_DIR "common_func.js"; std::string entryPoint_ = "_GLOBAL::func_main_0"; }; std::unique_ptr GetJsStepoverLoopTest() { return std::make_unique(); } } // namespace panda::ecmascript::tooling::test #endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_STEPOVER_LOOP_TEST_H