dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/mdadm-test-Refactor-and-revamp-test-script.patch

2c1b57
From 20d10b4be873baf6044304702808bd66ce84299c Mon Sep 17 00:00:00 2001
2c1b57
From: Zhilong Liu <zlliu@suse.com>
2c1b57
Date: Wed, 14 Jun 2017 21:02:51 +0800
2c1b57
Subject: [RHEL7.5 PATCH 155/169] mdadm/test: Refactor and revamp 'test'
2c1b57
 script
2c1b57
2c1b57
Adding functions:
2c1b57
die()
2c1b57
  uniform the abnormal situations that have to abort.
2c1b57
check_env()
2c1b57
  do various basic checking before running test suite.
2c1b57
save_log()
2c1b57
  collect array infos, include of dmesg, superblock,
2c1b57
  bitmap and /proc/mdstat.
2c1b57
main()
2c1b57
  the core function of this script.
2c1b57
2c1b57
Improve functions:
2c1b57
cleanup()
2c1b57
  clear dmesg and remove the /var/tmp/mdtest* files.
2c1b57
mdadm()
2c1b57
  clear superblock once creating or building arrays
2c1b57
  every time, because it's always creating arrays
2c1b57
  many times in a test case.
2c1b57
check()
2c1b57
  just tidy up with die(), didn't change code meanings.
2c1b57
testdev()
2c1b57
  add checking $1 must be a block device, add 'return 0'
2c1b57
  in final because this function exists in last line of
2c1b57
  test case, such as tests/05r6tor0.
2c1b57
do_test()
2c1b57
  add checking abnormal dmesg and changing log management.
2c1b57
do_help()
2c1b57
  just recommend a better way to print Usage.
2c1b57
parse_args()
2c1b57
  revamp and improve.
2c1b57
2c1b57
Delete function:
2c1b57
fast_sync()
2c1b57
  It's no longer used, so get rid of it.
2c1b57
2c1b57
Signed-off-by: Zhilong Liu <zlliu@suse.com>
2c1b57
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2c1b57
---
2c1b57
 test | 408 +++++++++++++++++++++++++++++++++++++------------------------------
2c1b57
 1 file changed, 228 insertions(+), 180 deletions(-)
2c1b57
2c1b57
diff --git a/test b/test
2c1b57
index 7942d6e..7ee523b 100755
2c1b57
--- a/test
2c1b57
+++ b/test
2c1b57
@@ -1,37 +1,20 @@
2c1b57
 #!/bin/bash
2c1b57
 #
2c1b57
 # run test suite for mdadm
2c1b57
-user=`id -un`
2c1b57
-if [ " $user" != " root" ]
2c1b57
-then
2c1b57
-	echo >&2 "test: testing can only be done as 'root'."
2c1b57
-	exit 1
2c1b57
-fi
2c1b57
-
2c1b57
-prefix='[0-9][0-9]'
2c1b57
-
2c1b57
-dir=`pwd`
2c1b57
+dir=$(pwd)
2c1b57
 mdadm=$dir/mdadm
2c1b57
-if [ \! -x $mdadm ]
2c1b57
-then
2c1b57
-	echo >&2 "test: $mdadm isn't usable."
2c1b57
-fi
2c1b57
-
2c1b57
 testdir="tests"
2c1b57
-logdir="$testdir/logs"
2c1b57
-logsave=0
2c1b57
-exitonerror=1
2c1b57
+targetdir="/var/tmp"
2c1b57
+logdir="$targetdir"
2c1b57
+config=/tmp/mdadm.conf
2c1b57
 
2c1b57
-echo "Testing on linux-$(uname -r) kernel"
2c1b57
+savelogs=0
2c1b57
+exitonerror=1
2c1b57
+prefix='[0-9][0-9]'
2c1b57
 
