Skip to content

Commit

Permalink
Modifiying all related gcovr materials to obtain the report.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmramosr committed May 11, 2020
1 parent 9cbcb1b commit 039c873
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 19 deletions.
40 changes: 40 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
codecov:
notify:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "65...90"

status:
project:
default:
threshold: 0.5 # Allow the coverage to drop by threshold %, and posting a success status.
patch:
default:
target: 0% # trial operation
changes: no

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "header, diff"
behavior: default
require_changes: no

ignore:
- ".git*"
- "*.yml"
- "*.md"
- "CMake*"
# ignore folders and all its contents
- "CMakeFiles/.*"
- "gtest/.*"
- "cmake_modules/.*"
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ cache:

script:
- cmake -DCMAKE_BUILD_TYPE=ON -DCOVERAGE=1 -DBUILD_TESTS=ON .
- build-wrapper-linux-x86-64 --out-dir bw-output make all
- ./runUnitTests
- build-wrapper-linux-x86-64 --out-dir bw-output make generate_gcovr
- bash generate_gcov.sh
- sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output

Expand Down
43 changes: 30 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@ list(REMOVE_ITEM SRC_FILES ${PROJECT_SOURCE_DIR}/src/main.cpp)

set(CMAKE_CXX_STANDARD 11)

set(O0_COMPILER_FLAGS "-o0"
CACHE INTERNAL "")

function(append_no_optimization_compiler_flags)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${O0_COMPILER_FLAGS}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${O0_COMPILER_FLAGS}" PARENT_SCOPE)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${O0_COMPILER_FLAGS}" PARENT_SCOPE)
message(STATUS "Appending no optimization compiler flags: ${O0_COMPILER_FLAGS}")
endfunction() # append_no_optimization_compiler_flags

################################
# Normal Libraries & Executables
################################
add_library(project1_lib ${SRC_FILES})
add_executable(project1 ${PROJECT_SOURCE_DIR}/src/main.cpp)

# Key idea: SEPARATE OUT your main() function into its own file so it can be its
# own executable. Separating out main() means you can add this library to be
# used elsewhere (e.g linking to the test executable).
if(CMAKE_COMPILER_IS_GNUCXX)
LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
# this is optional if you want to exclude some directory from the report
set(COVERAGE_LCOV_EXCLUDES 'dir1/*' 'dir2/*')
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME project1_coverage
EXECUTABLE project1
DEPENDENCIES project1)
endif()
#add_executable(project1 ${PROJECT_SOURCE_DIR}/src/main.cpp)

target_link_libraries(project1 project1_lib)
#target_link_libraries(project1 project1_lib)

################################
# Testing
Expand All @@ -55,13 +56,29 @@ option(BUILD_TESTS "Build all tests." OFF) # Makes boolean 'test' available.
if (BUILD_TESTS)

enable_testing()


##############
# Unit Tests
##############
add_executable(runUnitTests ${TEST_SRC_FILES})

if(CMAKE_COMPILER_IS_GNUCXX)
LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")
include(CodeCoverage)
APPEND_NO_OPTIMIZATION_COMPILER_FLAGS()
APPEND_COVERAGE_COMPILER_FLAGS()
# this is optional if you want to exclude some directory from the report
#set(COVERAGE_LCOV_EXCLUDES 'dir1/*' 'dir2/*')
# Both setups - SETUP_TARGET_FOR_COVERAGE_LCOV and SETUP_TARGET_FOR_COVERAGE_LCOV must be after the add_executable
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME generate_coverage
EXECUTABLE runUnitTests
DEPENDENCIES runUnitTests)
SETUP_TARGET_FOR_COVERAGE_GCOVR_XML( NAME generate_gcovr
EXECUTABLE runUnitTests
DEPENDENCIES runUnitTests)
endif()

# Standard linking to gtest stuff.
target_link_libraries(runUnitTests gtest pthread)

Expand Down
8 changes: 4 additions & 4 deletions generate_gcov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ do
done

# Erase all .gcov files in ./gcov/trash
rm -f ./*.gcov
#rm -f ./*.gcov

# Going out to ./gcov
cd ..
cd ../../
# gcovr it!
gcovr -r ./ --xml -o ../coverage/coverage.xml
gcovr -r ./ --xml -o ./coverage/coverage.xml
#gcovr -r ./ --html --html-details -o ../coverage/coverage.html
# Exit pacefully
cd ..
# cd ..

echo "done gcovving"

0 comments on commit 039c873

Please sign in to comment.