From 9c34d4ed092ccbfc969c34b0f96349a898496102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Wed, 8 Oct 2014 11:03:45 +0200 Subject: [PATCH] add ./configure valgrind support to test suites --- ChangeLog | 4 ++++ configure.ac | 20 ++++++++++++++++++++ testenv/ChangeLog | 6 ++++++ testenv/Makefile.am | 3 ++- testenv/README | 6 ++++-- testenv/test/base_test.py | 11 +++++++---- tests/ChangeLog | 5 +++++ tests/Makefile.am | 3 ++- tests/WgetTests.pm | 17 +++++++++++++---- 9 files changed, 63 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 81e1ecbd..6f74205a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-10-28 Tim Ruehsen + + * configure.ac: add --enable-valgrind-tests + 2014-10-28 Giuseppe Scrivano * cfg.mk (local-checks-to-skip): Add sc_makefile_at_at_check. diff --git a/configure.ac b/configure.ac index 3cbe6188..ded4714c 100644 --- a/configure.ac +++ b/configure.ac @@ -100,6 +100,25 @@ ENABLE_DEBUG=$enableval, ENABLE_DEBUG=yes) test x"${ENABLE_DEBUG}" = xyes && AC_DEFINE([ENABLE_DEBUG], 1, [Define if you want the debug output support compiled in.]) +dnl +dnl Check for valgrind +dnl +AC_ARG_ENABLE(valgrind-tests, + AS_HELP_STRING([--enable-valgrind-tests], [enable using Valgrind for tests]), + [ac_enable_valgrind=$enableval], [ac_enable_valgrind=no]) +if test "${ac_enable_valgrind}" != "no" ; then + AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no) + if test "$HAVE_VALGRIND" = "yes" ; then + VALGRIND_TESTS="1" + AC_SUBST(VALGRIND_TESTS) + VALGRIND_INFO="Test suite will be run under Valgrind" + else + VALGRIND_INFO="Valgrind not found" + fi +else + VALGRIND_INFO="Valgrind testing not enabled" +fi + dnl dnl Find the compiler dnl @@ -599,4 +618,5 @@ AC_MSG_NOTICE([Summary of build options: NTLM: $ENABLE_NTLM OPIE: $ENABLE_OPIE Debugging: $ENABLE_DEBUG + Valgrind: $VALGRIND_INFO ]) diff --git a/testenv/ChangeLog b/testenv/ChangeLog index 18087b65..c57a4319 100644 --- a/testenv/ChangeLog +++ b/testenv/ChangeLog @@ -1,3 +1,9 @@ +2014-10-25 Tim Ruehsen + + * test/base_test.py (gen_cmd_line): generate valgrind command line if requested + * README: amend description of VALGRIND_TESTS + * Makefile.am: set/export VALGRIND_TESTS + 2014-10-01 Darshit Shah * Makefile.am: Run the tests in Python's Optimizedmode diff --git a/testenv/Makefile.am b/testenv/Makefile.am index b1f6781f..33604bcb 100644 --- a/testenv/Makefile.am +++ b/testenv/Makefile.am @@ -27,7 +27,8 @@ AUTOMAKE_OPTIONS = parallel-tests -AM_TESTS_ENVIRONMENT = export WGETRC=/dev/null; MAKE_CHECK=True; export MAKE_CHECK; export PYTHONPATH=$$PYTHONPATH:$(srcdir); +AM_TESTS_ENVIRONMENT = export WGETRC=/dev/null; MAKE_CHECK=True; export MAKE_CHECK;\ + export PYTHONPATH=$$PYTHONPATH:$(srcdir); export VALGRIND_TESTS="@VALGRIND_TESTS@"; TESTS = Test-auth-basic-fail.py \ Test-auth-basic.py \ Test-auth-both.py \ diff --git a/testenv/README b/testenv/README index 413e12ec..081a957f 100644 --- a/testenv/README +++ b/testenv/README @@ -93,8 +93,10 @@ Environment Variables: valgrind. * NO_CLEANUP: Do not remove the temporary files created by the test. This will prevent the ${testname}-test directory from being deleted -* VALGRIND_TESTS: If this variable is set, the test suite will execute all the - tests through valgrind's memcheck tool. +* VALGRIND_TESTS: If this variable is set and contains the valgrind command line, + the test suite will execute all the tests via this command. + If it is set to "1", valgrind memcheck is enabled with hard coded options. + This variable is set by ./configure --enable-valgrind-tests. File Structure: diff --git a/testenv/test/base_test.py b/testenv/test/base_test.py index 665b3c51..0d98078a 100644 --- a/testenv/test/base_test.py +++ b/testenv/test/base_test.py @@ -100,11 +100,14 @@ class BaseTest: "..", '..', 'src', "wget")) wget_options = '--debug --no-config %s' % self.wget_options - if os.getenv("VALGRIND_TESTS"): - valgrind_test = "valgrind --error-exitcode=301 --leak-check=full --track-origins=yes" + valgrind = os.getenv("VALGRIND_TESTS", "") + if valgrind in ("", "0"): + cmd_line = '%s %s ' % (wget_path, wget_options) + elif valgrind == "1": + cmd_line = 'valgrind --error-exitcode=301 --leak-check=yes --track-origins=yes %s %s ' % (wget_path, wget_options) else: - valgrind_test = "" - cmd_line = '%s %s %s ' % (valgrind_test, wget_path, wget_options) + cmd_line = '%s %s %s ' % (os.getenv("VALGRIND_TESTS", ""), wget_path, wget_options) + for protocol, urls, domain in zip(self.protocols, self.urls, self.domains): diff --git a/tests/ChangeLog b/tests/ChangeLog index 3a7b326e..0f08a5bc 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2014-10-25 Tim Ruehsen + + * WgetTests.pm (run): generate valgrind command line if requested + * Makefile.am: set/export VALGRIND_TESTS + 2014-10-28 Tim Ruehsen * tests/Test-proxied-https-auth.px: synchronize client and server diff --git a/tests/Makefile.am b/tests/Makefile.am index 094cea17..58ef5b77 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -140,6 +140,7 @@ CLEANFILES = *~ *.bak core core.[0-9]* TESTS = ./unit-tests$(EXEEXT) $(PX_TESTS) TEST_EXTENSIONS = .px -AM_TESTS_ENVIRONMENT = export WGETRC=/dev/null; export SYSTEM_WGETRC=/dev/null; PX_LOG_COMPILER = $(PERL) AM_PX_LOG_FLAGS = -I$(srcdir) +AM_TESTS_ENVIRONMENT = export WGETRC=/dev/null; export SYSTEM_WGETRC=/dev/null;\ + export VALGRIND_TESTS="@VALGRIND_TESTS@"; diff --git a/tests/WgetTests.pm b/tests/WgetTests.pm index 1c65d54c..b3d4bc67 100644 --- a/tests/WgetTests.pm +++ b/tests/WgetTests.pm @@ -88,13 +88,22 @@ sub run { # Call wget chdir ("$self->{_workdir}/$self->{_name}/output"); + my $cmdline = $self->{_cmdline}; $cmdline = $self->_substitute_port($cmdline); + $cmdline = ($cmdline =~ m{^/.*}) ? $cmdline : "$self->{_workdir}/$cmdline"; + + my $valgrind = $ENV{VALGRIND_TESTS}; + if (!defined $valgrind || $valgrind == "" || $valgrind == "0") { + # Valgrind not requested - leave $cmdline as it is + } elsif ($valgrind == "1") { + $cmdline = "valgrind --error-exitcode=301 --leak-check=yes --track-origins=yes " . $cmdline; + } else { + $cmdline = $valgrind . " " . $cmdline; + } + print "Calling $cmdline\n"; - $errcode = - ($cmdline =~ m{^/.*}) - ? system ($cmdline) - : system ("$self->{_workdir}/$cmdline"); + $errcode = system($cmdline); $errcode >>= 8; # XXX: should handle abnormal error codes. # Shutdown server