[CRIU] [PATCH] make: add ability to collect code coverage (v2)
Andrey Vagin
avagin at openvz.org
Mon Dec 24 10:42:59 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
v2: declare the weak __gcov_flush
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
Makefile | 17 +++++++++++++++++
cr-restore.c | 6 ++++++
2 files changed, 23 insertions(+)
diff --git a/Makefile b/Makefile
index be1083e..e60d129 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
+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 70343ba..a2d8911 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1702,6 +1702,10 @@ static int sigreturn_prep_xsave_frame(struct thread_restore_args *args, CoreEntr
return 0;
}
+extern void __gcov_flush(void) __attribute__((weak));
+
+void __gcov_flush(void) {}
+
static int sigreturn_restore(pid_t pid, CoreEntry *core)
{
long restore_task_vma_len;
@@ -1962,6 +1966,8 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
close_image_dir();
+ __gcov_flush();
+
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