From 6015139264a216fd33cb998dd2b1218b963fcfbb Mon Sep 17 00:00:00 2001 From: Hai Nguyen Date: Sun, 17 Mar 2024 16:24:37 +0100 Subject: [PATCH] Add gcovr (#17) * Add support for covr * add gcovr action * add gcovr in docker and remove duplication --- .github/workflows/github_ci.yaml | 11 ++++++++--- .gitignore | 5 +++-- CMakeLists.txt | 8 +++++++- CMakePresets.json | 29 ++++++++++++++++++++------- Makefile | 34 +++----------------------------- dockerfile | 5 ++--- 6 files changed, 45 insertions(+), 47 deletions(-) diff --git a/.github/workflows/github_ci.yaml b/.github/workflows/github_ci.yaml index 00c971e..f36d93b 100644 --- a/.github/workflows/github_ci.yaml +++ b/.github/workflows/github_ci.yaml @@ -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/ \ No newline at end of file + run: ctest preset=linux_test_debug --test-dir build_linux_test_debug// + + - name: Coverage + working-directory: ${{github.workspace}} + run: gcovr -r . --filter=easy_embedded \ No newline at end of file diff --git a/.gitignore b/.gitignore index a0548a8..378aca0 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .vscode/ .vs/ -build/ +build_*/ tools/StateMachineGenerator/*.c tools/StateMachineGenerator/*.h tools/template_generator/*.c @@ -8,4 +8,5 @@ tools/template_generator/*.h tools/template_generator/CMakeLists.txt doxygen/ tools/template_generator/__pycache__/ -Testing/ \ No newline at end of file +Testing/ +coverage/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 09bee83..90619ad 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,4 +20,10 @@ endif() add_custom_target(doxygen COMMAND doxygen Doxyfile - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) \ No newline at end of file + 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) \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 877b080..e67ca8c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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", @@ -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": [ @@ -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} } diff --git a/Makefile b/Makefile index 8a3ed51..8ee4320 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,6 @@ .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 @@ -11,32 +8,7 @@ docker_build_image: 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) \ No newline at end of file + $(info docker_run_bash: run container in interactive mode) \ No newline at end of file diff --git a/dockerfile b/dockerfile index 80c4d57..e05845b 100755 --- a/dockerfile +++ b/dockerfile @@ -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 \ No newline at end of file