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

dlt-coverage: Add coverage report generator for dlt #501

Merged
merged 1 commit into from
Jul 14, 2023
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
42 changes: 29 additions & 13 deletions .github/workflows/cmake-ctest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,57 @@ 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:
- uses: actions/checkout@v3

- 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'
minminlittleshrimp marked this conversation as resolved.
Show resolved Hide resolved
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ include/dlt/dlt_user.h
*.out
*.swp
cmake-build-debug/
.vscode/
.vscode/
googletest/
34 changes: 24 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -186,18 +187,30 @@ 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()

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(
$<$<COMPILE_LANGUAGE:C>:-std=gnu99>
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++11>
Expand All @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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}")
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 6 additions & 0 deletions util/dlt_coverage_report/lcov_report_generator.sh
Original file line number Diff line number Diff line change
@@ -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
92 changes: 0 additions & 92 deletions util/gcov/gcov.sh

This file was deleted.

Loading