changeset 18239:d938a49c2045

dovecot.m4: External plugins can now more easily run their tests via Valgrind. DC_DOVECOT macro automatically adds RUN_TEST variable to Makefiles, which can be used to call any test programs. If valgrind exists, the tests are run through it. This is done by writing run-test.sh to the build directory, so the original run-test.sh in hg is no longer needed.
author Timo Sirainen <tss@iki.fi>
date Tue, 10 Feb 2015 13:12:42 +0200
parents 43a61a8bf9c5
children 51d04f935e61
files .hgignore configure.ac dovecot.m4 run-test.sh
diffstat 4 files changed, 32 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Feb 10 12:31:12 2015 +0200
+++ b/.hgignore	Tue Feb 10 13:12:42 2015 +0200
@@ -36,6 +36,7 @@
 ChangeLog
 Makefile
 Makefile.in
+run-test.sh
 
 *.o
 *.lo
--- a/configure.ac	Tue Feb 10 12:31:12 2015 +0200
+++ b/configure.ac	Tue Feb 10 13:12:42 2015 +0200
@@ -2816,13 +2816,7 @@
 fi
 AC_SUBST(docdir)
 
-AC_CHECK_PROG(VALGRIND, valgrind, yes, no)
-if test $VALGRIND = yes; then
-  RUN_TEST='$(SHELL) $(top_srcdir)/run-test.sh'
-else
-  RUN_TEST=''
-fi
-AC_SUBST(RUN_TEST)
+DC_DOVECOT_TEST_WRAPPER
 AC_SUBST(abs_top_builddir)
 
 AC_CONFIG_HEADERS([config.h])
--- a/dovecot.m4	Tue Feb 10 12:31:12 2015 +0200
+++ b/dovecot.m4	Tue Feb 10 13:12:42 2015 +0200
@@ -31,6 +31,35 @@
 	unset _plugin_deps
 ])
 
+AC_DEFUN([DC_DOVECOT_TEST_WRAPPER],[
+  AC_CHECK_PROG(VALGRIND, valgrind, yes, no)
+  if test $VALGRIND = yes; then
+    cat > run-test.sh <<EOF
+#!/bin/sh
+top_srcdir=\$[1]
+shift
+
+trap "rm -f test.out.\$\$" 0 1 2 3 15
+supp_path="\$top_srcdir/run-test-valgrind.supp"
+if test -r "\$supp_path"; then
+  valgrind -q --suppressions="\$supp_path" --log-file=test.out.\$\$ \$[*]
+else
+  valgrind -q --log-file=test.out.\$\$ \$[*]
+fi
+ret=\$?
+if test -s test.out.\$\$; then
+  cat test.out.\$\$
+  exit 1
+fi
+exit \$ret
+EOF
+    RUN_TEST='$(SHELL) $(top_builddir)/run-test.sh $(top_srcdir)'
+  else
+    RUN_TEST=''
+  fi
+  AC_SUBST(RUN_TEST)
+])
+
 # Substitute every var in the given comma seperated list
 AC_DEFUN([AX_SUBST_L],[
 	m4_foreach([__var__], [$@], [AC_SUBST(__var__)])
@@ -92,4 +121,5 @@
 	AX_SUBST_L([LIBDOVECOT_INCLUDE], [LIBDOVECOT_LDA_INCLUDE], [LIBDOVECOT_DOVEADM_INCLUDE], [LIBDOVECOT_SERVICE_INCLUDE], [LIBDOVECOT_STORAGE_INCLUDE], [LIBDOVECOT_LOGIN_INCLUDE], [LIBDOVECOT_CONFIG_INCLUDE], [LIBDOVECOT_IMAP_INCLUDE], [LIBDOVECOT_DSYNC_INCLUDE])
 
 	DC_PLUGIN_DEPS
+	DC_DOVECOT_TEST_WRAPPER
 ])
--- a/run-test.sh	Tue Feb 10 12:31:12 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-trap "rm -f test.out.$$" 0 1 2 3 15
-supp_path="`dirname $0`/run-test-valgrind.supp"
-if [ -r "$supp_path" ]; then
-  valgrind -q --suppressions="$supp_path" --log-file=test.out.$$ $*
-else
-  valgrind -q --log-file=test.out.$$ $*
-fi
-ret=$?
-if [ -s test.out.$$ ]; then
-  cat test.out.$$
-  exit 1
-fi
-exit $ret