From 0b976c4619e533a4b8c5f25a22b3d3a953b27242 Mon Sep 17 00:00:00 2001 From: xiaojiazhu <258828110.@qq.com> Date: Sun, 7 Apr 2024 08:00:41 -0700 Subject: [PATCH] Add:TCP server module. --- external/libhv/libhv-1.3.2/CMakeLists.txt | 4 +- test/utils/CMakeLists.txt | 3 +- test/utils/TcpModule/CMakeLists.txt | 68 +++++++++++++++++++++ test/utils/TcpModule/mainTest.cpp | 23 +++++++ test/utils/TcpModule/src/TcpModule_Test.cpp | 31 ++++++++++ test/utils/UartDevice/CMakeLists.txt | 2 - utils/TcpModule/CMakeLists.txt | 4 +- utils/TcpModule/src/TcpClient.cpp | 14 +++++ utils/TcpModule/src/TcpClient.h | 14 +++++ utils/TcpModule/src/TcpModuleImpl.h | 2 +- utils/TcpModule/src/TcpServer.cpp | 14 +++++ utils/TcpModule/src/TcpServer.h | 14 +++++ 12 files changed, 184 insertions(+), 9 deletions(-) create mode 100644 test/utils/TcpModule/CMakeLists.txt create mode 100644 test/utils/TcpModule/mainTest.cpp create mode 100644 test/utils/TcpModule/src/TcpModule_Test.cpp create mode 100644 utils/TcpModule/src/TcpClient.cpp create mode 100644 utils/TcpModule/src/TcpClient.h create mode 100644 utils/TcpModule/src/TcpServer.cpp create mode 100644 utils/TcpModule/src/TcpServer.h diff --git a/external/libhv/libhv-1.3.2/CMakeLists.txt b/external/libhv/libhv-1.3.2/CMakeLists.txt index 4a29432..a79d2eb 100644 --- a/external/libhv/libhv-1.3.2/CMakeLists.txt +++ b/external/libhv/libhv-1.3.2/CMakeLists.txt @@ -99,8 +99,8 @@ set(SRCDIR src) set(LIBDIR lib) set(BINDIR bin) # ================== added by xiao ================== # -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBS_OUTPUT_PATH}) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBS_OUTPUT_PATH}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${EXTERNAL_LIBS_OUTPUT_PATH}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${EXTERNAL_LIBS_OUTPUT_PATH}) # ================== added by xiao ================== # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BINDIR}) message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") diff --git a/test/utils/CMakeLists.txt b/test/utils/CMakeLists.txt index d79f2dd..251acc6 100644 --- a/test/utils/CMakeLists.txt +++ b/test/utils/CMakeLists.txt @@ -8,5 +8,4 @@ add_subdirectory(LinuxApiMock) add_subdirectory(McuProtocol) add_subdirectory(FxHttpServer) add_subdirectory(TestManager) - - +add_subdirectory(TcpModule) \ No newline at end of file diff --git a/test/utils/TcpModule/CMakeLists.txt b/test/utils/TcpModule/CMakeLists.txt new file mode 100644 index 0000000..72dce6d --- /dev/null +++ b/test/utils/TcpModule/CMakeLists.txt @@ -0,0 +1,68 @@ +# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake) +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin) + +include_directories( + ./tool/include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + ${UTILS_SOURCE_PATH}/TcpModule/include + ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include +) + +link_directories( + ${LIBS_OUTPUT_PATH} + ${EXTERNAL_LIBS_OUTPUT_PATH} +) + +aux_source_directory(. SRC_FILES) +aux_source_directory(./src SRC_FILES) +if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) + aux_source_directory(./src_mock SRC_FILES) +endif() + +set(TARGET_NAME TcpModuleTest) +add_executable(${TARGET_NAME} ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} TcpModule gtest gmock pthread Log) +if(${TEST_COVERAGE} MATCHES "true") + target_link_libraries(${TARGET_NAME} gcov) +endif() +if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) + target_link_libraries(${TARGET_NAME} LinuxApiMock) +endif() +# if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") +add_custom_target( + TcpModuleTest_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + # --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/gtest.h\"}]' + --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]' + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/utils/TcpModule +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + TcpModuleTest_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/utils/TcpModule +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make TcpModuleTest_code_check + COMMAND make TcpModuleTest_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +# endif() + +define_file_name(${TARGET_NAME}) + +# add_subdirectory(tool) \ No newline at end of file diff --git a/test/utils/TcpModule/mainTest.cpp b/test/utils/TcpModule/mainTest.cpp new file mode 100644 index 0000000..475ceee --- /dev/null +++ b/test/utils/TcpModule/mainTest.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Fancy Code. + * 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 +#include +#include +#include +int main(int argc, char *argv[]) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/test/utils/TcpModule/src/TcpModule_Test.cpp b/test/utils/TcpModule/src/TcpModule_Test.cpp new file mode 100644 index 0000000..a493ca4 --- /dev/null +++ b/test/utils/TcpModule/src/TcpModule_Test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Fancy Code. + * 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 "ILog.h" +#include "TcpModule.h" +#include +#include +namespace TcpModuleTest +{ +// ../output_files/test/bin/TcpModuleTest --gtest_filter=TcpModuleTest.UNIT_TcpModule_AUTO_IllegalObject +/** + * TcpModule module api will not crash when object is illegal. + */ +TEST(TcpModuleTest, UNIT_TcpModule_AUTO_IllegalObject) +{ + CreateLogModule(); + ILogInit(LOG_INSTANCE_TYPE_END); + ILogUnInit(); +} +} // namespace TcpModuleTest \ No newline at end of file diff --git a/test/utils/UartDevice/CMakeLists.txt b/test/utils/UartDevice/CMakeLists.txt index 0527aa0..3d63348 100644 --- a/test/utils/UartDevice/CMakeLists.txt +++ b/test/utils/UartDevice/CMakeLists.txt @@ -17,8 +17,6 @@ link_directories( ${EXTERNAL_LIBS_OUTPUT_PATH} ) - - aux_source_directory(. SRC_FILES) aux_source_directory(./src SRC_FILES) if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) diff --git a/utils/TcpModule/CMakeLists.txt b/utils/TcpModule/CMakeLists.txt index 2b6dd88..732bd8f 100644 --- a/utils/TcpModule/CMakeLists.txt +++ b/utils/TcpModule/CMakeLists.txt @@ -19,7 +19,7 @@ set(TARGET_NAME TcpModule) add_library(${TARGET_NAME} STATIC ${SRC_FILES}) target_link_libraries(${TARGET_NAME} LinuxApi StatusCode Log) -if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") +# if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") add_custom_target( TcpModule_code_check COMMAND ${CLANG_TIDY_EXE} @@ -46,7 +46,7 @@ add_custom_command( COMMAND make TcpModule_code_format WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ ) -endif() +# endif() define_file_name(${TARGET_NAME}) diff --git a/utils/TcpModule/src/TcpClient.cpp b/utils/TcpModule/src/TcpClient.cpp new file mode 100644 index 0000000..f297c00 --- /dev/null +++ b/utils/TcpModule/src/TcpClient.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Fancy Code. + * 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. + */ \ No newline at end of file diff --git a/utils/TcpModule/src/TcpClient.h b/utils/TcpModule/src/TcpClient.h new file mode 100644 index 0000000..f297c00 --- /dev/null +++ b/utils/TcpModule/src/TcpClient.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Fancy Code. + * 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. + */ \ No newline at end of file diff --git a/utils/TcpModule/src/TcpModuleImpl.h b/utils/TcpModule/src/TcpModuleImpl.h index e143026..138441a 100644 --- a/utils/TcpModule/src/TcpModuleImpl.h +++ b/utils/TcpModule/src/TcpModuleImpl.h @@ -18,7 +18,7 @@ #include "TcpModule.h" #include #define TCP_MODULE_INIT_NAME "UART" -typedef struct uart_device_header +typedef struct tcp_module_header { const char *mCheckName; } TcpModuleHeader; diff --git a/utils/TcpModule/src/TcpServer.cpp b/utils/TcpModule/src/TcpServer.cpp new file mode 100644 index 0000000..f297c00 --- /dev/null +++ b/utils/TcpModule/src/TcpServer.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Fancy Code. + * 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. + */ \ No newline at end of file diff --git a/utils/TcpModule/src/TcpServer.h b/utils/TcpModule/src/TcpServer.h new file mode 100644 index 0000000..f297c00 --- /dev/null +++ b/utils/TcpModule/src/TcpServer.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Fancy Code. + * 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. + */ \ No newline at end of file