Skip to content

Commit

Permalink
Merge pull request #825 from greenbone/add-coverage
Browse files Browse the repository at this point in the history
Add: Coverage CMake targets and Codecov upload
  • Loading branch information
a-h-abdelsalam authored Jul 1, 2024
2 parents eb74c3a + 4317b6a commit 59833c9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci-c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,32 @@ jobs:
runs-on: 'ubuntu-latest'
container: greenbone/gvm-libs:edge
steps:
- name: Install git for Codecov uploader
run: |
apt update
apt install --no-install-recommends -y ca-certificates git
rm -rf /var/lib/apt/lists/*
- uses: actions/checkout@v4
- name: Set git safe.directory
run: git config --global --add safe.directory '*'
- run: sh .github/install-dependencies.sh
- name: Configure and Compile gvm-libs
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=1 ..
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=1 -DENABLE_COVERAGE=1 ..
make install
- name: Test gvm-libs
run: |
cd build
make tests
CTEST_OUTPUT_ON_FAILURE=1 make test
- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: build/coverage/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests

scan-build:
name: Scan-build gvm-libs with clang
Expand Down
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,16 @@ message ("-- Using redis socket ${REDIS_SOCKET_PATH}")
message ("-- Install prefix: ${CMAKE_INSTALL_PREFIX}")

if (ENABLE_COVERAGE)
set (COVERAGE_FLAGS "--coverage")
set (COVERAGE_FLAGS "--coverage -ftest-coverage -fprofile-arcs")
set (COVERAGE_DIR "${CMAKE_BINARY_DIR}/coverage")
file (MAKE_DIRECTORY ${COVERAGE_DIR})
message ("-- Code Coverage enabled")
endif (ENABLE_COVERAGE)

set (HARDENING_FLAGS "-Wformat -Wformat-security -D_FORTIFY_SOURCE=2 -fstack-protector")
set (LINKER_HARDENING_FLAGS "-Wl,-z,relro -Wl,-z,now")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${HARDENING_FLAGS}")
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${HARDENING_FLAGS} ${COVERAGE_FLAGS}")

set (
CMAKE_C_FLAGS
Expand Down Expand Up @@ -232,6 +235,22 @@ if (BUILD_TESTS AND NOT SKIP_SRC)

endif (BUILD_TESTS AND NOT SKIP_SRC)

# Code coverage

if (ENABLE_COVERAGE)
add_custom_target (coverage-html
COMMAND gcovr --html-details ${COVERAGE_DIR}/coverage.html
-r ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
add_custom_target (coverage-xml
COMMAND gcovr --xml ${COVERAGE_DIR}/coverage.xml
-r ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
add_custom_target (coverage DEPENDS coverage-xml coverage-html)
endif (ENABLE_COVERAGE)

add_custom_target (clean-coverage
COMMAND find . -name *.gcda -delete -or -name *.gcno -delete
COMMAND rm -f ${COVERAGE_DIR}/*)

## Program

if (NOT SKIP_SRC)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# gvm-libs

[![GitHub releases](https://img.shields.io/github/release/greenbone/gvm-libs.svg)](https://github.com/greenbone/gvm-libs/releases)
[![Code Documentation Coverage](https://img.shields.io/codecov/c/github/greenbone/gvm-libs.svg?label=Documentation%20Coverage&logo=codecov)](https://codecov.io/gh/greenbone/gvm-libs)
[![Build and test C](https://github.com/greenbone/gvm-libs/actions/workflows/ci-c.yml/badge.svg)](https://github.com/greenbone/gvm-libs/actions/workflows/ci-c.yml)

This is the libraries module for the Greenbone Community Edition.
Expand Down

0 comments on commit 59833c9

Please sign in to comment.