Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[cmake,ci] Add support for llvm coverage.
  • Loading branch information
Axel-Naumann committed Aug 21, 2023
commit fb7bdfee426bffafc972ae5cb2e651ce2b63dbfb
22 changes: 16 additions & 6 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ jobs:
options: '--security-opt label=disable --rm'
env:
OS_APPLICATION_CREDENTIAL_ID: '7f5b64a265244623a3a933308569bdba'
# Handle up to 256 profiles being generated concurrently and merged
LLVM_PROFILE_FILE: 'llvm_profile_out_%256m.profraw'
PYTHONUNBUFFERED: true

steps:
- name: Install cov packages
- name: Install clang and coverage packages
run: |
sudo dnf -y update
sudo dnf -y install lcov
sudo dnf -y install clang llvm
pip3 install gcovr

- name: Checkout
Expand All @@ -86,7 +88,11 @@ jobs:

- name: Apply option override from matrix for this job
env:
OVERRIDE: "coverage=On"
OVERRIDE: |
coverage=On
CMAKE_CXX_COMPILER=clang++
CMAKE_C_COMPILER=clang
CMAKE_BUILD_TYPE=Release
FILE: .github/workflows/root-ci-config/buildconfig/fedora38.txt
shell: bash
run: |
Expand Down Expand Up @@ -133,13 +139,17 @@ jobs:
--repository ${{ github.server_url }}/${{ github.repository }}
"

- name: Merge raw coverage reports
run: |
find . -name '*.profraw' > input-profraw.txt
llvm-profdata merge -sparse --input-files=input-profraw.txt --output=merged.profdata
llvm-cov export -format=lcov -instr-profile merged.profdata
ls -ltr
- name: Upload coverage to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v3
with:
env_vars: OS,PYTHON
fail_ci_if_error: true
files: /github/home/ROOT-CI/build/cobertura-cov.xml
flags: unittests
name: codecov-umbrella
files: /github/home/ROOT-CI/build/merged.profdata.lcov
verbose: true
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,20 @@ endif()

#---Enable test coverage -----------------------------------------------------------------------
if(coverage)
set(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
set(GCC_COVERAGE_LINK_FLAGS "-fprofile-arcs")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHAREDLINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# GCC
set(COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
set(COVERAGE_LINK_FLAGS "-fprofile-arcs")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(COVERAGE_COMPILE_FLAGS "-fprofile-instr-generate -fcoverage-mapping")
set(COVERAGE_LINK_FLAGS "-fprofile-instr-generate")
else()
message(FATAL_ERROR "Coverage currently only supported for GCC and clang!")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COVERAGE_LINK_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHAREDLINKER_FLAGS} ${COVERAGE_LINK_FLAGS}")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} ${COVERAGE_COMPILE_FLAGS}")
endif()

#--- Enable build timing -----------------------------------------------------------------------
Expand Down