]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/run.sh
4 # Copyright (C) 2007 Karel Zak <kzak@redhat.com>
6 # This file is part of util-linux.
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.
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.
19 TS_TOPDIR
=$
(cd ${0%/*} && pwd)
36 if num
=$
(nproc
2>/dev
/null
); then
39 elif num
=$
(sysctl
-n hw.ncpu
2>/dev
/null
); then
42 num
=$
(grep -c "^processor" /proc
/cpuinfo
2>/dev
/null
)
45 # translate garbage output to "1"
46 if test "$num" -gt "0" 2>/dev
/null
;then
53 function find_test_scripts
()
56 find "$searchdir" -type f
-regex ".*/[^\.~]*" \
57 \
( -perm -u=x
-o -perm -g=x
-o -perm -o=x \
)
64 --memcheck-valgrind |\
71 # these options are simply forwarded to the test scripts
82 --use-system-commands)
88 if [ $
(id
-ru) -eq 0 ]; then
89 echo "Ignore util-linux test suite [non-root UID expected]."
94 top_srcdir
="${1##--srcdir=}"
97 top_builddir
="${1##--builddir=}"
100 paraller_jobs
="${1##--parallel=}"
101 if ! [ "$paraller_jobs" -ge 0 ] 2>/dev
/null
; then
102 echo "invalid argument '$paraller_jobs' for --parallel="
107 paraller_jobs
=$
(num_cpus
)
113 EXCLUDETESTS
="${1##--exclude=}"
116 echo "Unknown option $1"
118 echo " $(basename $0) [options] [<component> ...]"
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"
129 echo " --noskip-commands fail on missing commands"
130 echo " --srcdir=<path> autotools top source directory"
131 echo " --builddir=<path> autotools top build directory"
132 echo " --parallel=<num> number of parallel test jobs, default: num cpus"
133 echo " --parsable use parsable output (default on --parallel)"
134 echo " --exclude=<list> exclude tests by list '<utilname>/<testname> ..'"
140 SUBTESTS
="$SUBTESTS $1"
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.
150 # The default is the source tree with this script.
152 if [ -z "$top_srcdir" ]; then
153 top_srcdir
="$TS_TOPDIR/.."
155 if [ -z "$top_builddir" ]; then
156 top_builddir
="$TS_TOPDIR/.."
157 if [ -e "$top_builddir/build/meson.conf" ]; then
158 top_builddir
="$TS_TOPDIR/../build"
159 elif [ -e "$PWD/meson.conf" ]; then
164 OPTS
="$OPTS --srcdir=$top_srcdir --builddir=$top_builddir"
166 # Auto-enable ASAN to avoid conflicts between tests and binaries
167 if [ -z "$has_asan_opt" ]; then
168 if [ -e "$top_builddir/Makefile" ]; then
169 asan
=$
(awk '/^ASAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile
)
170 elif [ -f "$top_builddir/meson.conf" ]; then
171 .
"$top_builddir/meson.conf"
173 if [ -n "$asan" ]; then
174 OPTS
="$OPTS --memcheck-asan"
178 if [ -z "$has_ubsan_opt" ]; then
179 if [ -e "$top_builddir/Makefile" ]; then
180 ubsan
=$
(awk '/^UBSAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile
)
182 if [ -n "$ubsan" ]; then
183 OPTS
="$OPTS --memcheck-ubsan"
188 if [ -n "$SUBTESTS" ]; then
189 # selected tests only
190 for s
in $SUBTESTS; do
191 if [ -e "$top_srcdir/tests/ts/$s" ]; then
192 comps
+=( $
(find_test_scripts
"$top_srcdir/tests/ts/$s") ) ||
exit 1
194 echo "Unknown test component '$s'"
199 if [ -z "$SYSCOMMANDS" -a ! -f "$top_builddir/test_ttyutils" ]; then
200 echo "Tests not compiled! Run 'make check-programs' to fix the problem."
204 comps
=( $
(find_test_scripts
"$top_srcdir/tests/ts") ) ||
exit 1
207 if [ -n "$EXCLUDETESTS" ]; then
208 declare -a xcomps
# temporary array
209 for ts
in ${comps[@]}; do
210 tsname
=${ts##*ts/} # test name
212 if [[ "$EXCLUDETESTS" == *${tsname}* ]]; then
213 #echo "Ignore ${tsname}."
219 comps
=("${xcomps[@]}") # replace the array
225 unset LIBSMARTCOLS_DEBUG
228 echo "-------------------- util-linux regression tests --------------------"
230 echo " For development purpose only. "
231 echo " Don't execute on production system! "
234 # TODO: add more information about system
235 printf "%13s: %-30s " "kernel" "$(uname -r)"
238 echo " options: $(echo $OPTS | sed 's/ / \\\n /g')"
241 if [ "$paraller_jobs" -ne 1 ]; then
243 [ "$paraller_jobs" -eq 0 ] && tmp
=infinite
244 echo " Executing the tests in parallel ($tmp jobs) "
246 OPTS
="$OPTS --parallel"
250 mkdir
-p $top_builddir/tests
/
251 >|
$top_builddir/tests
/failures
252 printf "%s\n" ${comps[*]} |
254 xargs -I '{}' -P $paraller_jobs -n 1 bash
-c "'{}' \"$OPTS\" ||
255 echo '{}' >> $top_builddir/tests/failures"
257 echo "xargs error" >&2
262 fail_file
=( $
( < $top_builddir/tests
/failures
) ) ||
exit 1
264 echo "---------------------------------------------------------------------"
265 if [ ${#fail_file[@]} -eq 0 ]; then
266 echo " All ${#comps[@]} tests PASSED"
269 echo " ${#fail_file[@]} tests of ${#comps[@]} FAILED"
272 for ts
in ${fail_file[@]}; do
274 COMPONENT
=$
(basename $
(dirname $ts))
275 echo " $COMPONENT/$NAME"
279 echo "---------------------------------------------------------------------"
281 rm -f $top_builddir/tests
/failures