Commit a57fba05 authored by Sergey Bronnikov's avatar Sergey Bronnikov Committed by Pavel Emelyanov

make: update target to measure code coverage

This patch updates Makefile for measuring code coverage in CRIU.

criu binary should be compiled with option --coverage and linked with -lgcov
option. lcov utility creates HTML pages containing the source code annotated
with coverage information.

make GCOV=1
make test
make gcov
Look at gcov/html/index.html

Changes:
- disable optimization on compilation for gathering coverage data
- mention an option for coverage in help
- cleanup the files produced for code coverage
- make path to coverage files produced by tests in ns independent on environment
- add an option lcov_branch_coverage as branch coverage disabled by default
Signed-off-by: 's avatarSergey Bronnikov <sergeyb@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 4ea3acb0
...@@ -77,6 +77,12 @@ ifeq ($(ARCH),ia32) ...@@ -77,6 +77,12 @@ ifeq ($(ARCH),ia32)
export PROTOUFIX ldflags-y export PROTOUFIX ldflags-y
endif endif
ifeq ($(GCOV),1)
LDFLAGS += -lgcov
DEBUG = 1 # disable optimization if we want to measure code coverage
%.o $(PROGRAM): override CFLAGS += --coverage -fno-exceptions -fno-inline
endif
ifeq ($(shell echo $(ARCH) | sed -e 's/arm.*/arm/'),arm) ifeq ($(shell echo $(ARCH) | sed -e 's/arm.*/arm/'),arm)
ARMV := $(shell echo $(ARCH) | sed -nr 's/armv([[:digit:]]).*/\1/p; t; i7') ARMV := $(shell echo $(ARCH) | sed -nr 's/armv([[:digit:]]).*/\1/p; t; i7')
SRCARCH := arm SRCARCH := arm
...@@ -196,10 +202,6 @@ PROGRAM := criu ...@@ -196,10 +202,6 @@ PROGRAM := criu
.PHONY: all zdtm test rebuild clean distclean tags cscope \ .PHONY: all zdtm test rebuild clean distclean tags cscope \
docs help pie protobuf $(ARCH_DIR) clean-built lib crit docs help pie protobuf $(ARCH_DIR) clean-built lib crit
ifeq ($(GCOV),1)
%.o $(PROGRAM): override CFLAGS += --coverage
endif
all: config pie $(VERSION_HEADER) $(CRIU-LIB) all: config pie $(VERSION_HEADER) $(CRIU-LIB)
$(Q) $(MAKE) $(PROGRAM) $(Q) $(MAKE) $(PROGRAM)
$(Q) $(MAKE) crit $(Q) $(MAKE) crit
...@@ -277,7 +279,7 @@ clean: clean-built ...@@ -277,7 +279,7 @@ clean: clean-built
$(Q) $(RM) ./*.img $(Q) $(RM) ./*.img
$(Q) $(RM) ./*.out $(Q) $(RM) ./*.out
$(Q) $(RM) ./*.bin $(Q) $(RM) ./*.bin
$(Q) $(RM) ./*.gcov ./*.gcda ./*.gcno $(Q) $(RM) ./*.{gcda,gcno,gcov} ./test/`pwd`/*.{gcda,gcno,gcov} ./pie/*.{gcda,gcno,gcov}
$(Q) $(RM) -r ./gcov $(Q) $(RM) -r ./gcov
$(Q) $(RM) protobuf-desc-gen.h $(Q) $(RM) protobuf-desc-gen.h
$(Q) $(MAKE) -C test $@ $(Q) $(MAKE) -C test $@
...@@ -356,17 +358,19 @@ help: ...@@ -356,17 +358,19 @@ help:
@echo ' cscope - Generate cscope database' @echo ' cscope - Generate cscope database'
@echo ' rebuild - Force-rebuild of [*] targets' @echo ' rebuild - Force-rebuild of [*] targets'
@echo ' test - Run zdtm test-suite' @echo ' test - Run zdtm test-suite'
@echo ' gcov - Make code coverage report'
gcov: gcov:
$(E) " GCOV" $(E) " GCOV"
$(Q) mkdir gcov && \ $(Q) test -d gcov || mkdir gcov && \
cp *.{gcno,c} test/`pwd`/ && \
geninfo --output-filename gcov/crtools.h.info --no-recursion . && \
geninfo --output-filename gcov/crtools.ns.info --no-recursion test/`pwd`/ && \
sed -i 's#/test/`pwd`##' gcov/crtools.ns.info && \
cd gcov && \ cd gcov && \
cp ../*.gcno ../*.c ../test/root/crtools/ && \ lcov --rc lcov_branch_coverage=1 --add-tracefile crtools.h.info --add-tracefile crtools.ns.info --output-file criu.info && \
geninfo --no-checksum --output-filename crtools.l.info --no-recursion .. && \ genhtml --rc lcov_branch_coverage=1 --output-directory html criu.info
geninfo --no-checksum --output-filename crtools.ns.info --no-recursion ../test/root/crtools && \ @echo "Code coverage report is in `pwd`/gcov/html/ directory."
sed -i 's#/test/root/crtools##' crtools.ns.info && \
lcov -a crtools.l.info -a crtools.ns.info -o crtools.info && \
genhtml -o html crtools.info
.PHONY: gcov .PHONY: gcov
docker-build: docker-build:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment