From 0dffe1b3162cbf86724113f035af95b38b4bea0d Mon Sep 17 00:00:00 2001 From: bigtea Date: Mon, 2 Sep 2024 10:31:33 +0800 Subject: [PATCH] Enable cpuprofile and heapsampling testcases Issue: IAO0ZS Signed-off-by: bigtea --- tooling/test/client_utils/test_list.cpp | 8 ++ ...loop_test.h => js_cpuprofile_async_test.h} | 83 +++++++++---------- 2 files changed, 46 insertions(+), 45 deletions(-) rename tooling/test/testcases/{js_cpuprofile_loop_test.h => js_cpuprofile_async_test.h} (56%) diff --git a/tooling/test/client_utils/test_list.cpp b/tooling/test/client_utils/test_list.cpp index cdd96ac0..ab1fc442 100644 --- a/tooling/test/client_utils/test_list.cpp +++ b/tooling/test/client_utils/test_list.cpp @@ -70,6 +70,10 @@ #include "tooling/test/testcases/js_heapusage_loop_test.h" #include "tooling/test/testcases/js_heapusage_recursion_test.h" #include "tooling/test/testcases/js_smart_stepInto_test.h" +#include "tooling/test/testcases/js_cpuprofile_test.h" +#include "tooling/test/testcases/js_cpuprofile_async_test.h" +#include "tooling/test/testcases/js_heapsampling_loop_test.h" +#include "tooling/test/testcases/js_heapsampling_test.h" namespace panda::ecmascript::tooling::test { static std::string g_currentTestName = ""; @@ -129,6 +133,10 @@ static void RegisterTests() TestUtil::RegisterTest("JsHeapusageLoopTest", GetJsHeapusageLoopTest()); TestUtil::RegisterTest("JsHeapusageRecursionTest", GetJsHeapusageRecursionTest()); TestUtil::RegisterTest("JsSmartStepoutTest", GetJsSmartStepoutTest()); + TestUtil::RegisterTest("JsCpuprofileTest", GetJsCpuprofileTest()); + TestUtil::RegisterTest("JsCpuprofileAsyncTest", GetJsCpuprofileAsyncTest()); + TestUtil::RegisterTest("JsHeapsamplingTest", GetJsHeapsamplingTest()); + TestUtil::RegisterTest("JsHeapSamplingLoopTest", GetJsHeapSamplingLoopTest()); } std::vector GetTestList() diff --git a/tooling/test/testcases/js_cpuprofile_loop_test.h b/tooling/test/testcases/js_cpuprofile_async_test.h similarity index 56% rename from tooling/test/testcases/js_cpuprofile_loop_test.h rename to tooling/test/testcases/js_cpuprofile_async_test.h index a33541ec..18460cc1 100644 --- a/tooling/test/testcases/js_cpuprofile_loop_test.h +++ b/tooling/test/testcases/js_cpuprofile_async_test.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_LOOP_TEST_H -#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_LOOP_TEST_H +#ifndef ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_ASYNC_TEST_H +#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_ASYNC_TEST_H #include "tooling/test/client_utils/test_util.h" namespace panda::ecmascript::tooling::test { -class JsCpuprofileLoopTest : public TestActions { +class JsCpuprofileAsyncTest : public TestActions { public: - JsCpuprofileLoopTest() + JsCpuprofileAsyncTest() { testAction = { {SocketAction::SEND, "enable"}, @@ -30,75 +30,68 @@ public: {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::SEND, "run"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - // load common_func.js + // load async_func.js {SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN}, // break on start {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, {SocketAction::SEND, "cpuprofile-enable"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - {SocketAction::SEND, "cpuprofile"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - // resume and stop cpuprofile + {SocketAction::SEND, "resume"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + {SocketAction::SEND, "cpuprofile-stop"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, - [this](auto recv, auto, auto) -> bool { return RecvCpuprofileInfo(recv); }}, - // cpuprofile second time and disable - {SocketAction::SEND, "cpuprofile"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - {SocketAction::SEND, "cpuprofile-stop"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, - [this](auto recv, auto, auto) -> bool { return RecvCpuprofileInfo(recv); }}, + [](auto recv, auto, auto) -> bool { + std::unique_ptr json = PtJson::Parse(recv); + Result ret; + int id = 0; + ret = json->GetInt("id", &id); + if (ret != Result::SUCCESS) { + return false; + } + + std::unique_ptr result = nullptr; + ret = json->GetObject("result", &result); + if (ret != Result::SUCCESS) { + return false; + } + + std::unique_ptr profile = nullptr; + ret = result->GetObject("profile", &profile); + if (ret != Result::SUCCESS) { + return false; + } + + return true; + }}, {SocketAction::SEND, "cpuprofile-disable"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, + // reply success {SocketAction::SEND, "success"}, }; } - bool RecvCpuprofileInfo(std::string recv) - { - std::unique_ptr json = PtJson::Parse(recv); - Result ret; - int id = 0; - ret = json->GetInt("id", &id); - if (ret != Result::SUCCESS) { - return false; - } - - std::unique_ptr result = nullptr; - ret = json->GetObject("result", &result); - if (ret != Result::SUCCESS) { - return false; - } - - std::unique_ptr profile = nullptr; - ret = result->GetObject("profile", &profile); - if (ret != Result::SUCCESS) { - return false; - } - return true; - } - std::pair GetEntryPoint() override { return {pandaFile_, entryPoint_}; } - ~JsCpuprofileLoopTest() = default; + ~JsCpuprofileAsyncTest() = default; private: - std::string pandaFile_ = DEBUGGER_ABC_DIR "common_func.abc"; - std::string sourceFile_ = DEBUGGER_JS_DIR "common_func.js"; + std::string pandaFile_ = DEBUGGER_ABC_DIR "async_func.abc"; + std::string sourceFile_ = DEBUGGER_JS_DIR "async_func.js"; std::string entryPoint_ = "_GLOBAL::func_main_0"; }; -std::unique_ptr GetJsCpuprofileLoopTest() +std::unique_ptr GetJsCpuprofileAsyncTest() { - return std::make_unique(); + return std::make_unique(); } -} // namespace panda::ecmascript::tooling::test +} // namespace panda::ecmascript::tooling::test -#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_LOOP_TEST_H +#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_ASYNC_TEST_H -- Gitee