From b3064200cd20bcbc34ed66f3b0f51929f9751189 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 15 Apr 2020 08:36:59 +1000 Subject: [PATCH] build: Add ./configure --coverage To make it easier to generate code coverage output. Ensure that gcovr is installed, then do: ./configure --coverage make test coverage And see the report in coverage.html Signed-off-by: Steve Bennett --- .gitignore | 4 ++++ Makefile.in | 14 ++++++++++++++ auto.def | 25 +++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fd90885..f9ad15c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ libjim.a configure.gnu jimsh0 build-jim-ext +*.gcda +*.gcno +*.gcov +coverage*.html diff --git a/Makefile.in b/Makefile.in index 67d503c..b299c1a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -182,8 +182,22 @@ Tcl.html: jim_tcl.txt @srcdir@/make-index @echo "asciidoc is not available"; false @endif +coverage: +@if COVERAGE +@if GCOVR + @GCOVR@ -s -e 'conftest*' --html --html-details --output coverage.html +@else + gcov @srcdir@/*.c +@endif +@else + @echo "Use ./configure --coverage to enable code coverage" +@endif + clean: rm -f *.o *.so *.dll *.exe lib*.a $(JIMSH) $(LIBJIM) Tcl.html _*.c +@if COVERAGE + rm -f *.gcno *.gcov *.gcda coverage*.html +@endif distclean: clean rm -f jimautoconf.h jim-config.h Makefile config.log @srcdir@/autosetup/jimsh0@EXEEXT@ build-jim-ext diff --git a/auto.def b/auto.def index 681c913..7693e13 100644 --- a/auto.def +++ b/auto.def @@ -25,6 +25,7 @@ options { docs=1 => "don't build or install the documentation" docdir:path => "path to install docs (if built)" random-hash => "randomise hash tables. more secure but hash table results are not predicable" + coverage => "build with code coverage support" with-jim-ext: {with-ext:"ext1,ext2,..."} => { Specify additional jim extensions to include. These are enabled by default: @@ -77,6 +78,8 @@ options { install-jim=1 } +set warnings {} + # Save the user-specified LIBS # We add detected libs to LDLIBS explicitly set LIBS [get-define LIBS] @@ -98,6 +101,20 @@ if {[cctest -cflags -fno-unwind-tables]} { if {[cctest -cflags -fno-asynchronous-unwind-tables]} { define-append CCOPTS -fno-asynchronous-unwind-tables } +if {[opt-bool coverage]} { + if {[cctest -link 1 -cflags --coverage]} { + # Disable ccache when using coverage + define CCACHE "" + define-append CCOPTS --coverage + define-append LDFLAGS --coverage + define COVERAGE 1 + if {![cc-check-progs gcovr]} { + lappend warnings "Note: gcovr is not available, falling back to gcov" + } + } else { + lappend warnings "Warning: --coverage specified, but compiler does not support --coverage" + } +} cc-check-includes time.h sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h @@ -551,11 +568,15 @@ make-template jimtcl.pc.in catch {exec chmod +x build-jim-ext} -# Finally produce any warnings if {[get-define SIZEOF_TIME_T] <= 4} { set note "" if {[have-feature windows]} { set note ", consider CFLAGS=-D__MINGW_USE_VC2005_COMPAT on mingw32" } - user-notice "Warning: sizeof(time_t) is [get-define SIZEOF_TIME_T] -- not Y2038 compliant$note" + lappend warnings "Warning: sizeof(time_t) is [get-define SIZEOF_TIME_T] -- not Y2038 compliant$note" +} + +# Output any warnings at the end to make them easier to see +foreach warning $warnings { + user-notice $warning } -- 2.11.4.GIT