From c3c28cb4c197d8d68e0090e1a87a4668816ef184 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 2 Dec 2021 12:17:02 +0100 Subject: [PATCH] add code coverage support Signed-off-by: Steffen Jaeckel --- .gitignore | 5 +++++ ChangeLog | 3 +++ Makefile.am | 19 +++++++++++++++++-- README.markdown | 21 +++++++++++++++++---- configure.ac | 21 +++++++++++++++++++++ 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 10fee15..e41c312 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ autom4te.cache .dirstamp .deps .sconsign* +src/*.gcda +src/*.gcno src/*.o src/*.lo examples/*.o @@ -72,3 +74,6 @@ expat/ .settings/ .project .cproject +coverage/ +coverage.info +configure~ diff --git a/ChangeLog b/ChangeLog index 2cf8ecf..d807d32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +0.12.0 + - Add code coverage support + 0.11.0 - SASL EXTERNAL support (XEP-0178) - Client certificate can be provided for TLS negotiation. If the diff --git a/Makefile.am b/Makefile.am index 55483f0..8892198 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,11 @@ AUTOMAKE_OPTIONS = subdir-objects ACLOCAL_AMFLAGS = -I m4 +COVERAGE_CFLAGS=@COVERAGE_CFLAGS@ +COVERAGE_LDFLAGS=@COVERAGE_LDFLAGS@ +COVERAGE_PRE=@COVERAGE_PRE@ +COVERAGE_POST=@COVERAGE_POST@ + PARSER_CFLAGS=@PARSER_CFLAGS@ PARSER_LIBS=@PARSER_LIBS@ @@ -18,12 +23,12 @@ RESOLV_LIBS = @RESOLV_LIBS@ WARNING_FLAGS = @WARNING_FLAGS@ STROPHE_FLAGS = -I$(top_srcdir) $(WARNING_FLAGS) -STROPHE_LIBS = libstrophe.la +STROPHE_LIBS = $(COVERAGE_PRE) libstrophe.la $(COVERAGE_POST) $(COVERAGE_LDFLAGS) ## Main build targets lib_LTLIBRARIES = libstrophe.la -libstrophe_la_CFLAGS = $(SSL_CFLAGS) $(STROPHE_FLAGS) $(PARSER_CFLAGS) $(RESOLV_CFLAGS) +libstrophe_la_CFLAGS = $(SSL_CFLAGS) $(STROPHE_FLAGS) $(PARSER_CFLAGS) $(RESOLV_CFLAGS) $(COVERAGE_CFLAGS) libstrophe_la_LDFLAGS = $(SSL_LIBS) $(PARSER_LIBS) $(RESOLV_LIBS) -no-undefined # Export only public API libstrophe_la_LDFLAGS += -export-symbols-regex '^xmpp_' @@ -255,3 +260,13 @@ format: @echo " * run clang-format on all sources" @dos2unix -q src/*.[ch] *.h tests/*.[ch] examples/*.c @clang-format -i src/*.[ch] *.h tests/*.[ch] examples/*.c + +if COVERAGE +MOSTLYCLEANFILES = src/*.gcno src/*.gcda coverage.info +clean-local: + -rm -rf coverage/ + +coverage: check + @lcov --capture --no-external --directory src -q --output-file coverage.info + @genhtml coverage.info --output-directory coverage -q +endif diff --git a/README.markdown b/README.markdown index fac06e9..89925df 100644 --- a/README.markdown +++ b/README.markdown @@ -42,17 +42,30 @@ another path use the `--prefix` option during configure, e.g.: Run script `build-android.sh` and follow the instructions. You will need expat sources and android-ndk. +### Code Coverage + +If you want to create a code coverage report, run: + + ./configure --enable-coverage + make coverage + +The coverage report can be found in `./coverage/index.html`. + + Requirements ------------ libstrophe requires: -- expat or libxml2 - expat is the default; use --with-libxml2 to +- expat or libxml2 - expat is the default; use `--with-libxml2` to switch -- openssl on UNIX systems +- openssl or GnuTLS on UNIX systems - openssl is default; use + `--with-gnutls` to switch -To build libstrophe using autotools you will need autoconf, automake, -libtool and pkg-config. +To build libstrophe using autotools you will need `autoconf`, +`automake`, `libtool` and `pkg-config`. + +To run code coverage analysis you will need `gcov` and `lcov`. Installation ------------ diff --git a/configure.ac b/configure.ac index 31bf0db..baec8a0 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,23 @@ if test "x$enable_fuzzing" = "xyes" ; then fi fi +AC_ARG_ENABLE([coverage], + [AS_HELP_STRING([--enable-coverage], [turn on coverage for tests])], + [case "${enableval}" in yes) coverage=true ;; no) coverage=false ;; *) AC_MSG_ERROR([bad value ${enableval} for --enable-coverage]) ;; esac],[coverage=false]) +AM_CONDITIONAL([COVERAGE], [test x$coverage = xtrue]) + +if test "$enable_coverage" = "yes"; then + COVERAGE_CFLAGS="--coverage -g" + COVERAGE_LDFLAGS="--coverage -lgcov" + COVERAGE_PRE="-Wl,--whole-archive" + COVERAGE_POST="-Wl,--no-whole-archive" +else + COVERAGE_CFLAGS="" + COVERAGE_LDFLAGS="" + COVERAGE_PRE="" + COVERAGE_POST="" +fi + AC_SEARCH_LIBS([socket], [network socket]) AC_CHECK_FUNCS([snprintf vsnprintf]) AC_CHECK_DECLS([va_copy], [], [], [#include ]) @@ -174,6 +191,10 @@ AC_SUBST([PC_REQUIRES], [${PC_REQUIRES}]) AC_SUBST([PC_CFLAGS], [${PC_CFLAGS}]) AC_SUBST([PC_LIBS], [${PC_LIBS}]) +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_LDFLAGS) +AC_SUBST(COVERAGE_PRE) +AC_SUBST(COVERAGE_POST) AC_SUBST(PARSER_CFLAGS) AC_SUBST(PARSER_LIBS) AC_SUBST(RESOLV_CFLAGS)