Skip to content

Commit

Permalink
Add support for testing under valgrind.
Browse files Browse the repository at this point in the history
Use 'make check-valgrind' to run all the tests under valgrind.
  • Loading branch information
rwmjones committed Jul 10, 2016
1 parent 8477cf4 commit 271150d
Show file tree
Hide file tree
Showing 28 changed files with 478 additions and 28 deletions.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ EXTRA_DIST = \
SUBDIRS = docs plugins include src tests

CLEANFILES = *~

check-valgrind:
$(MAKE) -C tests check-valgrind
11 changes: 11 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ For the OCaml plugin:
- OCaml >= 4.02.2 which has support for shared libraries, see:
http://caml.inria.fr/mantis/view.php?id=6693

To test for memory leaks ('make check-valgrind'):

- valgrind

For non-essential enhancements to the test suite:

- socat

- ss (from iproute package)

After installing any dependencies:

To build from tarball: To build from git:
Expand All @@ -86,6 +96,7 @@ After installing any dependencies:
./configure ./configure
make make
make check make check
make check-valgrind make check-valgrind

Optionally run this as root to install everything:

Expand Down
12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ or the configure test may be wrong.
The code will still compile, but is likely to leak memory and other
resources when it runs.])])

dnl Check for valgrind.
AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind],[no])
AS_IF([test "x$VALGRIND" != "xno"],[
# Substitute the whole valgrind command.
VG='$(VALGRIND) --vgdb=no --leak-check=full --error-exitcode=119 --suppressions=$(abs_top_srcdir)/valgrind-suppressions --trace-children=no --child-silent-after-fork=yes --run-libc-freeres=no'
],[
# Valgrind is not installed, substitute something which will break.
VG=VALGRIND_IS_NOT_INSTALLED
])
AC_SUBST([VG])
AM_SUBST_NOTMAKE([VG])

dnl Check for Perl POD.
AC_CHECK_PROG([POD2MAN], [pod2man], [pod2man], [no])
AM_CONDITIONAL([HAVE_POD2MAN], [test "x$POD2MAN" != "xno"])
Expand Down
50 changes: 34 additions & 16 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,38 @@ MAINTAINERCLEANFILES =
EXTRA_DIST = \
README.tests \
test-captive.sh \
test-connect.sh \
test-dump-config.sh \
test-dump-plugin.sh \
test-file.sh \
test-foreground.sh \
test-gzip.sh \
test-help.sh \
test-help-plugin.sh \
test-ipv4.sh \
test.pl \
test.py \
test-newstyle.sh \
test_ocaml_plugin.ml \
test-ocaml.c \
test-ocaml.sh \
test-oldstyle.sh \
test.pl \
test-perl.sh \
test.py \
test-python.sh \
test.rb \
test-single.sh \
test-start.sh \
test-random-sock.sh \
test-ruby.sh \
test-streaming.sh \
test-version.sh \
test-version-plugin.sh
test-version-plugin.sh \
test-xz.sh

# Use 'make check' to run the ordinary tests. To run all the tests
# under valgrind, use the following rule:
check-valgrind:
$(MAKE) VG="@VG@" check

# Basic server command line and start-up tests.

Expand Down Expand Up @@ -87,19 +103,21 @@ check_LTLIBRARIES = libtest.la
libtest_la_SOURCES = test.c test.h
libtest_la_CFLAGS = $(WARNINGS_CFLAGS)

# Basic connection test.
check_PROGRAMS = test-connect
TESTS += test-connect
check_PROGRAMS =
check_DATA =
check_SCRIPTS =

# Basic connection test.
check_PROGRAMS += test-connect
TESTS += test-connect.sh

test_connect_SOURCES = test-connect.c test.h
test_connect_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
test_connect_LDADD = libtest.la $(LIBGUESTFS_LIBS)

# file plugin test.
check_PROGRAMS += test-file
TESTS += test-file
TESTS += test-file.sh
check_DATA += file-data
MAINTAINERCLEANFILES += file-data

Expand All @@ -114,15 +132,15 @@ file-data:

# newstyle protocol test.
check_PROGRAMS += test-newstyle
TESTS += test-newstyle
TESTS += test-newstyle.sh

test_newstyle_SOURCES = test-newstyle.c test.h
test_newstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
test_newstyle_LDADD = libtest.la $(LIBGUESTFS_LIBS)

# oldstyle protocol test.
check_PROGRAMS += test-oldstyle
TESTS += test-oldstyle
TESTS += test-oldstyle.sh

test_oldstyle_SOURCES = test-oldstyle.c test.h
test_oldstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
Expand All @@ -133,7 +151,7 @@ if HAVE_ZLIB
if HAVE_GUESTFISH

check_PROGRAMS += test-gzip
TESTS += test-gzip
TESTS += test-gzip.sh
check_DATA += disk disk.gz
MAINTAINERCLEANFILES += disk disk.gz

