diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4c9ea0406a0..eda772c4048 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -39,7 +39,7 @@ jobs: run: mkdir -p build - name: CMake with gcc if: matrix.compiler == 'gcc' - run: cd build && cmake .. + run: cd build && cmake -DENABLE_COVERAGE=ON .. - name: CMake with clang if: matrix.compiler == 'clang' run: cd build && cmake -DCMAKE_CXX_COMPILER=clang++-8 -DCMAKE_C_COMPILER=clang-8 -DENABLE_ASAN=on -DNEBULA_CLANG_USE_GCC_TOOLCHAIN=/opt/vesoft/toolset/gcc/7.5.0 .. @@ -48,3 +48,12 @@ jobs: - name: CTest with single thread timeout-minutes: 40 run: cd build && ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ASAN_OPTIONS=fast_unwind_on_malloc=0 ctest --timeout 300 --output-on-failure + - name: Coverage Report + if: success() && matrix.compiler == 'gcc' && matrix.tag == 'centos7' + run: cd build && lcov --gcov-tool $GCOV --capture --directory . --output-file coverage.info + - name: Coveralls + if: success() && matrix.compiler == 'gcc' && matrix.tag == 'centos7' + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: build/coverage.info diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index d363b02d3e9..3bb8b488db1 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -55,7 +55,7 @@ jobs: [ -d build/ ] && rm -rf build/* || mkdir -p build - name: CMake with gcc if: matrix.compiler == 'gcc' && steps.ignore_docs.outputs.num_source_files != 0 - run: cd build && cmake .. + run: cd build && cmake -DENABLE_COVERAGE=ON .. - name: CMake with clang if: matrix.compiler == 'clang' && steps.ignore_docs.outputs.num_source_files != 0 run: cd build && cmake -DCMAKE_CXX_COMPILER=clang++-8 -DCMAKE_C_COMPILER=clang-8 -DENABLE_ASAN=on -DNEBULA_CLANG_USE_GCC_TOOLCHAIN=/opt/vesoft/toolset/gcc/7.5.0 .. @@ -70,6 +70,19 @@ jobs: if: failure() && steps.ignore_docs.outputs.num_source_files != 0 timeout-minutes: 30 run: cd build && ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ASAN_OPTIONS=fast_unwind_on_malloc=0 ctest --timeout 300 --output-on-failure --rerun-failed + - name: Coverage Report + if: success() && matrix.compiler == 'gcc' && matrix.tag == 'centos7' + run: | + cd build && lcov --gcov-tool $GCOV --capture --directory . --output-file coverage.info + stat coverage.info + - name: Coveralls + if: success() && matrix.compiler == 'gcc' && matrix.tag == 'centos7' + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: build/coverage.info + env: + NODE_OPTIONS: --max-old-space-size=20480 - name: Cleanup if: always() run: rm -rf build diff --git a/CMakeLists.txt b/CMakeLists.txt index 66a4fbf7f09..af93d7a7fdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ option(ENABLE_NATIVE "Whether to build native client" OFF) option(ENABLE_CCACHE "Whether to use ccache to speed up compiling" ON) option(ENABLE_ASAN "Whether to turn AddressSanitizer ON or OFF" OFF) option(ENABLE_TESTING "Whether to turn unit test ON or OFF" ON) +option(ENABLE_COVERAGE "Enable testing coverage reporting" OFF) option(ENABLE_UBSAN "Whether to turn Undefined Behavior Sanitizer ON or OFF" OFF) option(ENABLE_FUZZ_TEST "Whether to turn Fuzz Test ON or OFF" OFF) option(ENABLE_WERROR "Whether to error on warnings" ON) @@ -66,6 +67,13 @@ if (!CMAKE_CXX_COMPILER) message(FATAL_ERROR "No C++ compiler found") endif() +if(ENABLE_TESTING AND ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + # Add required flags (GCC & LLVM/Clang) + add_compile_options( + --coverage # sets all required flags + ) +endif() + set(CMAKE_CXX_STANDARD 14) # specify the C++ standard set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -453,6 +461,12 @@ else() set(GETTIME_LIB) endif() +if (ENABLE_TESTING AND ENABLE_COVERAGE) + set(COVERAGE --coverage) +else() + set(COVERAGE) +endif() + # A wrapper for target_link_libraries() macro(nebula_link_libraries target) target_link_libraries( @@ -477,6 +491,7 @@ macro(nebula_link_libraries target) dl ${GETTIME_LIB} -pthread + ${COVERAGE} ) endmacro(nebula_link_libraries) diff --git a/src/common/stats/StatsManager.cpp b/src/common/stats/StatsManager.cpp index 3361a02cfbd..46165c39de7 100644 --- a/src/common/stats/StatsManager.cpp +++ b/src/common/stats/StatsManager.cpp @@ -129,7 +129,7 @@ StatusOr StatsManager::readValue(folly::StringPiece metricName } TimeRange range; - if ( parts[2] == "5") { + if (parts[2] == "5") { range = TimeRange::FIVE_SECONDS; } else if (parts[2] == "60") { range = TimeRange::ONE_MINUTE; diff --git a/src/storage/BaseProcessor.inl b/src/storage/BaseProcessor.inl index 2ab517b5e3e..5e415474623 100644 --- a/src/storage/BaseProcessor.inl +++ b/src/storage/BaseProcessor.inl @@ -125,7 +125,7 @@ BaseProcessor::collectIndexValues(RowReader* reader, } return values; } - + template void BaseProcessor::collectProps(RowReader* reader, @@ -161,7 +161,7 @@ void BaseProcessor::collectProps(RowReader* reader, } } } - + } // namespace storage } // namespace nebula