summaryrefslogtreecommitdiffstats
path: root/test
blob: 61d9ee83226e32f67df3d9f1289ebf98732ff8a3 (plain)
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
#!/bin/bash
#
# run test suite for mdadm
mdadm=$PWD/mdadm
targetdir="/var/tmp"
logdir="$targetdir"
config=/tmp/mdadm.conf
testdir=$PWD/tests
devlist=

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

# make sure to test local mdmon, not system one
export MDADM_NO_SYSTEMCTL=1

# assume md0, md1, md2 exist in /dev
md0=/dev/md0
md1=/dev/md1
md2=/dev/md2
mdp0=/dev/md_d0
mdp1=/dev/md_d1

die() {
	echo -e "\n\tERROR: $* \n"
	save_log fail
	exit 2
}

ctrl_c() {
	exitonerror=1
	ctrl_c_error=1
}

# mdadm always adds --quiet, and we want to see any unexpected messages
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 --quiet "$@" --auto=yes
		;;
	* )
		$mdadm 2> $targetdir/stderr --quiet "$@"
		;;
	esac
	rv=$?
	case $* in
	*-S* )
		udevadm settle
		echo $p > /proc/sys/dev/raid/speed_limit_max
		;;
	esac
	cat >&2 $targetdir/stderr
	return $rv
}

do_test() {
	_script=$1
	_basename=`basename $_script`
	_broken=0

	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
		# this might have been reset: restore the default.
		echo 2000 > /proc/sys/dev/raid/speed_limit_max
		do_clean
		# source script in a subshell, so it has access to our
		# namespace, but cannot change it.
		echo -ne "$_script... "
		if ( set -ex ; . $_script ) &> $targetdir/log
		then
			dmesg | grep -iq "error\|call trace\|segfault" &&
				die "dmesg prints errors when testing $_basename!"
			echo "succeeded"
			_fail=0
		else
			save_log fail
			_fail=1
			if [ "$_broken" == "1" ]; then
				echo "  (KNOWN BROKEN TEST: $_broken_msg)"
			fi
		fi
		[ "$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
	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
		--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
			;;
		--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
}

main() {
	do_setup

	echo "Testing on linux-$(uname -r) kernel"
	[ "$savelogs" == "1" ] &&
		echo "Saving logs to $logdir"

	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
	exit 0
}

parse_args $@
main