From 838e2066a64d72784f2e17f4a8226c491de5d2e9 Mon Sep 17 00:00:00 2001 From: Aleksey Loginov <32845901+victimsnino@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:03:06 +0300 Subject: [PATCH 1/7] Test --- .github/workflows/CodeCov.yml | 62 +++++++++++++++++++++++++++++++++++ CMakeLists.txt | 27 +++++++++------ src/tests/CMakeLists.txt | 2 +- 3 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/CodeCov.yml diff --git a/.github/workflows/CodeCov.yml b/.github/workflows/CodeCov.yml new file mode 100644 index 000000000..696bfe908 --- /dev/null +++ b/.github/workflows/CodeCov.yml @@ -0,0 +1,62 @@ +name: Build Status + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Debug + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + token: ${{ secrets.TOKEN }} + + - name: Update apt-get + run: sudo apt-get update + + # LCOV + - name: Install lcov + run: sudo apt-get install lcov + + # CODECOV + - name: Install codecov + shell: bash + run: sudo pip install codecov + + - name: Setup cache + uses: mikehardy/buildcache-action@v1 + if: matrix.config.os != 'windows-latest' + with: + cache_key: codecov + + - name: Configure CMake + env: + CC: gcc + CXX: g++ + run: cmake -B ${{github.workspace}}/build -DAUTOTESTS=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=buildcache -DCMAKE_CXX_COMPILER_LAUNCHER=buildcache + + - name: Build + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 4 + + # CODE COVERAGE + - name: Code coverage - Capture coverage info + working-directory: ${{runner.workspace}} + run: lcov --directory . --capture --output-file coverage.info + - name: Code coverage - Filter out system, external, and unit test source files + working-directory: ${{runner.workspace}} + run: lcov --remove coverage.info '/Library/*' '/usr/*' "${HOME}"'/.cache/*' '*/tests/*' '*/submodules/*' --output-file coverage.info + - name: Code coverage - Output coverage data for debugging + working-directory: ${{runner.workspace}} + run: lcov --list coverage.info + - name: Code coverage - Upload to CodeCov + working-directory: ${{runner.workspace}} + run: bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports" \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b5d9a9af2..beb4c5e64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,16 +38,23 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(TEST_RESULTS_DIR ${CMAKE_BINARY_DIR}/test_results) set(BUILD_TESTS ON CACHE BOOL "Enable unit tests building" FORCE) -# if (AUTOTESTS AND MSVC) -# # PDB debug information is not supported by buildcache. -# # Store debug info in the object files. -# string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") -# string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") -# string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") -# string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") -# string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") -# string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") -# endif() +# Code Coverage Configuration +add_library(coverage_config INTERFACE) + +option(CODE_COVERAGE "Enable coverage reporting" OFF) +if(CODE_COVERAGE) + # Add required flags (GCC & LLVM/Clang) + target_compile_options(coverage_config INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags + ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(coverage_config INTERFACE --coverage) + else() + target_link_libraries(coverage_config INTERFACE --coverage) + endif() +endif(CODE_COVERAGE) # ================== TESTS ================== diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 7636854b4..1001f8297 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -37,7 +37,7 @@ add_executable(${TARGET} copy_count_tracker.h ) -target_link_libraries(${TARGET} PRIVATE rpp Catch2WithMain) +target_link_libraries(${TARGET} PRIVATE rpp Catch2WithMain coverage_config) set_target_properties(${TARGET} PROPERTIES FOLDER Tests) From 52103259b73de514a4b37db3c81aa369a84f290f Mon Sep 17 00:00:00 2001 From: Aleksey Loginov <32845901+victimsnino@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:05:00 +0300 Subject: [PATCH 2/7] fix --- .github/workflows/CodeCov.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CodeCov.yml b/.github/workflows/CodeCov.yml index 696bfe908..08ee6e0bd 100644 --- a/.github/workflows/CodeCov.yml +++ b/.github/workflows/CodeCov.yml @@ -1,4 +1,4 @@ -name: Build Status +name: CodeCoverage Report on: push: @@ -11,7 +11,7 @@ env: BUILD_TYPE: Debug jobs: - build: + build_and_generate_report: runs-on: ubuntu-latest steps: @@ -40,8 +40,8 @@ jobs: - name: Configure CMake env: - CC: gcc - CXX: g++ + CC: gcc-10 + CXX: g++-10 run: cmake -B ${{github.workspace}}/build -DAUTOTESTS=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=buildcache -DCMAKE_CXX_COMPILER_LAUNCHER=buildcache - name: Build From 15b33758a9c3a2c63f1b9bbfac1e7d3688d2b6cb Mon Sep 17 00:00:00 2001 From: Aleksey Loginov <32845901+victimsnino@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:07:46 +0300 Subject: [PATCH 3/7] add test --- .github/workflows/CodeCov.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/CodeCov.yml b/.github/workflows/CodeCov.yml index 08ee6e0bd..f3c7be307 100644 --- a/.github/workflows/CodeCov.yml +++ b/.github/workflows/CodeCov.yml @@ -47,6 +47,10 @@ jobs: - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 4 + - name: Test + working-directory: ${{github.workspace}}/build + run: ctest -C ${{env.BUILD_TYPE}} + # CODE COVERAGE - name: Code coverage - Capture coverage info working-directory: ${{runner.workspace}} From 16adf2d2ce40fd6eccec257e451c211edc6b8f2d Mon Sep 17 00:00:00 2001 From: Aleksey Loginov <32845901+victimsnino@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:10:38 +0300 Subject: [PATCH 4/7] define.. --- .github/workflows/CodeCov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CodeCov.yml b/.github/workflows/CodeCov.yml index f3c7be307..72aaa4dc5 100644 --- a/.github/workflows/CodeCov.yml +++ b/.github/workflows/CodeCov.yml @@ -42,7 +42,7 @@ jobs: env: CC: gcc-10 CXX: g++-10 - run: cmake -B ${{github.workspace}}/build -DAUTOTESTS=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=buildcache -DCMAKE_CXX_COMPILER_LAUNCHER=buildcache + run: cmake -B ${{github.workspace}}/build -DAUTOTESTS=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=buildcache -DCMAKE_CXX_COMPILER_LAUNCHER=buildcache -DCODE_COVERAGE=1 - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 4 From 287229eeea480020c457dc433189f2c6ac59a365 Mon Sep 17 00:00:00 2001 From: Aleksey Loginov <32845901+victimsnino@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:14:49 +0300 Subject: [PATCH 5/7] fix checkout issue --- .github/workflows/CodeCov.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CodeCov.yml b/.github/workflows/CodeCov.yml index 72aaa4dc5..322cb739c 100644 --- a/.github/workflows/CodeCov.yml +++ b/.github/workflows/CodeCov.yml @@ -15,10 +15,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true token: ${{ secrets.TOKEN }} + fetch-depth: 0 - name: Update apt-get run: sudo apt-get update From 686319b4829fcfeaf44dda099658d56600679c41 Mon Sep 17 00:00:00 2001 From: Aleksey Loginov <32845901+victimsnino@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:18:06 +0300 Subject: [PATCH 6/7] temp --- .github/workflows/CodeCov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CodeCov.yml b/.github/workflows/CodeCov.yml index 322cb739c..49d75c4d4 100644 --- a/.github/workflows/CodeCov.yml +++ b/.github/workflows/CodeCov.yml @@ -58,7 +58,7 @@ jobs: run: lcov --directory . --capture --output-file coverage.info - name: Code coverage - Filter out system, external, and unit test source files working-directory: ${{runner.workspace}} - run: lcov --remove coverage.info '/Library/*' '/usr/*' "${HOME}"'/.cache/*' '*/tests/*' '*/submodules/*' --output-file coverage.info + run: lcov --remove coverage.info '/Library/*' '/usr/*' "${HOME}"'/.cache/*' '*/submodules/*' --output-file coverage.info - name: Code coverage - Output coverage data for debugging working-directory: ${{runner.workspace}} run: lcov --list coverage.info From 24748a6aa7719a470fb6f03e26094a3403581910 Mon Sep 17 00:00:00 2001 From: Aleksey Loginov <32845901+victimsnino@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:27:16 +0300 Subject: [PATCH 7/7] try to fix --- .github/workflows/CodeCov.yml | 4 ++-- src/include/CMakeLists.txt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CodeCov.yml b/.github/workflows/CodeCov.yml index 49d75c4d4..1ad663f08 100644 --- a/.github/workflows/CodeCov.yml +++ b/.github/workflows/CodeCov.yml @@ -55,10 +55,10 @@ jobs: # CODE COVERAGE - name: Code coverage - Capture coverage info working-directory: ${{runner.workspace}} - run: lcov --directory . --capture --output-file coverage.info + run: lcov --directory ${{github.workspace}} --capture --output-file coverage.info - name: Code coverage - Filter out system, external, and unit test source files working-directory: ${{runner.workspace}} - run: lcov --remove coverage.info '/Library/*' '/usr/*' "${HOME}"'/.cache/*' '*/submodules/*' --output-file coverage.info + run: lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' '*/tests/*' '*/submodules/*' --output-file coverage.info - name: Code coverage - Output coverage data for debugging working-directory: ${{runner.workspace}} run: lcov --list coverage.info diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index 3d203ee28..6da6bfab1 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -26,6 +26,7 @@ file(GLOB_RECURSE FILES "*.h") add_library(rpp INTERFACE ${FILES}) target_sources(rpp INTERFACE ${FILES}) target_include_directories(rpp INTERFACE .) +target_link_libraries(rpp INTERFACE coverage_config) foreach(FILE ${FILES}) get_filename_component(PARENT_DIR "${FILE}" PATH)