3 # Copyright (C) 2009-2020 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # This program is a test driver that supports running a test under valgrind.
20 # Usage: run-test CHECKER PROGRAM [ARGUMENT...]
25 # outputs to stdout the --help usage message.
29 Usage: run-test [OPTION...] CHECKER PROGRAM [ARGUMENT...]
31 Runs PROGRAM under the control of CHECKER.
33 CHECKER may be empty or a valgrind command with some options, such as
34 'valgrind --tool=memcheck --num-callers=20 --leak-check=yes --leak-resolution=high --show-reachable=yes'.
36 When CHECKER is not empty, it is recommended that the package has been
38 --disable-shared so that tests are real executables and not libtool
40 CFLAGS=\"-g\" so that valgrind shows line numbers.
42 Report bugs to Bruno Haible."
46 # outputs to stdout the --version message.
51 Copyright (C) 2020 Free Software Foundation, Inc.
52 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
53 This is free software: you are free to change and redistribute it.
54 There is NO WARRANTY, to the extent permitted by law.
56 Written by" "Bruno Haible"
59 # func_fatal_error message
60 # outputs to stderr a fatal error message, and terminates the program.
62 # - progname name of this program
65 echo "$progname: *** $1" 1>&2
66 echo "$progname: *** Stop." 1>&2
70 # Command-line option processing.
71 # Removes the OPTIONS from the arguments. Sets the variables:
72 # - checker wrapper program for executables
74 while test $# -gt 0; do
76 --help |
--hel |
--he |
--h )
79 --version |
--versio |
--versi |
--vers |
--ver |
--ve |
--v )
83 # Stop option processing
87 echo "run-test: unknown option $1" 1>&2
88 echo "Try 'run-test --help' for more information." 1>&2
95 if test $# -lt 2; then
96 echo "run-test: too few arguments" 1>&2
97 echo "Try 'run-test --help' for more information." 1>&2
105 if test -z "$checker"; then
106 # No checker. Run the test directly.
109 # Support environments where sh exists but not /bin/sh.
117 # Using valgrind. We want to apply valgrind only to executables, not to
118 # shell scripts, because
119 # 1. we don't want to look for memory leaks in bash,
120 # 2. on a bi-arch system, we would get an error message such as
121 # "valgrind: wrong executable class (eg. 32-bit instead of 64-bit)".
124 # A shell script. Ignore the checker.
125 # Support environments where sh exists but not /bin/sh.
129 # The 'file' command is not portable enough. So, look
130 # at the first two bytes of the file. Are they '#!'?
131 if { if od -A x
< /dev
/null
>/dev
/null
2>/dev
/null
; then
133 firstbytes
=`od -A n -t o1 -N 2 < "$1" | tr -d ' '`
136 firstbytes
=`dd if="$1" bs=1 count=2 2>/dev/null | hexdump -e '1/1 "%03o"'`
138 test "$firstbytes" = "043041"
140 # A shell script. Ignore the checker.
143 # An executable. Use the checker.