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