xref: /kvm-unit-tests/scripts/common.bash (revision dfc1fec2fbde04ad607e1aed560cf7059350c70f)
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]}$'\n'
41			while read -r -u $fd; do
42				#escape backslash newline, but not double backslash
43				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
44					if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
45						opts=${opts%\\$'\n'}
46					fi
47				fi
48				if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
49					opts+=${BASH_REMATCH[1]}
50					break
51				else
52					opts+=$REPLY$'\n'
53				fi
54			done
55		elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
56			opts=${BASH_REMATCH[1]}
57		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
58			groups=${BASH_REMATCH[1]}
59		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
60			arch=${BASH_REMATCH[1]}
61		elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
62			check=${BASH_REMATCH[1]}
63		elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then
64			accel=${BASH_REMATCH[1]}
65		elif [[ $line =~ ^timeout\ *=\ *(.*)$ ]]; then
66			timeout=${BASH_REMATCH[1]}
67		fi
68	done
69	if [ -n "${testname}" ]; then
70		$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
71	fi
72	exec {fd}<&-
73}
74
75function arch_cmd()
76{
77	[ "${ARCH_CMD}" ] && echo "${ARCH_CMD}"
78}
79
80# The current file has to be the only file sourcing the arch helper
81# file
82ARCH_FUNC=scripts/${ARCH}/func.bash
83if [ -f "${ARCH_FUNC}" ]; then
84	source "${ARCH_FUNC}"
85fi
86