diff mbox

tests: add gcov target

Message ID CAAu8pHuQwN=+LuUhWuJDSdMVHhYG=Za7x+VzjFtpxk_Qqh26hg@mail.gmail.com
State New
Headers show

Commit Message

Blue Swirl May 1, 2012, 6:49 p.m. UTC
Add support for compiling for GCOV test coverage, enabled
with '--enable-gcov' during configure.

After tests, test coverage can be reported with 'make gcov'.

Add LDFLAGS (which may include GCOV flags) to libcacard
Makefile to avoid a build breakage.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 configure          |   18 ++++++++++++++++++
 libcacard/Makefile |    2 +-
 tests/Makefile     |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)


@@ -87,6 +113,7 @@ check-help:
 	@echo " make check-unit           Run qobject tests"
 	@echo " make check-block          Run block tests"
 	@echo " make check-report.html    Generates an HTML test report"
+	@echo " make gcov                 Report test coverage"
 	@echo
 	@echo "Please note that HTML reports do not regenerate if the unit tests"
 	@echo "has not changed."
@@ -126,6 +153,12 @@ check-report.xml: $(patsubst
%,check-report-qtest-%.xml, $(QTEST_TARGETS)) check
 check-report.html: check-report.xml
 	$(call quiet-command,gtester-report $< > $@, "  GEN    $@")

+# Gcov test coverage
+gcov:
+	$(GCOV) -n $(GCOV_FILES)
+	(cd i386-softmmu; $(GCOV) -n $(GCOV_I386_SOFTMMU_FILES))
+	(cd libhw64; $(GCOV) -n $(GCOV_LIBHW64_FILES))
+	(cd qapi; $(GCOV) -n $(GCOV_QAPI_FILES))

 # Other tests

Comments

Blue Swirl May 1, 2012, 6:57 p.m. UTC | #1
On Tue, May 1, 2012 at 18:49, Blue Swirl <blauwirbel@gmail.com> wrote:
> Add support for compiling for GCOV test coverage, enabled
> with '--enable-gcov' during configure.
>
> After tests, test coverage can be reported with 'make gcov'.

This is how it looks like:
File '/src/qemu/qjson.c'
Lines executed:86.52% of 141

File '/usr/include/bits/stdio2.h'
Lines executed:100.00% of 1

File '/usr/include/bits/string3.h'
Lines executed:100.00% of 1

File '/src/qemu/qstring.c'
Lines executed:90.48% of 42

File '/src/qemu/qfloat.c'
Lines executed:93.33% of 15

File '/src/qemu/qdict.c'
Lines executed:86.51% of 126

File '/src/qemu/qobject.h'
Lines executed:100.00% of 11

File '/src/qemu/qint.c'
Lines executed:93.33% of 15

File '/src/qemu/qlist.c'
Lines executed:94.12% of 51

File '/src/qemu/coroutine-ucontext.c'
Lines executed:85.00% of 80

(cd i386-softmmu; gcov -n hw/mc146818rtc.c)
File '/src/qemu/hw/mc146818rtc.c'
Lines executed:62.58% of 318

File '/src/qemu/qemu-timer.h'
Lines executed:100.00% of 2

File '/src/qemu/qemu-common.h'
Lines executed:100.00% of 7

File '/src/qemu/hw/irq.h'
Lines executed:100.00% of 2

(cd libhw64; gcov -n hw/m48t59.c)
File '/src/qemu/hw/m48t59.c'
Lines executed:87.19% of 320

File '/src/qemu/qemu-timer.h'
Lines executed:100.00% of 1

File '/src/qemu/qemu-common.h'
Lines executed:100.00% of 2

(cd qapi; gcov -n qapi/qmp-output-visitor.c qapi/qmp-input-visitor.c
qapi/qmp-dispatch.c qapi/string-input-visitor.c
qapi/string-output-visitor.c)
File '/src/qemu/qapi/string-input-visitor.c'
Lines executed:80.33% of 61

File '/src/qemu/qlist.h'
Lines executed:100.00% of 3