2c1b57
-# Check whether to run multipath tests
2c1b57
-modprobe multipath 2> /dev/null
2c1b57
-if grep -s 'Personalities : .*multipath' > /dev/null /proc/mdstat
2c1b57
-then
2c1b57
-	MULTIPATH="yes"
2c1b57
-fi
2c1b57
-INTEGRITY=yes
2c1b57
+# use loop devices by default if doesn't specify --dev
2c1b57
 DEVTYPE=loop
2c1b57
+INTEGRITY=yes
2c1b57
 LVM_VOLGROUP=mdtest
2c1b57
 
2c1b57
 # make sure to test local mdmon, not system one
2c1b57
@@ -46,7 +29,6 @@ mdp1=/dev/md_d1
2c1b57
 
2c1b57
 # We test mdadm on loop-back block devices.
2c1b57
 # dir for storing files should be settable by command line maybe
2c1b57
-targetdir=/var/tmp
2c1b57
 size=20000
2c1b57
 # super0, round down to multiple of 64 and substract 64
2c1b57
 mdsize0=19904
2c1b57
@@ -68,20 +50,65 @@ mdsize12=19988
2c1b57
 # ddf needs bigger devices as 32Meg is reserved!
2c1b57
 ddfsize=65536
2c1b57
 
2c1b57
-config=/tmp/mdadm.conf
2c1b57
+# $1 is optional parameter, it shows why to save log
2c1b57
+save_log() {
2c1b57
+	status=$1
2c1b57
+	logfile="$status""$_basename".log
2c1b57
+
2c1b57
+	cat $targetdir/stderr >> $targetdir/log
2c1b57
+	cp $targetdir/log $logdir/$_basename.log
2c1b57
+	echo "## $HOSTNAME: saving dmesg." >> $logdir/$logfile
2c1b57
+	dmesg -c >> $logdir/$logfile
2c1b57
+	$mdadm -As 2> /dev/null
2c1b57
+	echo "## $HOSTNAME: saving proc mdstat." >> $logdir/$logfile
2c1b57
+	cat /proc/mdstat >> $logdir/$logfile
2c1b57
+	array=($(mdadm -Ds | cut -d' ' -f2))
2c1b57
+	echo "## $HOSTNAME: mdadm -D ${array[@]}" >> $logdir/$logfile
2c1b57
+	$mdadm -D ${array[@]} >> $logdir/$logfile
2c1b57
+	[ "$1" == "fail" ] &&
2c1b57
+		echo "FAILED - see $logdir/$_basename.log and $logdir/$logfile for details"
2c1b57
+	# ignore saving external(external file, imsm...) bitmap
2c1b57
+	cat /proc/mdstat | grep -q "linear\|external" && return 0
2c1b57
+	if [ $DEVTYPE == 'lvm' ]
2c1b57
+	then
2c1b57
+		# not supported lvm type yet
2c1b57
+		echo
2c1b57
+	elif [ $DEVTYPE == 'loop' ]
2c1b57
+	then
2c1b57
+		if [ ! -z ${array[@]} -a ${#array[@]} -ge 1 ]
2c1b57
+		then
2c1b57
+			md_disks=($($mdadm -D -Y ${array[@]} | grep "/dev/$DEVTYPE" | cut -d'=' -f2))
2c1b57
+			cat /proc/mdstat | grep -q "bitmap"
2c1b57
+			if [ $? -eq 0 ]
2c1b57
+			then
2c1b57
+				echo "## $HOSTNAME: mdadm -X ${md_disks[@]}" >> $logdir/$logfile
2c1b57
+				$mdadm -X ${md_disks[@]} >> $logdir/$logfile
2c1b57
+			fi
2c1b57
+		else
2c1b57
+			echo "## $HOSTNAME: no array assembled!" >> $logdir/$logfile
2c1b57
+		fi
2c1b57
+	fi
2c1b57
+}
2c1b57
+
2c1b57
+die() {
2c1b57
+	echo -e "\n\tERROR: $* \n"
2c1b57
+	save_log fail
2c1b57
+	exit 2
2c1b57
+}
2c1b57
 
2c1b57
 cleanup() {
2c1b57
 	udevadm settle
2c1b57
 	$mdadm -Ssq 2> /dev/null
2c1b57
 	case $DEVTYPE in
2c1b57
-	loop)
2c1b57
+	loop )
2c1b57
 		for d in 0 1 2 3 4 5 6 7  8 9 10 11 12 13
2c1b57
 		do
2c1b57
-			losetup -d /dev/loop$d # rm -f $targetdir/mdtest$d
2c1b57
+			losetup -d /dev/loop$d
2c1b57
 			rm -f /dev/disk/by-path/loop*
2c1b57
+			rm -f /var/tmp/mdtest$d
2c1b57
 		done
2c1b57
 		;;
2c1b57
-	lvm)
2c1b57
+	lvm )
2c1b57
 		for d in 0 1 2 3 4 5 6 7  8 9 10 11 12 13
