Skip to content

Commit

Permalink
Adding code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Dec 17, 2023
1 parent c82a361 commit f68828f
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
coverage:
precision: 2
round: down
range: "30...100"

status:
project: no
patch: yes
changes: no

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "header, diff, changes, tree"
behavior: default

ignore:
- "*.h"
- "src/test/**" # ignore test harness code
- "src/den2obj.cpp" # ignore main routine of den2obj
21 changes: 18 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install -y build-essential cmake libglm-dev libtclap-dev libboost-all-dev libopenvdb-dev libtbb-dev libcppunit-dev libeigen3-dev liblzma-dev zlib1g-dev libbz2-dev
run: sudo apt install -y build-essential cmake libglm-dev libtclap-dev libboost-all-dev libopenvdb-dev libtbb-dev libcppunit-dev libeigen3-dev liblzma-dev zlib1g-dev libbz2-dev gcovr
- name: Configure CMake
run: mkdir build && cd build && cmake ../src
run: mkdir build && cd build && cmake ../src -DUSE_GCOV=1
- name: Build
run: cd build && make -j3
run: cd build && make -j
- name: Perform unit tests
run: cd build && make test
- name: Perform code coverage
run: |
cd build
gcovr -r ../ . --xml-pretty -e ".*\.h" > coverage.xml
gcovr -r ../ . --html -e ".*\.h" > report.html
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: ./build/report.html
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./build/coverage.xml
22 changes: 22 additions & 0 deletions .github/workflows/stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: stats

on:
push:
branches: [ "master", "develop" ]
pull_request:
branches: [ "master", "develop" ]

jobs:
build-stats:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install packages
run: sudo apt update && sudo apt install -y cloc
- name: Collect package statistics
run: cloc . --report-file=stats.txt
- name: Store package statistics
uses: actions/upload-artifact@v3
with:
name: stats
path: ./stats.txt
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ src/config.h

# do not save doc build
docs/_build/
docs/userguide/build*
docs/userguide/build*

# VSCODE
.vscode
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/ifilot/den2obj?label=version)
[![C/C++ CI](https://github.com/ifilot/den2obj/actions/workflows/build.yml/badge.svg)](https://github.com/ifilot/den2obj/actions/workflows/build.yml)
[![OpenVDB build CI](https://github.com/ifilot/den2obj/actions/workflows/build-openvdb.yml/badge.svg)](https://github.com/ifilot/den2obj/actions/workflows/build-openvdb.yml)
[![codecov](https://codecov.io/gh/ifilot/bramble/graph/badge.svg?token=25GK2ME5ZV)](https://codecov.io/gh/ifilot/den2obj)
[![Documentation](https://github.com/ifilot/den2obj/actions/workflows/docs.yml/badge.svg)](https://den2obj.imc-tue.nl)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Expand Down
26 changes: 25 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,39 @@
cmake_minimum_required(VERSION 2.8.12)
project (den2obj)

# change compiler directives when code coverage is required
if(USE_GCOV)
set(CMAKE_BUILD_TYPE "Debug")

# Set global c and c++ flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")

# Link flags used for creating executables
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov -fprofile-arcs")

# Link flags used for creating shared libraries
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lgcov -profile-arcs")
endif()

# add custom directory to look for .cmake files
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules )

# store git hash
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# prepare configuration file
SET(PROGNAME "DEN2OBJ")
SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "1")
SET(VERSION_MICRO "0")
configure_file(config.h.in ../src/config.h @ONLY)
message(STATUS "Writing configuration file in: ${CMAKE_CURRENT_SOURCE_DIR}/config.h")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)

# Enable release build
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
Expand Down
2 changes: 2 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
#define VERSION_MINOR @VERSION_MINOR@
#define VERSION_MICRO @VERSION_MICRO@
#define VERSION "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_MICRO@"
#define GIT_HASH "@GIT_HASH@"

static const std::string PROGRAM_NAME(PROGNAME);
static const std::string PROGRAM_VERSION(VERSION);
static const std::string PROGRAM_GIT_HASH(GIT_HASH);
static const unsigned int PROGRAM_VERSION_MAJOR = VERSION_MAJOR;
static const unsigned int PROGRAM_VERSION_MINOR = VERSION_MINOR;
static const unsigned int PROGRAM_VERSION_MICRO = VERSION_MICRO;
Expand Down
3 changes: 3 additions & 0 deletions src/den2obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ int main(int argc, char* argv[]) {
std::cout << "Website: https://den2obj.imc-tue.nl" << std::endl;
std::cout << "Github: https://github.com/ifilot/den2obj" << std::endl;
std::cout << "--------------------------------------------------------------" << std::endl;
std::cout << "Compilation time: " << __DATE__ << " " << __TIME__ << std::endl;
std::cout << "Git Hash: " << PROGRAM_GIT_HASH << std::endl;
std::cout << "--------------------------------------------------------------" << std::endl;

//**************************************
// parsing values
Expand Down
13 changes: 11 additions & 2 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@
add_library(unittest STATIC unittest.cpp)

# set executables
SET(EXECUTABLES TestIsosurface TestScalarField TestD2OFileFormat TestGenerator)
SET(EXECUTABLES TestIsosurface TestScalarField TestD2OFileFormat)

# remove this test from the list as it takes too long
if(NOT USE_GCOV)
list(APPEND EXECUTABLES TestGenerator)
endif()

#######################################################
# Add executables
#######################################################
add_executable(TestIsosurface test_isosurface.cpp)
add_executable(TestScalarField test_scalarfield.cpp)
add_executable(TestD2OFileFormat test_d2o_fileformat.cpp)
add_executable(TestGenerator test_generator.cpp)

# remove this test from the list as it takes too long
if(NOT USE_GCOV)
add_executable(TestGenerator test_generator.cpp)
endif()

#######################################################
# Link mkmsources and other dependencies
Expand Down

0 comments on commit f68828f

Please sign in to comment.