From 1afde961eb1dba09b1951d4ce928013a86b725f5 Mon Sep 17 00:00:00 2001 From: ehds Date: Fri, 12 Apr 2024 11:48:22 +0800 Subject: [PATCH] fix --- .github/workflows/build.yml | 27 +++++++++++++++++++++++++-- src/CMakeLists.txt | 5 +++++ test/CMakeLists.txt | 23 +++++++++++++++++------ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5466bdc..bc5e26f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,7 +49,7 @@ jobs: sudo apt-get update sudo apt-get install -qq libgflags-dev \ libprotobuf-dev libprotoc-dev protobuf-compiler \ - libleveldb-dev libgoogle-perftools-dev + libleveldb-dev libgoogle-perftools-dev lcov sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo env "PATH=$PATH" cmake . && sudo make && sudo mv ./lib/libgtest* /usr/lib/ - name: Install bazel if: ${{ matrix.build_tool == 'bazel' }} @@ -65,17 +65,40 @@ jobs: cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DWITH_TESTS=ON cmake --build bld --parallel 16 -- brpc-static cmake --build "${{ env.CMAKE_BUILD_DIR }}" --parallel 16 + - name: Build with bazel if: ${{ matrix.build_tool == 'bazel' }} run: | ~/.bazel/bin/bazel build -c opt --copt -DHAVE_ZLIB=1 //... + - name: Run Tests if: ${{ matrix.with_test }} id: test-braft working-directory: ${{ github.workspace }}/bld/test run: | ulimit -c unlimited -S - sh ../../test/run_tests.sh + # sh ../../test/run_tests.sh + ./test_ballot + + - name: Coverage + if: ${{ matrix.with_test && matrix.compiler == 'clang' }} + working-directory: ${{ github.workspace }} + run: | + # generate coverage report + lcov --capture --directory . --output-file coverage.info --ignore-errors inconsistent --no-external + # only keep braft/src files + lcov --extract coverage.info 'braft/src/*' --output-file coverage.info --ignore-errors inconsistent + # report + lcov --list coverage.info --ignore-errors inconsistent + - uses: actions/checkout@master + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true # optional (default = false) + files: ./coverage.info # optional + name: codecov-umbrella # optional + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) + - name: Collect failure info if: ${{ steps.test-braft.conclusion == 'failure'}} run: | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 59c8498..1d64338 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,11 @@ include_directories(${CMAKE_SOURCE_DIR}/src) add_library(OBJ_LIB OBJECT ${SOURCES}) set_property(TARGET ${OBJ_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1) + +if(WITH_TESTS AND WITH_COVERAGE) + target_compile_options(OBJ_LIB PRIVATE -fprofile-instr-generate -fcoverage-mapping --coverage) +endif() + add_library(braft-shared SHARED $) add_library(braft-static STATIC $) target_link_libraries(braft-shared ${DYNAMIC_LIB}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4c5e67f..cc4571f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,26 +8,37 @@ include_directories(${CMAKE_SOURCE_DIR}/test) set(CMAKE_CPP_FLAGS "-DGFLAGS_NS=${GFLAGS_NS}") set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -D__const__=__unused__ -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -g -Dprivate=public -Dprotected=public -D__STRICT_ANSI__ -include sstream_workaround.h") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -Wno-unused-result") -use_cxx11() + +if (WITH_COVERAGE) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -coverage") +endif() # bthread_* functions are used in logging.cc, and they need to be marked as # weak symbols explicitly in Darwin system. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(DYNAMIC_LIB ${DYNAMIC_LIB} - "-Wl,-U,_bthread_getspecific" - "-Wl,-U,_bthread_setspecific" - "-Wl,-U,_bthread_key_create") + pthread + "-framework CoreFoundation" + "-framework CoreGraphics" + "-framework CoreData" + "-framework CoreText" + "-framework Security" + "-framework Foundation" + "-Wl,-U,_MallocExtension_ReleaseFreeMemory" + "-Wl,-U,_ProfilerStart" + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() file(GLOB TEST_BRAFT_SRCS "test_*.cpp") foreach(BRAFT_UT ${TEST_BRAFT_SRCS}) get_filename_component(BRAFT_UT_WE ${BRAFT_UT} NAME_WE) - add_executable(${BRAFT_UT_WE} ${BRAFT_UT} - $) + add_executable(${BRAFT_UT_WE} ${BRAFT_UT}) target_link_libraries(${BRAFT_UT_WE} ${GTEST_MAIN_LIB} ${GTEST_LIB} ${GPERFTOOLS_LIBRARY} ${DYNAMIC_LIB} + $ ) endforeach()