diff --git a/.github/workflows/cmake-ctest.yml b/.github/workflows/cmake-ctest.yml index df877654a..c1f469f62 100644 --- a/.github/workflows/cmake-ctest.yml +++ b/.github/workflows/cmake-ctest.yml @@ -7,16 +7,12 @@ on: branches: [ "master" ] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release - WITH_DLT_UNIT_TESTS: ON + WITH_DLT_COVERAGE: ON BUILD_GMOCK: OFF jobs: build: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. - # You can convert this to a matrix build if you need cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix runs-on: ubuntu-latest steps: @@ -24,24 +20,44 @@ jobs: - name: Prepare submodule run: | - git submodule init + git submodule init git submodule update - name: Configure CMake - # 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 -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ - -DWITH_DLT_UNIT_TESTS=${{env.WITH_DLT_UNIT_TESTS}} \ + -DWITH_DLT_COVERAGE=${{env.WITH_DLT_COVERAGE}} \ -DBUILD_GMOCK=${{env.BUILD_GMOCK}} - name: Build - # Build your program with the given configuration run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - name: Test working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} + + - name: Install dependencies + run: sudo apt-get install lcov + + - name: Generate lcov report + working-directory: ${{github.workspace}} + run: bash util/dlt_coverage_report/lcov_report_generator.sh build -xe + + - name: Archive coverage results + uses: actions/upload-artifact@v3 + with: + name: dlt_coverage_report + path: ${{github.workspace}}/dlt_lcov_report + + - name: Upload lcov report + if: github.ref == 'refs/heads/master' + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git checkout -b dlt_coverage_report + git submodule deinit -f googletest + rm -rf .git/modules/googletest + git rm -f googletest + git add --all + git commit -m "Upload lcov report for dlt-daemon" + git push -f origin dlt_coverage_report diff --git a/.gitignore b/.gitignore index e9e8645c2..0da830a7c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ include/dlt/dlt_user.h *.out *.swp cmake-build-debug/ -.vscode/ \ No newline at end of file +.vscode/ +googletest/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 74d0e6e07..014fc3bb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,7 @@ option(WITH_DLT_SYSTEM "Set to ON to build src/system binaries" option(WITH_DLT_DBUS "Set to ON to build src/dbus binaries" OFF) option(WITH_DLT_TESTS "Set to ON to build src/test binaries" ON) option(WITH_DLT_UNIT_TESTS "Set to ON to build gtest framework and tests/binaries" OFF) +option(WITH_DLT_COVERAGE "Set to ON to generate coverage report for dlt-daemon source code" OFF) option(WITH_DLT_QNX_SYSTEM "Set to ON to build QNX system binary dlt-qnx-system" OFF) option(WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK "Set to ON to enable fallback to syslog if dlt logging to file fails" OFF) option(WITH_DLT_NETWORK_TRACE "Set to ON to enable network trace (if message queue is supported)" ON) @@ -186,11 +187,11 @@ if(WITH_DLT_QNX_SYSTEM AND NOT "${CMAKE_C_COMPILER}" MATCHES "nto-qnx|qcc|ntoaar message(FATAL_ERROR "Can only compile for QNX with a QNX compiler, but found '${CMAKE_C_COMPILER}'.") endif() -if (WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK) +if(WITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK) add_definitions(-DWITH_DLT_FILE_LOGGING_SYSLOG_FALLBACK) endif() -if (WITH_DLT_LOGSTORAGE_GZIP) +if(WITH_DLT_LOGSTORAGE_GZIP) add_definitions(-DDLT_LOGSTORAGE_USE_GZIP) endif() @@ -198,6 +199,18 @@ if(WITH_GPROF) add_compile_options(-pg) endif() +if(WITH_DLT_COVERAGE) + add_definitions(-DWITH_DLT_COVERAGE) + set(WITH_DLT_UNIT_TESTS ON) + if(WITH_DLT_UNIT_TESTS) + add_definitions(-DDLT_UNIT_TESTS) + endif() + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") +endif() + add_compile_options( $<$:-std=gnu99> $<$:-std=gnu++11> @@ -214,7 +227,7 @@ else() set(PACKAGE_DOC "") endif() -if (BUILD_SHARED_LIBS) +if(BUILD_SHARED_LIBS) set(CMAKE_STATIC_LIB_PATH "") else() set(CMAKE_STATIC_LIB_PATH "-L\$\{libdir\}/static") @@ -236,7 +249,7 @@ add_definitions(-DCONFIGURATION_FILES_DIR="${CONFIGURATION_FILES_DIR}") add_subdirectory(cmake) -if (WITH_DLT_NETWORK_TRACE) +if(WITH_DLT_NETWORK_TRACE) # Message queue if(HAVE_MQUEUE_H AND HAVE_FUNC_MQOPEN AND HAVE_FUNC_MQCLOSE AND HAVE_FUNC_MQUNLINK AND HAVE_FUNC_MQSEND AND HAVE_FUNC_MQRECEIVE) @@ -272,15 +285,15 @@ if(WITH_SYSTEMD add_definitions(-DDLT_SYSTEMD_JOURNAL_ENABLE) endif() - if (WITH_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX) + if(WITH_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX) add_definitions(-DDLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE) endif() - if (WITH_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_DLT_SYSTEM) + if(WITH_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_DLT_SYSTEM) add_definitions(-DDLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYTSTEM) endif() - if (WITH_SYSTEMD_SOCKET_ACTIVATION) + if(WITH_SYSTEMD_SOCKET_ACTIVATION) if(NOT DLT_IPC STREQUAL "UNIX_SOCKET") message(FATAL_ERROR "WITH_SYSTEMD_SOCKET_ACTIVATION is only supported for UNIX_SOCKET") endif() @@ -332,11 +345,11 @@ add_subdirectory(doc) add_subdirectory(src) add_subdirectory(include) add_subdirectory(testscripts) -if (WITH_DLT_UNIT_TESTS) +if(WITH_DLT_UNIT_TESTS) find_package(GTest) - if (NOT GTEST_FOUND) - add_subdirectory( googletest ) + if(NOT GTEST_FOUND) + add_subdirectory(googletest) endif() enable_testing() add_subdirectory(tests) @@ -362,6 +375,7 @@ message(STATUS "WITH_DLT_FILETRANSFER = ${WITH_DLT_FILETRANSFER}") message(STATUS "WITH_DLT_DBUS = ${WITH_DLT_DBUS}") message(STATUS "WITH_DLT_TESTS = ${WITH_DLT_TESTS}") message(STATUS "WITH_DLT_UNIT_TESTS = ${WITH_DLT_UNIT_TESTS}") +message(STATUS "WITH_DLT_COVERAGE = ${WITH_DLT_COVERAGE}") message(STATUS "WITH_DLT_SHM_ENABLE = ${WITH_DLT_SHM_ENABLE}") message(STATUS "WITH_DLTTEST = ${WITH_DLTTEST}") message(STATUS "WITH_DLT_PKGCONFIG = ${WITH_DLT_PKGCONFIG}") diff --git a/README.md b/README.md index 5a72c54d6..ba1299459 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ # Diagnostic Log and Trace -Status: [![Build Status](https://github.com/COVESA/dlt-daemon/actions/workflows/cmake-ctest.yml/badge.svg)]( https://github.com/COVESA/dlt-daemon/actions/workflows/cmake-ctest.yml) + +[![Build Status](https://github.com/COVESA/dlt-daemon/actions/workflows/cmake-ctest.yml/badge.svg)]( https://github.com/COVESA/dlt-daemon/actions/workflows/cmake-ctest.yml) [![CodeQL](https://github.com/COVESA/dlt-daemon/actions/workflows/codeql-analysis.yml/badge.svg?branch=master)](https://github.com/COVESA/dlt-daemon/actions/workflows/codeql-analysis.yml) +[![Page-build-deployment](https://github.com/COVESA/dlt-daemon/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/COVESA/dlt-daemon/actions/workflows/pages/pages-build-deployment) + +**Code coverage reports online** 📄 [LCOV - code coverage report](https://COVESA.github.io/dlt-daemon/dlt_lcov_report/index.html) # Diagnostic Log and Trace diff --git a/util/dlt_coverage_report/lcov_report_generator.sh b/util/dlt_coverage_report/lcov_report_generator.sh new file mode 100755 index 000000000..84e1f8188 --- /dev/null +++ b/util/dlt_coverage_report/lcov_report_generator.sh @@ -0,0 +1,6 @@ +#!/bin/bash +mkdir dlt_lcov_report +lcov --capture --directory $1/src --output-file dlt_lcov_report/dlt_init_coverage.info > /dev/null +lcov --remove dlt_lcov_report/dlt_init_coverage.info -o dlt_lcov_report/dlt_final_coverage.info '/usr/*' '*/include/*' > /dev/null +rm dlt_lcov_report/dlt_init_coverage.info > /dev/null +genhtml dlt_lcov_report/dlt_final_coverage.info --output-directory dlt_lcov_report diff --git a/util/gcov/gcov.sh b/util/gcov/gcov.sh deleted file mode 100755 index 86f8a735c..000000000 --- a/util/gcov/gcov.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh - -RESULT=/tmp/dlt-daemon/$2 -LOG=$RESULT/$(basename $1).log - -FN_usage() -{ - echo "Usage: ${CMD_NAME} gtest_binary output_path" - exit 1 -} - -FN_copy_gcno() -{ - array=`find . -type f -name "*.gcda" -printf '%P\n' | sed "s/gcda/gcno/"` - - # Copy gcno - echo " Copy gcno" - for a in $array; do - GCNO=/$a - DIR=$(dirname $a) - - cp $GCNO $DIR - done -} - -FN_copy_gcda_gcno() -{ - # Copy gcda and gcno to common folder - echo " Copy gcda and gcno to common folder" - find . -name "*.gcda" | xargs -I{} cp {} . - find . -name "*.gcno" | xargs -I{} cp {} . -} - -FN_generate_result() -{ - # Generate result - echo " Generate result" - lcov -d . -c -o coverage.info > /dev/null - lcov -r coverage.info */gtest-1.7.0/* */x86_64-linux-gnu/* */c++/* */tests/* */include/* -o coverageFiltered.info > /dev/null - genhtml -o lcovHtml --num-spaces 4 -s --legend coverageFiltered.info > /dev/null - rm coverage.info coverageFiltered.info -} - -############################################################# -## main -############################################################# - -CMD_NAME=`basename $0` - -while getopts :h OPT -do - case $OPT in - h) FN_usage - ;; - \?) FN_usage - ;; - esac -done - -shift $((OPTIND - 1)) - -if [ $# -ne 2 ] -then - FN_usage -fi - -echo "########################################" -echo "Run gtest: $1" - -if [ ! -f $1 ]; then - echo "gtest does not exist. Run on valid folder." - exit 1 -fi - -echo " Output the result to $RESULT" -mkdir -p $RESULT -export GCOV_PREFIX=$RESULT - -# Run gtest -./$1 > ${LOG} - -pushd $RESULT > /dev/null - -FN_copy_gcno -FN_copy_gcda_gcno -FN_generate_result - -echo " Result can be found in $RESULT/lcovHtml/index.html" -echo "########################################" - -popd > /dev/null -