From 30bc0aa7948a8a3000dab117646a829cd3a2b3ad Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Wed, 22 Oct 2014 16:08:50 +1100 Subject: Preliminary code coverage reporting infrastructure Add support in core/test/Makefile.check to build -gcov binaries (with -lgcov and -fprofile-blah-blah) as well as some targets for producing lcov HTML code coverage reports. As part of this, I had to fix up an oddity in run-mem_region_init where that due to running under Valgrind, we'd be malloc()ed a heap with a small address, well inside the mem_regions we added but when not running under valgrind (e.g. for code coverage reporting) we would get a much larger address, outside this range and hit an assert. So, after fiddling with the memory stuff for this test, I think I have it right - it passes both under valgrind and not and does produce code coverage data. Currently, we're at this level of code coverage by unit tests: Hit Total Coverage Lines: 1936 2574 75.2 % Functions: 177 225 78.7 % Branches: 1243 2360 52.7 % The totals should largely be ignored due to the only code being counted is that linked into the unit tests (total LOC is ~50kLOC according to sloccount... so unit tests currently cover < 5%) Try the "make coverage-report" target, you'll get coverage-report directory with a LCOV HTML report Signed-off-by: Stewart Smith --- libflash/test/Makefile.check | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'libflash') diff --git a/libflash/test/Makefile.check b/libflash/test/Makefile.check index f9f1ca8..54a7890 100644 --- a/libflash/test/Makefile.check +++ b/libflash/test/Makefile.check @@ -1,7 +1,12 @@ # -*-Makefile-*- LIBFLASH_TEST := libflash/test/test-flash -check: $(LIBFLASH_TEST:%=%-check) +check: $(LIBFLASH_TEST:%=%-check) $(CORE_TEST:%=%-gcov-run) + +coverage: $(LIBFLASH_TEST:%=%-gcov-run) + +$(LIBFLASH_TEST:%=%-gcov-run) : %-run: % + $< $(LIBFLASH_TEST:%=%-check) : %-check: % $(VALGRIND) $< @@ -14,7 +19,13 @@ $(LIBFLASH_TEST) : libflash/test/stubs.o libflash/libflash.c $(LIBFLASH_TEST) : % : %.c $(HOSTCC) $(HOSTCFLAGS) -O0 -g -I include -I . -o $@ $< libflash/test/stubs.o +$(LIBFLASH_TEST:%=%-gcov): %-gcov : %.c % + $(HOSTCC) $(HOSTCFLAGS) -fprofile-arcs -ftest-coverage -lgcov -O0 -g -I include -I . -o $@ $< libflash/test/stubs.o + +$(LIBFLASH_TEST:%=%-gcov): % : $(%.d:-gcov=) + clean: libflash-test-clean libflash-test-clean: $(RM) libflash/test/*.o $(LIBFLASH_TEST) + $(RM) libflash/test/*-gcov -- cgit v1.1