Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Coverage CMake targets and Codecov upload #2237

Merged
merged 4 commits into from
Jul 1, 2024
Merged
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
13 changes: 13 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,24 @@ jobs:
runs-on: ubuntu-latest
container: ${{ vars.IMAGE_REGISTRY }}/greenbone/gvmd-build:stable
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/*
- name: Check out gvmd
uses: actions/checkout@v4
- name: Set git safe.directory
run: git config --global --add safe.directory '*'
- name: Build gvmd
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=1
cmake --build build
- name: Configure and run tests
run: CTEST_OUTPUT_ON_FAILURE=1 cmake --build build -- tests test
- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: build/coverage/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
2 changes: 2 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
steps:
- name: Run the c lang coverage action
uses: greenbone/actions/doc-coverage-clang@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

build-gmp-doc:
name: Build GMP documentation
Expand Down
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,22 @@ configure_file (tools/greenbone-scapdata-sync.in tools/greenbone-scapdata-sync @
configure_file (tools/greenbone-certdata-sync.in tools/greenbone-certdata-sync @ONLY)
configure_file (tools/gvm-manage-certs.in tools/gvm-manage-certs @ONLY)

## Code coverage

OPTION (ENABLE_COVERAGE "Enable support for coverage analysis" OFF)
if (ENABLE_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)

## Testing

enable_testing ()

## Program

if (ENABLE_COVERAGE)
set (COVERAGE_FLAGS "--coverage")
endif (ENABLE_COVERAGE)

if (DEBUG_FUNCTION_NAMES)
# The excluded functions are for update_nvti_cache, which fills the log
# quickly. Hopefully this internal NVTi cache is removed soon.
Expand All @@ -280,7 +286,7 @@ set (HARDENING_FLAGS "-Wformat -Wformat-security -D_FORTIFY_SOURCE=2
set (LINKER_HARDENING_FLAGS "-Wl,-z,relro -Wl,-z,now")

# To find unused functions, add: -flto -fwhole-program -ffunction-sections -Wl,--gc-sections -Wl,--print-gc-sections
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -D_BSD_SOURCE -D_ISOC99_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE -D_FILE_OFFSET_BITS=64 -DOPENVASD=${OPENVASD}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -D_BSD_SOURCE -D_ISOC99_SOURCE -D_SVID_SOURCE -D_DEFAULT_SOURCE -D_FILE_OFFSET_BITS=64 -DOPENVASD=${OPENVASD} ${COVERAGE_FLAGS}")

set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror -Wshadow ${COVERAGE_FLAGS} ${DEBUG_FUNCTION_NAMES_FLAGS}")
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${HARDENING_FLAGS} ${COVERAGE_FLAGS}")
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 @@
# Greenbone Vulnerability Manager

[![GitHub releases](https://img.shields.io/github/release/greenbone/gvmd.svg)](https://github.com/greenbone/gvmd/releases)
[![Code Documentation Coverage](https://img.shields.io/codecov/c/github/greenbone/gvmd.svg?label=Documentation%20Coverage&logo=codecov)](https://codecov.io/gh/greenbone/gvmd)
[![Build and Test](https://github.com/greenbone/gvmd/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/greenbone/gvmd/actions/workflows/build-and-test.yml)
[![Docker Pulls](https://img.shields.io/docker/pulls/greenbone/gvmd.svg)](https://hub.docker.com/r/greenbone/gvmd/)
[![Docker Image Size](https://img.shields.io/docker/image-size/greenbone/gvmd.svg?maxAge=2592000)](https://hub.docker.com/r/greenbone/gvmd/)
Expand Down
15 changes: 15 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,21 @@ add_custom_target (tests
DEPENDS
gmp-tickets-test manage-test manage-sql-test manage-utils-test utils-test)

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}/*)


add_executable (gvmd
main.c gvmd.c
debug_utils.c
Expand Down
Loading