2c1b57
 		do
2c1b57
 			eval "lvremove --quiet -f \$dev$d"
2c1b57
@@ -98,23 +125,26 @@ do_setup() {
2c1b57
 	trap cleanup 0 1 3 15
2c1b57
 	trap ctrl_c 2
2c1b57
 
2c1b57
-	# make sure there are no loop devices remaining.
2c1b57
-	# udev started things can sometimes prevent them being stopped
2c1b57
-	# immediately
2c1b57
-	while grep loop /proc/partitions > /dev/null 2>&1
2c1b57
-	do
2c1b57
-		mdadm -Ss
2c1b57
-		losetup -d /dev/loop[0-9]* 2> /dev/null
2c1b57
-		sleep 1
2c1b57
-	done
2c1b57
+	[ -d $logdir ] || mkdir -p $logdir
2c1b57
+	dmesg -c > /dev/null
2c1b57
+
2c1b57
+	if [ "$DEVTYPE" == "loop" ]
2c1b57
+	then
2c1b57
+		# make sure there are no loop devices remaining.
2c1b57
+		# udev started things can sometimes prevent them being stopped
2c1b57
+		# immediately
2c1b57
+		while grep loop /proc/partitions > /dev/null 2>&1
2c1b57
+		do
2c1b57
+			$mdadm -Ssq
2c1b57
+			losetup -d /dev/loop[0-9]* 2> /dev/null
2c1b57
+			sleep 0.2
2c1b57
+		done
2c1b57
+	fi
2c1b57
 	devlist=
2c1b57
 	for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
2c1b57
 	do
2c1b57
 		sz=$size
2c1b57
-		if [ $d -gt 7 ]
2c1b57
-		then
2c1b57
-			sz=$ddfsize
2c1b57
-		fi
2c1b57
+		[ $d -gt 7 ] && sz=$ddfsize
2c1b57
 		case $DEVTYPE in
2c1b57
 		loop)
2c1b57
 			[ -f $targetdir/mdtest$d ] ||
2c1b57
@@ -169,7 +199,17 @@ mdadm() {
2c1b57
 		;;
2c1b57
 	esac
2c1b57
 	case $* in
2c1b57
-	*-C* )
2c1b57
+	*-C* | *--create* | *-B* | *--build* )
2c1b57
+		# clear superblock every time once creating or
2c1b57
+		# building arrays, because it's always creating
2c1b57
+		# and building array many times in a test case.
2c1b57
+		for args in $*
2c1b57
+		do
2c1b57
+			[[ $args =~ "/dev/" ]] && {
2c1b57
+				[[ $args =~ "md" ]] ||
2c1b57
+					$mdadm --zero $args > /dev/null
2c1b57
+			}
2c1b57
+		done
2c1b57
 		$mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes
2c1b57
 		;;
2c1b57
 	* )
