[tests] Added coverage report target 'check'

Issuing 'make check' now collects unit tests coverage data and generates
a report in HTML.
This commit is contained in:
Bruno de Oliveira Abinader
2016-02-17 12:43:04 +02:00
parent ec97264431
commit cdfe4e46aa
3 changed files with 67 additions and 0 deletions

View File

@@ -117,6 +117,9 @@ ifeq ($(BUILD),osx)
xtest: ; $(RUN) HOST=osx HOST_VERSION=x86_64 Xcode/test
endif
.PHONY: check
check: ; $(RUN) BUILDTYPE=Debug check
.PHONY: render
render: ; $(RUN) Makefile/mbgl-render

61
scripts/collect-coverage.sh Executable file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -e
set -o pipefail
function usage() {
echo "Error: LCOV and genhtml are required for generating coverage reports."
if [ `uname -s` = 'Linux' ]; then
echo "On Debian-based distros, you can install them via 'apt-get install lcov'"
elif [ `uname -s` = 'Darwin' ]; then
echo "On OS X, you can install them via 'brew install lcov'"
fi
exit 1
}
command -v lcov >/dev/null 2>&1 || usage
command -v genhtml >/dev/null 2>&1 || usage
# Zero coverage counters
lcov \
--quiet \
--zerocounters \
--directory "build/${HOST_SLUG}/${BUILDTYPE}" \
--output-file "build/${HOST_SLUG}/${BUILDTYPE}/coverage.info" \
>/dev/null 2>&1
# Run all unit tests
./scripts/run_tests.sh "build/${HOST_SLUG}/${BUILDTYPE}/test"
# Collect coverage data and save it into coverage.info
echo "Collecting coverage data..."
lcov \
--quiet \
--capture \
--no-external \
--directory "src/mbgl" \
--directory "platform" \
--directory "include/mbgl" \
--directory "build/${HOST_SLUG}/${BUILDTYPE}" \
--base-directory "build/${HOST_SLUG}/${BUILDTYPE}" \
--output-file "build/${HOST_SLUG}/${BUILDTYPE}/coverage.info" \
>/dev/null 2>&1
# Generate HTML report based on coverage.info
echo "Generating HTML report..."
genhtml \
--quiet \
--show-details \
--keep-descriptions \
--function-coverage \
--no-branch-coverage \
--title "Mapbox GL Native" \
--num-spaces 4 \
--sort \
--demangle-cpp \
--prefix $(pwd -P) \
--output-directory "build/${HOST_SLUG}/${BUILDTYPE}/coverage" \
"build/${HOST_SLUG}/${BUILDTYPE}/coverage.info" \
>/dev/null 2>&1
echo "Coverage report is now available in build/${HOST_SLUG}/${BUILDTYPE}/coverage/index.html"

View File

@@ -166,6 +166,9 @@ tidy: Ninja/compdb
test-%: Makefile/test
./scripts/run_tests.sh "build/$(HOST_SLUG)/$(BUILDTYPE)/test" --gtest_filter=$*
check: Makefile/test
./scripts/collect-coverage.sh
#### Helper targets ############################################################
.PHONY: print-env