Document xapian-compact --blocksize takes an argument
[xapian.git] / xapian-core / tests / runtest.in
blobaa252e4b990387ba78faeb52ee56afcacbe04deb
1 #!/bin/sh
2 # @configure_input@
4 # Wrapper script for running test programs (using libtool, valgrind and
5 # eatmydata if required).
7 # Copyright (C) 2003,2004,2007,2008,2009,2010,2013 Olly Betts
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of the
12 # License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 # USA
24 if test 0 = "$#"; then
25 echo "syntax: $0 <test program> [<arguments>]"
26 echo "syntax: $0 gdb <test program> [<arguments>]"
27 echo "syntax: $0 <tool> <test program> [<arguments>]"
28 exit 1
31 # Set srcdir if it isn't already.
32 : ${srcdir="@srcdir@"}
33 export srcdir
35 case $1 in
36 *test|*test@EXEEXT@) ;;
37 *gdb|"*gdb *")
38 # gdb needs special handling (--args)
39 gdb=$1
40 shift
41 : ${top_builddir=`echo "$0"|sed 's![^/]*$!..!'`}
42 export top_builddir
43 LIBTOOL=`echo '@LIBTOOL@'|sed 's,\$(SHELL),@SHELL@,g;s,\$(top_builddir),'"$top_builddir"',g'`
44 echo "Running test '$@' under $gdb"
45 exec $LIBTOOL --mode=execute $gdb --args "$@" ;;
47 # Handles any tool which can just be run as:
48 # TOOL TOOL-ARGS PROGRAM PROGRAM-ARGS
49 tool=$1
50 shift
51 : ${top_builddir=`echo "$0"|sed 's![^/]*$!..!'`}
52 export top_builddir
53 LIBTOOL=`echo '@LIBTOOL@'|sed 's,\$(SHELL),@SHELL@,g;s,\$(top_builddir),'"$top_builddir"',g'`
54 echo "Running test '$@' under $tool"
55 exec $LIBTOOL --mode=execute $tool "$@" ;;
56 esac
58 if [ -n "$XAPIAN_TESTSUITE_LD_PRELOAD" ] ; then
59 if [ -n "$LD_PRELOAD" ] ; then
60 LD_PRELOAD=$LD_PRELOAD:$XAPIAN_TESTSUITE_LD_PRELOAD
61 else
62 LD_PRELOAD=$XAPIAN_TESTSUITE_LD_PRELOAD
64 export LD_PRELOAD
67 # Allow configure probed value for EATMYDATA to be overridden by e.g.
68 # EATMYDATA= ./runtest ./apitest
69 test -z "${EATMYDATA+set}" && EATMYDATA="@EATMYDATA@"
71 # Allow configure probed value for VALGRIND to be overridden by e.g.
72 # VALGRIND= ./runtest ./apitest
73 test -z "${VALGRIND+set}" && VALGRIND="@VALGRIND@"
74 if test -z "$VALGRIND" ; then
75 # valgrind isn't involved, so just run the test program directly.
77 # If we're using glibc, tell it to call abort if malloc heap corruption is
78 # detected. This incurs a small time penalty, but is probably worth it.
79 # See "man malloc" on a recent Linux distro for details.
80 MALLOC_CHECK_=2
81 export MALLOC_CHECK_
83 # If we're using glibc, tell it to fill newly allocated memory (unless
84 # allocated by calloc) with this byte value and overwrite memory released
85 # by free with this value xor 0xff.
86 # http://udrepper.livejournal.com/11429.html
87 # Just some value, y'know?
88 MALLOC_PERTURB_=42
89 export MALLOC_PERTURB_
91 if test -n "$EATMYDATA" ; then
92 echo "Running test '$@' under eatmydata"
94 exec $EATMYDATA "$@"
95 exit 1
98 # Get libtool to run the test program under valgrind. We have to use
99 # libtool --mode=execute because we want to run valgrind on the compiled
100 # C++ test program, not on the shell running the shell script wrapper libtool
101 # generates.
102 : ${top_builddir=`echo "$0"|sed 's![^/]*$!..!'`}
103 export top_builddir
104 LIBTOOL=`echo '@LIBTOOL@'|sed 's,\$(SHELL),@SHELL@,g;s,\$(top_builddir),'"$top_builddir"',g'`
106 # For GCC 3.4 and newer, force the GNU C++ STL to not pool memory, which gives
107 # more accurate memory leak reports with valgrind.
108 GLIBCXX_FORCE_NEW=1
109 export GLIBCXX_FORCE_NEW
111 # Tell the testsuite to hook into valgrind.
112 XAPIAN_TESTSUITE_VALGRIND=1
113 export XAPIAN_TESTSUITE_VALGRIND
115 vg_opts='--log-file=.valgrind.log.%p --leak-resolution=high'
116 vg_opts="$vg_opts --suppressions=$srcdir/valgrind.supp"
117 if test -n "$EATMYDATA" ; then
118 echo "Running test '$@' under eatmydata and valgrind"
119 else
120 echo "Running test '$@' under valgrind"
122 # zlib can produce "uninitialised" output from "initialised" input - the output
123 # does decode to the input, so this is presumably just some unused bits in the
124 # output, so we use an LD_PRELOAD hack to get valgrind to check the input is
125 # initialised and then tell it that the output is initialised.
126 if [ -f zlib-vg.so ] ; then
127 if [ -n "$LD_PRELOAD" ] ; then
128 LD_PRELOAD=$LD_PRELOAD:./zlib-vg.so
129 else
130 LD_PRELOAD=./zlib-vg.so
132 export LD_PRELOAD
134 exec $EATMYDATA $LIBTOOL --mode=execute $VALGRIND $vg_opts "$@"