From 3ee653d98222d82d6ba1e788164a5bfd5b849cfe Mon Sep 17 00:00:00 2001 From: tantingting Date: Thu, 15 Aug 2024 17:26:59 +0800 Subject: [PATCH 01/51] add inspector Signed-off-by: tantingting --- inspector/connect_inspector.cpp | 36 ++++++++++++++++++++++++++++++--- inspector/connect_inspector.h | 8 +++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/inspector/connect_inspector.cpp b/inspector/connect_inspector.cpp index 200d2842..7622db24 100644 --- a/inspector/connect_inspector.cpp +++ b/inspector/connect_inspector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -26,6 +26,8 @@ static constexpr char REQUEST_MESSAGE[] = "tree"; static constexpr char STOPDEBUGGER_MESSAGE[] = "stopDebugger"; static constexpr char OPEN_ARKUI_STATE_PROFILER[] = "ArkUIStateProfilerOpen"; static constexpr char CLOSE_ARKUI_STATE_PROFILER[] = "ArkUIStateProfilerClose"; +static constexpr char START_RECORD_MESSAGE[] = "rsNodeStartRecord"; +static constexpr char STOP_RECORD_MESSAGE[] = "rsNodeStopRecord"; std::function g_setConnectCallBack; void* HandleDebugManager(void* const server) @@ -67,6 +69,25 @@ void OnOpenMessage(const std::string& message) } } +void OnInspectorRecordMessage(const std::string& message) +{ + if (message.find(START_RECORD_MESSAGE, 0) != std::string::npos) { + if (g_inspector->startRecord_ != nullptr && !g_inspector->isRecording_) { + LOGI("record start"); + g_inspector->startRecord_(); + g_inspector->isRecording_ = true; + } + } + + if (message.find(STOP_RECORD_MESSAGE, 0) != std::string::npos) { + if (g_inspector->stopRecord_ != nullptr && g_inspector->isRecording_) { + LOGI("record stop"); + g_inspector->stopRecord_(); + g_inspector->isRecording_ = false; + } + } +} + void OnMessage(const std::string& message) { std::lock_guard lock(g_connectMutex); @@ -74,12 +95,10 @@ void OnMessage(const std::string& message) LOGE("message is empty"); return; } - LOGI("ConnectServer OnMessage: %{public}s", message.c_str()); if (g_inspector != nullptr && g_inspector->connectServer_ != nullptr) { g_inspector->ideMsgQueue_.push(message); OnConnectedMessage(message); - OnOpenMessage(message); if (message.find(CLOSE_MESSAGE, 0) != std::string::npos) { if (g_setConnectCallBack != nullptr) { @@ -115,6 +134,7 @@ void OnMessage(const std::string& message) g_inspector->setDebugMode_(); } } + OnInspectorRecordMessage(message); } } @@ -269,4 +289,14 @@ void SetProfilerCallback(const std::function &setArkUIStateProfilerS g_inspector->setArkUIStateProfilerStatus_ = setArkUIStateProfilerStatus; } +void SetRecordCallback(const std::function &startRecordFunc, + const std::function &stopRecordFunc) +{ + std::lock_guard lock(g_connectMutex); + if (g_inspector == nullptr) { + g_inspector = std::make_unique(); + } + g_inspector->startRecord_ = startRecordFunc; + g_inspector->stopRecord_ = stopRecordFunc; +} } // OHOS::ArkCompiler::Toolchain diff --git a/inspector/connect_inspector.h b/inspector/connect_inspector.h index 4225304f..2d0420a8 100644 --- a/inspector/connect_inspector.h +++ b/inspector/connect_inspector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -59,6 +59,9 @@ void SetSwitchCallBack(const std::function& setSwitchStatus, void SetProfilerCallback(const std::function &setArkUIStateProfilerStatus); +void SetRecordCallback(const std::function &startRecordFunc, + const std::function &stopRecordFunc); + #ifdef __cplusplus #if __cplusplus } @@ -86,6 +89,9 @@ public: std::function createLayoutInfo_; std::function setDebugMode_; int32_t instanceId_ = -1; + std::function startRecord_; + std::function stopRecord_; + bool isRecording_ = false; }; } // namespace OHOS::ArkCompiler::Toolchain -- Gitee From 1fdaa56e6c8106f6a3fc2793c6fa189e7fae7fe6 Mon Sep 17 00:00:00 2001 From: daiweihao Date: Tue, 9 Jul 2024 10:01:32 +0800 Subject: [PATCH 02/51] Add websocket and http_decoder testcase 1. Add test cases for websocket callback functions. 2. Add test cases for abnormal links between client and server. 3. Add test cases for http decoding under abnormal message conditions. Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAA24Z Signed-off-by: daiweihao Change-Id: Ic4e704ab3d6fd850957cf53f3828f0e499b9d6b0 --- websocket/test/http_decoder_test.cpp | 38 +++++++++++++++++ websocket/test/websocket_test.cpp | 64 ++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/websocket/test/http_decoder_test.cpp b/websocket/test/http_decoder_test.cpp index 655e9d2d..55472dbe 100644 --- a/websocket/test/http_decoder_test.cpp +++ b/websocket/test/http_decoder_test.cpp @@ -38,12 +38,24 @@ public: "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n\r\n"; std::string requestHeaders = std::string(REQUEST_HEADERS); + static constexpr std::string_view ERR_REQUEST_HEADERS = "GEY\r\n"; + std::string errRequestHeaders = std::string(ERR_REQUEST_HEADERS); + + static constexpr std::string_view NO_INFO_REQUEST_HEADERS = "GET\r\n"; + std::string noInfoRequestHeaders = std::string(NO_INFO_REQUEST_HEADERS); + static constexpr std::string_view RESPONSE_HEADERS = "HTTP/1.1 101 Switching Protocols\r\n" "Connection: Upgrade\r\n" "Upgrade: websocket\r\n" "Sec-WebSocket-Accept: AyuTxzyBTJJdViDskomT0Q==\r\n\r\n"; std::string responseHeaders = std::string(RESPONSE_HEADERS); + static constexpr std::string_view ERR_RESPONSE_HEADERS = "HTTB\r\n"; + std::string errResponseHeaders = std::string(ERR_RESPONSE_HEADERS); + + static constexpr std::string_view NO_INFO_RESPONSE_HEADERS = "HTTP\r\n"; + std::string noInfoResponseHeaders = std::string(NO_INFO_RESPONSE_HEADERS); + static constexpr std::string_view EXPECTED_VERSION = "HTTP/1.1"; static constexpr std::string_view EXPECTED_STATUS = "101"; static constexpr std::string_view EXPECTED_CONNECTION = "Upgrade"; @@ -63,6 +75,18 @@ HWTEST_F(HttpDecoderTest, TestRequestDecode, testing::ext::TestSize.Level0) ASSERT_EQ(parsed.secWebSocketKey, EXPECTED_SEC_WEBSOCKET_KEY); } +HWTEST_F(HttpDecoderTest, TestAbnormalRequestDecode, testing::ext::TestSize.Level0) +{ + HttpRequest parsed; + ASSERT_FALSE(HttpRequest::Decode(errRequestHeaders, parsed)); + ASSERT_TRUE(HttpRequest::Decode(noInfoRequestHeaders, parsed)); + + ASSERT_EQ(parsed.version, ""); + ASSERT_EQ(parsed.connection, ""); + ASSERT_EQ(parsed.upgrade, ""); + ASSERT_EQ(parsed.secWebSocketKey, ""); +} + HWTEST_F(HttpDecoderTest, TestResponseDecode, testing::ext::TestSize.Level0) { HttpResponse parsed; @@ -75,4 +99,18 @@ HWTEST_F(HttpDecoderTest, TestResponseDecode, testing::ext::TestSize.Level0) ASSERT_EQ(parsed.upgrade, EXPECTED_UPGRADE); ASSERT_EQ(parsed.secWebSocketAccept, EXPECTED_SEC_WEBSOCKET_KEY); } + +HWTEST_F(HttpDecoderTest, TestAbnormalResponseDecode, testing::ext::TestSize.Level0) +{ + HttpResponse parsed; + ASSERT_FALSE(HttpResponse::Decode(errResponseHeaders, parsed)); + ASSERT_TRUE(HttpResponse::Decode(noInfoResponseHeaders, parsed)); + + ASSERT_EQ(parsed.version, ""); + ASSERT_EQ(parsed.status, ""); + ASSERT_EQ(parsed.connection, ""); + ASSERT_EQ(parsed.upgrade, ""); + ASSERT_EQ(parsed.secWebSocketAccept, ""); +} + } // namespace panda::test diff --git a/websocket/test/websocket_test.cpp b/websocket/test/websocket_test.cpp index 838bcd1c..c97017a9 100644 --- a/websocket/test/websocket_test.cpp +++ b/websocket/test/websocket_test.cpp @@ -127,6 +127,11 @@ HWTEST_F(WebSocketTest, ConnectWebSocketTest, testing::ext::TestSize.Level0) exit(0); } else if (pid > 0) { // mainprocess, handle server connect and recv/send message + auto openCallBack = []() -> void { + GTEST_LOG_(INFO) << "ConnectWebSocketTest connection is open."; + }; + serverSocket.SetOpenConnectionCallback(openCallBack); + ret = serverSocket.AcceptNewConnection(); ASSERT_TRUE(ret); std::string recv = serverSocket.Decode(); @@ -215,4 +220,63 @@ HWTEST_F(WebSocketTest, ReConnectWebSocketTest, testing::ext::TestSize.Level0) } serverSocket.Close(); } + +HWTEST_F(WebSocketTest, ClientAbnormalTest, testing::ext::TestSize.Level0) +{ + WebSocketClient clientSocket; + ASSERT_STREQ(clientSocket.GetSocketStateString().c_str(), "uninited"); + ASSERT_FALSE(clientSocket.ClientSendWSUpgradeReq()); + ASSERT_FALSE(clientSocket.ClientRecvWSUpgradeRsp()); + ASSERT_FALSE(clientSocket.SendReply(HELLO_SERVER)); +} + +HWTEST_F(WebSocketTest, ServerAbnormalTest, testing::ext::TestSize.Level0) +{ + WebSocketServer serverSocket; + // No connection established, the function returns directly. + serverSocket.Close(); + ASSERT_FALSE(serverSocket.AcceptNewConnection()); + +#if defined(OHOS_PLATFORM) + int appPid = getpid(); + ASSERT_TRUE(serverSocket.InitUnixWebSocket(UNIX_DOMAIN_PATH + std::to_string(appPid), 5)); +#else + ASSERT_TRUE(serverSocket.InitTcpWebSocket(TCP_PORT, 5)); +#endif + pid_t pid = fork(); + if (pid == 0) { + WebSocketClient clientSocket; + auto closeCallBack = []() -> void { + GTEST_LOG_(INFO) << "ServerAbnormalTest client connection is closed."; + }; + clientSocket.SetCloseConnectionCallback(closeCallBack); + +#if defined(OHOS_PLATFORM) + ASSERT_TRUE(clientSocket.InitToolchainWebSocketForSockName(UNIX_DOMAIN_PATH + 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)); +#else + ASSERT_TRUE(clientSocket.InitToolchainWebSocketForPort(TCP_PORT, 5)); + // state is not UNITED, the function returns directly. + ASSERT_TRUE(clientSocket.InitToolchainWebSocketForPort(TCP_PORT, 5)); +#endif + ASSERT_TRUE(clientSocket.ClientSendWSUpgradeReq()); + ASSERT_FALSE(clientSocket.ClientRecvWSUpgradeRsp()); + exit(0); + } else if (pid > 0) { + auto failCallBack = []() -> void { + GTEST_LOG_(INFO) << "ServerAbnormalTest server connection is failed."; + }; + serverSocket.SetFailConnectionCallback(failCallBack); + auto notValidCallBack = [](const HttpRequest&) -> bool { + GTEST_LOG_(INFO) << "ServerAbnormalTest server connection request is not valid."; + return false; + }; + serverSocket.SetValidateConnectionCallback(notValidCallBack); + ASSERT_FALSE(serverSocket.AcceptNewConnection()); + } else { + std::cerr << "ServerAbnormalTest::fork failed, error = " + << errno << ", desc = " << strerror(errno) << std::endl; + } +} } // namespace panda::test \ No newline at end of file -- Gitee From 7a6e904b63cdca0158d248d3bedf4cc665150b75 Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Thu, 11 Jul 2024 17:04:09 +0800 Subject: [PATCH 03/51] Modifying format issues 1.Fix G.NAM.01 2.Fix G.CMT.03 3.Fix G.VAR.03 Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IABEH2 Signed-off-by: swx1282997 --- build/compile_script/ark.py | 54 +++--- build/config/mac/sdk_info.py | 170 +++++++++--------- build/misc/mac/check_return_value.py | 3 +- tooling/client/tcpServer/test/js_test_base.py | 3 +- .../tcpServer/test/js_test_case/js_test.py | 149 +++++++-------- tooling/client/tcpServer/test/runtest.py | 16 +- 6 files changed, 200 insertions(+), 195 deletions(-) diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index 7eadf1bd..ae11b1a4 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -358,18 +358,18 @@ class ArkPy: def get_test262_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout): print("running test262 in JIT mode\n") if any('target_cpu="arm64"' in arg for arg in gn_args): - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{1}/thirdparty/icu/" \ - ":../../{1}/thirdparty/bounds_checking_function" \ - ":../../{1}/arkcompiler/ets_runtime:" \ - " --ark-arch aarch64" \ - " --run-jit" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{1}/thirdparty/icu/" \ + ":../../{1}/thirdparty/bounds_checking_function" \ + ":../../{1}/arkcompiler/ets_runtime:" \ + " --ark-arch aarch64" \ + " --run-jit" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) else: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ @@ -386,21 +386,21 @@ class ArkPy: def get_test262_baseline_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout): print("running test262 in baseline JIT mode\n") if any('target_cpu="arm64"' in arg for arg in gn_args): - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - ":../../{1}/thirdparty/icu" \ - ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos" \ - ":../../{1}/thirdparty/bounds_checking_function" \ - ":../../{1}/arkcompiler/ets_runtime" \ - ":../../{1}/common/common/libc/lib" \ - " --ark-arch aarch64" \ - " --run-baseline-jit" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + ":../../{1}/thirdparty/icu" \ + ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos" \ + ":../../{1}/thirdparty/bounds_checking_function" \ + ":../../{1}/arkcompiler/ets_runtime" \ + ":../../{1}/common/common/libc/lib" \ + " --ark-arch aarch64" \ + " --run-baseline-jit" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) else: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ " --libs-dir ../../{1}/lib.unstripped/arkcompiler/ets_runtime" \ diff --git a/build/config/mac/sdk_info.py b/build/config/mac/sdk_info.py index 6396c0fe..f757cd3d 100755 --- a/build/config/mac/sdk_info.py +++ b/build/config/mac/sdk_info.py @@ -16,91 +16,91 @@ import sys # "iphoneos" or "macosx" generally). -def SplitVersion(version): - """Splits the Xcode version to 3 values. - - >>> list(SplitVersion('8.2.1.1')) - ['8', '2', '1'] - >>> list(SplitVersion('9.3')) - ['9', '3', '0'] - >>> list(SplitVersion('10.0')) - ['10', '0', '0'] - """ - if isinstance(version, bytes): - version = version.decode() - version = version.split('.') - return itertools.islice(itertools.chain(version, itertools.repeat('0')), 0, 3) - - -def FormatVersion(version): - """Converts Xcode version to a format required for DTXcode in Info.plist - - >>> FormatVersion('8.2.1') - '0821' - >>> FormatVersion('9.3') - '0930' - >>> FormatVersion('10.0') - '1000' - """ - major, minor, patch = SplitVersion(version) - return ('%2s%s%s' % (major, minor, patch)).replace(' ', '0') - - -def FillXcodeVersion(settings): - """Fills the Xcode version and build number into |settings|.""" - lines = subprocess.check_output(['xcodebuild', '-version']).splitlines() - settings['xcode_version'] = FormatVersion(lines[0].split()[-1]) - settings['xcode_version_int'] = int(settings['xcode_version'], 10) - settings['xcode_build'] = lines[-1].split()[-1] - - -def FillMachineOSBuild(settings): - """Fills OS build number into |settings|.""" - settings['machine_os_build'] = subprocess.check_output( - ['sw_vers', '-buildVersion']).strip() - - -def FillSDKPathAndVersion(settings, platform, xcode_version): - """Fills the SDK path and version for |platform| into |settings|.""" - settings['sdk_path'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-path']).strip() - settings['sdk_version'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-version']).strip() - settings['sdk_platform_path'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-platform-path']).strip() - if xcode_version >= '0720': - settings['sdk_build'] = subprocess.check_output([ - 'xcrun', '-sdk', platform, '--show-sdk-build-version']).strip() - else: - settings['sdk_build'] = settings['sdk_version'] +def split_version(version): + """Splits the Xcode version to 3 values. + + >>> list(SplitVersion('8.2.1.1')) + ['8', '2', '1'] + >>> list(SplitVersion('9.3')) + ['9', '3', '0'] + >>> list(SplitVersion('10.0')) + ['10', '0', '0'] + """ + if isinstance(version, bytes): + version = version.decode() + version = version.split('.') + return itertools.islice(itertools.chain(version, itertools.repeat('0')), 0, 3) + + +def format_version(version): + """Converts Xcode version to a format required for DTXcode in Info.plist + + >>> FormatVersion('8.2.1') + '0821' + >>> FormatVersion('9.3') + '0930' + >>> FormatVersion('10.0') + '1000' + """ + major, minor, patch = split_version(version) + return ('%2s%s%s' % (major, minor, patch)).replace(' ', '0') + + +def fill_xcode_version(settings_xcode): + """Fills the Xcode version and build number into |settings_xcode|.""" + lines = subprocess.check_output(['xcodebuild', '-version']).splitlines() + settings_xcode['xcode_version'] = format_version(lines[0].split()[-1]) + settings_xcode['xcode_version_int'] = int(settings_xcode['xcode_version'], 10) + settings_xcode['xcode_build'] = lines[-1].split()[-1] + + +def fill_machine_os_build(settings_os): + """Fills OS build number into |settings_os|.""" + settings_os['machine_os_build'] = subprocess.check_output( + ['sw_vers', '-buildVersion']).strip() + + +def fill_sdk_path_and_version(settings_sdk, platform, xcode_version): + """Fills the SDK path and version for |platform| into |settings|.""" + settings_sdk['sdk_path'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-path']).strip() + settings_sdk['sdk_version'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-version']).strip() + settings_sdk['sdk_platform_path'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-platform-path']).strip() + if xcode_version >= '0720': + settings_sdk['sdk_build'] = subprocess.check_output([ + 'xcrun', '-sdk', platform, '--show-sdk-build-version']).strip() + else: + settings_sdk['sdk_build'] = settings_sdk['sdk_version'] if __name__ == '__main__': - doctest.testmod() - - parser = argparse.ArgumentParser() - parser.add_argument("--developer_dir", required=False) - args, unknownargs = parser.parse_known_args() - if args.developer_dir: - os.environ['DEVELOPER_DIR'] = args.developer_dir - - if len(unknownargs) != 1: - sys.stderr.write( - 'usage: %s [iphoneos|iphonesimulator|macosx]\n' % - os.path.basename(sys.argv[0])) - sys.exit(1) - - settings = {} - FillMachineOSBuild(settings) - FillXcodeVersion(settings) - FillSDKPathAndVersion(settings, unknownargs[0], settings['xcode_version']) - - for key in sorted(settings): - value = settings[key] - if isinstance(value, bytes): - value = value.decode() - if key != 'xcode_version_int': - value = '"%s"' % value - print('%s=%s' % (key, value)) - else: - print('%s=%d' % (key, value)) + doctest.testmod() + + parser = argparse.ArgumentParser() + parser.add_argument("--developer_dir", required=False) + args, unknownargs = parser.parse_known_args() + if args.developer_dir: + os.environ['DEVELOPER_DIR'] = args.developer_dir + + if len(unknownargs) != 1: + sys.stderr.write( + 'usage: %s [iphoneos|iphonesimulator|macosx]\n' % + os.path.basename(sys.argv[0])) + sys.exit(1) + + settings = {} + fill_machine_os_build(settings) + fill_xcode_version(settings) + fill_sdk_path_and_version(settings, unknownargs[0], settings['xcode_version']) + + for key in sorted(settings): + value = settings[key] + if isinstance(value, bytes): + value = value.decode() + if key != 'xcode_version_int': + value = '"%s"' % value + print('%s=%s' % (key, value)) + else: + print('%s=%d' % (key, value)) diff --git a/build/misc/mac/check_return_value.py b/build/misc/mac/check_return_value.py index f12ddb20..33c5bc1a 100755 --- a/build/misc/mac/check_return_value.py +++ b/build/misc/mac/check_return_value.py @@ -5,7 +5,8 @@ # found in the LICENSE file. """This program wraps an arbitrary command and prints "1" if the command ran -successfully.""" +successfully. +""" import os import subprocess diff --git a/tooling/client/tcpServer/test/js_test_base.py b/tooling/client/tcpServer/test/js_test_base.py index ce920b20..3b6875a7 100644 --- a/tooling/client/tcpServer/test/js_test_base.py +++ b/tooling/client/tcpServer/test/js_test_base.py @@ -20,6 +20,7 @@ import subprocess import sys import unittest + class JsTestBase(unittest.TestCase): hdctool = None tcp_client_socket = None @@ -80,7 +81,7 @@ class JsTestBase(unittest.TestCase): try: self.tcp_client_socket.settimeout(15) os.environ["isSkipped"] = "False" - data, ADDR = self.tcp_client_socket.recvfrom(self.BUFSIZ) + data, addr = self.tcp_client_socket.recvfrom(self.BUFSIZ) print("Recv: ", data.decode('utf-8')) except TimeoutError: self.tcp_client_socket.close() diff --git a/tooling/client/tcpServer/test/js_test_case/js_test.py b/tooling/client/tcpServer/test/js_test_case/js_test.py index 7b083f8b..51824d97 100644 --- a/tooling/client/tcpServer/test/js_test_case/js_test.py +++ b/tooling/client/tcpServer/test/js_test_case/js_test.py @@ -18,8 +18,11 @@ import unittest import os from js_test_base import JsTestBase + + class JsTestCase(JsTestBase): repeat_time = 3 + @classmethod def setUpClass(cls): os.environ["isSkipped"] = "False" @@ -44,8 +47,8 @@ class JsTestCase(JsTestBase): cls.run_arkdb_server(cls, dbg_name) cls.connect_client_socket(cls, dbg_name) cls.tcp_client_socket.send("enable".encode('utf-8')) - data, ADDR = cls.tcp_client_socket.recvfrom(cls.BUFSIZ) - data, ADDR = cls.tcp_client_socket.recvfrom(cls.BUFSIZ) + data, addr = cls.tcp_client_socket.recvfrom(cls.BUFSIZ) + data, addr = cls.tcp_client_socket.recvfrom(cls.BUFSIZ) print("recv: ", data.decode('utf-8')) @classmethod @@ -124,27 +127,27 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") for line in breakpoint_lines: self.send_command("b entry/src/main/ets/pages/%s" % line) - subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-into") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool,stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-into") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-into") @@ -154,7 +157,7 @@ class JsTestCase(JsTestBase): for i in breakpoint_lines: self.send_command("delete 1") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") @@ -169,7 +172,7 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("step-out") for i in range(self.repeat_time): @@ -177,14 +180,14 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("step-out") for i in range(self.repeat_time): @@ -192,14 +195,14 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("step-out") for i in range(self.repeat_time): @@ -210,7 +213,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -222,27 +225,27 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") for line in breakpoint_lines: self.send_command("b entry/src/main/ets/pages/%s" % line) - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-over") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-over") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-over") for i in range(self.repeat_time): @@ -251,7 +254,7 @@ class JsTestCase(JsTestBase): for i in breakpoint_lines: self.send_command("delete 1") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") @@ -262,29 +265,29 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") for line in breakpoint_lines: self.send_command("b entry/src/main/ets/pages/%s" % line) - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-into") self.send_command("step-over") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-into") self.send_command("step-over") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-into") self.send_command("step-over") @@ -294,7 +297,7 @@ class JsTestCase(JsTestBase): for i in breakpoint_lines: self.send_command("delete 1") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") @@ -309,7 +312,7 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("watch a") for i in range(self.repeat_time): @@ -320,7 +323,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -332,29 +335,29 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") for line in breakpoint_lines: self.send_command("b entry/src/main/ets/pages/%s" % line) - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-over") self.send_command("watch a") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-over") self.send_command("watch a") for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("step-over") self.send_command("watch a") @@ -364,7 +367,7 @@ class JsTestCase(JsTestBase): for i in breakpoint_lines: self.send_command("delete 1") - subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout = subprocess.PIPE) + subprocess.run("%s shell wukong special -t 600,600 -c 1" % self.hdctool, stdout=subprocess.PIPE) for i in range(self.repeat_time): self.send_command("resume") @@ -379,7 +382,7 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("print") self.send_command("print 2") @@ -391,7 +394,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -407,9 +410,9 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) - for i in range (self.repeat_time): + for i in range(self.repeat_time): self.send_command("print") for i in range(self.repeat_time): self.send_command("resume") @@ -419,7 +422,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -435,7 +438,7 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("cpuprofile-enable") @@ -451,7 +454,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -467,14 +470,14 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("heapprofiler-enable") self.send_command("heapdump") self.send_command("resume") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -487,7 +490,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -503,14 +506,14 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("heapprofiler-enable") self.send_command("allocationtrack") self.send_command("resume") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -523,7 +526,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -539,7 +542,7 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("heapprofiler-enable") @@ -554,7 +557,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -570,7 +573,7 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("heapusage") @@ -581,7 +584,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -597,13 +600,13 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("showstack") self.send_command("resume") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -612,7 +615,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -628,7 +631,7 @@ class JsTestCase(JsTestBase): self.send_command("b entry/src/main/ets/pages/%s" % line) subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("step-into") @@ -639,7 +642,7 @@ class JsTestCase(JsTestBase): self.send_command("sampling") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -654,7 +657,7 @@ class JsTestCase(JsTestBase): self.send_command("showstack") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -663,7 +666,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -674,7 +677,7 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("cpuprofile-enable") @@ -686,7 +689,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -697,13 +700,13 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("heapprofiler-enable") self.send_command("heapdump") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -713,7 +716,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -724,13 +727,13 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("heapprofiler-enable") self.send_command("allocationtrack") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -741,7 +744,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -752,7 +755,7 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("heapprofiler-enable") @@ -764,7 +767,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -775,7 +778,7 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("heapusage") @@ -784,7 +787,7 @@ class JsTestCase(JsTestBase): subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") @@ -795,20 +798,20 @@ class JsTestCase(JsTestBase): self.send_command("rt-enable") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) self.send_command("showstack") self.send_command("resume") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") subprocess.run( "%s shell wukong special -t 600,600 -c 1" % self.hdctool, - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) for i in range(self.repeat_time): self.send_command("resume") \ No newline at end of file diff --git a/tooling/client/tcpServer/test/runtest.py b/tooling/client/tcpServer/test/runtest.py index e02ad1ad..f58fc163 100644 --- a/tooling/client/tcpServer/test/runtest.py +++ b/tooling/client/tcpServer/test/runtest.py @@ -33,17 +33,17 @@ class RunTest: parser = argparse.ArgumentParser(description = 'Plugin test.') parser.add_argument( '-hdctool', - action = 'store', - required = True, - default = None, - help = 'Remote connnection tool.' + action='store', + required=True, + default=None, + help='Remote connnection tool.' ) self.args = parser.parse_args() def discover_cases(self): current_dir = os.path.dirname(os.path.abspath(__file__)) case_dir = current_dir + os.sep + 'js_test_case' - discover = self.loader.discover(case_dir, pattern = '*.py') + discover = self.loader.discover(case_dir, pattern='*.py') self.suite.addTest(discover) def get_panda_list(self): @@ -64,10 +64,10 @@ class RunTest: self.suite = unittest.TestSuite() self.discover_cases() os.environ["HapName"] = hap_name - runner = unittest.TextTestRunner(verbosity = 2) + runner = unittest.TextTestRunner(verbosity=2) runner.run(self.suite) -main = RunTest +Main = RunTest if __name__ == '__main__': - main() + Main() -- Gitee From 26da365ba8bddee7f1e93ae0741ae932f348829c Mon Sep 17 00:00:00 2001 From: fangting Date: Thu, 11 Jul 2024 10:09:42 +0800 Subject: [PATCH 04/51] fix mac standalone build failed fix mac standalone build failed Issue:#IAC532 Signed-off-by: fangting --- tooling/client/ark_multi/main.cpp | 33 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tooling/client/ark_multi/main.cpp b/tooling/client/ark_multi/main.cpp index 661a49b1..7e94fb9a 100644 --- a/tooling/client/ark_multi/main.cpp +++ b/tooling/client/ark_multi/main.cpp @@ -26,7 +26,10 @@ #include "ecmascript/js_runtime_options.h" #include "ecmascript/napi/include/jsnapi.h" #include "ecmascript/platform/file.h" - +#ifdef PANDA_TARGET_MACOS +#include +#include +#endif static panda::ecmascript::Mutex g_mutex; static std::list g_files; static std::list::iterator g_iter; @@ -73,6 +76,26 @@ std::pair GetNextPara() return {fileName, entry}; } +std::string GetMsg(int ret, std::string& msg, std::string& fileName) +{ + if (!ret) { +#ifdef PANDA_TARGET_MACOS + msg = "[FAILED] [" + std::to_string(syscall(SYS_thread_selfid)) + "] Run " + + fileName + " failed!"; +#else + msg = "[FAILED] [" + std::to_string(gettid()) + "] Run " + fileName + " failed!"; +#endif + } else { +#ifdef PANDA_TARGET_MACOS + msg = "[PASS] [" + std::to_string(syscall(SYS_thread_selfid)) + "] Run " + + fileName + " success!"; +#else + msg = "[PASS] [" + std::to_string(gettid()) + "] Run " + fileName + " success!"; +#endif + } + return msg; +} + bool StartThread(uv_loop_t *loop) { uv_thread_t tid = 0; @@ -99,13 +122,7 @@ bool StartThread(uv_loop_t *loop) panda::JSNApi::DestroyJSVM(vm); auto loop = static_cast(arg); auto work = new uv_work_t; - std::string msg; - if (!ret) { - msg = "[FAILED] [" + std::to_string(gettid()) + "] Run " + fileName + " failed!"; - } else { - msg = "[PASS] [" + std::to_string(gettid()) + "] Run " + fileName + " success!"; - continue; - } + std::string msg = GetMsg(ret, msg, fileName); work->data = new char[msg.size() + 1]; if (strncpy_s(static_cast(work->data), msg.size() + 1, msg.data(), msg.size()) != EOK) { delete[] static_cast(work->data); -- Gitee From 96f8eee8e93522bdf4abd71e1887950572a8265f Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Fri, 12 Jul 2024 10:17:19 +0800 Subject: [PATCH 05/51] CFI Rule Adjustment Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IA7UUH Signed-off-by: swx1282997 --- tooling/agent/css_impl.cpp | 25 +++++--- tooling/agent/css_impl.h | 7 ++- tooling/agent/dom_impl.cpp | 25 +++++--- tooling/agent/dom_impl.h | 7 ++- tooling/agent/heapprofiler_impl.cpp | 93 ++++++++++++++++++++++------- tooling/agent/heapprofiler_impl.h | 18 +++++- tooling/agent/overlay_impl.cpp | 25 +++++--- tooling/agent/overlay_impl.h | 7 ++- tooling/agent/page_impl.cpp | 25 +++++--- tooling/agent/page_impl.h | 7 ++- tooling/agent/runtime_impl.cpp | 53 +++++++++++----- tooling/agent/runtime_impl.h | 11 +++- tooling/agent/target_impl.cpp | 25 +++++--- tooling/agent/target_impl.h | 7 ++- tooling/agent/tracing_impl.cpp | 51 +++++++++++----- tooling/agent/tracing_impl.h | 11 +++- 16 files changed, 293 insertions(+), 104 deletions(-) diff --git a/tooling/agent/css_impl.cpp b/tooling/agent/css_impl.cpp index 06226c85..251c5793 100755 --- a/tooling/agent/css_impl.cpp +++ b/tooling/agent/css_impl.cpp @@ -21,17 +21,24 @@ namespace panda::ecmascript::tooling { void CssImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "disable", &CssImpl::DispatcherImpl::Disable }, - }; + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to CssImpl"; + switch (method) { + case Method::DISABLE: + Disable(request); + break; + case Method::UNKNWON: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(INFO) << "dispatch [" << method << "] to CssImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); +CssImpl::DispatcherImpl::Method CssImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "disable") { + return Method::DISABLE; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNWON; } } diff --git a/tooling/agent/css_impl.h b/tooling/agent/css_impl.h index d82f5711..af2e8d1f 100755 --- a/tooling/agent/css_impl.h +++ b/tooling/agent/css_impl.h @@ -36,11 +36,16 @@ public: void Disable(const DispatchRequest &request); void Dispatch(const DispatchRequest &request) override; + enum class Method { + DISABLE, + UNKNWON + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (CssImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr css_ {}; }; diff --git a/tooling/agent/dom_impl.cpp b/tooling/agent/dom_impl.cpp index c38533dc..89218ee3 100755 --- a/tooling/agent/dom_impl.cpp +++ b/tooling/agent/dom_impl.cpp @@ -21,17 +21,24 @@ namespace panda::ecmascript::tooling { void DomImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "disable", &DomImpl::DispatcherImpl::Disable }, - }; + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to DomImpl"; + switch (method) { + case Method::DISABLE: + Disable(request); + break; + case Method::UNKNWON: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(INFO) << "dispatch [" << method << "] to DomImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); +DomImpl::DispatcherImpl::Method DomImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "disable") { + return Method::DISABLE; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNWON; } } diff --git a/tooling/agent/dom_impl.h b/tooling/agent/dom_impl.h index dcf0b2b2..4e81b532 100755 --- a/tooling/agent/dom_impl.h +++ b/tooling/agent/dom_impl.h @@ -36,11 +36,16 @@ public: void Disable(const DispatchRequest &request); void Dispatch(const DispatchRequest &request) override; + enum class Method { + DISABLE, + UNKNWON + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (DomImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr dom_ {}; }; diff --git a/tooling/agent/heapprofiler_impl.cpp b/tooling/agent/heapprofiler_impl.cpp index 51d9444c..68cd3b21 100644 --- a/tooling/agent/heapprofiler_impl.cpp +++ b/tooling/agent/heapprofiler_impl.cpp @@ -28,28 +28,79 @@ void HeapProfilerImpl::InitializeExtendedProtocolsList() void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "addInspectedHeapObject", &HeapProfilerImpl::DispatcherImpl::AddInspectedHeapObject }, - { "collectGarbage", &HeapProfilerImpl::DispatcherImpl::CollectGarbage }, - { "enable", &HeapProfilerImpl::DispatcherImpl::Enable }, - { "disable", &HeapProfilerImpl::DispatcherImpl::Disable }, - { "getHeapObjectId", &HeapProfilerImpl::DispatcherImpl::GetHeapObjectId }, - { "getObjectByHeapObjectId", &HeapProfilerImpl::DispatcherImpl::GetObjectByHeapObjectId }, - { "getSamplingProfile", &HeapProfilerImpl::DispatcherImpl::GetSamplingProfile }, - { "startSampling", &HeapProfilerImpl::DispatcherImpl::StartSampling }, - { "startTrackingHeapObjects", &HeapProfilerImpl::DispatcherImpl::StartTrackingHeapObjects }, - { "stopSampling", &HeapProfilerImpl::DispatcherImpl::StopSampling }, - { "stopTrackingHeapObjects", &HeapProfilerImpl::DispatcherImpl::StopTrackingHeapObjects }, - { "takeHeapSnapshot", &HeapProfilerImpl::DispatcherImpl::TakeHeapSnapshot } - }; - - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to HeapProfilerImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(DEBUG) << "dispatch [" << request.GetMethod() << "] to HeapProfilerImpl"; + switch (method) { + case Method::ADDINSPECTEDHEAPOBJECT: + AddInspectedHeapObject(request); + break; + case Method::COLLECTGARBAGE: + CollectGarbage(request); + break; + case Method::ENABLE: + Enable(request); + break; + case Method::DISABLE: + Disable(request); + break; + case Method::GETHEAPOBJECTID: + GetHeapObjectId(request); + break; + case Method::GETOBJECTBYHEAPOBJECTID: + GetObjectByHeapObjectId(request); + break; + case Method::GETSAMPLINGPROFILE: + GetSamplingProfile(request); + break; + case Method::STARTSAMPLING: + StartSampling(request); + break; + case Method::STARTTRACKINGHEAPOBJECTS: + StartTrackingHeapObjects(request); + break; + case Method::STOPSAMPLING: + StopSampling(request); + break; + case Method::STOPTRACKINGHEAPOBJECTS: + StopTrackingHeapObjects(request); + break; + case Method::TAKEHEAPSNAPSHOT: + TakeHeapSnapshot(request); + break; + case Method::UNKNOWN: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} + +HeapProfilerImpl::DispatcherImpl::Method HeapProfilerImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "addInspectedHeapObject") { + return Method::ADDINSPECTEDHEAPOBJECT; + } else if (method == "collectGarbage") { + return Method::COLLECTGARBAGE; + } else if (method == "enable") { + return Method::ENABLE; + } else if (method == "disable") { + return Method::DISABLE; + } else if (method == "getHeapObjectId") { + return Method::GETHEAPOBJECTID; + } else if (method == "getObjectByHeapObjectId") { + return Method::GETOBJECTBYHEAPOBJECTID; + } else if (method == "getSamplingProfile") { + return Method::GETSAMPLINGPROFILE; + } else if (method == "startSampling") { + return Method::STARTSAMPLING; + } else if (method == "startTrackingHeapObjects") { + return Method::STARTTRACKINGHEAPOBJECTS; + } else if (method == "stopSampling") { + return Method::STOPSAMPLING; + } else if (method == "stopTrackingHeapObjects") { + return Method::STOPTRACKINGHEAPOBJECTS; + } else if (method == "takeHeapSnapshot") { + return Method::TAKEHEAPSNAPSHOT; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/heapprofiler_impl.h b/tooling/agent/heapprofiler_impl.h index 4aa6aa52..839490fe 100644 --- a/tooling/agent/heapprofiler_impl.h +++ b/tooling/agent/heapprofiler_impl.h @@ -79,11 +79,27 @@ public: void StopTrackingHeapObjects(const DispatchRequest &request); void TakeHeapSnapshot(const DispatchRequest &request); + enum class Method { + ADDINSPECTEDHEAPOBJECT, + COLLECTGARBAGE, + ENABLE, + DISABLE, + GETHEAPOBJECTID, + GETOBJECTBYHEAPOBJECTID, + GETSAMPLINGPROFILE, + STARTSAMPLING, + STARTTRACKINGHEAPOBJECTS, + STOPSAMPLING, + STOPTRACKINGHEAPOBJECTS, + TAKEHEAPSNAPSHOT, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (HeapProfilerImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr heapprofiler_ {}; }; diff --git a/tooling/agent/overlay_impl.cpp b/tooling/agent/overlay_impl.cpp index 8f35afbd..a936396f 100755 --- a/tooling/agent/overlay_impl.cpp +++ b/tooling/agent/overlay_impl.cpp @@ -23,17 +23,24 @@ namespace panda::ecmascript::tooling { void OverlayImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "disable", &OverlayImpl::DispatcherImpl::Disable }, - }; + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to OverlayImpl"; + switch (method) { + case Method::DISABLE: + Disable(request); + break; + case Method::UNKNOWN: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(INFO) << "dispatch [" << method << "] to OverlayImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); +OverlayImpl::DispatcherImpl::Method OverlayImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "disable") { + return Method::DISABLE; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/overlay_impl.h b/tooling/agent/overlay_impl.h index 1bf52f66..7fd858bf 100755 --- a/tooling/agent/overlay_impl.h +++ b/tooling/agent/overlay_impl.h @@ -36,11 +36,16 @@ public: void Disable(const DispatchRequest &request); void Dispatch(const DispatchRequest &request) override; + enum class Method { + DISABLE, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (OverlayImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr overlay_ {}; }; diff --git a/tooling/agent/page_impl.cpp b/tooling/agent/page_impl.cpp index 4522234b..203ae8ce 100755 --- a/tooling/agent/page_impl.cpp +++ b/tooling/agent/page_impl.cpp @@ -21,17 +21,24 @@ namespace panda::ecmascript::tooling { void PageImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "getNavigationHistory", &PageImpl::DispatcherImpl::GetNavigationHistory }, - }; + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to PageImpl"; + switch (method) { + case Method::GETNAVIGATIONHISTORY: + GetNavigationHistory(request); + break; + case Method::UNKNOWN: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(INFO) << "dispatch [" << method << "] to PageImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); +PageImpl::DispatcherImpl::Method PageImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "getNavigationHistory") { + return Method::GETNAVIGATIONHISTORY; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/page_impl.h b/tooling/agent/page_impl.h index abdc4dee..1a7dd198 100755 --- a/tooling/agent/page_impl.h +++ b/tooling/agent/page_impl.h @@ -36,11 +36,16 @@ public: void GetNavigationHistory(const DispatchRequest &request); void Dispatch(const DispatchRequest &request) override; + enum class Method { + GETNAVIGATIONHISTORY, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (PageImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr page_ {}; }; diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index 8ad8d88b..1d7f8553 100644 --- a/tooling/agent/runtime_impl.cpp +++ b/tooling/agent/runtime_impl.cpp @@ -33,23 +33,44 @@ void RuntimeImpl::InitializeExtendedProtocolsList() void RuntimeImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "enable", &RuntimeImpl::DispatcherImpl::Enable }, - { "disable", &RuntimeImpl::DispatcherImpl::Disable }, - { "getProperties", &RuntimeImpl::DispatcherImpl::GetProperties }, - { "runIfWaitingForDebugger", &RuntimeImpl::DispatcherImpl::RunIfWaitingForDebugger }, - { "getHeapUsage", &RuntimeImpl::DispatcherImpl::GetHeapUsage } - }; - - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to RuntimeImpl"; - - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end()) { - (this->*(entry->second))(request); + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(DEBUG) << "dispatch [" << request.GetMethod() << "] to RuntimeImpl"; + switch (method) { + case Method::ENABLE: + Enable(request); + break; + case Method::DISABLE: + Disable(request); + break; + case Method::GETPROPERTIES: + GetProperties(request); + break; + case Method::RUNIFWAITINGFORDEBUGGER: + RunIfWaitingForDebugger(request); + break; + case Method::GETHEAPUSAGE: + GetHeapUsage(request); + break; + case Method::UNKNOWN: + SendResponse(request, DispatchResponse::Fail("unknown method: " + request.GetMethod())); + break; + } +} + +RuntimeImpl::DispatcherImpl::Method RuntimeImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "enable") { + return Method::ENABLE; + } else if (method == "disable") { + return Method::DISABLE; + } else if (method == "getProperties") { + return Method::GETPROPERTIES; + } else if (method == "runIfWaitingForDebugger") { + return Method::RUNIFWAITINGFORDEBUGGER; + } else if (method == "getHeapUsage") { + return Method::GETHEAPUSAGE; } else { - LOG_DEBUGGER(ERROR) << "unknown method: " << method; - SendResponse(request, DispatchResponse::Fail("unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/runtime_impl.h b/tooling/agent/runtime_impl.h index 14518d9e..e7b67a4b 100644 --- a/tooling/agent/runtime_impl.h +++ b/tooling/agent/runtime_impl.h @@ -53,8 +53,17 @@ public: void GetProperties(const DispatchRequest &request); void GetHeapUsage(const DispatchRequest &request); + enum class Method { + ENABLE, + DISABLE, + GETPROPERTIES, + RUNIFWAITINGFORDEBUGGER, + GETHEAPUSAGE, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: - using AgentHandler = void (RuntimeImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr runtime_ {}; NO_COPY_SEMANTIC(DispatcherImpl); diff --git a/tooling/agent/target_impl.cpp b/tooling/agent/target_impl.cpp index 739dff14..1b9322c5 100755 --- a/tooling/agent/target_impl.cpp +++ b/tooling/agent/target_impl.cpp @@ -21,17 +21,24 @@ namespace panda::ecmascript::tooling { void TargetImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "setAutoAttach", &TargetImpl::DispatcherImpl::SetAutoAttach }, - }; + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to TargetImpl"; + switch (method) { + case Method::SETAUTOATTACH: + SetAutoAttach(request); + break; + case Method::UNKNOWN: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(INFO) << "dispatch [" << method << "] to TargetImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); +TargetImpl::DispatcherImpl::Method TargetImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "setAutoAttach") { + return Method::SETAUTOATTACH; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/target_impl.h b/tooling/agent/target_impl.h index e5264fb0..31fef9cc 100755 --- a/tooling/agent/target_impl.h +++ b/tooling/agent/target_impl.h @@ -36,11 +36,16 @@ public: void SetAutoAttach(const DispatchRequest &request); void Dispatch(const DispatchRequest &request) override; + enum class Method { + SETAUTOATTACH, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (TargetImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr target_ {}; }; diff --git a/tooling/agent/tracing_impl.cpp b/tooling/agent/tracing_impl.cpp index 14b5ae00..88488235 100644 --- a/tooling/agent/tracing_impl.cpp +++ b/tooling/agent/tracing_impl.cpp @@ -23,21 +23,44 @@ namespace panda::ecmascript::tooling { void TracingImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "end", &TracingImpl::DispatcherImpl::End }, - { "getCategories", &TracingImpl::DispatcherImpl::GetCategories }, - { "recordClockSyncMarker", &TracingImpl::DispatcherImpl::RecordClockSyncMarker }, - { "requestMemoryDump", &TracingImpl::DispatcherImpl::RequestMemoryDump }, - { "start", &TracingImpl::DispatcherImpl::Start } - }; - - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to TracingImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(DEBUG) << "dispatch [" << request.GetMethod() << "] to TracingImpl"; + switch (method) { + case Method::END: + End(request); + break; + case Method::GETCATEGORIES: + GetCategories(request); + break; + case Method::RECORDCLOCKSYNCMARKER: + RecordClockSyncMarker(request); + break; + case Method::REQUESTMEMORYDUMP: + RequestMemoryDump(request); + break; + case Method::START: + Start(request); + break; + case Method::UNKNOWN: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} + +TracingImpl::DispatcherImpl::Method TracingImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "end") { + return Method::END; + } else if (method == "getCategories") { + return Method::GETCATEGORIES; + } else if (method == "recordClockSyncMarker") { + return Method::RECORDCLOCKSYNCMARKER; + } else if (method == "requestMemoryDump") { + return Method::REQUESTMEMORYDUMP; + } else if (method == "start") { + return Method::START; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/tracing_impl.h b/tooling/agent/tracing_impl.h index 3dcac215..f3e5df48 100644 --- a/tooling/agent/tracing_impl.h +++ b/tooling/agent/tracing_impl.h @@ -58,11 +58,20 @@ public: void RequestMemoryDump(const DispatchRequest &request); void Start(const DispatchRequest &request); + enum class Method { + END, + GETCATEGORIES, + RECORDCLOCKSYNCMARKER, + REQUESTMEMORYDUMP, + START, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (TracingImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr tracing_ {}; }; -- Gitee From b7037367f407a2ab45cac9f1d20282e718b44921 Mon Sep 17 00:00:00 2001 From: bergamot14 Date: Mon, 24 Jun 2024 20:46:03 +0300 Subject: [PATCH 06/51] Add fastverify mode Description: Add fastverify mode for build Testing: all tests passed Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IA7YUE Signed-off-by: Tokmakov Alexander Change-Id: Ie6866f02936f26b2694bb6b7a6a87f5f0e259ba7 --- BUILD.gn | 17 ++++++++++++++++- build/compile_script/ark.py | 6 ++++++ build/config/build_type.gni | 16 ++++++++++++++++ toolchain_config.gni | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 build/config/build_type.gni diff --git a/BUILD.gn b/BUILD.gn index 2b09e573..5d98ae83 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -94,6 +94,8 @@ config("ark_toolchain_common_config") { "-Wformat=2", ] + cflags_c = [] + if (is_linux) { defines += [ "PANDA_TARGET_UNIX", @@ -163,7 +165,20 @@ config("ark_toolchain_common_config") { ] } - if (is_debug) { + if (is_fastverify) { + cflags_cc += [ + "-O3", + "-ggdb3", + "-fno-omit-frame-pointer", + "-D_GLIBCXX_ASSERTIONS", + ] + cflags_c += [ + "-O3", + "-ggdb3", + "-fno-omit-frame-pointer", + "-D_GLIBCXX_ASSERTIONS", + ] + } else if (is_debug) { cflags_cc += [ "-O0", "-ggdb3", diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index ae11b1a4..e456f3bb 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -186,6 +186,12 @@ class ArkPy: "gn_args": ["is_debug=true"], "suffix_of_name_of_out_dir_of_second_level": "debug", }, + "fastverify": { + "flags": ["fastverify", "fv"], + "description": "Build for arkcompiler target(executables and libraries) for fastverify.", + "gn_args": ["is_debug=true is_fastverify=true"], + "suffix_of_name_of_out_dir_of_second_level": "fastverify", + }, }, "target": { "test262": { diff --git a/build/config/build_type.gni b/build/config/build_type.gni new file mode 100644 index 00000000..e45ecd07 --- /dev/null +++ b/build/config/build_type.gni @@ -0,0 +1,16 @@ +# 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. + +declare_args() { + is_fastverify = false +} diff --git a/toolchain_config.gni b/toolchain_config.gni index 501b4f8e..e02bd052 100644 --- a/toolchain_config.gni +++ b/toolchain_config.gni @@ -22,10 +22,12 @@ if (target_cpu == "arm64") { if (!ark_standalone_build) { build_root = "//build" ark_third_party_root = "//third_party" + import("$build_root/config/components/toolchain/build_type.gni") import("$build_root/ohos.gni") } else { ark_third_party_root = "//arkcompiler/toolchain/build/third_party_gn" import("$build_root/ark.gni") + import("$build_root/config/build_type.gni") } ark_root = "//arkcompiler/runtime_core" js_root = "//arkcompiler/ets_runtime" -- Gitee From dce5b39c4592f9be7c91026a135f584919410759 Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Mon, 15 Jul 2024 15:30:02 +0800 Subject: [PATCH 07/51] CFI adjustment and format modification 1.CFI adjustment for folder agent 2.Format alarm adjustment Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IABG22 Signed-off-by: swx1282997 --- tooling/agent/css_impl.cpp | 4 +- tooling/agent/css_impl.h | 2 +- tooling/agent/debugger_impl.cpp | 187 ++++++++++++++++++++++------ tooling/agent/debugger_impl.h | 34 ++++- tooling/agent/dom_impl.cpp | 4 +- tooling/agent/dom_impl.h | 2 +- tooling/agent/heapprofiler_impl.cpp | 42 +++---- tooling/agent/heapprofiler_impl.h | 20 +-- tooling/agent/overlay_impl.cpp | 2 +- tooling/agent/page_impl.cpp | 6 +- tooling/agent/page_impl.h | 2 +- tooling/agent/profiler_impl.cpp | 103 +++++++++++---- tooling/agent/profiler_impl.h | 20 ++- tooling/agent/runtime_impl.cpp | 14 +-- tooling/agent/runtime_impl.h | 6 +- tooling/agent/target_impl.cpp | 6 +- tooling/agent/target_impl.h | 2 +- tooling/agent/tracing_impl.cpp | 14 +-- tooling/agent/tracing_impl.h | 6 +- 19 files changed, 350 insertions(+), 126 deletions(-) diff --git a/tooling/agent/css_impl.cpp b/tooling/agent/css_impl.cpp index 251c5793..4d66b791 100755 --- a/tooling/agent/css_impl.cpp +++ b/tooling/agent/css_impl.cpp @@ -27,7 +27,7 @@ void CssImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) case Method::DISABLE: Disable(request); break; - case Method::UNKNWON: + default: SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); break; } @@ -38,7 +38,7 @@ CssImpl::DispatcherImpl::Method CssImpl::DispatcherImpl::GetMethodEnum(const std if (method == "disable") { return Method::DISABLE; } else { - return Method::UNKNWON; + return Method::UNKNOWN; } } diff --git a/tooling/agent/css_impl.h b/tooling/agent/css_impl.h index af2e8d1f..c85f612e 100755 --- a/tooling/agent/css_impl.h +++ b/tooling/agent/css_impl.h @@ -38,7 +38,7 @@ public: enum class Method { DISABLE, - UNKNWON + UNKNOWN }; Method GetMethodEnum(const std::string& method); diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index 8c54f22e..b188ccb5 100644 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -388,44 +388,159 @@ void DebuggerImpl::InitializeExtendedProtocolsList() void DebuggerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "continueToLocation", &DebuggerImpl::DispatcherImpl::ContinueToLocation }, - { "enable", &DebuggerImpl::DispatcherImpl::Enable }, - { "disable", &DebuggerImpl::DispatcherImpl::Disable }, - { "evaluateOnCallFrame", &DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame }, - { "getPossibleBreakpoints", &DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints }, - { "getScriptSource", &DebuggerImpl::DispatcherImpl::GetScriptSource }, - { "pause", &DebuggerImpl::DispatcherImpl::Pause }, - { "removeBreakpoint", &DebuggerImpl::DispatcherImpl::RemoveBreakpoint }, - { "removeBreakpointsByUrl", &DebuggerImpl::DispatcherImpl::RemoveBreakpointsByUrl }, - { "resume", &DebuggerImpl::DispatcherImpl::Resume }, - { "setAsyncCallStackDepth", &DebuggerImpl::DispatcherImpl::SetAsyncCallStackDepth }, - { "setBreakpointByUrl", &DebuggerImpl::DispatcherImpl::SetBreakpointByUrl }, - { "setBreakpointsActive", &DebuggerImpl::DispatcherImpl::SetBreakpointsActive }, - { "setPauseOnExceptions", &DebuggerImpl::DispatcherImpl::SetPauseOnExceptions }, - { "setSkipAllPauses", &DebuggerImpl::DispatcherImpl::SetSkipAllPauses }, - { "stepInto", &DebuggerImpl::DispatcherImpl::StepInto }, - { "smartStepInto", &DebuggerImpl::DispatcherImpl::SmartStepInto}, - { "stepOut", &DebuggerImpl::DispatcherImpl::StepOut }, - { "stepOver", &DebuggerImpl::DispatcherImpl::StepOver }, - { "setMixedDebugEnabled", &DebuggerImpl::DispatcherImpl::SetMixedDebugEnabled }, - { "setBlackboxPatterns", &DebuggerImpl::DispatcherImpl::SetBlackboxPatterns }, - { "replyNativeCalling", &DebuggerImpl::DispatcherImpl::ReplyNativeCalling }, - { "getPossibleAndSetBreakpointByUrl", &DebuggerImpl::DispatcherImpl::GetPossibleAndSetBreakpointByUrl }, - { "dropFrame", &DebuggerImpl::DispatcherImpl::DropFrame }, - { "setNativeRange", &DebuggerImpl::DispatcherImpl::SetNativeRange }, - { "resetSingleStepper", &DebuggerImpl::DispatcherImpl::ResetSingleStepper }, - { "clientDisconnect", &DebuggerImpl::DispatcherImpl::ClientDisconnect }, - { "callFunctionOn", &DebuggerImpl::DispatcherImpl::CallFunctionOn } - }; + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(DEBUG) << "dispatch [" << request.GetMethod() << "] to DebuggerImpl"; + switch (method) { + case Method::CONTINUE_TO_LOCATION: + ContinueToLocation(request); + break; + case Method::ENABLE: + Enable(request); + break; + case Method::DISABLE: + Disable(request); + break; + case Method::EVALUATE_ON_CALL_FRAME: + EvaluateOnCallFrame(request); + break; + case Method::GET_POSSIBLE_BREAKPOINTS: + GetPossibleBreakpoints(request); + break; + case Method::GET_SCRIPT_SOURCE: + GetScriptSource(request); + break; + case Method::PAUSE: + Pause(request); + break; + case Method::REMOVE_BREAKPOINT: + RemoveBreakpoint(request); + break; + case Method::REMOVE_BREAKPOINTS_BY_URL: + RemoveBreakpointsByUrl(request); + break; + case Method::RESUME: + Resume(request); + break; + case Method::SET_ASYNC_CALL_STACK_DEPTH: + SetAsyncCallStackDepth(request); + break; + case Method::SET_BREAKPOINT_BY_URL: + SetBreakpointByUrl(request); + break; + case Method::SET_BREAKPOINTS_ACTIVE: + SetBreakpointsActive(request); + break; + case Method::SET_PAUSE_ON_EXCEPTIONS: + SetPauseOnExceptions(request); + break; + case Method::SET_SKIP_ALL_PAUSES: + SetSkipAllPauses(request); + break; + case Method::STEP_INTO: + StepInto(request); + break; + case Method::SMART_STEP_INTO: + SmartStepInto(request); + break; + case Method::STEP_OUT: + StepOut(request); + break; + case Method::STEP_OVER: + StepOver(request); + break; + case Method::SET_MIXED_DEBUG_ENABLED: + SetMixedDebugEnabled(request); + break; + case Method::SET_BLACKBOX_PATTERNS: + SetBlackboxPatterns(request); + break; + case Method::REPLY_NATIVE_CALLING: + ReplyNativeCalling(request); + break; + case Method::GET_POSSIBLE_AND_SET_BREAKPOINT_BY_URL: + GetPossibleAndSetBreakpointByUrl(request); + break; + case Method::DROP_FRAME: + DropFrame(request); + break; + case Method::SET_NATIVE_RANGE: + SetNativeRange(request); + break; + case Method::RESET_SINGLE_STEPPER: + ResetSingleStepper(request); + break; + case Method::CLIENT_DISCONNECT: + ClientDisconnect(request); + break; + case Method::CALL_FUNCTION_ON: + CallFunctionOn(request); + break; + default: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to DebuggerImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); +DebuggerImpl::DispatcherImpl::Method DebuggerImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "continueToLocation") { + return Method::CONTINUE_TO_LOCATION; + } else if (method == "enable") { + return Method::ENABLE; + } else if (method == "disable") { + return Method::DISABLE; + } else if (method == "evaluateOnCallFrame") { + return Method::EVALUATE_ON_CALL_FRAME; + } else if (method == "getPossibleBreakpoints") { + return Method::GET_POSSIBLE_BREAKPOINTS; + } else if (method == "getScriptSource") { + return Method::GET_SCRIPT_SOURCE; + } else if (method == "pause") { + return Method::PAUSE; + } else if (method == "removeBreakpoint") { + return Method::REMOVE_BREAKPOINT; + } else if (method == "removeBreakpointsByUrl") { + return Method::REMOVE_BREAKPOINTS_BY_URL; + } else if (method == "resume") { + return Method::RESUME; + } else if (method == "setAsyncCallStackDepth") { + return Method::SET_ASYNC_CALL_STACK_DEPTH; + } else if (method == "setBreakpointByUrl") { + return Method::SET_BREAKPOINT_BY_URL; + } else if (method == "setBreakpointsActive") { + return Method::SET_BREAKPOINTS_ACTIVE; + } else if (method == "setPauseOnExceptions") { + return Method::SET_PAUSE_ON_EXCEPTIONS; + } else if (method == "setSkipAllPauses") { + return Method::SET_SKIP_ALL_PAUSES; + } else if (method == "stepInto") { + return Method::STEP_INTO; + } else if (method == "smartStepInto") { + return Method::SMART_STEP_INTO; + } else if (method == "stepOut") { + return Method::STEP_OUT; + } else if (method == "stepOver") { + return Method::STEP_OVER; + } else if (method == "setMixedDebugEnabled") { + return Method::SET_MIXED_DEBUG_ENABLED; + } else if (method == "setBlackboxPatterns") { + return Method::SET_BLACKBOX_PATTERNS; + } else if (method == "replyNativeCalling") { + return Method::REPLY_NATIVE_CALLING; + } else if (method == "getPossibleAndSetBreakpointByUrl") { + return Method::GET_POSSIBLE_AND_SET_BREAKPOINT_BY_URL; + } else if (method == "dropFrame") { + return Method::DROP_FRAME; + } else if (method == "setNativeRange") { + return Method::SET_NATIVE_RANGE; + } else if (method == "resetSingleStepper") { + return Method::RESET_SINGLE_STEPPER; + } else if (method == "clientDisconnect") { + return Method::CLIENT_DISCONNECT; + } else if (method == "callFunctionOn") { + return Method::CALL_FUNCTION_ON; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index 72248c90..40186259 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -184,11 +184,43 @@ public: void ClientDisconnect(const DispatchRequest &request); void CallFunctionOn(const DispatchRequest &request); + enum class Method { + CONTINUE_TO_LOCATION, + ENABLE, + DISABLE, + EVALUATE_ON_CALL_FRAME, + GET_POSSIBLE_BREAKPOINTS, + GET_SCRIPT_SOURCE, + PAUSE, + REMOVE_BREAKPOINT, + REMOVE_BREAKPOINTS_BY_URL, + RESUME, + SET_ASYNC_CALL_STACK_DEPTH, + SET_BREAKPOINT_BY_URL, + SET_BREAKPOINTS_ACTIVE, + SET_PAUSE_ON_EXCEPTIONS, + SET_SKIP_ALL_PAUSES, + STEP_INTO, + SMART_STEP_INTO, + STEP_OUT, + STEP_OVER, + SET_MIXED_DEBUG_ENABLED, + SET_BLACKBOX_PATTERNS, + REPLY_NATIVE_CALLING, + GET_POSSIBLE_AND_SET_BREAKPOINT_BY_URL, + DROP_FRAME, + SET_NATIVE_RANGE, + RESET_SINGLE_STEPPER, + CLIENT_DISCONNECT, + CALL_FUNCTION_ON, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (DebuggerImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr debugger_ {}; }; diff --git a/tooling/agent/dom_impl.cpp b/tooling/agent/dom_impl.cpp index 89218ee3..8889d791 100755 --- a/tooling/agent/dom_impl.cpp +++ b/tooling/agent/dom_impl.cpp @@ -27,7 +27,7 @@ void DomImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) case Method::DISABLE: Disable(request); break; - case Method::UNKNWON: + default: SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); break; } @@ -38,7 +38,7 @@ DomImpl::DispatcherImpl::Method DomImpl::DispatcherImpl::GetMethodEnum(const std if (method == "disable") { return Method::DISABLE; } else { - return Method::UNKNWON; + return Method::UNKNOWN; } } diff --git a/tooling/agent/dom_impl.h b/tooling/agent/dom_impl.h index 4e81b532..921071aa 100755 --- a/tooling/agent/dom_impl.h +++ b/tooling/agent/dom_impl.h @@ -38,7 +38,7 @@ public: enum class Method { DISABLE, - UNKNWON + UNKNOWN }; Method GetMethodEnum(const std::string& method); diff --git a/tooling/agent/heapprofiler_impl.cpp b/tooling/agent/heapprofiler_impl.cpp index 68cd3b21..8774aeeb 100644 --- a/tooling/agent/heapprofiler_impl.cpp +++ b/tooling/agent/heapprofiler_impl.cpp @@ -31,10 +31,10 @@ void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) Method method = GetMethodEnum(request.GetMethod()); LOG_DEBUGGER(DEBUG) << "dispatch [" << request.GetMethod() << "] to HeapProfilerImpl"; switch (method) { - case Method::ADDINSPECTEDHEAPOBJECT: + case Method::ADD_INSPECTED_HEAP_OBJECT: AddInspectedHeapObject(request); break; - case Method::COLLECTGARBAGE: + case Method::COLLECT_GARBAGE: CollectGarbage(request); break; case Method::ENABLE: @@ -43,31 +43,31 @@ void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) case Method::DISABLE: Disable(request); break; - case Method::GETHEAPOBJECTID: + case Method::GET_HEAP_OBJECT_ID: GetHeapObjectId(request); break; - case Method::GETOBJECTBYHEAPOBJECTID: + case Method::GET_OBJECT_BY_HEAP_OBJECT_ID: GetObjectByHeapObjectId(request); break; - case Method::GETSAMPLINGPROFILE: + case Method::GET_SAMPLING_PROFILE: GetSamplingProfile(request); break; - case Method::STARTSAMPLING: + case Method::START_SAMPLING: StartSampling(request); break; - case Method::STARTTRACKINGHEAPOBJECTS: + case Method::START_TRACKING_HEAP_OBJECTS: StartTrackingHeapObjects(request); break; - case Method::STOPSAMPLING: + case Method::STOP_SAMPLING: StopSampling(request); break; - case Method::STOPTRACKINGHEAPOBJECTS: + case Method::STOP_TRACKING_HEAP_OBJECTS: StopTrackingHeapObjects(request); break; - case Method::TAKEHEAPSNAPSHOT: + case Method::TAKE_HEAP_SNAPSHOT: TakeHeapSnapshot(request); break; - case Method::UNKNOWN: + default: SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); break; } @@ -76,29 +76,29 @@ void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) HeapProfilerImpl::DispatcherImpl::Method HeapProfilerImpl::DispatcherImpl::GetMethodEnum(const std::string& method) { if (method == "addInspectedHeapObject") { - return Method::ADDINSPECTEDHEAPOBJECT; + return Method::ADD_INSPECTED_HEAP_OBJECT; } else if (method == "collectGarbage") { - return Method::COLLECTGARBAGE; + return Method::COLLECT_GARBAGE; } else if (method == "enable") { return Method::ENABLE; } else if (method == "disable") { return Method::DISABLE; } else if (method == "getHeapObjectId") { - return Method::GETHEAPOBJECTID; + return Method::GET_HEAP_OBJECT_ID; } else if (method == "getObjectByHeapObjectId") { - return Method::GETOBJECTBYHEAPOBJECTID; + return Method::GET_OBJECT_BY_HEAP_OBJECT_ID; } else if (method == "getSamplingProfile") { - return Method::GETSAMPLINGPROFILE; + return Method::GET_SAMPLING_PROFILE; } else if (method == "startSampling") { - return Method::STARTSAMPLING; + return Method::START_SAMPLING; } else if (method == "startTrackingHeapObjects") { - return Method::STARTTRACKINGHEAPOBJECTS; + return Method::START_TRACKING_HEAP_OBJECTS; } else if (method == "stopSampling") { - return Method::STOPSAMPLING; + return Method::STOP_SAMPLING; } else if (method == "stopTrackingHeapObjects") { - return Method::STOPTRACKINGHEAPOBJECTS; + return Method::STOP_TRACKING_HEAP_OBJECTS; } else if (method == "takeHeapSnapshot") { - return Method::TAKEHEAPSNAPSHOT; + return Method::TAKE_HEAP_SNAPSHOT; } else { return Method::UNKNOWN; } diff --git a/tooling/agent/heapprofiler_impl.h b/tooling/agent/heapprofiler_impl.h index 839490fe..c8b5f2f7 100644 --- a/tooling/agent/heapprofiler_impl.h +++ b/tooling/agent/heapprofiler_impl.h @@ -80,18 +80,18 @@ public: void TakeHeapSnapshot(const DispatchRequest &request); enum class Method { - ADDINSPECTEDHEAPOBJECT, - COLLECTGARBAGE, + ADD_INSPECTED_HEAP_OBJECT, + COLLECT_GARBAGE, ENABLE, DISABLE, - GETHEAPOBJECTID, - GETOBJECTBYHEAPOBJECTID, - GETSAMPLINGPROFILE, - STARTSAMPLING, - STARTTRACKINGHEAPOBJECTS, - STOPSAMPLING, - STOPTRACKINGHEAPOBJECTS, - TAKEHEAPSNAPSHOT, + GET_HEAP_OBJECT_ID, + GET_OBJECT_BY_HEAP_OBJECT_ID, + GET_SAMPLING_PROFILE, + START_SAMPLING, + START_TRACKING_HEAP_OBJECTS, + STOP_SAMPLING, + STOP_TRACKING_HEAP_OBJECTS, + TAKE_HEAP_SNAPSHOT, UNKNOWN }; Method GetMethodEnum(const std::string& method); diff --git a/tooling/agent/overlay_impl.cpp b/tooling/agent/overlay_impl.cpp index a936396f..f7eb48aa 100755 --- a/tooling/agent/overlay_impl.cpp +++ b/tooling/agent/overlay_impl.cpp @@ -29,7 +29,7 @@ void OverlayImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) case Method::DISABLE: Disable(request); break; - case Method::UNKNOWN: + default: SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); break; } diff --git a/tooling/agent/page_impl.cpp b/tooling/agent/page_impl.cpp index 203ae8ce..db006ba0 100755 --- a/tooling/agent/page_impl.cpp +++ b/tooling/agent/page_impl.cpp @@ -24,10 +24,10 @@ void PageImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) Method method = GetMethodEnum(request.GetMethod()); LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to PageImpl"; switch (method) { - case Method::GETNAVIGATIONHISTORY: + case Method::GET_NAVIGATION_HISTORY: GetNavigationHistory(request); break; - case Method::UNKNOWN: + default: SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); break; } @@ -36,7 +36,7 @@ void PageImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) PageImpl::DispatcherImpl::Method PageImpl::DispatcherImpl::GetMethodEnum(const std::string& method) { if (method == "getNavigationHistory") { - return Method::GETNAVIGATIONHISTORY; + return Method::GET_NAVIGATION_HISTORY; } else { return Method::UNKNOWN; } diff --git a/tooling/agent/page_impl.h b/tooling/agent/page_impl.h index 1a7dd198..6e8ad7f4 100755 --- a/tooling/agent/page_impl.h +++ b/tooling/agent/page_impl.h @@ -37,7 +37,7 @@ public: void Dispatch(const DispatchRequest &request) override; enum class Method { - GETNAVIGATIONHISTORY, + GET_NAVIGATION_HISTORY, UNKNOWN }; Method GetMethodEnum(const std::string& method); diff --git a/tooling/agent/profiler_impl.cpp b/tooling/agent/profiler_impl.cpp index 95e71d2e..6d1575f9 100644 --- a/tooling/agent/profiler_impl.cpp +++ b/tooling/agent/profiler_impl.cpp @@ -38,30 +38,89 @@ void ProfilerImpl::InitializeExtendedProtocolsList() void ProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { - static std::unordered_map dispatcherTable { - { "disable", &ProfilerImpl::DispatcherImpl::Disable }, - { "enable", &ProfilerImpl::DispatcherImpl::Enable }, - { "start", &ProfilerImpl::DispatcherImpl::Start }, - { "stop", &ProfilerImpl::DispatcherImpl::Stop }, - { "setSamplingInterval", &ProfilerImpl::DispatcherImpl::SetSamplingInterval }, - { "getBestEffortCoverage", &ProfilerImpl::DispatcherImpl::GetBestEffortCoverage }, - { "stopPreciseCoverage", &ProfilerImpl::DispatcherImpl::StopPreciseCoverage }, - { "takePreciseCoverage", &ProfilerImpl::DispatcherImpl::TakePreciseCoverage }, - { "startPreciseCoverage", &ProfilerImpl::DispatcherImpl::StartPreciseCoverage }, - { "startTypeProfile", &ProfilerImpl::DispatcherImpl::StartTypeProfile }, - { "stopTypeProfile", &ProfilerImpl::DispatcherImpl::StopTypeProfile }, - { "takeTypeProfile", &ProfilerImpl::DispatcherImpl::TakeTypeProfile }, - { "enableSerializationTimeoutCheck", &ProfilerImpl::DispatcherImpl::EnableSerializationTimeoutCheck }, - { "disableSerializationTimeoutCheck", &ProfilerImpl::DispatcherImpl::DisableSerializationTimeoutCheck } - }; + Method method = GetMethodEnum(request.GetMethod()); + LOG_DEBUGGER(DEBUG) << "dispatch [" << request.GetMethod() << "] to ProfilerImpl"; + switch (method) { + case Method::DISABLE: + Disable(request); + break; + case Method::ENABLE: + Enable(request); + break; + case Method::START: + Start(request); + break; + case Method::STOP: + Stop(request); + break; + case Method::SET_SAMPLING_INTERVAL: + SetSamplingInterval(request); + break; + case Method::GET_BEST_EFFORT_COVERAGE: + GetBestEffortCoverage(request); + break; + case Method::STOP_PRECISE_COVERAGE: + StopPreciseCoverage(request); + break; + case Method::TAKE_PRECISE_COVERAGE: + TakePreciseCoverage(request); + break; + case Method::START_PRECISE_COVERAGE: + StartPreciseCoverage(request); + break; + case Method::START_TYPE_PROFILE: + StartTypeProfile(request); + break; + case Method::STOP_TYPE_PROFILE: + StopTypeProfile(request); + break; + case Method::TAKE_TYPE_PROFILE: + TakeTypeProfile(request); + break; + case Method::ENABLE_SERIALIZATION_TIMEOUT_CHECK: + EnableSerializationTimeoutCheck(request); + break; + case Method::DISABLE_SERIALIZATION_TIMEOUT_CHECK: + DisableSerializationTimeoutCheck(request); + break; + default: + SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); + break; + } +} - const std::string &method = request.GetMethod(); - LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to ProfilerImpl"; - auto entry = dispatcherTable.find(method); - if (entry != dispatcherTable.end() && entry->second != nullptr) { - (this->*(entry->second))(request); +ProfilerImpl::DispatcherImpl::Method ProfilerImpl::DispatcherImpl::GetMethodEnum(const std::string& method) +{ + if (method == "disable") { + return Method::DISABLE; + } else if (method == "enable") { + return Method::ENABLE; + } else if (method == "start") { + return Method::START; + } else if (method == "stop") { + return Method::STOP; + } else if (method == "setSamplingInterval") { + return Method::SET_SAMPLING_INTERVAL; + } else if (method == "getBestEffortCoverage") { + return Method::GET_BEST_EFFORT_COVERAGE; + } else if (method == "stopPreciseCoverage") { + return Method::STOP_PRECISE_COVERAGE; + } else if (method == "takePreciseCoverage") { + return Method::TAKE_PRECISE_COVERAGE; + } else if (method == "startPreciseCoverage") { + return Method::START_PRECISE_COVERAGE; + } else if (method == "startTypeProfile") { + return Method::START_TYPE_PROFILE; + } else if (method == "stopTypeProfile") { + return Method::STOP_TYPE_PROFILE; + } else if (method == "takeTypeProfile") { + return Method::TAKE_TYPE_PROFILE; + } else if (method == "enableSerializationTimeoutCheck") { + return Method::ENABLE_SERIALIZATION_TIMEOUT_CHECK; + } else if (method == "disableSerializationTimeoutCheck") { + return Method::DISABLE_SERIALIZATION_TIMEOUT_CHECK; } else { - SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + return Method::UNKNOWN; } } diff --git a/tooling/agent/profiler_impl.h b/tooling/agent/profiler_impl.h index 770e44ce..e953baca 100644 --- a/tooling/agent/profiler_impl.h +++ b/tooling/agent/profiler_impl.h @@ -66,11 +66,29 @@ public: void EnableSerializationTimeoutCheck(const DispatchRequest &request); void DisableSerializationTimeoutCheck(const DispatchRequest &request); + enum class Method { + DISABLE, + ENABLE, + START, + STOP, + SET_SAMPLING_INTERVAL, + GET_BEST_EFFORT_COVERAGE, + STOP_PRECISE_COVERAGE, + TAKE_PRECISE_COVERAGE, + START_PRECISE_COVERAGE, + START_TYPE_PROFILE, + STOP_TYPE_PROFILE, + TAKE_TYPE_PROFILE, + ENABLE_SERIALIZATION_TIMEOUT_CHECK, + DISABLE_SERIALIZATION_TIMEOUT_CHECK, + UNKNOWN + }; + Method GetMethodEnum(const std::string& method); + private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); - using AgentHandler = void (ProfilerImpl::DispatcherImpl::*)(const DispatchRequest &request); std::unique_ptr profiler_ {}; }; diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index 1d7f8553..94f8ad84 100644 --- a/tooling/agent/runtime_impl.cpp +++ b/tooling/agent/runtime_impl.cpp @@ -42,16 +42,16 @@ void RuntimeImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) case Method::DISABLE: Disable(request); break; - case Method::GETPROPERTIES: + case Method::GET_PROPERTIES: GetProperties(request); break; - case Method::RUNIFWAITINGFORDEBUGGER: + case Method::RUN_IF_WAITING_FOR_DEBUGGER: RunIfWaitingForDebugger(request); break; - case Method::GETHEAPUSAGE: + case Method::GET_HEAP_USAGE: GetHeapUsage(request); break; - case Method::UNKNOWN: + default: SendResponse(request, DispatchResponse::Fail("unknown method: " + request.GetMethod())); break; } @@ -64,11 +64,11 @@ RuntimeImpl::DispatcherImpl::Method RuntimeImpl::DispatcherImpl::GetMethodEnum(c } else if (method == "disable") { return Method::DISABLE; } else if (method == "getProperties") { - return Method::GETPROPERTIES; + return Method::GET_PROPERTIES; } else if (method == "runIfWaitingForDebugger") { - return Method::RUNIFWAITINGFORDEBUGGER; + return Method::RUN_IF_WAITING_FOR_DEBUGGER; } else if (method == "getHeapUsage") { - return Method::GETHEAPUSAGE; + return Method::GET_HEAP_USAGE; } else { return Method::UNKNOWN; } diff --git a/tooling/agent/runtime_impl.h b/tooling/agent/runtime_impl.h index e7b67a4b..b4b86ae1 100644 --- a/tooling/agent/runtime_impl.h +++ b/tooling/agent/runtime_impl.h @@ -56,9 +56,9 @@ public: enum class Method { ENABLE, DISABLE, - GETPROPERTIES, - RUNIFWAITINGFORDEBUGGER, - GETHEAPUSAGE, + GET_PROPERTIES, + RUN_IF_WAITING_FOR_DEBUGGER, + GET_HEAP_USAGE, UNKNOWN }; Method GetMethodEnum(const std::string& method); diff --git a/tooling/agent/target_impl.cpp b/tooling/agent/target_impl.cpp index 1b9322c5..a84bc0b3 100755 --- a/tooling/agent/target_impl.cpp +++ b/tooling/agent/target_impl.cpp @@ -24,10 +24,10 @@ void TargetImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) Method method = GetMethodEnum(request.GetMethod()); LOG_DEBUGGER(INFO) << "dispatch [" << request.GetMethod() << "] to TargetImpl"; switch (method) { - case Method::SETAUTOATTACH: + case Method::SET_AUTO_ATTACH: SetAutoAttach(request); break; - case Method::UNKNOWN: + default: SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); break; } @@ -36,7 +36,7 @@ void TargetImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) TargetImpl::DispatcherImpl::Method TargetImpl::DispatcherImpl::GetMethodEnum(const std::string& method) { if (method == "setAutoAttach") { - return Method::SETAUTOATTACH; + return Method::SET_AUTO_ATTACH; } else { return Method::UNKNOWN; } diff --git a/tooling/agent/target_impl.h b/tooling/agent/target_impl.h index 31fef9cc..87cbd98c 100755 --- a/tooling/agent/target_impl.h +++ b/tooling/agent/target_impl.h @@ -37,7 +37,7 @@ public: void Dispatch(const DispatchRequest &request) override; enum class Method { - SETAUTOATTACH, + SET_AUTO_ATTACH, UNKNOWN }; Method GetMethodEnum(const std::string& method); diff --git a/tooling/agent/tracing_impl.cpp b/tooling/agent/tracing_impl.cpp index 88488235..ec418201 100644 --- a/tooling/agent/tracing_impl.cpp +++ b/tooling/agent/tracing_impl.cpp @@ -29,19 +29,19 @@ void TracingImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) case Method::END: End(request); break; - case Method::GETCATEGORIES: + case Method::GET_CATEGORIES: GetCategories(request); break; - case Method::RECORDCLOCKSYNCMARKER: + case Method::RECORD_CLOCK_SYNC_MARKER: RecordClockSyncMarker(request); break; - case Method::REQUESTMEMORYDUMP: + case Method::REQUEST_MEMORY_DUMP: RequestMemoryDump(request); break; case Method::START: Start(request); break; - case Method::UNKNOWN: + default: SendResponse(request, DispatchResponse::Fail("Unknown method: " + request.GetMethod())); break; } @@ -52,11 +52,11 @@ TracingImpl::DispatcherImpl::Method TracingImpl::DispatcherImpl::GetMethodEnum(c if (method == "end") { return Method::END; } else if (method == "getCategories") { - return Method::GETCATEGORIES; + return Method::GET_CATEGORIES; } else if (method == "recordClockSyncMarker") { - return Method::RECORDCLOCKSYNCMARKER; + return Method::RECORD_CLOCK_SYNC_MARKER; } else if (method == "requestMemoryDump") { - return Method::REQUESTMEMORYDUMP; + return Method::REQUEST_MEMORY_DUMP; } else if (method == "start") { return Method::START; } else { diff --git a/tooling/agent/tracing_impl.h b/tooling/agent/tracing_impl.h index f3e5df48..b79cf8ce 100644 --- a/tooling/agent/tracing_impl.h +++ b/tooling/agent/tracing_impl.h @@ -60,9 +60,9 @@ public: enum class Method { END, - GETCATEGORIES, - RECORDCLOCKSYNCMARKER, - REQUESTMEMORYDUMP, + GET_CATEGORIES, + RECORD_CLOCK_SYNC_MARKER, + REQUEST_MEMORY_DUMP, START, UNKNOWN }; -- Gitee From 296679475f2c7050d16222d624f5e840481c9426 Mon Sep 17 00:00:00 2001 From: bigtea Date: Tue, 16 Jul 2024 20:13:48 +0800 Subject: [PATCH 08/51] Disable some testcases Issue: IADFP3 Signed-off-by: bigtea --- tooling/test/debugger_cint_client_test.cpp | 2 +- websocket/test/websocket_test.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tooling/test/debugger_cint_client_test.cpp b/tooling/test/debugger_cint_client_test.cpp index c56746cc..5d125a13 100644 --- a/tooling/test/debugger_cint_client_test.cpp +++ b/tooling/test/debugger_cint_client_test.cpp @@ -64,7 +64,7 @@ public: JSThread *thread {nullptr}; }; -HWTEST_P_L0(DebuggerCIntClientTest, DebuggerSuite) +HWTEST_P_L0(DebuggerCIntClientTest, DISABLED_DebuggerSuite) { std::string testName = GetCurrentTestName(); std::cout << "Running " << testName << std::endl; diff --git a/websocket/test/websocket_test.cpp b/websocket/test/websocket_test.cpp index c97017a9..9ff86380 100644 --- a/websocket/test/websocket_test.cpp +++ b/websocket/test/websocket_test.cpp @@ -65,7 +65,7 @@ public: const std::string WebSocketTest::LONG_MSG = std::string(1000, 'f'); const std::string WebSocketTest::LONG_LONG_MSG = std::string(0xfffff, 'f'); -HWTEST_F(WebSocketTest, ConnectWebSocketTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, DISABLED_ConnectWebSocketTest, testing::ext::TestSize.Level0) { WebSocketServer serverSocket; bool ret = false; @@ -162,7 +162,7 @@ HWTEST_F(WebSocketTest, ConnectWebSocketTest, testing::ext::TestSize.Level0) } } -HWTEST_F(WebSocketTest, ReConnectWebSocketTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, DISABLED_ReConnectWebSocketTest, testing::ext::TestSize.Level0) { WebSocketServer serverSocket; bool ret = false; @@ -221,7 +221,7 @@ HWTEST_F(WebSocketTest, ReConnectWebSocketTest, testing::ext::TestSize.Level0) serverSocket.Close(); } -HWTEST_F(WebSocketTest, ClientAbnormalTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, DISABLED_ClientAbnormalTest, testing::ext::TestSize.Level0) { WebSocketClient clientSocket; ASSERT_STREQ(clientSocket.GetSocketStateString().c_str(), "uninited"); @@ -230,7 +230,7 @@ HWTEST_F(WebSocketTest, ClientAbnormalTest, testing::ext::TestSize.Level0) ASSERT_FALSE(clientSocket.SendReply(HELLO_SERVER)); } -HWTEST_F(WebSocketTest, ServerAbnormalTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, DISABLED_ServerAbnormalTest, testing::ext::TestSize.Level0) { WebSocketServer serverSocket; // No connection established, the function returns directly. -- Gitee From 5632a0d082780200375eda495cb978c0b84bd717 Mon Sep 17 00:00:00 2001 From: daiweihao Date: Mon, 15 Jul 2024 20:51:41 +0800 Subject: [PATCH 09/51] Fix cpuprofile and infos bug When executing the cpupprofile and infosource commands, if the information sent by the server is missing the 'method', it will cause the client to return an exception when parsing the message information. In the current logic, it is allowed that there is no 'method' in the message, so the judgment logic that returns when 'method' is empty is deleted. Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAD5Y9 Signed-off-by: daiweihao Change-Id: I149af37ea1352cb47cac9ac2aea1ff304aaaf832 --- tooling/client/manager/domain_manager.cpp | 7 +++---- tooling/dispatcher.cpp | 6 +----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/tooling/client/manager/domain_manager.cpp b/tooling/client/manager/domain_manager.cpp index d9d1cdaf..16981052 100644 --- a/tooling/client/manager/domain_manager.cpp +++ b/tooling/client/manager/domain_manager.cpp @@ -55,12 +55,11 @@ void DomainManager::DispatcherReply(char* msg) std::string wholeMethod; ret = json->GetString("method", &wholeMethod); - if (wholeMethod.empty()) { - LOGE("find method empty"); - return; - } if (ret == Result::SUCCESS) { std::string::size_type length = wholeMethod.length(); + if (length == 0) { + return; + } std::string::size_type indexPoint = 0; indexPoint = wholeMethod.find_first_of('.', 0); if (indexPoint == std::string::npos || indexPoint == 0 || indexPoint == length - 1) { diff --git a/tooling/dispatcher.cpp b/tooling/dispatcher.cpp index 7e14dc8c..b83d8ae6 100644 --- a/tooling/dispatcher.cpp +++ b/tooling/dispatcher.cpp @@ -56,15 +56,11 @@ DispatchRequest::DispatchRequest(const std::string &message) std::string wholeMethod; ret = json->GetString("method", &wholeMethod); - if (ret != Result::SUCCESS) { + if (ret != Result::SUCCESS || wholeMethod.empty()) { code_ = RequestCode::PARSE_METHOD_ERROR; LOG_DEBUGGER(ERROR) << "parse method error"; return; } - if (wholeMethod.empty()) { - LOG_DEBUGGER(ERROR) << "find method empty"; - return; - } std::string::size_type length = wholeMethod.length(); std::string::size_type indexPoint = wholeMethod.find_first_of('.', 0); if (indexPoint == std::string::npos || indexPoint == 0 || indexPoint == length - 1) { -- Gitee From a1c8f6870acb543975444706d323aae878fc036d Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Wed, 17 Jul 2024 14:57:58 +0800 Subject: [PATCH 10/51] Alarm repair 1.Empty pointer alarm in file variable_manager.cpp 2.Format alarm Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IABEKI Signed-off-by: swx1282997 --- tooling/agent/heapprofiler_impl.h | 2 +- tooling/base/pt_types.cpp | 4 ++-- tooling/client/manager/variable_manager.cpp | 10 +++++----- tooling/client/tcpServer/test/js_test_base.py | 8 ++++---- tooling/client/tcpServer/test/js_test_case/js_test.py | 4 ++-- tooling/client/tcpServer/test/runtest.py | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tooling/agent/heapprofiler_impl.h b/tooling/agent/heapprofiler_impl.h index c8b5f2f7..b3cd4695 100644 --- a/tooling/agent/heapprofiler_impl.h +++ b/tooling/agent/heapprofiler_impl.h @@ -132,7 +132,7 @@ private: void EndOfStream() override {} int GetSize() override { - static const int heapProfilerChunkSise = 100_KB; + static const int heapProfilerChunkSise = static_cast(100_KB); return heapProfilerChunkSise; } bool WriteChunk(char *data, int32_t size) override diff --git a/tooling/base/pt_types.cpp b/tooling/base/pt_types.cpp index c3d883c4..9d1fb795 100644 --- a/tooling/base/pt_types.cpp +++ b/tooling/base/pt_types.cpp @@ -784,14 +784,14 @@ std::string ObjectRemoteObject::DescriptionForInt8Array(const EcmaVM *ecmaVm, Lo std::string ObjectRemoteObject::DescriptionForInt16Array(const EcmaVM *ecmaVm, Local tagged) { - int32_t len = tagged->ByteLength(ecmaVm) / static_cast(NumberSize::BYTES_OF_16BITS); + uint32_t len = tagged->ByteLength(ecmaVm) / NumberSize::BYTES_OF_16BITS; std::string description = ("Int16Array(" + std::to_string(len) + ")"); return description; } std::string ObjectRemoteObject::DescriptionForInt32Array(const EcmaVM *ecmaVm, Local tagged) { - int32_t len = tagged->ByteLength(ecmaVm) / static_cast(NumberSize::BYTES_OF_32BITS); + uint32_t len = tagged->ByteLength(ecmaVm) / NumberSize::BYTES_OF_32BITS; std::string description = ("Int32Array(" + std::to_string(len) + ")"); return description; } diff --git a/tooling/client/manager/variable_manager.cpp b/tooling/client/manager/variable_manager.cpp index 38e3b259..f7b7b47a 100644 --- a/tooling/client/manager/variable_manager.cpp +++ b/tooling/client/manager/variable_manager.cpp @@ -55,7 +55,7 @@ void TreeNode::Print(int depth) const } } else if (std::holds_alternative>(data)) { const auto &descriptor = std::get>(data); - if (descriptor) { + if (descriptor && descriptor->GetValue()) { if (descriptor->GetValue()->HasDescription()) { std::cout << indent << " " << descriptor->GetName() << " = " << descriptor->GetValue()->GetDescription() << std::endl; @@ -68,7 +68,7 @@ void TreeNode::Print(int depth) const const auto &descriptorMap = std::get(data); for (const auto& [key, descriptor] : descriptorMap) { std::cout << indent << key << ". "; - if (descriptor) { + if (descriptor && descriptor->GetValue()) { std::cout << descriptor->GetName() << " = " << descriptor->GetValue()->GetDescription() << std::endl; } } @@ -172,7 +172,7 @@ TreeNode* Tree::FindNodeWithObjectIdRecursive(TreeNode* node, int32_t objectId) } else if (std::holds_alternative(node->data)) { const auto& descriptorMap = std::get(node->data); for (const auto& [key, descriptor] : descriptorMap) { - if (descriptor && descriptor->GetValue()->GetObjectId() == objectId) { + if (descriptor && descriptor->GetValue() && descriptor->GetValue()->GetObjectId() == objectId) { return node; } } @@ -237,7 +237,7 @@ int32_t Tree::FindObjectByIndexRecursive(const TreeNode* node, int32_t index) co } else if (std::holds_alternative(node->data)) { const auto &descriptorMap = std::get(node->data); auto it = descriptorMap.find(index); - if (it != descriptorMap.end() && it->second) { + if (it != descriptorMap.end() && it->second && it->second->GetValue()) { return it->second->GetValue()->GetObjectId(); } } @@ -291,7 +291,7 @@ TreeNode* VariableManager::FindNodeWithObjectId(int32_t objectId) void VariableManager::AddVariableInfo(TreeNode *parentNode, std::unique_ptr variableInfo) { - if (variableInfo->GetValue()->HasObjectId()) { + if (variableInfo && variableInfo->GetValue() && variableInfo->GetValue()->HasObjectId()) { variableInfo_.AddObjectNode(parentNode, std::move(variableInfo)); } else { variableInfo_.AddVariableNode(parentNode, std::move(variableInfo)); diff --git a/tooling/client/tcpServer/test/js_test_base.py b/tooling/client/tcpServer/test/js_test_base.py index 3b6875a7..58fa95f5 100644 --- a/tooling/client/tcpServer/test/js_test_base.py +++ b/tooling/client/tcpServer/test/js_test_base.py @@ -41,7 +41,7 @@ class JsTestBase(unittest.TestCase): "tcp:%i" % self.PORT, "tcp:%i" % self.PORT, ], - stdout = subprocess.PIPE + stdout=subprocess.PIPE ) connection = 0 while(connection < 5): @@ -49,7 +49,7 @@ class JsTestBase(unittest.TestCase): ret = None result = subprocess.run( '%s shell "netstat -anp | grep PandaDebugger"' % os.environ.get("HDCTool", "hdc"), - stdout = subprocess.PIPE, + stdout=subprocess.PIPE, ) if (result.returncode == 0): ret = result.stdout @@ -94,7 +94,7 @@ class JsTestBase(unittest.TestCase): ret = None result = subprocess.run( '%s shell "netstat -anp | grep PandaDebugger"' % os.environ.get("HDCTool", "hdc"), - stdout = subprocess.PIPE, + stdout=subprocess.PIPE, ) if (result.returncode == 0): ret = result.stdout @@ -121,5 +121,5 @@ class JsTestBase(unittest.TestCase): subprocess.Popen( [self.hdctool, 'shell', 'arkdb', real_panda_name, 'server'], - stdout = subprocess.PIPE, + stdout=subprocess.PIPE, ) diff --git a/tooling/client/tcpServer/test/js_test_case/js_test.py b/tooling/client/tcpServer/test/js_test_case/js_test.py index 51824d97..96270687 100644 --- a/tooling/client/tcpServer/test/js_test_case/js_test.py +++ b/tooling/client/tcpServer/test/js_test_case/js_test.py @@ -42,7 +42,7 @@ class JsTestCase(JsTestBase): "-b", hap_name, ], - stdout = subprocess.PIPE, + stdout=subprocess.PIPE, ) cls.run_arkdb_server(cls, dbg_name) cls.connect_client_socket(cls, dbg_name) @@ -64,7 +64,7 @@ class JsTestCase(JsTestBase): "force-stop", hap_name, ], - stdout = subprocess.PIPE, + stdout=subprocess.PIPE, ) def test_set_and_delete_breakpoints(self): diff --git a/tooling/client/tcpServer/test/runtest.py b/tooling/client/tcpServer/test/runtest.py index f58fc163..22814ab6 100644 --- a/tooling/client/tcpServer/test/runtest.py +++ b/tooling/client/tcpServer/test/runtest.py @@ -30,7 +30,7 @@ class RunTest: self.run_test() def parse_args(self): - parser = argparse.ArgumentParser(description = 'Plugin test.') + parser = argparse.ArgumentParser(description='Plugin test.') parser.add_argument( '-hdctool', action='store', -- Gitee From 4ddc53623f7e1a4106bd74c78905c1fb1b1958d2 Mon Sep 17 00:00:00 2001 From: Ishin Pavel Date: Fri, 12 Jul 2024 16:37:07 +0300 Subject: [PATCH 11/51] Update list of the reviewrs Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IACO4H?from=project-issue Tests: - Signed-off-by: Ishin Pavel --- REVIEWERS | 1 + 1 file changed, 1 insertion(+) diff --git a/REVIEWERS b/REVIEWERS index 3f1d9f1d..9abad16e 100644 --- a/REVIEWERS +++ b/REVIEWERS @@ -12,3 +12,4 @@ # limitations under the License. * @weng-changcheng @wanghuan2022 +build/compile_script/ark.py @shirunova_viktoria @weng-changcheng @wanghuan2022 @zhuheng27 -- Gitee From 0e7b4c4ecbee5e59ba2d4044b66037a104df5a21 Mon Sep 17 00:00:00 2001 From: bigtea Date: Thu, 11 Jul 2024 15:45:45 +0800 Subject: [PATCH 12/51] change connection scope when previewer init Issue: IACAK8 Signed-off-by: bigtea --- websocket/server/websocket_server.cpp | 20 ++++++++++++++++++-- websocket/server/websocket_server.h | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/websocket/server/websocket_server.cpp b/websocket/server/websocket_server.cpp index 65b49427..208cd9a3 100644 --- a/websocket/server/websocket_server.cpp +++ b/websocket/server/websocket_server.cpp @@ -13,6 +13,14 @@ * limitations under the License. */ +#if !defined(OHOS_PLATFORM) +#if defined(PANDA_TARGET_WINDOWS) +#include +#else +#include +#endif +#endif + #include #include "common/log_wrapper.h" #include "frame_builder.h" @@ -177,13 +185,21 @@ bool WebSocketServer::InitTcpWebSocket(int port, uint32_t timeoutLimit) CloseServerSocket(); return false; } + return BindAndListenTcpWebSocket(port); +} + +bool WebSocketServer::BindAndListenTcpWebSocket(int port) +{ sockaddr_in addrSin = {}; addrSin.sin_family = AF_INET; addrSin.sin_port = htons(port); - addrSin.sin_addr.s_addr = INADDR_ANY; + if (inet_pton(AF_INET, "127.0.0.1", &addrSin.sin_addr) != NET_SUCCESS) { + LOGE("BindAndListenTcpWebSocket inet_pton failed, error = %{public}d", errno); + return false; + } if (bind(serverFd_, reinterpret_cast(&addrSin), sizeof(addrSin)) != SOCKET_SUCCESS || listen(serverFd_, 1) != SOCKET_SUCCESS) { - LOGE("InitTcpWebSocket bind/listen failed, errno = %{public}d", errno); + LOGE("BindAndListenTcpWebSocket bind/listen failed, errno = %{public}d", errno); CloseServerSocket(); return false; } diff --git a/websocket/server/websocket_server.h b/websocket/server/websocket_server.h index 2926dc6c..af5827f5 100644 --- a/websocket/server/websocket_server.h +++ b/websocket/server/websocket_server.h @@ -35,6 +35,7 @@ public: #if !defined(OHOS_PLATFORM) // Initialize server socket, transition to `INITED` state. bool InitTcpWebSocket(int port, uint32_t timeoutLimit = 0); + bool BindAndListenTcpWebSocket(int port); #else // Initialize server socket, transition to `INITED` state. bool InitUnixWebSocket(const std::string& sockName, uint32_t timeoutLimit = 0); @@ -74,6 +75,7 @@ private: OpenConnectionCallback openCb_; static constexpr std::string_view BAD_REQUEST_RESPONSE = "HTTP/1.1 400 Bad Request\r\n\r\n"; + static constexpr int NET_SUCCESS = 1; }; } // namespace OHOS::ArkCompiler::Toolchain -- Gitee From c53f32f9c1275a99e39f4614297c6693d5020192 Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Fri, 19 Jul 2024 13:55:58 +0800 Subject: [PATCH 13/51] Fix alarm G.TYP.07 Fix alarm G.TYP.07 in file sdk_info.py Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAE5BE Signed-off-by: swx1282997 --- build/config/mac/sdk_info.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build/config/mac/sdk_info.py b/build/config/mac/sdk_info.py index f757cd3d..97ad4f54 100755 --- a/build/config/mac/sdk_info.py +++ b/build/config/mac/sdk_info.py @@ -93,7 +93,10 @@ if __name__ == '__main__': settings = {} fill_machine_os_build(settings) fill_xcode_version(settings) - fill_sdk_path_and_version(settings, unknownargs[0], settings['xcode_version']) + test_xcode_version = settings.get('xcode_version') + if test_xcode_version is None: + raise ValueError("Xcode version is not set or invalid.") + fill_sdk_path_and_version(settings, unknownargs[0], test_xcode_version) for key in sorted(settings): value = settings[key] -- Gitee From d7a466ebaa71d4a1abd18a2dc68068df8eca0415 Mon Sep 17 00:00:00 2001 From: fangting Date: Fri, 19 Jul 2024 17:13:27 +0800 Subject: [PATCH 14/51] fix ut bug fix ut bug Issue:#IAE5XT Signed-off-by: fangting --- tooling/test/testcases/js_stepout_loop_test.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tooling/test/testcases/js_stepout_loop_test.h b/tooling/test/testcases/js_stepout_loop_test.h index acaa30e5..9471824a 100644 --- a/tooling/test/testcases/js_stepout_loop_test.h +++ b/tooling/test/testcases/js_stepout_loop_test.h @@ -44,18 +44,6 @@ public: {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, - {SocketAction::SEND, "so"}, - {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 RecvStepoutInfo(recv, "for_loop", 26); }}, - - {SocketAction::SEND, "so"}, - {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 RecvStepoutInfo(recv, "for_loop", 26); }}, - {SocketAction::SEND, "so"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, -- Gitee From df2c54a0cf515e42449d1ef081941f1d776234f0 Mon Sep 17 00:00:00 2001 From: liu-zelin Date: Wed, 17 Jul 2024 14:09:31 +0800 Subject: [PATCH 15/51] Fix ExecuteNativeModule in shared module Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IADIOB?from=project-issue Signed-off-by: liu-zelin Change-Id: I6c6dd26480bbdd48a3ff62160ccec64fad1b2c73 --- tooling/agent/runtime_impl.cpp | 27 +++++++++++++++++++++++++++ tooling/agent/runtime_impl.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index 94f8ad84..ee07472a 100644 --- a/tooling/agent/runtime_impl.cpp +++ b/tooling/agent/runtime_impl.cpp @@ -228,6 +228,8 @@ DispatchResponse RuntimeImpl::GetProperties(const GetPropertiesParams ¶ms, GetCollatorValue(value, outPropertyDesc); } else if (value->IsJSDateTimeFormat(vm_)) { GetDateTimeFormatValue(value, outPropertyDesc); + } else if (value->IsSharedMap(vm_)) { + GetSharedMapValue(value, outPropertyDesc); } else if (value->IsMap(vm_)) { GetMapValue(value, outPropertyDesc); } else if (value->IsWeakMap(vm_)) { @@ -594,6 +596,31 @@ void RuntimeImpl::GetDateTimeFormatValue(Local value, SetKeyValue(jsValueRef, outPropertyDesc, "format"); } +void RuntimeImpl::GetSharedMapValue(Local value, + std::vector> *outPropertyDesc) +{ + Local sendableMapRef(value); + int32_t size = sendableMapRef->GetSize(vm_); + int32_t len = sendableMapRef->GetTotalElements(vm_); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < len; ++i) { + Local jsKey = sendableMapRef->GetKey(vm_, i); + if (jsKey->IsHole()) { + continue; + } + Local jsValue = sendableMapRef->GetValue(vm_, i); + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "key"), jsKey); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), jsValue); + DebuggerApi::AddInternalProperties(vm_, objRef, ArkInternalValueType::Entry, internalObjects_); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } + DebuggerApi::AddInternalProperties(vm_, jsValueRef, ArkInternalValueType::Entry, internalObjects_); + SetKeyValue(jsValueRef, outPropertyDesc, "[[Entries]]"); +} void RuntimeImpl::GetMapValue(Local value, std::vector> *outPropertyDesc) { diff --git a/tooling/agent/runtime_impl.h b/tooling/agent/runtime_impl.h index b4b86ae1..d7e6a1d7 100644 --- a/tooling/agent/runtime_impl.h +++ b/tooling/agent/runtime_impl.h @@ -110,6 +110,8 @@ private: std::vector> *outPropertyDesc); void GetDateTimeFormatValue(Local value, std::vector> *outPropertyDesc); + void GetSharedMapValue(Local value, + std::vector> *outPropertyDesc); void GetMapValue(Local value, std::vector> *outPropertyDesc); void GetWeakMapValue(Local value, -- Gitee From d453d5b9cebf51ede95e84c5d8fdf9db55691145 Mon Sep 17 00:00:00 2001 From: huangtianzhi Date: Mon, 22 Jul 2024 15:39:37 +0800 Subject: [PATCH 16/51] Debugger breakpoint adapts sendable features Reconstruct and revise debugger breakpoint module to adapt sendable features Issue: #IAE06X Signed-off-by: huangtianzhi --- tooling/agent/debugger_impl.cpp | 159 ++++++++++++++------- tooling/agent/debugger_impl.h | 7 +- tooling/base/pt_types.h | 1 + tooling/test/debugger_cint_client_test.cpp | 1 + tooling/test/debugger_client_test.cpp | 1 + tooling/test/debugger_impl_test.cpp | 10 +- tooling/test/utils/test_extractor.cpp | 3 +- 7 files changed, 123 insertions(+), 59 deletions(-) diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index b188ccb5..7db643fb 100644 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -252,8 +252,23 @@ void DebuggerImpl::NotifyPaused(std::optional location, PauseReaso if (!MatchScripts(scriptFunc, location->GetSourceFile(), ScriptMatchType::URL) || extractor == nullptr || !extractor->MatchLineWithOffset(callbackLineFunc, methodId, offset) || !extractor->MatchColumnWithOffset(callbackColumnFunc, methodId, offset)) { - LOG_DEBUGGER(ERROR) << "NotifyPaused: unknown file " << location->GetSourceFile(); - return; + LOG_DEBUGGER(WARN) << "NotifyPaused: unknown file " << location->GetSourceFile(); + auto jsPandaFile = location->GetJsPandaFile(); + if (jsPandaFile == nullptr) { + LOG_DEBUGGER(WARN) << "NotifyPaused: jsPandaFile is nullptr"; + return; + } + CString moduleName = jsPandaFile->GetJSPandaFileDesc(); + CString recordName = location->GetRecordName(); + if (moduleName.empty() || recordName.empty()) { + LOG_DEBUGGER(WARN) << "NotifyPaused: try to reload module after paused failed"; + return; + } + hooks_->LoadModule(moduleName, recordName); + detail.url_ = location->GetSourceFile(); + detail.line_ = location->GetLine(); + detail.column_ = location->GetColumn(); + detail.needResetBreakpoint_ = location->GetNeedResetBreakpoint(); } hitBreakpoints.emplace_back(BreakpointDetails::ToString(detail)); } @@ -1052,7 +1067,8 @@ DispatchResponse DebuggerImpl::GetPossibleBreakpoints(const GetPossibleBreakpoin auto callbackFunc = [](const JSPtLocation &) -> bool { return true; }; - if (extractor->MatchWithLocation(callbackFunc, line, column, url, GetRecordName(url))) { + Global funcRef = Global(vm_, FunctionRef::Undefined(vm_)); + if (extractor->MatchWithLocation(callbackFunc, line, column, url, GetRecordName(url), funcRef)) { std::unique_ptr location = std::make_unique(); location->SetScriptId(start->GetScriptId()).SetLine(line).SetColumn(column); locations->emplace_back(std::move(location)); @@ -1097,8 +1113,13 @@ DispatchResponse DebuggerImpl::RemoveBreakpoint(const RemoveBreakpointParams &pa return true; }; if (!MatchScripts(scriptFunc, metaData.url_, ScriptMatchType::URL)) { - LOG_DEBUGGER(ERROR) << "RemoveBreakpoint: Unknown url: " << metaData.url_; - return DispatchResponse::Fail("Unknown file name."); + LOG_DEBUGGER(WARN) << "RemoveBreakpoint: Unknown url: " << metaData.url_; + JSPtLocation location{metaData.url_, metaData.line_, metaData.column_}; + bool res = DebuggerApi::RemoveBreakpointWithNoMatchUrl(jsDebugger_, location); + if (!res) { + return DispatchResponse::Fail("RemoveBreakpointWithNoMatchUrl failed"); + } + return DispatchResponse::Ok(); } std::vector extractors = GetExtractors(metaData.url_); @@ -1112,8 +1133,9 @@ DispatchResponse DebuggerImpl::RemoveBreakpoint(const RemoveBreakpointParams &pa LOG_DEBUGGER(INFO) << "remove breakpoint location: " << location.ToString(); return DebuggerApi::RemoveBreakpoint(jsDebugger_, location); }; + Global funcRef = Global(vm_, FunctionRef::Undefined(vm_)); if (!extractor->MatchWithLocation(callbackFunc, metaData.line_, metaData.column_, - metaData.url_, GetRecordName(metaData.url_))) { + metaData.url_, GetRecordName(metaData.url_), funcRef)) { LOG_DEBUGGER(ERROR) << "failed to remove breakpoint location number: " << metaData.line_ << ":" << metaData.column_; } @@ -1130,13 +1152,14 @@ DispatchResponse DebuggerImpl::RemoveBreakpointsByUrl(const RemoveBreakpointsByU return true; }; if (!MatchScripts(scriptMatchCallback, url, ScriptMatchType::URL)) { - LOG_DEBUGGER(ERROR) << "RemoveBreakpointByUrl: Unknown url: " << url; - return DispatchResponse::Fail("Unknown url"); - } - if (!DebuggerApi::RemoveBreakpointsByUrl(jsDebugger_, url)) { - return DispatchResponse::Fail("RemoveBreakpointByUrl failed"); + if (!DebuggerApi::RemoveAllBreakpointsByUrl(jsDebugger_, url, true)) { + return DispatchResponse::Fail("RemoveBreakpointsByUrl failed"); + } + } else { + if (!DebuggerApi::RemoveAllBreakpointsByUrl(jsDebugger_, url, false)) { + return DispatchResponse::Fail("RemoveBreakpointsByUrl failed"); + } } - LOG_DEBUGGER(INFO) << "All breakpoints on " << url << " are removed"; return DispatchResponse::Ok(); } @@ -1159,20 +1182,27 @@ DispatchResponse DebuggerImpl::SetAsyncCallStackDepth() void DebuggerImpl::AddBreakpointDetail(const std::string &url, int32_t lineNumber, std::string *outId, - std::vector> *outLocations) + std::vector> *outLocations, + bool hasScriptId) { - std::vector ptScripts = MatchAllScripts(url); - for (auto ptScript : ptScripts) { - ScriptId scriptId = ptScript->GetScriptId(); + if (!hasScriptId) { + ScriptId invalidId = -1; std::unique_ptr location = std::make_unique(); - location->SetScriptId(scriptId).SetLine(lineNumber).SetColumn(0); + location->SetScriptId(invalidId).SetLine(lineNumber).SetColumn(0); outLocations->emplace_back(std::move(location)); + } else { + std::vector ptScripts = MatchAllScripts(url); + for (auto ptScript : ptScripts) { + ScriptId scriptId = ptScript->GetScriptId(); + std::unique_ptr location = std::make_unique(); + location->SetScriptId(scriptId).SetLine(lineNumber).SetColumn(0); + outLocations->emplace_back(std::move(location)); + } } BreakpointDetails metaData{lineNumber, 0, url}; *outId = BreakpointDetails::ToString(metaData); } - DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams ¶ms, std::string *outId, std::vector> *outLocations, @@ -1192,8 +1222,14 @@ DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams return true; }; if (!MatchScripts(scriptFunc, url, ScriptMatchType::URL)) { - LOG_DEBUGGER(ERROR) << "SetBreakpointByUrl: Unknown url: " << url; - return DispatchResponse::Fail("Unknown file name."); + LOG_DEBUGGER(WARN) << "SetBreakpointByUrl: Unknown url: " << url; + JSPtLocation location{url, lineNumber, columnNumber}; + bool res = DebuggerApi::SetBreakpointWithNoMatchUrl(jsDebugger_, location); + if (!res) { + return DispatchResponse::Fail("DebuggerImpl SetBreakpointWithNoMatchUrl failed"); + } + AddBreakpointDetail(url, lineNumber, outId, outLocations, false); + return DispatchResponse::Ok(); } std::vector extractors = GetExtractors(url); @@ -1215,13 +1251,14 @@ DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams } return DebuggerApi::SetBreakpoint(jsDebugger_, location, condFuncRef, isSmartBreakpoint); }; - if (!extractor->MatchWithLocation(callbackFunc, lineNumber, columnNumber, url, GetRecordName(url))) { + Global funcRef = Global(vm_, FunctionRef::Undefined(vm_)); + if (!extractor->MatchWithLocation(callbackFunc, lineNumber, columnNumber, url, GetRecordName(url), funcRef)) { LOG_DEBUGGER(ERROR) << "failed to set breakpoint location number: " << lineNumber << ":" << columnNumber; return DispatchResponse::Fail("Breakpoint not found."); } } - AddBreakpointDetail(url, lineNumber, outId, outLocations); + AddBreakpointDetail(url, lineNumber, outId, outLocations, true); return DispatchResponse::Ok(); } @@ -1241,26 +1278,31 @@ DispatchResponse DebuggerImpl::GetPossibleAndSetBreakpointByUrl(const GetPossibl return DispatchResponse::Fail("GetPossibleAndSetBreakpointByUrl: no pennding breakpoint exists"); } auto breakpointList = params.GetBreakpointsList(); + std::vector processedList; + CUnorderedMap scriptIdList; + int32_t index = 0; + for (const auto &breakpoint : *breakpointList) { - if (!ProcessSingleBreakpoint(*breakpoint, outLocations)) { - std::string invalidBpId = "invalid"; - std::unique_ptr bpInfo = std::make_unique(); - bpInfo->SetId(invalidBpId) - .SetLineNumber(breakpoint->GetLineNumber()) - .SetColumnNumber(breakpoint->GetColumnNumber()); - outLocations.emplace_back(std::move(bpInfo)); - } + ScriptId id = PreProcessBreakpoint(*breakpoint, processedList); + scriptIdList[index++] = id; + } + auto resultList = DebuggerApi::SetBreakpointByList(jsDebugger_, processedList); + index = 0; + ASSERT(resultList.size() == scriptIdList.size()); + for (auto const &res : resultList) { + auto breakpoint = processedList.at(index); + GenerateBreakpointOutLocation(scriptIdList[index++], breakpoint.GetSourceFile(), + breakpoint.GetLine(), res, outLocations); } return DispatchResponse::Ok(); } -bool DebuggerImpl::ProcessSingleBreakpoint(const BreakpointInfo &breakpoint, - std::vector> &outLocations) +ScriptId DebuggerImpl::PreProcessBreakpoint(const BreakpointInfo &breakpoint, std::vector &list) { const std::string &url = breakpoint.GetUrl(); int32_t lineNumber = breakpoint.GetLineNumber(); - // it is not support column breakpoint now, so columnNumber is not useful int32_t columnNumber = -1; + ScriptId noMatchedId = -1; auto condition = breakpoint.HasCondition() ? breakpoint.GetCondition() : std::optional {}; ScriptId scriptId; @@ -1269,14 +1311,14 @@ bool DebuggerImpl::ProcessSingleBreakpoint(const BreakpointInfo &breakpoint, return true; }; if (!MatchScripts(scriptFunc, url, ScriptMatchType::URL)) { - LOG_DEBUGGER(ERROR) << "GetPossibleAndSetBreakpointByUrl: Unknown url: " << url; - return false; + LOG_DEBUGGER(INFO) << "DebuggerImpl::PreProcessBreakpoint SUCCESS: URL-NO-MATCH Breakpoint"; + JSPtLocation location{url, lineNumber, columnNumber}; + list.emplace_back(location); + return noMatchedId; } - std::vector extractors = GetExtractors(url); for (auto extractor : extractors) { if (extractor == nullptr) { - LOG_DEBUGGER(DEBUG) << "GetPossibleAndSetBreakpointByUrl: extractor is null"; continue; } // decode and convert condition to function before doing matchWithLocation @@ -1284,26 +1326,43 @@ bool DebuggerImpl::ProcessSingleBreakpoint(const BreakpointInfo &breakpoint, if (condition.has_value() && !condition.value().empty()) { funcRef = CheckAndGenerateCondFunc(condition); if (funcRef->IsUndefined()) { - LOG_DEBUGGER(ERROR) << "GetPossibleAndSetBreakpointByUrl: generate function failed"; - return false; + JSPtLocation location{"invalid", lineNumber, columnNumber}; + list.emplace_back(location); + return noMatchedId; } } - auto matchLocationCbFunc = [this, &funcRef](const JSPtLocation &location) -> bool { - return DebuggerApi::SetBreakpoint(jsDebugger_, location, funcRef); + auto matchLocationCbFunc = [&list](const JSPtLocation &location) -> bool { + list.emplace_back(location); + return true; }; - if (!extractor->MatchWithLocation(matchLocationCbFunc, lineNumber, columnNumber, url, GetRecordName(url))) { - LOG_DEBUGGER(ERROR) << "failed to set breakpoint location number: " << lineNumber << ":" << columnNumber; - return false; + Global globalFuncRef = Global(vm_, funcRef); + if (!extractor->MatchWithLocation(matchLocationCbFunc, lineNumber, + columnNumber, url, GetRecordName(url), globalFuncRef)) { + JSPtLocation location{"invalid", lineNumber, columnNumber}; + list.emplace_back(location); + return noMatchedId; + } else { + return scriptId; } } - - BreakpointDetails bpMetaData {lineNumber, 0, url}; - std::string outId = BreakpointDetails::ToString(bpMetaData); + JSPtLocation location{"invalid", lineNumber, columnNumber}; + list.emplace_back(location); + return noMatchedId; +} + +void DebuggerImpl::GenerateBreakpointOutLocation(ScriptId scriptId, const std::string &url, int32_t line, + bool res, std::vector> &outLocations) +{ + BreakpointDetails bpMetaData {line, 0, url}; std::unique_ptr bpInfo = std::make_unique(); - bpInfo->SetScriptId(scriptId).SetLineNumber(lineNumber).SetColumnNumber(0).SetId(outId); + if (res) { + std::string outId = BreakpointDetails::ToString(bpMetaData); + bpInfo->SetScriptId(scriptId).SetLineNumber(line).SetColumnNumber(0).SetId(outId); + } else { + std::string invalidBpId = "invalid"; + bpInfo->SetScriptId(scriptId).SetLineNumber(line).SetColumnNumber(0).SetId(invalidBpId); + } outLocations.emplace_back(std::move(bpInfo)); - - return true; } DispatchResponse DebuggerImpl::SetNativeRange(const SetNativeRangeParams ¶ms) diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index 40186259..b8543592 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -53,7 +53,7 @@ public: bool IsUserCode(const void *nativeAddress); void SetDebuggerState(DebuggerState debuggerState); void AddBreakpointDetail(const std::string &url, int32_t lineNumber, - std::string *outId, std::vector> *outLocations); + std::string *outId, std::vector> *outLocations, bool hasScriptId); DispatchResponse ContinueToLocation(const ContinueToLocationParams ¶ms); DispatchResponse Enable(const EnableParams ¶ms, UniqueDebuggerId *id); @@ -255,11 +255,12 @@ private: bool IsSkipLine(const JSPtLocation &location); bool CheckPauseOnException(); bool IsWithinVariableScope(const LocalVariableInfo &localVariableInfo, uint32_t bcOffset); - bool ProcessSingleBreakpoint(const BreakpointInfo &breakpoint, - std::vector> &outLocations); bool IsVariableSkipped(const std::string &varName); Local CheckAndGenerateCondFunc(const std::optional &condition); void InitializeExtendedProtocolsList(); + void GenerateBreakpointOutLocation(ScriptId scriptId, const std::string &url, int32_t line, + bool res, std::vector> &outLocations); + ScriptId PreProcessBreakpoint(const BreakpointInfo &breakpoint, std::vector &list); const std::unordered_set &GetRecordName(const std::string &url) { diff --git a/tooling/base/pt_types.h b/tooling/base/pt_types.h index 483a5c67..c3122276 100644 --- a/tooling/base/pt_types.h +++ b/tooling/base/pt_types.h @@ -81,6 +81,7 @@ struct BreakpointDetails { int32_t line_ {0}; int32_t column_ {0}; std::string url_ {}; + bool needResetBreakpoint_ {false}; }; // Debugger.CallFrameId diff --git a/tooling/test/debugger_cint_client_test.cpp b/tooling/test/debugger_cint_client_test.cpp index 5d125a13..09809e99 100644 --- a/tooling/test/debugger_cint_client_test.cpp +++ b/tooling/test/debugger_cint_client_test.cpp @@ -49,6 +49,7 @@ public: JSNApi::StartDebugger(instance, debugOption); if (instance->GetJsDebuggerManager() != nullptr) { instance->GetJsDebuggerManager()->DisableObjectHashDisplay(); + instance->GetJsDebuggerManager()->DisableBreakpointSync(); } } diff --git a/tooling/test/debugger_client_test.cpp b/tooling/test/debugger_client_test.cpp index ba9df5f6..2f54ce54 100644 --- a/tooling/test/debugger_client_test.cpp +++ b/tooling/test/debugger_client_test.cpp @@ -49,6 +49,7 @@ public: JSNApi::StartDebugger(instance, debugOption); if (instance->GetJsDebuggerManager() != nullptr) { instance->GetJsDebuggerManager()->DisableObjectHashDisplay(); + instance->GetJsDebuggerManager()->DisableBreakpointSync(); } } diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 25d9fd86..141f91c5 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -494,8 +494,7 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__003) DispatchRequest request(msg); dispatcherImpl->Dispatch(request); - EXPECT_STREQ(outStrForCallbackCheck.c_str(), - R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})"); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})"); if (protocolChannel) { delete protocolChannel; protocolChannel = nullptr; @@ -551,7 +550,7 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__002) DispatchRequest request(msg); dispatcherImpl->Dispatch(request); - EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown url"}})"); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})"); if (protocolChannel) { delete protocolChannel; protocolChannel = nullptr; @@ -703,7 +702,8 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__002) DispatchRequest request(msg); dispatcherImpl->Dispatch(request); - EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})"); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"DebuggerImpl SetBreakpointWithNoMatchUrl failed"}})"); if (protocolChannel) { delete protocolChannel; protocolChannel = nullptr; @@ -1176,7 +1176,7 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__0 dispatcherImpl->Dispatch(request); EXPECT_STREQ(outStrForCallbackCheck.c_str(), - R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":20,"id":"invalid","scriptId":0}]}})"); + R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":0,"id":"invalid","scriptId":-1}]}})"); if (protocolChannel) { delete protocolChannel; protocolChannel = nullptr; diff --git a/tooling/test/utils/test_extractor.cpp b/tooling/test/utils/test_extractor.cpp index 5a57694e..48e291e9 100644 --- a/tooling/test/utils/test_extractor.cpp +++ b/tooling/test/utils/test_extractor.cpp @@ -36,7 +36,8 @@ std::pair TestExtractor::GetBreakpointAddress(const SourceLo return true; }; std::unordered_set recordName {}; - MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, "", recordName); + Global funcRef; + MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, "", recordName, funcRef); return {retId, retOffset}; } -- Gitee From f9af335286944d048de628d3eb3f7c14e49956d7 Mon Sep 17 00:00:00 2001 From: fangting Date: Mon, 22 Jul 2024 11:25:57 +0800 Subject: [PATCH 17/51] unreasonable reliance unreasonable reliance Issue:#IAELL5 Signed-off-by: fangting --- bundle.json | 1 - tooling/BUILD.gn | 15 --------------- tooling/client/BUILD.gn | 1 - tooling/client/ark_cli/BUILD.gn | 1 - 4 files changed, 18 deletions(-) diff --git a/bundle.json b/bundle.json index 818542d8..4b3ca904 100644 --- a/bundle.json +++ b/bundle.json @@ -34,7 +34,6 @@ "libuv", "cJSON", "openssl", - "zlib", "ffrt" ], "third_party": [] diff --git a/tooling/BUILD.gn b/tooling/BUILD.gn index 5e0ce350..2000fa87 100644 --- a/tooling/BUILD.gn +++ b/tooling/BUILD.gn @@ -70,11 +70,6 @@ ohos_source_set("libark_ecma_debugger_set") { external_deps += [ "cJSON:cjson" ] } external_deps += [ "libuv:uv" ] - if (!ark_standalone_build) { - public_external_deps = [ "zlib:libz" ] - } else { - external_deps += [ "zlib:libz" ] - } if (is_ohos && is_standard_system && !is_arkui_x) { defines += [ "ENABLE_FFRT_INTERFACES" ] @@ -104,11 +99,6 @@ ohos_shared_library("libark_ecma_debugger") { stack_protector_ret = false deps = [ ":libark_ecma_debugger_set" ] external_deps = [ "libuv:uv" ] - if (!ark_standalone_build) { - public_external_deps = [ "zlib:libz" ] - } else { - external_deps += [ "zlib:libz" ] - } if (is_mac) { external_deps += [ "cJSON:cjson_static" ] } @@ -150,11 +140,6 @@ ohos_shared_library("libark_ecma_debugger_test") { deps = [ "$js_root:libark_jsruntime_test" ] external_deps = [ "libuv:uv" ] - if (!ark_standalone_build) { - public_external_deps = [ "zlib:libz" ] - } else { - external_deps += [ "zlib:libz" ] - } if ((is_arkui_x && target_os == "ios") || target_os == "mac") { external_deps += [ "cJSON:cjson_static" ] } else { diff --git a/tooling/client/BUILD.gn b/tooling/client/BUILD.gn index b58f6aae..fd96ed7e 100644 --- a/tooling/client/BUILD.gn +++ b/tooling/client/BUILD.gn @@ -55,7 +55,6 @@ ohos_source_set("libark_client_set") { "cJSON:cjson_static", "ets_runtime:libark_jsruntime", "libuv:uv", - "zlib:libz", ] configs = [ "../..:ark_toolchain_common_config" ] diff --git a/tooling/client/ark_cli/BUILD.gn b/tooling/client/ark_cli/BUILD.gn index 9ad53a09..5ea01791 100644 --- a/tooling/client/ark_cli/BUILD.gn +++ b/tooling/client/ark_cli/BUILD.gn @@ -33,7 +33,6 @@ ohos_executable("arkdb") { "cJSON:cjson", "ets_runtime:libark_jsruntime", "libuv:uv", - "zlib:libz", ] # hiviewdfx libraries -- Gitee From 2a2f2a7197a701212fb5dfe78e4bb2c6180dad87 Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Wed, 17 Jul 2024 14:19:39 +0800 Subject: [PATCH 18/51] fix 'musl_log' 'flto' 'gwp_asan' 'legacy' 'custom_libc' features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue:https://gitee.com/openharmony/third_party_musl/issues/IADCCI?from=project-issue Signed-off-by: xwx1135370 --- build/third_party_gn/musl/musl_template.gni | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/third_party_gn/musl/musl_template.gni b/build/third_party_gn/musl/musl_template.gni index 21f5dd2c..84c653b5 100644 --- a/build/third_party_gn/musl/musl_template.gni +++ b/build/third_party_gn/musl/musl_template.gni @@ -170,8 +170,8 @@ template("musl_libs") { ] } - if (!is_standard_system && defined(enable_musl_log)) { - if (enable_musl_log) { + if (!is_standard_system && defined(musl_enable_musl_log)) { + if (musl_enable_musl_log) { defines += [ "ENABLE_MUSL_LOG" ] } } -- Gitee From ac9457dc836f43de2f08e30ff38664321a3d379f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=B1=9F=E6=B5=A9?= <5715935+Yejianghao1995@user.noreply.gitee.com> Date: Mon, 22 Jul 2024 17:38:06 +0800 Subject: [PATCH 19/51] add js_pt_hooks testcase Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IACMO8 Signed-off-by: yejianghao Change-Id: Id225d077c82465dd2252a5a7af25898d45f174ab --- tooling/agent/debugger_impl.cpp | 6 ++++++ tooling/agent/debugger_impl.h | 1 + tooling/test/debugger_impl_test.cpp | 18 ++++++++++++++++++ tooling/test/js_pt_hooks_test.cpp | 8 ++++++++ 4 files changed, 33 insertions(+) mode change 100644 => 100755 tooling/agent/debugger_impl.cpp mode change 100644 => 100755 tooling/test/js_pt_hooks_test.cpp diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp old mode 100644 new mode 100755 index 7db643fb..05cc8fdc --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -377,6 +377,12 @@ void DebuggerImpl::SetDebuggerState(DebuggerState debuggerState) debuggerState_ = debuggerState; } +// only use for test case +void DebuggerImpl::SetNativeOutPause(bool nativeOutPause) +{ + nativeOutPause_ = nativeOutPause; +} + void DebuggerImpl::NotifyHandleProtocolCommand() { auto *handler = vm_->GetJsDebuggerManager()->GetDebuggerHandler(); diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index b8543592..9c842173 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -52,6 +52,7 @@ public: void NotifyReturnNative(); bool IsUserCode(const void *nativeAddress); void SetDebuggerState(DebuggerState debuggerState); + void SetNativeOutPause(bool nativeOutPause); void AddBreakpointDetail(const std::string &url, int32_t lineNumber, std::string *outId, std::vector> *outLocations, bool hasScriptId); diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 141f91c5..4aaa0338 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -1241,4 +1241,22 @@ HWTEST_F_L0(DebuggerImplTest, DispatcherImplCallFunctionOn) protocolChannel = nullptr; } } +HWTEST_F_L0(DebuggerImplTest, NativeOutTest) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr jspthooks = std::make_unique(debuggerImpl.get()); + bool result1 = jspthooks->NativeOut(); + ASSERT_TRUE(!result1); + bool value = true; + debuggerImpl->SetNativeOutPause(value); + bool result2 = jspthooks->NativeOut(); + ASSERT_TRUE(result2); + ASSERT_NE(jspthooks, nullptr); +} } // namespace panda::test diff --git a/tooling/test/js_pt_hooks_test.cpp b/tooling/test/js_pt_hooks_test.cpp old mode 100644 new mode 100755 index 6ac5baae..5d261d31 --- a/tooling/test/js_pt_hooks_test.cpp +++ b/tooling/test/js_pt_hooks_test.cpp @@ -121,4 +121,12 @@ HWTEST_F_L0(JSPtHooksTest, NativeCallingTest) jspthooks->NativeCalling(nullptr); ASSERT_NE(jspthooks, nullptr); } + +HWTEST_F_L0(JSPtHooksTest, NativeReturnTest) +{ + auto debugger = std::make_unique(ecmaVm, nullptr, nullptr); + std::unique_ptr jspthooks = std::make_unique(debugger.get()); + jspthooks->NativeReturn(nullptr); + ASSERT_NE(jspthooks, nullptr); +} } \ No newline at end of file -- Gitee From a5a89178e09c1fe5cb10d259e8e6d2ceb52c5158 Mon Sep 17 00:00:00 2001 From: Viktoria Shirunova Date: Tue, 9 Jul 2024 19:55:22 +0300 Subject: [PATCH 20/51] ark.py/regress tests: support --test-list option Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAAESE Testing: All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: Viktoria Shirunova --- build/compile_script/ark.py | 202 ++++++++++++++++++++++-------------- 1 file changed, 124 insertions(+), 78 deletions(-) diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index e456f3bb..f378adb4 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -24,6 +24,7 @@ import os import platform import subprocess import sys +from typing import List, Tuple, Union, Optional CURRENT_FILENAME = os.path.basename(__file__) @@ -421,6 +422,125 @@ class ArkPy: "{2}".format(args_to_test262_cmd, out_path, x64_out_path, timeout) return test262_cmd + @staticmethod + def build_args_to_test262_cmd(arg_list): + args_to_test262_cmd = [] + + disable_force_gc = [arg for arg in arg_list if "disable-force-gc" in arg] + if disable_force_gc: + args_to_test262_cmd.append("--disable-force-gc") + arg_list.remove(disable_force_gc[0]) + + threads_name = "--threads" + threads_value, arg_list = ArkPy.parse_option(arg_list, option_name=threads_name, default_value=None) + if threads_value: + args_to_test262_cmd.extend([threads_name, threads_value]) + + if len(arg_list) == 0: + args_to_test262_cmd.append("--es2021 all") + elif len(arg_list) == 1: + arg = arg_list[0] + if ".js" in arg: + args_to_test262_cmd.append("--file test262/data/test_es2021/{}".format(arg)) + else: + args_to_test262_cmd.append("--dir test262/data/test_es2021/{}".format(arg)) + else: + print("\033[92m\"test262\" not support multiple additional arguments.\033[0m\n".format()) + sys.exit(0) + + return " ".join(args_to_test262_cmd) + + @staticmethod + def build_args_to_regress_cmd(arg_list): + args_to_regress_cmd = [] + + processes_name = "--processes" + processes_value, arg_list = ArkPy.parse_option(arg_list, option_name=processes_name, default_value=1) + args_to_regress_cmd.extend([processes_name, processes_value]) + + test_list_name = "--test-list" + test_list_value, arg_list = ArkPy.parse_option(arg_list, option_name=test_list_name, default_value=None) + if test_list_value is not None: + args_to_regress_cmd.extend([test_list_name, test_list_value]) + + if len(arg_list) == 1: + arg = arg_list[0] + if ".js" in arg: + args_to_regress_cmd.append(f"--test-file {arg}") + else: + args_to_regress_cmd.append(f"--test-dir {arg}") + elif len(arg_list) > 1: + print("\033[92m\"regresstest\" not support multiple additional arguments.\033[0m\n".format()) + sys.exit(0) + + return " ".join([str(arg) for arg in args_to_regress_cmd]) + + @staticmethod + def parse_option(arg_list: List[str], option_name: str, default_value: Optional[Union[str, int]]) \ + -> Tuple[Optional[Union[str, int]], List[str]]: + option_value, arg_list = ArkPy.__parse_option_with_space(arg_list, option_name) + if option_value is None: + option_value, arg_list = ArkPy.__parse_option_with_equal(arg_list, option_name) + if option_value is None and default_value is not None: + option_value = default_value + return option_value, arg_list + + @staticmethod + def __is_option_value_int(value: Optional[Union[str, int]]) -> Tuple[bool, Optional[int]]: + if isinstance(value, int): + return True, int(value) + else: + return False, None + + @staticmethod + def __is_option_value_str(value: Optional[Union[str, int]]) -> Tuple[bool, Optional[str]]: + if isinstance(value, str): + return True, str(value) + else: + return False, None + + @staticmethod + def __get_option_value(option_name: str, value: Optional[Union[str, int]]) -> Union[str, int]: + result, res_value = ArkPy.__is_option_value_int(value) + if result: + return res_value + result, res_value = ArkPy.__is_option_value_str(value) + if result: + return res_value + print(f"Invalid '{option_name}' value.") + sys.exit(1) + + @staticmethod + def __parse_option_with_space(arg_list: List[str], option_name: str) \ + -> Tuple[Optional[Union[str, int]], List[str]]: + if option_name in arg_list: + option_index = arg_list.index(option_name) + if len(arg_list) > option_index + 1: + option_value = ArkPy.__get_option_value(option_name, arg_list[option_index + 1]) + arg_list = arg_list[:option_index] + arg_list[option_index + 2:] + else: + print(f"Missing {option_name} value.") + sys.exit(1) + + return option_value, arg_list + return None, arg_list + + @staticmethod + def __parse_option_with_equal(arg_list: List[str], option_name: str) \ + -> Tuple[Optional[Union[str, int]], List[str]]: + for index, arg in enumerate(arg_list): + local_option_name = f"{option_name}=" + if arg.startswith(local_option_name): + option_value = arg[len(local_option_name):] + if option_value: + option_value = ArkPy.__get_option_value(option_name, option_value) + arg_list = arg_list[:index] + arg_list[index + 1:] + return option_value, arg_list + else: + print(f"Missing {option_name} value.") + sys.exit(1) + return None, arg_list + def get_binaries(self): host_os = sys.platform host_cpu = platform.machine() @@ -505,7 +625,7 @@ class ArkPy: " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --baseline-jit] [none or --threads=X]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [unittest] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [regresstest] [none, file or dir] " \ - "[none or --processes=X]\033[0m\n") + "[none or --processes X and/or --test-list TEST_LIST_NAME]\033[0m\n") # Command examples help_msg += "\033[32mCommand examples:\033[0m\n{}\n\n".format( " python3 ark.py \033[92mx64.release\033[0m\n" @@ -585,34 +705,6 @@ class ArkPy: print("=== ninja success! ===\n") return - @staticmethod - def build_args_to_test262_cmd(arg_list): - args_to_test262_cmd = [] - - disable_force_gc = [arg for arg in arg_list if "disable-force-gc" in arg] - if disable_force_gc: - args_to_test262_cmd.append("--disable-force-gc") - arg_list.remove(disable_force_gc[0]) - - threads = [arg for arg in arg_list if arg.startswith("--threads=")] - if threads: - args_to_test262_cmd.extend(threads) - arg_list.remove(threads[0]) - - if len(arg_list) == 0: - args_to_test262_cmd.append("--es2021 all") - elif len(arg_list) == 1: - arg = arg_list[0] - if ".js" in arg: - args_to_test262_cmd.append("--file test262/data/test_es2021/{}".format(arg)) - else: - args_to_test262_cmd.append("--dir test262/data/test_es2021/{}".format(arg)) - else: - print("\033[92m\"test262\" not support multiple additional arguments.\033[0m\n".format()) - sys.exit(0) - - return " ".join(args_to_test262_cmd) - def build_for_test262(self, out_path, timeout, gn_args: list, arg_list: list, log_file_name: str, aot_mode: bool, run_pgo=False, enable_litecg=False, run_jit=False, run_baseline_jit=False): @@ -660,27 +752,6 @@ class ArkPy: log_file_name) return - @staticmethod - def build_args_to_regress_cmd(arg_list): - args_to_regress_cmd = [] - - processes = [arg for arg in arg_list if arg.startswith("--processes=")] - if processes: - args_to_regress_cmd.extend(processes) - arg_list.remove(processes[0]) - - if len(arg_list) == 1: - arg = arg_list[0] - if ".js" in arg: - args_to_regress_cmd.append(f"--test-file {arg}") - else: - args_to_regress_cmd.append(f"--test-dir {arg}") - elif len(arg_list) > 1: - print("\033[92m\"regresstest\" not support multiple additional arguments.\033[0m\n".format()) - sys.exit(0) - - return " ".join(args_to_regress_cmd) - def build_for_regress_test(self, out_path, gn_args: list, arg_list: list, log_file_name: str, timeout): args_to_regress_test_cmd = self.build_args_to_regress_cmd(arg_list) self.build_for_gn_target( @@ -748,39 +819,14 @@ class ArkPy: sys.exit(0) self.build_for_unittest(out_path, gn_args, self.UNITTEST_LOG_FILE_NAME) elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["regresstest"], arg_list[0]): - timeout = 200 - if '--timeout' in arg_list: - timeout_index = arg_list.index('--timeout') - if len(arg_list) > timeout_index + 1: - try: - timeout = int(arg_list[timeout_index + 1]) - arg_list = arg_list[:timeout_index] + arg_list[timeout_index + 2:] - except ValueError: - print("Invalid timeout value.") - sys.exit(1) - else: - print("Missing timeout value.") - sys.exit(1) + timeout, arg_list = self.parse_option(arg_list, option_name="--timeout", default_value=200) self.build_for_regress_test(out_path, gn_args, arg_list[1:], self.REGRESS_TEST_LOG_FILE_NAME, timeout) else: self.build_for_gn_target(out_path, gn_args, arg_list, self.GN_TARGET_LOG_FILE_NAME) return - def parse_timeout(self, arg_list): - timeout = 400000 - if '--timeout' in arg_list: - timeout_index = arg_list.index('--timeout') - if len(arg_list) > timeout_index + 1: - try: - timeout = int(arg_list[timeout_index + 1]) - arg_list = arg_list[:timeout_index] + arg_list[timeout_index + 2:] - except ValueError: - print("Invalid timeout value.") - sys.exit(1) - else: - print("Missing timeout value.") - sys.exit(1) - return timeout, arg_list + def parse_timeout(self, arg_list) -> Tuple[Optional[Union[str, int]], List[str]]: + return self.parse_option(arg_list, option_name="--timeout", default_value=400000) def match_options(self, arg_list: list, out_path: str) -> [list, list]: arg_list_ret = [] -- Gitee From 2e6593a26f95ed2bf16b5cc5c602eb0482e3c6e7 Mon Sep 17 00:00:00 2001 From: ZitongLi Date: Sat, 20 Jul 2024 16:37:08 +0800 Subject: [PATCH 21/51] Cpp crash during debug and profiler due to ffrt Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IADJTZ Signed-off-by: zitongli --- inspector/BUILD.gn | 5 +++++ inspector/inspector.cpp | 25 ++++++++++++++++++++++--- inspector/inspector.h | 3 +++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/inspector/BUILD.gn b/inspector/BUILD.gn index 68cd485a..48d5efab 100644 --- a/inspector/BUILD.gn +++ b/inspector/BUILD.gn @@ -43,6 +43,11 @@ ohos_source_set("ark_debugger_static") { external_deps += [ "bounds_checking_function:libsec_shared" ] deps += hiviewdfx_deps + if (is_ohos && is_standard_system && !is_arkui_x) { + defines += [ "ENABLE_FFRT_INTERFACES" ] + external_deps += [ "ffrt:libffrt" ] + } + configs = [ "..:ark_toolchain_common_config" ] subsystem_name = "arkcompiler" part_name = "toolchain" diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 3b77b608..1c2b4574 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -33,6 +33,10 @@ #include "tooling/debugger_service.h" #endif +#if defined(ENABLE_FFRT_INTERFACES) +#include "ffrt.h" +#endif + namespace OHOS::ArkCompiler::Toolchain { namespace { enum DispatchStatus : int32_t { @@ -281,20 +285,35 @@ void Inspector::OnMessage(std::string&& msg) }); } else { #if defined(OHOS_PLATFORM) - debuggerPostTask_([tid = tidForSocketPair_, vm = vm_] { - if (tid != static_cast(syscall(SYS_gettid))) { + debuggerPostTask_([tid = tidForSocketPair_, vm = vm_, this] { + uint64_t threadOrTaskId = GetThreadOrTaskId(); + if (tid != static_cast(threadOrTaskId)) { LOGE("Task not in debugger thread for socketpair"); return; } g_processMessage(vm); }); -#endif +#endif // defined(OHOS_PLATFORM) } } else { LOGW("No debuggerPostTask provided"); } } +#if defined(OHOS_PLATFORM) +uint64_t Inspector::GetThreadOrTaskId() +{ + uint64_t threadOrTaskId = getproctid(); +#if defined(ENABLE_FFRT_INTERFACES) + threadOrTaskId = ffrt_this_task_get_id(); + if (threadOrTaskId == 0) { + threadOrTaskId = getproctid(); + } +#endif // defined(ENABLE_FFRT_INTERFACES) + return threadOrTaskId; +} +#endif // defined(OHOS_PLATFORM) + const DebuggerPostTask &GetDebuggerPostTask(int tid) { std::shared_lock lock(g_mutex); diff --git a/inspector/inspector.h b/inspector/inspector.h index f4f890db..893eac98 100644 --- a/inspector/inspector.h +++ b/inspector/inspector.h @@ -57,6 +57,9 @@ public: ~Inspector() = default; void OnMessage(std::string&& msg); +#if defined(OHOS_PLATFORM) + uint64_t GetThreadOrTaskId(); +#endif // defined(OHOS_PLATFORM) static constexpr int32_t DELAY_CHECK_DISPATCH_STATUS = 100; -- Gitee From 20c84568217a91cec3009cf4c379f6c9bc8ad2d8 Mon Sep 17 00:00:00 2001 From: Denis Silakov Date: Mon, 22 Jul 2024 14:01:33 +0300 Subject: [PATCH 22/51] Proper exit code for prebuilts_download Exit with non-zero code in case of download or uncompress problems. Allow configuring number of retry attempts in case of network issues. Issue: #IAERU7 Signed-off-by: Denis Silakov --- .../prebuilts_download/prebuilts_download.py | 102 ++++++++++++------ .../prebuilts_download_config.json | 1 + 2 files changed, 68 insertions(+), 35 deletions(-) diff --git a/build/prebuilts_download/prebuilts_download.py b/build/prebuilts_download/prebuilts_download.py index a4f11a19..c62d8e2d 100755 --- a/build/prebuilts_download/prebuilts_download.py +++ b/build/prebuilts_download/prebuilts_download.py @@ -88,7 +88,8 @@ def _uncompress(args, src_file, code_dir, unzip_dir, unzip_filename, mark_file_p cmd = 'tar -xvzf {} -C {};echo 0 > {}'.format(src_file, dest_dir, mark_file_path) else: cmd = 'tar -xvf {} -C {};echo 0 > {}'.format(src_file, dest_dir, mark_file_path) - _run_cmd(cmd) + _, _, returncode = _run_cmd(cmd) + return returncode def _copy_url(args, task_id, url, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path): # download files @@ -100,6 +101,7 @@ def _copy_url(args, task_id, url, local_file, code_dir, unzip_dir, unzip_filenam response = urlopen(url) except urllib.error.HTTPError as e: progress.console.log("Failed to open {}, HTTPError: {}".format(url, e.code), style='red') + return 1 progress.update(task_id, total=int(response.info()["Content-length"])) with os.fdopen(os.open(local_file, flags, modes), 'wb') as dest_file: progress.start_task(task_id) @@ -107,48 +109,73 @@ def _copy_url(args, task_id, url, local_file, code_dir, unzip_dir, unzip_filenam dest_file.write(data) progress.update(task_id, advance=len(data)) progress.console.log("Downloaded {}".format(local_file)) + if not _check_sha256(url, local_file): + progress.console.log('{}, Sha256 check download FAILED.'.format(local_file), style='red') + return 1 # decompressing files progress.console.log("Decompressing {}".format(local_file)) - _uncompress(args, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path) + returncode = _uncompress(args, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path) progress.console.log("Decompressed {}".format(local_file)) + return returncode -def _hwcloud_download(args, config, bin_dir, code_dir): + +def _hwcloud_download_wrapper(args, config, bin_dir, code_dir, retries): + attempt = 0 + success = False + with progress: + while not success and attempt < retries: + success = _hwcloud_download(args, config, bin_dir, code_dir, retries) + attempt += 1 + return success + + +def _hwcloud_download(args, config, bin_dir, code_dir, retries): try: cnt = cpu_count() except: cnt = 1 - with progress: - with ThreadPoolExecutor(max_workers=cnt) as pool: - tasks = dict() - for config_info in config: - unzip_dir, huaweicloud_url, unzip_filename, md5_huaweicloud_url, bin_file = _config_parse(config_info, - args.tool_repo) - abs_unzip_dir = os.path.join(code_dir, unzip_dir) - if not os.path.exists(abs_unzip_dir): - os.makedirs(abs_unzip_dir) - if _check_sha256_by_mark(args, huaweicloud_url, code_dir, unzip_dir, unzip_filename): - progress.console.log('{}, Sha256 markword check OK.'.format(huaweicloud_url), style='green') - else: - _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/*.', unzip_filename, '.mark'])) - _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/', unzip_filename])) - local_file = os.path.join(bin_dir, ''.join([md5_huaweicloud_url, '.', bin_file])) - if os.path.exists(local_file): - if _check_sha256(huaweicloud_url, local_file): - progress.console.log('{}, Sha256 check download OK.'.format(local_file), style='green') - task = pool.submit(_uncompress, args, local_file, code_dir, unzip_dir, unzip_filename, - args.mark_file_path) - tasks[task] = os.path.basename(huaweicloud_url) - else: - os.remove(local_file) - else: - filename = huaweicloud_url.split("/")[-1] - task_id = progress.add_task("download", filename=filename, start=False) - task = pool.submit(_copy_url, args, task_id, huaweicloud_url, local_file, code_dir, unzip_dir, - unzip_filename, args.mark_file_path) - tasks[task] = os.path.basename(huaweicloud_url) - for task in as_completed(tasks): - progress.console.log('{}, download and decompress completed'.format(tasks.get(task)), style='green') + + success = False + with ThreadPoolExecutor(max_workers=cnt) as pool: + tasks = dict() + for config_info in config: + unzip_dir, huaweicloud_url, unzip_filename, md5_huaweicloud_url, bin_file = _config_parse(config_info, + args.tool_repo) + abs_unzip_dir = os.path.join(code_dir, unzip_dir) + if not os.path.exists(abs_unzip_dir): + os.makedirs(abs_unzip_dir) + if _check_sha256_by_mark(args, huaweicloud_url, code_dir, unzip_dir, unzip_filename): + progress.console.log('{}, Sha256 markword check OK.'.format(huaweicloud_url), style='green') + continue + + _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/*.', unzip_filename, '.mark'])) + _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/', unzip_filename])) + local_file = os.path.join(bin_dir, ''.join([md5_huaweicloud_url, '.', bin_file])) + if not os.path.exists(local_file): + filename = huaweicloud_url.split("/")[-1] + task_id = progress.add_task("download", filename=filename, start=False) + task = pool.submit(_copy_url, args, task_id, huaweicloud_url, local_file, code_dir, unzip_dir, + unzip_filename, args.mark_file_path) + tasks[task] = os.path.basename(huaweicloud_url) + continue + + if _check_sha256(huaweicloud_url, local_file): + progress.console.log('{}, Sha256 check download OK.'.format(local_file), style='green') + task = pool.submit(_uncompress, args, local_file, code_dir, unzip_dir, unzip_filename, + args.mark_file_path) + tasks[task] = os.path.basename(huaweicloud_url) + else: + os.remove(local_file) + returncode = 0 + for task in as_completed(tasks): + if task.result(): + returncode += task.result() + progress.console.log('{}, download and decompress completed, exit code: {}' + .format(tasks.get(task), task.result()), style='green') + success = returncode == 0 + return success + def _file_handle(config, code_dir): for config_info in config: @@ -203,8 +230,13 @@ def main(): elif host_platform == 'darwin': darwin_copy_config = config_info.get(host_platform).get(host_cpu).get('darwin_copy_config') copy_config.extend(darwin_copy_config) - _hwcloud_download(args, copy_config, args.bin_dir, args.code_dir) + retries = config_info.get('retries') + args.retries = 1 if retries is None else retries + if not _hwcloud_download_wrapper(args, copy_config, args.bin_dir, args.code_dir, args.retries): + return 1 _file_handle(file_handle_config, args.code_dir) + return 0 + if __name__ == '__main__': sys.exit(main()) diff --git a/build/prebuilts_download/prebuilts_download_config.json b/build/prebuilts_download/prebuilts_download_config.json index 12f96850..f427f90e 100644 --- a/build/prebuilts_download/prebuilts_download_config.json +++ b/build/prebuilts_download/prebuilts_download_config.json @@ -1,5 +1,6 @@ { "prebuilts_download_dir": "../openharmony_prebuilts", + "retries": 3, "file_handle_config": [ { "src": "/prebuilts/clang/ohos/linux-x86_64/clang_linux-x86_64-ef68e8-20240229", -- Gitee From 9bd899ed72604fbe9cd923d691da4fe61b71bdec Mon Sep 17 00:00:00 2001 From: karenonni Date: Wed, 24 Jul 2024 06:32:37 +0000 Subject: [PATCH 23/51] add arm64 test262 Issue: IAF90X Signed-off-by: karenonni Change-Id: I6e3c2316c4127054dd79b412d2b772edc8a2c44f --- build/compile_script/ark.py | 114 +++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index f378adb4..c5a83d6b 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -309,56 +309,71 @@ class ArkPy: return False @staticmethod - def get_test262_cmd(gn_args, out_path, x64_out_path, aot_mode, run_pgo, enable_litecg, args_to_test262_cmd, + def get_test262_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, timeout): - if aot_mode: - print("running test262 in AotMode\n") - if any('target_cpu="arm64"' in arg for arg in gn_args): - if run_pgo: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {4}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ - "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-arch aarch64" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-aot" \ - " --ark-frontend=es2panda"\ - "{3}".format(args_to_test262_cmd, out_path, x64_out_path, " --run-pgo", timeout) - else: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{2}/thirdparty/icu/" \ - " --ark-arch aarch64" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + + print("running test262 in AsmMode\n") + if any('target_cpu="arm64"' in arg for arg in gn_args): + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ + "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --ark-arch aarch64" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path) + else: + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {2}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, timeout) + return test262_cmd + + @staticmethod + def get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, + timeout): + print("running test262 in AotMode\n") + if any('target_cpu="arm64"' in arg for arg in gn_args): + if run_pgo: + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {4}" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ + "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --ark-arch aarch64" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-aot" \ + " --ark-frontend=es2panda"\ + "{3}".format(args_to_test262_cmd, out_path, x64_out_path, " --run-pgo", timeout) else: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ - ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-aot" \ - " --ark-frontend=es2panda"\ - "{2}".format(args_to_test262_cmd, out_path, " --run-pgo" if run_pgo else "", timeout) - if enable_litecg: - test262_cmd = test262_cmd + " --enable-litecg" + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{2}/thirdparty/icu/" \ + " --ark-arch aarch64" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) else: - print("running test262 in AsmMode\n") - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {2}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, timeout) + test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ + ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-aot" \ + " --ark-frontend=es2panda"\ + "{2}".format(args_to_test262_cmd, out_path, " --run-pgo" if run_pgo else "", timeout) + if enable_litecg: + test262_cmd = test262_cmd + " --enable-litecg" return test262_cmd @staticmethod @@ -732,9 +747,12 @@ class ArkPy: elif run_baseline_jit: test262_cmd = self.get_test262_baseline_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout) + elif aot_mode: + test262_cmd = self.get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, + timeout) else: - test262_cmd = self.get_test262_cmd(gn_args, out_path, x64_out_path, aot_mode, run_pgo, - enable_litecg, args_to_test262_cmd, timeout) + test262_cmd = self.get_test262_cmd(gn_args, out_path, x64_out_path, run_pgo, + enable_litecg, args_to_test262_cmd, timeout) test262_log_path = os.path.join(out_path, log_file_name) str_to_test262_log = "================================\ntest262_time: {0}\ntest262_target: {1}\n\n".format( str_of_time_now(), args_to_test262_cmd) -- Gitee From d743ac0d4163b92c4f4b332bc1aad2ffa76a7657 Mon Sep 17 00:00:00 2001 From: karenonni Date: Thu, 25 Jul 2024 02:06:51 +0000 Subject: [PATCH 24/51] Support to run workload in interpreter mod Issue: IAFA4L Signed-off-by: karenonni Change-Id: I7e5e0f61e9a2b95612243207ad44ca7836aece1f --- build/compile_script/ark.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index c5a83d6b..53faada5 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -893,6 +893,7 @@ class ArkPy: boundary_value = '-10' run_count = '10' code_v = '' + run_interpreter = False if len(arg_list) >= 2 and arg_list[1] == 'report': report = True if len(arg_list) >= 3 and arg_list[2]: @@ -903,6 +904,8 @@ class ArkPy: run_count = arg_list[4] if len(arg_list) >= 6 and arg_list[5]: code_v = arg_list[5] + if len(arg_list) >= 7 and arg_list[6] == '--run-interpreter': + run_interpreter = True self.build_for_gn_target(out_path, gn_args, ["default"], self.GN_TARGET_LOG_FILE_NAME) workload_cmd = "cd arkcompiler/ets_runtime/test/workloadtest/ && python3 work_load.py" \ " --code-path {0}" \ @@ -912,6 +915,8 @@ class ArkPy: " --run-count {4}" \ " --code-v {5}" \ .format(root_dir, report, tools, boundary_value, run_count, code_v) + if run_interpreter: + workload_cmd += " --run-interpreter true" workload_log_path = os.path.join(out_path, log_file_name) str_to_workload_log = "================================\nwokload_time: {0}\nwokload_target: {1}\n\n".format( str_of_time_now(), 'file') -- Gitee From d2bb01df5adc266aa9176fdc4625f9bb1b42d736 Mon Sep 17 00:00:00 2001 From: daiweihao Date: Fri, 26 Jul 2024 20:14:20 +0800 Subject: [PATCH 25/51] Fix WebSocketTest testcase After disconnecting the test case, resources will remain for a period of time and the port cannot be released. If a connection is established in other use cases in the future, it will result in connection failure. Therefore, after disconnecting, let the program sleep for 3 seconds to ensure the release of resources. Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAFVKU Signed-off-by: daiweihao Change-Id: Ic06e91b987720b4fa0db5d0779490040bb91b1c8 --- websocket/test/websocket_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/websocket/test/websocket_test.cpp b/websocket/test/websocket_test.cpp index 9ff86380..55774f96 100644 --- a/websocket/test/websocket_test.cpp +++ b/websocket/test/websocket_test.cpp @@ -219,6 +219,7 @@ HWTEST_F(WebSocketTest, DISABLED_ReConnectWebSocketTest, testing::ext::TestSize. } } serverSocket.Close(); + sleep(3); } HWTEST_F(WebSocketTest, DISABLED_ClientAbnormalTest, testing::ext::TestSize.Level0) @@ -274,6 +275,7 @@ HWTEST_F(WebSocketTest, DISABLED_ServerAbnormalTest, testing::ext::TestSize.Leve }; serverSocket.SetValidateConnectionCallback(notValidCallBack); ASSERT_FALSE(serverSocket.AcceptNewConnection()); + sleep(3); } else { std::cerr << "ServerAbnormalTest::fork failed, error = " << errno << ", desc = " << strerror(errno) << std::endl; -- Gitee From 598677b2a76bb93d546aa9f4a47fb2b91e4cfb63 Mon Sep 17 00:00:00 2001 From: liu-zelin Date: Fri, 26 Jul 2024 14:39:14 +0800 Subject: [PATCH 26/51] Fix clean code warnning Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAFKGK?from=project-issue Signed-off-by: liu-zelin Change-Id: Ifd6c4c170ec0902ff44c2eb805dd8662b5ec69ea --- tooling/agent/runtime_impl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index ee07472a..2cd0c683 100644 --- a/tooling/agent/runtime_impl.cpp +++ b/tooling/agent/runtime_impl.cpp @@ -600,13 +600,13 @@ void RuntimeImpl::GetSharedMapValue(Local value, std::vector> *outPropertyDesc) { Local sendableMapRef(value); - int32_t size = sendableMapRef->GetSize(vm_); - int32_t len = sendableMapRef->GetTotalElements(vm_); - int32_t index = 0; + uint32_t size = sendableMapRef->GetSize(vm_); + uint32_t len = sendableMapRef->GetTotalElements(vm_); + uint32_t index = 0; Local jsValueRef = NumberRef::New(vm_, size); SetKeyValue(jsValueRef, outPropertyDesc, "size"); jsValueRef = ArrayRef::New(vm_, size); - for (int32_t i = 0; i < len; ++i) { + for (uint32_t i = 0; i < len; ++i) { Local jsKey = sendableMapRef->GetKey(vm_, i); if (jsKey->IsHole()) { continue; -- Gitee From 49214450baa8d91a4d666072500010b79b244fef Mon Sep 17 00:00:00 2001 From: Denis Slynko Date: Tue, 2 Jul 2024 15:08:09 +0300 Subject: [PATCH 27/51] Fix issues with data races and shutdown Description: - Shutdown sockets on all platforms, which prevents hanging on reads after closing the socket - Fix data races on `connectionFd_` and `serverFd_` Issue: IAA1Y7 Signed-off-by: Denis Slynko --- inspector/ws_server.cpp | 2 - websocket/client/websocket_client.cpp | 158 ++++++++++-------- websocket/client/websocket_client.h | 25 ++- websocket/server/README.md | 71 ++++++++ websocket/server/websocket_server.cpp | 232 +++++++++++++++++++------- websocket/server/websocket_server.h | 98 +++++++++-- websocket/test/websocket_test.cpp | 2 +- websocket/websocket_base.cpp | 187 ++++++++++++++++----- websocket/websocket_base.h | 130 +++++++++++---- 9 files changed, 678 insertions(+), 227 deletions(-) create mode 100644 websocket/server/README.md diff --git a/inspector/ws_server.cpp b/inspector/ws_server.cpp index 9d6ee164..0a77d285 100644 --- a/inspector/ws_server.cpp +++ b/inspector/ws_server.cpp @@ -116,9 +116,7 @@ void WsServer::StopServer() webSocket_->Close(); } } -#if defined(OHOS_PLATFORM) pthread_join(tid_, nullptr); -#endif if (webSocket_ != nullptr) { webSocket_.reset(); } diff --git a/websocket/client/websocket_client.cpp b/websocket/client/websocket_client.cpp index f8d0f918..4900c6cf 100644 --- a/websocket/client/websocket_client.cpp +++ b/websocket/client/websocket_client.cpp @@ -27,25 +27,65 @@ #include "client/websocket_client.h" namespace OHOS::ArkCompiler::Toolchain { +static bool ValidateServerHandShake(HttpResponse& response) +{ + static constexpr std::string_view HTTP_SWITCHING_PROTOCOLS_STATUS_CODE = "101"; + static constexpr std::string_view HTTP_RESPONSE_REQUIRED_UPGRADE = "websocket"; + static constexpr std::string_view HTTP_RESPONSE_REQUIRED_CONNECTION = "upgrade"; + // NB! `defaultWebSocketKey` must match "Sec-WebSocket-Key" used in `WebSocketClient`. + static constexpr unsigned char defaultWebSocketKey[] = "64b4B+s5JDlgkdg7NekJ+g=="; + + // in accordance to https://www.rfc-editor.org/rfc/rfc6455#section-4.1 + if (response.status != HTTP_SWITCHING_PROTOCOLS_STATUS_CODE) { + return false; + } + ToLowerCase(response.upgrade); + if (response.upgrade != HTTP_RESPONSE_REQUIRED_UPGRADE) { + return false; + } + ToLowerCase(response.connection); + if (response.connection != HTTP_RESPONSE_REQUIRED_CONNECTION) { + return false; + } + + // The same WebSocket-Key is used for all connections + // - must either use a randomly-selected, as required by spec or do this calculation statically. + unsigned char expectedSecWebSocketAccept[WebSocketKeyEncoder::ENCODED_KEY_LEN + 1]; + if (!WebSocketKeyEncoder::EncodeKey(defaultWebSocketKey, expectedSecWebSocketAccept)) { + LOGE("ValidateServerHandShake failed to generate expected Sec-WebSocket-Accept token"); + return false; + } + + Trim(response.secWebSocketAccept); + if (response.secWebSocketAccept.size() != WebSocketKeyEncoder::ENCODED_KEY_LEN || + response.secWebSocketAccept.compare(reinterpret_cast(expectedSecWebSocketAccept)) != 0) { + return false; + } + + // may support two remaining checks + return true; +} + bool WebSocketClient::InitToolchainWebSocketForPort(int port, uint32_t timeoutLimit) { - if (socketState_ != SocketState::UNINITED) { + if (GetConnectionState() != ConnectionState::CLOSED) { LOGE("InitToolchainWebSocketForPort::client has inited."); return true; } - connectionFd_ = socket(AF_INET, SOCK_STREAM, 0); - if (connectionFd_ < SOCKET_SUCCESS) { + int connection = socket(AF_INET, SOCK_STREAM, 0); + if (connection < SOCKET_SUCCESS) { LOGE("InitToolchainWebSocketForPort::client socket failed, error = %{public}d , desc = %{public}s", errno, strerror(errno)); return false; } + SetConnectionSocket(connection); // set send and recv timeout limit - if (!SetWebSocketTimeOut(connectionFd_, timeoutLimit)) { + if (!SetWebSocketTimeOut(connection, timeoutLimit)) { LOGE("InitToolchainWebSocketForPort::client SetWebSocketTimeOut failed, error = %{public}d , desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } @@ -53,7 +93,7 @@ bool WebSocketClient::InitToolchainWebSocketForPort(int port, uint32_t timeoutLi if (memset_s(&clientAddr, sizeof(clientAddr), 0, sizeof(clientAddr)) != EOK) { LOGE("InitToolchainWebSocketForPort::client memset_s clientAddr failed, error = %{public}d, desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } clientAddr.sin_family = AF_INET; @@ -62,42 +102,43 @@ bool WebSocketClient::InitToolchainWebSocketForPort(int port, uint32_t timeoutLi if (ret != NET_SUCCESS) { LOGE("InitToolchainWebSocketForPort::client inet_pton failed, error = %{public}d, desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } - ret = connect(connectionFd_, reinterpret_cast(&clientAddr), sizeof(clientAddr)); + ret = connect(connection, reinterpret_cast(&clientAddr), sizeof(clientAddr)); if (ret != SOCKET_SUCCESS) { LOGE("InitToolchainWebSocketForPort::client connect failed, error = %{public}d, desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } - socketState_ = SocketState::INITED; + SetConnectionState(ConnectionState::CONNECTING); LOGI("InitToolchainWebSocketForPort::client connect success."); return true; } bool WebSocketClient::InitToolchainWebSocketForSockName(const std::string &sockName, uint32_t timeoutLimit) { - if (socketState_ != SocketState::UNINITED) { + if (GetConnectionState() != ConnectionState::CLOSED) { LOGE("InitToolchainWebSocketForSockName::client has inited."); return true; } - connectionFd_ = socket(AF_UNIX, SOCK_STREAM, 0); - if (connectionFd_ < SOCKET_SUCCESS) { + int connection = socket(AF_UNIX, SOCK_STREAM, 0); + if (connection < SOCKET_SUCCESS) { LOGE("InitToolchainWebSocketForSockName::client socket failed, error = %{public}d , desc = %{public}s", errno, strerror(errno)); return false; } + SetConnectionSocket(connection); // set send and recv timeout limit - if (!SetWebSocketTimeOut(connectionFd_, timeoutLimit)) { + if (!SetWebSocketTimeOut(connection, timeoutLimit)) { LOGE("InitToolchainWebSocketForSockName::client SetWebSocketTimeOut failed, " "error = %{public}d, desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } @@ -106,7 +147,7 @@ bool WebSocketClient::InitToolchainWebSocketForSockName(const std::string &sockN LOGE("InitToolchainWebSocketForSockName::client memset_s clientAddr failed, " "error = %{public}d, desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } serverAddr.sun_family = AF_UNIX; @@ -114,40 +155,41 @@ bool WebSocketClient::InitToolchainWebSocketForSockName(const std::string &sockN LOGE("InitToolchainWebSocketForSockName::client strcpy_s serverAddr.sun_path failed, " "error = %{public}d, desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } serverAddr.sun_path[0] = '\0'; uint32_t len = offsetof(struct sockaddr_un, sun_path) + strlen(sockName.c_str()) + 1; - int ret = connect(connectionFd_, reinterpret_cast(&serverAddr), static_cast(len)); + int ret = connect(connection, reinterpret_cast(&serverAddr), static_cast(len)); if (ret != SOCKET_SUCCESS) { LOGE("InitToolchainWebSocketForSockName::client connect failed, error = %{public}d, desc = %{public}s", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } - socketState_ = SocketState::INITED; + SetConnectionState(ConnectionState::CONNECTING); LOGI("InitToolchainWebSocketForSockName::client connect success."); return true; } bool WebSocketClient::ClientSendWSUpgradeReq() { - if (socketState_ == SocketState::UNINITED) { + auto state = GetConnectionState(); + if (state == ConnectionState::CLOSING || state == ConnectionState::CLOSED) { LOGE("ClientSendWSUpgradeReq::client has not inited."); return false; } - if (socketState_ == SocketState::CONNECTED) { + if (state == ConnectionState::OPEN) { LOGE("ClientSendWSUpgradeReq::client has connected."); return true; } // length without null-terminator - if (!Send(connectionFd_, CLIENT_WEBSOCKET_UPGRADE_REQ, sizeof(CLIENT_WEBSOCKET_UPGRADE_REQ) - 1, 0)) { + if (!Send(GetConnectionSocket(), CLIENT_WEBSOCKET_UPGRADE_REQ, sizeof(CLIENT_WEBSOCKET_UPGRADE_REQ) - 1, 0)) { LOGE("ClientSendWSUpgradeReq::client send wsupgrade req failed, error = %{public}d, desc = %{public}sn", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } LOGI("ClientSendWSUpgradeReq::client send wsupgrade req success."); @@ -156,25 +198,26 @@ bool WebSocketClient::ClientSendWSUpgradeReq() bool WebSocketClient::ClientRecvWSUpgradeRsp() { - if (socketState_ == SocketState::UNINITED) { + auto state = GetConnectionState(); + if (state == ConnectionState::CLOSING || state == ConnectionState::CLOSED) { LOGE("ClientRecvWSUpgradeRsp::client has not inited."); return false; } - if (socketState_ == SocketState::CONNECTED) { + if (state == ConnectionState::OPEN) { LOGE("ClientRecvWSUpgradeRsp::client has connected."); return true; } std::string msgBuf(HTTP_HANDSHAKE_MAX_LEN, 0); ssize_t msgLen = 0; - while ((msgLen = recv(connectionFd_, msgBuf.data(), HTTP_HANDSHAKE_MAX_LEN, 0)) < 0 && + while ((msgLen = recv(GetConnectionSocket(), msgBuf.data(), HTTP_HANDSHAKE_MAX_LEN, 0)) < 0 && (errno == EINTR || errno == EAGAIN)) { LOGW("ClientRecvWSUpgradeRsp::client recv wsupgrade rsp failed, errno = %{public}d", errno); } if (msgLen <= 0) { LOGE("ClientRecvWSUpgradeRsp::client recv wsupgrade rsp failed, error = %{public}d, desc = %{public}sn", errno, strerror(errno)); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } // reduce to received size @@ -183,52 +226,18 @@ bool WebSocketClient::ClientRecvWSUpgradeRsp() HttpResponse response; if (!HttpResponse::Decode(msgBuf, response) || !ValidateServerHandShake(response)) { LOGE("ClientRecvWSUpgradeRsp::client server handshake response is invalid"); - CloseConnectionSocketOnFail(); + CloseOnInitFailure(); return false; } - socketState_ = SocketState::CONNECTED; + SetConnectionState(ConnectionState::OPEN); LOGI("ClientRecvWSUpgradeRsp::client recv wsupgrade rsp success."); return true; } std::string WebSocketClient::GetSocketStateString() { - return std::string(SOCKET_STATE_NAMES[EnumToNumber(socketState_.load())]); -} - -/* static */ -bool WebSocketClient::ValidateServerHandShake(HttpResponse& response) -{ - // in accordance to https://www.rfc-editor.org/rfc/rfc6455#section-4.1 - if (response.status != HTTP_SWITCHING_PROTOCOLS_STATUS_CODE) { - return false; - } - ToLowerCase(response.upgrade); - if (response.upgrade != HTTP_RESPONSE_REQUIRED_UPGRADE) { - return false; - } - ToLowerCase(response.connection); - if (response.connection != HTTP_RESPONSE_REQUIRED_CONNECTION) { - return false; - } - - // The same WebSocket-Key is used for all connections - // - must either use a randomly-selected, as required by spec or do this calculation statically. - unsigned char expectedSecWebSocketAccept_[WebSocketKeyEncoder::ENCODED_KEY_LEN + 1]; - if (!WebSocketKeyEncoder::EncodeKey(DEFAULT_WEB_SOCKET_KEY, expectedSecWebSocketAccept_)) { - LOGE("ValidateServerHandShake::client failed to generate expected Sec-WebSocket-Accept token"); - return false; - } - - Trim(response.secWebSocketAccept); - if (response.secWebSocketAccept.size() != WebSocketKeyEncoder::ENCODED_KEY_LEN || - response.secWebSocketAccept.compare(reinterpret_cast(expectedSecWebSocketAccept_)) != 0) { - return false; - } - - // may support two remaining checks - return true; + return std::string(SOCKET_STATE_NAMES[EnumToNumber(GetConnectionState())]); } bool WebSocketClient::DecodeMessage(WebSocketFrame& wsFrame) const @@ -241,7 +250,7 @@ bool WebSocketClient::DecodeMessage(WebSocketFrame& wsFrame) const auto& buffer = wsFrame.payload; buffer.resize(msgLen, 0); - if (!Recv(connectionFd_, buffer, 0)) { + if (!RecvUnderLock(buffer)) { LOGE("DecodeMessage: Recv message without mask failed"); return false; } @@ -251,17 +260,24 @@ bool WebSocketClient::DecodeMessage(WebSocketFrame& wsFrame) const void WebSocketClient::Close() { - if (socketState_ == SocketState::CONNECTED) { - CloseConnection(CloseStatusCode::SERVER_GO_AWAY, SocketState::UNINITED); + if (!CloseConnection(CloseStatusCode::SERVER_GO_AWAY)) { + LOGW("Failed to close WebSocketClient"); } } -void WebSocketClient::CloseConnectionSocketOnFail() +void WebSocketClient::CloseOnInitFailure() { - CloseConnectionSocket(ConnectionCloseReason::FAIL, SocketState::UNINITED); + // Must be in `CONNECTING` or `CLOSED` state. + auto expected = ConnectionState::CONNECTING; + if (!CompareExchangeConnectionState(expected, ConnectionState::CLOSING) && + expected != ConnectionState::CLOSED) { + LOGE("CloseOnInitFailure violation: must be either CONNECTING or CLOSED, but got %{public}d", + EnumToNumber(expected)); + } + CloseConnectionSocket(ConnectionCloseReason::FAIL); } -bool WebSocketClient::ValidateIncomingFrame(const WebSocketFrame& wsFrame) +bool WebSocketClient::ValidateIncomingFrame(const WebSocketFrame& wsFrame) const { // "A server MUST NOT mask any frames that it sends to the client." // https://www.rfc-editor.org/rfc/rfc6455#section-5.1 diff --git a/websocket/client/websocket_client.h b/websocket/client/websocket_client.h index 5a50d413..ded6a969 100644 --- a/websocket/client/websocket_client.h +++ b/websocket/client/websocket_client.h @@ -30,8 +30,7 @@ class WebSocketClient final : public WebSocketBase { public: ~WebSocketClient() noexcept override = default; - bool DecodeMessage(WebSocketFrame& wsFrame) const override; - void Close() override; + void Close(); bool InitToolchainWebSocketForPort(int port, uint32_t timeoutLimit = 5); bool InitToolchainWebSocketForSockName(const std::string &sockName, uint32_t timeoutLimit = 5); @@ -41,27 +40,23 @@ public: std::string GetSocketStateString(); private: - static bool ValidateServerHandShake(HttpResponse& response); + bool DecodeMessage(WebSocketFrame& wsFrame) const override; - void CloseConnectionSocketOnFail(); - bool ValidateIncomingFrame(const WebSocketFrame& wsFrame) override; + void CloseOnInitFailure(); + bool ValidateIncomingFrame(const WebSocketFrame& wsFrame) const override; std::string CreateFrame(bool isLast, FrameType frameType) const override; std::string CreateFrame(bool isLast, FrameType frameType, const std::string& payload) const override; std::string CreateFrame(bool isLast, FrameType frameType, std::string&& payload) const override; private: - static constexpr std::array SOCKET_STATE_NAMES = { - "uninited", - "inited", - "connected" + static constexpr std::array SOCKET_STATE_NAMES = { + "connecting", + "open", + "closing", + "closed" }; - static constexpr std::string_view HTTP_SWITCHING_PROTOCOLS_STATUS_CODE = "101"; - static constexpr std::string_view HTTP_RESPONSE_REQUIRED_UPGRADE = "websocket"; - static constexpr std::string_view HTTP_RESPONSE_REQUIRED_CONNECTION = "upgrade"; - - // may replace default websocket-key with randomly generated, as required by spec - static constexpr unsigned char DEFAULT_WEB_SOCKET_KEY[] = "64b4B+s5JDlgkdg7NekJ+g=="; + // May replace default websocket-key with randomly generated, as required by spec. static constexpr char CLIENT_WEBSOCKET_UPGRADE_REQ[] = "GET / HTTP/1.1\r\n" "Connection: Upgrade\r\n" "Pragma: no-cache\r\n" diff --git a/websocket/server/README.md b/websocket/server/README.md new file mode 100644 index 00000000..53ef0036 --- /dev/null +++ b/websocket/server/README.md @@ -0,0 +1,71 @@ +# WebSocketServer + +Class `WebSocketServer` represents: +* Server endpoint accepting new `WebSocket` connections, +* Single connection with client, encapsulated in `WebSocketBase` class. + +All operations operations of the class (e.g. accepting new connection or receiving new messages) are blocking. Hence typical usage cases imply initializing server and starting a distinct _server thread_, which will: +* Call `AcceptNewConnection` when there is no active connection; +* Until the connection is ended in loop call `Decode`, handle the incoming message and reply with `SendReply`. + +The connection might terminate either from client side or by call to `CloseConnection` (gracefully closes connection according to specification) or `Close` (will close both endpoint and active connection). + +Interface is designed with trade safety, and all _external threads_ are able to call `SendReply`, `CloseConnection` and `Close`. Note that `SendReply` from an _external thread_ might happen concurrently with `CloseConnection` and `AcceptNewConnection`, so the message might be send to the new connection. To prevent such unexpected behavior, the _external thread_ can set callbacks to be triggered before the connection is finally closed, which is done with `SetCloseConnectionCallback` and `SetFailConnectionCallback` methods. + +The following diagram sums up separation of concerns between server and external threads: + +```mermaid +sequenceDiagram + participant ExternalThread + participant ServerThread + participant WebSocketServer + participant RemoteClient + + ExternalThread->>WebSocketServer: InitUnixWebSocket() + ExternalThread->>ServerThread: spawn + par While server thread running + ServerThread->>WebSocketServer: AcceptNewConnection() + RemoteClient->>WebSocketServer: accept() + loop while connected + ServerThread->>WebSocketServer: Decode() + RemoteClient->>WebSocketServer: recv() + alt Successful recv + alt Close frame + WebSocketServer->>WebSocketServer: CloseConnection() + else Data Frame + ServerThread->>ServerThread: DoHandlingLogic() + ServerThread->>WebSocketServer: SendReply() + WebSocketServer->>RemoteClient: send() + end + else Failed recv + WebSocketServer->>WebSocketServer: CloseConnection() + end + end + and While external thread running + loop On event + ExternalThread->>WebSocketServer: SendReply() + WebSocketServer->>RemoteClient: send() + end + ExternalThread->>WebSocketServer: Close() + WebSocketServer->>WebSocketServer: stop accepting, wait if active Connecting state + WebSocketServer->>WebSocketServer: CloseConnection() + end +``` + +## Connection + +`WebSocketServer` incapsulates an active connection with a client. Methods `Decode`, `SendReply`, `CloseConnection` relate to a currently active connection (if any presents). Class maintains connection's state according to RFC6455: + +```mermaid +stateDiagram-v2 + state Connecting + state Open + state Closing + state Closed + + Closed --> Connecting : call AcceptNewConnection() + Connecting --> Open : HttpHandShake() success + Connecting --> Closed : HttpHandShake() failure + Open --> Closing : call CloseConnection() + Closing --> Closed : call CloseConnectionSocket() +``` diff --git a/websocket/server/websocket_server.cpp b/websocket/server/websocket_server.cpp index 208cd9a3..f06201a9 100644 --- a/websocket/server/websocket_server.cpp +++ b/websocket/server/websocket_server.cpp @@ -13,13 +13,11 @@ * limitations under the License. */ -#if !defined(OHOS_PLATFORM) #if defined(PANDA_TARGET_WINDOWS) #include #else #include #endif -#endif #include #include "common/log_wrapper.h" @@ -27,11 +25,35 @@ #include "handshake_helper.h" #include "network.h" #include "server/websocket_server.h" +#include "string_utils.h" + +#include +#include namespace OHOS::ArkCompiler::Toolchain { +static bool ValidateHandShakeMessage(const HttpRequest& req) +{ + std::string upgradeHeaderValue = req.upgrade; + // Switch to lower case in order to support obsolete versions of WebSocket protocol. + ToLowerCase(upgradeHeaderValue); + return req.connection.find("Upgrade") != std::string::npos && + upgradeHeaderValue.find("websocket") != std::string::npos && + req.version.compare("HTTP/1.1") == 0; +} + +WebSocketServer::~WebSocketServer() noexcept +{ + if (serverFd_ != -1) { + LOGW("WebSocket server is closed while destructing the object"); + close(serverFd_); + // Reset directly in order to prevent static analyzer warnings. + serverFd_ = -1; + } +} + bool WebSocketServer::DecodeMessage(WebSocketFrame& wsFrame) const { - uint64_t msgLen = wsFrame.payloadLen; + const uint64_t msgLen = wsFrame.payloadLen; if (msgLen == 0) { // receiving empty data is OK return true; @@ -39,18 +61,18 @@ bool WebSocketServer::DecodeMessage(WebSocketFrame& wsFrame) const auto& buffer = wsFrame.payload; buffer.resize(msgLen, 0); - if (!Recv(connectionFd_, wsFrame.maskingKey, sizeof(wsFrame.maskingKey), 0)) { + if (!RecvUnderLock(wsFrame.maskingKey, sizeof(wsFrame.maskingKey))) { LOGE("DecodeMessage: Recv maskingKey failed"); return false; } - if (!Recv(connectionFd_, buffer, 0)) { + if (!RecvUnderLock(buffer)) { LOGE("DecodeMessage: Recv message with mask failed"); return false; } for (uint64_t i = 0; i < msgLen; i++) { - auto j = i % WebSocketFrame::MASK_LEN; + const auto j = i % WebSocketFrame::MASK_LEN; buffer[i] = static_cast(buffer[i]) ^ wsFrame.maskingKey[j]; } @@ -66,7 +88,7 @@ bool WebSocketServer::ProtocolUpgrade(const HttpRequest& req) } ProtocolUpgradeBuilder requestBuilder(encodedKey); - if (!Send(connectionFd_, requestBuilder.GetUpgradeMessage(), requestBuilder.GetLength(), 0)) { + if (!SendUnderLock(requestBuilder.GetUpgradeMessage(), requestBuilder.GetLength())) { LOGE("ProtocolUpgrade: Send failed"); return false; } @@ -75,17 +97,20 @@ bool WebSocketServer::ProtocolUpgrade(const HttpRequest& req) bool WebSocketServer::ResponseInvalidHandShake() const { - std::string response(BAD_REQUEST_RESPONSE); - return Send(connectionFd_, response, 0); + const std::string response(BAD_REQUEST_RESPONSE); + return SendUnderLock(response); } bool WebSocketServer::HttpHandShake() { std::string msgBuf(HTTP_HANDSHAKE_MAX_LEN, 0); ssize_t msgLen = 0; - while ((msgLen = recv(connectionFd_, msgBuf.data(), HTTP_HANDSHAKE_MAX_LEN, 0)) < 0 && - (errno == EINTR || errno == EAGAIN)) { - LOGW("HttpHandShake recv failed, errno = %{public}d", errno); + { + std::shared_lock lock(GetConnectionMutex()); + while ((msgLen = recv(GetConnectionSocket(), msgBuf.data(), HTTP_HANDSHAKE_MAX_LEN, 0)) < 0 && + (errno == EINTR || errno == EAGAIN)) { + LOGW("HttpHandShake recv failed, errno = %{public}d", errno); + } } if (msgLen <= 0) { LOGE("ReadMsg failed, msgLen = %{public}ld, errno = %{public}d", static_cast(msgLen), errno); @@ -115,47 +140,86 @@ bool WebSocketServer::HttpHandShake() return false; } -/* static */ -bool WebSocketServer::ValidateHandShakeMessage(const HttpRequest& req) +bool WebSocketServer::MoveToConnectingState() { - return req.connection.find("Upgrade") != std::string::npos && - req.upgrade.find("websocket") != std::string::npos && - req.version.compare("HTTP/1.1") == 0; + if (!serverUp_.load()) { + // Server `Close` happened, must not accept new connections. + return false; + } + auto expected = ConnectionState::CLOSED; + if (!CompareExchangeConnectionState(expected, ConnectionState::CONNECTING)) { + switch (expected) { + case ConnectionState::CLOSING: + LOGW("MoveToConnectingState during closing connection"); + break; + case ConnectionState::OPEN: + LOGW("MoveToConnectingState during already established connection"); + break; + case ConnectionState::CONNECTING: + LOGE("MoveToConnectingState during opening connection, which violates WebSocketServer guarantees"); + break; + default: + break; + } + return false; + } + // Must check once again because of `Close` method implementation. + if (!serverUp_.load()) { + // Server `Close` happened, `serverFd_` was closed, new connection must not be opened. + expected = SetConnectionState(ConnectionState::CLOSED); + if (expected != ConnectionState::CONNECTING) { + LOGE("AcceptNewConnection: Close guarantees violated"); + } + return false; + } + return true; } bool WebSocketServer::AcceptNewConnection() { - if (socketState_ == SocketState::UNINITED) { - LOGE("AcceptNewConnection failed, websocket not inited"); + if (!MoveToConnectingState()) { return false; } - if (socketState_ == SocketState::CONNECTED) { - LOGI("AcceptNewConnection websocket has connected"); - return true; - } - if ((connectionFd_ = accept(serverFd_, nullptr, nullptr)) < SOCKET_SUCCESS) { + const int newConnectionFd = accept(serverFd_, nullptr, nullptr); + if (newConnectionFd < SOCKET_SUCCESS) { LOGI("AcceptNewConnection accept has exited"); + + auto expected = SetConnectionState(ConnectionState::CLOSED); + if (expected != ConnectionState::CONNECTING) { + LOGE("AcceptNewConnection: violation due to concurrent close and accept: got %{public}d", + EnumToNumber(expected)); + } return false; } + { + std::unique_lock lock(GetConnectionMutex()); + SetConnectionSocket(newConnectionFd); + } if (!HttpHandShake()) { - LOGE("AcceptNewConnection HttpHandShake failed"); - CloseConnectionSocket(ConnectionCloseReason::FAIL, SocketState::INITED); + LOGW("AcceptNewConnection HttpHandShake failed"); + + auto expected = SetConnectionState(ConnectionState::CLOSING); + if (expected != ConnectionState::CONNECTING) { + LOGE("AcceptNewConnection: violation due to concurrent close and accept: got %{public}d", + EnumToNumber(expected)); + } + CloseConnectionSocket(ConnectionCloseReason::FAIL); return false; } + OnNewConnection(); return true; } -#if !defined(OHOS_PLATFORM) bool WebSocketServer::InitTcpWebSocket(int port, uint32_t timeoutLimit) { if (port < 0) { LOGE("InitTcpWebSocket invalid port"); return false; } - if (socketState_ != SocketState::UNINITED) { + if (serverUp_.load()) { LOGI("InitTcpWebSocket websocket has inited"); return true; } @@ -203,13 +267,14 @@ bool WebSocketServer::BindAndListenTcpWebSocket(int port) CloseServerSocket(); return false; } - socketState_ = SocketState::INITED; + serverUp_.store(true); return true; } -#else + +#if !defined(WINDOWS_PLATFORM) bool WebSocketServer::InitUnixWebSocket(const std::string& sockName, uint32_t timeoutLimit) { - if (socketState_ != SocketState::UNINITED) { + if (serverUp_.load()) { LOGI("InitUnixWebSocket websocket has inited"); return true; } @@ -249,67 +314,72 @@ bool WebSocketServer::InitUnixWebSocket(const std::string& sockName, uint32_t ti CloseServerSocket(); return false; } - socketState_ = SocketState::INITED; + serverUp_.store(true); return true; } bool WebSocketServer::InitUnixWebSocket(int socketfd) { - if (socketState_ != SocketState::UNINITED) { + if (serverUp_.load()) { LOGI("InitUnixWebSocket websocket has inited"); return true; } if (socketfd < SOCKET_SUCCESS) { LOGE("InitUnixWebSocket socketfd is invalid"); - socketState_ = SocketState::UNINITED; return false; } - connectionFd_ = socketfd; - int flag = fcntl(connectionFd_, F_GETFL, 0); + SetConnectionSocket(socketfd); + const int flag = fcntl(socketfd, F_GETFL, 0); if (flag == -1) { LOGE("InitUnixWebSocket get client state is failed"); return false; } - fcntl(connectionFd_, F_SETFL, static_cast(flag) & ~O_NONBLOCK); - socketState_ = SocketState::INITED; + fcntl(socketfd, F_SETFL, static_cast(flag) & ~O_NONBLOCK); + serverUp_.store(true); return true; } bool WebSocketServer::ConnectUnixWebSocketBySocketpair() { - if (socketState_ == SocketState::UNINITED) { - LOGE("ConnectUnixWebSocket failed, websocket not inited"); + if (!MoveToConnectingState()) { return false; } - if (socketState_ == SocketState::CONNECTED) { - LOGI("ConnectUnixWebSocket websocket has connected"); - return true; - } if (!HttpHandShake()) { LOGE("ConnectUnixWebSocket HttpHandShake failed"); - CloseConnectionSocket(ConnectionCloseReason::FAIL, SocketState::UNINITED); + + auto expected = SetConnectionState(ConnectionState::CLOSING); + if (expected != ConnectionState::CONNECTING) { + LOGE("ConnectUnixWebSocketBySocketpair: violation due to concurrent close and accept: got %{public}d", + EnumToNumber(expected)); + } + CloseConnectionSocket(ConnectionCloseReason::FAIL); return false; } - socketState_ = SocketState::CONNECTED; + + OnNewConnection(); return true; } -#endif +#endif // WINDOWS_PLATFORM void WebSocketServer::CloseServerSocket() { close(serverFd_); serverFd_ = -1; - socketState_ = SocketState::UNINITED; } void WebSocketServer::OnNewConnection() { LOGI("New client connected"); - socketState_ = SocketState::CONNECTED; if (openCb_) { openCb_(); } + + auto expected = SetConnectionState(ConnectionState::OPEN); + if (expected != ConnectionState::CONNECTING) { + LOGE("OnNewConnection violation: expected CONNECTING, but got %{public}d", + EnumToNumber(expected)); + } } void WebSocketServer::SetValidateConnectionCallback(ValidateConnectionCallback cb) @@ -322,7 +392,7 @@ void WebSocketServer::SetOpenConnectionCallback(OpenConnectionCallback cb) openCb_ = std::move(cb); } -bool WebSocketServer::ValidateIncomingFrame(const WebSocketFrame& wsFrame) +bool WebSocketServer::ValidateIncomingFrame(const WebSocketFrame& wsFrame) const { // "The server MUST close the connection upon receiving a frame that is not masked." // https://www.rfc-editor.org/rfc/rfc6455#section-5.1 @@ -347,18 +417,66 @@ std::string WebSocketServer::CreateFrame(bool isLast, FrameType frameType, std:: return builder.SetPayload(std::move(payload)).Build(); } +WebSocketServer::ConnectionState WebSocketServer::WaitConnectingStateEnds(ConnectionState connection) +{ + auto shutdownSocketUnderLock = [this]() { + auto fd = GetConnectionSocket(); + if (fd == -1) { + return false; + } + int err = ShutdownSocket(fd); + if (err != 0) { + LOGW("Failed to shutdown client socket, errno = %{public}d", errno); + } + return true; + }; + + auto connectionSocketWasShutdown = false; + while (connection == ConnectionState::CONNECTING) { + if (!connectionSocketWasShutdown) { + // Try to shutdown the already accepted connection socket, + // otherwise thread can infinitely hang on handshake recv. + std::shared_lock lock(GetConnectionMutex()); + connectionSocketWasShutdown = shutdownSocketUnderLock(); + } + + std::this_thread::yield(); + connection = GetConnectionState(); + } + return connection; +} + void WebSocketServer::Close() { - if (socketState_ == SocketState::UNINITED) { + // Firstly stop accepting new connections. + if (!serverUp_.exchange(false)) { return; } - if (socketState_ == SocketState::CONNECTED) { - CloseConnection(CloseStatusCode::SERVER_GO_AWAY, SocketState::INITED); + + int err = ShutdownSocket(serverFd_); + if (err != 0) { + LOGW("Failed to shutdown server socket, errno = %{public}d", errno); } - usleep(10000); // 10000: time for websocket to enter the accept -#if defined(OHOS_PLATFORM) - shutdown(serverFd_, SHUT_RDWR); -#endif + + // If there is a concurrent call to `CloseConnection`, we can immediately close `serverFd_`. + // This is because new connections are already prevented, hence no reads of `serverFd_` will be done, + // and the connection itself will be closed by someone else. + auto connection = GetConnectionState(); + if (connection == ConnectionState::CLOSING || connection == ConnectionState::CLOSED) { + CloseServerSocket(); + return; + } + + connection = WaitConnectingStateEnds(connection); + + // Can safely close server socket, as there will be no more new connections attempts. CloseServerSocket(); + // Must check once again after finished `AcceptNewConnection`. + if (connection == ConnectionState::CLOSING || connection == ConnectionState::CLOSED) { + return; + } + + // If we reached this point, connection can be `OPEN`, `CLOSING` or `CLOSED`. Try to close it anyway. + CloseConnection(CloseStatusCode::SERVER_GO_AWAY); } } // namespace OHOS::ArkCompiler::Toolchain diff --git a/websocket/server/websocket_server.h b/websocket/server/websocket_server.h index af5827f5..cb568ff2 100644 --- a/websocket/server/websocket_server.h +++ b/websocket/server/websocket_server.h @@ -28,30 +28,77 @@ public: using OpenConnectionCallback = std::function; public: - ~WebSocketServer() noexcept override = default; + ~WebSocketServer() noexcept override; + /** + * @brief Accept new posix-socket connection. + * Safe to call concurrently with `Close`. + * Must not be called concurrently with `SendReply` or `Decode`, as it might lead to race condition. + */ bool AcceptNewConnection(); -#if !defined(OHOS_PLATFORM) - // Initialize server socket, transition to `INITED` state. + /** + * @brief Initialize server posix-socket. + * Non thread safe. + * On success, `serverFd_` is initialized and `serverUp_` evaluates true. + * @param port server TCP socket port number. + * @param timeoutLimit timeout in seconds for server socket. If zero, timeout is not set. + * @returns true on success, false otherwise. + */ bool InitTcpWebSocket(int port, uint32_t timeoutLimit = 0); - bool BindAndListenTcpWebSocket(int port); -#else - // Initialize server socket, transition to `INITED` state. + +#if !defined(WINDOWS_PLATFORM) + /** + * @brief Initialize server unix-socket. + * Non thread safe. + * On success, `serverFd_` is initialized and `serverUp_` evaluates true. + * @param sockName server socket name. + * @param timeoutLimit timeout in seconds for server socket. If zero, timeout is not set. + * @returns true on success, false otherwise. + */ bool InitUnixWebSocket(const std::string& sockName, uint32_t timeoutLimit = 0); + + /** + * @brief Initialize connection with unix-socket. + * Non thread safe. + * On success, `serverFd_` stays uninitialized, but `serverUp_` evaluates true. + * Note that this mode supports only a single connection, + * which must be accepted by calling `ConnectUnixWebSocketBySocketpair`. + * @param socketfd connection socket file descriptor, must be correctly opened before calling the method. + * @returns true on success, false otherwise. + */ bool InitUnixWebSocket(int socketfd); + + /** + * @brief Accept new unix-socket connection. + * Safe to call concurrently with `Close`. + */ bool ConnectUnixWebSocketBySocketpair(); -#endif +#endif // WINDOWS_PLATFORM + /** + * @brief Set callback for calling after received HTTP handshake request. + * Non thread safe. + */ void SetValidateConnectionCallback(ValidateConnectionCallback cb); + + /** + * @brief Set callback for calling after accepted new connection. + * Non thread safe. + */ void SetOpenConnectionCallback(OpenConnectionCallback cb); - void Close() override; + /** + * @brief Close server endpoint and connection sockets. + * Safe to call concurrently with: + * `AcceptNewConnection`, `ConnectUnixWebSocketBySocketpair` `SendReply`, `Decode`, `CloseConnection`. + */ + void Close(); private: - static bool ValidateHandShakeMessage(const HttpRequest& req); + bool BindAndListenTcpWebSocket(int port); - bool ValidateIncomingFrame(const WebSocketFrame& wsFrame) override; + bool ValidateIncomingFrame(const WebSocketFrame& wsFrame) const override; std::string CreateFrame(bool isLast, FrameType frameType) const override; std::string CreateFrame(bool isLast, FrameType frameType, const std::string& payload) const override; std::string CreateFrame(bool isLast, FrameType frameType, std::string&& payload) const override; @@ -60,16 +107,41 @@ private: bool HttpHandShake(); bool ProtocolUpgrade(const HttpRequest& req); bool ResponseInvalidHandShake() const; - // Run `openCb_`, transition to `OnNewConnection` state. + + /** + * @brief Runs user-provided callback and performs transition from `CONNECTING` to `OPEN` state. + */ void OnNewConnection(); - // Close server socket, transition to `UNINITED` state. + void CloseServerSocket(); + /** + * @brief Performs transition from `CLOSED` to `CONNECTING` state if the server is up. + * @returns true on success, false otherwise. + */ + bool MoveToConnectingState(); + + /** + * @brief Wait until concurrent `CONNECTING` state transition ends. + * There might be a concurrent call to `AcceptNewConnection`; + * in this case, it must finish and move into either: + * - `CLOSED` (due to failed `accept` or handshake), + * - `OPEN` (which can then concurrently transition to either `CLOSING` or `CLOSE`). + * @param connection previously loaded connection state. + * @returns updated connection state. + */ + ConnectionState WaitConnectingStateEnds(ConnectionState connection); + private: + // Server initialization status. + // Note that there could be alive connections after `serverUp_` switched to false, + // but they must terminate soon after. Users must track this with callbacks. + std::atomic_bool serverUp_ {false}; + int32_t serverFd_ {-1}; // Callbacks used during different stages of connection lifecycle. - // E.g. validation callback - it is executed during handshake + // E.g. validation callback is executed during handshake // and used to indicate whether the incoming connection should be accepted. ValidateConnectionCallback validateCb_; OpenConnectionCallback openCb_; diff --git a/websocket/test/websocket_test.cpp b/websocket/test/websocket_test.cpp index 55774f96..1c942286 100644 --- a/websocket/test/websocket_test.cpp +++ b/websocket/test/websocket_test.cpp @@ -225,7 +225,7 @@ HWTEST_F(WebSocketTest, DISABLED_ReConnectWebSocketTest, testing::ext::TestSize. HWTEST_F(WebSocketTest, DISABLED_ClientAbnormalTest, testing::ext::TestSize.Level0) { WebSocketClient clientSocket; - ASSERT_STREQ(clientSocket.GetSocketStateString().c_str(), "uninited"); + ASSERT_STREQ(clientSocket.GetSocketStateString().c_str(), "closed"); ASSERT_FALSE(clientSocket.ClientSendWSUpgradeReq()); ASSERT_FALSE(clientSocket.ClientRecvWSUpgradeRsp()); ASSERT_FALSE(clientSocket.SendReply(HELLO_SERVER)); diff --git a/websocket/websocket_base.cpp b/websocket/websocket_base.cpp index 187a8834..e9f4cac0 100644 --- a/websocket/websocket_base.cpp +++ b/websocket/websocket_base.cpp @@ -19,19 +19,41 @@ #include "network.h" #include "websocket_base.h" +#include + namespace OHOS::ArkCompiler::Toolchain { +static std::string ToString(CloseStatusCode status) +{ + if (status == CloseStatusCode::NO_STATUS_CODE) { + return ""; + } + std::string result; + PushNumberPerByte(result, EnumToNumber(status)); + return result; +} + +WebSocketBase::~WebSocketBase() noexcept +{ + if (connectionFd_ != -1) { + LOGW("WebSocket connection is closed while destructing the object"); + close(connectionFd_); + // Reset directly in order to prevent static analyzer warnings. + connectionFd_ = -1; + } +} + // if the data is too large, it will be split into multiple frames, the first frame will be marked as 0x0 // and the last frame will be marked as 0x1. // we just add the 'isLast' parameter to indicate whether it is the last frame. bool WebSocketBase::SendReply(const std::string& message, FrameType frameType, bool isLast) const { - if (socketState_ != SocketState::CONNECTED) { + if (connectionState_.load() != ConnectionState::OPEN) { LOGE("SendReply failed, websocket not connected"); return false; } - auto frame = CreateFrame(isLast, frameType, message); - if (!Send(connectionFd_, frame, 0)) { + const auto frame = CreateFrame(isLast, frameType, message); + if (!SendUnderLock(frame)) { LOGE("SendReply: send failed"); return false; } @@ -60,18 +82,18 @@ bool WebSocketBase::SendReply(const std::string& message, FrameType frameType, b * +---------------------------------------------------------------+ */ -bool WebSocketBase::ReadPayload(WebSocketFrame& wsFrame) +bool WebSocketBase::ReadPayload(WebSocketFrame& wsFrame) const { if (wsFrame.payloadLen == WebSocketFrame::TWO_BYTES_LENTH_ENC) { uint8_t recvbuf[WebSocketFrame::TWO_BYTES_LENTH] = {0}; - if (!Recv(connectionFd_, recvbuf, WebSocketFrame::TWO_BYTES_LENTH, 0)) { + if (!RecvUnderLock(recvbuf, WebSocketFrame::TWO_BYTES_LENTH)) { LOGE("ReadPayload: Recv payloadLen == 126 failed"); return false; } wsFrame.payloadLen = NetToHostLongLong(recvbuf, WebSocketFrame::TWO_BYTES_LENTH); } else if (wsFrame.payloadLen == WebSocketFrame::EIGHT_BYTES_LENTH_ENC) { uint8_t recvbuf[WebSocketFrame::EIGHT_BYTES_LENTH] = {0}; - if (!Recv(connectionFd_, recvbuf, WebSocketFrame::EIGHT_BYTES_LENTH, 0)) { + if (!RecvUnderLock(recvbuf, WebSocketFrame::EIGHT_BYTES_LENTH)) { LOGE("ReadPayload: Recv payloadLen == 127 failed"); return false; } @@ -80,7 +102,7 @@ bool WebSocketBase::ReadPayload(WebSocketFrame& wsFrame) return DecodeMessage(wsFrame); } -bool WebSocketBase::HandleDataFrame(WebSocketFrame& wsFrame) +bool WebSocketBase::HandleDataFrame(WebSocketFrame& wsFrame) const { if (wsFrame.opcode == EnumToNumber(FrameType::TEXT)) { return ReadPayload(wsFrame); @@ -104,28 +126,29 @@ bool WebSocketBase::HandleControlFrame(WebSocketFrame& wsFrame) SendPongFrame(wsFrame.payload); } else if (wsFrame.opcode == EnumToNumber(FrameType::CLOSE)) { // might read payload to response by echoing the status code - CloseConnection(CloseStatusCode::NO_STATUS_CODE, SocketState::INITED); + CloseConnection(CloseStatusCode::NO_STATUS_CODE); } return true; } std::string WebSocketBase::Decode() { - if (socketState_ != SocketState::CONNECTED) { - LOGE("Decode failed, websocket not connected!"); + if (auto state = connectionState_.load(); state != ConnectionState::OPEN) { + LOGE("Decode failed: websocket not connected, state = %{public}d", EnumToNumber(state)); return ""; } uint8_t recvbuf[WebSocketFrame::HEADER_LEN] = {0}; - if (!Recv(connectionFd_, recvbuf, WebSocketFrame::HEADER_LEN, 0)) { + if (!RecvUnderLock(recvbuf, WebSocketFrame::HEADER_LEN)) { LOGE("Decode failed, client websocket disconnect"); - CloseConnection(CloseStatusCode::UNEXPECTED_ERROR, SocketState::INITED); + CloseConnection(CloseStatusCode::UNEXPECTED_ERROR); return std::string(DECODE_DISCONNECT_MSG); } WebSocketFrame wsFrame(recvbuf); if (!ValidateIncomingFrame(wsFrame)) { LOGE("Received websocket frame is invalid - header is %02x%02x", recvbuf[0], recvbuf[1]); - CloseConnection(CloseStatusCode::PROTOCOL_ERROR, SocketState::INITED); + CloseConnection(CloseStatusCode::PROTOCOL_ERROR); + return std::string(DECODE_DISCONNECT_MSG); } if (IsControlFrame(wsFrame.opcode)) { @@ -135,12 +158,14 @@ std::string WebSocketBase::Decode() } else if (HandleDataFrame(wsFrame)) { return wsFrame.payload; } + // Unexpected data, must close the connection. + CloseConnection(CloseStatusCode::PROTOCOL_ERROR); return std::string(DECODE_DISCONNECT_MSG); } -bool WebSocketBase::IsConnected() +bool WebSocketBase::IsConnected() const { - return socketState_ == SocketState::CONNECTED; + return connectionState_.load() == ConnectionState::OPEN; } void WebSocketBase::SetCloseConnectionCallback(CloseConnectionCallback cb) @@ -153,15 +178,8 @@ void WebSocketBase::SetFailConnectionCallback(FailConnectionCallback cb) failCb_ = std::move(cb); } -void WebSocketBase::CloseConnectionSocket(ConnectionCloseReason status, SocketState newSocketState) +void WebSocketBase::OnConnectionClose(ConnectionCloseReason status) { -#if defined(OHOS_PLATFORM) - shutdown(connectionFd_, SHUT_RDWR); -#endif - close(connectionFd_); - connectionFd_ = -1; - socketState_ = newSocketState; - if (status == ConnectionCloseReason::FAIL) { if (failCb_) { failCb_(); @@ -173,38 +191,117 @@ void WebSocketBase::CloseConnectionSocket(ConnectionCloseReason status, SocketSt } } -void WebSocketBase::SendPongFrame(std::string payload) +void WebSocketBase::CloseConnectionSocket(ConnectionCloseReason status) { - auto frame = CreateFrame(true, FrameType::PONG, std::move(payload)); - if (!Send(connectionFd_, frame, 0)) { - LOGE("Decode: Send pong frame failed"); + OnConnectionClose(status); + + { + // Shared lock due to other thread possibly hanging on `recv` with acquired shared lock. + std::shared_lock lock(connectionMutex_); + int err = ShutdownSocket(connectionFd_); + if (err != 0) { + LOGW("Failed to shutdown client socket, errno = %{public}d", errno); + } + } + { + // Unique lock due to close and write into `connectionFd_`. + // Note that `close` must be also done in critical section, + // otherwise the other thread can continue using the outdated and possibly reassigned file descriptor. + std::unique_lock lock(connectionMutex_); + close(connectionFd_); + // Reset directly in order to prevent static analyzer warnings. + connectionFd_ = -1; + } + + auto expected = ConnectionState::CLOSING; + if (!connectionState_.compare_exchange_strong(expected, ConnectionState::CLOSED)) { + LOGE("In connection transition CLOSING->CLOSED got initial state = %{public}d", EnumToNumber(expected)); } } -static std::string ToString(CloseStatusCode status) +void WebSocketBase::SendPongFrame(std::string payload) const { - if (status == CloseStatusCode::NO_STATUS_CODE) { - return ""; + const auto frame = CreateFrame(true, FrameType::PONG, std::move(payload)); + if (!SendUnderLock(frame)) { + LOGE("Decode: Send pong frame failed"); } - std::string result; - PushNumberPerByte(result, EnumToNumber(status)); - return result; } -void WebSocketBase::SendCloseFrame(CloseStatusCode status) +void WebSocketBase::SendCloseFrame(CloseStatusCode status) const { - auto frame = CreateFrame(true, FrameType::CLOSE, ToString(status)); - if (!Send(connectionFd_, frame, 0)) { + const auto frame = CreateFrame(true, FrameType::CLOSE, ToString(status)); + if (!SendUnderLock(frame)) { LOGE("SendCloseFrame: Send close frame failed"); } } -void WebSocketBase::CloseConnection(CloseStatusCode status, SocketState newSocketState) +bool WebSocketBase::CloseConnection(CloseStatusCode status) { + auto expected = ConnectionState::OPEN; + if (!connectionState_.compare_exchange_strong(expected, ConnectionState::CLOSING)) { + // Concurrent connection close detected, do nothing. + return false; + } + LOGI("Close connection, status = %{public}d", static_cast(status)); SendCloseFrame(status); // can close connection right after sending back close frame. - CloseConnectionSocket(ConnectionCloseReason::CLOSE, newSocketState); + CloseConnectionSocket(ConnectionCloseReason::CLOSE); + return true; +} + +int WebSocketBase::GetConnectionSocket() const +{ + return connectionFd_; +} + +void WebSocketBase::SetConnectionSocket(int socketFd) +{ + connectionFd_ = socketFd; +} + +std::shared_mutex &WebSocketBase::GetConnectionMutex() +{ + return connectionMutex_; +} + +WebSocketBase::ConnectionState WebSocketBase::GetConnectionState() const +{ + return connectionState_.load(); +} + +WebSocketBase::ConnectionState WebSocketBase::SetConnectionState(ConnectionState newState) +{ + return connectionState_.exchange(newState); +} + +bool WebSocketBase::CompareExchangeConnectionState(ConnectionState& expected, ConnectionState newState) +{ + return connectionState_.compare_exchange_strong(expected, newState); +} + +bool WebSocketBase::SendUnderLock(const std::string& message) const +{ + std::shared_lock lock(connectionMutex_); + return Send(connectionFd_, message, 0); +} + +bool WebSocketBase::SendUnderLock(const char* buf, size_t totalLen) const +{ + std::shared_lock lock(connectionMutex_); + return Send(connectionFd_, buf, totalLen, 0); +} + +bool WebSocketBase::RecvUnderLock(std::string& message) const +{ + std::shared_lock lock(connectionMutex_); + return Recv(connectionFd_, message, 0); +} + +bool WebSocketBase::RecvUnderLock(uint8_t* buf, size_t totalLen) const +{ + std::shared_lock lock(connectionMutex_); + return Recv(connectionFd_, buf, totalLen, 0); } /* static */ @@ -250,4 +347,18 @@ bool WebSocketBase::SetWebSocketTimeOut(int32_t fd, uint32_t timeoutLimit) return true; } #endif + +#if defined(WINDOWS_PLATFORM) +/* static */ +int WebSocketBase::ShutdownSocket(int32_t fd) +{ + return shutdown(fd, SD_BOTH); +} +#else +/* static */ +int WebSocketBase::ShutdownSocket(int32_t fd) +{ + return shutdown(fd, SHUT_RDWR); +} +#endif } // namespace OHOS::ArkCompiler::Toolchain diff --git a/websocket/websocket_base.h b/websocket/websocket_base.h index fd750d18..9e4c5624 100644 --- a/websocket/websocket_base.h +++ b/websocket/websocket_base.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace OHOS::ArkCompiler::Toolchain { @@ -44,29 +45,61 @@ public: static bool IsDecodeDisconnectMsg(const std::string& message); WebSocketBase() = default; - virtual ~WebSocketBase() noexcept = default; - - // Receive and decode a message. - // In case of control frames this method handles it accordingly and returns an empty string, - // otherwise returns the decoded received message. + virtual ~WebSocketBase() noexcept; + + /** + * @brief Receive and decode a message. + * Must not be called concurrently on the same connection. + * Safe to call concurrently with `SendReply` and `Close`. + * Control frames are handled according to specification with an empty string as returned value, + * otherwise the method returns the decoded received message. + * Note that this method closes the connection after receiving invalid data. + * This event can be checked with `IsDecodeDisconnectMsg`. + */ std::string Decode(); - // Send message on current connection. - // Returns success status. + + /** + * @brief Send message on current connection. + * Safe to call concurrently with: `SendReply`, `Decode`, `Close`. + * Note that the connection is not closed on transmission failures. + * @param message text payload. + * @param frameType frame type, must be either TEXT, BINARY or CONTINUATION. + * @param isLast flag indicating whether the message is the final. + * @returns true on success, false otherwise. + */ bool SendReply(const std::string& message, FrameType frameType = FrameType::TEXT, bool isLast = true) const; - bool IsConnected(); + /** + * @brief Check if connection is in `OPEN` state. + */ + bool IsConnected() const; + /** + * @brief Set callback for calling after normal connection close. + * Non thread safe. + */ void SetCloseConnectionCallback(CloseConnectionCallback cb); + + /** + * @brief Set callback for calling after closing connection on any failure. + * Non thread safe. + */ void SetFailConnectionCallback(FailConnectionCallback cb); - // Close current websocket endpoint and connections (if any). - virtual void Close() = 0; + /** + * @brief Send `CLOSE` frame and close the connection socket. + * Does nothing if connection was not in `OPEN` state. + * @param status close status code specified in sent frame. + * @returns true if connection was closed, false otherwise. + */ + bool CloseConnection(CloseStatusCode status); protected: - enum class SocketState : uint8_t { - UNINITED, - INITED, - CONNECTED, + enum class ConnectionState : uint8_t { + CONNECTING, + OPEN, + CLOSING, + CLOSED, }; enum class ConnectionCloseReason: uint8_t { @@ -75,37 +108,74 @@ protected: }; protected: + /** + * @brief Set `send` and `recv` timeout limits. + * @param fd socket to set timeout on. + * @param timeoutLimit timeout in seconds. If zero, function is no-op. + * @returns true on success, false otherwise. + */ static bool SetWebSocketTimeOut(int32_t fd, uint32_t timeoutLimit); - bool ReadPayload(WebSocketFrame& wsFrame); - void SendPongFrame(std::string payload); - void SendCloseFrame(CloseStatusCode status); - // Sending close frame and close connection. - void CloseConnection(CloseStatusCode status, SocketState newSocketState); - // Close connection socket. - void CloseConnectionSocket(ConnectionCloseReason status, SocketState newSocketState); - - virtual bool HandleDataFrame(WebSocketFrame& wsFrame); - virtual bool HandleControlFrame(WebSocketFrame& wsFrame); - - virtual bool ValidateIncomingFrame(const WebSocketFrame& wsFrame) = 0; + /** + * @brief Shutdown socket for sends and receives. + * Note that the implementation of this function is platform-specific, + * so there is no unified way to retrieve error code returned from system call. + * @param fd socket file descriptor. + * @returns zero on success, `-1` otherwise. + */ + static int ShutdownSocket(int32_t fd); + + /** + * @brief Close the connection socket. + * Must be transition from `CLOSING` to `CLOSED` connection state. + * @param status close reason, depends which callback to execute. + */ + void CloseConnectionSocket(ConnectionCloseReason status); + + /** + * @brief Execute user-provided callbacks before closing the connection socket. + */ + void OnConnectionClose(ConnectionCloseReason status); + + int GetConnectionSocket() const; + void SetConnectionSocket(int socketFd); + std::shared_mutex &GetConnectionMutex(); + + ConnectionState GetConnectionState() const; + ConnectionState SetConnectionState(ConnectionState newState); + bool CompareExchangeConnectionState(ConnectionState& expected, ConnectionState newState); + + bool HandleDataFrame(WebSocketFrame& wsFrame) const; + bool HandleControlFrame(WebSocketFrame& wsFrame); + bool ReadPayload(WebSocketFrame& wsFrame) const; + void SendPongFrame(std::string payload) const; + void SendCloseFrame(CloseStatusCode status) const; + + bool SendUnderLock(const std::string& message) const; + bool SendUnderLock(const char* buf, size_t totalLen) const; + bool RecvUnderLock(std::string& message) const; + bool RecvUnderLock(uint8_t* buf, size_t totalLen) const; + + virtual bool ValidateIncomingFrame(const WebSocketFrame& wsFrame) const = 0; virtual std::string CreateFrame(bool isLast, FrameType frameType) const = 0; virtual std::string CreateFrame(bool isLast, FrameType frameType, const std::string& payload) const = 0; virtual std::string CreateFrame(bool isLast, FrameType frameType, std::string&& payload) const = 0; virtual bool DecodeMessage(WebSocketFrame& wsFrame) const = 0; protected: - std::atomic socketState_ {SocketState::UNINITED}; + static constexpr size_t HTTP_HANDSHAKE_MAX_LEN = 1024; + static constexpr int SOCKET_SUCCESS = 0; + +private: + std::atomic connectionState_ {ConnectionState::CLOSED}; + mutable std::shared_mutex connectionMutex_; int connectionFd_ {-1}; // Callbacks used during different stages of connection lifecycle. CloseConnectionCallback closeCb_; FailConnectionCallback failCb_; - static constexpr char WEB_SOCKET_GUID[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; - static constexpr size_t HTTP_HANDSHAKE_MAX_LEN = 1024; - static constexpr int SOCKET_SUCCESS = 0; static constexpr std::string_view DECODE_DISCONNECT_MSG = "disconnect"; }; } // namespace OHOS::ArkCompiler::Toolchain -- Gitee From 9a7490d6af89e19d14bbb2609b056801287ef92e Mon Sep 17 00:00:00 2001 From: Maxim Logaev Date: Thu, 13 Jun 2024 17:50:35 +0300 Subject: [PATCH 28/51] Added missing `` Description: Added missing `` for GCC >= 13. Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IA5B05 Testing: Build with GCC >=13 Signed-off-by: Maxim Logaev --- websocket/web_socket_frame.h | 1 + 1 file changed, 1 insertion(+) diff --git a/websocket/web_socket_frame.h b/websocket/web_socket_frame.h index 71fb088d..9e2dabb6 100644 --- a/websocket/web_socket_frame.h +++ b/websocket/web_socket_frame.h @@ -17,6 +17,7 @@ #define ARKCOMPILER_TOOLCHAIN_WEBSOCKET_WS_FRAME_H #include +#include namespace OHOS::ArkCompiler::Toolchain { enum class FrameType : uint8_t { -- Gitee From 930354215c486e4bd90b780080eec8d02ab8a731 Mon Sep 17 00:00:00 2001 From: Andrey Efremov Date: Mon, 22 Jul 2024 00:01:30 +0800 Subject: [PATCH 29/51] Optimize ArkJS VM build time Issue: https://gitee.com/open_harmony/dashboard?issue_id=IACDZP Change-Id: I729c3a2741cb2571d6f7184b2726e5f06eca802a Signed-off-by: Andrey Efremov Change-Id: I73c34c2b7a5d644715ba8cf3edc17e6c554fe686 Signed-off-by: Andrey Efremov --- tooling/agent/debugger_impl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index 05cc8fdc..c2ee0ba6 100755 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -26,6 +26,8 @@ #include "ecmascript/jspandafile/js_pandafile_manager.h" #include "ecmascript/napi/jsnapi_helper.h" +#include "ecmascript/tagged_array-inl.h" + namespace panda::ecmascript::tooling { using namespace std::placeholders; -- Gitee From 8ce6c0213f6114f146de521c9cc5b88525883d97 Mon Sep 17 00:00:00 2001 From: wuhailong Date: Mon, 29 Jul 2024 16:31:46 +0800 Subject: [PATCH 30/51] Revert "adapt SDK on OpenHarmony" This reverts commit 578dff46922d5a31772a3bbb1e1b4f93a9e0471c. Issue: #IAG3HC Signed-off-by: wuhailong Change-Id: I92956686c60ea68fc2b196d2b40eb481018c578c --- build/ark_var.gni | 2 -- 1 file changed, 2 deletions(-) diff --git a/build/ark_var.gni b/build/ark_var.gni index 001e4dc5..4739e065 100644 --- a/build/ark_var.gni +++ b/build/ark_var.gni @@ -17,6 +17,4 @@ declare_args() { # system package dir system_base_dir = "system" - - device_name = "" } -- Gitee From 52cca0e7f0549dae41ce6ccbc8367eb9f6a0f1c7 Mon Sep 17 00:00:00 2001 From: fangting Date: Mon, 15 Jul 2024 10:17:47 +0800 Subject: [PATCH 31/51] es2abc change es2abc change Issue:#IACX51 Signed-off-by: fangting --- .../components/ets_frontend/es2abc_config.gni | 104 ++++++++++++++++++ .../ets_frontend/ets_frontend_config.gni | 36 ++++++ build/core/gn/BUILD.gn | 4 +- build/scripts/generate_js_bytecode.py | 96 ++++++++++++++++ test/test_helper.gni | 4 +- tooling/test/BUILD.gn | 3 +- 6 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 build/config/components/ets_frontend/es2abc_config.gni create mode 100644 build/config/components/ets_frontend/ets_frontend_config.gni create mode 100755 build/scripts/generate_js_bytecode.py diff --git a/build/config/components/ets_frontend/es2abc_config.gni b/build/config/components/ets_frontend/es2abc_config.gni new file mode 100644 index 00000000..a805c564 --- /dev/null +++ b/build/config/components/ets_frontend/es2abc_config.gni @@ -0,0 +1,104 @@ +# Copyright (c) 2021-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("$build_root/config/components/ets_frontend/ets_frontend_config.gni") + +es2abc_root = "//arkcompiler/ets_frontend/es2panda" +es2abc_build_path = "" +es2abc_build_deps = "" +es2abc_out_root = "" + +if (host_toolchain == toolchain_mac) { + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_mac)", "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_mac)" ] +} else if (host_toolchain == toolchain_win) { + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_win)", "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_win)" ] +} else { + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_linux)", "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_linux)" ] +} +es2abc_build_path = es2abc_out_root + "/arkcompiler/ets_frontend" + +# Generate abc. +# +# Mandatory arguments: +# plugin_path -- plugin js file path +# plugin_name -- name of js file, ex: BatteryPlugin.js +# generat_file -- name of generated file +# package_name -- name of generated file's package +# extra_dependencies -- a list of files that should be considered as dependencies, must be label +# out_puts +template("es2abc_gen_abc") { + assert(defined(invoker.src_js), "src_js is required!") + assert(defined(invoker.dst_file), "dst_file is required!") + assert(defined(invoker.out_puts), "out_puts is required!") + + extra_dependencies = [] + if (defined(invoker.extra_dependencies)) { + extra_dependencies += invoker.extra_dependencies + } + + action("$target_name") { + if (defined(invoker.extra_visibility)) { + visibility = invoker.extra_visibility + } + + script = "$build_root/scripts/generate_js_bytecode.py" + + deps = extra_dependencies + deps += es2abc_build_deps + + args = [ + "--src-js", + invoker.src_js, + "--dst-file", + invoker.dst_file, + "--frontend-tool-path", + rebase_path("${es2abc_build_path}"), + ] + + if (defined(invoker.extension)) { + args += [ + "--extension", + invoker.extension, + ] + } + + if (defined(invoker.dump_symbol_table)) { + args += [ + "--dump-symbol-table", + invoker.dump_symbol_table, + ] + } + if (defined(invoker.input_symbol_table)) { + args += [ + "--input-symbol-table", + invoker.input_symbol_table, + ] + } + + if (defined(invoker.extra_args)) { + args += invoker.extra_args + } + + if (defined(invoker.in_puts)) { + inputs = invoker.in_puts + } + + outputs = invoker.out_puts + } +} diff --git a/build/config/components/ets_frontend/ets_frontend_config.gni b/build/config/components/ets_frontend/ets_frontend_config.gni new file mode 100644 index 00000000..2aebf108 --- /dev/null +++ b/build/config/components/ets_frontend/ets_frontend_config.gni @@ -0,0 +1,36 @@ +# Copyright (c) 2021-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. + +if (!defined(ark_standalone_build)) { + ark_standalone_build = false +} + +if (!ark_standalone_build) { + build_root = "//build" + ark_third_party_root = "//third_party" + import("$build_root/ohos.gni") +} else { + ark_third_party_root = "//arkcompiler/toolchain/build/third_party_gn" + import("$build_root/ark.gni") +} +import("$build_root/test.gni") + +ets_frontend_root = "//arkcompiler/ets_frontend" + +toolchain_linux = "$build_root/toolchain/linux:clang_x64" +if (host_cpu == "arm64") { + toolchain_mac = "$build_root/toolchain/mac:clang_arm64" +} else { + toolchain_mac = "$build_root/toolchain/mac:clang_x64" +} +toolchain_win = "$build_root/toolchain/mingw:mingw_x86_64" diff --git a/build/core/gn/BUILD.gn b/build/core/gn/BUILD.gn index 2dc69e0b..c9ff832c 100644 --- a/build/core/gn/BUILD.gn +++ b/build/core/gn/BUILD.gn @@ -11,8 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//arkcompiler/ets_frontend/ets_frontend_config.gni") -import("../../../toolchain.gni") +import("//arkcompiler/toolchain/toolchain.gni") +import("$build_root/config/components/ets_frontend/ets_frontend_config.gni") print("root_out_dir=$root_out_dir") print("root_build_dir=$root_build_dir") diff --git a/build/scripts/generate_js_bytecode.py b/build/scripts/generate_js_bytecode.py new file mode 100755 index 00000000..f978b33d --- /dev/null +++ b/build/scripts/generate_js_bytecode.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# coding: utf-8 + +""" +Copyright (c) 2021 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. + +Description: Generate javascript byte code using es2abc +""" + +import os +import subprocess +import platform +import argparse + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--src-js', + help='js source file') + parser.add_argument('--dst-file', + help='the converted target file') + parser.add_argument('--frontend-tool-path', + help='path of the frontend conversion tool') + parser.add_argument('--extension', + help='source file extension') + parser.add_argument("--debug", action='store_true', + help='whether add debuginfo') + parser.add_argument("--module", action='store_true', + help='whether is module') + parser.add_argument("--commonjs", action='store_true', + help='whether is commonjs') + parser.add_argument("--merge-abc", action='store_true', + help='whether is merge abc') + parser.add_argument("--generate-patch", action='store_true', + help='generate patch abc') + parser.add_argument("--dump-symbol-table", + help='dump symbol table of base abc') + parser.add_argument("--input-symbol-table", + help='input symbol table for patch abc') + arguments = parser.parse_args() + return arguments + + +def run_command(cmd, execution_path): + print(" ".join(cmd) + " | execution_path: " + execution_path) + proc = subprocess.Popen(cmd, cwd=execution_path) + proc.wait() + + +def gen_abc_info(input_arguments): + frontend_tool_path = input_arguments.frontend_tool_path + + (path, name) = os.path.split(frontend_tool_path) + + cmd = [os.path.join("./", name, "es2abc"), + '--output', input_arguments.dst_file, + input_arguments.src_js] + + if input_arguments.extension: + cmd += ['--extension', input_arguments.extension] + if input_arguments.dump_symbol_table: + cmd += ['--dump-symbol-table', input_arguments.dump_symbol_table] + if input_arguments.input_symbol_table: + cmd += ['--input-symbol-table', input_arguments.input_symbol_table] + if input_arguments.debug: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--debug-info') + if input_arguments.module: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--module') + if input_arguments.commonjs: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--commonjs') + if input_arguments.merge_abc: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--merge-abc') + if input_arguments.generate_patch: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--generate-patch') + # insert d.ts option to cmd later + run_command(cmd, path) + + +if __name__ == '__main__': + gen_abc_info(parse_args()) \ No newline at end of file diff --git a/test/test_helper.gni b/test/test_helper.gni index f1f98843..65c55916 100644 --- a/test/test_helper.gni +++ b/test/test_helper.gni @@ -11,9 +11,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") +import("//arkcompiler/toolchain/toolchain.gni") +import("$build_root/config/components/ets_frontend/es2abc_config.gni") import("$build_root/test.gni") -import("../toolchain.gni") if (is_standard_system || ark_standalone_build) { _icu_path_ = "thirdparty/icu" diff --git a/tooling/test/BUILD.gn b/tooling/test/BUILD.gn index 7d941caf..86cee6a2 100644 --- a/tooling/test/BUILD.gn +++ b/tooling/test/BUILD.gn @@ -11,9 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") import("//arkcompiler/toolchain/test/test_helper.gni") -import("../../toolchain.gni") +import("$build_root/config/components/ets_frontend/es2abc_config.gni") module_output_path = "arkcompiler/toolchain" -- Gitee From 9d7525b81cfd528d81aff81c1dc7dd35140f4343 Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Tue, 30 Jul 2024 09:19:47 +0800 Subject: [PATCH 32/51] Fix alarm Fix security alerts in file inspector.cpp Handle unreasonable forced conversions in file pt_types.cpp Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAGFDL Signed-off-by: swx1282997 --- inspector/inspector.cpp | 4 ++-- tooling/base/pt_types.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 1c2b4574..3292a9d6 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -303,11 +303,11 @@ void Inspector::OnMessage(std::string&& msg) #if defined(OHOS_PLATFORM) uint64_t Inspector::GetThreadOrTaskId() { - uint64_t threadOrTaskId = getproctid(); + uint64_t threadOrTaskId = static_cast(getproctid()); #if defined(ENABLE_FFRT_INTERFACES) threadOrTaskId = ffrt_this_task_get_id(); if (threadOrTaskId == 0) { - threadOrTaskId = getproctid(); + threadOrTaskId = static_cast(getproctid()); } #endif // defined(ENABLE_FFRT_INTERFACES) return threadOrTaskId; diff --git a/tooling/base/pt_types.cpp b/tooling/base/pt_types.cpp index 9d1fb795..b138d947 100644 --- a/tooling/base/pt_types.cpp +++ b/tooling/base/pt_types.cpp @@ -770,14 +770,14 @@ std::string ObjectRemoteObject::DescriptionForSharedArrayBuffer(const EcmaVM *ec std::string ObjectRemoteObject::DescriptionForUint8Array(const EcmaVM *ecmaVm, Local tagged) { - int32_t len = static_cast(tagged->ByteLength(ecmaVm)); + uint32_t len = tagged->ByteLength(ecmaVm); std::string description = ("Uint8Array(" + std::to_string(len) + ")"); return description; } std::string ObjectRemoteObject::DescriptionForInt8Array(const EcmaVM *ecmaVm, Local tagged) { - int32_t len = static_cast(tagged->ByteLength(ecmaVm)); + uint32_t len = tagged->ByteLength(ecmaVm); std::string description = ("Int8Array(" + std::to_string(len) + ")"); return description; } -- Gitee From 70931c3fa646bda256373c874f6cede4df3e5c89 Mon Sep 17 00:00:00 2001 From: yp9522 Date: Fri, 21 Jun 2024 15:02:49 +0800 Subject: [PATCH 33/51] support compiler ark_toolchain_unittest Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IA716C Change-Id: I3f7acb9b3bcb157a97fea7cd3ab9264ef0e4866f Signed-off-by: yp9522 --- tooling/test/BUILD.gn | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tooling/test/BUILD.gn b/tooling/test/BUILD.gn index 86cee6a2..47212275 100644 --- a/tooling/test/BUILD.gn +++ b/tooling/test/BUILD.gn @@ -143,7 +143,10 @@ ohos_shared_library("jsdebugtest") { external_deps += [ "hilog:libhilog" ] } - external_deps += [ "cJSON:cjson_static" ] + external_deps += [ + "cJSON:cjson_static", + "ets_runtime:libark_jsruntime", + ] install_enable = false output_extension = "so" subsystem_name = "test" @@ -297,6 +300,7 @@ host_unittest_action("DebuggerClientTest") { # hiviewdfx libraries external_deps = hiviewdfx_ext_deps external_deps += [ + "bounds_checking_function:libsec_shared", "cJSON:cjson_static", "icu:shared_icui18n", "icu:shared_icuuc", @@ -342,6 +346,7 @@ host_unittest_action("DebuggerCIntClientTest") { # hiviewdfx libraries external_deps = hiviewdfx_ext_deps external_deps += [ + "bounds_checking_function:libsec_shared", "cJSON:cjson_static", "icu:shared_icui18n", "icu:shared_icuuc", -- Gitee From b2b65049d240fa91e0ed55bad3adf5f7b4aca016 Mon Sep 17 00:00:00 2001 From: yang-19970325 Date: Mon, 5 Aug 2024 22:45:42 +0800 Subject: [PATCH 34/51] Revert pr 682 Issue: #IAI0Q4 This reverts commit 6bb8d597704f9194bf9791d5f1ce465696662ab1. Signed-off-by: yang-19970325 --- tooling/agent/debugger_impl.cpp | 7 ++----- tooling/agent/debugger_impl.h | 11 ----------- tooling/backend/js_pt_hooks.cpp | 20 ++++++++------------ tooling/backend/js_pt_hooks.h | 1 + 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index c2ee0ba6..fcd48504 100755 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -124,10 +124,6 @@ bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &file // Store parsed script in map scripts_[script->GetScriptId()] = std::move(script); - - // Store parsed file url, used by hook to determine - // whether a Break_on_start pause is needed - parsedFileNames_.emplace(url); return true; } @@ -404,7 +400,8 @@ void DebuggerImpl::InitializeExtendedProtocolsList() "setNativeRange", "resetSingleStepper", "callFunctionOn", - "smartStepInto" + "smartStepInto", + "callFunctionOn" }; debuggerExtendedProtocols_ = std::move(debuggerProtocolList); } diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index 9c842173..153f5d8f 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -273,16 +273,6 @@ private: return recordName; } - void RemoveUrlFromParsedSet(std::string &url) - { - parsedFileNames_.erase(url); - } - - bool IsUrlFoundInParsedSet(std::string &url) - { - return parsedFileNames_.find(url) != parsedFileNames_.end(); - } - class Frontend { public: explicit Frontend(ProtocolChannel *channel) : channel_(channel) {} @@ -334,7 +324,6 @@ private: JsDebuggerManager::SingleStepperFunc stepperFunc_ {nullptr}; JsDebuggerManager::ReturnNativeFunc returnNative_ {nullptr}; std::vector debuggerExtendedProtocols_ {}; - CUnorderedSet parsedFileNames_ {}; friend class JSPtHooks; friend class test::TestHooks; diff --git a/tooling/backend/js_pt_hooks.cpp b/tooling/backend/js_pt_hooks.cpp index c46f608b..bcb05660 100644 --- a/tooling/backend/js_pt_hooks.cpp +++ b/tooling/backend/js_pt_hooks.cpp @@ -16,7 +16,6 @@ #include "backend/js_pt_hooks.h" #include "agent/debugger_impl.h" -#include "ecmascript/jspandafile/js_pandafile_manager.h" namespace panda::ecmascript::tooling { void JSPtHooks::DebuggerStmt([[maybe_unused]] const JSPtLocation &location) @@ -48,16 +47,13 @@ bool JSPtHooks::SingleStep(const JSPtLocation &location) LOG_DEBUGGER(VERBOSE) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(debugger_->vm_); - if (!debugger_->parsedFileNames_.empty()) { - auto jsPandaFile = location.GetJsPandaFile(); - DebugInfoExtractor *extractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(jsPandaFile); - std::string url = extractor->GetSourceFile(location.GetMethodId()); - if (debugger_->IsUrlFoundInParsedSet(url)) { - debugger_->RemoveUrlFromParsedSet(url); - debugger_->NotifyPaused({}, BREAK_ON_START); - return false; - } + if (UNLIKELY(firstTime_)) { + firstTime_ = false; + + debugger_->NotifyPaused({}, BREAK_ON_START); + return false; } + // pause or step complete if (debugger_->NotifySingleStep(location)) { debugger_->NotifyPaused({}, OTHER); @@ -88,8 +84,8 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entr [[maybe_unused]] LocalScope scope(debugger_->vm_); static uint32_t scriptId = 0; - if (!debugger_->NotifyScriptParsed(scriptId++, pandaFileName.data(), entryPoint)) { - LOG_DEBUGGER(DEBUG) << "JSPtHooks: LoadModule: " << pandaFileName << " NotifyParsed fail"; + if (debugger_->NotifyScriptParsed(scriptId++, pandaFileName.data(), entryPoint)) { + firstTime_ = true; } } diff --git a/tooling/backend/js_pt_hooks.h b/tooling/backend/js_pt_hooks.h index 085c6fdf..cb5f7726 100644 --- a/tooling/backend/js_pt_hooks.h +++ b/tooling/backend/js_pt_hooks.h @@ -46,6 +46,7 @@ private: NO_MOVE_SEMANTIC(JSPtHooks); DebuggerImpl *debugger_ {nullptr}; + bool firstTime_ {true}; }; } // namespace panda::ecmascript::tooling #endif // ECMASCRIPT_TOOLING_BACKEND_JS_PT_HOOKS_H \ No newline at end of file -- Gitee From c9d12363c0a39c475894e8e7b35ccf1238f09d8e Mon Sep 17 00:00:00 2001 From: fangting Date: Sun, 4 Aug 2024 15:04:36 +0800 Subject: [PATCH 35/51] update tag update tag Issue:#IAFYVD Signed-off-by: fangting --- build/third_party_gn/googletest/BUILD.gn | 175 +++-- build/third_party_gn/icu/icu4c/BUILD.gn | 16 +- build/third_party_gn/libuv/BUILD.gn | 35 +- build/third_party_gn/libuv/src/log_ohos.c | 20 + build/third_party_gn/libuv/src/trace_ohos.c | 19 + build/third_party_gn/musl/BUILD.gn | 69 +- build/third_party_gn/musl/musl_src.gni | 720 +++++++++++++------- build/third_party_gn/musl/musl_template.gni | 105 +-- build/third_party_gn/openssl/BUILD.gn | 4 + 9 files changed, 732 insertions(+), 431 deletions(-) create mode 100644 build/third_party_gn/libuv/src/log_ohos.c create mode 100644 build/third_party_gn/libuv/src/trace_ohos.c diff --git a/build/third_party_gn/googletest/BUILD.gn b/build/third_party_gn/googletest/BUILD.gn index 05146504..04449d71 100644 --- a/build/third_party_gn/googletest/BUILD.gn +++ b/build/third_party_gn/googletest/BUILD.gn @@ -19,8 +19,22 @@ config("gtest_private_config") { include_dirs = [ "$googletest_dir" ] } +config("gtest_private_config_rtti") { + visibility = [ ":*" ] + include_dirs = [ "googletest" ] + cflags = [ "-frtti" ] + cflags_objcc = [ "-frtti" ] + cflags_cc = [ "-frtti" ] +} + config("gtest_config") { include_dirs = [ "$googletest_dir/include" ] + cflags_cc = [ + "-std=c++17", + "-Wno-float-equal", + "-Wno-sign-compare", + "-Wno-reorder-init-list", + ] if (is_mingw) { cflags_cc = [ "-Wno-unused-const-variable", @@ -29,57 +43,74 @@ config("gtest_config") { } } +sources_files = [ + "$googletest_dir/include/gtest/gtest-death-test.h", + "$googletest_dir/include/gtest/gtest-matchers.h", + "$googletest_dir/include/gtest/gtest-message.h", + "$googletest_dir/include/gtest/gtest-param-test.h", + "$googletest_dir/include/gtest/gtest-printers.h", + "$googletest_dir/include/gtest/gtest-test-part.h", + "$googletest_dir/include/gtest/gtest-typed-test.h", + "$googletest_dir/include/gtest/gtest_pred_impl.h", + "$googletest_dir/include/gtest/gtest_prod.h", + "$googletest_dir/include/gtest/hwext/gtest-ext.h", + "$googletest_dir/include/gtest/hwext/gtest-filter.h", + "$googletest_dir/include/gtest/hwext/gtest-multithread.h", + "$googletest_dir/include/gtest/hwext/gtest-tag.h", + "$googletest_dir/include/gtest/hwext/utils.h", + "$googletest_dir/include/gtest/internal/custom/gtest-port.h", + "$googletest_dir/include/gtest/internal/custom/gtest-printers.h", + "$googletest_dir/include/gtest/internal/custom/gtest.h", + "$googletest_dir/include/gtest/internal/gtest-death-test-internal.h", + "$googletest_dir/include/gtest/internal/gtest-filepath.h", + "$googletest_dir/include/gtest/internal/gtest-internal.h", + "$googletest_dir/include/gtest/internal/gtest-param-util.h", + "$googletest_dir/include/gtest/internal/gtest-port-arch.h", + "$googletest_dir/include/gtest/internal/gtest-port.h", + "$googletest_dir/include/gtest/internal/gtest-string.h", + "$googletest_dir/include/gtest/internal/gtest-type-util.h", + "$googletest_dir/src/gtest-all.cc", + "$googletest_dir/src/gtest-assertion-result.cc", + "$googletest_dir/src/gtest-death-test.cc", + "$googletest_dir/src/gtest-filepath.cc", + "$googletest_dir/src/gtest-internal-inl.h", + "$googletest_dir/src/gtest-matchers.cc", + "$googletest_dir/src/gtest-port.cc", + "$googletest_dir/src/gtest-printers.cc", + "$googletest_dir/src/gtest-test-part.cc", + "$googletest_dir/src/gtest-typed-test.cc", + "$googletest_dir/src/gtest.cc", + "$googletest_dir/src/hwext/gtest-ext.cc", + "$googletest_dir/src/hwext/gtest-filter.cc", + "$googletest_dir/src/hwext/gtest-multithread.cpp", + "$googletest_dir/src/hwext/gtest-tag.cc", + "$googletest_dir/src/hwext/gtest-utils.cc", +] + static_library("gtest") { testonly = true public = [ "$googletest_dir/include/gtest/gtest-spi.h", "$googletest_dir/include/gtest/gtest.h", ] - sources = [ - "$googletest_dir/include/gtest/gtest-death-test.h", - "$googletest_dir/include/gtest/gtest-matchers.h", - "$googletest_dir/include/gtest/gtest-message.h", - "$googletest_dir/include/gtest/gtest-param-test.h", - "$googletest_dir/include/gtest/gtest-printers.h", - "$googletest_dir/include/gtest/gtest-test-part.h", - "$googletest_dir/include/gtest/gtest-typed-test.h", - "$googletest_dir/include/gtest/gtest_pred_impl.h", - "$googletest_dir/include/gtest/gtest_prod.h", - "$googletest_dir/include/gtest/hwext/gtest-ext.h", - "$googletest_dir/include/gtest/hwext/gtest-filter.h", - "$googletest_dir/include/gtest/hwext/gtest-tag.h", - "$googletest_dir/include/gtest/hwext/utils.h", - "$googletest_dir/include/gtest/internal/custom/gtest-port.h", - "$googletest_dir/include/gtest/internal/custom/gtest-printers.h", - "$googletest_dir/include/gtest/internal/custom/gtest.h", - "$googletest_dir/include/gtest/internal/gtest-death-test-internal.h", - "$googletest_dir/include/gtest/internal/gtest-filepath.h", - "$googletest_dir/include/gtest/internal/gtest-internal.h", - "$googletest_dir/include/gtest/internal/gtest-param-util.h", - "$googletest_dir/include/gtest/internal/gtest-port-arch.h", - "$googletest_dir/include/gtest/internal/gtest-port.h", - "$googletest_dir/include/gtest/internal/gtest-string.h", - "$googletest_dir/include/gtest/internal/gtest-type-util.h", - "$googletest_dir/src/gtest-all.cc", - "$googletest_dir/src/gtest-death-test.cc", - "$googletest_dir/src/gtest-filepath.cc", - "$googletest_dir/src/gtest-internal-inl.h", - "$googletest_dir/src/gtest-matchers.cc", - "$googletest_dir/src/gtest-port.cc", - "$googletest_dir/src/gtest-printers.cc", - "$googletest_dir/src/gtest-test-part.cc", - "$googletest_dir/src/gtest-typed-test.cc", - "$googletest_dir/src/gtest.cc", - "$googletest_dir/src/hwext/gtest-ext.cc", - "$googletest_dir/src/hwext/gtest-filter.cc", - "$googletest_dir/src/hwext/gtest-tag.cc", - "$googletest_dir/src/hwext/gtest-utils.cc", - ] + sources = sources_files sources -= [ "$googletest_dir/src/gtest-all.cc" ] public_configs = [ ":gtest_config" ] configs += [ ":gtest_private_config" ] } +static_library("gtest_rtti") { + testonly = true + public = [ + "$googletest_dir/include/gtest/gtest-spi.h", + "$googletest_dir/include/gtest/gtest.h", + ] + sources = sources_files + sources -= [ "$googletest_dir/src/gtest-all.cc" ] + public_configs = [ ":gtest_config" ] + configs += [ ":gtest_private_config_rtti" ] +} + static_library("gtest_main") { testonly = true sources = [ "$googletest_dir/src/gtest_main.cc" ] @@ -91,6 +122,14 @@ config("gmock_private_config") { include_dirs = [ "$googlemock_dir" ] } +config("gmock_private_config_rtti") { + visibility = [ ":*" ] + include_dirs = [ "googlemock_dir/include" ] + cflags = [ "-frtti" ] + cflags_objcc = [ "-frtti" ] + cflags_cc = [ "-frtti" ] +} + config("gmock_config") { include_dirs = [ "$googlemock_dir/include" ] @@ -104,37 +143,49 @@ config("gmock_config") { ] } +gmock_sources_files = [ + "$googlemock_dir/include/gmock/gmock-actions.h", + "$googlemock_dir/include/gmock/gmock-cardinalities.h", + "$googlemock_dir/include/gmock/gmock-function-mocker.h", + "$googlemock_dir/include/gmock/gmock-matchers.h", + "$googlemock_dir/include/gmock/gmock-more-actions.h", + "$googlemock_dir/include/gmock/gmock-more-matchers.h", + "$googlemock_dir/include/gmock/gmock-nice-strict.h", + "$googlemock_dir/include/gmock/gmock-spec-builders.h", + "$googlemock_dir/include/gmock/internal/custom/gmock-generated-actions.h", + "$googlemock_dir/include/gmock/internal/custom/gmock-matchers.h", + "$googlemock_dir/include/gmock/internal/custom/gmock-port.h", + "$googlemock_dir/include/gmock/internal/gmock-internal-utils.h", + "$googlemock_dir/include/gmock/internal/gmock-port.h", + "$googlemock_dir/include/gmock/internal/gmock-pp.h", + "$googlemock_dir/src/gmock-all.cc", + "$googlemock_dir/src/gmock-cardinalities.cc", + "$googlemock_dir/src/gmock-internal-utils.cc", + "$googlemock_dir/src/gmock-matchers.cc", + "$googlemock_dir/src/gmock-spec-builders.cc", + "$googlemock_dir/src/gmock.cc", +] + static_library("gmock") { testonly = true public = [ "$googlemock_dir/include/gmock/gmock.h" ] - sources = [ - "$googlemock_dir/include/gmock/gmock-actions.h", - "$googlemock_dir/include/gmock/gmock-cardinalities.h", - "$googlemock_dir/include/gmock/gmock-function-mocker.h", - "$googlemock_dir/include/gmock/gmock-matchers.h", - "$googlemock_dir/include/gmock/gmock-more-actions.h", - "$googlemock_dir/include/gmock/gmock-more-matchers.h", - "$googlemock_dir/include/gmock/gmock-nice-strict.h", - "$googlemock_dir/include/gmock/gmock-spec-builders.h", - "$googlemock_dir/include/gmock/internal/custom/gmock-generated-actions.h", - "$googlemock_dir/include/gmock/internal/custom/gmock-matchers.h", - "$googlemock_dir/include/gmock/internal/custom/gmock-port.h", - "$googlemock_dir/include/gmock/internal/gmock-internal-utils.h", - "$googlemock_dir/include/gmock/internal/gmock-port.h", - "$googlemock_dir/include/gmock/internal/gmock-pp.h", - "$googlemock_dir/src/gmock-all.cc", - "$googlemock_dir/src/gmock-cardinalities.cc", - "$googlemock_dir/src/gmock-internal-utils.cc", - "$googlemock_dir/src/gmock-matchers.cc", - "$googlemock_dir/src/gmock-spec-builders.cc", - "$googlemock_dir/src/gmock.cc", - ] + sources = gmock_sources_files sources -= [ "$googlemock_dir/src/gmock-all.cc" ] public_configs = [ ":gmock_config" ] configs += [ ":gmock_private_config" ] deps = [ ":gtest" ] } +static_library("gmock_rtti") { + testonly = true + public = [ "$googlemock_dir/include/gmock/gmock.h" ] + sources = gmock_sources_files + sources -= [ "$googlemock_dir/src/gmock-all.cc" ] + public_configs = [ ":gmock_config" ] + configs += [ ":gmock_private_config_rtti" ] + deps = [ ":gtest_rtti" ] +} + static_library("gmock_main") { testonly = true sources = [ "$googlemock_dir/src/gmock_main.cc" ] diff --git a/build/third_party_gn/icu/icu4c/BUILD.gn b/build/third_party_gn/icu/icu4c/BUILD.gn index 082ce8bc..cafe6465 100644 --- a/build/third_party_gn/icu/icu4c/BUILD.gn +++ b/build/third_party_gn/icu/icu4c/BUILD.gn @@ -499,13 +499,7 @@ ohos_shared_library("shared_icuuc") { "-shared", "-lm", ] - if (current_os == "ios") { - ldflags += [ - "-Wl", - "-install_name", - "@rpath/libhmicuuc.framework/libhmicuuc", - ] - } + configs = [ ":icu_config", "$build_root/config/compiler:rtti", @@ -552,14 +546,6 @@ ohos_shared_library("shared_icuuc") { install_enable = true } -if (current_os == "ios") { - ohos_combine_darwin_framework("libhmicuuc") { - deps = [ ":shared_icuuc" ] - subsystem_name = "thirdparty" - part_name = "icu" - } -} - ohos_shared_library("shared_icui18n") { ldflags = [ "-shared", diff --git a/build/third_party_gn/libuv/BUILD.gn b/build/third_party_gn/libuv/BUILD.gn index b7276c26..5bb82bb0 100644 --- a/build/third_party_gn/libuv/BUILD.gn +++ b/build/third_party_gn/libuv/BUILD.gn @@ -20,6 +20,7 @@ common_source = [ "//third_party/libuv/src/random.c", "//third_party/libuv/src/strscpy.c", "//third_party/libuv/src/threadpool.c", + "//third_party/libuv/src/thread-common.c", "//third_party/libuv/src/timer.c", "//third_party/libuv/src/uv-common.c", "//third_party/libuv/src/uv-data-getter-setters.c", @@ -28,7 +29,6 @@ common_source = [ ] if (!is_mingw && !is_win) { nonwin_srcs = [ - "//third_party/libuv/src/unix/epoll.c", "//third_party/libuv/src/unix/async.c", "//third_party/libuv/src/unix/core.c", "//third_party/libuv/src/unix/dl.c", @@ -57,6 +57,7 @@ config("libuv_config") { "//third_party/libuv/src", "//third_party/libuv/src/unix", ] + defines = [] cflags = [ "-Wno-unused-parameter" ] if (is_linux || is_ohos) { cflags += [ @@ -68,7 +69,7 @@ config("libuv_config") { # Adding NDEBUG macro manually to avoid compilation # error in debug version, FIX ME # https://gitee.com/openharmony/build/pulls/1206/files - defines = [ "NDEBUG" ] + defines += [ "NDEBUG" ] } else if (is_mingw || is_win) { cflags += [ "-Wno-missing-braces", @@ -79,7 +80,7 @@ config("libuv_config") { "-Wno-error=unknown-pragmas", "-Wno-unused-variable", ] - defines = [ + defines += [ "WIN32_LEAN_AND_MEAN", "_WIN32_WINNT=0x0600", ] @@ -98,7 +99,7 @@ config("libuv_config") { "ws2_32", ] } else if (is_android) { - defines = [ "_GNU_SOURCE" ] + defines += [ "_GNU_SOURCE" ] } } @@ -122,7 +123,7 @@ ohos_source_set("libuv_source") { stack_protector_ret = false configs = [ ":libuv_config" ] sources = common_source - + external_deps = [] if (is_mac || (defined(is_ios) && is_ios)) { sources += nonwin_srcs + [ "//third_party/libuv/src/unix/bsd-ifaddrs.c", @@ -132,8 +133,9 @@ ohos_source_set("libuv_source") { "//third_party/libuv/src/unix/darwin.c", "//third_party/libuv/src/unix/fsevents.c", "//third_party/libuv/src/unix/os390-proctitle.c", + "//third_party/libuv/src/unix/log_unix.c", + "//third_party/libuv/src/unix/trace_unix.c", ] - sources -= [ "//third_party/libuv/src/unix/epoll.c" ] } else if (is_mingw || is_win) { sources += [ "//third_party/libuv/src/win/async.c", @@ -146,6 +148,7 @@ ohos_source_set("libuv_source") { "//third_party/libuv/src/win/getaddrinfo.c", "//third_party/libuv/src/win/getnameinfo.c", "//third_party/libuv/src/win/handle.c", + "//third_party/libuv/src/win/log_win.c", "//third_party/libuv/src/win/loop-watcher.c", "//third_party/libuv/src/win/pipe.c", "//third_party/libuv/src/win/poll.c", @@ -156,6 +159,7 @@ ohos_source_set("libuv_source") { "//third_party/libuv/src/win/stream.c", "//third_party/libuv/src/win/tcp.c", "//third_party/libuv/src/win/thread.c", + "//third_party/libuv/src/win/trace_win.c", "//third_party/libuv/src/win/tty.c", "//third_party/libuv/src/win/udp.c", "//third_party/libuv/src/win/util.c", @@ -164,31 +168,30 @@ ohos_source_set("libuv_source") { ] } else if (is_ohos || (defined(is_android) && is_android)) { sources += nonwin_srcs + [ - "//third_party/libuv/src/unix/linux-core.c", - "//third_party/libuv/src/unix/linux-inotify.c", - "//third_party/libuv/src/unix/linux-syscalls.c", + "//third_party/libuv/src/unix/linux.c", "//third_party/libuv/src/unix/procfs-exepath.c", - "//third_party/libuv/src/unix/pthread-fixes.c", "//third_party/libuv/src/unix/random-getentropy.c", "//third_party/libuv/src/unix/random-getrandom.c", "//third_party/libuv/src/unix/random-sysctl-linux.c", "//third_party/libuv/src/unix/proctitle.c", ] + sources += [ + "src/log_ohos.c", + "src/trace_ohos.c", + ] } else if (is_linux) { sources += nonwin_srcs + [ - "//third_party/libuv/src/unix/linux-core.c", - "//third_party/libuv/src/unix/linux-inotify.c", - "//third_party/libuv/src/unix/linux-syscalls.c", + "//third_party/libuv/src/unix/linux.c", "//third_party/libuv/src/unix/procfs-exepath.c", "//third_party/libuv/src/unix/random-getrandom.c", "//third_party/libuv/src/unix/random-sysctl-linux.c", "//third_party/libuv/src/unix/proctitle.c", + "//third_party/libuv/src/unix/log_unix.c", + "//third_party/libuv/src/unix/trace_unix.c", ] } else { sources += nonwin_srcs + [ - "//third_party/libuv/src/unix/linux-core.c", - "//third_party/libuv/src/unix/linux-inotify.c", - "//third_party/libuv/src/unix/linux-syscalls.c", + "//third_party/libuv/src/unix/linux.c", "//third_party/libuv/src/unix/procfs-exepath.c", "//third_party/libuv/src/unix/random-getrandom.c", "//third_party/libuv/src/unix/random-sysctl-linux.c", diff --git a/build/third_party_gn/libuv/src/log_ohos.c b/build/third_party_gn/libuv/src/log_ohos.c new file mode 100644 index 00000000..adca6ab0 --- /dev/null +++ b/build/third_party_gn/libuv/src/log_ohos.c @@ -0,0 +1,20 @@ +/* + * 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. + */ +#include "uv_log.h" + +int uv__log_impl(enum uv__log_level level, const char* fmt, ...) +{ + return 0; +} \ No newline at end of file diff --git a/build/third_party_gn/libuv/src/trace_ohos.c b/build/third_party_gn/libuv/src/trace_ohos.c new file mode 100644 index 00000000..d288639d --- /dev/null +++ b/build/third_party_gn/libuv/src/trace_ohos.c @@ -0,0 +1,19 @@ +/* + * 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 +#define UV_TRACE_TAG (1ULL << 30) + +void uv_start_trace(uint64_t tag, const char* name) {} +void uv_end_trace(uint64_t tag) {} \ No newline at end of file diff --git a/build/third_party_gn/musl/BUILD.gn b/build/third_party_gn/musl/BUILD.gn index 2b827ba2..8cbfe3ec 100644 --- a/build/third_party_gn/musl/BUILD.gn +++ b/build/third_party_gn/musl/BUILD.gn @@ -39,41 +39,46 @@ action("create_porting_src") { outdir = [ "${target_out_dir}/${musl_ported_dir}" ] src_files = musl_src_arch_file - src_files += musl_inc_root_files - src_files += musl_inc_fortify_files - src_files += musl_inc_sys_files - src_files += musl_inc_scsi_files - src_files += musl_inc_netpacket_files - src_files += musl_inc_netinet_files - src_files += musl_inc_net_files - src_files += musl_inc_arpa_files - src_files += musl_inc_bits_files - src_files += musl_src_ldso src_files += musl_src_file + src_files += musl_src_ldso + src_files += musl_inc_bits_files + src_files += musl_inc_arpa_files + src_files += musl_inc_net_files + src_files += musl_inc_netinet_files + src_files += musl_inc_netpacket_files + src_files += musl_inc_scsi_files + src_files += musl_inc_sys_files + src_files += musl_inc_fortify_files + src_files += musl_inc_root_files + src_files += musl_inc_info_files + src_files += musl_inc_trace_files src_files += [ - "scripts/create_syscall.sh", - "scripts/create_vesion.sh", - "scripts/create_alltypes.sh", - "scripts/install.py", - "tools/install.sh", - "tools/version.sh", - "VERSION", - "include/alltypes.h.in", - "arch/${musl_arch}/bits/syscall.h.in", - "arch/${musl_arch}/bits/alltypes.h.in", - "tools/mkalltypes.sed", - "crt/rcrt1.c", - "crt/crt1.c", "crt/Scrt1.c", - "crt/${musl_arch}/crtn.s", + "crt/crt1.c", + "crt/rcrt1.c", + "tools/mkalltypes.sed", + "arch/${musl_arch}/bits/alltypes.h.in", + "arch/${musl_arch}/bits/syscall.h.in", + "include/alltypes.h.in", + "VERSION", + "tools/version.sh", + "tools/install.sh", + "scripts/install.py", + "scripts/create_alltypes.sh", + "scripts/create_vesion.sh", + "scripts/create_syscall.sh", + ] + src_files += [ "crt/${musl_arch}/crti.s", + "crt/${musl_arch}/crtn.s", ] + args = [ "-i" ] + rebase_path(sources_dir) args += [ "-o" ] + rebase_path(outdir) args += [ "-p" ] + [ "${musl_target_os}" ] foreach(i, src_files) { - foreach(s, musl_src_porting_file) { + foreach(s, musl_src_files_ext) { if (i == s) { src_files -= [ "${s}" ] } @@ -85,16 +90,24 @@ action("create_porting_src") { outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] } - foreach(s, musl_src_porting_file) { + foreach(s, musl_src_files_ext) { outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] } + inputs = [] + foreach(i, src_files) { + foreach(s, musl_src_linux_files) { + if (i == s) { + src_files -= [ "${s}" ] + } + } + } foreach(s, src_files) { inputs += [ "${musl_dir}/${s}" ] } - foreach(s, musl_src_porting_file) { - inputs += [ "${musl_porting_dir}/${s}" ] + foreach(s, musl_src_files_ext) { + inputs += [ "${musl_dir}/${s}" ] } } diff --git a/build/third_party_gn/musl/musl_src.gni b/build/third_party_gn/musl/musl_src.gni index eeb0267d..aa32f5cc 100644 --- a/build/third_party_gn/musl/musl_src.gni +++ b/build/third_party_gn/musl/musl_src.gni @@ -14,6 +14,7 @@ import("//third_party/FreeBSD/FreeBSD.gni") import("$build_root/third_party_gn/musl/musl_config.gni") +OPTRTDIR = "//third_party/optimized-routines/" if (musl_arch == "arm") { musl_src_arch_file = [ "src/exit/arm/__aeabi_atexit.c", @@ -21,7 +22,6 @@ if (musl_arch == "arm") { "src/fenv/arm/fenv.c", "src/ldso/arm/dlsym.s", "src/ldso/arm/dlsym_time64.S", - "src/ldso/arm/dlvsym.s", "src/ldso/arm/find_exidx.c", "src/ldso/arm/tlsdesc.S", "src/math/arm/fabs.c", @@ -44,6 +44,7 @@ if (musl_arch == "arm") { "src/thread/arm/atomics.s", "src/thread/arm/clone.s", "src/thread/arm/syscall_cp.s", + "src/linux/arm/flock.s", "compat/time32/adjtime32.c", "compat/time32/adjtimex_time32.c", "compat/time32/aio_suspend_time32.c", @@ -113,7 +114,6 @@ if (musl_arch == "arm") { musl_src_arch_file = [ "src/fenv/aarch64/fenv.s", "src/ldso/aarch64/dlsym.s", - "src/ldso/aarch64/dlvsym.s", "src/ldso/aarch64/tlsdesc.s", "src/math/aarch64/ceil.c", "src/math/aarch64/ceilf.c", @@ -152,15 +152,58 @@ if (musl_arch == "arm") { "src/thread/aarch64/__set_thread_area.s", "src/thread/aarch64/__unmapself.s", "src/thread/aarch64/clone.s", - "src/misc/aarch64/fstat.s", "src/thread/aarch64/syscall_cp.s", - "src/misc/aarch64/syscall.s", + "src/linux/aarch64/flock.s", + ] +} else if (musl_arch == "mips") { + musl_src_arch_file = [ + "src/fenv/mips/fenv-sf.c", + "src/fenv/mips/fenv.S", + "src/ldso/mips/dlsym_time64.S", + "src/ldso/mips/dlsym.s", + "src/math/mips/fabs.c", + "src/math/mips/fabsf.c", + "src/math/mips/sqrt.c", + "src/math/mips/sqrtf.c", + "src/setjmp/mips/longjmp.S", + "src/setjmp/mips/setjmp.S", + "src/signal/mips/sigsetjmp.s", + "src/thread/mips/__unmapself.s", + "src/thread/mips/clone.s", + "src/thread/mips/syscall_cp.s", + "src/unistd/mips/pipe.s", + ] +} else if (musl_arch == "riscv64") { + musl_src_arch_file = [ + "src/fenv/riscv64/fenv-sf.c", + "src/fenv/riscv64/fenv.S", + "src/ldso/riscv64/dlsym.s", + "src/ldso/riscv64/tlsdesc.s", + "src/math/riscv64/copysign.c", + "src/math/riscv64/copysignf.c", + "src/math/riscv64/fabs.c", + "src/math/riscv64/fabsf.c", + "src/math/riscv64/fma.c", + "src/math/riscv64/fmaf.c", + "src/math/riscv64/fmax.c", + "src/math/riscv64/fmaxf.c", + "src/math/riscv64/fmin.c", + "src/math/riscv64/fminf.c", + "src/math/riscv64/sqrt.c", + "src/math/riscv64/sqrtf.c", + "src/setjmp/riscv64/longjmp.S", + "src/setjmp/riscv64/setjmp.S", + "src/signal/riscv64/restore.s", + "src/signal/riscv64/sigsetjmp.s", + "src/thread/riscv64/__set_thread_area.s", + "src/thread/riscv64/__unmapself.s", + "src/thread/riscv64/clone.s", + "src/thread/riscv64/syscall_cp.s", ] } else if (musl_arch == "x86_64") { musl_src_arch_file = [ "src/fenv/x86_64/fenv.s", "src/ldso/x86_64/dlsym.s", - "src/ldso/x86_64/dlvsym.s", "src/ldso/x86_64/tlsdesc.s", "src/math/x86_64/__invtrigl.s", "src/math/x86_64/acosl.s", @@ -205,38 +248,32 @@ if (musl_arch == "arm") { "src/thread/x86_64/__unmapself.s", "src/thread/x86_64/clone.s", "src/thread/x86_64/syscall_cp.s", + "src/linux/x86_64/flock.s", ] -} else if (musl_arch == "mips") { +} else if (musl_arch == "loongarch64") { musl_src_arch_file = [ - "src/fenv/mips/fenv.S", - "src/fenv/mips/fenv-sf.c", - "src/ldso/mips/dlsym.s", - "src/ldso/mips/dlsym_time64.S", - "src/math/mips/fabs.c", - "src/math/mips/fabsf.c", - "src/math/mips/sqrt.c", - "src/math/mips/sqrtf.c", - "src/setjmp/mips/longjmp.S", - "src/setjmp/mips/setjmp.S", - "src/signal/mips/restore.s", - "src/signal/mips/sigsetjmp.s", - "src/thread/mips/__unmapself.s", - "src/thread/mips/clone.s", - "src/thread/mips/syscall_cp.s", + "src/fenv/loongarch64/fenv.S", + "src/ldso/loongarch64/dlsym.s", + "src/ldso/loongarch64/tlsdesc.s", + "src/setjmp/loongarch64/longjmp.S", + "src/setjmp/loongarch64/setjmp.S", + "src/signal/loongarch64/restore.s", + "src/signal/loongarch64/sigsetjmp.s", + "src/thread/loongarch64/__set_thread_area.s", + "src/thread/loongarch64/__unmapself.s", + "src/thread/loongarch64/clone.s", + "src/thread/loongarch64/syscall_cp.s", ] } musl_src_file = [ - "src/thread/pthread_cond_clockwait.c", - "src/thread/pthread_cond_timedwait_monotonic_np.c", - "src/thread/pthread_cond_timeout_np.c", "src/internal/pthread_impl.h", "src/internal/locale_impl.h", - "src/thread/pthread_rwlock_clockrdlock.c", + "src/internal/locale_impl.c", + "src/internal/stdio_impl.h", + "src/internal/unsupported_api.h", + "src/internal/syscall_hooks.h", "src/thread/pthread_rwlock_timedrdlock.c", - "src/thread/pthread_rwlock_timedrdlock_monotonic_np.c", - "src/thread/pthread_rwlock_clockwrlock.c", - "src/thread/pthread_rwlock_timedwrlock_monotonic_np.c", "src/thread/pthread_rwlock_timedwrlock.c", "src/aio/aio.c", "src/aio/aio_suspend.c", @@ -391,6 +428,7 @@ musl_src_file = [ "src/exit/at_quick_exit.c", "src/exit/atexit.c", "src/exit/exit.c", + "src/exit/cxa_thread_atexit_impl.c", "src/exit/quick_exit.c", "src/fcntl/creat.c", "src/fcntl/fcntl.c", @@ -398,6 +436,7 @@ musl_src_file = [ "src/fcntl/openat.c", "src/fcntl/posix_fadvise.c", "src/fcntl/posix_fallocate.c", + "src/fdsan/fdsan.c", "src/fenv/__flt_rounds.c", "src/fenv/fegetexceptflag.c", "src/fenv/feholdexcept.c", @@ -406,6 +445,8 @@ musl_src_file = [ "src/fenv/fesetround.c", "src/fenv/feupdateenv.c", "src/fortify/fortify.c", + "src/gwp_asan/gwp_asan.c", + "src/gwp_asan/gwp_asan.h", "src/internal/defsysinfo.c", "src/internal/floatscan.c", "src/internal/intscan.c", @@ -413,9 +454,7 @@ musl_src_file = [ "src/internal/procfdname.c", "src/internal/shgetc.c", "src/internal/syscall_ret.c", - "src/internal/vdso.c", "src/internal/version.c", - "src/internal/network_conf_function.c", "src/hilog/hilog_adapter.c", "src/hilog/vsnprintf_s_p.c", "src/ipc/ftok.c", @@ -488,15 +527,14 @@ musl_src_file = [ "src/linux/open_by_handle_at.c", "src/linux/personality.c", "src/linux/pivot_root.c", - "src/linux/ppoll.c", "src/linux/prctl.c", + "src/linux/preadv2.c", "src/linux/prlimit.c", "src/linux/process_vm.c", "src/linux/ptrace.c", "src/linux/quotactl.c", "src/linux/readahead.c", "src/linux/reboot.c", - "src/linux/tgkill.c", "src/linux/remap_file_pages.c", "src/linux/sbrk.c", "src/linux/sendfile.c", @@ -508,6 +546,7 @@ musl_src_file = [ "src/linux/settimeofday.c", "src/linux/signalfd.c", "src/linux/splice.c", + "src/linux/statx.c", "src/linux/stime.c", "src/linux/swap.c", "src/linux/sync_file_range.c", @@ -521,6 +560,7 @@ musl_src_file = [ "src/linux/vmsplice.c", "src/linux/wait3.c", "src/linux/wait4.c", + "src/linux/pwritev2.c", "src/linux/xattr.c", "src/locale/__lctrans.c", "src/locale/__mo_lookup.c", @@ -542,6 +582,7 @@ musl_src_file = [ "src/locale/setlocale.c", "src/locale/strcoll.c", "src/locale/strtod_l.c", + "src/locale/wcstod_l.c", "src/locale/strfmon.c", "src/locale/strxfrm.c", "src/locale/textdomain.c", @@ -556,8 +597,6 @@ musl_src_file = [ "src/malloc/mallocng/malloc.c", "src/malloc/mallocng/meta.h", "src/malloc/mallocng/realloc.c", - "src/malloc/stats.c", - "src/malloc/calloc.c", "src/malloc/free.c", "src/malloc/libc_calloc.c", "src/malloc/lite_malloc.c", @@ -1029,6 +1068,7 @@ musl_src_file = [ "src/regex/regerror.c", "src/regex/regexec.c", "src/regex/tre-mem.c", + "src/syscall_hooks/syscall_hooks.c", "src/sched/sched_cpualloc.c", "src/sched/affinity.c", "src/sched/sched_cpucount.c", @@ -1049,6 +1089,7 @@ musl_src_file = [ "src/search/tsearch.c", "src/search/twalk.c", "src/select/poll.c", + "src/select/ppoll.c", "src/select/pselect.c", "src/select/select.c", "src/setjmp/longjmp.c", @@ -1091,7 +1132,6 @@ musl_src_file = [ "src/signal/sigtimedwait.c", "src/signal/sigwait.c", "src/signal/sigwaitinfo.c", - "src/sigchain/sigchain.c", "src/stat/__xstat.c", "src/stat/chmod.c", "src/stat/fchmod.c", @@ -1250,6 +1290,7 @@ musl_src_file = [ "src/stdlib/strtol.c", "src/stdlib/wcstod.c", "src/stdlib/wcstol.c", + "src/string/strcspn.c", "src/string/bcmp.c", "src/string/bcopy.c", "src/string/bzero.c", @@ -1268,13 +1309,11 @@ musl_src_file = [ "src/string/stpcpy.c", "src/string/stpncpy.c", "src/string/strcasecmp.c", - "src/string/strcasestr.c", "src/string/strcat.c", "src/string/strchr.c", "src/string/strchrnul.c", "src/string/strcmp.c", "src/string/strcpy.c", - "src/string/strcspn.c", "src/string/strdup.c", "src/string/strerror_r.c", "src/string/strlcat.c", @@ -1415,9 +1454,6 @@ musl_src_file = [ "src/thread/pthread_mutex_lock.c", "src/thread/pthread_mutex_setprioceiling.c", "src/thread/pthread_mutex_timedlock.c", - "src/thread/pthread_mutex_clocklock.c", - "src/thread/pthread_mutex_timedlock_monotonic_np.c", - "src/thread/pthread_mutex_lock_timeout_np.c", "src/thread/pthread_mutex_trylock.c", "src/thread/pthread_mutex_unlock.c", "src/thread/pthread_mutexattr_destroy.c", @@ -1596,6 +1632,39 @@ musl_src_file = [ "src/info/application_target_sdk_version.c", "src/info/device_api_version.c", "src/info/fatal_message.c", + "arch/generic/crtbrand.s", + "crt/crtplus.c", + "ldso/namespace.h", + "ldso/ns_config.h", + "ldso/strops.h", + "ldso/cfi.h", + "ldso/ld_log.h", + "ldso/dynlink_rand.h", + "src/internal/vdso.c", + "src/internal/emulate_wait4.c", + "src/internal/malloc_config.h", + "src/internal/malloc_random.h", + "src/internal/hilog_adapter.h", + "src/internal/musl_log.h", + "src/internal/musl_log.c", + "src/internal/network_conf_function.c", + "src/internal/network_conf_function.h", + "src/internal/services.h", + "src/internal/proc_xid_impl.h", + "src/linux/tgkill.c", + "src/malloc/calloc.c", + "src/malloc/stats.c", + "src/sigchain/sigchain.c", + "src/thread/pthread_cond_clockwait.c", + "src/thread/pthread_cond_timedwait_monotonic_np.c", + "src/thread/pthread_cond_timeout_np.c", + "src/thread/pthread_mutex_clocklock.c", + "src/thread/pthread_mutex_timedlock_monotonic_np.c", + "src/thread/pthread_mutex_lock_timeout_np.c", + "src/thread/pthread_rwlock_clockrdlock.c", + "src/thread/pthread_rwlock_timedrdlock_monotonic_np.c", + "src/thread/pthread_rwlock_clockwrlock.c", + "src/thread/pthread_rwlock_timedwrlock_monotonic_np.c", ] if (musl_arch == "arm") { @@ -1718,13 +1787,54 @@ if (musl_arch == "arm") { musl_src_filterout = [ "src/fenv/fenv.c", "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", + "src/math/fabs.c", + "src/math/fabsf.c", + "src/math/sqrt.c", + "src/math/sqrtf.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/thread/__unmapself.c", + "src/thread/clone.c", + "src/thread/syscall_cp.c", + "src/unistd/pipe.c", + ] +} else if (musl_arch == "riscv64") { + musl_src_filterout = [ + "src/fenv/fenv.c", + "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", "src/math/fabs.c", "src/math/fabsf.c", + "src/math/fma.c", "src/math/fmaf.c", + "src/math/fmax.c", + "src/math/fmaxf.c", + "src/math/fmin.c", + "src/math/fminf.c", "src/math/sqrt.c", "src/math/sqrtf.c", + "src/setjmp/longjmp.c", "src/setjmp/setjmp.c", "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/thread/__set_thread_area.c", + "src/thread/__unmapself.c", + "src/thread/clone.c", + "src/thread/syscall_cp.c", + ] +} else if (musl_arch == "loongarch64") { + musl_src_filterout = [ + "src/fenv/fenv.c", + "src/ldso/dlsym.c", + "src/ldso/tlsdesc.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/restore.c", + "src/signal/sigsetjmp.c", + "src/thread/__set_thread_area.c", "src/thread/__unmapself.c", "src/thread/clone.c", "src/thread/syscall_cp.c", @@ -1828,7 +1938,6 @@ if (musl_arch == "arm") { "arch/x86_64/bits/stat.h", "arch/x86_64/bits/stdint.h", "arch/x86_64/bits/user.h", - "arch/generic/bits/dirent.h", "arch/generic/bits/errno.h", "arch/generic/bits/hwcap.h", @@ -1855,40 +1964,115 @@ if (musl_arch == "arm") { ] } else if (musl_arch == "mips") { musl_inc_bits_files = [ - "arch/mips/bits/errno.h", - "arch/mips/bits/fcntl.h", + "arch/generic/bits/fcntl.h", "arch/mips/bits/fenv.h", "arch/mips/bits/float.h", - "arch/mips/bits/hwcap.h", - "arch/mips/bits/ioctl.h", - "arch/mips/bits/ipcstat.h", - "arch/mips/bits/mman.h", - "arch/mips/bits/msg.h", - "arch/mips/bits/poll.h", "arch/mips/bits/posix.h", - "arch/mips/bits/ptrace.h", "arch/mips/bits/reg.h", - "arch/mips/bits/resource.h", - "arch/mips/bits/sem.h", "arch/mips/bits/setjmp.h", - "arch/mips/bits/shm.h", "arch/mips/bits/signal.h", - "arch/mips/bits/socket.h", "arch/mips/bits/stat.h", - "arch/mips/bits/statfs.h", "arch/mips/bits/stdint.h", - "arch/mips/bits/termios.h", "arch/mips/bits/user.h", + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/hwcap.h", "arch/generic/bits/ioctl_fix.h", + "arch/generic/bits/ioctl.h", "arch/generic/bits/io.h", "arch/generic/bits/ipc.h", + "arch/generic/bits/ipcstat.h", "arch/generic/bits/kd.h", "arch/generic/bits/limits.h", "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/msg.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/ptrace.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/sem.h", + "arch/generic/bits/shm.h", + "arch/generic/bits/socket.h", "arch/generic/bits/soundcard.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/termios.h", "arch/generic/bits/vt.h", ] +} else if (musl_arch == "riscv64") { + musl_inc_bits_files = [ + "arch/generic/bits/fcntl.h", + "arch/riscv64/bits/fenv.h", + "arch/riscv64/bits/float.h", + "arch/riscv64/bits/posix.h", + "arch/riscv64/bits/reg.h", + "arch/riscv64/bits/setjmp.h", + "arch/riscv64/bits/signal.h", + "arch/riscv64/bits/stat.h", + "arch/riscv64/bits/stdint.h", + "arch/riscv64/bits/user.h", + + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/hwcap.h", + "arch/generic/bits/ioctl_fix.h", + "arch/generic/bits/ioctl.h", + "arch/generic/bits/io.h", + "arch/generic/bits/ipc.h", + "arch/generic/bits/ipcstat.h", + "arch/generic/bits/kd.h", + "arch/generic/bits/limits.h", + "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/msg.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/ptrace.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/sem.h", + "arch/generic/bits/shm.h", + "arch/generic/bits/socket.h", + "arch/generic/bits/soundcard.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/termios.h", + "arch/generic/bits/vt.h", + ] +} else if (musl_arch == "loongarch64") { + musl_inc_bits_files = [ + "arch/loongarch64/bits/fenv.h", + "arch/loongarch64/bits/float.h", + "arch/loongarch64/bits/posix.h", + "arch/loongarch64/bits/reg.h", + "arch/loongarch64/bits/setjmp.h", + "arch/loongarch64/bits/signal.h", + "arch/loongarch64/bits/stat.h", + "arch/loongarch64/bits/stdint.h", + "arch/loongarch64/bits/user.h", + + "arch/generic/bits/dirent.h", + "arch/generic/bits/errno.h", + "arch/generic/bits/hwcap.h", + "arch/generic/bits/ioctl_fix.h", + "arch/generic/bits/ioctl.h", + "arch/generic/bits/io.h", + "arch/generic/bits/ipc.h", + "arch/generic/bits/ipcstat.h", + "arch/generic/bits/kd.h", + "arch/generic/bits/link.h", + "arch/generic/bits/mman.h", + "arch/generic/bits/msg.h", + "arch/generic/bits/poll.h", + "arch/generic/bits/sem.h", + "arch/generic/bits/shm.h", + "arch/generic/bits/socket.h", + "arch/generic/bits/soundcard.h", + "arch/generic/bits/termios.h", + "arch/generic/bits/vt.h", + "arch/generic/bits/statfs.h", + "arch/generic/bits/ptrace.h", + "arch/generic/bits/resource.h", + "arch/generic/bits/fcntl.h", + "arch/generic/bits/limits.h", + ] } musl_inc_arpa_files = [ @@ -2117,239 +2301,245 @@ musl_inc_root_files = [ "include/wchar.h", "include/wctype.h", "include/wordexp.h", + "include/syscall_hooks.h", + "include/pthread_ffrt.h", ] -musl_src_porting_file = [ - "arch/aarch64/syscall_arch.h", - "arch/arm/bits/fenv.h", - "arch/generic/bits/shm.h", - "arch/generic/crtbrand.s", - "arch/x86_64/bits/float.h", - "include/ctype.h", - "include/info/application_target_sdk_version.h", - "include/info/device_api_version.h", - "include/info/fatal_message.h", - "include/malloc.h", - "include/pthread.h", - "include/fcntl.h", - "include/poll.h", - "include/stdio.h", - "include/stdlib.h", - "include/string.h", - "include/sys/stat.h", - "include/sys/sspret.h", - "include/sys/cdefs.h", - "include/fortify/fcntl.h", - "include/fortify/fortify.h", - "include/fortify/poll.h", - "include/fortify/socket.h", - "include/fortify/stat.h", - "include/fortify/stdlib.h", - "include/fortify/string.h", - "include/fortify/unistd.h", - "include/fortify/stdio.h", +musl_src_files_ext = [ + "src/internal/linux/musl_log.c", + "src/internal/linux/vdso.c", + "src/hook/linux/malloc_common.c", + "src/hook/linux/musl_preinit.c", + "src/hook/linux/musl_socket_preinit.c", + "src/hook/linux/socket_common.c", + "src/hook/linux/memory_trace.c", + "src/hook/linux/musl_fdtrack.c", + "src/hook/linux/musl_fdtrack_load.c", + "src/hook/linux/musl_preinit_common.c", + "src/hook/linux/musl_socket_preinit_common.c", + "crt/linux/crtplus.c", + "src/linux/arm/linux/flock.s", + "src/linux/aarch64/linux/flock.s", + "src/linux/x86_64/linux/flock.s", + "src/exit/linux/assert.c", + "src/exit/linux/atexit.c", + "src/fdsan/linux/fdsan.c", + "src/fortify/linux/fortify.c", + "src/gwp_asan/linux/gwp_asan.c", + "src/gwp_asan/linux/gwp_asan.h", + "src/hilog/linux/hilog_adapter.c", + "src/hilog/linux/hilog_common.h", + "src/hilog/linux/output_p.inl", + "src/hilog/linux/vsnprintf_s_p.c", + "src/hilog/linux/vsnprintf_s_p.h", + "src/linux/linux/clone.c", + "src/linux/linux/getprocpid.c", + "src/network/linux/getaddrinfo.c", + "src/syscall_hooks/linux/syscall_hooks.c", + "src/signal/linux/sigaction.c", + "src/thread/linux/pthread_create.c", + "src/trace/linux/trace_marker.c", + "include/trace/linux/trace_marker.h", + "src/info/linux/application_target_sdk_version.c", + "src/info/linux/device_api_version.c", + "src/info/linux/fatal_message.c", + "ldso/linux/cfi.c", + "ldso/linux/dynlink.c", + "ldso/linux/dynlink_rand.h", + "ldso/linux/ld_log.h", + "ldso/linux/namespace.h", + "ldso/linux/ns_config.h", + "ldso/linux/strops.c", + "ldso/linux/zip_archive.h", + "ldso/linux/cfi.h", + "ldso/linux/dynlink_rand.c", + "ldso/linux/ld_log.c", + "ldso/linux/namespace.c", + "ldso/linux/ns_config.c", + "ldso/linux/strops.h", + "include/sys/linux/capability.h", + "include/sys/linux/cdefs.h", + "include/sys/linux/sspret.h", + "include/info/linux/application_target_sdk_version.h", + "include/info/linux/device_api_version.h", + "include/info/linux/fatal_message.h", + "include/fortify/linux/fcntl.h", + "include/fortify/linux/poll.h", + "include/fortify/linux/stat.h", + "include/fortify/linux/stdlib.h", + "include/fortify/linux/unistd.h", + "include/fortify/linux/fortify.h", + "include/fortify/linux/socket.h", + "include/fortify/linux/stdio.h", + "include/fortify/linux/string.h", + "include/linux/dlfcn_ext.h", + "include/linux/sigchain.h", + "include/linux/syscall_hooks.h", + "src/ldso/arm/linux/dlvsym.s", + "src/ldso/aarch64/linux/dlvsym.s", + "src/ldso/x86_64/linux/dlvsym.s", + "src/misc/aarch64/linux/fstat.s", + "src/misc/aarch64/linux/syscall.s", + "src/malloc/linux/calloc.c", + "src/malloc/linux/stats.c", + "src/sigchain/linux/sigchain.c", + "src/internal/linux/malloc_config.h", + "src/internal/linux/proc_xid_impl.h", + "src/internal/linux/malloc_random.h", + "src/internal/linux/musl_log.h", + "src/internal/linux/syscall_hooks.h", + "src/hook/linux/common_def.h", + "src/hook/linux/musl_fdtrack.h", + "src/hook/linux/musl_fdtrack_hook.h", + "src/hook/linux/musl_malloc_dispatch.h", + "src/hook/linux/musl_malloc_dispatch_table.h", + "src/hook/linux/musl_preinit_common.h", + "src/hook/linux/musl_malloc.h", + "src/hook/linux/musl_socket_dispatch.h", + "src/hook/linux/musl_socket_preinit_common.h", + "src/hook/linux/memory_trace.h", + "src/hook/linux/musl_socket.h", +] + +musl_src_linux_files = [ + "src/internal/malloc_config.h", + "src/internal/proc_xid_impl.h", + "src/internal/malloc_random.h", + "src/internal/musl_log.h", + "src/internal/syscall_hooks.h", + "src/hook/common_def.h", + "src/hook/musl_fdtrack.h", + "src/hook/musl_fdtrack_hook.h", + "src/hook/musl_malloc_dispatch.h", + "src/hook/musl_malloc_dispatch_table.h", + "src/hook/musl_preinit_common.h", + "src/hook/musl_malloc.h", + "src/hook/musl_socket_dispatch.h", + "src/hook/musl_socket_preinit_common.h", + "src/hook/memory_trace.h", + "src/hook/musl_socket.h", + "src/internal/musl_log.c", + "src/internal/vdso.c", + "src/hook/malloc_common.c", + "src/hook/musl_preinit.c", + "src/hook/musl_socket_preinit.c", + "src/hook/socket_common.c", + "src/hook/memory_trace.c", + "src/hook/musl_fdtrack.c", + "src/hook/musl_fdtrack_load.c", + "src/hook/musl_preinit_common.c", + "src/hook/musl_socket_preinit_common.c", + "crt/crtplus.c", + "src/linux/arm/flock.s", + "src/linux/aarch64/flock.s", + "src/linux/x86_64/flock.s", + "src/exit/assert.c", + "src/exit/atexit.c", + "src/fdsan/fdsan.c", "src/fortify/fortify.c", - "include/sys/capability.h", - "include/sys/reboot.h", - "include/sys/socket.h", - "include/sys/sysinfo.h", - "include/signal.h", - "include/sigchain.h", - "include/sched.h", - "src/internal/dynlink.h", - "include/sys/tgkill.h", - "include/trace/trace_marker.h", - "include/unistd.h", - "include/dlfcn.h", - "include/dlfcn_ext.h", - "src/fcntl/open.c", + "src/gwp_asan/gwp_asan.c", + "src/gwp_asan/gwp_asan.h", + "src/hilog/hilog_adapter.c", "src/hilog/hilog_common.h", + "src/hilog/output_p.inl", + "src/hilog/vsnprintf_s_p.c", "src/hilog/vsnprintf_s_p.h", - "src/internal/hilog_adapter.h", - "src/internal/musl_log.h", - "src/info/application_target_sdk_version.c", - "src/info/device_api_version.c", - "src/info/fatal_message.c", - "src/env/__init_tls.c", - "src/env/__libc_start_main.c", - "src/internal/pthread_impl.h", - "src/internal/locale_impl.h", - "src/internal/syscall.h", - "src/internal/services.h", - "src/internal/network_conf_function.h", - "src/internal/network_conf_function.c", - "src/internal/proc_xid_impl.h", - "ldso/namespace.h", - "ldso/ns_config.h", - "ldso/strops.h", - "src/legacy/ulimit.c", "src/linux/clone.c", "src/linux/getprocpid.c", - "src/linux/reboot.c", - "src/linux/tgkill.c", - "src/malloc/mallocng/malloc_usable_size.c", - "src/malloc/mallocng/malloc.c", - "src/malloc/mallocng/meta.h", - "src/malloc/mallocng/donate.c", - "src/malloc/mallocng/aligned_alloc.c", - "src/malloc/lite_malloc.c", - "src/malloc/stats.c", - "src/malloc/calloc.c", - "src/malloc/free.c", - "src/network/getnameinfo.c", - "src/malloc/libc_calloc.c", - "src/malloc/realloc.c", - "src/network/inet_legacy.c", - "src/network/lookup_name.c", - "src/network/lookup_serv.c", - "src/network/resolvconf.c", - "src/network/socket.c", - "src/passwd/getspnam_r.c", - "src/sched/sched_setparam.c", - "src/sched/sched_getparam.c", - "src/sched/sched_setscheduler.c", - "src/sched/sched_getscheduler.c", - "src/thread/arm/clone.s", - "src/thread/arm/syscall_cp.s", - "src/thread/pthread_mutex_clocklock.c", - "src/thread/pthread_mutex_timedlock.c", - "src/thread/pthread_mutex_lock.c", - "src/thread/pthread_mutex_timedlock_monotonic_np.c", - "src/thread/pthread_mutex_lock_timeout_np.c", - "src/thread/pthread_mutex_init.c", - "src/thread/pthread_rwlock_clockrdlock.c", - "src/thread/pthread_rwlock_timedrdlock.c", - "src/thread/pthread_rwlock_timedrdlock_monotonic_np.c", - "src/thread/pthread_rwlock_init.c", - "src/thread/pthread_cond_timedwait.c", - "src/thread/pthread_cond_timedwait_monotonic_np.c", - "src/thread/pthread_cond_timeout_np.c", - "src/thread/pthread_cond_clockwait.c", - "src/thread/pthread_cond_init.c", + "src/network/getaddrinfo.c", + "src/syscall_hooks/syscall_hooks.c", + "src/signal/sigaction.c", "src/thread/pthread_create.c", - "src/thread/pthread_rwlock_clockwrlock.c", - "src/thread/pthread_rwlock_timedwrlock_monotonic_np.c", - "src/thread/pthread_rwlock_timedwrlock.c", - "src/thread/pthread_sigmask.c", "src/trace/trace_marker.c", - "src/ldso/dlclose.c", - "src/ldso/dlerror.c", + "include/trace/trace_marker.h", + "src/info/application_target_sdk_version.c", + "src/info/device_api_version.c", + "src/info/fatal_message.c", + "ldso/cfi.c", "ldso/dynlink.c", - "src/exit/atexit.c", - "crt/arm/crti.s", - "crt/aarch64/crti.s", - "crt/crtplus.c", - "ldso/cfi.h", + "ldso/dynlink_rand.h", "ldso/ld_log.h", + "ldso/namespace.h", + "ldso/ns_config.h", + "ldso/strops.c", + "ldso/zip_archive.h", + "ldso/cfi.h", + "ldso/dynlink_rand.c", "ldso/ld_log.c", "ldso/namespace.c", "ldso/ns_config.c", - "ldso/strops.c", - "ldso/cfi.c", - "ldso/dynlink_rand.c", - "ldso/dynlink_rand.h", - "src/sched/sched_cpualloc.c", - "src/signal/signal.c", - "src/signal/sigaction.c", - "src/signal/siginterrupt.c", - "include/langinfo.h", - "include/locale.h", - "src/hilog/hilog_adapter.c", - "src/hilog/vsnprintf_s_p.c", - "src/internal/libc.h", - "src/locale/dcngettext.c", - "src/locale/locale_map.c", - "src/locale/langinfo.c", - "src/locale/newlocale.c", - "src/time/__tz.c", - "src/time/gmtime_r.c", - "src/time/strftime.c", - "src/time/strptime.c", - "src/time/time_impl.h", - "src/ldso/aarch64/dlvsym.s", + "ldso/strops.h", + "include/sys/capability.h", + "include/sys/cdefs.h", + "include/sys/sspret.h", + "include/info/application_target_sdk_version.h", + "include/info/device_api_version.h", + "include/info/fatal_message.h", + "include/fortify/fcntl.h", + "include/fortify/poll.h", + "include/fortify/stat.h", + "include/fortify/stdlib.h", + "include/fortify/unistd.h", + "include/fortify/fortify.h", + "include/fortify/socket.h", + "include/fortify/stdio.h", + "include/fortify/string.h", + "include/dlfcn_ext.h", + "include/sigchain.h", + "include/syscall_hooks.h", "src/ldso/arm/dlvsym.s", - "src/ldso/riscv64/dlvsym.s", + "src/ldso/aarch64/dlvsym.s", "src/ldso/x86_64/dlvsym.s", - "src/stdio/__fdopen.c", - "src/stdio/vfprintf.c", - "src/stdio/__stdio_read.c", - "src/stdio/__stdio_write.c", - "src/stdio/__stdout_write.c", - "src/stdio/fread.c", - "src/stdio/fmemopen.c", - "src/stdio/freopen.c", - "src/stdio/stdin.c", - "src/stdio/__fmodeflags.c", - "src/stdio/fopen.c", - "src/stdio/ofl.c", - "src/stdio/fclose.c", - "src/stdio/__toread.c", - "src/stdio/__towrite.c", - "src/stdio/stderr.c", - "src/stdio/fgets.c", - "src/stdio/vsnprintf.c", - "src/stdio/vsscanf.c", - "src/internal/stdio_impl.h", - "src/internal/vdso.c", - "src/time/clock_gettime.c", - "src/time/clock_getres.c", - "src/time/gettimeofday.c", - "src/time/time.c", - "src/unistd/getpid.c", - "src/process/_Fork.c", - "src/process/vfork.c", - "src/process/arm/__vfork.s", - "src/process/x86_64/__vfork.s", - "src/linux/cache.c", - "src/sched/sched_getcpu.c", - "src/sigchain/sigchain.c", - "src/conf/legacy.c", - "src/conf/sysconf.c", - "src/env/getenv.c", - "src/string/strcasecmp.c", - "src/string/strncasecmp.c", - "src/string/strncat.c", - "src/string/stpncpy.c", - "src/string/strncpy.c", - "src/stat/fstat.c", - "src/string/strcspn.c", - "src/thread/pthread_once.c", - "src/thread/pthread_cancel.c", - "src/mq/mq_notify.c", - "src/aio/aio.c", "src/misc/aarch64/fstat.s", "src/misc/aarch64/syscall.s", - "src/stdlib/strtol.c", - "src/stdlib/strtod.c", - "src/thread/sem_timedwait.c", - "src/stdio/vfscanf.c", - "src/stdio/fileno.c", + "src/malloc/calloc.c", + "src/malloc/stats.c", + "src/sigchain/sigchain.c", ] +if (musl_arch == "arm") { + musl_src_file += [ + "src/process/arm/__vfork.s", + "src/ldso/arm/dlvsym.s", + ] +} else if (musl_arch == "aarch64") { + musl_src_file += [ + "arch/aarch64/syscall_arch.h", + "src/misc/aarch64/fstat.s", + "src/misc/aarch64/syscall.s", + "src/ldso/aarch64/dlvsym.s", + ] +} else if (musl_arch == "loongarch64") { + musl_src_file += [ "arch/loongarch64/syscall_arch.h" ] +} else if (musl_arch == "x86_64") { + musl_src_file += [ + "src/process/x86_64/__vfork.s", + "src/ldso/x86_64/dlvsym.s", + ] +} + musl_inc_hook_files = [ - "//third_party/musl/porting/linux/user/src/internal/hilog_adapter.h", - "//third_party/musl/porting/linux/user/src/internal/musl_log.h", - "//third_party/musl/porting/linux/user/src/hook/memory_trace.h", - "//third_party/musl/porting/linux/user/src/hook/musl_malloc_dispatch_table.h", - "//third_party/musl/porting/linux/user/src/hook/musl_malloc_dispatch.h", - "//third_party/musl/porting/linux/user/src/hook/musl_preinit_common.h", + "//third_party/musl/src/internal/hilog_adapter.h", + "//third_party/musl/src/internal/linux/musl_log.h", + "//third_party/musl/src/hook/linux/memory_trace.h", + "//third_party/musl/src/hook/linux/musl_fdtrack.h", + "//third_party/musl/src/hook/linux/musl_fdtrack_hook.h", + "//third_party/musl/src/hook/linux/musl_malloc_dispatch_table.h", + "//third_party/musl/src/hook/linux/musl_malloc_dispatch.h", + "//third_party/musl/src/hook/linux/musl_preinit_common.h", + "//third_party/musl/src/hook/linux/musl_socket_dispatch.h", ] added_freebsd_files = [ - "$FREEBSD_DIR/contrib/gdtoa/strtod.c", - "$FREEBSD_DIR/contrib/gdtoa/gethex.c", - "$FREEBSD_DIR/contrib/gdtoa/smisc.c", - "$FREEBSD_DIR/contrib/gdtoa/misc.c", - "$FREEBSD_DIR/contrib/gdtoa/strtord.c", - "$FREEBSD_DIR/contrib/gdtoa/hexnan.c", - "$FREEBSD_DIR/contrib/gdtoa/gmisc.c", - "$FREEBSD_DIR/contrib/gdtoa/hd_init.c", - "$FREEBSD_DIR/contrib/gdtoa/strtodg.c", - "$FREEBSD_DIR/contrib/gdtoa/ulp.c", - "$FREEBSD_DIR/contrib/gdtoa/strtof.c", - "$FREEBSD_DIR/contrib/gdtoa/sum.c", - "$FREEBSD_DIR/lib/libc/gdtoa/glue.c", - "$FREEBSD_DIR/lib/libc/stdio/parsefloat.c", + "$FREEBSD_DIR/contrib/tcp_wrappers/strcasecmp.c", + "$FREEBSD_DIR/lib/libc/gen/arc4random.c", + "$FREEBSD_DIR/lib/libc/gen/arc4random_uniform.c", + "$FREEBSD_DIR/lib/libc/stdlib/qsort.c", + "$FREEBSD_DIR/lib/libc/stdlib/strtoimax.c", + "$FREEBSD_DIR/lib/libc/stdlib/strtoul.c", + "$FREEBSD_DIR/lib/libc/stdlib/strtoumax.c", ] +freebsd_headers = [ "$FREEBSD_DIR/contrib/libexecinfo/execinfo.h" ] + freebsd_sys_headers = [ "$FREEBSD_DIR/sys/sys/queue.h" ] diff --git a/build/third_party_gn/musl/musl_template.gni b/build/third_party_gn/musl/musl_template.gni index 84c653b5..c62f882f 100644 --- a/build/third_party_gn/musl/musl_template.gni +++ b/build/third_party_gn/musl/musl_template.gni @@ -302,6 +302,7 @@ template("musl_libs") { "//third_party/jemalloc/include/", "//third_party/jemalloc/include/jemalloc/internal", "//third_party/jemalloc/include/jemalloc", + "//third_party/FreeBSD/contrib/libexecinfo", ] } @@ -333,25 +334,43 @@ template("musl_libs") { source_set("soft_musl_src") { sources_orig = [] sources = [] - + include_dirs = [] sources_orig = musl_src_arch_file + musl_src_file + sources_orig -= musl_src_filterout sources_orig -= [ - "src/env/__stack_chk_fail.c", - "src/env/__libc_start_main.c", - "src/env/__init_tls.c", - "src/string/memset.c", "src/string/mempcpy.c", + "src/string/memset.c", + "src/env/__init_tls.c", + "src/env/__libc_start_main.c", + "src/env/__stack_chk_fail.c", "src/stdlib/qsort.c", "src/stdlib/qsort_nr.c", - ] - if (musl_arch == "mips") { - sources_orig += [ "src/string/memset.c" ] - } - sources_orig -= musl_src_filterout - - sources += [ - "$FREEBSD_DIR/contrib/tcp_wrappers/strcasecmp.c", - "$FREEBSD_DIR/lib/libc/stdlib/qsort.c", + "src/string/strncpy.c", + ] + + freebsd_files = [ + "//third_party/FreeBSD/contrib/gdtoa/strtod.c", + "//third_party/FreeBSD/contrib/gdtoa/gethex.c", + "//third_party/FreeBSD/contrib/gdtoa/smisc.c", + "//third_party/FreeBSD/contrib/gdtoa/misc.c", + "//third_party/FreeBSD/contrib/gdtoa/strtord.c", + "//third_party/FreeBSD/contrib/gdtoa/hexnan.c", + "//third_party/FreeBSD/contrib/gdtoa/gmisc.c", + "//third_party/FreeBSD/contrib/gdtoa/hd_init.c", + "//third_party/FreeBSD/contrib/gdtoa/strtodg.c", + "//third_party/FreeBSD/contrib/gdtoa/ulp.c", + "//third_party/FreeBSD/contrib/gdtoa/strtof.c", + "//third_party/FreeBSD/contrib/gdtoa/sum.c", + "//third_party/FreeBSD/lib/libc/gdtoa/glue.c", + "//third_party/FreeBSD/lib/libc/stdio/parsefloat.c", + "//third_party/FreeBSD/contrib/tcp_wrappers/strcasecmp.c", + "//third_party/FreeBSD/lib/libc/gen/arc4random.c", + "//third_party/FreeBSD/lib/libc/gen/arc4random_uniform.c", + "//third_party/FreeBSD/lib/libc/stdlib/qsort.c", + "//third_party/FreeBSD/lib/libc/stdlib/strtoimax.c", + "//third_party/FreeBSD/lib/libc/stdlib/strtoul.c", + "//third_party/FreeBSD/lib/libc/stdlib/strtoumax.c", + "//third_party/musl/third_party/openbsd/lib/libc/string/strncpy.c", ] if (musl_arch == "arm") { @@ -382,6 +401,7 @@ template("musl_libs") { "src/math/powl.c", "src/math/sinf.c", "src/math/cosf.c", + "src/linux/flock.c", ] } else if (musl_arch == "aarch64") { sources_orig -= [ @@ -416,12 +436,23 @@ template("musl_libs") { "src/math/sincos.c", "src/math/pow.c", "src/math/powf.c", + "src/linux/flock.c", ] } else if (musl_arch == "x86_64") { - sources_orig -= [ "src/thread/${musl_arch}/__set_thread_area.s" ] + sources_orig -= [ + "src/thread/${musl_arch}/__set_thread_area.s", + "src/linux/flock.c", + ] } defines = [] + defines += [ "FEATURE_ICU_LOCALE" ] + + # There are two ways to implement cxa_thread_atexit_impl: + # - CXA_THREAD_USE_TSD(default): use pthread_key_xxx to implement cxa_thread_atexit_impl. + # - CXA_THREAD_USE_TLS: put dtors in pthread to implement cxa_thread_atexit_impl. + defines += [ "CXA_THREAD_USE_TSD" ] + if (musl_arch == "arm") { defines += [ "MUSL_ARM_ARCH" ] } @@ -477,8 +508,7 @@ template("musl_libs") { "$OPTRTDIR/string/arm/strcmp.S", "$OPTRTDIR/string/arm/strlen-armv6t2.S", ] - - sources += added_freebsd_files + sources += freebsd_files asmflags = [ "-D__memcpy_arm = memcpy", "-D__memchr_arm = memchr", @@ -487,6 +517,7 @@ template("musl_libs") { "-D__strlen_armv6t2 = strlen", ] } else if (musl_arch == "aarch64") { + sources += freebsd_files if (defined(ARM_FEATURE_SVE)) { sources += [ "$OPTRTDIR/string/aarch64/memchr-sve.S", @@ -565,7 +596,6 @@ template("musl_libs") { "$OPTRTDIR/string/aarch64/strnlen.S", "$OPTRTDIR/string/aarch64/strrchr.S", ] - sources += added_freebsd_files asmflags = [ "-D__memmove_aarch64 = memmove", "-D__memcpy_aarch64 = memcpy", @@ -588,37 +618,19 @@ template("musl_libs") { cflags = [ "-O3", "-fPIC", - "-ffreestanding", "-fstack-protector-strong", - "-flto", ] - if (use_jemalloc) { - defines += [ "USE_JEMALLOC" ] - if (use_jemalloc_dfx_intf) { - defines += [ "USE_JEMALLOC_DFX_INTF" ] - } - include_dirs = [ "//third_party/jemalloc/include/jemalloc" ] - } - - if (!defined(include_dirs)) { - if (musl_arch == "aarch64") { - include_dirs = [ "//third_party/FreeBSD/lib/libc/aarch64" ] - } - if (musl_arch == "arm") { - include_dirs = [ "//third_party/FreeBSD/lib/libc/arm" ] - } - } else { - if (musl_arch == "aarch64") { - include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ] - } - if (musl_arch == "arm") { - include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ] - } - } - configs -= musl_inherited_configs configs += [ ":soft_musl_config" ] + if (musl_arch == "aarch64") { + include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ] + } else if (musl_arch == "arm") { + include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ] + } + include_dirs += [ "//third_party/FreeBSD/lib/libc/include" ] + include_dirs += [ "//third_party/FreeBSD/contrib/libexecinfo" ] + include_dirs += [ "//third_party/FreeBSD/crypto/openssh/openbsd-compat" ] if (!defined(defines)) { defines = [] @@ -633,7 +645,8 @@ template("musl_libs") { defines += [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ] } } - + external_deps = [] + external_deps += [ "FreeBSD:libc_static" ] deps = porting_deps } @@ -827,6 +840,8 @@ template("musl_libs") { ":soft_musl_src_nossp", ":soft_musl_src_optimize", ] + external_deps = [] + external_deps = [ "FreeBSD:libc_static" ] output_name = "libc" complete_static_lib = true } diff --git a/build/third_party_gn/openssl/BUILD.gn b/build/third_party_gn/openssl/BUILD.gn index 0b311628..cae0e8ea 100644 --- a/build/third_party_gn/openssl/BUILD.gn +++ b/build/third_party_gn/openssl/BUILD.gn @@ -636,6 +636,10 @@ libdefault_common_sources = [ "//third_party/openssl/providers/implementations/ciphers/cipher_cts.c", "//third_party/openssl/providers/implementations/ciphers/cipher_null.c", "//third_party/openssl/providers/implementations/ciphers/cipher_sm4.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_ccm.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_ccm_hw.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_gcm.c", + "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_gcm_hw.c", "//third_party/openssl/providers/implementations/ciphers/cipher_sm4_hw.c", "//third_party/openssl/providers/implementations/ciphers/cipher_tdes.c", "//third_party/openssl/providers/implementations/ciphers/cipher_tdes_common.c", -- Gitee From c05e217e54a164c55e31ed66e236759032ae5b96 Mon Sep 17 00:00:00 2001 From: bigtea Date: Mon, 5 Aug 2024 09:29:53 +0800 Subject: [PATCH 36/51] Fix failed and enable UT Issue: IAGKTX Signed-off-by: bigtea --- tooling/test/client_utils/test_list.cpp | 13 -- tooling/test/debugger_cint_client_test.cpp | 2 +- tooling/test/debugger_client_test.cpp | 2 +- .../test/testcases/js_cpuprofile_async_test.h | 109 --------------- .../test/testcases/js_cpuprofile_loop_test.h | 26 +--- .../testcases/js_cpuprofile_recursion_test.h | 120 ----------------- .../test/testcases/js_cpuprofile_step_test.h | 127 ------------------ tooling/test/testcases/js_cpuprofile_test.h | 18 +-- websocket/test/websocket_test.cpp | 8 +- 9 files changed, 12 insertions(+), 413 deletions(-) delete mode 100755 tooling/test/testcases/js_cpuprofile_async_test.h delete mode 100644 tooling/test/testcases/js_cpuprofile_recursion_test.h delete mode 100755 tooling/test/testcases/js_cpuprofile_step_test.h diff --git a/tooling/test/client_utils/test_list.cpp b/tooling/test/client_utils/test_list.cpp index f3acefb5..cdd96ac0 100644 --- a/tooling/test/client_utils/test_list.cpp +++ b/tooling/test/client_utils/test_list.cpp @@ -24,8 +24,6 @@ #include "tooling/test/testcases/js_closure_scope_test.h" #include "tooling/test/testcases/js_container_test.h" #include "tooling/test/testcases/js_exception_test.h" -#include "tooling/test/testcases/js_heapsampling_loop_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" @@ -51,9 +49,6 @@ #include "tooling/test/testcases/js_stepinto_async_test.h" #include "tooling/test/testcases/js_stepout_arrow_test.h" #include "tooling/test/testcases/js_stepout_async_test.h" -#include "tooling/test/testcases/js_cpuprofile_test.h" -#include "tooling/test/testcases/js_cpuprofile_async_test.h" -#include "tooling/test/testcases/js_cpuprofile_step_test.h" #include "tooling/test/testcases/js_heapusage_test.h" #include "tooling/test/testcases/js_heapusage_async_test.h" #include "tooling/test/testcases/js_heapusage_step_test.h" @@ -72,8 +67,6 @@ #include "tooling/test/testcases/js_breakpoint_loop_test.h" #include "tooling/test/testcases/js_breakpoint_recursion_test.h" #include "tooling/test/testcases/js_breakpoint_switch_test.h" -#include "tooling/test/testcases/js_cpuprofile_loop_test.h" -#include "tooling/test/testcases/js_cpuprofile_recursion_test.h" #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" @@ -94,7 +87,6 @@ static void RegisterTests() TestUtil::RegisterTest("JsModuleVariableTest", GetJsModuleVariableTest()); TestUtil::RegisterTest("JsSourceTest", GetJsSourceTest()); TestUtil::RegisterTest("JsTracingTest", GetJsTracingTest()); - TestUtil::RegisterTest("JsHeapsamplingTest", GetJsHeapsamplingTest()); TestUtil::RegisterTest("JsWatchTest", GetJsWatchTest()); TestUtil::RegisterTest("JsHeapdumpTest", GetJsHeapdumpTest()); TestUtil::RegisterTest("JsAllocationtrackTest", GetJsAllocationtrackTest()); @@ -113,16 +105,12 @@ static void RegisterTests() TestUtil::RegisterTest("JsStepintoAsyncTest", GetJsStepintoAsyncTest()); TestUtil::RegisterTest("JsStepoutArrowTest", GetJsStepoutArrowTest()); TestUtil::RegisterTest("JsStepoutAsyncTest", GetJsStepoutAsyncTest()); - TestUtil::RegisterTest("JsCpuprofileTest", GetJsCpuprofileTest()); - TestUtil::RegisterTest("JsCpuprofileAsyncTest", GetJsCpuprofileAsyncTest()); - TestUtil::RegisterTest("JsCpuprofileStepTest", GetJsCpuprofileStepTest()); TestUtil::RegisterTest("JsHeapusageTest", GetJsHeapusageTest()); TestUtil::RegisterTest("JsHeapusageAsyncTest", GetJsHeapusageAsyncTest()); TestUtil::RegisterTest("JsHeapusageStepTest", GetJsHeapusageStepTest()); TestUtil::RegisterTest("JsHeapdumpLoopTest", GetJsHeapdumpLoopTest()); TestUtil::RegisterTest("JsAllocationTrackLoopTest", GetJsAllocationTrackLoopTest()); TestUtil::RegisterTest("JsAllocationTrackRecursionTest", GetJsAllocationTrackRecursionTest()); - TestUtil::RegisterTest("JsHeapSamplingLoopTest", GetJsHeapSamplingLoopTest()); TestUtil::RegisterTest("JsJsWatchBasicTypeTest", GetJsWatchBasicTypeTest()); TestUtil::RegisterTest("JsJsWatchSetTypeTest", GetJsWatchSetTypeTest()); TestUtil::RegisterTest("JsJsWatchOtherTypeTest", GetJsWatchOtherTypeTest()); @@ -138,7 +126,6 @@ static void RegisterTests() TestUtil::RegisterTest("JsBreakpointLoopTest", GetJsBreakpointLoopTest()); TestUtil::RegisterTest("JsBreakpointRecursionTest", GetJsBreakpointRecursionTest()); TestUtil::RegisterTest("JsBreakpointSwitchTest", GetJsBreakpointSwitchTest()); - TestUtil::RegisterTest("JsCpuprofileLoopTest", GetJsCpuprofileLoopTest()); TestUtil::RegisterTest("JsHeapusageLoopTest", GetJsHeapusageLoopTest()); TestUtil::RegisterTest("JsHeapusageRecursionTest", GetJsHeapusageRecursionTest()); TestUtil::RegisterTest("JsSmartStepoutTest", GetJsSmartStepoutTest()); diff --git a/tooling/test/debugger_cint_client_test.cpp b/tooling/test/debugger_cint_client_test.cpp index 09809e99..b03f609b 100644 --- a/tooling/test/debugger_cint_client_test.cpp +++ b/tooling/test/debugger_cint_client_test.cpp @@ -65,7 +65,7 @@ public: JSThread *thread {nullptr}; }; -HWTEST_P_L0(DebuggerCIntClientTest, DISABLED_DebuggerSuite) +HWTEST_P_L0(DebuggerCIntClientTest, DebuggerSuite) { std::string testName = GetCurrentTestName(); std::cout << "Running " << testName << std::endl; diff --git a/tooling/test/debugger_client_test.cpp b/tooling/test/debugger_client_test.cpp index 2f54ce54..8f9db150 100644 --- a/tooling/test/debugger_client_test.cpp +++ b/tooling/test/debugger_client_test.cpp @@ -66,7 +66,7 @@ public: }; //NOTE: enable (issue 18042) -HWTEST_P_L0(DebuggerClientTest, DISABLED_DebuggerSuite) +HWTEST_P_L0(DebuggerClientTest, DebuggerSuite) { std::string testName = GetCurrentTestName(); std::cout << "Running " << testName << std::endl; diff --git a/tooling/test/testcases/js_cpuprofile_async_test.h b/tooling/test/testcases/js_cpuprofile_async_test.h deleted file mode 100755 index c1fb48a9..00000000 --- a/tooling/test/testcases/js_cpuprofile_async_test.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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_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 JsCpuprofileAsyncTest : public TestActions { -public: - JsCpuprofileAsyncTest() - { - 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 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}, - - {SocketAction::SEND, "b " DEBUGGER_JS_DIR "async_func.js 18"}, - {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}, - - {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, "cpuprofile-stop"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, - [](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 and run - {SocketAction::SEND, "success"}, - {SocketAction::SEND, "resume"}, - {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - }; - } - - std::pair GetEntryPoint() override - { - return {pandaFile_, entryPoint_}; - } - ~JsCpuprofileAsyncTest() = default; - -private: - 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 GetJsCpuprofileAsyncTest() -{ - return std::make_unique(); -} -} // namespace panda::ecmascript::tooling::test - -#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_ASYNC_TEST_H diff --git a/tooling/test/testcases/js_cpuprofile_loop_test.h b/tooling/test/testcases/js_cpuprofile_loop_test.h index f837cd65..a33541ec 100644 --- a/tooling/test/testcases/js_cpuprofile_loop_test.h +++ b/tooling/test/testcases/js_cpuprofile_loop_test.h @@ -39,43 +39,23 @@ public: {SocketAction::SEND, "cpuprofile"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - - {SocketAction::SEND, "b " DEBUGGER_JS_DIR "common_func.js 64"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - {SocketAction::SEND, "b " DEBUGGER_JS_DIR "common_func.js 65"}, - {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::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, {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, "resume"}, - {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, {SocketAction::SEND, "cpuprofile-stop"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [this](auto recv, auto, auto) -> bool { return RecvCpuprofileInfo(recv); }}, - {SocketAction::SEND, "cpuprofile-disable"}, {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 + // reply success {SocketAction::SEND, "success"}, - {SocketAction::SEND, "resume"}, - {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, }; } diff --git a/tooling/test/testcases/js_cpuprofile_recursion_test.h b/tooling/test/testcases/js_cpuprofile_recursion_test.h deleted file mode 100644 index a09a13db..00000000 --- a/tooling/test/testcases/js_cpuprofile_recursion_test.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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_CPUPROFILE_RECURSION_TEST_H -#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_RECURSION_TEST_H - -#include "tooling/test/client_utils/test_util.h" - -namespace panda::ecmascript::tooling::test { -class JsCpuprofileRecursionTest : public TestActions { -public: - JsCpuprofileRecursionTest() - { - 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}, - {SocketAction::SEND, "cpuprofile-enable"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - - {SocketAction::SEND, "cpuprofile"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - {SocketAction::SEND, "b " DEBUGGER_JS_DIR "common_func.js 67"}, - {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}, - {SocketAction::SEND, "cpuprofile-stop"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, - [this](auto recv, auto, auto) -> bool { return RecvCpuprofileInfo(recv); }}, - - {SocketAction::SEND, "cpuprofile"}, - {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}, - {SocketAction::SEND, "cpuprofile-stop"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, - [this](auto recv, auto, auto) -> bool { return RecvCpuprofileInfo(recv); }}, - - {SocketAction::SEND, "cpuprofile-disable"}, - {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 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_}; - } - ~JsCpuprofileRecursionTest() = 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 GetJsCpuprofileRecursionTest() -{ - return std::make_unique(); -} -} // namespace panda::ecmascript::tooling::test - -#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_LOOP_TEST_H diff --git a/tooling/test/testcases/js_cpuprofile_step_test.h b/tooling/test/testcases/js_cpuprofile_step_test.h deleted file mode 100755 index 199d3f1e..00000000 --- a/tooling/test/testcases/js_cpuprofile_step_test.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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_CPUPROFILE_STEP_TEST_H -#define ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_STEP_TEST_H - -#include "tooling/test/client_utils/test_util.h" - -namespace panda::ecmascript::tooling::test { -class JsCpuprofileStepTest : public TestActions { -public: - JsCpuprofileStepTest() - { - 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, "b " DEBUGGER_JS_DIR "sample.js 23"}, - {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}, - - {SocketAction::SEND, "so"}, - {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, - - {SocketAction::SEND, "si"}, - {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::STRING_CONTAIN}, - - {SocketAction::SEND, "so"}, - {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::STRING_CONTAIN}, - - {SocketAction::SEND, "cpuprofile-stop"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, - [](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 and run - {SocketAction::SEND, "success"}, - {SocketAction::SEND, "resume"}, - {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - }; - } - - std::pair GetEntryPoint() override - { - return {pandaFile_, entryPoint_}; - } - ~JsCpuprofileStepTest() = 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 GetJsCpuprofileStepTest() -{ - return std::make_unique(); -} -} // namespace panda::ecmascript::tooling::test - -#endif // ECMASCRIPT_TOOLING_TEST_TESTCASES_JS_CPUPROFILE_STEP_TEST_H diff --git a/tooling/test/testcases/js_cpuprofile_test.h b/tooling/test/testcases/js_cpuprofile_test.h index 9f99b793..8c2e4dd4 100755 --- a/tooling/test/testcases/js_cpuprofile_test.h +++ b/tooling/test/testcases/js_cpuprofile_test.h @@ -38,15 +38,11 @@ public: {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, {SocketAction::SEND, "cpuprofile"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - - {SocketAction::SEND, "b " DEBUGGER_JS_DIR "sample.js 23"}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - + // resume {SocketAction::SEND, "resume"}, {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, - {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, - + // stop and disable {SocketAction::SEND, "cpuprofile-stop"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, [](auto recv, auto, auto) -> bool { @@ -73,16 +69,8 @@ public: }}, {SocketAction::SEND, "cpuprofile-disable"}, {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 + // reply success {SocketAction::SEND, "success"}, - {SocketAction::SEND, "resume"}, - {SocketAction::RECV, "Debugger.resumed", ActionRule::STRING_CONTAIN}, - {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, }; } diff --git a/websocket/test/websocket_test.cpp b/websocket/test/websocket_test.cpp index 1c942286..0523f2a6 100644 --- a/websocket/test/websocket_test.cpp +++ b/websocket/test/websocket_test.cpp @@ -65,7 +65,7 @@ public: const std::string WebSocketTest::LONG_MSG = std::string(1000, 'f'); const std::string WebSocketTest::LONG_LONG_MSG = std::string(0xfffff, 'f'); -HWTEST_F(WebSocketTest, DISABLED_ConnectWebSocketTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, ConnectWebSocketTest, testing::ext::TestSize.Level0) { WebSocketServer serverSocket; bool ret = false; @@ -162,7 +162,7 @@ HWTEST_F(WebSocketTest, DISABLED_ConnectWebSocketTest, testing::ext::TestSize.Le } } -HWTEST_F(WebSocketTest, DISABLED_ReConnectWebSocketTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, ReConnectWebSocketTest, testing::ext::TestSize.Level0) { WebSocketServer serverSocket; bool ret = false; @@ -222,7 +222,7 @@ HWTEST_F(WebSocketTest, DISABLED_ReConnectWebSocketTest, testing::ext::TestSize. sleep(3); } -HWTEST_F(WebSocketTest, DISABLED_ClientAbnormalTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, ClientAbnormalTest, testing::ext::TestSize.Level0) { WebSocketClient clientSocket; ASSERT_STREQ(clientSocket.GetSocketStateString().c_str(), "closed"); @@ -231,7 +231,7 @@ HWTEST_F(WebSocketTest, DISABLED_ClientAbnormalTest, testing::ext::TestSize.Leve ASSERT_FALSE(clientSocket.SendReply(HELLO_SERVER)); } -HWTEST_F(WebSocketTest, DISABLED_ServerAbnormalTest, testing::ext::TestSize.Level0) +HWTEST_F(WebSocketTest, ServerAbnormalTest, testing::ext::TestSize.Level0) { WebSocketServer serverSocket; // No connection established, the function returns directly. -- Gitee From 454c9feb931d25eb8f0a2c41cf44e4d5660f9bd4 Mon Sep 17 00:00:00 2001 From: Viktoria Shirunova Date: Thu, 11 Jul 2024 14:19:56 +0300 Subject: [PATCH 37/51] Regress tests: support aot/pgo modes Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IACS7R Testing: All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: Viktoria Shirunova Change-Id: Icea1593831a1c81a2641ac99d60508caa978e99a --- build/compile_script/ark.py | 579 +++++++++++++++++++++--------------- 1 file changed, 345 insertions(+), 234 deletions(-) diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index 53faada5..4da2ce07 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -24,7 +24,7 @@ import os import platform import subprocess import sys -from typing import List, Tuple, Union, Optional +from typing import List, Any, Tuple, Union, Optional CURRENT_FILENAME = os.path.basename(__file__) @@ -96,7 +96,7 @@ class ArkPy: REGRESS_TEST_LOG_FILE_NAME = "regresstest.log" PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH = \ "./arkcompiler/toolchain/build/prebuilts_download/prebuilts_download_config.json" - INDENTATION_STRING_PER_LEVEL = " " # for help message + INDENTATION_STRING_PER_LEVEL = " " # for help message # In ARG_DICT, "flags" and "description" are must-keys for the leaf-dicts in it. # (Future designer need know.) ARG_DICT = { @@ -221,14 +221,14 @@ class ArkPy: "gn_targets_depend_on": ["default"], }, "gn_target": { - "flags": [""], # any other flags + "flags": [""], # any other flags "description": "Build for arkcompiler target assigned by user. Targets include group(ets_runtime), " "ohos_executable(ark_js_vm), ohos_shared_library(libark_jsruntime), " "ohos_static_library(static_icuuc), ohos_source_set(libark_jsruntime_set), " "ohos_unittest(EcmaVm_001_Test), action(EcmaVm_001_TestAction) and other target of user-defined " "template type in \"*.gn*\" file.", - "gn_targets_depend_on": [], # not need, depend on deps of itself in "*.gn*" file + "gn_targets_depend_on": [], # not need, depend on deps of itself in "*.gn*" file }, }, "option": { @@ -264,7 +264,7 @@ class ArkPy: "keep-going": { "flags": ["--keep-going=*", "-keep-going=*"], "description": "Keep running unittest etc. until errors occured less than N times" - " (use 0 to ignore all errors).", + " (use 0 to ignore all errors).", }, }, "help": { @@ -289,7 +289,7 @@ class ArkPy: arg_list = list(dict.fromkeys(arg_list)) # match [help] flag if len(arg_list) == 0 or ( - True in [self.is_dict_flags_match_arg(self.ARG_DICT["help"], arg) for arg in arg_list]): + True in [self.is_dict_flags_match_arg(self.ARG_DICT.get("help"), arg) for arg in arg_list]): print(self.get_help_msg_of_all()) return # match [[os_cpu].[mode]] flag @@ -307,135 +307,192 @@ class ArkPy: if fnmatch(arg_to_match, flag): return True return False - + @staticmethod - def get_test262_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, - timeout): - - print("running test262 in AsmMode\n") - if any('target_cpu="arm64"' in arg for arg in gn_args): - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ - "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-arch aarch64" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path) + def libs_dir(is_arm, is_aot, is_pgo, out_dir, x64_out_dir) -> str: + if is_arm and is_aot and is_pgo: + return (f"--libs-dir ../../{out_dir}/arkcompiler/ets_runtime:" + f"../../{out_dir}/thirdparty/icu:" + f"../../{out_dir}/third_party/icu:" + f"../../thirdparty/zlib:" + f"../../prebuilts/clang/ohos/linux-x86_64/llvm/lib") + if is_arm and is_aot and not is_pgo: + return ("--libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" + f":../../{x64_out_dir}/thirdparty/icu/") + if not is_arm and is_aot: + return (f"--libs-dir ../../{out_dir}/arkcompiler/ets_runtime" + f":../../{out_dir}/thirdparty/icu:" + f"../../{out_dir}/third_party/icu:" + f"../../thirdparty/zlib:" + f"../../prebuilts/clang/ohos/linux-x86_64/llvm/lib") + # not is_arm and not is_aot + return " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" + + @staticmethod + def get_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, aot_mode, run_pgo, + enable_litecg, args_to_cmd, timeout, ignore_list: Optional[str] = None): + cmd = [ + f"cd {test_script_path}", + f"&& python3 {test_script_name} {args_to_cmd}", + f"--timeout {timeout}", + f"--ark-tool=../../{out_path}/arkcompiler/ets_runtime/ark_js_vm", + "--ark-frontend=es2panda" + ] + is_arm = any('target_cpu="arm64"' in arg for arg in gn_args) + if is_arm: + cmd.append("--ark-arch aarch64") + cmd.append(f"--ark-arch-root=../../{out_path}/common/common/libc/") + cmd.append(f"--ark-frontend-binary=../../{x64_out_path}/arkcompiler/ets_frontend/es2abc") + cmd.append(f"--merge-abc-binary=../../{x64_out_path}/arkcompiler/ets_frontend/merge_abc") + if aot_mode: + cmd.append(f"--ark-aot-tool=../../{x64_out_path}/arkcompiler/ets_runtime/ark_aot_compiler") + if test_suite == "regresstest": + cmd.append(f"--stub-path=../../{x64_out_path}/gen/arkcompiler/ets_runtime/stub.an") else: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {2}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, timeout) - return test262_cmd + cmd.append(f"--ark-frontend-binary=../../{out_path}/arkcompiler/ets_frontend/es2abc") + cmd.append(f"--merge-abc-binary=../../{out_path}/arkcompiler/ets_frontend/merge_abc") + if aot_mode: + cmd.append(f"--ark-aot-tool=../../{out_path}/arkcompiler/ets_runtime/ark_aot_compiler") + if test_suite == "regresstest": + cmd.append(f"--stub-path=../../{out_path}/gen/arkcompiler/ets_runtime/stub.an") + + cmd.append(ArkPy.libs_dir( + is_arm=is_arm, + is_aot=aot_mode, + is_pgo=run_pgo, + out_dir=out_path, + x64_out_dir=x64_out_path + )) + + if aot_mode: + cmd.append("--ark-aot") + mode = ["AOT"] + if run_pgo: + cmd.append("--run-pgo") + mode.append("PGO") + if enable_litecg: + cmd.append("--enable-litecg") + mode.append("LiteCG") + mode_str = " ".join(mode) + print(f"Running {test_suite} in {mode_str} Mode\n") + + if test_suite == "regresstest" and ignore_list: + cmd.append(f"--ignore-list {ignore_list}") + + if test_suite == "regresstest": + cmd.append(f"--out-dir ../../{out_path}") + + return " ".join(cmd) @staticmethod def get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, - timeout): + timeout): print("running test262 in AotMode\n") if any('target_cpu="arm64"' in arg for arg in gn_args): if run_pgo: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {4}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ - "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-arch aarch64" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-aot" \ - " --ark-frontend=es2panda"\ - "{3}".format(args_to_test262_cmd, out_path, x64_out_path, " --run-pgo", timeout) + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu:" \ + "../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --ark-arch aarch64" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-aot" \ + " --ark-frontend=es2panda" \ + "{3}".format(args_to_test262_cmd, out_path, x64_out_path, " --run-pgo", timeout) else: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{2}/thirdparty/icu/" \ - " --ark-arch aarch64" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{2}/thirdparty/icu/" \ + " --ark-arch aarch64" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) else: test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ - ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-aot" \ - " --ark-frontend=es2panda"\ - "{2}".format(args_to_test262_cmd, out_path, " --run-pgo" if run_pgo else "", timeout) + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ + ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-aot-tool=../../{1}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-aot" \ + " --ark-frontend=es2panda" \ + "{2}".format(args_to_test262_cmd, out_path, " --run-pgo" if run_pgo else "", timeout) if enable_litecg: test262_cmd = test262_cmd + " --enable-litecg" return test262_cmd @staticmethod - def get_test262_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout): - print("running test262 in JIT mode\n") + def get_jit_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, args_to_cmd, + timeout): + print(f"running {test_suite} in JIT mode\n") if any('target_cpu="arm64"' in arg for arg in gn_args): - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{1}/thirdparty/icu/" \ - ":../../{1}/thirdparty/bounds_checking_function" \ - ":../../{1}/arkcompiler/ets_runtime:" \ - " --ark-arch aarch64" \ - " --run-jit" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + cmd = "cd {5} && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib:../../{1}/thirdparty/icu/" \ + ":../../{1}/thirdparty/bounds_checking_function" \ + ":../../{1}/arkcompiler/ets_runtime:" \ + " --ark-arch aarch64" \ + " --run-jit" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_cmd, out_path, x64_out_path, timeout, + test_script_name, test_script_path) else: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ - ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --run-jit" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda"\ - "{2}".format(args_to_test262_cmd, out_path, x64_out_path, timeout) - return test262_cmd - + cmd = "cd arkcompiler/ets_frontend && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime:../../{1}/thirdparty/icu" \ + ":../../{1}/thirdparty/zlib:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + " --run-jit" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda" \ + "{2}".format(args_to_cmd, out_path, x64_out_path, timeout, test_script_name) + return cmd + @staticmethod - def get_test262_baseline_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout): - print("running test262 in baseline JIT mode\n") + def get_baseline_jit_cmd(test_suite, test_script_name, test_script_path, gn_args, out_path, x64_out_path, + args_to_test262_cmd, timeout): + print(f"running {test_suite} in baseline JIT mode\n") if any('target_cpu="arm64"' in arg for arg in gn_args): - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - ":../../{1}/thirdparty/icu" \ - ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos" \ - ":../../{1}/thirdparty/bounds_checking_function" \ - ":../../{1}/arkcompiler/ets_runtime" \ - ":../../{1}/common/common/libc/lib" \ - " --ark-arch aarch64" \ - " --run-baseline-jit" \ - " --ark-arch-root=../../{1}/common/common/libc/" \ - " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout) + cmd = "cd {5} && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + ":../../{1}/thirdparty/icu" \ + ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos" \ + ":../../{1}/thirdparty/bounds_checking_function" \ + ":../../{1}/arkcompiler/ets_runtime" \ + ":../../{1}/common/common/libc/lib" \ + " --ark-arch aarch64" \ + " --run-baseline-jit" \ + " --ark-arch-root=../../{1}/common/common/libc/" \ + " --ark-aot-tool=../../{2}/arkcompiler/ets_runtime/ark_aot_compiler" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{2}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{2}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda".format(args_to_test262_cmd, out_path, x64_out_path, timeout, + test_script_name, test_script_path) else: - test262_cmd = "cd arkcompiler/ets_frontend && python3 test262/run_test262.py {0} --timeout {3}" \ - " --libs-dir ../../{1}/lib.unstripped/arkcompiler/ets_runtime" \ - ":../../{1}/lib.unstripped/thirdparty/icu" \ - ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - ":../../{1}/lib.unstripped/thirdparty/bounds_checking_function/" \ - " --run-baseline-jit" \ - " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ - " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ - " --ark-frontend=es2panda"\ - "{2}".format(args_to_test262_cmd, out_path, x64_out_path, timeout) - return test262_cmd + cmd = "cd {5} && python3 {4} {0} --timeout {3}" \ + " --libs-dir ../../{1}/lib.unstripped/arkcompiler/ets_runtime" \ + ":../../{1}/lib.unstripped/thirdparty/icu" \ + ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ + ":../../{1}/lib.unstripped/thirdparty/bounds_checking_function/" \ + " --run-baseline-jit" \ + " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ + " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ + " --merge-abc-binary=../../{1}/arkcompiler/ets_frontend/merge_abc" \ + " --ark-frontend=es2panda" \ + "{2}".format(args_to_test262_cmd, out_path, x64_out_path, timeout, + test_script_name, test_script_path) + return cmd @staticmethod def build_args_to_test262_cmd(arg_list): @@ -556,6 +613,16 @@ class ArkPy: sys.exit(1) return None, arg_list + @staticmethod + def __get_x64_out_path(out_path) -> str: + if 'release' in out_path: + return 'out/x64.release' + if 'debug' in out_path: + return 'out/x64.debug' + if 'fastverify' in out_path: + return 'out/x64.fastverify' + return "" + def get_binaries(self): host_os = sys.platform host_cpu = platform.machine() @@ -572,18 +639,18 @@ class ArkPy: print("\nLogic of getting gn binary or ninja binary does not match logic of prebuilts_download." \ "\nCheck func \033[92m{0} of class {1} in file {2}\033[0m against file {3} if the name of this " \ "file had not changed!\n".format( - sys._getframe().f_code.co_name, self.__class__.__name__, CURRENT_FILENAME, - self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH)) + sys._getframe().f_code.co_name, self.__class__.__name__, CURRENT_FILENAME, + self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH)) raise error if self.gn_binary_path == "" or self.ninja_binary_path == "": print("\nLogic of prebuilts_download may be wrong." \ "\nCheck \033[92mdata in file {0}\033[0m against func {1} of class {2} in file {3}!\n".format( - self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH, sys._getframe().f_code.co_name, self.__class__.__name__, - CURRENT_FILENAME)) + self.PREBUILTS_DOWNLOAD_CONFIG_FILE_PATH, sys._getframe().f_code.co_name, self.__class__.__name__, + CURRENT_FILENAME)) sys.exit(0) if not os.path.isfile(self.gn_binary_path) or not os.path.isfile(self.ninja_binary_path): print("\nStep for prebuilts_download may be ommited. (\033[92m./prebuilts_download.sh\033[0m)" \ - "\nCheck \033[92mwhether gn binary and ninja binary are under directory prebuilts\033[0m!\n".format()) + "\nCheck \033[92mwhether gn binary and ninja binary are under directory prebuilts\033[0m!\n".format()) sys.exit(0) return @@ -603,13 +670,13 @@ class ArkPy: if len(arg_to_list) == 1: os_cpu_part = arg_to_list[0] mode_part = "release" - key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["os_cpu"], os_cpu_part) - key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["mode"], mode_part) + key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("os_cpu"), os_cpu_part) + key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("mode"), mode_part) elif len(arg_to_list) == 2: os_cpu_part = arg_to_list[0] mode_part = arg_to_list[1] - key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["os_cpu"], os_cpu_part) - key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT["mode"], mode_part) + key_to_dict_in_os_cpu_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("os_cpu"), os_cpu_part) + key_to_dict_in_mode_matched_arg = self.which_dict_flags_match_arg(self.ARG_DICT.get("mode"), mode_part) else: print("\"\033[92m{0}\033[0m\" combined with more than 2 flags is not supported.".format(arg)) if (key_to_dict_in_os_cpu_matched_arg == "") | (key_to_dict_in_mode_matched_arg == ""): @@ -635,7 +702,7 @@ class ArkPy: help_msg += "\033[32mCommand template:\033[0m\n{}\n\n".format( " python3 ark.py \033[92m[os_cpu].[mode] [gn_target] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --aot] " \ - "[none or --pgo] [none or --litecg] [none, file or dir] [none or --threads=X] [option]\033[0m\n" + "[none or --pgo] [none or --litecg] [none, file or dir] [none or --threads=X] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --jit] [none or --threads=X]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --baseline-jit] [none or --threads=X]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [unittest] [option]\033[0m\n" @@ -686,8 +753,13 @@ class ArkPy: # prepare log file build_log_path = os.path.join(out_path, log_file_name) backup(build_log_path, "w") + if arg_list is not None: + build_target = " ".join([str(arg).strip() for arg in arg_list + if arg is not None or len(str(arg).strip()) > 0]) + else: + build_target = "" str_to_build_log = "================================\nbuild_time: {0}\nbuild_target: {1}\n\n".format( - str_of_time_now(), " ".join(arg_list)) + str_of_time_now(), build_target) _write(build_log_path, str_to_build_log, "a") # gn command print("=== gn gen start ===") @@ -704,13 +776,13 @@ class ArkPy: # Always add " -d keeprsp" to ninja command to keep response file("*.rsp"), thus we could get shared libraries # of an excutable from its response file. ninja_cmd = \ - self.ninja_binary_path + \ - (" -v" if self.enable_verbose else "") + \ - (" -d keepdepfile" if self.enable_keepdepfile else "") + \ - " -d keeprsp" + \ - " -C {}".format(out_path) + \ - " {}".format(" ".join(arg_list)) + \ - " -k {}".format(self.ignore_errors) + self.ninja_binary_path + \ + (" -v" if self.enable_verbose else "") + \ + (" -d keepdepfile" if self.enable_keepdepfile else "") + \ + " -d keeprsp" + \ + " -C {}".format(out_path) + \ + " {}".format(" ".join(arg_list if arg_list else [])) + \ + " -k {}".format(self.ignore_errors) print(ninja_cmd) code = call_with_output(ninja_cmd, build_log_path) if code != 0: @@ -720,77 +792,141 @@ class ArkPy: print("=== ninja success! ===\n") return - def build_for_test262(self, out_path, timeout, gn_args: list, arg_list: list, log_file_name: str, - aot_mode: bool, run_pgo=False, enable_litecg=False, run_jit=False, - run_baseline_jit=False): - args_to_test262_cmd = self.build_args_to_test262_cmd(arg_list) - x64_out_path = "" + def call_build_gn_target(self, gn_args, out_path, x64_out_path, test_suite, log_file_name): if any('target_cpu="arm64"' in arg for arg in gn_args): - if 'release' in out_path: - x64_out_path = 'out/x64.release' - if 'debug' in out_path: - x64_out_path = 'out/x64.debug' gn_args.append("so_dir_for_qemu=\"../../{0}/common/common/libc/\"".format(out_path)) gn_args.append("run_with_qemu=true".format(out_path)) if not os.path.exists(x64_out_path): os.makedirs(x64_out_path) self.build_for_gn_target( - x64_out_path, ['target_os="linux"', 'target_cpu="x64"', 'is_debug=false'], - self.ARG_DICT["target"]["test262"]["gn_targets_depend_on"], log_file_name) + x64_out_path, + ['target_os="linux"', 'target_cpu="x64"', 'is_debug=false'], + self.ARG_DICT.get("target").get(test_suite).get("gn_targets_depend_on"), + log_file_name) self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["test262"]["arm64_gn_targets_depend_on"], log_file_name) + out_path, + gn_args, + self.ARG_DICT.get("target").get(test_suite).get("arm64_gn_targets_depend_on"), + log_file_name) else: self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["test262"]["gn_targets_depend_on"], log_file_name) + out_path, + gn_args, + self.ARG_DICT.get("target").get(test_suite).get("gn_targets_depend_on"), + log_file_name) + + def get_build_cmd(self, *, test_suite, test_script_name, test_script_path, + out_path, x64_out_path, gn_args: list, args_to_cmd: str, timeout, + run_jit: bool = False, run_baseline_jit: bool = False, aot_mode: bool = False, + run_pgo: bool = False, enable_litecg: bool = False, ignore_list: Optional[str] = None) -> str: if run_jit: - test262_cmd = self.get_test262_jit_cmd(gn_args, out_path, x64_out_path, args_to_test262_cmd, timeout) + cmd = self.get_jit_cmd(test_suite, test_script_name, test_script_path, + gn_args, out_path, x64_out_path, args_to_cmd, timeout) elif run_baseline_jit: - test262_cmd = self.get_test262_baseline_jit_cmd(gn_args, out_path, x64_out_path, - args_to_test262_cmd, timeout) - elif aot_mode: - test262_cmd = self.get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, enable_litecg, args_to_test262_cmd, - timeout) + cmd = self.get_baseline_jit_cmd(test_suite, test_script_name, test_script_path, + gn_args, out_path, x64_out_path, args_to_cmd, timeout) + elif aot_mode and test_suite == "test262": + cmd = self.get_test262_aot_cmd(gn_args, out_path, x64_out_path, run_pgo, + enable_litecg, args_to_cmd, timeout) else: - test262_cmd = self.get_test262_cmd(gn_args, out_path, x64_out_path, run_pgo, - enable_litecg, args_to_test262_cmd, timeout) - test262_log_path = os.path.join(out_path, log_file_name) - str_to_test262_log = "================================\ntest262_time: {0}\ntest262_target: {1}\n\n".format( - str_of_time_now(), args_to_test262_cmd) - _write(test262_log_path, str_to_test262_log, "a") - print("=== test262 start ===") - code = call_with_output(test262_cmd, test262_log_path) + cmd = self.get_cmd(test_suite, test_script_name, test_script_path, + gn_args, out_path, x64_out_path, aot_mode, run_pgo, + enable_litecg, args_to_cmd, timeout, ignore_list) + return cmd + + def build_for_suite(self, *, test_suite, test_script_name, test_script_path, + out_path, gn_args: list, log_file_name, args_to_cmd: str, timeout, + run_jit: bool = False, run_baseline_jit: bool = False, aot_mode: bool = False, + run_pgo: bool = False, enable_litecg: bool = False, ignore_list: Optional[str] = None): + x64_out_path = self.__get_x64_out_path(out_path) + self.call_build_gn_target(gn_args, out_path, x64_out_path, test_suite, log_file_name) + cmd = self.get_build_cmd( + test_suite=test_suite, + test_script_name=test_script_name, + test_script_path=test_script_path, + out_path=out_path, + x64_out_path=x64_out_path, + gn_args=gn_args, + args_to_cmd=args_to_cmd, + timeout=timeout, + run_jit=run_jit, + run_baseline_jit=run_baseline_jit, + aot_mode=aot_mode, run_pgo=run_pgo, enable_litecg=enable_litecg, ignore_list=ignore_list) + log_path = str(os.path.join(out_path, log_file_name)) + str_to_log = "================================\n{2}_time: {0}\n{2}_target: {1}\n\n".format( + str_of_time_now(), args_to_cmd, test_suite) + _write(log_path, str_to_log, "a") + print(f"=== {test_suite} start ===") + code = call_with_output(cmd, log_path) if code != 0: - print("=== test262 fail! ===\n") + print(f"=== {test_suite} fail! ===\n") sys.exit(code) - print("=== test262 success! ===\n") + print(f"=== {test_suite} success! ===\n") + + def build_for_test262(self, out_path, gn_args: list, arg_list: list): + timeout, arg_list = self.parse_timeout(arg_list) + arg_list = arg_list[1:] + + is_aot_mode, arg_list = self.__purge_arg_list("--aot", arg_list) + is_pgo, arg_list = self.__purge_arg_list("--pgo", arg_list) + is_litecg, arg_list = self.__purge_arg_list("--litecg", arg_list) + is_jit, arg_list = self.__purge_arg_list("--jit", arg_list) + is_baseline_jit, arg_list = self.__purge_arg_list("--baseline-jit", arg_list) + print(f"Test262: arg_list = {arg_list}") + + args_to_test262_cmd = self.build_args_to_test262_cmd(arg_list) + self.build_for_suite( + test_suite="test262", + test_script_name="test262/run_test262.py", + test_script_path="arkcompiler/ets_frontend", + out_path=out_path, + gn_args=gn_args, + log_file_name=self.TEST262_LOG_FILE_NAME, + args_to_cmd=args_to_test262_cmd, + timeout=timeout, + run_jit=is_jit, + run_pgo=is_pgo, + run_baseline_jit=is_baseline_jit, + aot_mode=is_aot_mode, + enable_litecg=is_litecg + ) - def build_for_unittest(self, out_path: str, gn_args: list, log_file_name:str): + def build_for_unittest(self, out_path: str, gn_args: list, log_file_name: str): self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["unittest"]["gn_targets_depend_on"], + out_path, gn_args, self.ARG_DICT.get("target").get("unittest").get("gn_targets_depend_on"), log_file_name) return - def build_for_regress_test(self, out_path, gn_args: list, arg_list: list, log_file_name: str, timeout): + def build_for_regress_test(self, out_path, gn_args: list, arg_list: list): + timeout, arg_list = self.parse_option(arg_list, option_name="--timeout", default_value=200) + ignore_list, arg_list = self.parse_option(arg_list, option_name="--ignore-list", default_value=None) + + arg_list = arg_list[1:] + + is_aot, arg_list = self.__purge_arg_list("--aot", arg_list) + is_pgo, arg_list = self.__purge_arg_list("--pgo", arg_list) + is_litecg, arg_list = self.__purge_arg_list("--litecg", arg_list) + is_jit, arg_list = self.__purge_arg_list("--jit", arg_list) + is_baseline_jit, arg_list = self.__purge_arg_list("--baseline-jit", arg_list) + print(f"Regress: arg_list = {arg_list}") + args_to_regress_test_cmd = self.build_args_to_regress_cmd(arg_list) - self.build_for_gn_target( - out_path, gn_args, self.ARG_DICT["target"]["regresstest"]["gn_targets_depend_on"], log_file_name) - regress_test_cmd = "python3 arkcompiler/ets_runtime/test/regresstest/run_regress_test.py --timeout {2}" \ - " --ark-tool ./{0}/arkcompiler/ets_runtime/ark_js_vm" \ - " --ark-frontend-binary ./{0}/arkcompiler/ets_frontend/es2abc" \ - " --LD_LIBRARY_PATH ./{0}/arkcompiler/ets_runtime:./{0}/thirdparty/icu:" \ - "./prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - " --out-dir ./{0}/ {1}".format(out_path, args_to_regress_test_cmd, timeout) - regress_test_log_path = os.path.join(out_path, log_file_name) - str_to_test_log = "============\n regresstest_time: {0}\nregresstest_target: {1}\n\n".format( - str_of_time_now(), regress_test_cmd) - _write(regress_test_log_path, str_to_test_log, "a") - print("=== regresstest start ===") - code = call_with_output(regress_test_cmd, regress_test_log_path) - if code != 0: - print("=== regresstest fail! ===\n") - sys.exit(code) - print("=== regresstest success! ===\n") - return + self.build_for_suite( + test_suite="regresstest", + test_script_name="test/regresstest/run_regress_test.py", + test_script_path="arkcompiler/ets_runtime", + out_path=out_path, + gn_args=gn_args, + log_file_name=self.REGRESS_TEST_LOG_FILE_NAME, + args_to_cmd=args_to_regress_test_cmd, + timeout=timeout, + run_jit=is_jit, + run_pgo=is_pgo, + run_baseline_jit=is_baseline_jit, + aot_mode=is_aot, + enable_litecg=is_litecg, + ignore_list=ignore_list + ) def build(self, out_path: str, gn_args: list, arg_list: list): if not os.path.exists(out_path): @@ -798,47 +934,17 @@ class ArkPy: os.makedirs(out_path) if len(arg_list) == 0: self.build_for_gn_target(out_path, gn_args, ["default"], self.GN_TARGET_LOG_FILE_NAME) - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["workload"], arg_list[0]): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("workload"), arg_list[0]): self.build_for_workload(arg_list, out_path, gn_args, 'workload.log') - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["test262"], arg_list[0]): - timeout, arg_list = self.parse_timeout(arg_list) - run_aot_mode = len(arg_list) >= 2 and arg_list[1] == "--aot" - run_aot_pgo_litecg = len(arg_list) >= 4 and ((arg_list[2] == "--pgo" and arg_list[3] == "--litecg") or - (arg_list[3] == "--pgo" and arg_list[2] == "--litecg")) - run_aot_pgo = len(arg_list) >= 3 and arg_list[2] == "--pgo" - run_aot_litecg = len(arg_list) >= 3 and arg_list[2] == "--litecg" - run_jit = len(arg_list) >= 2 and arg_list[1] == "--jit" - run_baseline_jit = len(arg_list) >= 2 and arg_list[1] == "--baseline-jit" - if run_aot_mode: - if run_aot_pgo_litecg: - self.build_for_test262(out_path, timeout, gn_args, arg_list[4:], self.TEST262_LOG_FILE_NAME, True, - True, True) - elif run_aot_litecg: - self.build_for_test262(out_path, timeout, gn_args, arg_list[3:], self.TEST262_LOG_FILE_NAME, True, - False, True) - elif run_aot_pgo: - self.build_for_test262(out_path, timeout, gn_args, arg_list[3:], - self.TEST262_LOG_FILE_NAME, True, True) - else: - self.build_for_test262(out_path, timeout, gn_args, arg_list[2:], self.TEST262_LOG_FILE_NAME, True) - elif run_jit: - self.build_for_test262(out_path, timeout, gn_args, arg_list[2:], - self.TEST262_LOG_FILE_NAME, False, False, - False, True) - elif run_baseline_jit: - self.build_for_test262(out_path, timeout, gn_args, arg_list[2:], - self.TEST262_LOG_FILE_NAME, False, False, - False, False, True) - else: - self.build_for_test262(out_path, timeout, gn_args, arg_list[1:], self.TEST262_LOG_FILE_NAME, False) - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["unittest"], arg_list[0]): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("test262"), arg_list[0]): + self.build_for_test262(out_path, gn_args, arg_list) + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("unittest"), arg_list[0]): if len(arg_list) > 1: print("\033[92m\"unittest\" not support additional arguments.\033[0m\n".format()) sys.exit(0) self.build_for_unittest(out_path, gn_args, self.UNITTEST_LOG_FILE_NAME) - elif self.is_dict_flags_match_arg(self.ARG_DICT["target"]["regresstest"], arg_list[0]): - timeout, arg_list = self.parse_option(arg_list, option_name="--timeout", default_value=200) - self.build_for_regress_test(out_path, gn_args, arg_list[1:], self.REGRESS_TEST_LOG_FILE_NAME, timeout) + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("target").get("regresstest"), arg_list[0]): + self.build_for_regress_test(out_path, gn_args, arg_list) else: self.build_for_gn_target(out_path, gn_args, arg_list, self.GN_TARGET_LOG_FILE_NAME) return @@ -851,27 +957,27 @@ class ArkPy: gn_args_ret = [] for arg in arg_list: # match [option][clean] flag - if self.is_dict_flags_match_arg(self.ARG_DICT["option"]["clean"], arg): + if self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("clean"), arg): self.clean(out_path) sys.exit(0) # match [option][clean-continue] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["clean-continue"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("clean-continue"), arg): if not self.has_cleaned: self.clean(out_path) self.has_cleaned = True # match [option][gn-args] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["gn-args"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("gn-args"), arg): gn_args_ret.append(arg[(arg.find("=") + 1):]) # match [option][keepdepfile] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["keepdepfile"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("keepdepfile"), arg): if not self.enable_keepdepfile: self.enable_keepdepfile = True # match [option][verbose] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["verbose"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("verbose"), arg): if not self.enable_verbose: self.enable_verbose = True # match [option][keep-going] flag - elif self.is_dict_flags_match_arg(self.ARG_DICT["option"]["keep-going"], arg): + elif self.is_dict_flags_match_arg(self.ARG_DICT.get("option").get("keep-going"), arg): if self.ignore_errors == 1: input_value = arg[(arg.find("=") + 1):] try: @@ -908,13 +1014,13 @@ class ArkPy: run_interpreter = True self.build_for_gn_target(out_path, gn_args, ["default"], self.GN_TARGET_LOG_FILE_NAME) workload_cmd = "cd arkcompiler/ets_runtime/test/workloadtest/ && python3 work_load.py" \ - " --code-path {0}" \ - " --report {1}" \ - " --tools-type {2}" \ - " --boundary-value {3}" \ - " --run-count {4}" \ - " --code-v {5}" \ - .format(root_dir, report, tools, boundary_value, run_count, code_v) + " --code-path {0}" \ + " --report {1}" \ + " --tools-type {2}" \ + " --boundary-value {3}" \ + " --run-count {4}" \ + " --code-v {5}" \ + .format(root_dir, report, tools, boundary_value, run_count, code_v) if run_interpreter: workload_cmd += " --run-interpreter true" workload_log_path = os.path.join(out_path, log_file_name) @@ -934,19 +1040,24 @@ class ArkPy: self.get_binaries() # get out_path name_of_out_dir_of_second_level = \ - self.ARG_DICT["os_cpu"][os_cpu_key]["prefix_of_name_of_out_dir_of_second_level"] + \ + self.ARG_DICT.get("os_cpu").get(os_cpu_key).get("prefix_of_name_of_out_dir_of_second_level") + \ self.DELIMITER_FOR_SECOND_OUT_DIR_NAME + \ - self.ARG_DICT["mode"][mode_key]["suffix_of_name_of_out_dir_of_second_level"] + self.ARG_DICT.get("mode").get(mode_key).get("suffix_of_name_of_out_dir_of_second_level") out_path = os.path.join(self.NAME_OF_OUT_DIR_OF_FIRST_LEVEL, name_of_out_dir_of_second_level) # match [option] flag [arg_list, gn_args] = self.match_options(arg_list, out_path) # get expression which would be written to args.gn file - gn_args.extend(self.ARG_DICT["os_cpu"][os_cpu_key]["gn_args"]) - gn_args.extend(self.ARG_DICT["mode"][mode_key]["gn_args"]) + gn_args.extend(self.ARG_DICT.get("os_cpu").get(os_cpu_key).get("gn_args")) + gn_args.extend(self.ARG_DICT.get("mode").get(mode_key).get("gn_args")) # start to build self.build(out_path, gn_args, arg_list) return + def __purge_arg_list(self, option_name: str, arg_list: List[Any]) -> Tuple[bool, List[Any]]: + if option_name in arg_list: + arg_list.remove(option_name) + return True, arg_list + return False, arg_list if __name__ == "__main__": -- Gitee From 6711c23a14b9e0df8d2286b2296facc52887873a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=B1=9F=E6=B5=A9?= <5715935+Yejianghao1995@user.noreply.gitee.com> Date: Sat, 10 Aug 2024 09:12:41 +0800 Subject: [PATCH 38/51] debugger_impl.cpp dispatch testcase Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAIZQC Signed-off-by: yejianghao Change-Id: Ia42aeea0d12eeb4436c6bda13890b84893b5c8f0 --- tooling/test/debugger_impl_test.cpp | 307 ++++++++++++++++++++++++++++ 1 file changed, 307 insertions(+) diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 4aaa0338..3367e691 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -1241,6 +1241,313 @@ HWTEST_F_L0(DebuggerImplTest, DispatcherImplCallFunctionOn) protocolChannel = nullptr; } } + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.smartStepInto", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.smartStepInto", + "params":{ + "lineNumber":0, + "url":"url_str", + "urlRegex":"urlRegex_str", + "scriptHash":"scriptHash_str", + "columnNumber":0, + "condition":"condition_str" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"Can only perform operation while paused"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__003) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + debuggerImpl->SetDebuggerState(DebuggerState::PAUSED); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.smartStepInto", + "params":{ + "lineNumber":0, + "url":"url_str", + "urlRegex":"urlRegex_str", + "scriptHash":"scriptHash_str", + "columnNumber":0, + "condition":"condition_str" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"SetBreakpointByUrl: debugger agent is not enabled"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setNativeRange", + "params":{ + "nativeRange":"" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setNativeRange", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.resetSingleStepper", + "params":{ + "resetSingleStepper":"test" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.resetSingleStepper", + "params":{ + "resetSingleStepper":true + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ClientDisconnect) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.clientDisconnect", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"()"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.callFunctionOn", + "params":{ + "callFrameId":"1", + "functionDeclaration":"test" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.callFunctionOn", + "params":{ + "callFrameId":"0", + "functionDeclaration":0 + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + HWTEST_F_L0(DebuggerImplTest, NativeOutTest) { std::string outStrForCallbackCheck = ""; -- Gitee From 4cb6cb446b2dcb45a96361639f67f677c37ccc6c Mon Sep 17 00:00:00 2001 From: yanzhiqi1 Date: Fri, 9 Aug 2024 14:39:36 +0800 Subject: [PATCH 39/51] Clear security warnings Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAIT3Z Signed-off-by: yanzhiqi1 --- tooling/base/pt_types.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/base/pt_types.cpp b/tooling/base/pt_types.cpp index b138d947..6d44cf8e 100644 --- a/tooling/base/pt_types.cpp +++ b/tooling/base/pt_types.cpp @@ -3216,7 +3216,7 @@ std::unique_ptr TraceConfig::Create(const PtJson ¶ms) std::unique_ptr syntheticDelays; ret = params.GetArray("syntheticDelays", &syntheticDelays); if (ret == Result::SUCCESS) { - int32_t syntheticDelaysLen = includedCategories->GetSize(); + int32_t syntheticDelaysLen = syntheticDelays->GetSize(); for (int32_t i = 0; i < syntheticDelaysLen; ++i) { std::string pSyntheticDelays = syntheticDelays->Get(i)->GetString(); traceConfig->syntheticDelays_.value().emplace_back(pSyntheticDelays); -- Gitee From 11ac28746769854ff10c71c7cfa701d83c059103 Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Sun, 11 Aug 2024 10:21:38 +0800 Subject: [PATCH 40/51] Coverage supplement Supplement the coverage of the profiler_impl heapprofiler_impl pt_types Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAHS46 Signed-off-by: swx1282997 --- tooling/test/heapprofiler_impl_test.cpp | 22 ++--- tooling/test/profiler_impl_test.cpp | 100 +++++++++++++------ tooling/test/pt_types_test.cpp | 124 ++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 40 deletions(-) diff --git a/tooling/test/heapprofiler_impl_test.cpp b/tooling/test/heapprofiler_impl_test.cpp index fe021a45..b847cd83 100644 --- a/tooling/test/heapprofiler_impl_test.cpp +++ b/tooling/test/heapprofiler_impl_test.cpp @@ -177,13 +177,13 @@ HWTEST_F_L0(HeapProfilerImplTest, DispatcherImplAddInspectedHeapObject) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.disable","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.addInspectedHeapObject","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->AddInspectedHeapObject(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result.find("wrong params") != std::string::npos); - msg = std::string() + R"({"id":0,"method":"HeapProfiler.disable","params":{"heapObjectId":"0"}})"; + msg = std::string() + R"({"id":0,"method":"HeapProfiler.addInspectedHeapObject","params":{"heapObjectId":"0"}})"; DispatchRequest request1 = DispatchRequest(msg); - dispatcherImpl->AddInspectedHeapObject(request1); + dispatcherImpl->Dispatch(request1); if (channel) { delete channel; channel = nullptr; @@ -201,7 +201,7 @@ HWTEST_F_L0(HeapProfilerImplTest, DispatcherImplCollectGarbage) auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.collectGarbage","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->CollectGarbage(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); if (channel) { delete channel; @@ -219,7 +219,7 @@ HWTEST_F_L0(HeapProfilerImplTest, DispatcherImplEnable) auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.enable","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->Enable(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result.find("protocols") != std::string::npos); if (channel) { delete channel; @@ -237,7 +237,7 @@ HWTEST_F_L0(HeapProfilerImplTest, DispatcherImplDisable) auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.disable","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->Disable(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); if (channel) { delete channel; @@ -255,11 +255,11 @@ HWTEST_F_L0(HeapProfilerImplTest, DispatcherImplGetHeapObjectId) auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.getHeapObjectId","params":{"objectId":true}})"; DispatchRequest request(msg); - dispatcherImpl->GetHeapObjectId(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result.find("wrong params") != std::string::npos); msg = std::string() + R"({"id":0,"method":"HeapProfiler.getHeapObjectId","params":{"objectId":"0"}})"; DispatchRequest request1(msg); - dispatcherImpl->GetHeapObjectId(request1); + dispatcherImpl->Dispatch(request1); ASSERT_TRUE(result.find("GetHeapObjectId not support now") != std::string::npos); if (channel) { delete channel; @@ -278,12 +278,12 @@ HWTEST_F_L0(HeapProfilerImplTest, DispatcherImplGetObjectByHeapObjectId) std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.getObjectByHeapObjectId","params":{ "objectId":001}})"; DispatchRequest request(msg); - dispatcherImpl->GetObjectByHeapObjectId(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result.find("wrong params") != std::string::npos); msg = std::string() + R"({"id":0,"method":"HeapProfiler.getObjectByHeapObjectId","params":{"objectId":"001", "objectGroup":"000"}})"; DispatchRequest request1(msg); - dispatcherImpl->GetObjectByHeapObjectId(request1); + dispatcherImpl->Dispatch(request1); ASSERT_TRUE(result.find("GetObjectByHeapObjectId not support now") != std::string::npos); if (channel) { delete channel; diff --git a/tooling/test/profiler_impl_test.cpp b/tooling/test/profiler_impl_test.cpp index 1037493e..6d086956 100644 --- a/tooling/test/profiler_impl_test.cpp +++ b/tooling/test/profiler_impl_test.cpp @@ -186,11 +186,11 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplDispatch) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.Test","params":{}})"; DispatchRequest request(msg); dispatcherImpl->Dispatch(request); ASSERT_TRUE(result.find("Unknown method: Test") != std::string::npos); - msg = std::string() + R"({"id":0,"method":"Debugger.disable","params":{}})"; + msg = std::string() + R"({"id":0,"method":"Profiler.disable","params":{}})"; DispatchRequest request1 = DispatchRequest(msg); dispatcherImpl->Dispatch(request1); if (channel) { @@ -208,9 +208,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplEnable) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.enable","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->Enable(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -226,9 +226,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplDisable) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.disable","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->Disable(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -244,11 +244,13 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplStart) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.start","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->Start(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); - dispatcherImpl->Stop(request); + msg = std::string() + R"({"id":0,"method":"Profiler.stop","params":{}})"; + DispatchRequest request1 = DispatchRequest(msg); + dispatcherImpl->Dispatch(request1); if (channel) { delete channel; channel = nullptr; @@ -265,9 +267,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplStop) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.stop","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->Stop(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -283,13 +285,13 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplSetSamplingInterval) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.setSamplingInterval","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->SetSamplingInterval(request); + dispatcherImpl->Dispatch(request); ASSERT_TRUE(result.find("wrong params") != std::string::npos); - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"interval":24}})"; + msg = std::string() + R"({"id":0,"method":"Profiler.setSamplingInterval","params":{"interval":24}})"; DispatchRequest request1(msg); - dispatcherImpl->SetSamplingInterval(request1); + dispatcherImpl->Dispatch(request1); if (channel) { delete channel; channel = nullptr; @@ -305,9 +307,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplGetBestEffortCoverage) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.getBestEffortCoverage","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->GetBestEffortCoverage(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -323,9 +325,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplStopPreciseCoverage) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.stopPreciseCoverage","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->StopPreciseCoverage(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -341,9 +343,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplTakePreciseCoverage) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.takePreciseCoverage","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->TakePreciseCoverage(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -359,9 +361,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplStartPreciseCoverage) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.startPreciseCoverage","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->StartPreciseCoverage(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -377,9 +379,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplStartTypeProfile) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.startTypeProfile","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->StartTypeProfile(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -395,9 +397,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplStopTypeProfile) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.stopTypeProfile","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->StopTypeProfile(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -413,9 +415,9 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplTakeTypeProfile) ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); auto tracing = std::make_unique(ecmaVm, channel); auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); - std::string msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + std::string msg = std::string() + R"({"id":0,"method":"Profiler.takeTypeProfile","params":{}})"; DispatchRequest request(msg); - dispatcherImpl->TakeTypeProfile(request); + dispatcherImpl->Dispatch(request); if (channel) { delete channel; channel = nullptr; @@ -423,6 +425,46 @@ HWTEST_F_L0(ProfilerImplTest, DispatcherImplTakeTypeProfile) ASSERT_TRUE(result.find("TakeTypeProfile not support now") != std::string::npos); } +HWTEST_F_L0(ProfilerImplTest, DispatcherImplDisableSerializationTimeoutCheck) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) { result = temp; }; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = std::string() + R"({"id":0,"method":"Profiler.disableSerializationTimeoutCheck","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->Dispatch(request); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); +} + +HWTEST_F_L0(ProfilerImplTest, DispatcherImplEnableSerializationTimeoutCheck) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) { result = temp; }; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = std::string() + R"({"id":0,"method":"Profiler.enableSerializationTimeoutCheck","params":{}})"; + DispatchRequest request(msg); + dispatcherImpl->Dispatch(request); + ASSERT_TRUE(result.find("wrong params") != std::string::npos); + msg = std::string() + R"({"id":0,"method":"Profiler.enableSerializationTimeoutCheck","params":{"threshold": 5}})"; + DispatchRequest request1(msg); + dispatcherImpl->Dispatch(request1); + if (channel) { + delete channel; + channel = nullptr; + } + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); +} + HWTEST_F_L0(ProfilerImplTest, FrontendPreciseCoverageDeltaUpdate) { std::string result = ""; diff --git a/tooling/test/pt_types_test.cpp b/tooling/test/pt_types_test.cpp index 02c2e543..2ec83070 100644 --- a/tooling/test/pt_types_test.cpp +++ b/tooling/test/pt_types_test.cpp @@ -901,4 +901,128 @@ HWTEST_F_L0(PtTypesTest, SamplingHeapProfileTransferHead) int32_t columnNumber = callFrame->GetColumnNumber(); ASSERT_TRUE(columnNumber == allocationNode.callFrameInfo_.columnNumber_); } + +HWTEST_F_L0(PtTypesTest, DescriptionForObjectTest) +{ + Local weakmap = WeakMapRef::New(ecmaVm); + std::string description = ObjectRemoteObject::DescriptionForObject(ecmaVm, weakmap); + ASSERT_TRUE(description.find("WeakMap") != std::string::npos); + + Local map = MapRef::New(ecmaVm); + Local mapiterator = MapIteratorRef::New(ecmaVm, map); + description = ObjectRemoteObject::DescriptionForObject(ecmaVm, mapiterator); + ASSERT_TRUE(description.find("MapIterator") != std::string::npos); + + Local set = SetRef::New(ecmaVm); + Local setiterator = SetIteratorRef::New(ecmaVm, set); + description = ObjectRemoteObject::DescriptionForObject(ecmaVm, setiterator); + ASSERT_TRUE(description.find("SetIterator") != std::string::npos); + + size_t size = 10; + Local nativepointer = NativePointerRef::New(ecmaVm, ecmaVm, size); + description = ObjectRemoteObject::DescriptionForObject(ecmaVm, nativepointer); + std::cout << description << std::endl; + ASSERT_TRUE(description.find("External") != std::string::npos); +} + +HWTEST_F_L0(PtTypesTest, FromTaggedTest) +{ + double input = 123456789.0; + Local date = DateRef::New(ecmaVm, input); + std::unique_ptr remoteObject = RemoteObject::FromTagged(ecmaVm, date); + std::string description = remoteObject->GetDescription(); + ASSERT_TRUE(description.find("GMT") != std::string::npos); + + Local weakmap = WeakMapRef::New(ecmaVm); + remoteObject = RemoteObject::FromTagged(ecmaVm, weakmap); + description = remoteObject->GetDescription(); + ASSERT_TRUE(description.find("WeakMap") != std::string::npos); + + Local map = MapRef::New(ecmaVm); + Local mapiterator = MapIteratorRef::New(ecmaVm, map); + remoteObject = RemoteObject::FromTagged(ecmaVm, mapiterator); + description = remoteObject->GetDescription(); + ASSERT_TRUE(description.find("MapIterator") != std::string::npos); + + Local set = SetRef::New(ecmaVm); + Local setiterator = SetIteratorRef::New(ecmaVm, set); + remoteObject = RemoteObject::FromTagged(ecmaVm, setiterator); + description = remoteObject->GetDescription(); + ASSERT_TRUE(description.find("SetIterator") != std::string::npos); + + Local capability = PromiseCapabilityRef::New(ecmaVm); + Local promise = capability->GetPromise(ecmaVm); + remoteObject = RemoteObject::FromTagged(ecmaVm, promise); + description = remoteObject->GetDescription(); + ASSERT_TRUE(description.find("Promise") != std::string::npos); + + size_t size = 10; + Local nativepointer = NativePointerRef::New(ecmaVm, ecmaVm, size); + remoteObject = RemoteObject::FromTagged(ecmaVm, nativepointer); + description = remoteObject->GetDescription(); + ASSERT_TRUE(description.find("External") != std::string::npos); +} + +HWTEST_F_L0(PtTypesTest, NativeRangeCreateTest) +{ + std::string msg; + std::unique_ptr nativeRange; + + msg = std::string() + R"({})"; + nativeRange = NativeRange::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(nativeRange, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"start":20,"end":40}})"; + nativeRange = NativeRange::Create(DispatchRequest(msg).GetParams()); + ASSERT_TRUE(nativeRange != nullptr); +} + +HWTEST_F_L0(PtTypesTest, BreakpointInfoCreateTest) +{ + std::string msg; + std::unique_ptr breakpointInfo; + + msg = std::string() + R"({})"; + breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(breakpointInfo, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"condition":"Test","urlRegex":"Test"}})"; + breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(breakpointInfo, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test", + "params":{"scriptHash":"Test", "restrictToFunction": true}})"; + breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(breakpointInfo, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"lineNumber":1,"columnNumber":2,"url":"Test", + "condition":"Test", "urlRegex":"Test", "scriptHash":"Test", "restrictToFunction": true}})"; + breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams()); + std::unique_ptr resultJson = breakpointInfo->ToJson(); + ASSERT_TRUE(resultJson != nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test", + "params":{"lineNumber":1, "columnNumber":2, "url":"Test"}})"; + breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams()); + resultJson = breakpointInfo->ToJson(); + ASSERT_TRUE(resultJson != nullptr); +} + +HWTEST_F_L0(PtTypesTest, BreakpointReturnInfoCreateTest) +{ + std::string msg; + std::unique_ptr breakpointReturnInfo; + + msg = std::string() + R"({})"; + breakpointReturnInfo = BreakpointReturnInfo::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(breakpointReturnInfo, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"lineNumber":20,"columnNumber":40}})"; + breakpointReturnInfo = BreakpointReturnInfo::Create(DispatchRequest(msg).GetParams()); + ASSERT_TRUE(breakpointReturnInfo != nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"id":"Test","scriptId":5}})"; + breakpointReturnInfo = BreakpointReturnInfo::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(breakpointReturnInfo, nullptr); +} } // namespace panda::test -- Gitee From 7b9a047efc335aeda809e593f8546f091f1903e2 Mon Sep 17 00:00:00 2001 From: ZitongLi Date: Fri, 2 Aug 2024 16:40:17 +0800 Subject: [PATCH 41/51] Refactoring getthreadortaskid Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAHGXO Signed-off-by: zitongli --- inspector/inspector.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 3292a9d6..2b2fe896 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -303,14 +303,16 @@ void Inspector::OnMessage(std::string&& msg) #if defined(OHOS_PLATFORM) uint64_t Inspector::GetThreadOrTaskId() { - uint64_t threadOrTaskId = static_cast(getproctid()); #if defined(ENABLE_FFRT_INTERFACES) - threadOrTaskId = ffrt_this_task_get_id(); - if (threadOrTaskId == 0) { - threadOrTaskId = static_cast(getproctid()); + uint64_t threadOrTaskId = ffrt_this_task_get_id(); + if (threadOrTaskId != 0) { + return threadOrTaskId; + } else { + return static_cast(getproctid()); } +#else + return static_cast(getproctid()); #endif // defined(ENABLE_FFRT_INTERFACES) - return threadOrTaskId; } #endif // defined(OHOS_PLATFORM) -- Gitee From 4e66bf72200d7d26b9e4c520644923408f6516bc Mon Sep 17 00:00:00 2001 From: lixiaoyan Date: Fri, 9 Aug 2024 11:23:16 +0800 Subject: [PATCH 42/51] Add switch enable-rm Issue: IAHTXE Signed-off-by: lixiaoyan Change-Id: Id2b7be09a99f358119dc19f7c24665424d28025c --- build/compile_script/ark.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py index 4da2ce07..ce690347 100755 --- a/build/compile_script/ark.py +++ b/build/compile_script/ark.py @@ -481,10 +481,10 @@ class ArkPy: test_script_name, test_script_path) else: cmd = "cd {5} && python3 {4} {0} --timeout {3}" \ - " --libs-dir ../../{1}/lib.unstripped/arkcompiler/ets_runtime" \ - ":../../{1}/lib.unstripped/thirdparty/icu" \ + " --libs-dir ../../{1}/arkcompiler/ets_runtime" \ + ":../../{1}/thirdparty/icu" \ ":../../prebuilts/clang/ohos/linux-x86_64/llvm/lib" \ - ":../../{1}/lib.unstripped/thirdparty/bounds_checking_function/" \ + ":../../{1}/thirdparty/bounds_checking_function/" \ " --run-baseline-jit" \ " --ark-tool=../../{1}/arkcompiler/ets_runtime/ark_js_vm" \ " --ark-frontend-binary=../../{1}/arkcompiler/ets_frontend/es2abc" \ @@ -508,6 +508,11 @@ class ArkPy: if threads_value: args_to_test262_cmd.extend([threads_name, threads_value]) + enable_rm = [arg for arg in arg_list if "enable-rm" in arg] + if enable_rm: + args_to_test262_cmd.append("--enable-rm") + arg_list.remove(enable_rm[0]) + if len(arg_list) == 0: args_to_test262_cmd.append("--es2021 all") elif len(arg_list) == 1: @@ -704,7 +709,8 @@ class ArkPy: " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --aot] " \ "[none or --pgo] [none or --litecg] [none, file or dir] [none or --threads=X] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --jit] [none or --threads=X]\033[0m\n" - " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --baseline-jit] [none or --threads=X]\033[0m\n" + " python3 ark.py \033[92m[os_cpu].[mode] [test262] [none or --baseline-jit] [none or --enable-rm] " \ + "[none or --threads=X]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [unittest] [option]\033[0m\n" " python3 ark.py \033[92m[os_cpu].[mode] [regresstest] [none, file or dir] " \ "[none or --processes X and/or --test-list TEST_LIST_NAME]\033[0m\n") @@ -718,7 +724,7 @@ class ArkPy: " python3 ark.py \033[92mx64.release test262 --threads=16\033[0m\n" " python3 ark.py \033[92mx64.release test262 --aot --pgo --litecg\033[0m\n" " python3 ark.py \033[92mx64.release test262 --aot --pgo --litecg --threads=8\033[0m\n" - " python3 ark.py \033[92mx64.release test262 --jit\033[0m\n" + " python3 ark.py \033[92mx64.release test262 --jit --enable-rm\033[0m\n" " python3 ark.py \033[92mx64.release test262 --baseline-jit\033[0m\n" " python3 ark.py \033[92mx64.release test262 built-ins/Array\033[0m\n" " python3 ark.py \033[92mx64.release test262 built-ins/Array/name.js\033[0m\n" -- Gitee From 55e3f2b79b6c4f44acef0ed1a0263f68f68bdaed Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Fri, 9 Aug 2024 16:50:48 +0800 Subject: [PATCH 43/51] [Bug]: Fix the musl feature configured in part_config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAF3U3?from=project-issue Test:Source code compilation Signed-off-by: xwx1135370 --- build/third_party_gn/musl/BUILD.gn | 12 ++++++------ build/third_party_gn/musl/musl_config.gni | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build/third_party_gn/musl/BUILD.gn b/build/third_party_gn/musl/BUILD.gn index 8cbfe3ec..73729d5e 100644 --- a/build/third_party_gn/musl/BUILD.gn +++ b/build/third_party_gn/musl/BUILD.gn @@ -162,7 +162,7 @@ action("create_syscall_h_file") { } uapi_from = "local" -uapi_full_path = rebase_path(uapi_dir) +uapi_full_path = rebase_path(musl_uapi_dir) arguments_uapi = [ "-c" ] # exclude these files because they need special treatment @@ -179,7 +179,7 @@ uspi_files = exec_script("/bin/sh", arguments_uapi, "list lines") # Generate a copy target for each file foreach(file, uspi_files) { copy("copy_uapi_${file}") { - sources = [ "${uapi_dir}/${file}" ] + sources = [ "${musl_uapi_dir}/${file}" ] outputs = [ "${target_out_dir}/${musl_inc_out_dir}/${file}" ] } } @@ -188,7 +188,7 @@ group("copy_uapi_scsi") { deps = [] sources = [] outputs = [] - uapi_scsi_dir = rebase_path("${uapi_dir}/scsi") + uapi_scsi_dir = rebase_path("${musl_uapi_dir}/scsi") arguments_scsi = [ "-c" ] arguments_scsi += [ "ls ${uapi_scsi_dir}" ] uapi_scsi_files = exec_script("/bin/sh", arguments_scsi, "list lines") @@ -196,7 +196,7 @@ group("copy_uapi_scsi") { # Generate a copy target for each file in scsi dir to avoid being influenced by musl_copy_inc_scsi output foreach(file, uapi_scsi_files) { copy("copy_uapi_scsi_${file}") { - sources += [ "${uapi_dir}/scsi/${file}" ] + sources += [ "${musl_uapi_dir}/scsi/${file}" ] outputs += [ "${target_out_dir}/${musl_inc_out_dir}/scsi/${file}" ] } deps += [ ":copy_uapi_scsi_${file}" ] @@ -210,9 +210,9 @@ copy("copy_uapi_asm") { } else { # aarch64 and x86_64 use same file file_name = "asm-arm64" } - sources = [ "${uapi_dir}/${file_name}/asm" ] + sources = [ "${musl_uapi_dir}/${file_name}/asm" ] } else { - sources = [ "${uapi_dir}/asm" ] + sources = [ "${musl_uapi_dir}/asm" ] } outputs = [ "${target_out_dir}/${musl_inc_out_dir}/asm" ] } diff --git a/build/third_party_gn/musl/musl_config.gni b/build/third_party_gn/musl/musl_config.gni index ceff6198..52814f23 100644 --- a/build/third_party_gn/musl/musl_config.gni +++ b/build/third_party_gn/musl/musl_config.gni @@ -45,10 +45,10 @@ declare_args() { declare_args() { runtime_lib_path = "//prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/15.0.4/lib" - use_jemalloc = false + musl_use_jemalloc = false musl_ported_dir = "intermidiates/${musl_target_os}/musl_src_ported" musl_inc_out_dir = "usr/include/${musl_target_triple}" - uapi_dir = "//kernel/linux/patches/linux-5.10/prebuilts/usr/include" + musl_uapi_dir = "//kernel/linux/patches/linux-5.10/prebuilts/usr/include" musl_dir = "//third_party/musl" musl_porting_dir = "//third_party/musl/porting/linux/user" } -- Gitee From 392034a876441a655de75b37d6635ae5f1188ba4 Mon Sep 17 00:00:00 2001 From: swx1282997 Date: Tue, 13 Aug 2024 18:19:10 +0800 Subject: [PATCH 44/51] Coverage supplement Supplement the coverage of the pt_json pt_returns pt_params debugger_service Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAJNH4 Signed-off-by: swx1282997 --- tooling/test/debugger_service_test.cpp | 15 +++++++++++++ tooling/test/pt_json_test.cpp | 31 ++++++++++++++++++++++++++ tooling/test/pt_params_test.cpp | 24 ++++++++++++++++++++ tooling/test/pt_returns_test.cpp | 14 ++++++++++++ 4 files changed, 84 insertions(+) diff --git a/tooling/test/debugger_service_test.cpp b/tooling/test/debugger_service_test.cpp index 694f0599..68b8796f 100644 --- a/tooling/test/debugger_service_test.cpp +++ b/tooling/test/debugger_service_test.cpp @@ -59,6 +59,9 @@ HWTEST_F_L0(DebuggerServiceTest, InitializeDebuggerTest) ASSERT_TRUE(handler != nullptr); InitializeDebugger(ecmaVm, nullptr); ASSERT_TRUE(handler != nullptr); + EcmaVM *vm = nullptr; + InitializeDebugger(vm, nullptr); + ASSERT_TRUE(handler != nullptr); } HWTEST_F_L0(DebuggerServiceTest, UninitializeDebuggerTest) @@ -70,6 +73,9 @@ HWTEST_F_L0(DebuggerServiceTest, UninitializeDebuggerTest) UninitializeDebugger(ecmaVm); handler = ecmaVm->GetJsDebuggerManager()->GetDebuggerHandler(); ASSERT_TRUE(handler == nullptr); + EcmaVM *vm = nullptr; + UninitializeDebugger(vm); + ASSERT_TRUE(handler == nullptr); } HWTEST_F_L0(DebuggerServiceTest, OnMessageTest) @@ -85,6 +91,9 @@ HWTEST_F_L0(DebuggerServiceTest, OnMessageTest) OnMessage(ecmaVm, msg + ""); ProcessMessage(ecmaVm); ASSERT_TRUE(result.find("Unknown method: Test") != std::string::npos); + EcmaVM *vm = nullptr; + OnMessage(vm, ""); + ASSERT_TRUE(result.find("Unknown method: Test") != std::string::npos); } HWTEST_F_L0(DebuggerServiceTest, WaitForDebuggerTest) @@ -107,6 +116,9 @@ HWTEST_F_L0(DebuggerServiceTest, ProcessMessageTest) OnMessage(ecmaVm, msg + ""); ProcessMessage(ecmaVm); ASSERT_TRUE(result.find("\"id\":0,") != std::string::npos); + EcmaVM *vm = nullptr; + ProcessMessage(vm); + ASSERT_TRUE(result.find("Stop is failure") != std::string::npos); } HWTEST_F_L0(DebuggerServiceTest, GetDispatchStatusTest) @@ -119,5 +131,8 @@ HWTEST_F_L0(DebuggerServiceTest, GetDispatchStatusTest) InitializeDebugger(ecmaVm, callback); status = ProtocolHandler::DispatchStatus(GetDispatchStatus(ecmaVm)); ASSERT_TRUE(status == ProtocolHandler::DispatchStatus::DISPATCHED); + EcmaVM *vm = nullptr; + int32_t GetDispatchStatusTest = GetDispatchStatus(vm); + ASSERT_TRUE(GetDispatchStatusTest == 0); } } // namespace panda::test \ No newline at end of file diff --git a/tooling/test/pt_json_test.cpp b/tooling/test/pt_json_test.cpp index 9157a8e0..9f42e46a 100644 --- a/tooling/test/pt_json_test.cpp +++ b/tooling/test/pt_json_test.cpp @@ -282,4 +282,35 @@ HWTEST_F_L0(PtJsonTest, AddTest) result = ptJson.Add(key, value2); ASSERT_EQ(result, false); } + +HWTEST_F_L0(PtJsonTest, UIntTest) +{ + std::string str = "UIntTest"; + std::unique_ptr json = PtJson::Parse(str.c_str()); + EXPECT_EQ(json->GetUInt(), 0); + str = "12345"; + json = PtJson::Parse(str.c_str()); + EXPECT_EQ(json->GetUInt(), 12345); +} + +HWTEST_F_L0(PtJsonTest, UInt64Test) +{ + std::string str = "UInt64Test"; + std::unique_ptr json = PtJson::Parse(str.c_str()); + EXPECT_EQ(json->GetUInt64(), 0); + str = "123456789012345"; + json = PtJson::Parse(str.c_str()); + EXPECT_EQ(json->GetUInt64(), 123456789012345); +} + +HWTEST_F_L0(PtJsonTest, ResultUInt64Test) +{ + auto test = PtJson::CreateObject(); + test->Add("a", "ResultUInt64Test"); + test->Add("b", 100); + uint64_t ui64; + ASSERT_EQ(test->GetUInt64("a", &ui64), Result::TYPE_ERROR); + ASSERT_EQ(test->GetUInt64("b", &ui64), Result::SUCCESS); + EXPECT_EQ(ui64, static_cast(100)); +} } \ No newline at end of file diff --git a/tooling/test/pt_params_test.cpp b/tooling/test/pt_params_test.cpp index 1ac83cfc..414158da 100644 --- a/tooling/test/pt_params_test.cpp +++ b/tooling/test/pt_params_test.cpp @@ -244,4 +244,28 @@ HWTEST_F_L0(PtParamsTest, StartParamsCreateTest) std::unique_ptr result1 = StartParams::Create(*ptJson1); ASSERT_TRUE(result1 == nullptr); } + +HWTEST_F_L0(PtParamsTest, AddRequireParamsTest) +{ + std::string msg; + std::unique_ptr smartStepIntoParams; + + msg = std::string() + R"({})"; + smartStepIntoParams = SmartStepIntoParams::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(smartStepIntoParams, nullptr); +} + +HWTEST_F_L0(PtParamsTest, SeriliazationTimeoutCheckEnableParamsCreateTest) +{ + std::string msg; + std::unique_ptr seriliazationParams; + + msg = std::string() + R"({})"; + seriliazationParams = SeriliazationTimeoutCheckEnableParams::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(seriliazationParams, nullptr); + + msg = std::string() + R"({"id":0,"method":"PtParams.Test","params":{"threshold":2}})"; + seriliazationParams = SeriliazationTimeoutCheckEnableParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_TRUE(seriliazationParams != nullptr); +} } // namespace panda::test \ No newline at end of file diff --git a/tooling/test/pt_returns_test.cpp b/tooling/test/pt_returns_test.cpp index 5ab02806..017ef1e6 100644 --- a/tooling/test/pt_returns_test.cpp +++ b/tooling/test/pt_returns_test.cpp @@ -282,4 +282,18 @@ HWTEST_F_L0(PtReturnsTest, GetCategoriesReturns) ASSERT_NE(json, nullptr); EXPECT_EQ(json->GetSize(), 1); } + +HWTEST_F_L0(PtReturnsTest, GetHeapUsageReturnsCreateTest) +{ + std::string msg; + std::unique_ptr heapUsageReturns; + + msg = std::string() + R"({})"; + heapUsageReturns = GetHeapUsageReturns::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(heapUsageReturns, nullptr); + + msg = std::string() + R"({"id":0,"method":"PtReturns.Test","params":{"usedSize":20,"totalSize":20}})"; + heapUsageReturns = GetHeapUsageReturns::Create(DispatchRequest(msg).GetParams()); + ASSERT_TRUE(heapUsageReturns != nullptr); +} } \ No newline at end of file -- Gitee From 5721ffd84063b34136e1fb33fb6c885ac7dba8ba Mon Sep 17 00:00:00 2001 From: duning Date: Wed, 14 Aug 2024 15:18:47 +0800 Subject: [PATCH 45/51] add testcase add testcase Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAAHIB Signed-off-by: duning Change-Id: I9d69f06f3fd6c2f6a0c2f38caeaac07832ff4e3b --- tooling/agent/debugger_impl.h | 1 + tooling/agent/heapprofiler_impl.h | 2 + tooling/test/debugger_impl_test.cpp | 242 ++++++++++++++++++++++++ tooling/test/heapprofiler_impl_test.cpp | 161 ++++++++++++++++ 4 files changed, 406 insertions(+) diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index 153f5d8f..61786a22 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -327,6 +327,7 @@ private: friend class JSPtHooks; friend class test::TestHooks; + friend class DebuggerImplFriendTest; }; } // namespace panda::ecmascript::tooling #endif \ No newline at end of file diff --git a/tooling/agent/heapprofiler_impl.h b/tooling/agent/heapprofiler_impl.h index b3cd4695..d0314759 100644 --- a/tooling/agent/heapprofiler_impl.h +++ b/tooling/agent/heapprofiler_impl.h @@ -197,6 +197,8 @@ private: #if defined(ECMASCRIPT_SUPPORT_HEAPPROFILER) uv_timer_t handle_ {}; #endif + + friend class HeapProfilerImplFriendTest; }; } // namespace panda::ecmascript::tooling #endif diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 3367e691..69702164 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -20,6 +20,37 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::tooling; +namespace panda::ecmascript::tooling { +class DebuggerImplFriendTest { +public: + explicit DebuggerImplFriendTest(std::unique_ptr &debuggerImpl) + { + debuggerImpl_ = std::move(debuggerImpl); + } + + void CheckAndGenerateCondFunc(const std::optional condition) + { + debuggerImpl_->CheckAndGenerateCondFunc(condition); + } + + Local ConvertToLocal(const std::string &varValue) + { + return debuggerImpl_->ConvertToLocal(varValue); + } + + bool GetMixStackEnabled() + { + return debuggerImpl_->mixStackEnabled_; + } + + bool DecodeAndCheckBase64(const std::string &src, std::vector &dest) + { + return debuggerImpl_->DecodeAndCheckBase64(src, dest); + } +private: + std::unique_ptr debuggerImpl_; +}; +} namespace panda::test { class DebuggerImplTest : public testing::Test { @@ -74,6 +105,28 @@ HWTEST_F_L0(DebuggerImplTest, NotifyScriptParsed__001) } } +HWTEST_F_L0(DebuggerImplTest, NotifyScriptParsed__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + ecmaVm->GetJsDebuggerManager()->SetIsDebugApp(true); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + // DebuggerImpl::NotifyScriptParsed -- fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH + std::string strFilename = ""; + EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(0, strFilename, "")); + ecmaVm->GetJsDebuggerManager()->SetIsDebugApp(false); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(false); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + HWTEST_F_L0(DebuggerImplTest, GenerateCallFrames__001) { } @@ -1566,4 +1619,193 @@ HWTEST_F_L0(DebuggerImplTest, NativeOutTest) ASSERT_TRUE(result2); ASSERT_NE(jspthooks, nullptr); } + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", false); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeReturn(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(!debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", true); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeReturn(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", true); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyReturnNative(); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", false); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyReturnNative(); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(!debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", false); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeCalling(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(!debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", true); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeCalling(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, CheckAndGenerateCondFunc__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto debugger = std::make_unique(debuggerImpl); + std::vector dest; + debugger->CheckAndGenerateCondFunc(""); + ASSERT_TRUE(!debugger->DecodeAndCheckBase64("", dest)); + std::string msg = "UEFOREEAAAAAAAAADAACAEgBAAAAAAAAAAAAAAIAAAA8AAAAAQAA"; + msg += "AEQBAAAAAAARAAAAAEAAABEAAAAkQAAAMQAAAB8AAAASAEAAAIAAABsAAAAAgAAAHQAAAD//////////"; + debugger->CheckAndGenerateCondFunc(msg); + ASSERT_TRUE(debugger->DecodeAndCheckBase64(msg, dest)); +} + +HWTEST_F_L0(DebuggerImplTest, ConvertToLocal__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto debugger = std::make_unique(debuggerImpl); + Local taggedValue = debugger->ConvertToLocal(""); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("false"); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("true"); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("undefined"); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("\"test\""); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("test"); + ASSERT_TRUE(taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("1"); + ASSERT_TRUE(!taggedValue.IsEmpty()); +} } // namespace panda::test diff --git a/tooling/test/heapprofiler_impl_test.cpp b/tooling/test/heapprofiler_impl_test.cpp index b847cd83..80a2cb45 100644 --- a/tooling/test/heapprofiler_impl_test.cpp +++ b/tooling/test/heapprofiler_impl_test.cpp @@ -19,6 +19,42 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::tooling; +namespace panda::ecmascript::tooling { +class HeapProfilerImplFriendTest { +public: + explicit HeapProfilerImplFriendTest(std::unique_ptr &heapprofilerImpl) + { + heapprofilerImpl_ = std::move(heapprofilerImpl); + } + + void ResetProfiles() + { + heapprofilerImpl_->frontend_.ResetProfiles(); + } + + void LastSeenObjectId(int32_t lastSeenObjectId, int64_t timeStampUs) + { + heapprofilerImpl_->frontend_.LastSeenObjectId(lastSeenObjectId, timeStampUs); + } + + void HeapStatsUpdate(HeapStat* updateData, int32_t count) + { + heapprofilerImpl_->frontend_.HeapStatsUpdate(updateData, count); + } + + void AddHeapSnapshotChunk(char *data, int32_t size) + { + heapprofilerImpl_->frontend_.AddHeapSnapshotChunk(data, size); + } + + void ReportHeapSnapshotProgress(int32_t done, int32_t total) + { + heapprofilerImpl_->frontend_.ReportHeapSnapshotProgress(done, total); + } +private: + std::unique_ptr heapprofilerImpl_; +}; +} namespace panda::test { class HeapProfilerImplTest : public testing::Test { @@ -409,4 +445,129 @@ HWTEST_F_L0(HeapProfilerImplTest, StopSamplingSuccessful) DispatchResponse result = heapProfiler->StopSampling(&samplingHeapProfile); ASSERT_TRUE(result.IsOk()); } + +HWTEST_F_L0(HeapProfilerImplTest, StartTrackingHeapObjects) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = ""; + msg += R"({"id":0,"method":"HeapProfiler.StartTrackingHeapObjects","params":{"trackAllocations":0}})"; + DispatchRequest request1(msg); + dispatcherImpl->StartTrackingHeapObjects(request1); + ASSERT_TRUE(result == "{\"id\":0,\"result\":{\"code\":1,\"message\":\"wrong params\"}}"); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, StopTrackingHeapObjects) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = ""; + msg += R"({"id":0,"method":"HeapProfiler.StopTrackingHeapObjects","params":{"reportProgress":0}})"; + DispatchRequest request1(msg); + dispatcherImpl->StopTrackingHeapObjects(request1); + ASSERT_TRUE(result == "{\"id\":0,\"result\":{\"code\":1,\"message\":\"wrong params\"}}"); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, ResetProfiles) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, nullptr); + auto heapprofiler = std::make_unique(tracing); + heapprofiler->ResetProfiles(); + ASSERT_TRUE(result == ""); + tracing = std::make_unique(ecmaVm, channel); + heapprofiler = std::make_unique(tracing); + heapprofiler->ResetProfiles(); + ASSERT_TRUE(result == ""); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, LastSeenObjectId) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, nullptr); + auto heapprofiler = std::make_unique(tracing); + heapprofiler->LastSeenObjectId(0, 0); + ASSERT_TRUE(result == ""); + tracing = std::make_unique(ecmaVm, channel); + heapprofiler = std::make_unique(tracing); + heapprofiler->LastSeenObjectId(0, 0); + std::string msg = "{\"method\":\"HeapProfiler.lastSeenObjectId\","; + msg += "\"params\":{\"lastSeenObjectId\":0,"; + msg += "\"timestamp\":0}}"; + ASSERT_TRUE(result == msg); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, HeapStatsUpdate) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, nullptr); + auto heapprofiler = std::make_unique(tracing); + heapprofiler->HeapStatsUpdate(nullptr, 0); + ASSERT_TRUE(result == ""); + tracing = std::make_unique(ecmaVm, channel); + heapprofiler = std::make_unique(tracing); + heapprofiler->HeapStatsUpdate(nullptr, 0); + std::string msg = "{\"method\":\"HeapProfiler.heapStatsUpdate\","; + msg += "\"params\":{\"statsUpdate\":[]}}"; + ASSERT_TRUE(result == msg); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, AddHeapSnapshotChunk) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + auto tracing = std::make_unique(ecmaVm, nullptr); + auto heapprofiler = std::make_unique(tracing); + heapprofiler->AddHeapSnapshotChunk(nullptr, 0); + ASSERT_TRUE(result == ""); +} + +HWTEST_F_L0(HeapProfilerImplTest, ReportHeapSnapshotProgress) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + auto tracing = std::make_unique(ecmaVm, nullptr); + auto heapprofiler = std::make_unique(tracing); + heapprofiler->ReportHeapSnapshotProgress(0, 0); + ASSERT_TRUE(result == ""); +} } // namespace panda::test -- Gitee From c89415775514e2862674c1e73f7b52b59cf218ca Mon Sep 17 00:00:00 2001 From: bigtea Date: Tue, 13 Aug 2024 15:28:45 +0800 Subject: [PATCH 46/51] Fix static variable multithreading issue Issue: IAJP7E Signed-off-by: bigtea --- tooling/backend/js_pt_hooks.cpp | 3 +-- tooling/backend/js_pt_hooks.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tooling/backend/js_pt_hooks.cpp b/tooling/backend/js_pt_hooks.cpp index bcb05660..a54aa068 100644 --- a/tooling/backend/js_pt_hooks.cpp +++ b/tooling/backend/js_pt_hooks.cpp @@ -83,8 +83,7 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entr [[maybe_unused]] LocalScope scope(debugger_->vm_); - static uint32_t scriptId = 0; - if (debugger_->NotifyScriptParsed(scriptId++, pandaFileName.data(), entryPoint)) { + if (debugger_->NotifyScriptParsed(g_scriptId++, pandaFileName.data(), entryPoint)) { firstTime_ = true; } } diff --git a/tooling/backend/js_pt_hooks.h b/tooling/backend/js_pt_hooks.h index cb5f7726..62c52cf9 100644 --- a/tooling/backend/js_pt_hooks.h +++ b/tooling/backend/js_pt_hooks.h @@ -25,6 +25,8 @@ namespace panda::ecmascript::tooling { class DebuggerImpl; +static std::atomic g_scriptId {0}; + class JSPtHooks : public PtHooks { public: explicit JSPtHooks(DebuggerImpl *debugger) : debugger_(debugger) {} -- Gitee From 4e619eb4349104daa7f041995ab6b11ceee5207f Mon Sep 17 00:00:00 2001 From: yangxiaoshuai2022 Date: Sat, 10 Aug 2024 15:10:43 +0800 Subject: [PATCH 47/51] fix the non-standard naming of DLL Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAJ58U Signed-off-by: yangxiaoshuai2022 --- inspector/BUILD.gn | 2 ++ inspector/inspector.cpp | 6 +++--- tooling/BUILD.gn | 1 + tooling/test/client_utils/test_util.h | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/inspector/BUILD.gn b/inspector/BUILD.gn index 48d5efab..ed217326 100644 --- a/inspector/BUILD.gn +++ b/inspector/BUILD.gn @@ -69,6 +69,7 @@ ohos_shared_library("ark_debugger") { innerapi_tags = [ "platformsdk" ] subsystem_name = "arkcompiler" part_name = "toolchain" + output_name = "ark_inspector" } ohos_source_set("connectserver_debugger_static") { @@ -118,4 +119,5 @@ ohos_shared_library("connectserver_debugger") { innerapi_tags = [ "platformsdk" ] subsystem_name = "arkcompiler" part_name = "toolchain" + output_name = "ark_connect_inspector" } diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 2b2fe896..f684b793 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -71,11 +71,11 @@ thread_local void* g_vm = nullptr; #if !defined(IOS_PLATFORM) #if defined(WINDOWS_PLATFORM) -constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_ecma_debugger.dll"; +constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_tooling.dll"; #elif defined(MAC_PLATFORM) -constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_ecma_debugger.dylib"; +constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_tooling.dylib"; #else -constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_ecma_debugger.so"; +constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_tooling.so"; #endif #endif diff --git a/tooling/BUILD.gn b/tooling/BUILD.gn index 2000fa87..9221adcb 100644 --- a/tooling/BUILD.gn +++ b/tooling/BUILD.gn @@ -127,6 +127,7 @@ ohos_shared_library("libark_ecma_debugger") { innerapi_tags = [ "platformsdk" ] subsystem_name = "arkcompiler" part_name = "toolchain" + output_name = "libark_tooling" } ohos_shared_library("libark_ecma_debugger_test") { diff --git a/tooling/test/client_utils/test_util.h b/tooling/test/client_utils/test_util.h index 81375f99..5fe22bbe 100644 --- a/tooling/test/client_utils/test_util.h +++ b/tooling/test/client_utils/test_util.h @@ -36,9 +36,9 @@ using TestMap = CUnorderedMap>; using namespace OHOS::ArkCompiler::Toolchain; #ifdef OHOS_PLATFORM -#define DEBUGGER_LIBRARY "libark_debugger.z.so" +#define DEBUGGER_LIBRARY "libark_inspector.z.so" #else -#define DEBUGGER_LIBRARY "libark_debugger.so" +#define DEBUGGER_LIBRARY "libark_inspector.so" #endif class TestUtil { -- Gitee From a76d7f7dbc53e7bb552b073df422d0b943ae309d Mon Sep 17 00:00:00 2001 From: Rokashevich Svetlana Date: Fri, 16 Aug 2024 12:08:51 +0300 Subject: [PATCH 48/51] Display codeowners for hidden folders and files Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/IAKBP2 Signed-off-by: Rokashevich Svetlana --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/CODEOWNERS b/CODEOWNERS index a2ad3740..ece02496 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -12,4 +12,5 @@ # limitations under the License. * @klooer +.* @klooer -- Gitee From 2c885415b0d84fe3481dbf2f5b76d8803a2320e4 Mon Sep 17 00:00:00 2001 From: yanzhiqi1 Date: Wed, 14 Aug 2024 10:45:27 +0800 Subject: [PATCH 49/51] Fix traceconfig::create Fix traceconfig::create Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAJVUA Signed-off-by: yanzhiqi1 --- tooling/base/pt_types.cpp | 5 +++- tooling/test/pt_types_test.cpp | 42 +++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/tooling/base/pt_types.cpp b/tooling/base/pt_types.cpp index 6d44cf8e..c000ff3f 100644 --- a/tooling/base/pt_types.cpp +++ b/tooling/base/pt_types.cpp @@ -3086,7 +3086,7 @@ std::unique_ptr ScriptTypeProfile::Create(const PtJson ¶m std::string error; auto scriptTypeProfile = std::make_unique(); Result ret; - + std::string scriptId; ret = params.GetString("scriptId", &scriptId); if (ret == Result::SUCCESS) { @@ -3193,6 +3193,7 @@ std::unique_ptr TraceConfig::Create(const PtJson ¶ms) ret = params.GetArray("includedCategories", &includedCategories); if (ret == Result::SUCCESS) { int32_t includedCategoriesLen = includedCategories->GetSize(); + traceConfig->includedCategories_= std::vector(); for (int32_t i = 0; i < includedCategoriesLen; ++i) { std::string pIncludedCategories = includedCategories->Get(i)->GetString(); traceConfig->includedCategories_.value().emplace_back(pIncludedCategories); @@ -3205,6 +3206,7 @@ std::unique_ptr TraceConfig::Create(const PtJson ¶ms) ret = params.GetArray("excludedCategories", &excludedCategories); if (ret == Result::SUCCESS) { int32_t excludedCategoriesLen = excludedCategories->GetSize(); + traceConfig->excludedCategories_ = std::vector(); for (int32_t i = 0; i < excludedCategoriesLen; ++i) { std::string pExcludedCategories = excludedCategories->Get(i)->GetString(); traceConfig->excludedCategories_.value().emplace_back(pExcludedCategories); @@ -3217,6 +3219,7 @@ std::unique_ptr TraceConfig::Create(const PtJson ¶ms) ret = params.GetArray("syntheticDelays", &syntheticDelays); if (ret == Result::SUCCESS) { int32_t syntheticDelaysLen = syntheticDelays->GetSize(); + traceConfig->syntheticDelays_ = std::vector(); for (int32_t i = 0; i < syntheticDelaysLen; ++i) { std::string pSyntheticDelays = syntheticDelays->Get(i)->GetString(); traceConfig->syntheticDelays_.value().emplace_back(pSyntheticDelays); diff --git a/tooling/test/pt_types_test.cpp b/tooling/test/pt_types_test.cpp index 2ec83070..16373a24 100644 --- a/tooling/test/pt_types_test.cpp +++ b/tooling/test/pt_types_test.cpp @@ -309,12 +309,9 @@ HWTEST_F_L0(PtTypesTest, TraceConfigToJsonTest) std::unique_ptr result = treceConfig.ToJson(); ASSERT_TRUE(result); } + HWTEST_F_L0(PtTypesTest, TraceConfigCreateTest) { - std::unique_ptr includedCategoriesArray = PtJson::CreateArray(); - std::unique_ptr excludedCategoriesArray = PtJson::CreateArray(); - std::unique_ptr syntheticDelaysArray = PtJson::CreateArray(); - std::unique_ptr object = PtJson::CreateObject(); std::string attribute = "test"; std::unique_ptr ptJson = PtJson::CreateObject(); ptJson->Add("recordMode", 0); @@ -327,23 +324,42 @@ HWTEST_F_L0(PtTypesTest, TraceConfigCreateTest) ptJson->Add("memoryDumpConfig", attribute.c_str()); std::unique_ptr traceConfig = TraceConfig::Create(*ptJson); ASSERT_TRUE(!traceConfig); - object->Add("test", 0); + std::unique_ptr ptJson1 = PtJson::CreateObject(); - ptJson1->Add("includedCategories", includedCategoriesArray); - ptJson1->Add("recordMode", attribute.c_str()); - ptJson1->Add("excludedCategories", excludedCategoriesArray); - ptJson1->Add("syntheticDelays", syntheticDelaysArray); - ptJson1->Add("memoryDumpConfig", object); + ptJson1->Add("recordMode", "test"); std::unique_ptr traceConfig1 = TraceConfig::Create(*ptJson1); ASSERT_TRUE(!traceConfig1); + std::unique_ptr ptJson2 = PtJson::CreateObject(); std::unique_ptr traceConfig2 = TraceConfig::Create(*ptJson2); ASSERT_TRUE(traceConfig2); + + std::unique_ptr includedCategoriesArray = PtJson::CreateArray(); + includedCategoriesArray->Push("includedCategory"); + std::unique_ptr excludedCategoriesArray = PtJson::CreateArray(); + excludedCategoriesArray->Push("excludedCategory1"); + excludedCategoriesArray->Push("excludedCategory2"); + std::unique_ptr syntheticDelaysArray = PtJson::CreateArray(); + syntheticDelaysArray->Push("syntheticDelay1"); + syntheticDelaysArray->Push("syntheticDelay2"); + syntheticDelaysArray->Push("syntheticDelay3"); std::unique_ptr ptJson3 = PtJson::CreateObject(); - std::unique_ptr memoryDumpConfig = PtJson::CreateArray(); - ptJson3->Add("memoryDumpConfig", std::move(memoryDumpConfig)); + ptJson3->Add("recordMode", "recordUntilFull"); + ptJson3->Add("enableSampling", true); + ptJson3->Add("enableSystrace", true); + ptJson3->Add("enableArgumentFilter", true); + ptJson3->Add("includedCategories", includedCategoriesArray); + ptJson3->Add("excludedCategories", excludedCategoriesArray); + ptJson3->Add("syntheticDelays", syntheticDelaysArray); + ptJson3->Add("memoryDumpConfig", PtJson::CreateObject()); std::unique_ptr traceConfig3 = TraceConfig::Create(*ptJson3); - ASSERT_TRUE(!traceConfig3); + ASSERT_TRUE(traceConfig3); + ASSERT_TRUE(traceConfig3->GetEnableSampling()); + ASSERT_TRUE(traceConfig3->GetEnableSystrace()); + ASSERT_TRUE(traceConfig3->GetEnableArgumentFilter()); + ASSERT_EQ(traceConfig3->GetIncludedCategories()->size(), 1); + ASSERT_EQ(traceConfig3->GetExcludedCategories()->size(), 2); + ASSERT_EQ(traceConfig3->GetSyntheticDelays()->size(), 3); } HWTEST_F_L0(PtTypesTest, ScriptTypeProfileCreateTest) -- Gitee From 81e7f14bdefeefa380f83dd2450b80fafc3210f6 Mon Sep 17 00:00:00 2001 From: daiweihao Date: Mon, 5 Aug 2024 21:22:08 +0800 Subject: [PATCH 50/51] 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 Change-Id: Ia9842cde33fbfd18d2a782def05b9a0d7fb3dda9 --- BUILD.gn | 3 + inspector/test/BUILD.gn | 69 +++++++++++ inspector/test/connect_server_test.cpp | 155 +++++++++++++++++++++++++ test/resource/tooling/ohos_test.xml | 5 + websocket/test/websocket_test.cpp | 18 +-- 5 files changed, 242 insertions(+), 8 deletions(-) create mode 100644 inspector/test/BUILD.gn create mode 100644 inspector/test/connect_server_test.cpp diff --git a/BUILD.gn b/BUILD.gn index 5d98ae83..6dce3edb 100644 --- a/BUILD.gn +++ b/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", ] diff --git a/inspector/test/BUILD.gn b/inspector/test/BUILD.gn new file mode 100644 index 00000000..4153eb43 --- /dev/null +++ b/inspector/test/BUILD.gn @@ -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" ] + } +} diff --git a/inspector/test/connect_server_test.cpp b/inspector/test/connect_server_test.cpp new file mode 100644 index 00000000..1eeeba1a --- /dev/null +++ b/inspector/test/connect_server_test.cpp @@ -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 \ No newline at end of file diff --git a/test/resource/tooling/ohos_test.xml b/test/resource/tooling/ohos_test.xml index a733d13e..5b9dc623 100755 --- a/test/resource/tooling/ohos_test.xml +++ b/test/resource/tooling/ohos_test.xml @@ -275,4 +275,9 @@