From 2a8655a76a8d875836edee1cbed7ae4483c82707 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Wed, 17 Jul 2024 13:43:30 +0800 Subject: [PATCH] Improve:cross compile. --- hal/src/WifiHal.cpp | 8 ++++---- middleware/StorageManager/src/SdCardHandle.cpp | 4 ++-- .../tool/src/MissionManagerTestTool.cpp | 4 ++-- test/hal/tool/CMakeLists.txt | 4 ++++ test/hal/tool/src/SdCardHalMock.cpp | 5 +++-- test/middleware/HuntingUpgrade/CMakeLists.txt | 2 +- .../tool/src/HuntingUpgradeTestTool.cpp | 4 ++-- .../middleware/IpcConfig/src_mock/IpcConfigTest.cpp | 2 +- test/middleware/IpcConfig/tool/CMakeLists.txt | 2 +- .../IpcConfig/tool/src/IpcConfigTestTool.cpp | 4 ++-- test/utils/LinuxApiMock/include/LinuxApiMock.h | 4 ++++ test/utils/SharedData/CMakeLists.txt | 2 +- utils/LinuxApi/include/LinuxApi.h | 13 +++++++++++++ utils/LinuxApi/src/LinuxApi.c | 4 ++++ utils/MediaBase/src/FfmpegMuxStreamV2.cpp | 2 +- utils/SharedData/src/SharedMemory.cpp | 2 +- utils/UpgradeTool/src/UpgradeTool.cpp | 4 ++-- 17 files changed, 48 insertions(+), 22 deletions(-) diff --git a/hal/src/WifiHal.cpp b/hal/src/WifiHal.cpp index e7e7cd0..7a15930 100644 --- a/hal/src/WifiHal.cpp +++ b/hal/src/WifiHal.cpp @@ -55,10 +55,10 @@ StatusCode WifiHal::OpenApMode(void) } } LogInfo("wlan0 ok. \n"); - fx_system("ifconfig wlan0 192.168.169.1 netmask 255.255.255.0"); - fx_system("hostapd -d /etc/hostapd.conf &"); - fx_system("touch /var/lib/misc/udhcpd.leases"); - fx_system("udhcpd -f /etc/udhcpd.conf &"); + fx_system_v2("ifconfig wlan0 192.168.169.1 netmask 255.255.255.0"); + fx_system_v2("hostapd -d /etc/hostapd.conf &"); + fx_system_v2("touch /var/lib/misc/udhcpd.leases"); + fx_system_v2("udhcpd -f /etc/udhcpd.conf &"); return CreateStatusCode(STATUS_CODE_OK); } StatusCode WifiHal::CloseApMode(void) diff --git a/middleware/StorageManager/src/SdCardHandle.cpp b/middleware/StorageManager/src/SdCardHandle.cpp index 1185c24..a93fc45 100644 --- a/middleware/StorageManager/src/SdCardHandle.cpp +++ b/middleware/StorageManager/src/SdCardHandle.cpp @@ -73,8 +73,8 @@ StatusCode SdCardHandle::SdSaveFile(const std::string &sourceFile, const std::st return CreateStatusCode(STATUS_CODE_NOT_OK); } snprintf(cmd, CMD_BUF_SIZE, "cp %s %s", sourceFile.c_str(), realSavePah.c_str()); - fx_system(cmd); - fx_system("sync"); + fx_system_v2(cmd); + fx_system_v2("sync"); return CreateStatusCode(STATUS_CODE_OK); } StorageEvent SdCardHandle::StorageEventConvert(const SdCardHalStatus &status) diff --git a/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp b/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp index 5c1e174..0cb1ab6 100644 --- a/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp +++ b/test/application/MissionManager/tool/src/MissionManagerTestTool.cpp @@ -31,7 +31,7 @@ void MissionManagerTestTool::UnInit(void) } void MissionManagerTestTool::CreateUpgradeFile(void) { - fx_system("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test"); + fx_system_v2("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test"); UpgradeTool::GetInstance()->PackFile(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test", SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH, "1.0.0.0", @@ -41,5 +41,5 @@ void MissionManagerTestTool::CreateUpgradeFile(void) } void MissionManagerTestTool::RemoveUpgradeFile(void) { - fx_system("rm " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH); + fx_system_v2("rm " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH); } \ No newline at end of file diff --git a/test/hal/tool/CMakeLists.txt b/test/hal/tool/CMakeLists.txt index 49ac463..2f0892d 100644 --- a/test/hal/tool/CMakeLists.txt +++ b/test/hal/tool/CMakeLists.txt @@ -24,6 +24,10 @@ set(TEST_TOOL_TARGET HalTestTool) add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) target_link_libraries(${TEST_TOOL_TARGET} MediaBase Hal KeyControl LedControl LinuxApiMock Log) +# if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) +# target_link_libraries(${TEST_TOOL_TARGET} LinuxApiMock) +# endif() + add_custom_target( HalTestTool_code_check COMMAND ${CLANG_TIDY_EXE} diff --git a/test/hal/tool/src/SdCardHalMock.cpp b/test/hal/tool/src/SdCardHalMock.cpp index efff5c5..2dc2d69 100644 --- a/test/hal/tool/src/SdCardHalMock.cpp +++ b/test/hal/tool/src/SdCardHalMock.cpp @@ -50,6 +50,7 @@ void SdCardHalMock::MockSdCardInsert(std::shared_ptr &mock) } void SdCardHalMock::MockSdCardFormatResult(std::shared_ptr &mock, const int &result) { - LinuxTest::SetSystemCommandResult(mock, "mkfs.vfat", result); - LinuxTest::SetSystemCommandResult(mock, "umount", result); + // TODO: improve + // LinuxTest::SetSystemCommandResult(mock, "mkfs.vfat", result); + // LinuxTest::SetSystemCommandResult(mock, "umount", result); } \ No newline at end of file diff --git a/test/middleware/HuntingUpgrade/CMakeLists.txt b/test/middleware/HuntingUpgrade/CMakeLists.txt index afbd69c..77999f0 100644 --- a/test/middleware/HuntingUpgrade/CMakeLists.txt +++ b/test/middleware/HuntingUpgrade/CMakeLists.txt @@ -32,7 +32,7 @@ endif() set(TARGET_NAME HuntingUpgradeTest) add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} HuntingUpgradeTestTool LinuxApiMock gtest gmock pthread) +target_link_libraries(${TARGET_NAME} HuntingUpgradeTestTool gtest gmock pthread) if(${TEST_COVERAGE} MATCHES "true") target_link_libraries(${TARGET_NAME} gcov) endif() diff --git a/test/middleware/HuntingUpgrade/tool/src/HuntingUpgradeTestTool.cpp b/test/middleware/HuntingUpgrade/tool/src/HuntingUpgradeTestTool.cpp index d547406..8f9744d 100644 --- a/test/middleware/HuntingUpgrade/tool/src/HuntingUpgradeTestTool.cpp +++ b/test/middleware/HuntingUpgrade/tool/src/HuntingUpgradeTestTool.cpp @@ -27,13 +27,13 @@ void HuntingUpgradeTestTool::Init(void) void HuntingUpgradeTestTool::UnInit(void) { if (access(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test", F_OK) == 0) { - fx_system("rm -rf " SD_CARD_MOUNT_PATH); + fx_system_v2("rm -rf " SD_CARD_MOUNT_PATH); } } void HuntingUpgradeTestTool::CreateUpgradeFile(void) { CheckDirectory(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test"); - fx_system("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test"); + fx_system_v2("touch " SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test"); UpgradeTool::GetInstance()->PackFile(SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH "-test", SD_CARD_MOUNT_PATH APPLICATION_CHECK_PATH, "6.4.5.6", diff --git a/test/middleware/IpcConfig/src_mock/IpcConfigTest.cpp b/test/middleware/IpcConfig/src_mock/IpcConfigTest.cpp index cf4b85e..a8662f5 100644 --- a/test/middleware/IpcConfig/src_mock/IpcConfigTest.cpp +++ b/test/middleware/IpcConfig/src_mock/IpcConfigTest.cpp @@ -60,6 +60,6 @@ void IpcConfigTest::RemoveConfigFile(void) constexpr int BUFF_SIZE = 128; char cmd[BUFF_SIZE] = {0}; snprintf(cmd, BUFF_SIZE, "rm -f %s", IPC_CONFIG_FILE_PATH); - fx_system(cmd); + fx_system_v2(cmd); } } \ No newline at end of file diff --git a/test/middleware/IpcConfig/tool/CMakeLists.txt b/test/middleware/IpcConfig/tool/CMakeLists.txt index 00ab20c..b0d053b 100644 --- a/test/middleware/IpcConfig/tool/CMakeLists.txt +++ b/test/middleware/IpcConfig/tool/CMakeLists.txt @@ -20,7 +20,7 @@ include_directories( aux_source_directory(./src TEST_TOOL_SRC_FILES) set(TEST_TOOL_TARGET IpcConfigTestTool) add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) -target_link_libraries(${TEST_TOOL_TARGET} IpcConfig LinuxApiMock Log) +target_link_libraries(${TEST_TOOL_TARGET} IpcConfig Log) add_custom_target( IpcConfigTestTool_code_check diff --git a/test/middleware/IpcConfig/tool/src/IpcConfigTestTool.cpp b/test/middleware/IpcConfig/tool/src/IpcConfigTestTool.cpp index d12906e..14619ab 100644 --- a/test/middleware/IpcConfig/tool/src/IpcConfigTestTool.cpp +++ b/test/middleware/IpcConfig/tool/src/IpcConfigTestTool.cpp @@ -34,7 +34,7 @@ void IpcConfigTestTool::UnInit(void) constexpr int BUF_LENGTH = 256; char cmd[BUF_LENGTH] = {0}; sprintf(cmd, "rm -rf %s", MOUNTED_FILE); - fx_system(cmd); + fx_system_v2(cmd); } void IpcConfigTestTool::MockMountedFile(void) { @@ -57,7 +57,7 @@ void IpcConfigTestTool::MockMountedFile(void) "rw,relatime,fmask=0022,dmask=0022,codepage=936,iocharset=cp936,shortname=mixed,utf8,errors=remount-ro 0 0\n"); fclose(file); - fx_system("sync"); + fx_system_v2("sync"); LogInfo("File written successfully.\n"); } FILE *IpcConfigTestTool::OpenMockMountedFile(const char *mode) diff --git a/test/utils/LinuxApiMock/include/LinuxApiMock.h b/test/utils/LinuxApiMock/include/LinuxApiMock.h index 93d4bb8..f14c54c 100644 --- a/test/utils/LinuxApiMock/include/LinuxApiMock.h +++ b/test/utils/LinuxApiMock/include/LinuxApiMock.h @@ -68,6 +68,10 @@ public: virtual int GetHandleForMock(void); public: + /** + * @brief The functions from here on are all used in the simulator under the Ubuntu system. When cross-compiling, it + * is forbidden to use the following functions directly. + */ static std::shared_ptr CreateLinuxTest(void); static void SetSystemCommandResult(std::shared_ptr &mock, const std::string &command, const int &result); }; diff --git a/test/utils/SharedData/CMakeLists.txt b/test/utils/SharedData/CMakeLists.txt index 89a4764..8c21a74 100644 --- a/test/utils/SharedData/CMakeLists.txt +++ b/test/utils/SharedData/CMakeLists.txt @@ -20,7 +20,7 @@ aux_source_directory(./src SRC_FILES) set(TARGET_NAME SharedDataTest) add_executable(${TARGET_NAME} ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} SharedData LinuxApiMock gtest gmock pthread Log) +target_link_libraries(${TARGET_NAME} SharedData gtest gmock pthread Log) if(${TEST_COVERAGE} MATCHES "true") target_link_libraries(${TARGET_NAME} gcov) endif() diff --git a/utils/LinuxApi/include/LinuxApi.h b/utils/LinuxApi/include/LinuxApi.h index ceef546..5200ef2 100644 --- a/utils/LinuxApi/include/LinuxApi.h +++ b/utils/LinuxApi/include/LinuxApi.h @@ -24,7 +24,20 @@ #ifdef __cplusplus extern "C" { #endif +/** + * @brief This function can be used to test the function, and the system function can be used as an imperative return + * result. + * @param command + * @return int + */ int fx_system(const char *command); +/** + * @brief Under the circumstances of the return of the system, there is a "warning" written by the organization, and the + * use of the function does not exist. + * @param command + * @return int + */ +int fx_system_v2(const char *command); int fx_open(const char *pathname, int flags); int fx_tcgetattr(int fd, struct termios *termios_p); int fx_tcsetattr(int fd, int optional_actions, const struct termios *termios_p); diff --git a/utils/LinuxApi/src/LinuxApi.c b/utils/LinuxApi/src/LinuxApi.c index 7fd4b4c..d8e2c6a 100644 --- a/utils/LinuxApi/src/LinuxApi.c +++ b/utils/LinuxApi/src/LinuxApi.c @@ -28,6 +28,10 @@ int fx_system(const char *command) { return system(command); } +int fx_system_v2(const char *command) +{ + return system(command); +} int fx_open(const char *pathname, int flags) { return open(pathname, flags); diff --git a/utils/MediaBase/src/FfmpegMuxStreamV2.cpp b/utils/MediaBase/src/FfmpegMuxStreamV2.cpp index f38dc70..c14ff4c 100644 --- a/utils/MediaBase/src/FfmpegMuxStreamV2.cpp +++ b/utils/MediaBase/src/FfmpegMuxStreamV2.cpp @@ -66,7 +66,7 @@ StatusCode FfmpegMuxStreamV2::CloseOutputFile(void) avio_closep(&mOutputFormat->pb); } avformat_free_context(mOutputFormat); - fx_system("sync"); + fx_system_v2("sync"); mOutputFileInfo.reset(); return CreateStatusCode(STATUS_CODE_OK); } diff --git a/utils/SharedData/src/SharedMemory.cpp b/utils/SharedData/src/SharedMemory.cpp index d2295f5..3a0386a 100644 --- a/utils/SharedData/src/SharedMemory.cpp +++ b/utils/SharedData/src/SharedMemory.cpp @@ -36,7 +36,7 @@ StatusCode SharedMemory::MakeSharedMemory(const int &size) char touchPath[128] = {0}; if (access(mPath, F_OK) != 0) { sprintf(touchPath, "%s %s", "touch", mPath); - fx_system(touchPath); + fx_system_v2(touchPath); } key_t key = ftok(mPath, mProjectId); if (key < 0) { diff --git a/utils/UpgradeTool/src/UpgradeTool.cpp b/utils/UpgradeTool/src/UpgradeTool.cpp index fb5bcbe..fab4a44 100644 --- a/utils/UpgradeTool/src/UpgradeTool.cpp +++ b/utils/UpgradeTool/src/UpgradeTool.cpp @@ -124,12 +124,12 @@ void UpgradeTool::PackFile(const std::string &fileName, const std::string &outpu LogError("write file failed, remove output file.\n"); char cmd[1024]; snprintf(cmd, sizeof(cmd), "rm -f %s", outputFile.c_str()); - fx_system(cmd); + fx_system_v2(cmd); } else { LogInfo("write file success.\n"); } fclose(input_file); fclose(output_file); - fx_system("sync"); + fx_system_v2("sync"); } \ No newline at end of file