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