]>
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 | { | |
30 | if lscpu -p &>/dev/null; then | |
31 | lscpu -p | grep -cv '^#' | |
32 | else | |
33 | echo 1 | |
34 | fi | |
35 | } | |
36 | ||
949cf64b KZ |
37 | while [ -n "$1" ]; do |
38 | case "$1" in | |
39 | --force) | |
40 | OPTS="$OPTS --force" | |
41 | ;; | |
42 | --fake) | |
43 | OPTS="$OPTS --fake" | |
44 | ;; | |
0269fcbb KZ |
45 | --memcheck) |
46 | OPTS="$OPTS --memcheck" | |
47 | ;; | |
1b03e2cd KZ |
48 | --verbose) |
49 | OPTS="$OPTS --verbose" | |
50 | ;; | |
d995c2f0 KZ |
51 | --skip-loopdevs) |
52 | OPTS="$OPTS --skip-loopdevs" | |
53 | ;; | |
1b03e2cd KZ |
54 | --nonroot) |
55 | if [ $(id -ru) -eq 0 ]; then | |
9779f598 | 56 | echo "Ignore util-linux test suite [non-root UID expected]." |
1b03e2cd KZ |
57 | exit 0 |
58 | fi | |
59 | ;; | |
60 | --srcdir=*) | |
61 | top_srcdir="${1##--srcdir=}" | |
62 | ;; | |
63 | --builddir=*) | |
64 | top_builddir="${1##--builddir=}" | |
65 | ;; | |
40e6f7a0 SK |
66 | --parallel=*) |
67 | paraller_jobs="${1##--parallel=}" | |
40e6f7a0 SK |
68 | ;; |
69 | --parallel) | |
6163259c | 70 | paraller_jobs=$(num_cpus) |
40e6f7a0 | 71 | ;; |
c8aa62a8 KZ |
72 | --exclude=*) |
73 | EXCLUDETESTS="${1##--exclude=}" | |
74 | ;; | |
949cf64b KZ |
75 | --*) |
76 | echo "Unknown option $1" | |
1b03e2cd KZ |
77 | echo "Usage: " |
78 | echo " $(basename $0) [options] [<component> ...]" | |
79 | echo "Options:" | |
80 | echo " --force execute demanding tests" | |
81 | echo " --fake do not run, setup tests only" | |
82 | echo " --memcheck run with valgrind" | |
83 | echo " --verbose verbose mode" | |
84 | echo " --nonroot ignore test suite if user is root" | |
85 | echo " --srcdir=<path> autotools top source directory" | |
86 | echo " --builddir=<path> autotools top build directory" | |
40e6f7a0 | 87 | echo " --parallel=<num> number of parallel test jobs, default: num cpus" |
c8aa62a8 | 88 | echo " --exclude=<list> exclude tests by list '<utilname>/<testname> ..'" |
1b03e2cd | 89 | echo |
a1be90bb | 90 | exit 1 |
949cf64b KZ |
91 | ;; |
92 | ||
93 | *) | |
94 | SUBTESTS="$SUBTESTS $1" | |
95 | ;; | |
96 | esac | |
97 | shift | |
98 | done | |
99 | ||
1b03e2cd KZ |
100 | # For compatibility with autotools is necessary to differentiate between source |
101 | # (with test scripts) and build (with temporary files) directories when | |
102 | # executed by our build-system. | |
103 | # | |
104 | # The default is the source tree with this script. | |
105 | # | |
106 | if [ -z "$top_srcdir" ]; then | |
107 | top_srcdir="$TS_TOPDIR/.." | |
108 | fi | |
109 | if [ -z "$top_builddir" ]; then | |
110 | top_builddir="$TS_TOPDIR/.." | |
111 | fi | |
112 | ||
113 | OPTS="$OPTS --srcdir=$top_srcdir --builddir=$top_builddir" | |
114 | ||
40e6f7a0 | 115 | declare -a comps |
949cf64b KZ |
116 | if [ -n "$SUBTESTS" ]; then |
117 | # selected tests only | |
118 | for s in $SUBTESTS; do | |
1b03e2cd | 119 | if [ -d "$top_srcdir/tests/ts/$s" ]; then |
40e6f7a0 | 120 | comps+=( $(find $top_srcdir/tests/ts/$s -type f -perm /a+x -regex ".*/[^\.~]*") ) |
949cf64b KZ |
121 | else |
122 | echo "Unknown test component '$s'" | |
123 | exit 1 | |
124 | fi | |
125 | done | |
126 | else | |
10a628c8 | 127 | if [ ! -f "$top_builddir/test_ttyutils" ]; then |
b5606aad KZ |
128 | echo "Tests not compiled! Run 'make check' to fix the problem." |
129 | exit 1 | |
130 | fi | |
b5606aad | 131 | |
40e6f7a0 | 132 | comps=( $(find $top_srcdir/tests/ts/ -type f -perm /a+x -regex ".*/[^\.~]*") ) |
a1be90bb KZ |
133 | fi |
134 | ||
c8aa62a8 KZ |
135 | if [ -n "$EXCLUDETESTS" ]; then |
136 | declare -a xcomps # temporary array | |
137 | for ts in ${comps[@]}; do | |
138 | tsname=${ts##*ts/} # test name | |
139 | ||
140 | if [[ "$EXCLUDETESTS" == *${tsname}* ]]; then | |
141 | #echo "Ignore ${tsname}." | |
142 | true | |
143 | else | |
144 | xcomps+=($ts) | |
145 | fi | |
146 | done | |
147 | comps=("${xcomps[@]}") # replace the array | |
148 | fi | |
b5606aad | 149 | |
72c92179 KZ |
150 | unset LIBMOUNT_DEBUG |
151 | unset LIBBLKID_DEBUG | |
76041e70 | 152 | unset LIBFDISK_DEBUG |
c8aa62a8 | 153 | unset LIBSMARTCOLS_DEBUG |
72c92179 | 154 | |
e83446da | 155 | echo |
21d1fa53 | 156 | echo "-------------------- util-linux regression tests --------------------" |
e83446da | 157 | echo |
c9860428 KZ |
158 | echo " For development purpose only. " |
159 | echo " Don't execute on production system! " | |
160 | echo | |
e83446da | 161 | |
40e6f7a0 SK |
162 | if [ $paraller_jobs -gt 1 ]; then |
163 | echo " Executing the tests in parallel ($paraller_jobs jobs) " | |
164 | echo | |
81b3d7ed | 165 | OPTS="$OPTS --parallel" |
40e6f7a0 | 166 | fi |
e83446da | 167 | |
40e6f7a0 | 168 | count=0 |
51f9b431 | 169 | >| $top_builddir/tests/failures |
40e6f7a0 | 170 | printf "%s\n" ${comps[*]} | |
667e4735 | 171 | sort | |
40e6f7a0 | 172 | xargs -I '{}' -P $paraller_jobs -n 1 bash -c "'{}' \"$OPTS\" || |
51f9b431 | 173 | echo 1 >> $top_builddir/tests/failures" |
40e6f7a0 | 174 | declare -a fail_file |
ddd2570f | 175 | fail_file=( $( < $top_builddir/tests/failures ) ) || exit 1 |
51f9b431 | 176 | rm -f $top_builddir/tests/failures |
e83446da KZ |
177 | echo |
178 | echo "---------------------------------------------------------------------" | |
40e6f7a0 SK |
179 | if [ ${#fail_file[@]} -eq 0 ]; then |
180 | echo " All ${#comps[@]} tests PASSED" | |
5b0d01d6 | 181 | res=0 |
e83446da | 182 | else |
40e6f7a0 | 183 | echo " ${#fail_file[@]} tests of ${#comps[@]} FAILED" |
5b0d01d6 | 184 | res=1 |
e83446da KZ |
185 | fi |
186 | echo "---------------------------------------------------------------------" | |
5b0d01d6 | 187 | exit $res |