]>
Commit | Line | Data |
---|---|---|
e83446da KZ |
1 | #!/bin/bash |
2 | ||
92f2c23e KZ |
3 | # |
4 | # Copyright (C) 2007 Karel Zak <kzak@redhat.com> | |
5 | # | |
601d12fb | 6 | # This file is part of util-linux. |
92f2c23e KZ |
7 | # |
8 | # This file is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 2 of the License, or | |
11 | # (at your option) any later version. | |
12 | # | |
13 | # This file is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
e83446da | 18 | |
e130ce53 | 19 | TS_TOPDIR=$(cd ${0%/*} && pwd) |
949cf64b | 20 | SUBTESTS= |
c8aa62a8 | 21 | EXCLUDETESTS= |
949cf64b | 22 | OPTS= |
43b4a4d3 | 23 | SYSCOMMANDS= |
949cf64b | 24 | |
1b03e2cd KZ |
25 | top_srcdir= |
26 | top_builddir= | |
40e6f7a0 | 27 | paraller_jobs=1 |
0b17c997 | 28 | has_asan_opt= |
e6a4d8cc | 29 | has_ubsan_opt= |
1b03e2cd | 30 | |
6163259c RM |
31 | function num_cpus() |
32 | { | |
5917d17f RM |
33 | local num |
34 | ||
35 | # coreutils | |
616f57d9 | 36 | if num=$(nproc 2>/dev/null); then |
5917d17f RM |
37 | : |
38 | # BSD, OSX | |
39 | elif num=$(sysctl -n hw.ncpu 2>/dev/null); then | |
40 | : | |
41 | else | |
42 | num=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null) | |
43 | fi | |
44 | ||
45 | # translate garbage output to "1" | |
46 | if test "$num" -gt "0" 2>/dev/null ;then | |
47 | echo "$num" | |
6163259c RM |
48 | else |
49 | echo 1 | |
50 | fi | |
51 | } | |
52 | ||
51658498 RM |
53 | function find_test_scripts() |
54 | { | |
55 | local searchdir="$1" | |
56 | find "$searchdir" -type f -regex ".*/[^\.~]*" \ | |
57 | \( -perm -u=x -o -perm -g=x -o -perm -o=x \) | |
58 | } | |
59 | ||
949cf64b KZ |
60 | while [ -n "$1" ]; do |
61 | case "$1" in | |
855f7f06 RM |
62 | --force |\ |
63 | --fake |\ | |
d3f58f8a | 64 | --memcheck-valgrind |\ |
9deb8c7d | 65 | --nolocks |\ |
74fe554a | 66 | --show-diff |\ |
855f7f06 RM |
67 | --verbose |\ |
68 | --skip-loopdevs |\ | |
7c90efa3 | 69 | --noskip-commands |\ |
855f7f06 RM |
70 | --parsable) |
71 | # these options are simply forwarded to the test scripts | |
72 | OPTS="$OPTS $1" | |
d995c2f0 | 73 | ;; |
0b17c997 KZ |
74 | --memcheck-asan) |
75 | OPTS="$OPTS $1" | |
76 | has_asan_opt="yes" | |
77 | ;; | |
e6a4d8cc EV |
78 | --memcheck-ubsan) |
79 | OPTS="$OPTS $1" | |
80 | has_ubsan_opt="yes" | |
81 | ;; | |
43b4a4d3 KZ |
82 | --use-system-commands) |
83 | OPTS="$OPTS $1" | |
84 | SYSCOMMANDS="yes" | |
85 | ;; | |
86 | ||
1b03e2cd KZ |
87 | --nonroot) |
88 | if [ $(id -ru) -eq 0 ]; then | |
9779f598 | 89 | echo "Ignore util-linux test suite [non-root UID expected]." |
1b03e2cd KZ |
90 | exit 0 |
91 | fi | |
92 | ;; | |
93 | --srcdir=*) | |
94 | top_srcdir="${1##--srcdir=}" | |
95 | ;; | |
96 | --builddir=*) | |
97 | top_builddir="${1##--builddir=}" | |
98 | ;; | |
40e6f7a0 SK |
99 | --parallel=*) |
100 | paraller_jobs="${1##--parallel=}" | |
406fb253 | 101 | if ! [ "$paraller_jobs" -ge 0 ] 2>/dev/null; then |
07b1ea7c RM |
102 | echo "invalid argument '$paraller_jobs' for --parallel=" |
103 | exit 1 | |
104 | fi | |
40e6f7a0 SK |
105 | ;; |
106 | --parallel) | |
6163259c | 107 | paraller_jobs=$(num_cpus) |
40e6f7a0 | 108 | ;; |
406fb253 KZ |
109 | --parsable) |
110 | OPTS="$OPTS $1" | |
111 | ;; | |
c8aa62a8 KZ |
112 | --exclude=*) |
113 | EXCLUDETESTS="${1##--exclude=}" | |
114 | ;; | |
949cf64b KZ |
115 | --*) |
116 | echo "Unknown option $1" | |
1b03e2cd KZ |
117 | echo "Usage: " |
118 | echo " $(basename $0) [options] [<component> ...]" | |
119 | echo "Options:" | |
43b4a4d3 KZ |
120 | echo " --force execute demanding tests" |
121 | echo " --fake do not run, setup tests only" | |
122 | echo " --memcheck-valgrind run with valgrind" | |
123 | echo " --memcheck-asan enable ASAN (requires ./configure --enable-asan)" | |
124 | echo " --nolocks don't use flock to lock resources" | |
125 | echo " --verbose verbose mode" | |
126 | echo " --show-diff show diff from failed tests" | |
127 | echo " --nonroot ignore test suite if user is root" | |
128 | echo " --use-system-commands use PATH rather than builddir" | |
7c90efa3 | 129 | echo " --noskip-commands fail on missing commands" |
43b4a4d3 KZ |
130 | echo " --srcdir=<path> autotools top source directory" |
131 | echo " --builddir=<path> autotools top build directory" | |
406fb253 KZ |
132 | echo " --parallel=<num> number of parallel test jobs, default: num cpus" |
133 | echo " --parsable use parsable output (default on --parallel)" | |
43b4a4d3 | 134 | echo " --exclude=<list> exclude tests by list '<utilname>/<testname> ..'" |
1b03e2cd | 135 | echo |
a1be90bb | 136 | exit 1 |
949cf64b KZ |
137 | ;; |
138 | ||
139 | *) | |
140 | SUBTESTS="$SUBTESTS $1" | |
141 | ;; | |
142 | esac | |
143 | shift | |
144 | done | |
145 | ||
1b03e2cd KZ |
146 | # For compatibility with autotools is necessary to differentiate between source |
147 | # (with test scripts) and build (with temporary files) directories when | |
148 | # executed by our build-system. | |
149 | # | |
150 | # The default is the source tree with this script. | |
151 | # | |
152 | if [ -z "$top_srcdir" ]; then | |
153 | top_srcdir="$TS_TOPDIR/.." | |
154 | fi | |
155 | if [ -z "$top_builddir" ]; then | |
156 | top_builddir="$TS_TOPDIR/.." | |
d928b9af KZ |
157 | if [ -e "$top_builddir/build/meson.conf" ]; then |
158 | top_builddir="$TS_TOPDIR/../build" | |
dc1d0f8d TW |
159 | elif [ -e "$PWD/meson.conf" ]; then |
160 | top_builddir="$PWD" | |
d928b9af | 161 | fi |
1b03e2cd KZ |
162 | fi |
163 | ||
164 | OPTS="$OPTS --srcdir=$top_srcdir --builddir=$top_builddir" | |
165 | ||
0b17c997 KZ |
166 | # Auto-enable ASAN to avoid conflicts between tests and binaries |
167 | if [ -z "$has_asan_opt" ]; then | |
d4c880d5 ZJS |
168 | if [ -e "$top_builddir/Makefile" ]; then |
169 | asan=$(awk '/^ASAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile) | |
331c5e0c | 170 | elif [ -f "$top_builddir/meson.conf" ]; then |
d4c880d5 ZJS |
171 | . "$top_builddir/meson.conf" |
172 | fi | |
0b17c997 KZ |
173 | if [ -n "$asan" ]; then |
174 | OPTS="$OPTS --memcheck-asan" | |
175 | fi | |
176 | fi | |
177 | ||
e6a4d8cc | 178 | if [ -z "$has_ubsan_opt" ]; then |
d928b9af KZ |
179 | if [ -e "$top_builddir/Makefile" ]; then |
180 | ubsan=$(awk '/^UBSAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile) | |
181 | fi | |
e6a4d8cc EV |
182 | if [ -n "$ubsan" ]; then |
183 | OPTS="$OPTS --memcheck-ubsan" | |
184 | fi | |
185 | fi | |
186 | ||
40e6f7a0 | 187 | declare -a comps |
949cf64b KZ |
188 | if [ -n "$SUBTESTS" ]; then |
189 | # selected tests only | |
190 | for s in $SUBTESTS; do | |
7cd6d50a | 191 | if [ -e "$top_srcdir/tests/ts/$s" ]; then |
51658498 | 192 | comps+=( $(find_test_scripts "$top_srcdir/tests/ts/$s") ) || exit 1 |
949cf64b KZ |
193 | else |
194 | echo "Unknown test component '$s'" | |
195 | exit 1 | |
196 | fi | |
197 | done | |
198 | else | |
43b4a4d3 | 199 | if [ -z "$SYSCOMMANDS" -a ! -f "$top_builddir/test_ttyutils" ]; then |
60bad224 | 200 | echo "Tests not compiled! Run 'make check-programs' to fix the problem." |
b5606aad KZ |
201 | exit 1 |
202 | fi | |
b5606aad | 203 | |
51658498 | 204 | comps=( $(find_test_scripts "$top_srcdir/tests/ts") ) || exit 1 |
a1be90bb KZ |
205 | fi |
206 | ||
c8aa62a8 KZ |
207 | if [ -n "$EXCLUDETESTS" ]; then |
208 | declare -a xcomps # temporary array | |
209 | for ts in ${comps[@]}; do | |
210 | tsname=${ts##*ts/} # test name | |
211 | ||
212 | if [[ "$EXCLUDETESTS" == *${tsname}* ]]; then | |
213 | #echo "Ignore ${tsname}." | |
214 | true | |
215 | else | |
216 | xcomps+=($ts) | |
217 | fi | |
218 | done | |
219 | comps=("${xcomps[@]}") # replace the array | |
220 | fi | |
b5606aad | 221 | |
72c92179 KZ |
222 | unset LIBMOUNT_DEBUG |
223 | unset LIBBLKID_DEBUG | |
76041e70 | 224 | unset LIBFDISK_DEBUG |
c8aa62a8 | 225 | unset LIBSMARTCOLS_DEBUG |
72c92179 | 226 | |
e83446da | 227 | echo |
21d1fa53 | 228 | echo "-------------------- util-linux regression tests --------------------" |
e83446da | 229 | echo |
c9860428 KZ |
230 | echo " For development purpose only. " |
231 | echo " Don't execute on production system! " | |
232 | echo | |
e83446da | 233 | |
b267ec30 KZ |
234 | # TODO: add more information about system |
235 | printf "%13s: %-30s " "kernel" "$(uname -r)" | |
236 | echo | |
237 | echo | |
0b17c997 KZ |
238 | echo " options: $(echo $OPTS | sed 's/ / \\\n /g')" |
239 | echo | |
b267ec30 | 240 | |
07b1ea7c RM |
241 | if [ "$paraller_jobs" -ne 1 ]; then |
242 | tmp=$paraller_jobs | |
243 | [ "$paraller_jobs" -eq 0 ] && tmp=infinite | |
244 | echo " Executing the tests in parallel ($tmp jobs) " | |
40e6f7a0 | 245 | echo |
81b3d7ed | 246 | OPTS="$OPTS --parallel" |
40e6f7a0 | 247 | fi |
e83446da | 248 | |
40e6f7a0 | 249 | count=0 |
9fb5486c | 250 | mkdir -p $top_builddir/tests/ |
51f9b431 | 251 | >| $top_builddir/tests/failures |
40e6f7a0 | 252 | printf "%s\n" ${comps[*]} | |
667e4735 | 253 | sort | |
40e6f7a0 | 254 | xargs -I '{}' -P $paraller_jobs -n 1 bash -c "'{}' \"$OPTS\" || |
4848ba31 | 255 | echo '{}' >> $top_builddir/tests/failures" |
07b1ea7c RM |
256 | if [ $? != 0 ]; then |
257 | echo "xargs error" >&2 | |
258 | exit 1 | |
259 | fi | |
4848ba31 | 260 | |
40e6f7a0 | 261 | declare -a fail_file |
ddd2570f | 262 | fail_file=( $( < $top_builddir/tests/failures ) ) || exit 1 |
e83446da KZ |
263 | echo |
264 | echo "---------------------------------------------------------------------" | |
40e6f7a0 SK |
265 | if [ ${#fail_file[@]} -eq 0 ]; then |
266 | echo " All ${#comps[@]} tests PASSED" | |
5b0d01d6 | 267 | res=0 |
e83446da | 268 | else |
40e6f7a0 | 269 | echo " ${#fail_file[@]} tests of ${#comps[@]} FAILED" |
4848ba31 KZ |
270 | |
271 | echo | |
272 | for ts in ${fail_file[@]}; do | |
273 | NAME=$(basename $ts) | |
274 | COMPONENT=$(basename $(dirname $ts)) | |
275 | echo " $COMPONENT/$NAME" | |
276 | done | |
5b0d01d6 | 277 | res=1 |
e83446da KZ |
278 | fi |
279 | echo "---------------------------------------------------------------------" | |
4848ba31 KZ |
280 | |
281 | rm -f $top_builddir/tests/failures | |
5b0d01d6 | 282 | exit $res |