[letor] Suppress unsigned-overflow in C++ stdlib
[xapian.git] / xapian-letor / tests / runtest.in
blobd5b2654ce506cc156b7b074dd4203955bf0957c1
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,2017,2018,2023 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 # Check for first argument starting with a '-' or no arguments and give usage
25 # message.
26 case $1:$# in
27 -*|*:0)
28 echo "syntax: $0 <test program> [<arguments>]"
29 echo "syntax: $0 gdb <test program> [<arguments>]"
30 echo "syntax: $0 <tool> <test program> [<arguments>]"
31 exit 1
33 esac
35 # Set srcdir if it isn't already.
36 : ${srcdir="@srcdir@"}
37 export srcdir
39 # Enable suppressions for UBSan (these are for defined-but-dubious behaviours
40 # such as unsigned overflow which UBSan can also catch - code in system library
41 # headers may trigger these checks). If UBSan isn't in use, setting this is
42 # harmless.
43 UBSAN_OPTIONS=suppressions=$srcdir/ubsan.supp
44 export UBSAN_OPTIONS
46 case $1 in
47 *test|*test@EXEEXT@) ;;
48 *gdb|"*gdb *")
49 # gdb needs special handling (--args)
50 gdb=$1
51 shift
52 : ${top_builddir=`echo "$0"|sed 's![^/]*$!..!'`}
53 export top_builddir
54 LIBTOOL=`echo '@LIBTOOL@'|sed 's,\$(SHELL),@SHELL@,g;s,\$(top_builddir),'"$top_builddir"',g'`
55 echo "Running test '$@' under $gdb"
56 exec $LIBTOOL --mode=execute $gdb --args "$@" ;;
58 # Handles any tool which can just be run as:
59 # TOOL TOOL-ARGS PROGRAM PROGRAM-ARGS
60 tool=$1
61 shift
62 : ${top_builddir=`echo "$0"|sed 's![^/]*$!..!'`}
63 export top_builddir
64 LIBTOOL=`echo '@LIBTOOL@'|sed 's,\$(SHELL),@SHELL@,g;s,\$(top_builddir),'"$top_builddir"',g'`
65 echo "Running test '$@' under $tool"
66 exec $LIBTOOL --mode=execute $tool "$@" ;;
67 esac
69 if [ -n "$XAPIAN_TESTSUITE_LD_PRELOAD" ] ; then
70 if [ -n "$LD_PRELOAD" ] ; then
71 LD_PRELOAD=$LD_PRELOAD:$XAPIAN_TESTSUITE_LD_PRELOAD
72 else
73 LD_PRELOAD=$XAPIAN_TESTSUITE_LD_PRELOAD
75 export LD_PRELOAD
78 # Allow configure probed value for EATMYDATA to be overridden by e.g.
79 # EATMYDATA= ./runtest ./apitest
80 test -z "${EATMYDATA+set}" && EATMYDATA="@EATMYDATA@"
82 # Allow configure probed value for VALGRIND to be overridden by e.g.
83 # VALGRIND= ./runtest ./apitest
84 test -z "${VALGRIND+set}" && VALGRIND="@VALGRIND@"
85 if test -z "$VALGRIND" ; then
86 # valgrind isn't involved, so just run the test program directly.
88 # If we're using glibc, tell it to call abort if malloc heap corruption is
89 # detected. This incurs a small time penalty, but is probably worth it.
90 # See "man malloc" on a recent Linux distro for details.
91 MALLOC_CHECK_=2
92 export MALLOC_CHECK_
94 # If we're using glibc, tell it to fill newly allocated memory (unless
95 # allocated by calloc) with this byte value and overwrite memory released
96 # by free with this value xor 0xff. See the mallopt(3) man page for
97 # details.
98 MALLOC_PERTURB_=42
99 export MALLOC_PERTURB_
101 if test -n "$EATMYDATA" ; then
102 echo "Running test '$@' under eatmydata"
104 exec $EATMYDATA "$@"
105 exit 1
108 # Get libtool to run the test program under valgrind. We have to use
109 # libtool --mode=execute because we want to run valgrind on the compiled
110 # C++ test program, not on the shell running the shell script wrapper libtool
111 # generates.
112 : ${top_builddir=`echo "$0"|sed 's![^/]*$!..!'`}
113 export top_builddir
114 LIBTOOL=`echo '@LIBTOOL@'|sed 's,\$(SHELL),@SHELL@,g;s,\$(top_builddir),'"$top_builddir"',g'`
116 # Tell the GNU C++ library (libstdc++) not to pool memory, which gives more
117 # accurate memory leak reports with valgrind.
118 GLIBCXX_FORCE_NEW=1
119 export GLIBCXX_FORCE_NEW
121 # Tell the testsuite to hook into valgrind.
122 XAPIAN_TESTSUITE_VALGRIND=1
123 export XAPIAN_TESTSUITE_VALGRIND
125 vg_opts='--log-file=.valgrind.log.%p --child-silent-after-fork=yes --leak-resolution=high --error-limit=no'
126 vg_opts="$vg_opts --suppressions=$srcdir/valgrind.supp"
127 if test -n "$EATMYDATA" ; then
128 echo "Running test '$@' under eatmydata and valgrind"
129 else
130 echo "Running test '$@' under valgrind"
132 # zlib can produce "uninitialised" output from "initialised" input - the output
133 # does decode to the input, so this is presumably just some unused bits in the
134 # output, so we use an LD_PRELOAD hack to get valgrind to check the input is
135 # initialised and then tell it that the output is initialised.
136 if [ -f zlib-vg.so ] ; then
137 if [ -n "$LD_PRELOAD" ] ; then
138 LD_PRELOAD=$LD_PRELOAD:./zlib-vg.so
139 else
140 LD_PRELOAD=./zlib-vg.so
142 export LD_PRELOAD
144 exec $EATMYDATA $LIBTOOL --mode=execute $VALGRIND $vg_opts "$@"