Skip to content

Commit

Permalink
Add gcovr (#17)
Browse files Browse the repository at this point in the history
* Add support for covr

* add gcovr action

* add gcovr in docker and remove duplication
  • Loading branch information
QuangHaiNguyen authored Mar 17, 2024
1 parent 4830abb commit 6015139
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 47 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/github_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: lukka/get-cmake@latest
- uses: threeal/gcovr-action@latest

- name: Configure CMake
working-directory: ${{github.workspace}}
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake --preset=linux_debug
run: cmake --preset=linux_test_debug

- name: Build
# Build your program with the given configuration
run: cmake --build --preset=linux_debug
run: cmake --build --preset=linux_test_debug

- name: Test
working-directory: ${{github.workspace}}
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest preset=github_ci --test-dir build/linux_debug/
run: ctest preset=linux_test_debug --test-dir build_linux_test_debug//

- name: Coverage
working-directory: ${{github.workspace}}
run: gcovr -r . --filter=easy_embedded
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.vscode/
.vs/
build/
build_*/
tools/StateMachineGenerator/*.c
tools/StateMachineGenerator/*.h
tools/template_generator/*.c
tools/template_generator/*.h
tools/template_generator/CMakeLists.txt
doxygen/
tools/template_generator/__pycache__/
Testing/
Testing/
coverage/
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ endif()

add_custom_target(doxygen
COMMAND doxygen Doxyfile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

add_custom_target(coverage
COMMAND cd ${CMAKE_SOURCE_DIR} && cmake --build --preset=linux_coverage
COMMAND cd ${CMAKE_SOURCE_DIR} && ctest --preset=github_ci
COMMAND cd ${CMAKE_SOURCE_DIR} && rm -rf coverage && mkdir coverage
COMMAND cd ${CMAKE_SOURCE_DIR} && gcovr -r . --filter=easy_embedded --html --html-details -o coverage/coverage.html)
29 changes: 22 additions & 7 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "linux_base",
"displayName": "Linux base configuration",
"description": "Base configuration using ninja generator on linux",
"generator": "Ninja",
"generator": "Unix Makefiles",
"hidden": true,
"condition": {
"type": "equals",
Expand All @@ -23,23 +23,34 @@
},
{
"name": "linux_debug",
"displayName": "Linux debug configuration",
"displayName": "linux_debug",
"description": "Debug configuration using ninja generator on linux",
"inherits": "linux_base",
"binaryDir": "${sourceDir}/build/linux_debug",
"binaryDir": "${sourceDir}/build_linux_debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "linux_release",
"displayName": "Linux release configuration",
"displayName": "linux_release",
"description": "Release configuration using ninja generator on linux",
"inherits": "linux_base",
"binaryDir": "${sourceDir}/build/linux_release",
"binaryDir": "${sourceDir}/build_linux_release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux_test_debug",
"displayName": "linux_test_debug",
"description": "Build, run unit test and measure coverage",
"inherits": "linux_base",
"binaryDir": "${sourceDir}/build_linux_test_debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_C_FLAGS":"-fprofile-arcs -ftest-coverage -fPIC"
}
}
],
"buildPresets": [
Expand All @@ -50,12 +61,16 @@
{
"name": "linux_release",
"configurePreset": "linux_release"
},
{
"name": "linux_test_debug",
"configurePreset": "linux_test_debug"
}
],
"testPresets": [
{
"name": "github_ci",
"configurePreset": "linux_debug",
"name": "linux_test_debug",
"configurePreset": "linux_test_debug",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": true}
}
Expand Down
34 changes: 3 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
.PHONY: help \
docker_build_image \
docker_run_bash \
docker_build_clean \
docker_build \
docker_run_tests
docker_run_bash

docker_build_image:
docker build . --tag toolchains

docker_run_bash:
docker run --mount src=".",target=/home/framework,type=bind -it --rm toolchains

docker_build_clean:
docker run \
--mount src=".",target=/home/framework,type=bind \
--rm toolchains \
rm -rf build; \
mkdir build; \
cmake -S . -B build; \
cmake --build build

docker_build:
docker run \
--mount src=".",target=/home/framework,type=bind \
--rm toolchains \
cmake -S . -B build; \
cmake --build build

docker_run_tests:
docker run \
--mount src=".",target=/home/framework,type=bind \
--rm toolchains \
./build/tests/ez_unit_test
help:
$(info lists of targets:)
$(info lists of commands:)
$(info docker_build_image: build docker image based on the dockerfile)
$(info docker_run_bash: run container in interactive mode)
$(info docker_build_clean: Clean build of the software)
$(info docker_build: build the software, provided that the build folder is available)
$(info docker_run_tests: run available unit test)
$(info help: print this message)
$(info docker_run_bash: run container in interactive mode)
5 changes: 2 additions & 3 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ RUN apt-get update -y && apt-get upgrade -y
# build tool
RUN apt-get install build-essential cmake --no-install-recommends -y
RUN apt-get install make -y
RUN apt-get install ninja-build doxygen graphviz -y
RUN apt-get install doxygen graphviz -y
RUN apt-get install --no-install-recommends curl -y
RUN apt-get install python3 python3-pip -y
RUN apt-get install git -y
RUN apt-get install doxygen -y
RUN apt-get install graphviz -y
RUN apt-get install gcovr -y

WORKDIR /home/framework

0 comments on commit 6015139

Please sign in to comment.