blob: bbf87cf4ed3f4659f08475c5c5676a714971d228 [file] [log] [blame]
Radim Krčmář103832e2016-01-19 14:24:06 +01001: "${RUNTIME_arch_run?}"
Andrew Jones1c0ab4e2019-11-20 15:19:28 +01002: ${MAX_SMP:=$(getconf _NPROCESSORS_ONLN)}
Andrew Jonesfd149352016-03-02 18:33:02 +01003: ${TIMEOUT:=90s}
Radim Krčmář6a53fc22016-01-19 14:24:05 +01004
Radim Krčmář9c51d8c2016-05-11 18:12:50 +02005PASS() { echo -ne "\e[32mPASS\e[0m"; }
6SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
7FAIL() { echo -ne "\e[31mFAIL\e[0m"; }
8
Radim Krčmáře9ae9612016-05-11 18:12:51 +02009extract_summary()
10{
Peng Haoa38015d2018-09-19 23:29:51 +020011 local cr=$'\r'
12 tail -3 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/'"$cr"'\{0,1\}$/)/'
Radim Krčmáře9ae9612016-05-11 18:12:51 +020013}
14
Radim Krčmářd5f55dc2016-05-11 18:30:41 +020015# We assume that QEMU is going to work if it tried to load the kernel
16premature_failure()
17{
18 local log="$(eval $(get_cmdline _NO_FILE_4Uhere_) 2>&1)"
Radim Krčmářd5f55dc2016-05-11 18:30:41 +020019
Lukáš Doktordf477982016-06-01 08:20:12 +020020 echo "$log" | grep "_NO_FILE_4Uhere_" |
Thomas Huth47a228b2019-12-11 10:42:18 +010021 grep -q -e "could not \(load\|open\) kernel" -e "error loading" &&
Radim Krčmářd5f55dc2016-05-11 18:30:41 +020022 return 1
23
24 RUNTIME_log_stderr <<< "$log"
25
Lukáš Doktordf477982016-06-01 08:20:12 +020026 echo "$log"
Radim Krčmářd5f55dc2016-05-11 18:30:41 +020027 return 0
28}
29
30get_cmdline()
31{
32 local kernel=$1
33 echo "TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
34}
35
Suraj Jitindar Singh9a008982016-08-19 11:10:10 +100036skip_nodefault()
37{
Andrew Jones7430e2c2017-03-08 18:00:35 +010038 [ "$run_all_tests" = "yes" ] && return 1
Thomas Huth57ab5a62022-01-20 19:22:00 +010039 [ "$KUT_STANDALONE" != "yes" ] && return 0
Suraj Jitindar Singh9a008982016-08-19 11:10:10 +100040
41 while true; do
Andrew Jonesd76bf072017-07-26 15:21:37 +020042 read -r -p "Test marked not to be run by default, are you sure (y/N)? " yn
Suraj Jitindar Singh9a008982016-08-19 11:10:10 +100043 case $yn in
44 "Y" | "y" | "Yes" | "yes")
45 return 1
46 ;;
47 "" | "N" | "n" | "No" | "no" | "q" | "quit" | "exit")
48 return 0
49 ;;
50 esac
51 done
52}
53
Sergey Bronnikov851a00d2018-07-18 00:02:22 +030054function print_result()
55{
Sergey Bronnikov851a00d2018-07-18 00:02:22 +030056 local status="$1"
57 local testname="$2"
58 local summary="$3"
59 local reason="$4"
60
Stefan Raspl6e1d3752019-02-22 15:38:58 +010061 if [ -z "$reason" ]; then
62 echo "`$status` $testname $summary"
Sergey Bronnikov851a00d2018-07-18 00:02:22 +030063 else
Stefan Raspl6e1d3752019-02-22 15:38:58 +010064 echo "`$status` $testname ($reason)"
Sergey Bronnikov851a00d2018-07-18 00:02:22 +030065 fi
66}
67
Paolo Bonzinib3733042020-07-01 11:43:07 +020068function find_word()
69{
70 grep -Fq " $1 " <<< " $2 "
71}
72
Radim Krčmář6a53fc22016-01-19 14:24:05 +010073function run()
74{
75 local testname="$1"
76 local groups="$2"
77 local smp="$3"
78 local kernel="$4"
79 local opts="$5"
80 local arch="$6"
Andrew Jonese9bdb8b2016-03-02 18:33:01 +010081 local check="${CHECK:-$7}"
Andrew Jonesa61dedd2020-04-04 17:47:39 +020082 local accel="$8"
Andrew Jonesfd149352016-03-02 18:33:02 +010083 local timeout="${9:-$TIMEOUT}" # unittests.cfg overrides the default
Radim Krčmář6a53fc22016-01-19 14:24:05 +010084
Alexandru Eliseic98ce6e2022-02-23 12:55:37 +000085 if [ "${CONFIG_EFI}" == "y" ]; then
Marc Orr9509ddf2021-11-16 12:40:51 -080086 kernel=$(basename $kernel .flat)
87 fi
88
Radim Krčmář6a53fc22016-01-19 14:24:05 +010089 if [ -z "$testname" ]; then
90 return
91 fi
92
Paolo Bonzinib3733042020-07-01 11:43:07 +020093 if [ -n "$only_tests" ] && ! find_word "$testname" "$only_tests"; then
Paolo Bonzini231a2e72019-02-14 16:59:20 +010094 return
95 fi
96
Paolo Bonzinib3733042020-07-01 11:43:07 +020097 if [ -n "$only_group" ] && ! find_word "$only_group" "$groups"; then
Radim Krčmář6a53fc22016-01-19 14:24:05 +010098 return
99 fi
100
Paolo Bonzinib3733042020-07-01 11:43:07 +0200101 if [ -z "$only_group" ] && find_word nodefault "$groups" &&
Suraj Jitindar Singh9a008982016-08-19 11:10:10 +1000102 skip_nodefault; then
Sergey Bronnikov851a00d2018-07-18 00:02:22 +0300103 print_result "SKIP" $testname "" "test marked as manual run only"
Suraj Jitindar Singh9a008982016-08-19 11:10:10 +1000104 return;
105 fi
106
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100107 if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
Sergey Bronnikov851a00d2018-07-18 00:02:22 +0300108 print_result "SKIP" $testname "" "$arch only"
Andrew Jonesa3831262016-03-02 18:32:58 +0100109 return 2
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100110 fi
111
Andrew Jonesa61dedd2020-04-04 17:47:39 +0200112 if [ -n "$accel" ] && [ -n "$ACCEL" ] && [ "$accel" != "$ACCEL" ]; then
113 print_result "SKIP" $testname "" "$accel only, but ACCEL=$ACCEL"
114 return 2
115 elif [ -n "$ACCEL" ]; then
116 accel="$ACCEL"
117 fi
118
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100119 # check a file for a particular value before running a test
120 # the check line can contain multiple files to check separated by a space
121 # but each check parameter needs to be of the form <path>=<value>
Paolo Bonzinicde27d42020-09-29 08:23:11 -0400122 if [ "$check" ]; then
123 for check_param in "${check[@]}"; do
124 path=${check_param%%=*}
125 value=${check_param#*=}
126 if ! [ -f "$path" ] || [ "$(cat $path)" != "$value" ]; then
127 print_result "SKIP" $testname "" "$path not equal to $value"
128 return 2
129 fi
130 done
131 fi
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100132
Andrew Jones8727c882016-11-15 18:26:24 +0100133 last_line=$(premature_failure > >(tail -1)) && {
Marc Orr9509ddf2021-11-16 12:40:51 -0800134 skip=true
Sean Christopherson9b335672022-06-15 23:29:31 +0000135 if [ "${CONFIG_EFI}" == "y" ] && [[ "${last_line}" =~ "Dummy Hello World!" ]]; then
Marc Orr9509ddf2021-11-16 12:40:51 -0800136 skip=false
137 fi
138 if [ ${skip} == true ]; then
139 print_result "SKIP" $testname "" "$last_line"
140 return 77
141 fi
Radim Krčmářd5f55dc2016-05-11 18:30:41 +0200142 }
143
144 cmdline=$(get_cmdline $kernel)
Andrew Jones745f5eb2021-11-12 14:37:39 +0100145 if find_word "migration" "$groups"; then
Thomas Huth37abdda2017-03-28 07:50:00 +0200146 cmdline="MIGRATION=yes $cmdline"
147 fi
Andrew Jones5b842da2016-01-22 15:58:28 +0100148 if [ "$verbose" = "yes" ]; then
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100149 echo $cmdline
150 fi
151
152 # extra_params in the config file may contain backticks that need to be
Radim Krčmáře9ae9612016-05-11 18:12:51 +0200153 # expanded, so use eval to start qemu. Use "> >(foo)" instead of a pipe to
154 # preserve the exit status.
Marc Hartmayere01499d2020-08-25 12:20:36 +0200155 summary=$(eval $cmdline 2> >(RUNTIME_log_stderr $testname) \
156 > >(tee >(RUNTIME_log_stdout $testname $kernel) | extract_summary))
Radim Krčmář5af378d2016-01-19 14:24:11 +0100157 ret=$?
Thomas Huth57ab5a62022-01-20 19:22:00 +0100158 [ "$KUT_STANDALONE" != "yes" ] && echo > >(RUNTIME_log_stdout $testname $kernel)
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100159
Andrew Jonesb2a2aa52016-03-02 18:32:59 +0100160 if [ $ret -eq 0 ]; then
Sergey Bronnikov851a00d2018-07-18 00:02:22 +0300161 print_result "PASS" $testname "$summary"
Radim Krčmářa0833bf2016-05-11 18:12:43 +0200162 elif [ $ret -eq 77 ]; then
Sergey Bronnikov851a00d2018-07-18 00:02:22 +0300163 print_result "SKIP" $testname "$summary"
Andrew Jonesfd149352016-03-02 18:33:02 +0100164 elif [ $ret -eq 124 ]; then
Sergey Bronnikov851a00d2018-07-18 00:02:22 +0300165 print_result "FAIL" $testname "" "timeout; duration=$timeout"
Nico Boehr83753792022-03-22 14:44:07 +0100166 if [ "$tap_output" = "yes" ]; then
167 echo "not ok TEST_NUMBER - ${testname}: timeout; duration=$timeout" >&3
168 fi
Andrew Jones8727c882016-11-15 18:26:24 +0100169 elif [ $ret -gt 127 ]; then
Nico Boehr83753792022-03-22 14:44:07 +0100170 signame="SIG"$(kill -l $(($ret - 128)))
171 print_result "FAIL" $testname "" "terminated on $signame"
172 if [ "$tap_output" = "yes" ]; then
173 echo "not ok TEST_NUMBER - ${testname}: terminated on $signame" >&3
174 fi
175 elif [ $ret -eq 127 ] && [ "$tap_output" = "yes" ]; then
176 echo "not ok TEST_NUMBER - ${testname}: aborted" >&3
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100177 else
Sergey Bronnikov851a00d2018-07-18 00:02:22 +0300178 print_result "FAIL" $testname "$summary"
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100179 fi
Radim Krčmář5af378d2016-01-19 14:24:11 +0100180
181 return $ret
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100182}
183
Andrew Jonesbc52c0c2016-01-22 15:58:24 +0100184#
185# Probe for MAX_SMP, in case it's less than the number of host cpus.
186#
187# This probing currently only works for ARM, as x86 bails on another
188# error first. Also, this probing isn't necessary for any ARM hosts
189# running kernels later than v4.3, i.e. those including ef748917b52
190# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some
191# point when maintaining the while loop gets too tiresome, we can
192# just remove it...
193while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
194 |& grep -qi 'exceeds max CPUs'; do
Christoffer Dall97b3ae92018-09-03 12:58:45 +0200195 MAX_SMP=$((MAX_SMP >> 1))
Radim Krčmář6a53fc22016-01-19 14:24:05 +0100196done