2c1b57
@@ -191,39 +231,28 @@ mdadm() {
2c1b57
 check() {
2c1b57
 	case $1 in
2c1b57
 	spares )
2c1b57
-		spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
2c1b57
-		if [ $spares -ne $2 ]
2c1b57
-		then
2c1b57
-			echo >&2 "ERROR expected $2 spares, found $spares"
2c1b57
-			exit 1
2c1b57
-		fi
2c1b57
+		spares=$(tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0)
2c1b57
+		[ $spares -ne $2 ] &&
2c1b57
+			die "expected $2 spares, found $spares"
2c1b57
 		;;
2c1b57
 	raid* | linear )
2c1b57
-		grep -s "active $1 " /proc/mdstat > /dev/null || {
2c1b57
-			echo >&2 "ERROR active $1 not found"
2c1b57
-			cat /proc/mdstat
2c1b57
-			exit 1
2c1b57
-		}
2c1b57
+		grep -sq "active $1 " /proc/mdstat ||
2c1b57
+			die "active $1 not found"
2c1b57
 		;;
2c1b57
 	algorithm )
2c1b57
-		grep -s " algorithm $2 " /proc/mdstat > /dev/null || {
2c1b57
-			echo >&2 "ERROR algorithm $2 not found"
2c1b57
-			cat /proc/mdstat
2c1b57
-			exit 1
2c1b57
-		}
2c1b57
+		grep -sq " algorithm $2 " /proc/mdstat ||
2c1b57
+			die "algorithm $2 not found"
2c1b57
 		;;
2c1b57
 	resync | recovery | reshape )
2c1b57
 		cnt=5
2c1b57
-		while ! grep -s $1 /proc/mdstat > /dev/null
2c1b57
+		while ! grep -sq $1 /proc/mdstat
2c1b57
 		do
2c1b57
 			if [ $cnt -gt 0 ] && grep -v idle /sys/block/md*/md/sync_action > /dev/null
2c1b57
 			then # Something isn't idle - wait a bit
2c1b57
 				sleep 0.5
2c1b57
 				cnt=$[cnt-1]
2c1b57
 			else
2c1b57
-				echo >&2 ERROR no $1 happening
2c1b57
-				cat /proc/mdstat
2c1b57
-				exit 1
2c1b57
+				die "no $1 happening"
2c1b57
 			fi
2c1b57
 		done
2c1b57
 		;;
2c1b57
@@ -234,22 +263,18 @@ check() {
2c1b57
 		# to do can still take a little longer than expected.
2c1b57
 		# add an extra check: is sync_completed shows the end is reached, assume
2c1b57
 		# there is no recovery.
2c1b57
-		if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat
2c1b57
+		if grep -sq -E '(resync|recovery|reshape) *=' /proc/mdstat
2c1b57
 		then
2c1b57
 			incomplete=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'`
2c1b57
-			if [ -n "$incomplete" ]
2c1b57
-			then
2c1b57
-				echo >&2 "ERROR resync or recovery is happening!"
2c1b57
-				cat /proc/mdstat
2c1b57
-				exit 1
2c1b57
-			fi
2c1b57
+			[ -n "$incomplete" ] &&
2c1b57
+				die "resync or recovery is happening!"
2c1b57
 		fi
2c1b57
 		;;
2c1b57
 	wait )
2c1b57
 		p=`cat /proc/sys/dev/raid/speed_limit_max`
2c1b57
 		echo 2000000 > /proc/sys/dev/raid/speed_limit_max
2c1b57
 		sleep 0.1
2c1b57
-		while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat ||
2c1b57
+		while grep -Eq '(resync|recovery|reshape|check|repair) *=' /proc/mdstat ||
2c1b57
 			grep -v idle > /dev/null /sys/block/md*/md/sync_action
2c1b57
 		do
2c1b57
 			sleep 0.5
2c1b57
@@ -257,45 +282,28 @@ check() {
2c1b57
 		echo $p > /proc/sys/dev/raid/speed_limit_max
2c1b57
 		;;
2c1b57
 	state )
