xref: /kvm-unit-tests/scripts/common.bash (revision dcd338445f5b117e1c393438b279c83604c3b10c)
1source config.mak
2source scripts/vmm.bash
3
4function for_each_unittest()
5{
6	local unittests="$1"
7	local cmd="$2"
8	local testname
9	local smp
10	local kernel
11	local test_args
12	local opts
13	local groups
14	local arch
15	local machine
16	local check
17	local accel
18	local timeout
19	local disabled_if
20	local rematch
21
22	# shellcheck disable=SC2155
23	local params_name=$(vmm_unittest_params_name)
24
25	exec {fd}<"$unittests"
26
27	while read -r -u $fd line; do
28		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
29			rematch=${BASH_REMATCH[1]}
30			if [ -n "${testname}" ]; then
31				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout" "$disabled_if"
32			fi
33			testname=$rematch
34			smp="$(vmm_optname_nr_cpus) 1"
35			kernel=""
36			# Intentionally don't use -append if test_args is empty
37			# because qemu interprets the first word after
38			# -append as a kernel parameter instead of a command
39			# line option.
40			test_args=""
41			opts="$(vmm_default_opts)"
42			groups=""
43			arch=""
44			machine=""
45			check=""
46			accel=""
47			timeout=""
48			disabled_if=""
49		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
50			kernel=$TEST_DIR/${BASH_REMATCH[1]}
51		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
52			smp="$(vmm_optname_nr_cpus) ${BASH_REMATCH[1]}"
53		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
54			test_args="$(vmm_optname_args) ${BASH_REMATCH[1]}"
55		elif [[ $line =~ ^$params_name\ *=\ *'"""'(.*)$ ]]; then
56			opts="$(vmm_defaults_opts) ${BASH_REMATCH[1]}$'\n'"
57			while read -r -u $fd; do
58				#escape backslash newline, but not double backslash
59				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
60					if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
61						opts=${opts%\\$'\n'}
62					fi
63				fi
64				if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
65					opts+=${BASH_REMATCH[1]}
66					break
67				else
68					opts+=$REPLY$'\n'
69				fi
70			done
71		elif [[ $line =~ ^$params_name\ *=\ *(.*)$ ]]; then
72			opts="$(vmm_default_opts) ${BASH_REMATCH[1]}"
73		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
74			groups=${BASH_REMATCH[1]}
75		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
76			arch=${BASH_REMATCH[1]}
77		elif [[ $line =~ ^machine\ *=\ *(.*)$ ]]; then
78			machine=${BASH_REMATCH[1]}
79		elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
80			check=${BASH_REMATCH[1]}
81		elif [[ $line =~ ^disabled_if\ *=\ *(.*)$ ]]; then
82			disabled_if=${BASH_REMATCH[1]}
83		elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then
84			accel=${BASH_REMATCH[1]}
85		elif [[ $line =~ ^timeout\ *=\ *(.*)$ ]]; then
86			timeout=${BASH_REMATCH[1]}
87		fi
88	done
89	if [ -n "${testname}" ]; then
90		$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
91	fi
92	exec {fd}<&-
93}
94
95function arch_cmd()
96{
97	[ "${ARCH_CMD}" ] && echo "${ARCH_CMD}"
98}
99
100# The current file has to be the only file sourcing the arch helper
101# file. Shellcheck can't follow this so help it out. There doesn't appear to be a
102# way to specify multiple alternatives, so we will have to rethink this if things
103# get more complicated.
104ARCH_FUNC=scripts/${ARCH}/func.bash
105if [ -f "${ARCH_FUNC}" ]; then
106# shellcheck source=scripts/s390x/func.bash
107	source "${ARCH_FUNC}"
108fi
109