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