2c1b57
-		grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
2c1b57
-			echo >&2 "ERROR state $2 not found!"
2c1b57
-			cat /proc/mdstat
2c1b57
-			exit 1
2c1b57
-		}
2c1b57
+		grep -sq "blocks.*\[$2\]\$" /proc/mdstat ||
2c1b57
+			die "state $2 not found!"
2c1b57
 		sleep 0.5
2c1b57
 		;;
2c1b57
 	bitmap )
2c1b57
-		grep -s bitmap > /dev/null /proc/mdstat || {
2c1b57
-			echo >&2 ERROR no bitmap
2c1b57
-			cat /proc/mdstat
2c1b57
-			exit 1
2c1b57
-		}
2c1b57
+		grep -sq bitmap /proc/mdstat ||
2c1b57
+			die "no bitmap"
2c1b57
 		;;
2c1b57
 	nobitmap )
2c1b57
-		if grep -s "bitmap" > /dev/null /proc/mdstat
2c1b57
-		then
2c1b57
-			echo >&2 ERROR bitmap present
2c1b57
-			cat /proc/mdstat
2c1b57
-			exit 1
2c1b57
-		fi
2c1b57
+		grep -sq "bitmap" /proc/mdstat &&
2c1b57
+			die "bitmap present"
2c1b57
 		;;
2c1b57
 	readonly )
2c1b57
-		grep -s "read-only" > /dev/null /proc/mdstat || {
2c1b57
-			echo >&2 "ERROR array is not read-only!"
2c1b57
-			cat /proc/mdstat
2c1b57
-			exit 1
2c1b57
-		}
2c1b57
+		grep -sq "read-only" /proc/mdstat ||
2c1b57
+			die "array is not read-only!"
2c1b57
 		;;
2c1b57
 	inactive )
2c1b57
-		grep -s "inactive" > /dev/null /proc/mdstat || {
2c1b57
-			echo >&2 "ERROR array is not inactive!"
2c1b57
-			cat /proc/mdstat
2c1b57
-			exit 1
2c1b57
-		}
2c1b57
+		grep -sq "inactive" /proc/mdstat ||
2c1b57
+			die "array is not inactive!"
2c1b57
 		;;
2c1b57
 	* )
2c1b57
-		echo >&2 ERROR unknown check $1
2c1b57
-		exit 1
2c1b57
+		die "unknown check $1"
2c1b57
 		;;
2c1b57
 	esac
2c1b57
 }
