Add support for running the testsuite under 'valgrind'.
authorBen Pfaff <blp@nicira.com>
Mon, 1 Feb 2010 22:26:07 +0000 (14:26 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 2 Feb 2010 23:21:09 +0000 (15:21 -0800)
tests/automake.mk
tests/openssl.supp [new file with mode: 0644]
tests/valgrind-wrapper.in [new file with mode: 0755]

index 4a48496..502e8db 100644 (file)
@@ -95,6 +95,54 @@ check-lcov: all tests/atconfig tests/atlocal $(TESTSUITE) $(lcov_wrappers)
                cd tests && genhtml -q -o coverage.html coverage.info; \
                exit $$rc
 \f
+# valgrind support
+
+valgrind_wrappers = \
+       tests/valgrind/ovs-appctl \
+       tests/valgrind/ovs-vsctl \
+       tests/valgrind/ovsdb-client \
+       tests/valgrind/ovsdb-server \
+       tests/valgrind/ovsdb-tool \
+       tests/valgrind/test-aes128 \
+       tests/valgrind/test-classifier \
+       tests/valgrind/test-csum \
+       tests/valgrind/test-dhcp-client \
+       tests/valgrind/test-dir_name \
+       tests/valgrind/test-flows \
+       tests/valgrind/test-hash \
+       tests/valgrind/test-hmap \
+       tests/valgrind/test-json \
+       tests/valgrind/test-jsonrpc \
+       tests/valgrind/test-list \
+       tests/valgrind/test-lockfile \
+       tests/valgrind/test-ovsdb \
+       tests/valgrind/test-reconnect \
+       tests/valgrind/test-sha1 \
+       tests/valgrind/test-stp \
+       tests/valgrind/test-timeval \
+       tests/valgrind/test-type-props \
+       tests/valgrind/test-uuid \
+       tests/valgrind/test-vconn
+
+$(valgrind_wrappers): tests/valgrind-wrapper.in
+       @test -d tests/valgrind || mkdir tests/valgrind
+       sed -e 's,[@]wrap_program[@],$@,' \
+               $(top_srcdir)/tests/valgrind-wrapper.in > $@.tmp
+       chmod +x $@.tmp
+       mv $@.tmp $@
+CLEANFILES += $(valgrind_wrappers)
+EXTRA_DIST += tests/valgrind-wrapper.in
+
+VALGRIND = valgrind --log-file=valgrind.%p --leak-check=full \
+       --suppressions=$(abs_top_srcdir)/tests/openssl.supp --num-callers=20
+EXTRA_DIST += tests/openssl.supp
+check-valgrind: all tests/atconfig tests/atlocal $(TESTSUITE) $(valgrind_wrappers)
+       $(SHELL) '$(TESTSUITE)' -C tests CHECK_VALGRIND=true VALGRIND='$(VALGRIND)' AUTOTEST_PATH='tests/valgrind:$(AUTOTEST_PATH)' -d $(TESTSUITEFLAGS)
+       @echo
+       @echo '----------------------------------------------------------------------'
+       @echo 'Valgrind output can be found in tests/testsuite.dir/*/valgrind.*'
+       @echo '----------------------------------------------------------------------'
+\f
 clean-local:
        test ! -f '$(TESTSUITE)' || $(SHELL) '$(TESTSUITE)' -C tests --clean
 
diff --git a/tests/openssl.supp b/tests/openssl.supp
new file mode 100644 (file)
index 0000000..eb461f8
--- /dev/null
@@ -0,0 +1,13 @@
+# suppress OpenSSL errors from valgrind
+
+{
+   BN_mod_inverse
+   Memcheck:Cond
+   fun:BN_mod_inverse
+}
+
+{
+   BN_div
+   Memcheck:Cond
+   fun:BN_div
+}
diff --git a/tests/valgrind-wrapper.in b/tests/valgrind-wrapper.in
new file mode 100755 (executable)
index 0000000..ed9a053
--- /dev/null
@@ -0,0 +1,36 @@
+#! /bin/sh
+
+wrap_program=`basename '@wrap_program@'`
+
+# Strip the first directory from $PATH that contains $wrap_program,
+# so that below we run the real $wrap_program, not ourselves.
+not_found=true
+new_path=
+first=true
+save_IFS=$IFS
+IFS=:
+for dir in $PATH; do
+    IFS=$save_IFS
+    if $not_found && test -x "$dir/$wrap_program"; then
+        not_found=false
+    else
+        if $first; then
+            first=false
+            new_path=$dir
+        else
+            new_path=$new_path:$dir
+        fi
+    fi
+done
+IFS=$save_IFS
+if $not_found; then
+    echo "$0: error: cannot find $wrap_program in \$PATH" >&2
+    exit 1
+fi
+PATH=$new_path
+export PATH
+
+: ${VALGRIND:=valgrind -q --log-file=valgrind.%p --leak-check=full}
+exec $VALGRIND $wrap_program "$@"
+echo "$0: failed to execute $VALGRIND $wrap_program" "$@" >&2
+exit 1