1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
|
#!/bin/bash
#
# run test suite for mdadm
mdadm=`which mdadm`
targetdir="/var/tmp"
logdir="$targetdir"
config=/tmp/mdadm.conf
testdir=$PWD/tests
system_speed_limit_max=0
system_speed_limit_min=0
test_speed_limit_min=100
test_speed_limit_max=500
devlist=
# If super1 metadata name doesn't have the same hostname with machine,
# it's treated as foreign.
# For example, /dev/md0 is created, stops it, then assemble it, the
# device node will be /dev/md127 (127 is choosed by mdadm autumatically)
is_foreign="no"
#disable selinux
sys_selinux="Permissive"
skipping_linear="no"
skipping_multipath="no"
savelogs=0
exitonerror=1
ctrl_c_error=0
skipbroken=0
loop=1
prefix='[0-9][0-9]'
# use loop devices by default if doesn't specify --dev
DEVTYPE=loop
INTEGRITY=yes
LVM_VOLGROUP=mdtest
# assume md0, md1, md2 exist in /dev
md0=/dev/md0
md1=/dev/md1
md2=/dev/md2
# if user doesn't specify minor number, mdadm chooses minor number
# automatically from 127.
md127=/dev/md127
md126=/dev/md126
md125=/dev/md125
mdp0=/dev/md_d0
mdp1=/dev/md_d1
SKIP=3
die() {
echo -e "\n\tERROR: $* \n"
save_log fail
exit 2
}
skip() {
echo -e "\n\tSKIPPING, REASON: $* \n"
exit $SKIP
}
ctrl_c() {
exitonerror=1
ctrl_c_error=1
}
mdadm() {
rm -f $targetdir/stderr
case $* in
*-S* )
udevadm settle
p=`cat /proc/sys/dev/raid/speed_limit_max`
echo 20000 > /proc/sys/dev/raid/speed_limit_max
;;
esac
case $* in
*-C* | *--create* | *-B* | *--build* )
# clear superblock every time once creating or
# building arrays, because it's always creating
# and building array many times in a test case.
for args in $*
do
[[ $args =~ "/dev/" ]] && {
[[ $args =~ "md" ]] ||
$mdadm --zero $args > /dev/null
}
done
$mdadm 2> $targetdir/stderr "$@"
;;
* )
$mdadm 2> $targetdir/stderr "$@"
;;
esac
rv=$?
case $* in
*-S* )
udevadm settle
echo $p > /proc/sys/dev/raid/speed_limit_max
;;
esac
cat >&2 $targetdir/stderr
return $rv
}
print_time_elapsed() {
local start_sec=$1
local end_sec=$(date +%s)
local execution_time=$((end_sec - start_sec))
echo -ne "Execution time (seconds): ${execution_time} "
}
do_test() {
_script=$1
_basename=`basename $_script`
_broken=0
local start_sec=$(date +%s)
if [ -f "$_script" ]
then
if [ -f "${_script}.broken" ]; then
_broken=1
_broken_msg=$(head -n1 "${_script}.broken" | tr -d '\n')
if [ "$skipbroken" == "all" ]; then
return
elif [ "$skipbroken" == "always" ] &&
[[ "$_broken_msg" == *always* ]]; then
return
fi
fi
rm -f $targetdir/stderr
do_clean
# source script in a subshell, so it has access to our
# namespace, but cannot change it.
control_system_speed_limit
echo -ne "$_script... "
if ( set -ex ; . $_script ) &> $targetdir/log
then
print_time_elapsed $start_sec
if [ -f "${_script}.inject_error" ]; then
echo "dmesg checking is skipped because test inject error"
else
dmesg | grep -iq "error\|call trace\|segfault" | grep -v "systemd" &&
die "dmesg prints errors when testing $_basename!"
fi
succeed "succeeded\n"
_fail=0
else
exit_code=$? # Capture the exit code from the script
if [ $exit_code -eq $SKIP ]; then
warn "skipping"
save_log
_fail=0
else
print_time_elapsed $start_sec
save_log fail
_fail=1
if [ "$_broken" == "1" ]; then
echo " (KNOWN BROKEN TEST: $_broken_msg)"
fi
fi
fi
restore_system_speed_limit
[ "$savelogs" == "1" ] && mv -f $targetdir/log $logdir/$_basename.log
[ "$ctrl_c_error" == "1" ] && exit 1
[ "$_fail" == "1" -a "$exitonerror" == "1" -a "$_broken" == "0" ] && exit 1
[ "$_fail" == "1" ] && do_test_ret=1
fi
}
do_help() {
cat <<-EOF
Usage: $0 [options]
Example for disk mode: ./test --dev=disk --disks=/dev/sda{2..15}
Options:
--tests=test1,test2,... Comma separated list of tests to run
--testdir= Specify testdir as tests|clustermd_tests
--raidtype= raid0|linear|raid1|raid456|raid10|ddf|imsm
--disable-multipath Disable any tests involving multipath
--disable-integrity Disable slow tests of RAID[56] consistency
--disable-linear Disable any tests involving linear
--logdir=directory Directory to save all logfiles in
--save-logs Usually use with --logdir together
--keep-going | --no-error Don't stop on error, ie. run all tests
--loop=N Run tests N times (0 to run forever)
--skip-broken Skip tests that are known to be broken
--skip-always-broken Skip tests that are known to always fail
--dev=loop|lvm|ram|disk Use loop devices (default), LVM, RAM or disk
--disks= Provide a bunch of physical devices for test
--volgroup=name LVM volume group for LVM test
setup Setup test environment and exit
cleanup Cleanup test environment
prefix Run tests with <prefix>
--help | -h Print this usage
EOF
}
parse_args() {
for i in $*
do
case $i in
--testdir=* )
case ${i##*=} in
tests )
testdir=tests
;;
clustermd_tests )
testdir=clustermd_tests
CLUSTER_CONF="$PWD/$testdir/cluster_conf"
;;
* )
echo "Unknown argument: $i"
do_help
exit 1
;;
esac
;;
esac
done
[ -z "$testdir" ] && testdir=tests
. $testdir/func.sh
for i in $*
do
case $i in
[0-9][0-9] )
prefix=$i
;;
setup )
echo "mdadm test environment setup"
do_setup
trap 0
exit 0
;;
cleanup )
cleanup
exit 0
;;
--testdir=* )
;;
--tests=* )
TESTLIST=($(echo ${i##*=} | sed -e 's/,/ /g'))
;;
--raidtype=* )
case ${i##*=} in
raid0 )
TESTLIST=($(ls $testdir | grep "[0-9][0-9]r0\|raid0"))
;;
linear )
TESTLIST=($(ls $testdir | grep "linear"))
;;
raid1 )
TESTLIST=($(ls $testdir | grep "[0-9][0-9]r1\|raid1" | grep -vi "r10\|raid10"))
;;
raid456 )
TESTLIST=($(ls $testdir | grep "[0-9][0-9]r[4-6]\|raid[4-6]"))
;;
raid10 )
TESTLIST=($(ls $testdir | grep "[0-9][0-9]r10\|raid10"))
;;
ddf )
TESTLIST=($(ls $testdir | grep "[0-9][0-9]ddf"))
;;
imsm )
TESTLIST=($(ls $testdir | grep "[0-9][0-9]imsm"))
;;
* )
echo "Unknown argument: $i"
do_help
exit 1
;;
esac
;;
--logdir=* )
logdir="${i##*=}"
;;
--save-logs )
savelogs=1
;;
--keep-going | --no-error )
exitonerror=0
;;
--loop=* )
loop="${i##*=}"
;;
--skip-broken )
skipbroken=all
;;
--skip-always-broken )
skipbroken=always
;;
--disable-multipath )
unset MULTIPATH
;;
--disable-integrity )
unset INTEGRITY
;;
--disable-linear )
unset LINEAR
;;
--dev=* )
case ${i##*=} in
loop )
DEVTYPE=loop
;;
lvm )
DEVTYPE=lvm
;;
ram )
DEVTYPE=ram
;;
disk )
DEVTYPE=disk
;;
* )
echo "Unknown argument: $i"
do_help
exit 1
;;
esac
;;
--disks=* )
disks=(${disks[*]} ${i##*=})
;;
--volgroup=* )
LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'`
;;
--help | -h )
do_help
exit 0
;;
* )
echo " $0: Unknown argument: $i"
do_help
exit 1
;;
esac
done
}
print_warning() {
warn "Warning! Tests are performed on system level mdadm!\n"
echo "If you want to test local build, you need to install it first!"
}
main() {
print_warning
do_setup
echo "Testing on linux-$(uname -r) kernel"
[ "$savelogs" == "1" ] &&
echo "Saving logs to $logdir"
do_test_ret=0
while true; do
if [ "x$TESTLIST" != "x" ]
then
for script in ${TESTLIST[@]}
do
do_test $testdir/$script
done
else
for script in $testdir/$prefix $testdir/$prefix*[^~]
do
case $script in *.broken) ;;
*)
do_test $script
esac
done
fi
let loop=$loop-1
if [ "$loop" == "0" ]; then
break
fi
done
restore_selinux
exit $do_test_ret
}
parse_args $@
main
|