2c1b57
@@ -311,6 +319,7 @@ no_errors() {
2c1b57
 
2c1b57
 # basic device test
2c1b57
 testdev() {
2c1b57
+	[ -b $1 ] || die "$1 isn't a block device."
2c1b57
 	udevadm settle
2c1b57
 	dev=$1
2c1b57
 	cnt=$2
2c1b57
@@ -329,20 +338,11 @@ testdev() {
2c1b57
 		rasize=$[rasize/DEV_ROUND_K/2]
2c1b57
 		rasize=$[rasize*DEV_ROUND_K*2]
2c1b57
 	fi
2c1b57
-	if [ `/sbin/blockdev --getsize $dev` -eq 0 ]
2c1b57
-	then
2c1b57
-		sleep 2
2c1b57
-	fi
2c1b57
+	[ `/sbin/blockdev --getsize $dev` -eq 0 ] && sleep 2
2c1b57
 	_sz=`/sbin/blockdev --getsize $dev`
2c1b57
-	if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ]
2c1b57
-	then
2c1b57
-		echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
2c1b57
-		exit 1
2c1b57
-	fi
2c1b57
-}
2c1b57
-
2c1b57
-fast_sync() {
2c1b57
-	echo 200000 > /proc/sys/dev/raid/speed_limit_max
2c1b57
+	[ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ] &&
2c1b57
+		die "size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
2c1b57
+	return 0
2c1b57
 }
2c1b57
 
2c1b57
 rotest() {
2c1b57
@@ -359,7 +359,6 @@ do_test() {
2c1b57
 		# stop all arrays, just incase some script left an array active.
2c1b57
 		$mdadm -Ssq 2> /dev/null
2c1b57
 		mdadm --zero $devlist 2> /dev/null
2c1b57
-		mdadm --zero $devlist 2> /dev/null
2c1b57
 		# this might have been reset: restore the default.
2c1b57
 		echo 2000 > /proc/sys/dev/raid/speed_limit_max
2c1b57
 		# source script in a subshell, so it has access to our
2c1b57
@@ -367,52 +366,44 @@ do_test() {
2c1b57
 		echo -ne "$_script... "
2c1b57
 		if ( set -ex ; . $_script ) &> $targetdir/log
2c1b57
 		then
2c1b57
+			dmesg | grep -iq "error\|call trace\|segfault" &&
2c1b57
+				die "dmesg prints errors when testing $_basename!"
2c1b57
 			echo "succeeded"
2c1b57
 			_fail=0
2c1b57
 		else
2c1b57
-			log=log
2c1b57
-			cat $targetdir/stderr >> $targetdir/log
2c1b57
-			echo "=======================dmesg=================" >> $targetdir/log
2c1b57
-			dmesg | tail -n 200 >> $targetdir/log
2c1b57
-			if [ $exitonerror == 0 ]; then
2c1b57
-				log=log-`basename $_script`
2c1b57
-				mv $targetdir/log $logdir/$log
2c1b57
-			fi
2c1b57
-			echo "FAILED - see $logdir/$log for details"
2c1b57
+			save_log fail
2c1b57
 			_fail=1
2c1b57
 		fi
2c1b57
-		if [ "$savelogs" == "1" ]
2c1b57
-		then
2c1b57
-			cp $targetdir/log $logdir/$_basename.log
2c1b57
-		fi
2c1b57
-		if [ "$_fail" == "1" -a "$exitonerror" == "1" ]
2c1b57
-		then
2c1b57
-			exit 1
2c1b57
-		fi
2c1b57
+		[ "$savelogs" == "1" ] &&
2c1b57
+			mv -f $targetdir/log $logdir/$_basename.log
2c1b57
+		[ "$_fail" == "1" -a "$exitonerror" == "1" ] && exit 1
2c1b57
 	fi
2c1b57
 }
2c1b57
 
2c1b57
 do_help() {
2c1b57
-	echo "Usage: $0 [options]"
2c1b57
-	echo " Options:"
2c1b57
-	echo "    --tests=<test1,test2,..>    Comma separated list of tests to run"
2c1b57
-	echo "    --disable-multipath         Disable any tests involving multipath"
2c1b57
-	echo "    --disable-integrity         Disable slow tests of RAID[56] consistency"
2c1b57
-	echo "    --logdir=<directory>        Directory to save logfiles in"
2c1b57
-	echo "    --save-logs                 Save all logs in <logdir>"
2c1b57
-	echo "    --keep-going                Don't stop on error, ie. run all tests"
2c1b57
-	echo "    --dev=[loop|lvm|ram]        Use loop devices (default), LVM, or RAM disk"
2c1b57
-	echo "    --volgroup=<name>           LVM volume group for LVM test"
2c1b57
-	echo "    setup                       Setup test environment and exit"
2c1b57
-	echo "    cleanup                     Cleanup test environment"
2c1b57
-	echo "    <prefix>                    Run tests with <prefix>"
2c1b57
+	cat <<-EOF
2c1b57
+	Usage: $0 [options]
2c1b57
+	Options:
2c1b57
+		--tests=test1,test2,...     Comma separated list of tests to run
2c1b57
+		--disable-multipath         Disable any tests involving multipath
2c1b57
+		--disable-integrity         Disable slow tests of RAID[56] consistency
2c1b57
+		--logdir=directory          Directory to save all logfiles in
2c1b57
+		--save-logs                 Usually use with --logdir together
2c1b57
+		--keep-going | --no-error   Don't stop on error, ie. run all tests
2c1b57
+		--dev=loop|lvm|ram          Use loop devices (default), LVM, or RAM disk
2c1b57
+		--volgroup=name             LVM volume group for LVM test
2c1b57
+		setup                       Setup test environment and exit
2c1b57
+		cleanup                     Cleanup test environment
2c1b57
+		prefix                      Run tests with <prefix>
2c1b57
+		--help | -h                 Print this usage
2c1b57
+	EOF
2c1b57
 }
2c1b57
 
2c1b57
 parse_args() {
2c1b57
 	for i in $*
2c1b57
 	do
2c1b57
 		case $i in
2c1b57
-		[0-9]* )
2c1b57
+		[0-9][0-9] )
2c1b57
 			prefix=$i
2c1b57
 			;;
2c1b57
 		setup )
2c1b57
@@ -426,10 +417,10 @@ parse_args() {
2c1b57
 			exit 0
2c1b57
 			;;
2c1b57
 		--tests=* )
2c1b57
-			TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
2c1b57
+			TESTLIST=($(echo ${i##*=} | sed -e 's/,/ /g'))
2c1b57
 			;;
2c1b57
 		--logdir=* )
2c1b57
-			logdir=`expr "x$i" : 'x[^=]*=\(.*\)'`
2c1b57
+			logdir="${i##*=}"
2c1b57
 			;;
2c1b57
 		--save-logs )
2c1b57
 			savelogs=1
2c1b57
@@ -443,52 +434,109 @@ parse_args() {
2c1b57
 		--disable-integrity )
2c1b57
 			unset INTEGRITY
2c1b57
 			;;
2c1b57
-		--dev=loop )
2c1b57
-			DEVTYPE=loop
2c1b57
-			;;
2c1b57
-		--dev=lvm )
2c1b57
-			DEVTYPE=lvm
2c1b57
-			;;
2c1b57
-		--dev=ram )
2c1b57
-			DEVTYPE=ram
2c1b57
+		--dev=* )
2c1b57
+			case ${i##*=} in
2c1b57
+			loop )
2c1b57
+				DEVTYPE=loop
2c1b57
+				;;
2c1b57
+			lvm )
2c1b57
+				DEVTYPE=lvm
2c1b57
+				;;
2c1b57
+			ram )
2c1b57
+				DEVTYPE=ram
2c1b57
+				;;
2c1b57
+			* )
2c1b57
+				echo "Unknown argument: $i"
2c1b57
+				do_help
2c1b57
+				exit 1
2c1b57
+				;;
2c1b57
+			esac
2c1b57
 			;;
