mirror of
https://gitee.com/openharmony/arkcompiler_toolchain
synced 2024-11-23 07:30:33 +00:00
Add connect inspector testcase
1.Add test cases for connect inspector. 2.In the websocket test case, modify the use of different sock names to prevent resource preemption. Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAI0GV Signed-off-by: daiweihao <daiweihao1@huawei.com> Change-Id: Ia9842cde33fbfd18d2a782def05b9a0d7fb3dda9
This commit is contained in:
parent
4194b8a047
commit
a08caa2854
3
BUILD.gn
3
BUILD.gn
@ -215,6 +215,7 @@ config("ark_toolchain_public_config") {
|
||||
# ecmascript unit testcase config
|
||||
config("toolchain_test_config") {
|
||||
visibility = [
|
||||
"./inspector/test/*",
|
||||
"./test/fuzztest/*",
|
||||
"./tooling/test/*",
|
||||
"./websocket/test/*",
|
||||
@ -243,6 +244,7 @@ group("ark_toolchain_unittest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
"./inspector/test:unittest",
|
||||
"./tooling/test:unittest",
|
||||
"./websocket/test:unittest",
|
||||
]
|
||||
@ -257,6 +259,7 @@ group("ark_toolchain_host_unittest") {
|
||||
|
||||
# js unittest
|
||||
deps += [
|
||||
"./inspector/test:host_unittest",
|
||||
"./tooling/test:host_unittest",
|
||||
"./websocket/test:host_unittest",
|
||||
]
|
||||
|
69
inspector/test/BUILD.gn
Normal file
69
inspector/test/BUILD.gn
Normal file
@ -0,0 +1,69 @@
|
||||
# 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.
|
||||
|
||||
import("//arkcompiler/toolchain/test/test_helper.gni")
|
||||
import("//arkcompiler/toolchain/toolchain.gni")
|
||||
|
||||
module_output_path = "arkcompiler/toolchain"
|
||||
|
||||
host_unittest_action("InspectorConnectTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
include_dirs = [ "$toolchain_root/inspector" ]
|
||||
|
||||
sources = [
|
||||
# test file
|
||||
"connect_server_test.cpp",
|
||||
]
|
||||
|
||||
configs = [ "$toolchain_root:toolchain_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$toolchain_root/inspector:connectserver_debugger",
|
||||
"$toolchain_root/websocket:websocket_client",
|
||||
"$toolchain_root/websocket:websocket_server",
|
||||
]
|
||||
|
||||
# hiviewdfx libraries
|
||||
external_deps = hiviewdfx_ext_deps
|
||||
if (is_arkui_x && target_os == "ios") {
|
||||
external_deps += [ "openssl:libcrypto_static" ]
|
||||
} else {
|
||||
external_deps += [ "openssl:libcrypto_shared" ]
|
||||
}
|
||||
|
||||
external_deps += [ "bounds_checking_function:libsec_shared" ]
|
||||
deps += hiviewdfx_deps
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
# deps file
|
||||
deps = [ ":InspectorConnectTest" ]
|
||||
|
||||
if (is_mac) {
|
||||
deps -= [ ":InspectorConnectTest" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("host_unittest") {
|
||||
testonly = true
|
||||
|
||||
# deps file
|
||||
deps = [ ":InspectorConnectTestAction" ]
|
||||
|
||||
if (is_mac) {
|
||||
deps -= [ ":InspectorConnectTestAction" ]
|
||||
}
|
||||
}
|
155
inspector/test/connect_server_test.cpp
Normal file
155
inspector/test/connect_server_test.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "inspector/connect_inspector.h"
|
||||
#include "inspector/connect_server.h"
|
||||
#include "websocket/client/websocket_client.h"
|
||||
#include "websocket/server/websocket_server.h"
|
||||
|
||||
using namespace OHOS::ArkCompiler::Toolchain;
|
||||
|
||||
namespace panda::test {
|
||||
class ConnectServerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ConnectServerTest::SetUpTestCase";
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ConnectServerTest::TearDownTestCase";
|
||||
}
|
||||
|
||||
void SetUp() override {}
|
||||
|
||||
void TearDown() override {}
|
||||
#if defined(OHOS_PLATFORM)
|
||||
static constexpr char CONNECTED_MESSAGE_TEST[] = "connected";
|
||||
static constexpr char OPEN_MESSAGE_TEST[] = "layoutOpen";
|
||||
static constexpr char CLOSE_MESSAGE_TEST[] = "layoutClose";
|
||||
static constexpr char REQUEST_MESSAGE_TEST[] = "tree";
|
||||
static constexpr char STOPDEBUGGER_MESSAGE_TEST[] = "stopDebugger";
|
||||
static constexpr char OPEN_ARKUI_STATE_PROFILER_TEST[] = "ArkUIStateProfilerOpen";
|
||||
static constexpr char CLOSE_ARKUI_STATE_PROFILER_TEST[] = "ArkUIStateProfilerClose";
|
||||
|
||||
static constexpr char HELLO_INSPECTOR_CLIENT[] = "hello inspector client";
|
||||
static constexpr char INSPECTOR_SERVER_OK[] = "inspector server ok";
|
||||
static constexpr char INSPECTOR_RUN[] = "inspector run";
|
||||
static constexpr char INSPECTOR_QUIT[] = "inspector quit";
|
||||
#endif
|
||||
};
|
||||
|
||||
bool g_profilerFlag = false;
|
||||
bool g_connectFlag = false;
|
||||
bool g_switchStatus = false;
|
||||
int32_t g_createInfoId = 0;
|
||||
int32_t g_instanceId = 1;
|
||||
|
||||
void CallbackInit()
|
||||
{
|
||||
auto profilerCb = [](bool flag) -> void {
|
||||
g_profilerFlag = flag;
|
||||
};
|
||||
SetProfilerCallback(profilerCb);
|
||||
|
||||
auto connectCb = [](bool flag) -> void {
|
||||
g_connectFlag = flag;
|
||||
};
|
||||
SetConnectCallback(connectCb);
|
||||
|
||||
auto debugModeCb = []() -> void {
|
||||
GTEST_LOG_(INFO) << "Execute DebugModeCallBack.";
|
||||
};
|
||||
SetDebugModeCallBack(debugModeCb);
|
||||
|
||||
auto switchStatusCb = [](bool flag) -> void {
|
||||
g_switchStatus = flag;
|
||||
};
|
||||
auto createInfoCb = [](int32_t id) -> void {
|
||||
g_createInfoId = id;
|
||||
};
|
||||
SetSwitchCallBack(switchStatusCb, createInfoCb, g_instanceId);
|
||||
GTEST_LOG_(INFO) << "ConnectServerTest::CallbackInit finished";
|
||||
}
|
||||
|
||||
HWTEST_F(ConnectServerTest, InspectorBasicTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
ASSERT_TRUE(WaitForConnection());
|
||||
}
|
||||
|
||||
HWTEST_F(ConnectServerTest, InspectorConnectTest, testing::ext::TestSize.Level0)
|
||||
{
|
||||
CallbackInit();
|
||||
#if defined(OHOS_PLATFORM)
|
||||
int appPid = getprocpid();
|
||||
int oldProcessfd = -2;
|
||||
StartServerForSocketPair(oldProcessfd);
|
||||
StoreMessage(g_instanceId, HELLO_INSPECTOR_CLIENT);
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
WebSocketClient clientSocket;
|
||||
ASSERT_TRUE(clientSocket.InitToolchainWebSocketForSockName(std::to_string(appPid)));
|
||||
ASSERT_TRUE(clientSocket.ClientSendWSUpgradeReq());
|
||||
ASSERT_TRUE(clientSocket.ClientRecvWSUpgradeRsp());
|
||||
EXPECT_TRUE(clientSocket.SendReply(OPEN_ARKUI_STATE_PROFILER_TEST));
|
||||
EXPECT_TRUE(clientSocket.SendReply(REQUEST_MESSAGE_TEST));
|
||||
EXPECT_TRUE(clientSocket.SendReply(OPEN_MESSAGE_TEST));
|
||||
EXPECT_TRUE(clientSocket.SendReply(CONNECTED_MESSAGE_TEST));
|
||||
|
||||
EXPECT_STREQ(clientSocket.Decode().c_str(), HELLO_INSPECTOR_CLIENT);
|
||||
|
||||
std::string recv = clientSocket.Decode();
|
||||
EXPECT_STREQ(recv.c_str(), INSPECTOR_SERVER_OK);
|
||||
if (strcmp(recv.c_str(), INSPECTOR_SERVER_OK) == 0) {
|
||||
EXPECT_TRUE(clientSocket.SendReply(CLOSE_MESSAGE_TEST));
|
||||
EXPECT_TRUE(clientSocket.SendReply(STOPDEBUGGER_MESSAGE_TEST));
|
||||
EXPECT_TRUE(clientSocket.SendReply(CLOSE_ARKUI_STATE_PROFILER_TEST));
|
||||
}
|
||||
|
||||
EXPECT_STREQ(clientSocket.Decode().c_str(), INSPECTOR_RUN);
|
||||
EXPECT_STREQ(clientSocket.Decode().c_str(), INSPECTOR_QUIT);
|
||||
clientSocket.Close();
|
||||
exit(0);
|
||||
} else if (pid > 0) {
|
||||
// Waiting for executing the message instruction sent by the client
|
||||
sleep(2);
|
||||
ASSERT_TRUE(g_profilerFlag);
|
||||
ASSERT_EQ(g_createInfoId, g_instanceId);
|
||||
ASSERT_TRUE(g_switchStatus);
|
||||
ASSERT_TRUE(g_connectFlag);
|
||||
ASSERT_FALSE(WaitForConnection());
|
||||
|
||||
SendMessage(INSPECTOR_SERVER_OK);
|
||||
SendLayoutMessage(INSPECTOR_RUN);
|
||||
|
||||
// Waiting for executing the message instruction sent by the client
|
||||
sleep(2);
|
||||
ASSERT_FALSE(g_profilerFlag);
|
||||
ASSERT_FALSE(g_switchStatus);
|
||||
ASSERT_FALSE(g_connectFlag);
|
||||
|
||||
SendProfilerMessage(INSPECTOR_QUIT);
|
||||
|
||||
StopServer("InspectorConnectTest");
|
||||
} else {
|
||||
std::cerr << "InspectorConnectTest::fork failed" << std::endl;
|
||||
}
|
||||
RemoveMessage(g_instanceId);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace panda::test
|
@ -275,4 +275,9 @@
|
||||
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="InspectorConnectTest">
|
||||
<preparer>
|
||||
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
|
@ -49,7 +49,9 @@ public:
|
||||
}
|
||||
|
||||
#if defined(OHOS_PLATFORM)
|
||||
static constexpr char UNIX_DOMAIN_PATH[] = "server.sock";
|
||||
static constexpr char UNIX_DOMAIN_PATH_1[] = "server.sock_1";
|
||||
static constexpr char UNIX_DOMAIN_PATH_2[] = "server.sock_2";
|
||||
static constexpr char UNIX_DOMAIN_PATH_3[] = "server.sock_3";
|
||||
#endif
|
||||
static constexpr char HELLO_SERVER[] = "hello server";
|
||||
static constexpr char HELLO_CLIENT[] = "hello client";
|
||||
@ -71,7 +73,7 @@ HWTEST_F(WebSocketTest, DISABLED_ConnectWebSocketTest, testing::ext::TestSize.Le
|
||||
bool ret = false;
|
||||
#if defined(OHOS_PLATFORM)
|
||||
int appPid = getpid();
|
||||
ret = serverSocket.InitUnixWebSocket(UNIX_DOMAIN_PATH + std::to_string(appPid), 5);
|
||||
ret = serverSocket.InitUnixWebSocket(UNIX_DOMAIN_PATH_1 + std::to_string(appPid), 5);
|
||||
#else
|
||||
ret = serverSocket.InitTcpWebSocket(TCP_PORT, 5);
|
||||
#endif
|
||||
@ -84,7 +86,7 @@ HWTEST_F(WebSocketTest, DISABLED_ConnectWebSocketTest, testing::ext::TestSize.Le
|
||||
WebSocketClient clientSocket;
|
||||
bool retClient = false;
|
||||
#if defined(OHOS_PLATFORM)
|
||||
retClient = clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH + std::to_string(appPid), 5);
|
||||
retClient = clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH_1 + std::to_string(appPid), 5);
|
||||
#else
|
||||
retClient = clientSocket.InitToolchainWebSocketForPort(TCP_PORT, 5);
|
||||
#endif
|
||||
@ -168,7 +170,7 @@ HWTEST_F(WebSocketTest, DISABLED_ReConnectWebSocketTest, testing::ext::TestSize.
|
||||
bool ret = false;
|
||||
#if defined(OHOS_PLATFORM)
|
||||
int appPid = getpid();
|
||||
ret = serverSocket.InitUnixWebSocket(UNIX_DOMAIN_PATH + std::to_string(appPid), 5);
|
||||
ret = serverSocket.InitUnixWebSocket(UNIX_DOMAIN_PATH_2 + std::to_string(appPid), 5);
|
||||
#else
|
||||
ret = serverSocket.InitTcpWebSocket(TCP_PORT, 5);
|
||||
#endif
|
||||
@ -182,7 +184,7 @@ HWTEST_F(WebSocketTest, DISABLED_ReConnectWebSocketTest, testing::ext::TestSize.
|
||||
WebSocketClient clientSocket;
|
||||
bool retClient = false;
|
||||
#if defined(OHOS_PLATFORM)
|
||||
retClient = clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH + std::to_string(appPid), 5);
|
||||
retClient = clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH_2 + std::to_string(appPid), 5);
|
||||
#else
|
||||
retClient = clientSocket.InitToolchainWebSocketForPort(TCP_PORT, 5);
|
||||
#endif
|
||||
@ -240,7 +242,7 @@ HWTEST_F(WebSocketTest, DISABLED_ServerAbnormalTest, testing::ext::TestSize.Leve
|
||||
|
||||
#if defined(OHOS_PLATFORM)
|
||||
int appPid = getpid();
|
||||
ASSERT_TRUE(serverSocket.InitUnixWebSocket(UNIX_DOMAIN_PATH + std::to_string(appPid), 5));
|
||||
ASSERT_TRUE(serverSocket.InitUnixWebSocket(UNIX_DOMAIN_PATH_3 + std::to_string(appPid), 5));
|
||||
#else
|
||||
ASSERT_TRUE(serverSocket.InitTcpWebSocket(TCP_PORT, 5));
|
||||
#endif
|
||||
@ -253,9 +255,9 @@ HWTEST_F(WebSocketTest, DISABLED_ServerAbnormalTest, testing::ext::TestSize.Leve
|
||||
clientSocket.SetCloseConnectionCallback(closeCallBack);
|
||||
|
||||
#if defined(OHOS_PLATFORM)
|
||||
ASSERT_TRUE(clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH + std::to_string(appPid), 5));
|
||||
ASSERT_TRUE(clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH_3 + std::to_string(appPid), 5));
|
||||
// state is not UNITED, the function returns directly.
|
||||
ASSERT_TRUE(clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH + std::to_string(appPid), 5));
|
||||
ASSERT_TRUE(clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH_3 + std::to_string(appPid), 5));
|
||||
#else
|
||||
ASSERT_TRUE(clientSocket.InitToolchainWebSocketForPort(TCP_PORT, 5));
|
||||
// state is not UNITED, the function returns directly.
|
||||
|
Loading…
Reference in New Issue
Block a user