xref: /kvm-unit-tests/scripts/common.bash (revision a303dbe1d0e5238aeb57ae0136ad2d2df7dcae53)
1source config.mak
2
3function for_each_unittest()
4{
5	local unittests="$1"
6	local cmd="$2"
7	local testname
8	local smp
9	local kernel
10	local opts
11	local groups
12	local arch
13	local check
14	local accel
15	local timeout
16
17	exec {fd}<"$unittests"
18
19	while read -r -u $fd line; do
20		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
21			if [ -n "${testname}" ]; then
22				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
23			fi
24			testname=${BASH_REMATCH[1]}
25			smp=1
26			kernel=""
27			opts=""
28			groups=""
29			arch=""
30			check=""
31			accel=""
32			timeout=""
33		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
34			kernel=$TEST_DIR/${BASH_REMATCH[1]}
35		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
36			smp=${BASH_REMATCH[1]}
37		elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
38			opts=${BASH_REMATCH[1]}
39		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
40			groups=${BASH_REMATCH[1]}
41		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
42			arch=${BASH_REMATCH[1]}
43		elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
44			check=${BASH_REMATCH[1]}
45		elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then
46			accel=${BASH_REMATCH[1]}
47		elif [[ $line =~ ^timeout\ *=\ *(.*)$ ]]; then
48			timeout=${BASH_REMATCH[1]}
49		fi
50	done
51	if [ -n "${testname}" ]; then
52		$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
53	fi
54	exec {fd}<&-
55}
56
57function arch_cmd()
58{
59	[ "${ARCH_CMD}" ] && echo "${ARCH_CMD}"
60}
61
62# The current file has to be the only file sourcing the arch helper
63# file
64ARCH_FUNC=scripts/${ARCH}/func.bash
65if [ -f "${ARCH_FUNC}" ]; then
66	source "${ARCH_FUNC}"
67fi
68