mirror of
https://gitee.com/openharmony/arkcompiler_toolchain
synced 2024-11-23 23:49:50 +00:00
add toolchain end to end test
Signed-off-by: yanpeng <yanpeng51@huawei.com> Change-Id: If277adac0c566003b9ecf7bbc1dc1ca0a34eba99 Signed-off-by: yanpeng <yanpeng51@huawei.com>
This commit is contained in:
parent
da21ec6655
commit
d96a538d6f
@ -46,6 +46,13 @@ std::ostream &operator<<(std::ostream &out, ActionRule value);
|
||||
|
||||
using MatchFunc = std::function<bool(const std::string&, const std::string&)>;
|
||||
|
||||
enum class TestCase {
|
||||
COMMON,
|
||||
SOURCE,
|
||||
WATCH,
|
||||
WATCH_OBJECT,
|
||||
};
|
||||
|
||||
/*
|
||||
* Add some common match func here
|
||||
*/
|
||||
@ -67,6 +74,7 @@ struct ActionInfo {
|
||||
MatchFunc matchFunc = [] (auto, auto) -> auto {
|
||||
return true;
|
||||
};
|
||||
TestCase event = TestCase::COMMON;
|
||||
|
||||
ActionInfo(const ActionInfo&) = default;
|
||||
ActionInfo& operator=(const ActionInfo&) = default;
|
||||
|
@ -22,10 +22,14 @@
|
||||
#include "tooling/test/testcases/js_breakpoint_async_test.h"
|
||||
#include "tooling/test/testcases/js_breakpoint_test.h"
|
||||
#include "tooling/test/testcases/js_closure_scope_test.h"
|
||||
#include "tooling/test/testcases/js_local_variable_scope_test.h"
|
||||
#include "tooling/test/testcases/js_exception_test.h"
|
||||
#include "tooling/test/testcases/js_container_test.h"
|
||||
#include "tooling/test/testcases/js_exception_test.h"
|
||||
#include "tooling/test/testcases/js_heapsampling_test.h"
|
||||
#include "tooling/test/testcases/js_local_variable_scope_test.h"
|
||||
#include "tooling/test/testcases/js_module_variable_test.h"
|
||||
#include "tooling/test/testcases/js_source_test.h"
|
||||
#include "tooling/test/testcases/js_tracing_test.h"
|
||||
#include "tooling/test/testcases/js_watch_test.h"
|
||||
|
||||
namespace panda::ecmascript::tooling::test {
|
||||
static std::string g_currentTestName = "";
|
||||
@ -41,6 +45,10 @@ static void RegisterTests()
|
||||
TestUtil::RegisterTest("JsExceptionTest", GetJsExceptionTest());
|
||||
TestUtil::RegisterTest("JsContainerTest", GetJsContainerTest());
|
||||
TestUtil::RegisterTest("JsModuleVariableTest", GetJsModuleVariableTest());
|
||||
TestUtil::RegisterTest("JsSourceTest", GetJsSourceTest());
|
||||
TestUtil::RegisterTest("JsTracingTest", GetJsTracingTest());
|
||||
TestUtil::RegisterTest("JsHeapsamplingTest", GetJsHeapsamplingTest());
|
||||
TestUtil::RegisterTest("JsWatchTest", GetJsWatchTest());
|
||||
}
|
||||
|
||||
std::vector<const char *> GetTestList()
|
||||
|
@ -121,32 +121,8 @@ void TestUtil::ForkSocketClient([[maybe_unused]] int port, const std::string &na
|
||||
} else {
|
||||
ASSERT(action.action == SocketAction::RECV);
|
||||
std::string recv = client.Decode();
|
||||
if (recv.empty()) {
|
||||
LOG_DEBUGGER(ERROR) << "Notify fail";
|
||||
NotifyFail();
|
||||
SessionManager::getInstance().DelSessionById(0);
|
||||
exit(-1);
|
||||
}
|
||||
int times = 0;
|
||||
while ((!strcmp(recv.c_str(), "try again")) && (times <= 5)) { // 5: five times
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(500000)); // 500000: 500ms
|
||||
recv = client.Decode();
|
||||
times++;
|
||||
}
|
||||
switch (action.rule) {
|
||||
case ActionRule::STRING_EQUAL: {
|
||||
success = (recv == action.message);
|
||||
break;
|
||||
}
|
||||
case ActionRule::STRING_CONTAIN: {
|
||||
success = (recv.find(action.message) != std::string::npos);
|
||||
break;
|
||||
}
|
||||
case ActionRule::CUSTOM_RULE: {
|
||||
success = action.matchFunc(recv, action.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
HandleAcceptanceMessages(action, client, recv, success);
|
||||
SendMessage(action, recv);
|
||||
LOG_DEBUGGER(INFO) << "recv: " << recv;
|
||||
LOG_DEBUGGER(INFO) << "rule: " << action.rule;
|
||||
}
|
||||
@ -163,4 +139,86 @@ void TestUtil::ForkSocketClient([[maybe_unused]] int port, const std::string &na
|
||||
}
|
||||
LOG_DEBUGGER(INFO) << "ForkSocketClient end";
|
||||
}
|
||||
|
||||
void TestUtil::HandleAcceptanceMessages(ActionInfo action, WebsocketClient &client, std::string &recv, bool &success)
|
||||
{
|
||||
if (recv.empty()) {
|
||||
LOG_DEBUGGER(ERROR) << "Notify fail";
|
||||
NotifyFail();
|
||||
SessionManager::getInstance().DelSessionById(0);
|
||||
exit(-1);
|
||||
}
|
||||
int times = 0;
|
||||
while ((!strcmp(recv.c_str(), "try again")) && (times <= 5)) { // 5: five times
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(500000)); // 500000: 500ms
|
||||
recv = client.Decode();
|
||||
times++;
|
||||
}
|
||||
switch (action.rule) {
|
||||
case ActionRule::STRING_EQUAL: {
|
||||
success = (recv == action.message);
|
||||
break;
|
||||
}
|
||||
case ActionRule::STRING_CONTAIN: {
|
||||
success = (recv.find(action.message) != std::string::npos);
|
||||
break;
|
||||
}
|
||||
case ActionRule::CUSTOM_RULE: {
|
||||
success = action.matchFunc(recv, action.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void TestUtil::SendMessage(ActionInfo action, std::string recv)
|
||||
{
|
||||
switch (action.event) {
|
||||
case TestCase::SOURCE: {
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
std::unique_ptr<PtJson> params = nullptr;
|
||||
Result ret = json->GetObject("params", ¶ms);
|
||||
std::string scriptId;
|
||||
ret = params->GetString("scriptId", &scriptId);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return;
|
||||
}
|
||||
SessionManager::getInstance().GetCurrentSession()->
|
||||
GetSourceManager().SendRequeSource(std::atoi(scriptId.c_str()));
|
||||
break;
|
||||
}
|
||||
case TestCase::WATCH: {
|
||||
if (!SessionManager::getInstance().GetCurrentSession()->GetWatchManager().GetWatchInfoSize()) {
|
||||
SessionManager::getInstance().GetCurrentSession()->GetWatchManager().AddWatchInfo("a");
|
||||
SessionManager::getInstance().GetCurrentSession()->GetWatchManager().AddWatchInfo("this");
|
||||
}
|
||||
const uint watchInfoSize = 2;
|
||||
for (uint i = 0; i < watchInfoSize; i++) {
|
||||
SessionManager::getInstance().GetCurrentSession()->GetWatchManager().SendRequestWatch(i, "0");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TestCase::WATCH_OBJECT: {
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
std::unique_ptr<PtJson> result = nullptr;
|
||||
Result ret = json->GetObject("result", &result);
|
||||
std::unique_ptr<PtJson> watchResult = nullptr;
|
||||
ret = result->GetObject("result", &watchResult);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return;
|
||||
}
|
||||
std::string objectId;
|
||||
ret = watchResult->GetString("objectId", &objectId);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return;
|
||||
}
|
||||
SessionManager::getInstance().GetCurrentSession()->GetWatchManager().GetPropertiesCommand(0, objectId);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} // namespace panda::ecmascript::tooling::test
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
}
|
||||
|
||||
static void ForkSocketClient(int port, const std::string &name);
|
||||
static void HandleAcceptanceMessages(ActionInfo action, WebsocketClient &client, std::string &recv, bool &success);
|
||||
static void SendMessage(ActionInfo action, std::string recv);
|
||||
|
||||
private:
|
||||
static void NotifyFail();
|
||||
|
@ -25,6 +25,15 @@ function count_to_ten() {
|
||||
a = 9;
|
||||
a = 10;
|
||||
}
|
||||
const person = {
|
||||
name: "rose",
|
||||
age: 19,
|
||||
greet: function() {
|
||||
this.name = "jack";
|
||||
this.age = 18;
|
||||
}
|
||||
};
|
||||
|
||||
count_to_ten();
|
||||
count_to_ten();
|
||||
count_to_ten();
|
||||
person.greet();
|
||||
|
109
tooling/test/testcases/js_heapsampling_test.h
Normal file
109
tooling/test/testcases/js_heapsampling_test.h
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_HEAPSAMPLING_TEST_H
|
||||
#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_HEAPSAMPLING_TEST_H
|
||||
|
||||
#include "tooling/test/client_utils/test_util.h"
|
||||
|
||||
namespace panda::ecmascript::tooling::test {
|
||||
class JsHeapsamplingTest : public TestActions {
|
||||
public:
|
||||
JsHeapsamplingTest()
|
||||
{
|
||||
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 sample.js
|
||||
{SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN},
|
||||
// break on start
|
||||
{SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
|
||||
{SocketAction::SEND, "heapprofiler-enable"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
{SocketAction::SEND, "sampling"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
// set breakpoint
|
||||
{SocketAction::SEND, "b " DEBUGGER_JS_DIR "sample.js 22"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
// 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},
|
||||
// hit breakpoint after resume second 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, "sampling-stop"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [this] (auto recv, auto) -> bool {
|
||||
return RecvHeapsamlingInfo(recv);
|
||||
}},
|
||||
{SocketAction::SEND, "heapprofiler-disable"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
// 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 RecvHeapsamlingInfo(std::string recv)
|
||||
{
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
int id;
|
||||
Result ret = json->GetInt("id", &id);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> result;
|
||||
ret = json->GetObject("result", &result);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> profile;
|
||||
ret = result->GetObject("profile", &profile);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> GetEntryPoint() override
|
||||
{
|
||||
return {pandaFile_, entryPoint_};
|
||||
}
|
||||
~JsHeapsamplingTest() = default;
|
||||
|
||||
private:
|
||||
std::string pandaFile_ = DEBUGGER_ABC_DIR "sample.abc";
|
||||
std::string sourceFile_ = DEBUGGER_JS_DIR "sample.js";
|
||||
std::string entryPoint_ = "_GLOBAL::func_main_0";
|
||||
};
|
||||
|
||||
std::unique_ptr<TestActions> GetJsHeapsamplingTest()
|
||||
{
|
||||
return std::make_unique<JsHeapsamplingTest>();
|
||||
}
|
||||
} // namespace panda::ecmascript::tooling::test
|
||||
|
||||
#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_HEAPSAMPLING_TEST_H
|
87
tooling/test/testcases/js_source_test.h
Normal file
87
tooling/test/testcases/js_source_test.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_SOURCE_TEST_H
|
||||
#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_SOURCE_TEST_H
|
||||
|
||||
#include "tooling/test/client_utils/test_util.h"
|
||||
|
||||
namespace panda::ecmascript::tooling::test {
|
||||
class JsSourceTest : public TestActions {
|
||||
public:
|
||||
JsSourceTest()
|
||||
{
|
||||
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 sample.js
|
||||
{SocketAction::RECV, "Debugger.scriptParsed", ActionRule::CUSTOM_RULE, [] (auto, auto) -> bool {
|
||||
return true;
|
||||
}, TestCase::SOURCE},
|
||||
// break on start
|
||||
{SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [] (auto recv, auto) -> bool {
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
Result ret;
|
||||
int id;
|
||||
ret = json->GetInt("id", &id);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> result = nullptr;
|
||||
ret = json->GetObject("result", &result);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string scriptSource;
|
||||
ret = result->GetString("scriptSource", &scriptSource);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}},
|
||||
// reply success and run
|
||||
{SocketAction::SEND, "success"},
|
||||
{SocketAction::SEND, "resume"},
|
||||
{SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
};
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> GetEntryPoint() override
|
||||
{
|
||||
return {pandaFile_, entryPoint_};
|
||||
}
|
||||
~JsSourceTest() = default;
|
||||
|
||||
private:
|
||||
std::string pandaFile_ = DEBUGGER_ABC_DIR "sample.abc";
|
||||
std::string sourceFile_ = DEBUGGER_JS_DIR "sample.js";
|
||||
std::string entryPoint_ = "_GLOBAL::func_main_0";
|
||||
};
|
||||
|
||||
std::unique_ptr<TestActions> GetJsSourceTest()
|
||||
{
|
||||
return std::make_unique<JsSourceTest>();
|
||||
}
|
||||
} // namespace panda::ecmascript::tooling::test
|
||||
|
||||
#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_SOURCE_TEST_H
|
92
tooling/test/testcases/js_tracing_test.h
Normal file
92
tooling/test/testcases/js_tracing_test.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_TRACING_TEST_H
|
||||
#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_TRACING_TEST_H
|
||||
|
||||
#include "tooling/test/client_utils/test_util.h"
|
||||
|
||||
namespace panda::ecmascript::tooling::test {
|
||||
class JsTracingTest : public TestActions {
|
||||
public:
|
||||
JsTracingTest()
|
||||
{
|
||||
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 sample.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},
|
||||
{SocketAction::SEND, "cpuprofile-stop"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [] (auto recv, auto) -> bool {
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
Result ret;
|
||||
int id;
|
||||
ret = json->GetInt("id", &id);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> result;
|
||||
ret = json->GetObject("result", &result);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> profile;
|
||||
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 and run
|
||||
{SocketAction::SEND, "success"},
|
||||
{SocketAction::SEND, "resume"},
|
||||
{SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
};
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> GetEntryPoint() override
|
||||
{
|
||||
return {pandaFile_, entryPoint_};
|
||||
}
|
||||
~JsTracingTest() = default;
|
||||
|
||||
private:
|
||||
std::string pandaFile_ = DEBUGGER_ABC_DIR "sample.abc";
|
||||
std::string sourceFile_ = DEBUGGER_JS_DIR "sample.js";
|
||||
std::string entryPoint_ = "_GLOBAL::func_main_0";
|
||||
};
|
||||
|
||||
std::unique_ptr<TestActions> GetJsTracingTest()
|
||||
{
|
||||
return std::make_unique<JsTracingTest>();
|
||||
}
|
||||
} // namespace panda::ecmascript::tooling::test
|
||||
|
||||
#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_TRACING_TEST_H
|
236
tooling/test/testcases/js_watch_test.h
Normal file
236
tooling/test/testcases/js_watch_test.h
Normal file
@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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_WATCH_TEST_H
|
||||
#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_WATCH_TEST_H
|
||||
|
||||
#include "tooling/test/client_utils/test_util.h"
|
||||
|
||||
namespace panda::ecmascript::tooling::test {
|
||||
class JsWatchTest : public TestActions {
|
||||
public:
|
||||
JsWatchTest()
|
||||
{
|
||||
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 sample.js
|
||||
{SocketAction::RECV, "Debugger.scriptParsed", ActionRule::STRING_CONTAIN},
|
||||
// break on start
|
||||
{SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN},
|
||||
// set breakpoint
|
||||
{SocketAction::SEND, "b " DEBUGGER_JS_DIR "sample.js 22"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
// 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},
|
||||
// hit breakpoint after resume second time
|
||||
{SocketAction::SEND, "resume"},
|
||||
{SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
{SocketAction::RECV, "Debugger.paused", ActionRule::CUSTOM_RULE, [] (auto, auto) -> bool { return true; },
|
||||
TestCase::WATCH},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [this] (auto recv, auto) -> bool {
|
||||
return RecvWatchDescription(recv);
|
||||
}},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [this] (auto recv, auto) -> bool {
|
||||
return RecvWatchType(recv);
|
||||
}},
|
||||
{SocketAction::SEND, "b " DEBUGGER_JS_DIR "sample.js 33"},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess},
|
||||
// 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::CUSTOM_RULE, [] (auto, auto) -> bool {
|
||||
return true;
|
||||
}, TestCase::WATCH},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [this] (auto recv, auto) -> bool {
|
||||
return RecvWatchType(recv);
|
||||
}},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [this] (auto recv, auto) -> bool {
|
||||
return RecvWatchObject(recv);
|
||||
}, TestCase::WATCH_OBJECT},
|
||||
{SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [this] (auto recv, auto) -> bool {
|
||||
return RecvWatchDescriptionByJack(recv);
|
||||
}},
|
||||
// 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 RecvWatchDescription(std::string recv)
|
||||
{
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
Result ret;
|
||||
int id;
|
||||
ret = json->GetInt("id", &id);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> result = nullptr;
|
||||
ret = json->GetObject("result", &result);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> watchResult = nullptr;
|
||||
ret = result->GetObject("result", &watchResult);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string numResult;
|
||||
ret = watchResult->GetString("description", &numResult);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (numResult != "5") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecvWatchType(std::string recv)
|
||||
{
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
Result ret;
|
||||
int id;
|
||||
ret = json->GetInt("id", &id);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> result = nullptr;
|
||||
ret = json->GetObject("result", &result);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> watchResult = nullptr;
|
||||
ret = result->GetObject("result", &watchResult);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string type;
|
||||
ret = watchResult->GetString("type", &type);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type != "undefined") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecvWatchObject(std::string recv)
|
||||
{
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
Result ret;
|
||||
int id;
|
||||
ret = json->GetInt("id", &id);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> result = nullptr;
|
||||
ret = json->GetObject("result", &result);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> watchResult = nullptr;
|
||||
ret = result->GetObject("result", &watchResult);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string type;
|
||||
ret = watchResult->GetString("type", &type);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type != "object") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RecvWatchDescriptionByJack(std::string recv)
|
||||
{
|
||||
std::unique_ptr<PtJson> json = PtJson::Parse(recv);
|
||||
Result ret;
|
||||
std::unique_ptr<PtJson> result = nullptr;
|
||||
ret = json->GetObject("result", &result);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> watchResult = nullptr;
|
||||
ret = result->GetArray("result", &watchResult);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<PtJson> value = nullptr;
|
||||
ret = watchResult->Get(0)->GetObject("value", &value);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string description;
|
||||
ret = value->GetString("description", &description);
|
||||
if (ret != Result::SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
if (description != "jack") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> GetEntryPoint() override
|
||||
{
|
||||
return {pandaFile_, entryPoint_};
|
||||
}
|
||||
~JsWatchTest() = default;
|
||||
|
||||
private:
|
||||
std::string pandaFile_ = DEBUGGER_ABC_DIR "sample.abc";
|
||||
std::string sourceFile_ = DEBUGGER_JS_DIR "sample.js";
|
||||
std::string entryPoint_ = "_GLOBAL::func_main_0";
|
||||
};
|
||||
|
||||
std::unique_ptr<TestActions> GetJsWatchTest()
|
||||
{
|
||||
return std::make_unique<JsWatchTest>();
|
||||
}
|
||||
} // namespace panda::ecmascript::tooling::test
|
||||
|
||||
#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_WATCH_TEST_H
|
Loading…
Reference in New Issue
Block a user