rom-properties/scripts/lcov.sh
David Korth b3ad0ef659 Added support for code coverage testing when using gcc or clang.
Set ENABLE_COVERAGE=ON to enable code coverage testing.

After the build is finished, run 'make coverage' to run the unit tests
and generate a code coverage page in the ${CMAKE_BINARY_DIR}/coverage
directory.

Reference: https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
(commit 59f8ab8dded56b490dec388ac6ad449318de8779)

CMakeLists.txt:
- Moved the CMAKE_BUILD_TYPE check to before INCLUDE(CTest),
  and capitalized the 'D' in "Debug", since CodeCoverage.cmake
  checks for that.

gcc.cmake:
- Set the required CFLAGS. (These aren't checked for explicitly, since
  they're basically present on all gcc since forever.)
- Link all targets to -lgcov.
- Create a 'coverage' target for automatically running tests and
  generating HTML output using lcov/genhtml.

options.cmake:
- Added ENABLE_COVERAGE.

scripts/lcov.sh:
- Shell script used by the 'coverage' target to generate the lcov/genhtml
  output from the gcov profiling data.
2016-10-18 22:55:21 -04:00

38 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# lcov code coverage script.
# Based on: https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
# (commit 59f8ab8dded56b490dec388ac6ad449318de8779)
#
# Parameters:
# - $1: Build configuration.
# - $2: Base name for lcov files.
# - $3: Output directory.
#
if [ "$#" != "3" -o ! -f CMakeCache.txt ]; then
echo "Syntax: $0 config basename output_directory"
echo "Run this script from the top-level CMake build directory."
exit 1
fi
CONFIG="$1"
coverage_info="$2.info"
coverage_cleaned="${coverage_info}.cleaned"
outputname="$3"
# Cleanup lcov.
lcov --directory . --zerocounters
# Run tests.
ctest -C "${CONFIG}"
if [ "$?" != "0" ]; then
echo "*** WARNING: Some tests failed. Generating the lcov report anyway." >&2
fi
# Capturing lcov counters and generating report.
lcov --directory . --capture --output-file ${coverage_info}
lcov --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned}
genhtml -o ${outputname} ${coverage_cleaned}
rm -f ${coverage_info} ${coverage_cleaned}
exit 0