2c1b57
 		--volgroup=* )
2c1b57
 			LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'`
2c1b57
 			;;
2c1b57
-		--help )
2c1b57
+		--help | -h )
2c1b57
 			do_help
2c1b57
 			exit 0
2c1b57
 			;;
2c1b57
-		-* )
2c1b57
+		* )
2c1b57
 			echo " $0: Unknown argument: $i"
2c1b57
 			do_help
2c1b57
-			exit 0
2c1b57
+			exit 1
2c1b57
 			;;
2c1b57
 		esac
2c1b57
 	done
2c1b57
 }
2c1b57
 
2c1b57
-logdir=$targetdir
2c1b57
-parse_args $@
2c1b57
+check_env() {
2c1b57
+	user=$(id -un)
2c1b57
+	[ "X$user" != "Xroot" ] && {
2c1b57
+		echo "test: testing can only be done as 'root'."
2c1b57
+		exit 1
2c1b57
+	}
2c1b57
+	[ -x "raid6check" -a -x $mdadm ] || {
2c1b57
+		echo "test: please run 'make everything' before perform testing."
2c1b57
+		exit 1
2c1b57
+	}
2c1b57
+	cmds=(mdadm lsblk df udevadm losetup mkfs.ext3 fsck)
2c1b57
+	for cmd in ${cmds[@]}
2c1b57
+	do
2c1b57
+		which $cmd > /dev/null || {
2c1b57
+			echo "$cmd command not found!"
2c1b57
+			exit 1
2c1b57
+		}
2c1b57
+	done
2c1b57
+	mdadm_src_ver="$($mdadm -V 2>&1)"
2c1b57
+	mdadm_sbin_ver="$($(which mdadm) -V 2>&1)"
2c1b57
+	if [ "$mdadm_src_ver" != "$mdadm_sbin_ver" ]
2c1b57
+	then
2c1b57
+		# it's nessesary to 'make install' mdadm to /SBIN/DIR,
2c1b57
+		# such as systemd/mdadm-grow-continue@.service, would
2c1b57
+		# run as an instance by systemd when reshape happens,
2c1b57
+		# thus ensure that the correct mdadm is in testing.
2c1b57
+		echo "test: please run 'make install' before testing."
2c1b57
+		exit 1
2c1b57
+	fi
2c1b57
+	if ! $(df -T . | grep -iq ext)
2c1b57
+	then
2c1b57
+		# 'external file' bitmap only supports with ext[2-4] file system
2c1b57
+		echo "test: please run test suite with ext[2-4] file system."
2c1b57
+		exit 1
2c1b57
+	fi
2c1b57
+	if $(lsblk -a | grep -iq raid)
2c1b57
+	then
2c1b57
+		# donot run mdadm -Ss directly if there are RAIDs working.
2c1b57
+		echo "test: please run test suite without running RAIDs environment."
2c1b57
+		exit 1
2c1b57
+	fi
2c1b57
+	# Check whether to run multipath tests
2c1b57
+	modprobe multipath 2> /dev/null
2c1b57
+	grep -sq 'Personalities : .*multipath' /proc/mdstat &&
2c1b57
+		MULTIPATH="yes"
2c1b57
+}
2c1b57
 