File '/src/qemu/qapi/qmp-input-visitor.c'
Lines executed:92.36% of 144

File '/src/qemu/qapi/qmp-output-visitor.c'
Lines executed:100.00% of 100

File '/src/qemu/qobject.h'
Lines executed:100.00% of 10

File '/src/qemu/qapi/qmp-dispatch.c'
Lines executed:74.14% of 58

File '/src/qemu/qapi/string-output-visitor.c'
Lines executed:100.00% of 36

With lcov it's possible to get HTML output, however generating it
takes ages for some reason.

>
> Add LDFLAGS (which may include GCOV flags) to libcacard
> Makefile to avoid a build breakage.
>
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> ---
>  configure          |   18 ++++++++++++++++++
>  libcacard/Makefile |    2 +-
>  tests/Makefile     |   33 +++++++++++++++++++++++++++++++++
>  3 files changed, 52 insertions(+), 1 deletion(-)
>
> diff --git a/configure b/configure
> index 3c72fa0..dfea46a 100755
> --- a/configure
> +++ b/configure
> @@ -152,6 +152,8 @@ strip_opt="yes"
>  tcg_interpreter="no"
>  bigendian="no"
>  mingw32="no"
> +gcov="no"
> +gcov_tool="gcov"
>  EXESUF=""
>  prefix="/usr/local"
>  mandir="\${prefix}/share/man"
> @@ -556,6 +558,8 @@ for opt do
>   ;;
>   --python=*) python="$optarg"
>   ;;
> +  --gcov=*) gcov_tool="$optarg"
> +  ;;
>   --smbd=*) smbd="$optarg"
>   ;;
>   --extra-cflags=*)
> @@ -576,6 +580,8 @@ for opt do
>   ;;
>   --enable-gprof) gprof="yes"
>   ;;
> +  --enable-gcov) gcov="yes"
> +  ;;
>   --static)
>     static="yes"
>     LDFLAGS="-static $LDFLAGS"
> @@ -1110,6 +1116,8 @@ echo "  --disable-guest-agent    disable
> building of the QEMU Guest Agent"
>  echo "  --enable-guest-agent     enable building of the QEMU Guest Agent"
>  echo "  --with-coroutine=BACKEND coroutine backend. Supported options:"
>  echo "                           gthread, ucontext, sigaltstack, windows"
> +echo "  --enable-gcov            enable test coverage analysis with gcov"
> +echo "  --gcov=GCOV              use specified gcov [$gcov_tool]"
>  echo ""
>  echo "NOTE: The object files are built at the place where configure
> is launched"
>  exit 1
> @@ -2883,6 +2891,11 @@ if test "$mingw32" = "yes" ; then
>     done
>  fi
>
> +if test "$gcov" = "yes" ; then
> +  QEMU_CFLAGS="-fprofile-arcs -ftest-coverage $QEMU_CFLAGS"
> +  LDFLAGS="-fprofile-arcs -ftest-coverage $LDFLAGS"
> +fi
> +
>  qemu_confdir=$sysconfdir$confsuffix
>  qemu_datadir=$datadir$confsuffix
>
> @@ -3008,6 +3021,8 @@ echo "OpenGL support    $opengl"
>  echo "libiscsi support  $libiscsi"
>  echo "build guest agent $guest_agent"
>  echo "coroutine backend $coroutine_backend"
> +echo "gcov              $gcov_tool"
> +echo "gcov enabled      $gcov"
>
>  if test "$sdl_too_old" = "yes"; then
>  echo "-> Your SDL version is too old - please upgrade to have SDL support"
> @@ -3412,6 +3427,9 @@ echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
>  echo "EXESUF=$EXESUF" >> $config_host_mak
>  echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
>  echo "POD2MAN=$POD2MAN" >> $config_host_mak
> +if test "$gcov" = "yes" ; then
> +  echo "GCOV=$gcov_tool" >> $config_host_mak
> +fi
>
>  # generate list of library paths for linker script
>
> diff --git a/libcacard/Makefile b/libcacard/Makefile
> index c6a896a..47a5eb1 100644
> --- a/libcacard/Makefile
> +++ b/libcacard/Makefile
> @@ -18,7 +18,7 @@ QEMU_CFLAGS+=-I../
>  libcacard.lib-y=$(addsuffix .lo,$(basename $(libcacard-y)))
>
>  vscclient: $(libcacard-y) $(QEMU_OBJS) vscclient.o
> -       $(call quiet-command,$(CC) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
> +       $(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs)
> $(LIBS),"  LINK  $@")
>
>  clean:
>        rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ vscclient *.lo .libs/* *.la *.pc
> diff --git a/tests/Makefile b/tests/Makefile
> index 9988681..a316180 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -1,18 +1,42 @@
>  export SRC_PATH
>
>  check-unit-y = tests/check-qdict$(EXESUF)
> +GCOV_FILES = qdict.c
>  check-unit-y += tests/check-qfloat$(EXESUF)
> +GCOV_FILES += qfloat.c
>  check-unit-y += tests/check-qint$(EXESUF)
> +GCOV_FILES += qint.c
>  check-unit-y += tests/check-qstring$(EXESUF)
> +GCOV_FILES += qstring.c
>  check-unit-y += tests/check-qlist$(EXESUF)
> +GCOV_FILES += qlist.c
>  check-unit-y += tests/check-qjson$(EXESUF)
> +GCOV_FILES += qjson.c
>  check-unit-y += tests/test-qmp-output-visitor$(EXESUF)
> +GCOV_QAPI_FILES += qapi/qmp-output-visitor.c
>  check-unit-y += tests/test-qmp-input-visitor$(EXESUF)
> +GCOV_QAPI_FILES += qapi/qmp-input-visitor.c
>  check-unit-y += tests/test-qmp-input-strict$(EXESUF)
>  check-unit-y += tests/test-qmp-commands$(EXESUF)
> +GCOV_QAPI_FILES += qapi/qmp-dispatch.c
>  check-unit-y += tests/test-string-input-visitor$(EXESUF)
> +GCOV_QAPI_FILES += qapi/string-input-visitor.c
>  check-unit-y += tests/test-string-output-visitor$(EXESUF)
> +GCOV_QAPI_FILES += qapi/string-output-visitor.c
>  check-unit-y += tests/test-coroutine$(EXESUF)
> +ifeq ($(CONFIG_WIN32),y)
> +GCOV_FILES += coroutine-win32.c
> +else
> +ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
> +GCOV_FILES += coroutine-ucontext.c
> +else
> +ifeq ($(CONFIG_SIGALTSTACK_COROUTINE),y)
> +GCOV_FILES += coroutine-sigaltstack.c
> +else
> +GCOV_FILES += coroutine-gthread.c
> +endif
> +endif
> +endif
>
>  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
>
> @@ -20,8 +44,10 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
>  # really in libqtest, not in the testcases themselves.
>  check-qtest-i386-y = tests/rtc-test
>  check-qtest-x86_64-y = $(check-qtest-i386-y)
> +GCOV_I386_SOFTMMU_FILES += hw/mc146818rtc.c
>  check-qtest-sparc-y = tests/m48t59-test$(EXESUF)
>  check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
> +GCOV_LIBHW64_FILES += hw/m48t59.c
>
>  GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h
> tests/test-qmp-commands.h
>
> @@ -87,6 +113,7 @@ check-help:
>        @echo " make check-unit           Run qobject tests"
>        @echo " make check-block          Run block tests"
>        @echo " make check-report.html    Generates an HTML test report"
> +       @echo " make gcov                 Report test coverage"
>        @echo
>        @echo "Please note that HTML reports do not regenerate if the unit tests"
>        @echo "has not changed."
> @@ -126,6 +153,12 @@ check-report.xml: $(patsubst
> %,check-report-qtest-%.xml, $(QTEST_TARGETS)) check
>  check-report.html: check-report.xml
>        $(call quiet-command,gtester-report $< > $@, "  GEN    $@")
>
> +# Gcov test coverage
> +gcov:
> +       $(GCOV) -n $(GCOV_FILES)
> +       (cd i386-softmmu; $(GCOV) -n $(GCOV_I386_SOFTMMU_FILES))
> +       (cd libhw64; $(GCOV) -n $(GCOV_LIBHW64_FILES))
> +       (cd qapi; $(GCOV) -n $(GCOV_QAPI_FILES))

Forgot to re-add '@'.

Makefile gurus could make the above logic more generic with pattern
matching (like subdir-*).

>
>  # Other tests
>
> --
> 1.7.10
diff mbox

Patch

From c5f46706b0a023968f88378b5a3009155aca3958 Mon Sep 17 00:00:00 2001
Message-Id: <c5f46706b0a023968f88378b5a3009155aca3958.1335897988.git.blauwirbel@gmail.com>
From: Blue Swirl <blauwirbel@gmail.com>
Date: Tue, 1 May 2012 18:45:39 +0000
Subject: [PATCH] tests: add gcov target

Add support for compiling for GCOV test coverage, enabled
with '--enable-gcov' during configure.

After tests, test coverage can be reported with 'make gcov'.

Add LDFLAGS (which may include GCOV flags) to libcacard
Makefile to avoid a build breakage.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 configure          |   18 ++++++++++++++++++
 libcacard/Makefile |    2 +-
 tests/Makefile     |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 3c72fa0..dfea46a 100755
--- a/configure
+++ b/configure
@@ -152,6 +152,8 @@  strip_opt="yes"
 tcg_interpreter="no"
 bigendian="no"
 mingw32="no"
+gcov="no"
+gcov_tool="gcov"
 EXESUF=""
 prefix="/usr/local"
 mandir="\${prefix}/share/man"
@@ -556,6 +558,8 @@  for opt do
   ;;
   --python=*) python="$optarg"
   ;;
+  --gcov=*) gcov_tool="$optarg"
+  ;;
   --smbd=*) smbd="$optarg"
   ;;
   --extra-cflags=*)
@@ -576,6 +580,8 @@  for opt do
   ;;
   --enable-gprof) gprof="yes"
   ;;
+  --enable-gcov) gcov="yes"
+  ;;
   --static)
     static="yes"
     LDFLAGS="-static $LDFLAGS"
@@ -1110,6 +1116,8 @@  echo "  --disable-guest-agent    disable building of the QEMU Guest Agent"
 echo "  --enable-guest-agent     enable building of the QEMU Guest Agent"
 echo "  --with-coroutine=BACKEND coroutine backend. Supported options:"
 echo "                           gthread, ucontext, sigaltstack, windows"
+echo "  --enable-gcov            enable test coverage analysis with gcov"
+echo "  --gcov=GCOV              use specified gcov [$gcov_tool]"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -2883,6 +2891,11 @@  if test "$mingw32" = "yes" ; then
     done
 fi
 
+if test "$gcov" = "yes" ; then
+  QEMU_CFLAGS="-fprofile-arcs -ftest-coverage $QEMU_CFLAGS"
+  LDFLAGS="-fprofile-arcs -ftest-coverage $LDFLAGS"
+fi
+
 qemu_confdir=$sysconfdir$confsuffix
 qemu_datadir=$datadir$confsuffix
 
@@ -3008,6 +3021,8 @@  echo "OpenGL support    $opengl"
 echo "libiscsi support  $libiscsi"
 echo "build guest agent $guest_agent"
 echo "coroutine backend $coroutine_backend"
+echo "gcov              $gcov_tool"
+echo "gcov enabled      $gcov"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3412,6 +3427,9 @@  echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "EXESUF=$EXESUF" >> $config_host_mak
 echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
 echo "POD2MAN=$POD2MAN" >> $config_host_mak
+if test "$gcov" = "yes" ; then
+  echo "GCOV=$gcov_tool" >> $config_host_mak
+fi
 
 # generate list of library paths for linker script
 
diff --git a/libcacard/Makefile b/libcacard/Makefile
index c6a896a..47a5eb1 100644
--- a/libcacard/Makefile
+++ b/libcacard/Makefile
@@ -18,7 +18,7 @@  QEMU_CFLAGS+=-I../
 libcacard.lib-y=$(addsuffix .lo,$(basename $(libcacard-y)))
 
 vscclient: $(libcacard-y) $(QEMU_OBJS) vscclient.o
-	$(call quiet-command,$(CC) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
+	$(call quiet-command,$(CC) $(LDFLAGS) -o $@ $^ $(libcacard_libs) $(LIBS),"  LINK  $@")
 
 clean:
 	rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ vscclient *.lo .libs/* *.la *.pc
diff --git a/tests/Makefile b/tests/Makefile
index 9988681..a316180 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,18 +1,42 @@ 
 export SRC_PATH
 
 check-unit-y = tests/check-qdict$(EXESUF)
+GCOV_FILES = qdict.c
 check-unit-y += tests/check-qfloat$(EXESUF)
+GCOV_FILES += qfloat.c
 check-unit-y += tests/check-qint$(EXESUF)
+GCOV_FILES += qint.c
 check-unit-y += tests/check-qstring$(EXESUF)
+GCOV_FILES += qstring.c
 check-unit-y += tests/check-qlist$(EXESUF)
+GCOV_FILES += qlist.c
 check-unit-y += tests/check-qjson$(EXESUF)
+GCOV_FILES += qjson.c
 check-unit-y += tests/test-qmp-output-visitor$(EXESUF)
+GCOV_QAPI_FILES += qapi/qmp-output-visitor.c
 check-unit-y += tests/test-qmp-input-visitor$(EXESUF)
+GCOV_QAPI_FILES += qapi/qmp-input-visitor.c
 check-unit-y += tests/test-qmp-input-strict$(EXESUF)
 check-unit-y += tests/test-qmp-commands$(EXESUF)
+GCOV_QAPI_FILES += qapi/qmp-dispatch.c
 check-unit-y += tests/test-string-input-visitor$(EXESUF)
+GCOV_QAPI_FILES += qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
+GCOV_QAPI_FILES += qapi/string-output-visitor.c
 check-unit-y += tests/test-coroutine$(EXESUF)
+ifeq ($(CONFIG_WIN32),y)
+GCOV_FILES += coroutine-win32.c
+else
+ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
+GCOV_FILES += coroutine-ucontext.c
+else
+ifeq ($(CONFIG_SIGALTSTACK_COROUTINE),y)
+GCOV_FILES += coroutine-sigaltstack.c
+else
+GCOV_FILES += coroutine-gthread.c
+endif
+endif
+endif
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -20,8 +44,10 @@  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 # really in libqtest, not in the testcases themselves.
 check-qtest-i386-y = tests/rtc-test
 check-qtest-x86_64-y = $(check-qtest-i386-y)
+GCOV_I386_SOFTMMU_FILES += hw/mc146818rtc.c
 check-qtest-sparc-y = tests/m48t59-test$(EXESUF)
 check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
+GCOV_LIBHW64_FILES += hw/m48t59.c
 
 GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
 
@@ -87,6 +113,7 @@  check-help:
 	@echo " make check-unit           Run qobject tests"
 	@echo " make check-block          Run block tests"
 	@echo " make check-report.html    Generates an HTML test report"
+	@echo " make gcov                 Report test coverage"
 	@echo
 	@echo "Please note that HTML reports do not regenerate if the unit tests"
 	@echo "has not changed."
@@ -126,6 +153,12 @@  check-report.xml: $(patsubst %,check-report-qtest-%.xml, $(QTEST_TARGETS)) check
 check-report.html: check-report.xml
 	$(call quiet-command,gtester-report $< > $@, "  GEN    $@")
 
+# Gcov test coverage
+gcov:
+	$(GCOV) -n $(GCOV_FILES)
+	(cd i386-softmmu; $(GCOV) -n $(GCOV_I386_SOFTMMU_FILES))
+	(cd libhw64; $(GCOV) -n $(GCOV_LIBHW64_FILES))
+	(cd qapi; $(GCOV) -n $(GCOV_QAPI_FILES))
 
 # Other tests
 
-- 
1.7.2.5