Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wardru committed Dec 11, 2023
1 parent 64a3291 commit ffda78c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,27 @@ jobs:
else
tidy="False"
fi
cmake --preset ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }} -DWITH_TIDY=$tidy
if [ "${{ matrix.os }}" = "windows" ]; then
cmake --preset ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }} -DWITH_TIDY=$tidy -DWITH_TESTS=False
else
cmake --preset ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }} -DWITH_TIDY=$tidy -DWITH_TESTS=True -DWITH_COVERAGE=True
fi
cmake --build --preset ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }}-${{ matrix.build_type }}
- name: "Test for ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }}-${{ matrix.build_type }}"
if: ${{ matrix.os == 'Linux' }}
run: |
echo "Test for ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }}-${{ matrix.build_type }}"
ctest --preset ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }}-${{ matrix.build_type }}
- name: "Coverage"
if: ${{ matrix.os == 'linux' && matrix.compiler == 'gcc' && matrix.build_type == 'debug' && matrix.lib_type == 'static' }}
if: ${{ matrix.os == 'linux' && matrix.compiler == 'clang' && matrix.lib_type == 'shared' && matrix.build_type == 'debug' }}
run: |
echo "Coverage for ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }}-${{ matrix.build_type }}"
grcov . -s ./ -t html --llvm -o ./build/coverage/ --binary-path ./build/${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.lib_type }} --ignore '*test*' --ignore '*examples*' --ignore '*include*' --llvm-path=/usr/bin
- name: "Upload coverage artifact"
if: ${{ matrix.os == 'linux' && matrix.compiler == 'clang' && matrix.lib_type == 'shared' && matrix.build_type == 'debug' }}
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: ./build/coverage/
15 changes: 2 additions & 13 deletions cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ endif()

option(WITH_COVERAGE "Enable code coverage" OFF)
if (WITH_COVERAGE)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-instr-generate")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-instr-generate")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fprofile-instr-generate")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fprofile-instr-generate")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message(STATUS "Enabling code coverage for GCC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ RUN pacman -Sy --noconfirm \
libunwind \
wine \
gcc \
clang
clang \
gtest \
grcov

RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
Expand Down
2 changes: 1 addition & 1 deletion include/pza/core/device.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

struct device_impl;
class mqtt_service;

struct device_info;

namespace pza
{
class client;
Expand Down
Binary file removed lol.tar.gz
Binary file not shown.
7 changes: 4 additions & 3 deletions test/unit/core.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ TEST(core, log_level)
EXPECT_EQ(pza::core::get_log_level(), pza::core::log_level::off);
}

TEST(core, version) {
EXPECT_NE(pza::core::get_version(), "");
EXPECT_NE(pza::core::get_version_githash(), "");
TEST(core, version)
{
EXPECT_NE(pza::core::get_version(), "");
EXPECT_NE(pza::core::get_version_githash(), "");
}

0 comments on commit ffda78c

Please sign in to comment.