2c1b57
-do_setup
2c1b57
-mkdir -p $logdir
2c1b57
+main() {
2c1b57
+	check_env
2c1b57
+	do_setup
2c1b57
 
2c1b57
-if [ "$savelogs" == "1" ]
2c1b57
-then
2c1b57
-	echo "Saving logs to $logdir"
2c1b57
-fi
2c1b57
+	echo "Testing on linux-$(uname -r) kernel"
2c1b57
+	[ "$savelogs" == "1" ] &&
2c1b57
+		echo "Saving logs to $logdir"
2c1b57
+	if [ "x$TESTLIST" != "x" ]
2c1b57
+	then
2c1b57
+		for script in ${TESTLIST[@]}
2c1b57
+		do
2c1b57
+			do_test $testdir/$script
2c1b57
+		done
2c1b57
+	else
2c1b57
+		for script in $testdir/$prefix $testdir/$prefix*[^~]
2c1b57
+		do
2c1b57
+			do_test $script
2c1b57
+		done
2c1b57
+	fi
2c1b57
 
2c1b57
-if [ "x$TESTLIST" != "x" ]
2c1b57
-then
2c1b57
-	for script in $TESTLIST
2c1b57
-	do
2c1b57
-		do_test $testdir/$script
2c1b57
-	done
2c1b57
-else
2c1b57
-	for script in $testdir/$prefix $testdir/$prefix*[^~]
2c1b57
-	do
2c1b57
-		do_test $script
2c1b57
-	done
2c1b57
-fi
2c1b57
-exit 0
2c1b57
+	exit 0
2c1b57
+}
2c1b57
+
2c1b57
+parse_args $@
2c1b57
+main
2c1b57
-- 
2c1b57
2.7.4
2c1b57