Commit 5b4186eb authored by Emmanuele Bassi's avatar Emmanuele Bassi
Browse files

Add GCOV coverage test support

Use GCOV, a GCC extension, to perform a coverage test on JSON-GLib when
we perform a 'make check'.

GCOV support builds JSON-GLib with compiler and linker flags that enable
coverage reports; then the check-local target will build the gcov file
for each source file, and the coverage report will be extracted from
those.
parent 56f56ae2
......@@ -4,9 +4,12 @@ Makefile.in
aclocal.m4
autom4te.cache
/build/autotools/*.m4
/build/autotools/shave-libtool
/build/autotools/shave
!/build/autotools/shave.m4
!/build/autotools/as-compiler-flag.m4
!/build/autotools/introspection.m4
!/build/autotools/Makefile.am.*
compile
configure
config.guess
......@@ -69,6 +72,4 @@ test-report.html
/doc/reference/json-glib.signals
omf.make
xmldocs.make
/build/autotools/gtk-doc.m4
/build/autotools/shave-libtool
/build/autotools/shave
*.gcov
......@@ -7,7 +7,8 @@ EXTRA_DIST = \
Makefile.am.silent \
Makefile.am.enums \
Makefile.am.marshal \
Makefile.am.gtest
Makefile.am.gtest \
Makefile.am.gcov
DISTCLEANFILES = shave-libtool shave
......
if GCOV_ENABLED
gcov-report.txt: gcov-clean
$(QUIET_GEN)(rm -f $@; \
echo -e "Test coverage for json-glib:\n" >> $@; \
total_covered=0; total_actual=0; \
for file in $(filter %.c,$(gcov_sources)); do \
gcov -o .libs/$${file/.c/.gcda} $$file > /dev/null; \
if test -f $$file.gcov; then \
actual=`grep -v ' -:' $$file.gcov | wc -l`; \
uncovered=`grep '#####:' $$file.gcov | wc -l`; \
covered=$$((actual - uncovered)); \
total_covered=$$((total_covered + covered)); \
total_actual=$$((total_actual + actual)); \
echo -e "$$file: \t$$covered / $$actual\t($$((($$covered * 100) / $$actual))%)"; \
fi \
done >> $@; \
cd $(abs_srcdir); \
echo -e "\nSource lines: $$total_actual\nCovered statements: $$total_covered\nTotal coverage: $$((($$total_covered * 100) / $$total_actual))%" >> $@)
gcov: gcov-report.txt
@cat gcov-report.txt
gcov-clean:
@find . -name "*.gcda" -o -name "*.gcov" -delete
else
gcov-report.txt:
@true
gcov-clean:
@true
gcov:
@echo "Need to reconfigure with --enable-gcov"
endif # GCOV_ENABLED
.PHONY: gcov gcov-clean gcov-report.txt
check-local: gcov
......@@ -56,6 +56,8 @@ test-report perf-report full-report: ${TEST_PROGS}
rm -rf "$$GTESTER_LOGDIR"/ ; \
${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \
}
.PHONY: test test-report perf-report full-report
# run make test as part of make check
check-local: test
......@@ -76,7 +76,7 @@ AC_SUBST(JSON_LIBS)
AM_CONDITIONAL(ENABLE_GLIB_TEST, [test "x$enable_glibtest" = "xyes"])
dnl = Enable debug level ===================================================
dnl = Enable debug level ======================================================
m4_define([debug_default], [m4_if(m4_eval(json_minor_version % 2), [1], [yes], [minimum])])
......@@ -109,7 +109,7 @@ AS_CASE([$enable_debug],
AC_SUBST(JSON_DEBUG_CFLAGS)
dnl = Enable strict compiler flags =========================================
dnl = Enable strict compiler flags ============================================
# use strict compiler flags only on development releases
m4_define([maintainer_flags_default], [m4_if(m4_eval(json_minor_version % 2), [1], [yes], [no])])
......@@ -131,6 +131,26 @@ AS_IF([test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
)
AC_SUBST([MAINTAINER_CFLAGS])
dnl = GCOV coverage checks ====================================================
AC_MSG_CHECKING([whether to build with gcov testing])
AC_ARG_ENABLE([gcov],
[AS_HELP_STRING([--enable-gcov],
[Whether to enable coverage testing (requires gcc and gcov)])],
[],
[enable_gcov=no])
AS_IF([test "x$enable_gcov" = "xyes" && test "x$GCC" = "xyes"],
[
GCOV_CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
GCOV_LDFLAGS="$LDFLAGS -fprofile-arcs -ftest-coverage"
]
)
AM_CONDITIONAL([GCOV_ENABLED], [test "x$enable_gcov" = "xyes"])
AC_SUBST([GCOV_CFLAGS])
AC_SUBST([GCOV_LDFLAGS])
AC_MSG_RESULT([$enable_gcov])
GTK_DOC_CHECK([1.11])
GOBJECT_INTROSPECTION_CHECK([0.6.4])
......@@ -182,4 +202,5 @@ echo " • API reference: ${enable_gtk_doc}"
echo ""
echo " • Enable test suite: ${enable_glibtest}"
echo " • Build introspection data: ${enable_introspection}"
echo " • Enable coverage test: ${enable_gcov}"
echo ""
include $(top_srcdir)/build/autotools/Makefile.am.gtest
include $(top_srcdir)/build/autotools/Makefile.am.silent
include $(top_srcdir)/build/autotools/Makefile.am.gtest
if ENABLE_GLIB_TEST
# build this directory *before* the tests/
......@@ -22,7 +22,7 @@ AM_CPPFLAGS = \
$(JSON_DEBUG_CFLAGS) \
$(NULL)
AM_CFLAGS = $(JSON_CFLAGS) $(MAINTAINER_CFLAGS)
AM_CFLAGS = $(JSON_CFLAGS) $(MAINTAINER_CFLAGS) $(GCOV_CFLAGS)
BUILT_SOURCES =
......@@ -69,7 +69,7 @@ lib_LTLIBRARIES = libjson-glib-1.0.la
libjson_glib_1_0_la_LIBADD = $(JSON_LIBS)
libjson_glib_1_0_la_SOURCES = $(source_c) $(source_h) $(source_h_private) $(BUILT_SOURCES)
libjson_glib_1_0_la_LDFLAGS = $(JSON_LT_LDFLAGS) -export-dynamic -export-symbols-regex "^json.*" -rpath $(libdir)
libjson_glib_1_0_la_LDFLAGS = $(JSON_LT_LDFLAGS) $(GCOV_LDFLAGS) -export-dynamic -export-symbols-regex "^json.*" -rpath $(libdir)
jsonincludedir = $(includedir)/json-glib-1.0/json-glib
jsoninclude_DATA = \
......@@ -120,3 +120,6 @@ typelibs_DATA = $(BUILT_GIRSOURCES:.gir=.typelib)
CLEANFILES += $(BUILT_GIRSOURCES) $(typelibs_DATA)
endif # HAVE_INTROSPECTION
gcov_sources = $(source_c)
include $(top_srcdir)/build/autotools/Makefile.am.gcov
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment