git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/7] Makefile: Include subdirectories in "make cover" reports

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 25, 2010, 17:02 UTC
Message-ID
<20100725170242.GB25658@burratino>
In-Reply-To
<1280068861-17701-3-git-send-email-avarab@gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 6 quoted lines
> We generate profiling files in all the $(OBJECTS) dirs. Aggregate
> results from there, and add them to the corresponding clean target.
> 
> Also expand the gcov arguments. Generate reports for things like "x()
> || y()" using --all-blocks, and add --preserve-paths since we're
> profiling in subdirectories now.

All good things. It might be good to add a GCOVFLAGS that can be added to the "make" command line, then.

Show 12 quoted lines
> +++ b/Makefile
> @@ -2280,8 +2280,11 @@ coverage:
>  	$(MAKE) coverage-build
>  	$(MAKE) coverage-report
>  
> +object_dirs := $(sort $(dir $(OBJECTS)))
>  coverage-clean:
> -	rm -f *.gcda *.gcno
> +	$(RM) $(addsuffix *.gcov,$(object_dirs))
> +	$(RM) $(addsuffix *.gcda,$(object_dirs))
> +	$(RM) $(addsuffix *.gcno,$(object_dirs))
>  COVERAGE_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
What about coverage-untested-functions?
[...]
Show 8 quoted lines
> @@ -2292,7 +2295,9 @@ coverage-build: coverage-clean
>  		-j1 test
>  
>  coverage-report:
> -	gcov -b *.c
> +	for dir in $(object_dirs); do \
> +		gcov --preserve-paths --branch-probabilities --all-blocks --object-directory=$$dir $$dir*.c; \
> +	done

This will not error out if "for" fails; maybe it would make sense to use set -e or exit.

More importantly, it spews quite a lot of output:
| for dir in ./ block-sha1/ builtin/ compat/ xdiff/; do \
|                 gcov --preserve-paths --branch-probabilities --all-blocks --object-directory=$dir $dir*.c || exit; \
|         done
| ./abspath.gcno:version '405p', prefer '404*'
| ./abspath.gcda:version '405p', prefer version '404*'
| ./advice.gcno:version '405p', prefer '404*'
[...]
| ./ctype.gcno:cannot open graph file
[...]
| File 'wt-status.c'
| Lines executed:36.26% of 535
| Branches executed:39.78% of 279
| Taken at least once:20.43% of 279
| No calls
| wt-status.c:creating 'wt-status.c.gcov'
|
| File 'write_or_die.c'
[...]
| block-sha1/sha1.c:creating 'block-sha1#sha1.c.gcov'
|
| builtin/add.gcno:version '405p', prefer '404*'
[...]
| compat/basename.gcno:cannot open graph file
| compat/cygwin.gcno:cannot open graph file
[...]

Can gcov be convinced to be a little quieter (i.e., only useful warnings)? (I don’t know; just asking.)

Here are the changes I squashed in for testing; please feel free to take or leave what you like.

diff --git i/Makefile w/Makefile
index a95d260..b791ad5 100644
--- i/Makefile
+++ w/Makefile
@@ -1485,6 +1485,7 @@ ifndef V
 	QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
 	QUIET_LNCP     = @echo '   ' LN/CP $@;
+	QUIET_GCOV     = @echo '   ' GCOV $@;
 	QUIET_SUBDIR0  = +@subdir=
 	QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
 			 $(MAKE) $(PRINT_DIR) -C $$subdir
@@ -2285,9 +2286,11 @@ coverage-clean:
 	$(RM) $(addsuffix *.gcov,$(object_dirs))
 	$(RM) $(addsuffix *.gcda,$(object_dirs))
 	$(RM) $(addsuffix *.gcno,$(object_dirs))
+	$(RM) coverage-untested-functions
 
 COVERAGE_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
 COVERAGE_LDFLAGS = $(CFLAGS)  -O0 -lgcov
+GCOVFLAGS = --preserve-paths --branch-probabilities --all-blocks
 
 coverage-build: coverage-clean
 	$(MAKE) CFLAGS="$(COVERAGE_CFLAGS)" LDFLAGS="$(COVERAGE_LDFLAGS)" all
@@ -2295,9 +2298,9 @@ coverage-build: coverage-clean
 		-j1 test
 
 coverage-report:
-	for dir in $(object_dirs); do \
-		gcov --preserve-paths --branch-probabilities --all-blocks --object-directory=$$dir $$dir*.c; \
+	$(QUIET_GCOV)for dir in $(object_dirs); do \
+		gcov $(GCOVFLAGS) --object-directory=$$dir $$dir*.c || exit; \
 	done
 	grep '^function.*called 0 ' *.c.gcov \
 		| sed -e 's/\([^:]*\)\.gcov: *function \([^ ]*\) called.*/\1: \2/' \
-		| tee coverage-untested-functions
+		> coverage-untested-functions
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 5 of 17 in “Detailed test coverage reports for Git”
  1. 0/7 Detailed test coverage reports for GitÆvar Arnfjörð Bjarmason, Jul 25, 2010
  2. 1/7 gitignore: Ignore files generated by "make coverage"Ævar Arnfjörð Bjarmason, Jul 25, 2010
  3. Jonathan NiederJul 25, 2010
  4. 2/7 Makefile: Include subdirectories in "make cover" reportsÆvar Arnfjörð Bjarmason, Jul 25, 2010
  5. Jonathan NiederJul 25, 2010
  6. 3/7 Makefile: Split out the untested functions targetÆvar Arnfjörð Bjarmason, Jul 25, 2010
  7. 4/7 Makefile: Add coverage-report-cover-db targetÆvar Arnfjörð Bjarmason, Jul 25, 2010
  8. Jonathan NiederJul 25, 2010
  9. 5/7 Makefile: Add coverage-report-cover-db-html targetÆvar Arnfjörð Bjarmason, Jul 25, 2010
  10. Jonathan NiederJul 25, 2010
  11. 6/7 t/README: A new section about test coverageÆvar Arnfjörð Bjarmason, Jul 25, 2010
  12. 7/7 t/README: Add a note about the dangers of coverage chasingÆvar Arnfjörð Bjarmason, Jul 25, 2010
  13. Jonathan NiederJul 25, 2010
  14. Ævar Arnfjörð BjarmasonJul 25, 2010
  15. Jonathan NiederJul 25, 2010
  16. Ævar Arnfjörð BjarmasonJul 25, 2010
  17. Jonathan NiederJul 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.