From patchwork Fri Dec 28 20:28:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 208567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B6DB22C00D7 for ; Sat, 29 Dec 2012 07:28:37 +1100 (EST) Received: from localhost ([::1]:59467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogXj-0007bV-KW for incoming@patchwork.ozlabs.org; Fri, 28 Dec 2012 15:28:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:45387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogXZ-0007bD-H0 for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:28:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TogXW-0002q3-HV for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:28:25 -0500 Received: from mail-la0-f48.google.com ([209.85.215.48]:34953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogXV-0002pp-W3 for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:28:22 -0500 Received: by mail-la0-f48.google.com with SMTP id ej20so1352784lab.7 for ; Fri, 28 Dec 2012 12:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=ArNKy9pGQeOtn6of//vfBClRg9+iQYwbok32GPVeXyY=; b=UMwCUbU9bziW4kJJiB9rjfuvI/SYFm5LYRs6ug/5L9JQ4karDiCFlJEABKBTYG99Ap 7xYVPrCvaSj3OVu1snr5pJltAu4N2CjpOmhv4RKyWJcElKYkRSFipBoK2R1VTlCjol5B EJPtlDNo3Knl4/sLmT6pQDcLam1OUBboGAUXUg7Qe8iTy05dEsbnSR3KhhhW9zUdDJB5 AuWDsCfQiqo/twhdQe9kWEWne1kIjdS1p1cNFGyVsdW4btrOvMo2LiCv8loxle1BVgYo EpOxOQfI/gxtKLLi/9OcNUAzuTdJM1ca3/3lB/E859q16ACHIyTGtljvxKgBitO13Auf LqtQ== X-Received: by 10.112.43.161 with SMTP id x1mr13957827lbl.32.1356726500556; Fri, 28 Dec 2012 12:28:20 -0800 (PST) Received: from localhost.localdomain (blueswirl.broker.freenet6.net. [2001:5c0:1400:b::1cf]) by mx.google.com with ESMTPS id sj3sm12690269lab.2.2012.12.28.12.28.17 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 28 Dec 2012 12:28:19 -0800 (PST) From: Blue Swirl To: qemu-devel@nongnu.org Date: Fri, 28 Dec 2012 20:28:00 +0000 Message-Id: X-Mailer: git-send-email 1.7.2.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.215.48 Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH v2] tests: add gcov target X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add support for compiling for GCOV test coverage, enabled with '--enable-gcov' during configure. After tests, test coverage can be reported with 'make gcov'. Signed-off-by: Blue Swirl Nacked-by: QEMU Patches --- v2: update to HEAD: report coverage for more files improve gcov invocation and use foo-y Makefile magic for GCOV_FILES --- Makefile.objs | 2 ++ configure | 19 ++++++++++++++++++- tests/Makefile | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 3a3a402..a3eab4b 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -31,6 +31,8 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o # coroutines coroutine-obj-y = qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o coroutine-obj-y += qemu-coroutine-sleep.o + +# If you change this logic, please also check tests/Makefile ifeq ($(CONFIG_UCONTEXT_COROUTINE),y) coroutine-obj-$(CONFIG_POSIX) += coroutine-ucontext.o else diff --git a/configure b/configure index 99c1ec3..ed801ad 100755 --- a/configure +++ b/configure @@ -176,6 +176,8 @@ strip_opt="yes" tcg_interpreter="no" bigendian="no" mingw32="no" +gcov="no" +gcov_tool="gcov" EXESUF="" prefix="/usr/local" mandir="\${prefix}/share/man" @@ -599,6 +601,8 @@ for opt do ;; --python=*) python="$optarg" ;; + --gcov=*) gcov_tool="$optarg" + ;; --smbd=*) smbd="$optarg" ;; --extra-cflags=*) @@ -619,6 +623,8 @@ for opt do ;; --enable-gprof) gprof="yes" ;; + --enable-gcov) gcov="yes" + ;; --static) static="yes" LDFLAGS="-static $LDFLAGS" @@ -1130,6 +1136,8 @@ echo " --with-coroutine=BACKEND coroutine backend. Supported options:" echo " gthread, ucontext, sigaltstack, windows" echo " --enable-glusterfs enable GlusterFS backend" echo " --disable-glusterfs disable GlusterFS backend" +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 @@ -3090,10 +3098,14 @@ fi # End of CC checks # After here, no more $cc or $ld runs -if test "$debug" = "no" ; then +if test "$gcov" = "yes" ; then + CFLAGS="-fprofile-arcs -ftest-coverage -g $CFLAGS" + LDFLAGS="-fprofile-arcs -ftest-coverage $LDFLAGS" +elif test "$debug" = "no" ; then CFLAGS="-O2 -D_FORTIFY_SOURCE=2 $CFLAGS" fi + # Disable zero malloc errors for official releases unless explicitly told to # enable/disable if test -z "$zero_malloc" ; then @@ -3274,6 +3286,8 @@ echo "build guest agent $guest_agent" echo "seccomp support $seccomp" echo "coroutine backend $coroutine_backend" echo "GlusterFS support $glusterfs" +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" @@ -3697,6 +3711,9 @@ echo "EXESUF=$EXESUF" >> $config_host_mak echo "LIBS_QGA+=$libs_qga" >> $config_host_mak echo "POD2MAN=$POD2MAN" >> $config_host_mak echo "TRANSLATE_OPT_CFLAGS=$TRANSLATE_OPT_CFLAGS" >> $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/tests/Makefile b/tests/Makefile index b60f0fb..d5386e0 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,33 +1,65 @@ export SRC_PATH check-unit-y = tests/check-qdict$(EXESUF) +GCOV_FILES-y = qdict.c check-unit-y += tests/check-qfloat$(EXESUF) +GCOV_FILES-y += qfloat.c check-unit-y += tests/check-qint$(EXESUF) +GCOV_FILES-y += qint.c check-unit-y += tests/check-qstring$(EXESUF) +GCOV_FILES-y += qstring.c check-unit-y += tests/check-qlist$(EXESUF) +GCOV_FILES-y += qlist.c check-unit-y += tests/check-qjson$(EXESUF) +GCOV_FILES-y += qjson.c check-unit-y += tests/test-qmp-output-visitor$(EXESUF) +GCOV_FILES-y += qapi/qmp-output-visitor.c check-unit-y += tests/test-qmp-input-visitor$(EXESUF) +GCOV_FILES-y += qapi/qmp-input-visitor.c check-unit-y += tests/test-qmp-input-strict$(EXESUF) check-unit-y += tests/test-qmp-commands$(EXESUF) +GCOV_FILES-y += qapi/qmp-dispatch.c check-unit-y += tests/test-string-input-visitor$(EXESUF) +GCOV_FILES-y += qapi/string-input-visitor.c check-unit-y += tests/test-string-output-visitor$(EXESUF) +GCOV_FILES-y += qapi/string-output-visitor.c check-unit-y += tests/test-coroutine$(EXESUF) check-unit-y += tests/test-visitor-serialization$(EXESUF) +ifeq ($(CONFIG_WIN32),y) +GCOV_FILES-y += coroutine-win32.c +else +ifeq ($(CONFIG_UCONTEXT_COROUTINE),y) +GCOV_FILES-y += coroutine-ucontext.c +else +ifeq ($(CONFIG_SIGALTSTACK_COROUTINE),y) +GCOV_FILES-y += coroutine-sigaltstack.c +else +GCOV_FILES-y += coroutine-gthread.c +endif +endif +endif check-unit-y += tests/test-iov$(EXESUF) +GCOV_FILES-y += iov.c check-unit-y += tests/test-aio$(EXESUF) +GCOV_FILES-$(CONFIG_WIN32) += aio-win32.c +GCOV_FILES-$(CONFIG_POSIX) += aio-posix.c check-unit-y += tests/test-thread-pool$(EXESUF) +GCOV_FILES-y += thread-pool.c check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh # All QTests for now are POSIX-only, but the dependencies are # really in libqtest, not in the testcases themselves. check-qtest-i386-y = tests/fdc-test$(EXESUF) +GCOV_FILES-y += hw/fdc.c check-qtest-i386-y += tests/hd-geo-test$(EXESUF) +GCOV_FILES-y += hw/hd-geometry.c check-qtest-i386-y += tests/rtc-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) +GCOV_FILES-y += i386-softmmu/hw/mc146818rtc.c check-qtest-sparc-y = tests/m48t59-test$(EXESUF) check-qtest-sparc64-y = tests/m48t59-test$(EXESUF) +GCOV_FILES-y += hw/m48t59.c GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h @@ -98,6 +130,8 @@ 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 " make gcov-zerocounters Zero test coverage counters" @echo @echo "Please note that HTML reports do not regenerate if the unit tests" @echo "has not changed." @@ -105,6 +139,8 @@ check-help: @echo "The variable SPEED can be set to control the gtester speed setting." @echo "Default options are -k and (for make V=1) --verbose; they can be" @echo "changed with variable GTESTER_OPTIONS." + @echo + @echo "For test coverage, please run 'make gcov-zerocounters check gcov'." SPEED = quick GTESTER_OPTIONS = -k $(if $(V),--verbose,-q) @@ -137,6 +173,16 @@ 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_OPTIONS = -n $(if $(V),-f,) +.PHONY: gcov gcov-zerocounters +gcov: + @for f in $(GCOV_FILES-y); do \ + $(GCOV) $(GCOV_OPTIONS) $$f -o `dirname $$f`; \ + done + +gcov-zerocounters: + rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda # Other tests