Skip to content

Commit

Permalink
Coverage support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagatikar Saiprasad authored and Kagatikar Saiprasad committed Jan 25, 2021
1 parent bcb9898 commit 04bcbef
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 19 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/Code_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Code_Coverage

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: "Ubuntu Latest - GCC", artifact: "linux-gcc.tar.xz",
os: ubuntu-latest,
cc: "gcc-9", cxx: "g++-9"
}

steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"

- name: Install Linux dependencies
if: runner.os == 'Linux'
run: sudo apt-get install libgtest-dev cmake lcov;

- name: Build gtest
run: cd /usr/src/gtest; sudo cmake CMakeLists.txt; sudo make; sudo cp *.a /usr/lib;

- name: Build
run : mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=Debug -DCODE_COVERAGE=ON .. ; make;

- name : Run tests
run : cd bin; ./Generic_Logger_test;

- name : Capture coverage stats
run : |
cd bin; lcov --directory ../build/ --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' --output-file coverage.info
lcov --list coverage.info
export CODECOV_TOKEN="33cd74a9-f59c-4eca-aeed-c70aa55866e5"
bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
2 changes: 1 addition & 1 deletion .github/workflows/Validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
run : mkdir build; cd build; cmake ..; make;

- name : Run tests
run : pwd;cd build; ./Generic_Logger_test;
run : pwd;cd bin; ./Generic_Logger_test;
35 changes: 31 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
project(Generic_Logger)

add_library(generic_logger src/logger.cpp)
include_directories(include)

# Tests
find_package(GTest REQUIRED)
if (GTest_FOUND)
message("Found GTest")
add_executable(Generic_Logger_test test/test_logger.cpp)
target_link_libraries(Generic_Logger_test GTest::GTest GTest::Main generic_logger)
endif()

# Coverage
if(CMAKE_BUILD_TYPE STREQUAL "coverage" OR CODE_COVERAGE)
if(CMAKE_COMPILER_IS_GNUCXX)
message("Building with lcov Code Coverage Tools")

find_program(LCOV_PATH lcov)
find_program(GENHTML_PATH genhtml)

# Warning/Error messages
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
message(WARNING "Code coverage results with an optimized (non-Debug) build may be misleading")
endif()

if(NOT LCOV_PATH)
message(FATAL_ERROR "lcov not found! Aborting...")
endif()

if(NOT GENHTML_PATH)
message(FATAL_ERROR "genhtml not found! Aborting...")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
else()
message(FATAL_ERROR "Code coverage requires GCC. Aborting.")
endif()
endif()
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/)
add_library(generic_logger src/logger.cpp)
include_directories(include)
14 changes: 0 additions & 14 deletions run_tests.sh

This file was deleted.

0 comments on commit 04bcbef

Please sign in to comment.