Expand All @@ -158,7 +176,7 @@ if HAVE_LIBLZMA
if HAVE_GUESTFISH

check_PROGRAMS += test-xz
TESTS += test-xz
TESTS += test-xz.sh
check_DATA += disk.xz
MAINTAINERCLEANFILES += disk.xz

Expand All @@ -177,7 +195,7 @@ endif
if HAVE_PERL

check_PROGRAMS += test-perl
TESTS += test-perl
TESTS += test-perl.sh

test_perl_SOURCES = test-lang-plugins.c test.h
test_perl_CFLAGS = \
Expand All @@ -191,7 +209,7 @@ endif
if HAVE_PYTHON

check_PROGRAMS += test-python
TESTS += test-python
TESTS += test-python.sh

test_python_SOURCES = test-lang-plugins.c test.h
test_python_CFLAGS = \
Expand All @@ -205,7 +223,7 @@ endif
if HAVE_OCAML

check_PROGRAMS += test-ocaml
TESTS += test-ocaml
TESTS += test-ocaml.sh

# This is somewhat different from the other tests because we have
# to build an actual plugin here.
Expand All @@ -227,7 +245,7 @@ endif
if HAVE_RUBY

check_PROGRAMS += test-ruby
TESTS += test-ruby
TESTS += test-ruby.sh

test_ruby_SOURCES = test-lang-plugins.c test.h
test_ruby_CFLAGS = \
Expand All @@ -240,7 +258,7 @@ endif
# streaming plugin test.
check_PROGRAMS += test-streaming
# Doesn't work:
#TESTS += test-streaming
#TESTS += test-streaming.sh

test_streaming_SOURCES = test-streaming.c test.h
test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-captive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ source ./functions.sh

rm -f captive.sock captive.out

../src/nbdkit -U captive.sock `nbdkit_plugin example1` --run '
$VG ../src/nbdkit -U captive.sock `nbdkit_plugin example1` --run '
sleep 5; echo nbd=$nbd; echo port=$port; echo socket=$unixsocket
' > captive.out

Expand Down
34 changes: 34 additions & 0 deletions tests/test-connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash -
# nbdkit
# Copyright (C) 2016 Red Hat Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Red Hat nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

exec $VG ./test-connect
2 changes: 1 addition & 1 deletion tests/test-dump-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

set -e

output="$(../src/nbdkit --dump-config)"
output="$($VG ../src/nbdkit --dump-config)"
if [[ ! ( "$output" =~ ^bindir= ) ]]; then
echo "$0: unexpected output from nbdkit --dump-config"
echo "$output"
Expand Down
2 changes: 1 addition & 1 deletion tests/test-dump-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
set -e
source ./functions.sh

output="$(../src/nbdkit `nbdkit_plugin example1` --dump-plugin)"
output="$($VG ../src/nbdkit `nbdkit_plugin example1` --dump-plugin)"
if [[ ! ( "$output" =~ name\=example1 ) ]]; then
echo "$0: unexpected output from nbdkit --dump-plugin"
echo "$output"
Expand Down
34 changes: 34 additions & 0 deletions tests/test-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash -
# nbdkit
# Copyright (C) 2016 Red Hat Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Red Hat nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

exec $VG ./test-file
2 changes: 1 addition & 1 deletion tests/test-foreground.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ source ./functions.sh

rm -f foreground.pid foreground.sock

../src/nbdkit \
$VG ../src/nbdkit \
-f -P foreground.pid -U foreground.sock `nbdkit_plugin example1` &
bg_pid=$!

Expand Down
34 changes: 34 additions & 0 deletions tests/test-gzip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash -
# nbdkit
# Copyright (C) 2016 Red Hat Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Red Hat nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

exec $VG ./test-gzip
2 changes: 1 addition & 1 deletion tests/test-help-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
set -e
source ./functions.sh

output="$(../src/nbdkit `nbdkit_plugin file` --help)"
output="$($VG ../src/nbdkit `nbdkit_plugin file` --help)"
if [[ ! ( "$output" =~ "nbdkit file plugin" ) ]]; then
echo "$0: unexpected output from nbdkit file --help"
echo "$output"
Expand Down
2 changes: 1 addition & 1 deletion tests/test-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

set -e

output="$(../src/nbdkit --help)"
output="$($VG ../src/nbdkit --help)"
if [[ ! ( "$output" =~ dump-config ) ]]; then
echo "$0: unexpected output from nbdkit --help"
echo "$output"
Expand Down
2 changes: 1 addition & 1 deletion tests/test-ipv4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for port in `seq 49152 65535`; do
done
echo picked unused port $port

../src/nbdkit -P ipv4.pid -p $port `nbdkit_plugin example1`
$VG ../src/nbdkit -P ipv4.pid -p $port `nbdkit_plugin example1`

# We may have to wait a short time for the pid file to appear.
for i in `seq 1 10`; do
Expand Down
Loading

0 comments on commit 271150d

Please sign in to comment.