[CRIU] [PATCH] make: add ability to collect code coverage

Andrey Vagin avagin at openvz.org
Mon Dec 24 09:46:22 EST 2012


gcc is executed with the option --coverage.
lcov creates HTML pages containing the source code annotated with
coverage information.

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

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 Makefile     | 17 +++++++++++++++++
 cr-restore.c |  8 ++++++++
 2 files changed, 25 insertions(+)

diff --git a/Makefile b/Makefile
index be1083e..ce5befe 100644
--- a/Makefile
+++ b/Makefile
@@ -124,6 +124,10 @@ DEPS		:= $(patsubst %.o,%.d,$(OBJS))
 .PHONY: all zdtm test rebuild clean distclean tags cscope	\
 	docs help pie protobuf x86
 
+ifeq ($(GCOV),1)
+%.o $(PROGRAM): override CFLAGS += --coverage -DCR_GCOV
+endif
+
 all: pie
 	$(Q) $(MAKE) $(PROGRAM)
 
@@ -180,6 +184,8 @@ clean:
 	$(Q) $(RM) -f ./*.bin
 	$(Q) $(RM) -f ./$(PROGRAM)
 	$(Q) $(RM) -rf ./test/dump/
+	$(Q) $(RM) -f ./*.gcov ./*.gcda ./*.gcno
+	$(Q) $(RM) -rf ./gcov
 	$(Q) $(MAKE) -C protobuf/ clean
 	$(Q) $(MAKE) -C arch/x86/ clean
 	$(Q) $(MAKE) -C pie/ clean
@@ -218,6 +224,17 @@ help:
 	$(E) '      rebuild         - Force-rebuild of [*] targets'
 	$(E) '      test            - Run zdtm test-suite'
 
+gcov:
+	$(E) " GCOV"
+	$(Q) mkdir gcov && \
+	cd gcov && \
+	cp ../*.gcno ../*.c ../test/root/crtools/	&& \
+	geninfo --no-checksum  --output-filename tproxyd.l.info --no-recursion .. && \
+	geninfo --no-checksum  --output-filename tproxyd.ns.info --no-recursion ../test/root/crtools && \
+	sed -i 's#/test/root/crtools##' tproxyd.ns.info && \
+	lcov -a tproxyd.l.info -a tproxyd.ns.info -o tproxyd.info && \
+	genhtml -o html tproxyd.info
+
 deps-targets := $(OBJS) $(patsubst %.o,%.s,$(OBJS)) $(patsubst %.o,%.i,$(OBJS)) $(PROGRAM)
 
 .DEFAULT_GOAL	:= all
diff --git a/cr-restore.c b/cr-restore.c
index 078dedc..befc27b 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1738,6 +1738,10 @@ static int sigreturn_prep_xsave_frame(struct thread_restore_args *args, CoreEntr
 	return 0;
 }
 
+#ifdef CR_GCOV
+extern void __gcov_flush(void);
+#endif
+
 static int sigreturn_restore(pid_t pid, CoreEntry *core)
 {
 	long restore_task_vma_len;
@@ -1998,6 +2002,10 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 
 	close_image_dir();
 
+#ifdef CR_GCOV
+	__gcov_flush();
+#endif
+
 	pr_info("task_args: %p\n"
 		"task_args->pid: %d\n"
 		"task_args->nr_threads: %d\n"
-- 
1.7.11.7



More information about the CRIU mailing list