]>
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= |
1b03e2cd | 29 | |
6163259c RM |
30 | function num_cpus() |
31 | { | |
5917d17f RM |
32 | local num |
33 | ||
34 | # coreutils | |
35 | if num=$(nproc --all 2>/dev/null); then | |
36 | : | |
37 | # BSD, OSX | |
38 | elif num=$(sysctl -n hw.ncpu 2>/dev/null); then | |
39 | : | |
40 | else | |
41 | num=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null) | |
42 | fi | |
43 | ||
44 | # translate garbage output to "1" | |
45 | if test "$num" -gt "0" 2>/dev/null ;then | |
46 | echo "$num" | |
6163259c RM |
47 | else |
48 | echo 1 | |
49 | fi | |
50 | } | |
51 | ||
51658498 RM |
52 | function find_test_scripts() |
53 | { | |
54 | local searchdir="$1" | |
55 | find "$searchdir" -type f -regex ".*/[^\.~]*" \ | |
56 | \( -perm -u=x -o -perm -g=x -o -perm -o=x \) | |
57 | } | |
58 | ||
949cf64b KZ |
59 | while [ -n "$1" ]; do |
60 | case "$1" in | |
855f7f06 RM |
61 | --force |\ |
62 | --fake |\ | |
d3f58f8a | 63 | --memcheck-valgrind |\ |
9deb8c7d | 64 | --nolocks |\ |
74fe554a | 65 | --show-diff |\ |
855f7f06 RM |
66 | --verbose |\ |
67 | --skip-loopdevs |\ | |
7c90efa3 | 68 | --noskip-commands |\ |
855f7f06 RM |
69 | --parsable) |
70 | # these options are simply forwarded to the test scripts | |
71 | OPTS="$OPTS $1" | |
d995c2f0 | 72 | ;; |
0b17c997 KZ |
73 | --memcheck-asan) |
74 | OPTS="$OPTS $1" | |
75 | has_asan_opt="yes" | |
76 | ;; | |
43b4a4d3 KZ |
77 | --use-system-commands) |
78 | OPTS="$OPTS $1" | |
79 | SYSCOMMANDS="yes" | |
80 | ;; | |
81 | ||
1b03e2cd KZ |
82 | --nonroot) |
83 | if [ $(id -ru) -eq 0 ]; then | |
9779f598 | 84 | echo "Ignore util-linux test suite [non-root UID expected]." |
1b03e2cd KZ |
85 | exit 0 |
86 | fi | |
87 | ;; | |
88 | --srcdir=*) | |
89 | top_srcdir="${1##--srcdir=}" | |
90 | ;; | |
91 | --builddir=*) | |
92 | top_builddir="${1##--builddir=}" | |
93 | ;; | |
40e6f7a0 SK |
94 | --parallel=*) |
95 | paraller_jobs="${1##--parallel=}" | |
4520caa1 | 96 | if ! [ "$paraller_jobs" -ge 0 ] 2>/dev/null; then |
07b1ea7c RM |
97 | echo "invalid argument '$paraller_jobs' for --parallel=" |
98 | exit 1 | |
99 | fi | |
40e6f7a0 SK |
100 | ;; |
101 | --parallel) | |
6163259c | 102 | paraller_jobs=$(num_cpus) |
40e6f7a0 | 103 | ;; |
c8aa62a8 KZ |
104 | --exclude=*) |
105 | EXCLUDETESTS="${1##--exclude=}" | |
106 | ;; | |
949cf64b KZ |
107 | --*) |
108 | echo "Unknown option $1" | |
1b03e2cd KZ |
109 | echo "Usage: " |
110 | echo " $(basename $0) [options] [<component> ...]" | |
111 | echo "Options:" | |
43b4a4d3 KZ |
112 | echo " --force execute demanding tests" |
113 | echo " --fake do not run, setup tests only" | |
114 | echo " --memcheck-valgrind run with valgrind" | |
115 | echo " --memcheck-asan enable ASAN (requires ./configure --enable-asan)" | |
116 | echo " --nolocks don't use flock to lock resources" | |
117 | echo " --verbose verbose mode" | |
118 | echo " --show-diff show diff from failed tests" | |
119 | echo " --nonroot ignore test suite if user is root" | |
120 | echo " --use-system-commands use PATH rather than builddir" | |
7c90efa3 | 121 | echo " --noskip-commands fail on missing commands" |
43b4a4d3 KZ |
122 | echo " --srcdir=<path> autotools top source directory" |
123 | echo " --builddir=<path> autotools top build directory" | |
124 | echo " --parallel=<num> number of parallel test jobs, default: num cpus" | |
125 | echo " --exclude=<list> exclude tests by list '<utilname>/<testname> ..'" | |
1b03e2cd | 126 | echo |
a1be90bb | 127 | exit 1 |
949cf64b KZ |
128 | ;; |
129 | ||
130 | *) | |
131 | SUBTESTS="$SUBTESTS $1" | |
132 | ;; | |
133 | esac | |
134 | shift | |
135 | done | |
136 | ||
1b03e2cd KZ |
137 | # For compatibility with autotools is necessary to differentiate between source |
138 | # (with test scripts) and build (with temporary files) directories when | |
139 | # executed by our build-system. | |
140 | # | |
141 | # The default is the source tree with this script. | |
142 | # | |
143 | if [ -z "$top_srcdir" ]; then | |
144 | top_srcdir="$TS_TOPDIR/.." | |
145 | fi | |
146 | if [ -z "$top_builddir" ]; then | |
147 | top_builddir="$TS_TOPDIR/.." | |
148 | fi | |
149 | ||
150 | OPTS="$OPTS --srcdir=$top_srcdir --builddir=$top_builddir" | |
151 | ||
0b17c997 KZ |
152 | # Auto-enable ASAN to avoid conflicts between tests and binaries |
153 | if [ -z "$has_asan_opt" ]; then | |
154 | asan=$(awk '/^ASAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile) | |
155 | if [ -n "$asan" ]; then | |
156 | OPTS="$OPTS --memcheck-asan" | |
157 | fi | |
158 | fi | |
159 | ||
40e6f7a0 | 160 | declare -a comps |
949cf64b KZ |
161 | if [ -n "$SUBTESTS" ]; then |
162 | # selected tests only | |
163 | for s in $SUBTESTS; do | |
7cd6d50a | 164 | if [ -e "$top_srcdir/tests/ts/$s" ]; then |
51658498 | 165 | comps+=( $(find_test_scripts "$top_srcdir/tests/ts/$s") ) || exit 1 |
949cf64b KZ |
166 | else |
167 | echo "Unknown test component '$s'" | |
168 | exit 1 | |
169 | fi | |
170 | done | |
171 | else | |
43b4a4d3 | 172 | if [ -z "$SYSCOMMANDS" -a ! -f "$top_builddir/test_ttyutils" ]; then |
b5606aad KZ |
173 | echo "Tests not compiled! Run 'make check' to fix the problem." |
174 | exit 1 | |
175 | fi | |
b5606aad | 176 | |
51658498 | 177 | comps=( $(find_test_scripts "$top_srcdir/tests/ts") ) || exit 1 |
a1be90bb KZ |
178 | fi |
179 | ||
c8aa62a8 KZ |
180 | if [ -n "$EXCLUDETESTS" ]; then |
181 | declare -a xcomps # temporary array | |
182 | for ts in ${comps[@]}; do | |
183 | tsname=${ts##*ts/} # test name | |
184 | ||
185 | if [[ "$EXCLUDETESTS" == *${tsname}* ]]; then | |
186 | #echo "Ignore ${tsname}." | |
187 | true | |
188 | else | |
189 | xcomps+=($ts) | |
190 | fi | |
191 | done | |
192 | comps=("${xcomps[@]}") # replace the array | |
193 | fi | |
b5606aad | 194 | |
72c92179 KZ |
195 | unset LIBMOUNT_DEBUG |
196 | unset LIBBLKID_DEBUG | |
76041e70 | 197 | unset LIBFDISK_DEBUG |
c8aa62a8 | 198 | unset LIBSMARTCOLS_DEBUG |
72c92179 | 199 | |
e83446da | 200 | echo |
21d1fa53 | 201 | echo "-------------------- util-linux regression tests --------------------" |
e83446da | 202 | echo |
c9860428 KZ |
203 | echo " For development purpose only. " |
204 | echo " Don't execute on production system! " | |
205 | echo | |
e83446da | 206 | |
b267ec30 KZ |
207 | # TODO: add more information about system |
208 | printf "%13s: %-30s " "kernel" "$(uname -r)" | |
209 | echo | |
210 | echo | |
0b17c997 KZ |
211 | echo " options: $(echo $OPTS | sed 's/ / \\\n /g')" |
212 | echo | |
b267ec30 | 213 | |
07b1ea7c RM |
214 | if [ "$paraller_jobs" -ne 1 ]; then |
215 | tmp=$paraller_jobs | |
216 | [ "$paraller_jobs" -eq 0 ] && tmp=infinite | |
217 | echo " Executing the tests in parallel ($tmp jobs) " | |
40e6f7a0 | 218 | echo |
81b3d7ed | 219 | OPTS="$OPTS --parallel" |
40e6f7a0 | 220 | fi |
e83446da | 221 | |
40e6f7a0 | 222 | count=0 |
51f9b431 | 223 | >| $top_builddir/tests/failures |
40e6f7a0 | 224 | printf "%s\n" ${comps[*]} | |
667e4735 | 225 | sort | |
40e6f7a0 | 226 | xargs -I '{}' -P $paraller_jobs -n 1 bash -c "'{}' \"$OPTS\" || |
51f9b431 | 227 | echo 1 >> $top_builddir/tests/failures" |
07b1ea7c RM |
228 | if [ $? != 0 ]; then |
229 | echo "xargs error" >&2 | |
230 | exit 1 | |
231 | fi | |
40e6f7a0 | 232 | declare -a fail_file |
ddd2570f | 233 | fail_file=( $( < $top_builddir/tests/failures ) ) || exit 1 |
51f9b431 | 234 | rm -f $top_builddir/tests/failures |
e83446da KZ |
235 | echo |
236 | echo "---------------------------------------------------------------------" | |
40e6f7a0 SK |
237 | if [ ${#fail_file[@]} -eq 0 ]; then |
238 | echo " All ${#comps[@]} tests PASSED" | |
5b0d01d6 | 239 | res=0 |
e83446da | 240 | else |
40e6f7a0 | 241 | echo " ${#fail_file[@]} tests of ${#comps[@]} FAILED" |
5b0d01d6 | 242 | res=1 |
e83446da KZ |
243 | fi |
244 | echo "---------------------------------------------------------------------" | |
5b0d01d6 | 245 | exit $res |