From 8fc252e508a19939385212c0d304253626ed8b98 Mon Sep 17 00:00:00 2001 From: Qiu Fengshuo Date: Thu, 18 Jul 2024 09:42:06 +0800 Subject: [PATCH] speedup CI UT job (#1606) * Split the original UT CI job into two separate jobs: one with SPL and one without SPL * fix: change design. Build .a and .so at the same CI UT job * fix * fix * fix * fix * fix * fix * fix --- .github/workflows/build-core-ut.yaml | 5 +- .github/workflows/build-core.yaml | 18 +-- .github/workflows/build.yaml | 20 +-- .github/workflows/e2e-framework.yaml | 20 +-- .github/workflows/e2e.yaml | 20 +-- core/CMakeLists.txt | 93 +++++++------ core/common/common.cmake | 2 +- core/dependencies.cmake | 12 +- core/flusher/flusher.cmake | 4 +- core/input/input.cmake | 2 +- core/processor/links.cmake | 6 +- core/processor/processor.cmake | 9 +- core/unittest/CMakeLists.txt | 131 +++++++++++------- core/unittest/app_config/CMakeLists.txt | 2 +- core/unittest/batch/CMakeLists.txt | 10 +- core/unittest/checkpoint/CMakeLists.txt | 6 +- core/unittest/common/CMakeLists.txt | 18 +-- core/unittest/compression/CMakeLists.txt | 6 +- core/unittest/config/CMakeLists.txt | 14 +- core/unittest/config_sdk/CMakeLists.txt | 2 +- .../unittest/container_manager/CMakeLists.txt | 2 +- core/unittest/controller/CMakeLists.txt | 2 +- core/unittest/event/CMakeLists.txt | 2 +- core/unittest/event_handler/CMakeLists.txt | 6 +- core/unittest/file_source/CMakeLists.txt | 4 +- core/unittest/flusher/CMakeLists.txt | 2 +- core/unittest/input/CMakeLists.txt | 4 +- core/unittest/log_pb/CMakeLists.txt | 2 +- core/unittest/logger/CMakeLists.txt | 2 +- core/unittest/models/CMakeLists.txt | 16 +-- core/unittest/monitor/CMakeLists.txt | 4 +- core/unittest/observer/CMakeLists.txt | 24 ++-- core/unittest/pipeline/CMakeLists.txt | 8 +- core/unittest/plugin/CMakeLists.txt | 14 +- core/unittest/polling/CMakeLists.txt | 2 +- core/unittest/processor/CMakeLists.txt | 28 ++-- core/unittest/queue/CMakeLists.txt | 8 +- core/unittest/reader/CMakeLists.txt | 16 +-- core/unittest/sdk/CMakeLists.txt | 2 +- core/unittest/sender/CMakeLists.txt | 4 +- core/unittest/serializer/CMakeLists.txt | 2 +- core/unittest/spl/CMakeLists.txt | 4 +- scripts/gen_build_scripts.sh | 3 +- scripts/run_core_ut.sh | 2 + 44 files changed, 292 insertions(+), 271 deletions(-) diff --git a/.github/workflows/build-core-ut.yaml b/.github/workflows/build-core-ut.yaml index 79752063c7..a07999a774 100644 --- a/.github/workflows/build-core-ut.yaml +++ b/.github/workflows/build-core-ut.yaml @@ -74,14 +74,15 @@ jobs: ENABLE_COMPATIBLE_MODE: OFF ENABLE_STATIC_LINK_CRT: ON WITHOUTGDB: ON - MAKE_JOBS: 8 + MAKE_JOBS: 16 + # BUILD_TYPE: Debug # TODO: Uncomment when memory management is refined run: CURRENT_DIR=$(pwd) && sed -i "s|/src|$CURRENT_DIR|g" docker/Dockerfile_build && make core PATH_IN_DOCKER=$(pwd) - name: Unit Test run: make unittest_core - name: Unit Test Coverage - run: docker build -t unittest_coverage -f ./docker/Dockerfile_coverage . && docker run -v $(pwd):$(pwd) unittest_coverage bash -c "cd $(pwd)/core && gcovr --root . --lcov coverage.lcov --txt coverage.txt" + run: docker build -t unittest_coverage -f ./docker/Dockerfile_coverage . && docker run -v $(pwd):$(pwd) unittest_coverage bash -c "cd $(pwd)/core && gcovr --root . --lcov coverage.lcov --txt coverage.txt -e \".*sdk.*\" -e \".*observer.*\" -e \".*log_pb.*\" -e \".*unittest.*\" -e \".*config_server.*\" -e \".*fuse.*\" -e \".*go_pipeline.*\"" - name: Setup Python3.10 uses: actions/setup-python@v5 diff --git a/.github/workflows/build-core.yaml b/.github/workflows/build-core.yaml index f14e6b6c57..8bdc756aa4 100644 --- a/.github/workflows/build-core.yaml +++ b/.github/workflows/build-core.yaml @@ -17,13 +17,13 @@ name: Build Core on: pull_request: paths-ignore: - - 'docs/**' - - 'example_config/**' - - 'docker/**' - - 'k8s_template/**' - - 'changes/**' - - 'licenses/**' - - 'CHANGELOG.md' + - "docs/**" + - "example_config/**" + - "docker/**" + - "k8s_template/**" + - "changes/**" + - "licenses/**" + - "CHANGELOG.md" push: branches: - main @@ -37,7 +37,7 @@ jobs: matrix: go-version: [1.19] # https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on - runner: [ arc-runner-set-ilogtail ] + runner: [arc-runner-set-ilogtail] fail-fast: true steps: - name: prepare ubuntu environment @@ -60,7 +60,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - + - name: Check out code uses: actions/checkout@v4 with: diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 224a18caa7..aad824fe0c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,13 +17,13 @@ name: Build on: pull_request: paths-ignore: - - 'docs/**' - - 'example_config/**' - - 'docker/**' - - 'k8s_template/**' - - 'changes/**' - - 'licenses/**' - - 'CHANGELOG.md' + - "docs/**" + - "example_config/**" + - "docker/**" + - "k8s_template/**" + - "changes/**" + - "licenses/**" + - "CHANGELOG.md" push: branches: - main @@ -37,7 +37,7 @@ jobs: matrix: go-version: [1.19] # https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on - runner: [ arc-runner-set-ilogtail ] + runner: [arc-runner-set-ilogtail] fail-fast: true steps: - name: prepare ubuntu environment @@ -51,7 +51,7 @@ jobs: sudo rm -rf "$AGENT_TOOLSDIRECTORY" sudo -E apt-get -qq autoremove --purge sudo -E apt-get -qq clean - + - name: Check disk space run: | df -hT $PWD @@ -60,7 +60,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - + - name: Check out code uses: actions/checkout@v4 with: diff --git a/.github/workflows/e2e-framework.yaml b/.github/workflows/e2e-framework.yaml index b9bc3f4cb1..281d90577d 100644 --- a/.github/workflows/e2e-framework.yaml +++ b/.github/workflows/e2e-framework.yaml @@ -17,13 +17,13 @@ name: E2E Core Test on: pull_request: paths-ignore: - - 'docs/**' - - 'example_config/**' - - 'docker/**' - - 'k8s_template/**' - - 'changes/**' - - 'licenses/**' - - 'CHANGELOG.md' + - "docs/**" + - "example_config/**" + - "docker/**" + - "k8s_template/**" + - "changes/**" + - "licenses/**" + - "CHANGELOG.md" push: branches: - main @@ -34,8 +34,8 @@ jobs: timeout-minutes: 60 strategy: matrix: - go-version: [ 1.19.10 ] - runner: [ ubuntu-latest ] + go-version: [1.19.10] + runner: [ubuntu-latest] fail-fast: true steps: # Clean up space to prevent action from running out of disk space. @@ -81,7 +81,7 @@ jobs: result: runs-on: ubuntu-latest timeout-minutes: 60 - needs: [ CI ] + needs: [CI] steps: - name: Build Result run: echo "Just to make the GitHub merge button green" diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index d6c09edf81..2c32832950 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -17,13 +17,13 @@ name: E2E Test on: pull_request: paths-ignore: - - 'docs/**' - - 'example_config/**' - - 'docker/**' - - 'k8s_template/**' - - 'changes/**' - - 'licenses/**' - - 'CHANGELOG.md' + - "docs/**" + - "example_config/**" + - "docker/**" + - "k8s_template/**" + - "changes/**" + - "licenses/**" + - "CHANGELOG.md" push: branches: - main @@ -34,8 +34,8 @@ jobs: timeout-minutes: 60 strategy: matrix: - go-version: [ 1.19.10 ] - runner: [ ubuntu-latest ] + go-version: [1.19.10] + runner: [ubuntu-latest] fail-fast: true steps: # Clean up space to prevent action from running out of disk space. @@ -83,7 +83,7 @@ jobs: result: runs-on: ubuntu-latest timeout-minutes: 60 - needs: [ CI ] + needs: [CI] steps: - name: Build Result run: echo "Just to make the GitHub merge button green" diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 6a5d6123a6..b034189144 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -25,14 +25,20 @@ endif () # Options. option(BUILD_LOGTAIL "Build Logtail executable and tools" ON) +# Used under the Android environment. option(BUILD_LOGTAIL_SHARED_LIBRARY "Build Logtail shared library") option(ENABLE_ENTERPRISE "enable enterprise feature") cmake_dependent_option(ENABLE_COMPATIBLE_MODE "Build Logtail in compatible mode (for low version Linux)" OFF "LINUX" OFF) cmake_dependent_option(ENABLE_STATIC_LINK_CRT "Build Logtail by linking CRT statically" OFF "LINUX" OFF) option(WITHOUTGDB "Build Logtail without gdb") -option(WITHOUTSPL "Build Logtail and UT without SPL") +option(WITHSPL "Build Logtail and UT with SPL" ON) option(BUILD_LOGTAIL_UT "Build unit test for Logtail") +if (BUILD_LOGTAIL_SHARED_LIBRARY AND WITHSPL) + message(FATEL_ERROR, "Generating logtail shared library is not supported to be linked with SPL. WITHSPL should be set OFF.") + return() +endif() + if (ENABLE_ENTERPRISE) message(STATUS "Enable Enterprise Feature.") add_definitions(-D__ENTERPRISE__) @@ -41,7 +47,7 @@ else () include(${CMAKE_CURRENT_SOURCE_DIR}/options.cmake) endif () -if (WITHOUTSPL) +if (NOT WITHSPL) add_definitions(-D__EXCLUDE_SPL__) endif() @@ -92,7 +98,8 @@ endif () include(${CMAKE_CURRENT_SOURCE_DIR}/utils.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/dependencies.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/links.cmake) -set(SUBDIR_SOURCE_FILES "") +set(PLUGIN_SOURCE_FILES_CORE "") +set(PLUGIN_SOURCE_FILES_SPL "") include(${CMAKE_CURRENT_SOURCE_DIR}/common/common.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/common/links.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/input/input.cmake) @@ -127,7 +134,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories("/opt/logtail_spl/include") if (LINUX) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/observer) - if (NOT WITHOUTSPL) + if (WITHSPL) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/spl) endif() endif() @@ -138,37 +145,39 @@ endforeach (DIR_NAME) foreach (DIR_NAME ${SUB_DIRECTORIES_LIST}) file(GLOB TEMP_SOURCE_FILES ${DIR_NAME}/*.c ${DIR_NAME}/*.cc ${DIR_NAME}/*.cpp) - list(APPEND SOURCE_FILES_LIST ${TEMP_SOURCE_FILES}) + list(APPEND FRAMEWORK_SOURCE_FILES ${TEMP_SOURCE_FILES}) endforeach (DIR_NAME) if (ENABLE_ENTERPRISE) # remove several files in shennong/sdk - list(REMOVE_ITEM SOURCE_FILES_LIST ${CMAKE_CURRENT_SOURCE_DIR}/shennong/sdk/sample.cpp) + list(REMOVE_ITEM FRAMEWORK_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/shennong/sdk/sample.cpp) endif() # remove several files in go_pipeline -list(REMOVE_ITEM SOURCE_FILES_LIST ${CMAKE_CURRENT_SOURCE_DIR}/go_pipeline/LogtailPluginAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/go_pipeline/LogtailPluginAdapter.h) +list(REMOVE_ITEM FRAMEWORK_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/go_pipeline/LogtailPluginAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/go_pipeline/LogtailPluginAdapter.h) if(MSVC) # remove linux event listener file(GLOB REMOVE_EVENT_LISTENER_SOURCES event_listener/*_Linux.cpp event_listener/*_Linux.h) - list(REMOVE_ITEM SOURCE_FILES_LIST ${REMOVE_EVENT_LISTENER_SOURCES}) - set(WINDOWS_SOURCE_FILES ${SOURCE_FILES_LIST} ${SUBDIR_SOURCE_FILES}) + list(REMOVE_ITEM FRAMEWORK_SOURCE_FILES ${REMOVE_EVENT_LISTENER_SOURCES}) elseif(UNIX) # remove windows event listener file(GLOB REMOVE_EVENT_LISTENER_SOURCES event_listener/*_Windows.cpp event_listener/*_Windows.h) - list(REMOVE_ITEM SOURCE_FILES_LIST ${REMOVE_EVENT_LISTENER_SOURCES}) + list(REMOVE_ITEM FRAMEWORK_SOURCE_FILES ${REMOVE_EVENT_LISTENER_SOURCES}) if (LINUX) # observer file(GLOB_RECURSE APPEND_OBSERVER_SOURCES observer/*) - list(APPEND SOURCE_FILES_LIST ${APPEND_OBSERVER_SOURCES}) + list(APPEND FRAMEWORK_SOURCE_FILES ${APPEND_OBSERVER_SOURCES}) + if (WITHSPL) + set(SRC_FILES ${PLUGIN_SOURCE_FILES_SPL}) + endif() endif() - set(UNIX_SOURCE_FILES ${SOURCE_FILES_LIST} ${SUBDIR_SOURCE_FILES}) endif() +set(SRC_FILES ${SRC_FILES} ${FRAMEWORK_SOURCE_FILES} ${PLUGIN_SOURCE_FILES_CORE}) # Generate SPL library. if (LINUX) - if (NOT WITHOUTSPL) + if (WITHSPL) add_subdirectory(spl) endif() endif() @@ -177,47 +186,35 @@ endif() if (BUILD_LOGTAIL) if (ENABLE_ENTERPRISE) if (UNIX) - add_executable(${LOGTAIL_TARGET} enterprise_logtail.cpp ${UNIX_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} enterprise_logtail.cpp ${SRC_FILES}) elseif (MSVC) - add_executable(${LOGTAIL_TARGET} enterprise_logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} enterprise_logtail_windows.cpp ${SRC_FILES}) endif () else () if (UNIX) - add_executable(${LOGTAIL_TARGET} logtail.cpp ${UNIX_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} logtail.cpp ${SRC_FILES}) elseif (MSVC) - add_executable(${LOGTAIL_TARGET} logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) + add_executable(${LOGTAIL_TARGET} logtail_windows.cpp ${SRC_FILES}) endif () endif() endif() -if (BUILD_LOGTAIL_SHARED_LIBRARY) - if (NOT WITHOUTSPL) - message(ERROR, "generating logtail shared library is not supported with SPL.") - else() - if (ENABLE_ENTERPRISE) - if (UNIX) - add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail.cpp ${UNIX_SOURCE_FILES}) - elseif (MSVC) - add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) - endif () - else () - if (UNIX) - add_library(${LOGTAIL_TARGET} SHARED logtail.cpp ${UNIX_SOURCE_FILES}) - elseif (MSVC) - add_library(${LOGTAIL_TARGET} SHARED logtail_windows.cpp ${WINDOWS_SOURCE_FILES}) - endif () - endif() +if (BUILD_LOGTAIL_SHARED_LIBRARY) + if (ENABLE_ENTERPRISE) + if (UNIX) + add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail.cpp ${SRC_FILES}) + elseif (MSVC) + add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail_windows.cpp ${SRC_FILES}) + endif () + else () + if (UNIX) + add_library(${LOGTAIL_TARGET} SHARED logtail.cpp ${SRC_FILES}) + elseif (MSVC) + add_library(${LOGTAIL_TARGET} SHARED logtail_windows.cpp ${SRC_FILES}) + endif () endif() endif () -# Logtail UT. -if (BUILD_LOGTAIL_UT) - message(STATUS "Build unittest.") - include(CTest) - enable_testing() - add_subdirectory(unittest) -endif () - # Generate independent libraries. # add_subdirectory(helper) add_subdirectory(go_pipeline) @@ -226,8 +223,16 @@ add_subdirectory(common) # Link libraries. if(BUILD_LOGTAIL OR BUILD_LOGTAIL_SHARED_LIBRARY) input_link(${LOGTAIL_TARGET}) - processor_link(${LOGTAIL_TARGET}) + processor_link(${LOGTAIL_TARGET} ${WITHSPL}) flusher_link(${LOGTAIL_TARGET}) all_link(${LOGTAIL_TARGET}) common_link(${LOGTAIL_TARGET}) -endif() \ No newline at end of file +endif() + +# Logtail UT. +if (BUILD_LOGTAIL_UT) + message(STATUS "Build unittest.") + include(CTest) + enable_testing() + add_subdirectory(unittest) +endif () \ No newline at end of file diff --git a/core/common/common.cmake b/core/common/common.cmake index d687938f77..c34a7cc83b 100644 --- a/core/common/common.cmake +++ b/core/common/common.cmake @@ -45,4 +45,4 @@ elseif(UNIX) endif() # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) \ No newline at end of file +set(PLUGIN_SOURCE_FILES_CORE ${PLUGIN_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) diff --git a/core/dependencies.cmake b/core/dependencies.cmake index f0000a171d..40775951e9 100644 --- a/core/dependencies.cmake +++ b/core/dependencies.cmake @@ -242,11 +242,7 @@ macro(link_lz4 target_name) if (lz4_${LINK_OPTION_SUFFIX}) target_link_libraries(${target_name} "${lz4_${LINK_OPTION_SUFFIX}}") elseif (UNIX) - if (WITHOUTSPL OR BUILD_LOGTAIL_SHARED_LIBRARY) - target_link_libraries(${target_name} "${lz4_${LIBRARY_DIR_SUFFIX}}/liblz4.so") - else () - target_link_libraries(${target_name} "${lz4_${LIBRARY_DIR_SUFFIX}}/liblz4.a") - endif () + target_link_libraries(${target_name} "${lz4_${LIBRARY_DIR_SUFFIX}}/liblz4.so") elseif (MSVC) target_link_libraries(${target_name} debug "liblz4_staticd" @@ -310,11 +306,7 @@ macro(link_unwind target_name) elseif (ANDROID) # target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwindstack.a") elseif (UNIX) - if (WITHOUTSPL OR BUILD_LOGTAIL_SHARED_LIBRARY) - target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwind.so") - else () - target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwind.a") - endif () + target_link_libraries(${target_name} "${unwind_${LIBRARY_DIR_SUFFIX}}/libunwind.so") elseif (MSVC) target_link_libraries(${target_name} debug "breakpad_commond.lib" diff --git a/core/flusher/flusher.cmake b/core/flusher/flusher.cmake index af3a2f0c20..2b17ec5c54 100644 --- a/core/flusher/flusher.cmake +++ b/core/flusher/flusher.cmake @@ -17,7 +17,7 @@ include_directories(flusher) # Add source files -file(GLOB THIS_SOURCE_FILES ${CMAKE_SOURCE_DIR}/flusher/*.c ${CMAKE_SOURCE_DIR}/flusher/*.cc ${CMAKE_SOURCE_DIR}/flusher/*.cpp ${CMAKE_SOURCE_DIR}/flusher/*.h) +file(GLOB THIS_SOURCE_FILES_LIST ${CMAKE_SOURCE_DIR}/flusher/*.c ${CMAKE_SOURCE_DIR}/flusher/*.cc ${CMAKE_SOURCE_DIR}/flusher/*.cpp ${CMAKE_SOURCE_DIR}/flusher/*.h) # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES}) \ No newline at end of file +set(PLUGIN_SOURCE_FILES_CORE ${PLUGIN_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) diff --git a/core/input/input.cmake b/core/input/input.cmake index 7727584eab..fb02f053cc 100644 --- a/core/input/input.cmake +++ b/core/input/input.cmake @@ -38,4 +38,4 @@ elseif(UNIX) endif() # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) \ No newline at end of file +set(PLUGIN_SOURCE_FILES_CORE ${PLUGIN_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) diff --git a/core/processor/links.cmake b/core/processor/links.cmake index 18fb6fe535..08c62b3c74 100644 --- a/core/processor/links.cmake +++ b/core/processor/links.cmake @@ -14,12 +14,10 @@ # limitations under the License. # This file is used to link external source files in processor directory -macro(processor_link target_name) +macro(processor_link target_name link_withspl) link_re2(${target_name}) - if (LINUX AND NOT WITHOUTSPL) + if (LINUX AND ${link_withspl}) link_spl(${target_name}) - endif () - if (LINUX AND NOT WITHOUTSPL) target_link_libraries(${target_name} spl) endif () link_ssl(${target_name}) # must after link_spl diff --git a/core/processor/processor.cmake b/core/processor/processor.cmake index a97ec0a09c..3dd62297ef 100644 --- a/core/processor/processor.cmake +++ b/core/processor/processor.cmake @@ -26,10 +26,7 @@ list(APPEND THIS_SOURCE_FILES_LIST ${THIS_SOURCE_FILES}) file(GLOB THIS_SOURCE_FILES ${CMAKE_SOURCE_DIR}/processor/inner/*.c ${CMAKE_SOURCE_DIR}/processor/inner/*.cc ${CMAKE_SOURCE_DIR}/processor/inner/*.cpp ${CMAKE_SOURCE_DIR}/processor/inner/*.h) list(APPEND THIS_SOURCE_FILES_LIST ${THIS_SOURCE_FILES}) -if(NOT LINUX OR WITHOUTSPL) - # remove spl related files in processor - list(REMOVE_ITEM THIS_SOURCE_FILES_LIST ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.cpp ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.h) -endif() - # Set source files to parent -set(SUBDIR_SOURCE_FILES ${SUBDIR_SOURCE_FILES} ${THIS_SOURCE_FILES_LIST}) \ No newline at end of file +list(REMOVE_ITEM THIS_SOURCE_FILES_LIST ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.cpp ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.h) +set(PLUGIN_SOURCE_FILES_CORE ${PLUGIN_SOURCE_FILES_CORE} ${THIS_SOURCE_FILES_LIST}) +set(PLUGIN_SOURCE_FILES_SPL ${PLUGIN_SOURCE_FILES_SPL} ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.cpp ${CMAKE_SOURCE_DIR}/processor/ProcessorSPL.h) diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index f554f8eac7..3c89794544 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -15,66 +15,91 @@ cmake_minimum_required(VERSION 3.22) project(unittest_base) -include(${CMAKE_SOURCE_DIR}/links.cmake) -include(${CMAKE_SOURCE_DIR}/common/links.cmake) -include(${CMAKE_SOURCE_DIR}/processor/links.cmake) -include(${CMAKE_SOURCE_DIR}/input/links.cmake) -include(${CMAKE_SOURCE_DIR}/flusher/links.cmake) - add_definitions(-DAPSARA_UNIT_TEST_MAIN) set(NO_TCMALLOC TRUE) add_definitions(-DLOGTAIL_NO_TC_MALLOC) if (MSVC) add_definitions(-DNOMINMAX) endif () -if (LINUX AND WITHOUTSPL) - add_library(${PROJECT_NAME} SHARED ${UNIX_SOURCE_FILES}) -else () - add_library(${PROJECT_NAME} STATIC ${UNIX_SOURCE_FILES}) -endif() -if(MSVC) - # For MSVC, use /W4 for a high level of warnings, and treat warnings as errors. - # target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) -else() - target_compile_options(${PROJECT_NAME} PRIVATE -Werror) -endif() - -input_link(${PROJECT_NAME}) -processor_link(${PROJECT_NAME}) -flusher_link(${PROJECT_NAME}) -all_link(${PROJECT_NAME}) -common_link(${PROJECT_NAME}) -add_subdirectory(app_config) -add_subdirectory(batch) -add_subdirectory(checkpoint) -add_subdirectory(common) -add_subdirectory(compression) -add_subdirectory(config) -add_subdirectory(config_sdk) -add_subdirectory(container_manager) -add_subdirectory(controller) -add_subdirectory(event) -add_subdirectory(event_handler) -add_subdirectory(file_source) -add_subdirectory(flusher) -add_subdirectory(input) -add_subdirectory(log_pb) -add_subdirectory(models) -add_subdirectory(monitor) -add_subdirectory(pipeline) -add_subdirectory(plugin) -add_subdirectory(polling) -add_subdirectory(processor) -add_subdirectory(queue) -add_subdirectory(reader) -add_subdirectory(sdk) -add_subdirectory(sender) -add_subdirectory(serializer) +macro(add_core_subdir) + add_subdirectory(app_config) + add_subdirectory(batch) + add_subdirectory(checkpoint) + add_subdirectory(common) + add_subdirectory(compression) + add_subdirectory(config) + add_subdirectory(config_sdk) + add_subdirectory(container_manager) + add_subdirectory(controller) + add_subdirectory(event) + add_subdirectory(event_handler) + add_subdirectory(file_source) + add_subdirectory(flusher) + add_subdirectory(input) + add_subdirectory(log_pb) + add_subdirectory(models) + add_subdirectory(monitor) + add_subdirectory(pipeline) + add_subdirectory(plugin) + add_subdirectory(polling) + add_subdirectory(processor) + add_subdirectory(queue) + add_subdirectory(reader) + add_subdirectory(sdk) + add_subdirectory(sender) + add_subdirectory(serializer) + if (LINUX) + add_subdirectory(observer) + endif () +endmacro() -if (LINUX) - if (NOT WITHOUTSPL) +macro(add_spl_subdir) + if (LINUX) add_subdirectory(spl) + endif () +endmacro() + +macro(ut_link ut_link_withspl) + input_link(${UT_BASE_TARGET}) + processor_link(${UT_BASE_TARGET} ${ut_link_withspl}) + flusher_link(${UT_BASE_TARGET}) + all_link(${UT_BASE_TARGET}) + common_link(${UT_BASE_TARGET}) +endmacro() + +set(SOURCE_FILES_CORE ${FRAMEWORK_SOURCE_FILES} ${PLUGIN_SOURCE_FILES_CORE}) +set(SOURCE_FILES_CORE_WITHSPL ${SOURCE_FILES_CORE} ${PLUGIN_SOURCE_FILES_SPL}) + +if (UNIX) + if (LINUX) + if (WITHSPL) + # add spl subdir + set(UT_BASE_TARGET "unittest_base_withspl") + add_library(${UT_BASE_TARGET} STATIC ${SOURCE_FILES_CORE_WITHSPL}) + target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) + add_spl_subdir() + set(UT_LINK_WITHSPL ON) + ut_link(${UT_LINK_WITHSPL}) + endif() + # add core subdir + set(UT_BASE_TARGET "unittest_base") + add_definitions(-D__EXCLUDE_SPL__) + add_library(${UT_BASE_TARGET} SHARED ${SOURCE_FILES_CORE}) + target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) + add_core_subdir() + set(UT_LINK_WITHSPL OFF) + ut_link(${UT_LINK_WITHSPL}) + else () + # add core subdir + set(UT_BASE_TARGET "unittest_base") + add_library(${UT_BASE_TARGET} STATIC ${SOURCE_FILES_CORE}) + target_compile_options(${UT_BASE_TARGET} PRIVATE -Werror) + add_core_subdir() + set(UT_LINK_WITHSPL OFF) + ut_link(${UT_LINK_WITHSPL}) endif () - add_subdirectory(observer) -endif () \ No newline at end of file +elseif (MSVC) + # For MSVC, use /W4 for a high level of warnings, and treat warnings as errors. + # target_compile_options(${UT_BASE_TARGET} PRIVATE /W4 /WX) +endif() diff --git a/core/unittest/app_config/CMakeLists.txt b/core/unittest/app_config/CMakeLists.txt index 1cfdc4e01f..408719baa2 100644 --- a/core/unittest/app_config/CMakeLists.txt +++ b/core/unittest/app_config/CMakeLists.txt @@ -16,4 +16,4 @@ cmake_minimum_required(VERSION 3.22) project(app_config_unittest) # add_executable(app_config_unittest AppConfigUnittest.cpp) -# target_link_libraries(app_config_unittest unittest_base) +# target_link_libraries(app_config_unittest ${UT_BASE_TARGET}) diff --git a/core/unittest/batch/CMakeLists.txt b/core/unittest/batch/CMakeLists.txt index 42d84cc689..aec7ec610d 100644 --- a/core/unittest/batch/CMakeLists.txt +++ b/core/unittest/batch/CMakeLists.txt @@ -16,19 +16,19 @@ cmake_minimum_required(VERSION 3.22) project(batch_unittest) add_executable(flush_strategy_unittest FlushStrategyUnittest.cpp) -target_link_libraries(flush_strategy_unittest unittest_base) +target_link_libraries(flush_strategy_unittest ${UT_BASE_TARGET}) add_executable(batch_status_unittest BatchStatusUnittest.cpp) -target_link_libraries(batch_status_unittest unittest_base) +target_link_libraries(batch_status_unittest ${UT_BASE_TARGET}) add_executable(batch_item_unittest BatchItemUnittest.cpp) -target_link_libraries(batch_item_unittest unittest_base) +target_link_libraries(batch_item_unittest ${UT_BASE_TARGET}) add_executable(batcher_unittest BatcherUnittest.cpp) -target_link_libraries(batcher_unittest unittest_base) +target_link_libraries(batcher_unittest ${UT_BASE_TARGET}) add_executable(timeout_flush_manager_unittest TimeoutFlushManagerUnittest.cpp) -target_link_libraries(timeout_flush_manager_unittest unittest_base) +target_link_libraries(timeout_flush_manager_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(flush_strategy_unittest) diff --git a/core/unittest/checkpoint/CMakeLists.txt b/core/unittest/checkpoint/CMakeLists.txt index b3c5999950..92ee28a890 100644 --- a/core/unittest/checkpoint/CMakeLists.txt +++ b/core/unittest/checkpoint/CMakeLists.txt @@ -16,13 +16,13 @@ cmake_minimum_required(VERSION 3.22) project(checkpoint_unittest) add_executable(checkpoint_manager_unittest CheckpointManagerUnittest.cpp) -target_link_libraries(checkpoint_manager_unittest unittest_base) +target_link_libraries(checkpoint_manager_unittest ${UT_BASE_TARGET}) # add_executable(checkpoint_manager_v2_unittest CheckpointManagerV2Unittest.cpp) -# target_link_libraries(checkpoint_manager_v2_unittest unittest_base) +# target_link_libraries(checkpoint_manager_v2_unittest ${UT_BASE_TARGET}) add_executable(adhoc_checkpoint_manager_unittest AdhocCheckpointManagerUnittest.cpp) -target_link_libraries(adhoc_checkpoint_manager_unittest unittest_base) +target_link_libraries(adhoc_checkpoint_manager_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(checkpoint_manager_unittest) diff --git a/core/unittest/common/CMakeLists.txt b/core/unittest/common/CMakeLists.txt index b6b15a2cb5..14218255c5 100644 --- a/core/unittest/common/CMakeLists.txt +++ b/core/unittest/common/CMakeLists.txt @@ -19,31 +19,31 @@ add_executable(common_simple_utils_unittest SimpleUtilsUnittest.cpp FileSystemUtilUnittest.h DevInodeUnittest.h TimeUtilUnittest.h) -target_link_libraries(common_simple_utils_unittest unittest_base) +target_link_libraries(common_simple_utils_unittest ${UT_BASE_TARGET}) add_executable(common_logfileoperator_unittest LogFileOperatorUnittest.cpp) -target_link_libraries(common_logfileoperator_unittest unittest_base) +target_link_libraries(common_logfileoperator_unittest ${UT_BASE_TARGET}) add_executable(common_sender_queue_unittest SenderQueueUnittest.cpp) -target_link_libraries(common_sender_queue_unittest unittest_base) +target_link_libraries(common_sender_queue_unittest ${UT_BASE_TARGET}) add_executable(common_sliding_window_counter_unittest SlidingWindowCounterUnittest.cpp) -target_link_libraries(common_sliding_window_counter_unittest unittest_base) +target_link_libraries(common_sliding_window_counter_unittest ${UT_BASE_TARGET}) # add_executable(common_string_piece_unittest StringPieceUnittest.cpp) -# target_link_libraries(common_string_piece_unittest unittest_base) +# target_link_libraries(common_string_piece_unittest ${UT_BASE_TARGET}) add_executable(common_string_tools_unittest StringToolsUnittest.cpp) -target_link_libraries(common_string_tools_unittest unittest_base) +target_link_libraries(common_string_tools_unittest ${UT_BASE_TARGET}) add_executable(common_machine_info_util_unittest MachineInfoUtilUnittest.cpp) -target_link_libraries(common_machine_info_util_unittest unittest_base) +target_link_libraries(common_machine_info_util_unittest ${UT_BASE_TARGET}) add_executable(encoding_converter_unittest EncodingConverterUnittest.cpp) -target_link_libraries(encoding_converter_unittest unittest_base) +target_link_libraries(encoding_converter_unittest ${UT_BASE_TARGET}) add_executable(yaml_util_unittest YamlUtilUnittest.cpp) -target_link_libraries(yaml_util_unittest unittest_base) +target_link_libraries(yaml_util_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(common_simple_utils_unittest) diff --git a/core/unittest/compression/CMakeLists.txt b/core/unittest/compression/CMakeLists.txt index f5f9cf4983..442a8db893 100644 --- a/core/unittest/compression/CMakeLists.txt +++ b/core/unittest/compression/CMakeLists.txt @@ -16,13 +16,13 @@ cmake_minimum_required(VERSION 3.22) project(compression_unittest) add_executable(compressor_factory_unittest CompressorFactoryUnittest.cpp) -target_link_libraries(compressor_factory_unittest unittest_base) +target_link_libraries(compressor_factory_unittest ${UT_BASE_TARGET}) add_executable(lz4_compressor_unittest LZ4CompressorUnittest.cpp) -target_link_libraries(lz4_compressor_unittest unittest_base) +target_link_libraries(lz4_compressor_unittest ${UT_BASE_TARGET}) add_executable(zstd_compressor_unittest ZstdCompressorUnittest.cpp) -target_link_libraries(zstd_compressor_unittest unittest_base) +target_link_libraries(zstd_compressor_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(compressor_factory_unittest) diff --git a/core/unittest/config/CMakeLists.txt b/core/unittest/config/CMakeLists.txt index 1b96a944d6..b859d7ab01 100644 --- a/core/unittest/config/CMakeLists.txt +++ b/core/unittest/config/CMakeLists.txt @@ -16,27 +16,27 @@ cmake_minimum_required(VERSION 3.22) project(config_unittest) # add_executable(config_match_unittest ConfigMatchUnittest.cpp) -# target_link_libraries(config_match_unittest unittest_base) +# target_link_libraries(config_match_unittest ${UT_BASE_TARGET}) # add_executable(config_updator_unittest ConfigUpdatorUnittest.cpp) -# target_link_libraries(config_updator_unittest unittest_base) +# target_link_libraries(config_updator_unittest ${UT_BASE_TARGET}) add_executable(config_unittest ConfigUnittest.cpp) -target_link_libraries(config_unittest unittest_base) +target_link_libraries(config_unittest ${UT_BASE_TARGET}) add_executable(config_watcher_unittest ConfigWatcherUnittest.cpp) -target_link_libraries(config_watcher_unittest unittest_base) +target_link_libraries(config_watcher_unittest ${UT_BASE_TARGET}) add_executable(config_update_unittest ConfigUpdateUnittest.cpp) -target_link_libraries(config_update_unittest unittest_base) +target_link_libraries(config_update_unittest ${UT_BASE_TARGET}) if (ENABLE_ENTERPRISE) add_executable(legacy_config_provider_unittest LegacyConfigProviderUnittest.cpp) - target_link_libraries(legacy_config_provider_unittest unittest_base) + target_link_libraries(legacy_config_provider_unittest ${UT_BASE_TARGET}) endif () add_executable(config_feedbackable_unittest ConfigFeedbackableUnittest.cpp) -target_link_libraries(config_feedbackable_unittest unittest_base) +target_link_libraries(config_feedbackable_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(config_unittest) diff --git a/core/unittest/config_sdk/CMakeLists.txt b/core/unittest/config_sdk/CMakeLists.txt index c7e3a72797..c84672886d 100644 --- a/core/unittest/config_sdk/CMakeLists.txt +++ b/core/unittest/config_sdk/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(config_sdk_unittest) add_executable(config_sdk_unittest config_sdk_unittest.cpp) -target_link_libraries(config_sdk_unittest unittest_base) +target_link_libraries(config_sdk_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(config_sdk_unittest) diff --git a/core/unittest/container_manager/CMakeLists.txt b/core/unittest/container_manager/CMakeLists.txt index d593574791..00dfa10352 100644 --- a/core/unittest/container_manager/CMakeLists.txt +++ b/core/unittest/container_manager/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(container_manager_unittest) add_executable(container_discovery_options_unittest ContainerDiscoveryOptionsUnittest.cpp) -target_link_libraries(container_discovery_options_unittest unittest_base) +target_link_libraries(container_discovery_options_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(container_discovery_options_unittest) diff --git a/core/unittest/controller/CMakeLists.txt b/core/unittest/controller/CMakeLists.txt index 0583076baf..6946a5b1b1 100644 --- a/core/unittest/controller/CMakeLists.txt +++ b/core/unittest/controller/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(controller_unittest) add_executable(event_dispatcher_dir_unittest EventDispatcherDirUnittest.cpp) -target_link_libraries(event_dispatcher_dir_unittest unittest_base) +target_link_libraries(event_dispatcher_dir_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(event_dispatcher_dir_unittest) diff --git a/core/unittest/event/CMakeLists.txt b/core/unittest/event/CMakeLists.txt index 3a95e1ecd0..f06131ef08 100644 --- a/core/unittest/event/CMakeLists.txt +++ b/core/unittest/event/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(event_unittest) add_executable(event_unittest EventUnittest.cpp) -target_link_libraries(event_unittest unittest_base) +target_link_libraries(event_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(event_unittest) diff --git a/core/unittest/event_handler/CMakeLists.txt b/core/unittest/event_handler/CMakeLists.txt index 9a539b0199..0e5e929ebe 100644 --- a/core/unittest/event_handler/CMakeLists.txt +++ b/core/unittest/event_handler/CMakeLists.txt @@ -16,13 +16,13 @@ cmake_minimum_required(VERSION 3.22) project(event_handler_unittest) # add_executable(create_modify_handler_unittest CreateModifyHandlerUnittest.cpp) -# target_link_libraries(create_modify_handler_unittest unittest_base) +# target_link_libraries(create_modify_handler_unittest ${UT_BASE_TARGET}) # add_executable(modify_handler_unittest ModifyHandlerUnittest.cpp) -# target_link_libraries(modify_handler_unittest unittest_base) +# target_link_libraries(modify_handler_unittest ${UT_BASE_TARGET}) add_executable(log_input_unittest LogInputUnittest.cpp) -target_link_libraries(log_input_unittest unittest_base) +target_link_libraries(log_input_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(log_input_unittest) diff --git a/core/unittest/file_source/CMakeLists.txt b/core/unittest/file_source/CMakeLists.txt index 6b2337cda0..15983d767f 100644 --- a/core/unittest/file_source/CMakeLists.txt +++ b/core/unittest/file_source/CMakeLists.txt @@ -16,10 +16,10 @@ cmake_minimum_required(VERSION 3.22) project(file_source_unittest) add_executable(file_discovery_options_unittest FileDiscoveryOptionsUnittest.cpp) -target_link_libraries(file_discovery_options_unittest unittest_base) +target_link_libraries(file_discovery_options_unittest ${UT_BASE_TARGET}) add_executable(multiline_options_unittest MultilineOptionsUnittest.cpp) -target_link_libraries(multiline_options_unittest unittest_base) +target_link_libraries(multiline_options_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(file_discovery_options_unittest) diff --git a/core/unittest/flusher/CMakeLists.txt b/core/unittest/flusher/CMakeLists.txt index 8d4d5b5a99..23bd6a9400 100644 --- a/core/unittest/flusher/CMakeLists.txt +++ b/core/unittest/flusher/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(flusher_unittest) add_executable(flusher_sls_unittest FlusherSLSUnittest.cpp) -target_link_libraries(flusher_sls_unittest unittest_base) +target_link_libraries(flusher_sls_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(flusher_sls_unittest) diff --git a/core/unittest/input/CMakeLists.txt b/core/unittest/input/CMakeLists.txt index 0419c47a9c..3e38377147 100644 --- a/core/unittest/input/CMakeLists.txt +++ b/core/unittest/input/CMakeLists.txt @@ -16,10 +16,10 @@ cmake_minimum_required(VERSION 3.22) project(input_unittest) add_executable(input_file_unittest InputFileUnittest.cpp) -target_link_libraries(input_file_unittest unittest_base) +target_link_libraries(input_file_unittest ${UT_BASE_TARGET}) add_executable(input_container_stdio_unittest InputContainerStdioUnittest.cpp) -target_link_libraries(input_container_stdio_unittest unittest_base) +target_link_libraries(input_container_stdio_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(input_file_unittest) diff --git a/core/unittest/log_pb/CMakeLists.txt b/core/unittest/log_pb/CMakeLists.txt index 2a7e5fa5ed..1941bc0a39 100644 --- a/core/unittest/log_pb/CMakeLists.txt +++ b/core/unittest/log_pb/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(log_pb_unittest) add_executable(log_pb_unittest PBUnittest.cpp) -target_link_libraries(log_pb_unittest unittest_base) +target_link_libraries(log_pb_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(log_pb_unittest) diff --git a/core/unittest/logger/CMakeLists.txt b/core/unittest/logger/CMakeLists.txt index 02dc1bf5f9..a5d4fef8d0 100644 --- a/core/unittest/logger/CMakeLists.txt +++ b/core/unittest/logger/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(logger_unittest) add_executable(logger_unittest logger_unittest.cpp) -target_link_libraries(logger_unittest unittest_base) +target_link_libraries(logger_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(logger_unittest) diff --git a/core/unittest/models/CMakeLists.txt b/core/unittest/models/CMakeLists.txt index c0831cd8bc..3face62690 100644 --- a/core/unittest/models/CMakeLists.txt +++ b/core/unittest/models/CMakeLists.txt @@ -16,25 +16,25 @@ cmake_minimum_required(VERSION 3.22) project(models_unittest) add_executable(pipeline_event_unittest PipelineEventUnittest.cpp) -target_link_libraries(pipeline_event_unittest unittest_base) +target_link_libraries(pipeline_event_unittest ${UT_BASE_TARGET}) add_executable(log_event_unittest LogEventUnittest.cpp) -target_link_libraries(log_event_unittest unittest_base) +target_link_libraries(log_event_unittest ${UT_BASE_TARGET}) add_executable(metric_value_unittest MetricValueUnittest.cpp) -target_link_libraries(metric_value_unittest unittest_base) +target_link_libraries(metric_value_unittest ${UT_BASE_TARGET}) add_executable(metric_event_unittest MetricEventUnittest.cpp) -target_link_libraries(metric_event_unittest unittest_base) +target_link_libraries(metric_event_unittest ${UT_BASE_TARGET}) add_executable(span_event_unittest SpanEventUnittest.cpp) -target_link_libraries(span_event_unittest unittest_base) +target_link_libraries(span_event_unittest ${UT_BASE_TARGET}) add_executable(pipeline_event_ptr_unittest PipelineEventPtrUnittest.cpp) -target_link_libraries(pipeline_event_ptr_unittest unittest_base) +target_link_libraries(pipeline_event_ptr_unittest ${UT_BASE_TARGET}) add_executable(pipeline_event_group_unittest PipelineEventGroupUnittest.cpp) -target_link_libraries(pipeline_event_group_unittest unittest_base) +target_link_libraries(pipeline_event_group_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(pipeline_event_unittest) @@ -46,4 +46,4 @@ gtest_discover_tests(pipeline_event_ptr_unittest) gtest_discover_tests(pipeline_event_group_unittest) add_executable(event_group_benchmark EventGroupBenchmark.cpp) -target_link_libraries(event_group_benchmark unittest_base) +target_link_libraries(event_group_benchmark ${UT_BASE_TARGET}) diff --git a/core/unittest/monitor/CMakeLists.txt b/core/unittest/monitor/CMakeLists.txt index e2c7995612..ad875c2263 100644 --- a/core/unittest/monitor/CMakeLists.txt +++ b/core/unittest/monitor/CMakeLists.txt @@ -16,10 +16,10 @@ cmake_minimum_required(VERSION 3.22) project(logtail_metric_unittest) add_executable(logtail_metric_unittest LogtailMetricUnittest.cpp) -target_link_libraries(logtail_metric_unittest unittest_base) +target_link_libraries(logtail_metric_unittest ${UT_BASE_TARGET}) add_executable(profiler_data_integrity_unittest DataIntegrityUnittest.cpp) -target_link_libraries(profiler_data_integrity_unittest unittest_base) +target_link_libraries(profiler_data_integrity_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(logtail_metric_unittest) diff --git a/core/unittest/observer/CMakeLists.txt b/core/unittest/observer/CMakeLists.txt index e1796f97cc..6804a3e4a6 100644 --- a/core/unittest/observer/CMakeLists.txt +++ b/core/unittest/observer/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(observer_unittest) add_executable(observer_config_unittest ObserverConfigUnittest.cpp) -target_link_libraries(observer_config_unittest unittest_base) +target_link_libraries(observer_config_unittest ${UT_BASE_TARGET}) # protocol unittest # add_executable(protocol_dns_unittest ProtocolDnsUnittest.cpp) @@ -25,29 +25,29 @@ target_link_libraries(observer_config_unittest unittest_base) # add_executable(protocol_pgsql_unittest ProtocolPgsqlUnittest.cpp) # add_executable(protocol_mysql_unittest ProtocolMySqlUnittest.cpp) -# target_link_libraries(protocol_dns_unittest unittest_base) -# target_link_libraries(protocol_http_unittest unittest_base) -# target_link_libraries(protocol_redis_unittest unittest_base) -# target_link_libraries(protocol_pgsql_unittest unittest_base) -# target_link_libraries(protocol_mysql_unittest unittest_base) +# target_link_libraries(protocol_dns_unittest ${UT_BASE_TARGET}) +# target_link_libraries(protocol_http_unittest ${UT_BASE_TARGET}) +# target_link_libraries(protocol_redis_unittest ${UT_BASE_TARGET}) +# target_link_libraries(protocol_pgsql_unittest ${UT_BASE_TARGET}) +# target_link_libraries(protocol_mysql_unittest ${UT_BASE_TARGET}) # cgoutp meta unittest # add_executable(cgroup_meta_unittest CGoupMetaUnittest.cpp) -# target_link_libraries(cgroup_meta_unittest unittest_base) +# target_link_libraries(cgroup_meta_unittest ${UT_BASE_TARGET}) add_executable(netlink_meta_unittest NetLinkUnittest.cpp) -target_link_libraries(netlink_meta_unittest unittest_base) +target_link_libraries(netlink_meta_unittest ${UT_BASE_TARGET}) add_executable(hostname_meta_unittest HostnameMetaUnittest.cpp) -target_link_libraries(hostname_meta_unittest unittest_base) +target_link_libraries(hostname_meta_unittest ${UT_BASE_TARGET}) # framework unittest add_executable(network_observer_unittest NetworkObserverUnittest.cpp) add_executable(protocol_util_unittest ProtocolUtilUnittest.cpp) add_executable(protocol_infer_unittest ProtocolInferUnittest.cpp) -target_link_libraries(network_observer_unittest unittest_base) -target_link_libraries(protocol_util_unittest unittest_base) -target_link_libraries(protocol_infer_unittest unittest_base) +target_link_libraries(network_observer_unittest ${UT_BASE_TARGET}) +target_link_libraries(protocol_util_unittest ${UT_BASE_TARGET}) +target_link_libraries(protocol_infer_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(observer_config_unittest) diff --git a/core/unittest/pipeline/CMakeLists.txt b/core/unittest/pipeline/CMakeLists.txt index 43304a1900..1a6a61cb3d 100644 --- a/core/unittest/pipeline/CMakeLists.txt +++ b/core/unittest/pipeline/CMakeLists.txt @@ -16,16 +16,16 @@ cmake_minimum_required(VERSION 3.22) project(pipeline_unittest) add_executable(global_config_unittest GlobalConfigUnittest.cpp) -target_link_libraries(global_config_unittest unittest_base) +target_link_libraries(global_config_unittest ${UT_BASE_TARGET}) add_executable(pipeline_unittest PipelineUnittest.cpp) -target_link_libraries(pipeline_unittest unittest_base) +target_link_libraries(pipeline_unittest ${UT_BASE_TARGET}) add_executable(pipeline_manager_unittest PipelineManagerUnittest.cpp) -target_link_libraries(pipeline_manager_unittest unittest_base) +target_link_libraries(pipeline_manager_unittest ${UT_BASE_TARGET}) add_executable(process_config_manager_unittest ProcessConfigManagerUnittest.cpp) -target_link_libraries(process_config_manager_unittest unittest_base) +target_link_libraries(process_config_manager_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(global_config_unittest) diff --git a/core/unittest/plugin/CMakeLists.txt b/core/unittest/plugin/CMakeLists.txt index 73a207c23f..b579277496 100644 --- a/core/unittest/plugin/CMakeLists.txt +++ b/core/unittest/plugin/CMakeLists.txt @@ -16,25 +16,25 @@ cmake_minimum_required(VERSION 3.22) project(plugin_unittest) add_executable(static_input_creator_unittest StaticInputCreatorUnittest.cpp) -target_link_libraries(static_input_creator_unittest unittest_base) +target_link_libraries(static_input_creator_unittest ${UT_BASE_TARGET}) add_executable(static_processor_creator_unittest StaticProcessorCreatorUnittest.cpp) -target_link_libraries(static_processor_creator_unittest unittest_base) +target_link_libraries(static_processor_creator_unittest ${UT_BASE_TARGET}) add_executable(static_flusher_creator_unittest StaticFlusherCreatorUnittest.cpp) -target_link_libraries(static_flusher_creator_unittest unittest_base) +target_link_libraries(static_flusher_creator_unittest ${UT_BASE_TARGET}) add_executable(input_instance_unittest InputInstanceUnittest.cpp) -target_link_libraries(input_instance_unittest unittest_base) +target_link_libraries(input_instance_unittest ${UT_BASE_TARGET}) add_executable(processor_instance_unittest ProcessorInstanceUnittest.cpp) -target_link_libraries(processor_instance_unittest unittest_base) +target_link_libraries(processor_instance_unittest ${UT_BASE_TARGET}) add_executable(flusher_instance_unittest FlusherInstanceUnittest.cpp) -target_link_libraries(flusher_instance_unittest unittest_base) +target_link_libraries(flusher_instance_unittest ${UT_BASE_TARGET}) add_executable(plugin_registry_unittest PluginRegistryUnittest.cpp) -target_link_libraries(plugin_registry_unittest unittest_base) +target_link_libraries(plugin_registry_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(static_input_creator_unittest) diff --git a/core/unittest/polling/CMakeLists.txt b/core/unittest/polling/CMakeLists.txt index 20b8197bd9..82b1b54a17 100644 --- a/core/unittest/polling/CMakeLists.txt +++ b/core/unittest/polling/CMakeLists.txt @@ -16,4 +16,4 @@ cmake_minimum_required(VERSION 3.22) project(polling_unittest) # add_executable(polling_unittest PollingUnittest.cpp) -# target_link_libraries(polling_unittest unittest_base) \ No newline at end of file +# target_link_libraries(polling_unittest ${UT_BASE_TARGET}) \ No newline at end of file diff --git a/core/unittest/processor/CMakeLists.txt b/core/unittest/processor/CMakeLists.txt index b970a70d70..dde242abb2 100644 --- a/core/unittest/processor/CMakeLists.txt +++ b/core/unittest/processor/CMakeLists.txt @@ -16,46 +16,46 @@ cmake_minimum_required(VERSION 3.22) project(processor_unittest) add_executable(processor_split_log_string_native_unittest ProcessorSplitLogStringNativeUnittest.cpp) -target_link_libraries(processor_split_log_string_native_unittest unittest_base) +target_link_libraries(processor_split_log_string_native_unittest ${UT_BASE_TARGET}) add_executable(processor_split_multiline_log_string_native_unittest ProcessorSplitMultilineLogStringNativeUnittest.cpp) -target_link_libraries(processor_split_multiline_log_string_native_unittest unittest_base) +target_link_libraries(processor_split_multiline_log_string_native_unittest ${UT_BASE_TARGET}) add_executable(processor_parse_regex_native_unittest ProcessorParseRegexNativeUnittest.cpp) -target_link_libraries(processor_parse_regex_native_unittest unittest_base) +target_link_libraries(processor_parse_regex_native_unittest ${UT_BASE_TARGET}) add_executable(processor_parse_json_native_unittest ProcessorParseJsonNativeUnittest.cpp) -target_link_libraries(processor_parse_json_native_unittest unittest_base) +target_link_libraries(processor_parse_json_native_unittest ${UT_BASE_TARGET}) add_executable(processor_parse_timestamp_native_unittest ProcessorParseTimestampNativeUnittest.cpp) -target_link_libraries(processor_parse_timestamp_native_unittest unittest_base) +target_link_libraries(processor_parse_timestamp_native_unittest ${UT_BASE_TARGET}) add_executable(processor_tag_native_unittest ProcessorTagNativeUnittest.cpp) -target_link_libraries(processor_tag_native_unittest unittest_base) +target_link_libraries(processor_tag_native_unittest ${UT_BASE_TARGET}) add_executable(processor_parse_apsara_native_unittest ProcessorParseApsaraNativeUnittest.cpp) -target_link_libraries(processor_parse_apsara_native_unittest unittest_base) +target_link_libraries(processor_parse_apsara_native_unittest ${UT_BASE_TARGET}) add_executable(processor_parse_delimiter_native_unittest ProcessorParseDelimiterNativeUnittest.cpp) -target_link_libraries(processor_parse_delimiter_native_unittest unittest_base) +target_link_libraries(processor_parse_delimiter_native_unittest ${UT_BASE_TARGET}) add_executable(processor_filter_native_unittest ProcessorFilterNativeUnittest.cpp) -target_link_libraries(processor_filter_native_unittest unittest_base) +target_link_libraries(processor_filter_native_unittest ${UT_BASE_TARGET}) add_executable(processor_desensitize_native_unittest ProcessorDesensitizeNativeUnittest.cpp) -target_link_libraries(processor_desensitize_native_unittest unittest_base) +target_link_libraries(processor_desensitize_native_unittest ${UT_BASE_TARGET}) add_executable(processor_merge_multiline_log_native_unittest ProcessorMergeMultilineLogNativeUnittest.cpp) -target_link_libraries(processor_merge_multiline_log_native_unittest unittest_base) +target_link_libraries(processor_merge_multiline_log_native_unittest ${UT_BASE_TARGET}) add_executable(processor_parse_container_log_native_unittest ProcessorParseContainerLogNativeUnittest.cpp) -target_link_libraries(processor_parse_container_log_native_unittest unittest_base) +target_link_libraries(processor_parse_container_log_native_unittest ${UT_BASE_TARGET}) add_executable(parse_container_log_benchmark ParseContainerLogBenchmark.cpp) -target_link_libraries(parse_container_log_benchmark unittest_base) +target_link_libraries(parse_container_log_benchmark ${UT_BASE_TARGET}) add_executable(boost_regex_benchmark BoostRegexBenchmark.cpp) -target_link_libraries(boost_regex_benchmark unittest_base) +target_link_libraries(boost_regex_benchmark ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(processor_split_log_string_native_unittest) diff --git a/core/unittest/queue/CMakeLists.txt b/core/unittest/queue/CMakeLists.txt index 6b26e6fbc6..b9544727b0 100644 --- a/core/unittest/queue/CMakeLists.txt +++ b/core/unittest/queue/CMakeLists.txt @@ -16,16 +16,16 @@ cmake_minimum_required(VERSION 3.22) project(queue_unittest) add_executable(queue_key_manager_unittest QueueKeyManagerUnittest.cpp) -target_link_libraries(queue_key_manager_unittest unittest_base) +target_link_libraries(queue_key_manager_unittest ${UT_BASE_TARGET}) add_executable(process_queue_unittest ProcessQueueUnittest.cpp) -target_link_libraries(process_queue_unittest unittest_base) +target_link_libraries(process_queue_unittest ${UT_BASE_TARGET}) add_executable(process_queue_manager_unittest ProcessQueueManagerUnittest.cpp) -target_link_libraries(process_queue_manager_unittest unittest_base) +target_link_libraries(process_queue_manager_unittest ${UT_BASE_TARGET}) add_executable(exactly_once_queue_manager_unittest ExactlyOnceQueueManagerUnittest.cpp) -target_link_libraries(exactly_once_queue_manager_unittest unittest_base) +target_link_libraries(exactly_once_queue_manager_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(queue_key_manager_unittest) diff --git a/core/unittest/reader/CMakeLists.txt b/core/unittest/reader/CMakeLists.txt index f1a8d9f46d..f870f9adfd 100644 --- a/core/unittest/reader/CMakeLists.txt +++ b/core/unittest/reader/CMakeLists.txt @@ -16,28 +16,28 @@ cmake_minimum_required(VERSION 3.22) project(log_file_reader_unittest) add_executable(log_file_reader_deleted_file_unittest DeletedFileUnittest.cpp) -target_link_libraries(log_file_reader_deleted_file_unittest unittest_base) +target_link_libraries(log_file_reader_deleted_file_unittest ${UT_BASE_TARGET}) add_executable(file_reader_options_unittest FileReaderOptionsUnittest.cpp) -target_link_libraries(file_reader_options_unittest unittest_base) +target_link_libraries(file_reader_options_unittest ${UT_BASE_TARGET}) add_executable(json_log_file_reader_unittest JsonLogFileReaderUnittest.cpp) -target_link_libraries(json_log_file_reader_unittest unittest_base) +target_link_libraries(json_log_file_reader_unittest ${UT_BASE_TARGET}) add_executable(remove_last_incomplete_log_unittest RemoveLastIncompleteLogUnittest.cpp) -target_link_libraries(remove_last_incomplete_log_unittest unittest_base) +target_link_libraries(remove_last_incomplete_log_unittest ${UT_BASE_TARGET}) add_executable(log_file_reader_unittest LogFileReaderUnittest.cpp) -target_link_libraries(log_file_reader_unittest unittest_base) +target_link_libraries(log_file_reader_unittest ${UT_BASE_TARGET}) add_executable(source_buffer_unittest SourceBufferUnittest.cpp) -target_link_libraries(source_buffer_unittest unittest_base) +target_link_libraries(source_buffer_unittest ${UT_BASE_TARGET}) add_executable(get_last_line_data_unittest GetLastLineDataUnittest.cpp) -target_link_libraries(get_last_line_data_unittest unittest_base) +target_link_libraries(get_last_line_data_unittest ${UT_BASE_TARGET}) add_executable(force_read_unittest ForceReadUnittest.cpp) -target_link_libraries(force_read_unittest unittest_base) +target_link_libraries(force_read_unittest ${UT_BASE_TARGET}) if (UNIX) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testDataSet) diff --git a/core/unittest/sdk/CMakeLists.txt b/core/unittest/sdk/CMakeLists.txt index 7c50e40f0e..f052c1a847 100644 --- a/core/unittest/sdk/CMakeLists.txt +++ b/core/unittest/sdk/CMakeLists.txt @@ -16,4 +16,4 @@ cmake_minimum_required(VERSION 3.22) project(sdk_unittest) # add_executable(sdk_common_unittest SDKCommonUnittest.cpp) -# target_link_libraries(sdk_common_unittest unittest_base) +# target_link_libraries(sdk_common_unittest ${UT_BASE_TARGET}) diff --git a/core/unittest/sender/CMakeLists.txt b/core/unittest/sender/CMakeLists.txt index 344c2f5e04..49f3eb0482 100644 --- a/core/unittest/sender/CMakeLists.txt +++ b/core/unittest/sender/CMakeLists.txt @@ -16,10 +16,10 @@ cmake_minimum_required(VERSION 3.22) project(sender_unittest) add_executable(pack_id_manager_unittest PackIdManagerUnittest.cpp) -target_link_libraries(pack_id_manager_unittest unittest_base) +target_link_libraries(pack_id_manager_unittest ${UT_BASE_TARGET}) # add_executable(sender_unittest SenderUnittest.cpp) -# target_link_libraries(sender_unittest unittest_base) +# target_link_libraries(sender_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(pack_id_manager_unittest) diff --git a/core/unittest/serializer/CMakeLists.txt b/core/unittest/serializer/CMakeLists.txt index 27cb3ad8ac..11c1436ee5 100644 --- a/core/unittest/serializer/CMakeLists.txt +++ b/core/unittest/serializer/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.22) project(serializer_unittest) add_executable(sls_serializer_unittest SLSSerializerUnittest.cpp) -target_link_libraries(sls_serializer_unittest unittest_base) +target_link_libraries(sls_serializer_unittest ${UT_BASE_TARGET}) include(GoogleTest) gtest_discover_tests(sls_serializer_unittest) diff --git a/core/unittest/spl/CMakeLists.txt b/core/unittest/spl/CMakeLists.txt index 886b8e62e7..c8c06addc9 100644 --- a/core/unittest/spl/CMakeLists.txt +++ b/core/unittest/spl/CMakeLists.txt @@ -18,6 +18,6 @@ project(spl_unittest) add_executable(spl_unittest SplUnittest.cpp) add_executable(spl_benchmark_test SplBenchmark.cpp) -target_link_libraries(spl_unittest unittest_base) +target_link_libraries(spl_unittest ${UT_BASE_TARGET}) -target_link_libraries(spl_benchmark_test unittest_base) +target_link_libraries(spl_benchmark_test ${UT_BASE_TARGET}) diff --git a/scripts/gen_build_scripts.sh b/scripts/gen_build_scripts.sh index 3346657d49..8110737838 100755 --- a/scripts/gen_build_scripts.sh +++ b/scripts/gen_build_scripts.sh @@ -39,6 +39,7 @@ BUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT:-OFF} ENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE:-OFF} ENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT:-OFF} WITHOUTGDB==${WITHOUTGDB:-OFF} +WITHSPL=${WITHSPL:-ON} BUILD_SCRIPT_FILE=$GENERATED_HOME/gen_build.sh COPY_SCRIPT_FILE=$GENERATED_HOME/gen_copy_docker.sh MAKE_JOBS=${MAKE_JOBS:-$(nproc)} @@ -83,7 +84,7 @@ EOF if [ $CATEGORY = "plugin" ]; then echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} .. && cd plugin && make -s PluginAdapter && cd ../../.. && ./scripts/upgrade_adapter_lib.sh && ./scripts/plugin_build.sh mod c-shared ${OUT_DIR} ${VERSION} ${PLUGINS_CONFIG_FILE} ${GO_MOD_FILE}" >>$BUILD_SCRIPT_FILE elif [ $CATEGORY = "core" ]; then - echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} -DBUILD_LOGTAIL=${BUILD_LOGTAIL} -DBUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT} -DENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE} -DENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT} -DWITHOUTGDB=${WITHOUTGDB} .. && make -sj${MAKE_JOBS}" >>$BUILD_SCRIPT_FILE + echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} -DBUILD_LOGTAIL=${BUILD_LOGTAIL} -DBUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT} -DENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE} -DENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT} -DWITHOUTGDB=${WITHOUTGDB} -DWITHSPL=${WITHSPL} .. && make -sj${MAKE_JOBS}" >>$BUILD_SCRIPT_FILE elif [ $CATEGORY = "all" ]; then echo "mkdir -p core/build && cd core/build && cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DLOGTAIL_VERSION=${VERSION} -DBUILD_LOGTAIL_UT=${BUILD_LOGTAIL_UT} -DENABLE_COMPATIBLE_MODE=${ENABLE_COMPATIBLE_MODE} -DENABLE_STATIC_LINK_CRT=${ENABLE_STATIC_LINK_CRT} -DWITHOUTGDB=${WITHOUTGDB} .. && make -sj\$nproc && cd - && ./scripts/upgrade_adapter_lib.sh && ./scripts/plugin_build.sh mod c-shared ${OUT_DIR} ${VERSION} ${PLUGINS_CONFIG_FILE} ${GO_MOD_FILE}" >>$BUILD_SCRIPT_FILE elif [ $CATEGORY = "e2e" ]; then diff --git a/scripts/run_core_ut.sh b/scripts/run_core_ut.sh index 848292d263..c611f79b13 100755 --- a/scripts/run_core_ut.sh +++ b/scripts/run_core_ut.sh @@ -35,5 +35,7 @@ search_files() { } # Maybe some unittest depend on relative paths, so execute in the unittest directory +UT_BASE_PATH="$(pwd)/${TARGET_ARTIFACT_PATH:2}" +export LD_LIBRARY_PATH=${UT_BASE_PATH}:$LD_LIBRARY_PATH cd $TARGET_ARTIFACT_PATH search_files .