annotate build-aux/run-test @ 40181:4edc083b6693

Add script for running tests under valgrind. * build-aux/run-test: New file, from GNU libunistring. * doc/valgrind-tests.texi: Rewritten to mention alternative approaches as well.
author Bruno Haible <bruno@clisp.org>
date Mon, 04 Feb 2019 22:35:38 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40181
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 #!/bin/sh
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 #
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 # Copyright (C) 2009-2019 Free Software Foundation, Inc.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 #
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 # This program is free software: you can redistribute it and/or modify
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 # the Free Software Foundation; either version 3 of the License, or
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 # (at your option) any later version.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 #
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 # GNU General Public License for more details.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 #
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 # This program is a test driver that supports running a test under valgrind.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 # Usage: run-test CHECKER PROGRAM [ARGUMENT...]
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 progname=$0
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 # func_usage
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 # outputs to stdout the --help usage message.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 func_usage ()
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 echo "\
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 Usage: run-test [OPTION...] CHECKER PROGRAM [ARGUMENT...]
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 Runs PROGRAM under the control of CHECKER.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 CHECKER may be empty or a valgrind command with some options, such as
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 'valgrind --tool=memcheck --num-callers=20 --leak-check=yes --leak-resolution=high --show-reachable=yes'.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 When CHECKER is not empty, it is recommended that the package has been
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 configured with
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 --disable-shared so that tests are real executables and not libtool
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 wrapper scripts, and
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 CFLAGS=\"-g\" so that valgrind shows line numbers.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 Report bugs to Bruno Haible."
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 }
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 # func_version
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 # outputs to stdout the --version message.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 func_version ()
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 echo "\
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 run-test (GNU gnulib)
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 Copyright (C) 2009-2019 Free Software Foundation, Inc.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 This is free software: you are free to change and redistribute it.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 There is NO WARRANTY, to the extent permitted by law.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 Written by" "Bruno Haible"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 }
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 # func_fatal_error message
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 # outputs to stderr a fatal error message, and terminates the program.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 # Input:
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 # - progname name of this program
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 func_fatal_error ()
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 {
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 echo "$progname: *** $1" 1>&2
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 echo "$progname: *** Stop." 1>&2
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 func_exit 1
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 }
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 # Command-line option processing.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 # Removes the OPTIONS from the arguments. Sets the variables:
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 # - checker wrapper program for executables
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 {
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 while test $# -gt 0; do
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 case "$1" in
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 --help | --hel | --he | --h )
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 func_usage
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 exit $? ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 --version | --versio | --versi | --vers | --ver | --ve | --v )
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 func_version
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 exit $? ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 -- )
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 # Stop option processing
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 shift
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 break ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 -* )
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 echo "run-test: unknown option $1" 1>&2
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 echo "Try 'run-test --help' for more information." 1>&2
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 exit 1 ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 * )
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 break ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 esac
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 done
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 if test $# -lt 2; then
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 echo "run-test: too few arguments" 1>&2
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 echo "Try 'run-test --help' for more information." 1>&2
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 exit 1
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 fi
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 checker="$1"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 shift
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 }
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 if test -z "$checker"; then
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 # No checker. Run the test directly.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 case "$1" in
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 *.sh)
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 # Support environments where sh exists but not /bin/sh.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 exec sh "$@"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 *)
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 exec "$@"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 esac
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 else
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 # Using valgrind. We want to apply valgrind only to executables, not to
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 # shell scripts, because
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 # 1. we don't want to look for memory leaks in bash,
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 # 2. on a bi-arch system, we would get an error message such as
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 # "valgrind: wrong executable class (eg. 32-bit instead of 64-bit)".
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 case "$1" in
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 *.sh)
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 # A shell script. Ignore the checker.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 # Support environments where sh exists but not /bin/sh.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 exec sh "$@"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 *)
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 # The 'file' command is not portable enough. So, look
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 # at the first two bytes of the file. Are they '#!'?
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 if { if od -A x < /dev/null >/dev/null 2>/dev/null; then
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 # Use POSIX od.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 firstbytes=`od -A n -t o1 -N 2 < "$1" | tr -d ' '`
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 else
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 # Use BSD hexdump.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 firstbytes=`dd if="$1" bs=1 count=2 2>/dev/null | hexdump -e '1/1 "%03o"'`
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 fi
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 test "$firstbytes" = "043041"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 }; then
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 # A shell script. Ignore the checker.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 exec "$@"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 else
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 # An executable. Use the checker.
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 exec $checker "$@"
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 fi
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 ;;
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 esac
4edc083b6693 Add script for running tests under valgrind.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 fi