Radim Krčmář | 103832e | 2016-01-19 14:24:06 +0100 | [diff] [blame] | 1 | : "${RUNTIME_arch_run?}" |
Andrew Jones | 1c0ab4e | 2019-11-20 15:19:28 +0100 | [diff] [blame] | 2 | : ${MAX_SMP:=$(getconf _NPROCESSORS_ONLN)} |
Andrew Jones | fd14935 | 2016-03-02 18:33:02 +0100 | [diff] [blame] | 3 | : ${TIMEOUT:=90s} |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 4 | |
Radim Krčmář | 9c51d8c | 2016-05-11 18:12:50 +0200 | [diff] [blame] | 5 | PASS() { echo -ne "\e[32mPASS\e[0m"; } |
| 6 | SKIP() { echo -ne "\e[33mSKIP\e[0m"; } |
| 7 | FAIL() { echo -ne "\e[31mFAIL\e[0m"; } |
| 8 | |
Radim Krčmář | e9ae961 | 2016-05-11 18:12:51 +0200 | [diff] [blame] | 9 | extract_summary() |
| 10 | { |
Peng Hao | a38015d | 2018-09-19 23:29:51 +0200 | [diff] [blame] | 11 | local cr=$'\r' |
| 12 | tail -3 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/'"$cr"'\{0,1\}$/)/' |
Radim Krčmář | e9ae961 | 2016-05-11 18:12:51 +0200 | [diff] [blame] | 13 | } |
| 14 | |
Radim Krčmář | d5f55dc | 2016-05-11 18:30:41 +0200 | [diff] [blame] | 15 | # We assume that QEMU is going to work if it tried to load the kernel |
| 16 | premature_failure() |
| 17 | { |
| 18 | local log="$(eval $(get_cmdline _NO_FILE_4Uhere_) 2>&1)" |
Radim Krčmář | d5f55dc | 2016-05-11 18:30:41 +0200 | [diff] [blame] | 19 | |
Lukáš Doktor | df47798 | 2016-06-01 08:20:12 +0200 | [diff] [blame] | 20 | echo "$log" | grep "_NO_FILE_4Uhere_" | |
Thomas Huth | 47a228b | 2019-12-11 10:42:18 +0100 | [diff] [blame] | 21 | grep -q -e "could not \(load\|open\) kernel" -e "error loading" && |
Radim Krčmář | d5f55dc | 2016-05-11 18:30:41 +0200 | [diff] [blame] | 22 | return 1 |
| 23 | |
| 24 | RUNTIME_log_stderr <<< "$log" |
| 25 | |
Lukáš Doktor | df47798 | 2016-06-01 08:20:12 +0200 | [diff] [blame] | 26 | echo "$log" |
Radim Krčmář | d5f55dc | 2016-05-11 18:30:41 +0200 | [diff] [blame] | 27 | return 0 |
| 28 | } |
| 29 | |
| 30 | get_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 Singh | 9a00898 | 2016-08-19 11:10:10 +1000 | [diff] [blame] | 36 | skip_nodefault() |
| 37 | { |
Andrew Jones | 7430e2c | 2017-03-08 18:00:35 +0100 | [diff] [blame] | 38 | [ "$run_all_tests" = "yes" ] && return 1 |
Thomas Huth | 57ab5a6 | 2022-01-20 19:22:00 +0100 | [diff] [blame] | 39 | [ "$KUT_STANDALONE" != "yes" ] && return 0 |
Suraj Jitindar Singh | 9a00898 | 2016-08-19 11:10:10 +1000 | [diff] [blame] | 40 | |
| 41 | while true; do |
Andrew Jones | d76bf07 | 2017-07-26 15:21:37 +0200 | [diff] [blame] | 42 | read -r -p "Test marked not to be run by default, are you sure (y/N)? " yn |
Suraj Jitindar Singh | 9a00898 | 2016-08-19 11:10:10 +1000 | [diff] [blame] | 43 | 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 Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 54 | function print_result() |
| 55 | { |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 56 | local status="$1" |
| 57 | local testname="$2" |
| 58 | local summary="$3" |
| 59 | local reason="$4" |
| 60 | |
Stefan Raspl | 6e1d375 | 2019-02-22 15:38:58 +0100 | [diff] [blame] | 61 | if [ -z "$reason" ]; then |
| 62 | echo "`$status` $testname $summary" |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 63 | else |
Stefan Raspl | 6e1d375 | 2019-02-22 15:38:58 +0100 | [diff] [blame] | 64 | echo "`$status` $testname ($reason)" |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 65 | fi |
| 66 | } |
| 67 | |
Paolo Bonzini | b373304 | 2020-07-01 11:43:07 +0200 | [diff] [blame] | 68 | function find_word() |
| 69 | { |
| 70 | grep -Fq " $1 " <<< " $2 " |
| 71 | } |
| 72 | |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 73 | function 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 Jones | e9bdb8b | 2016-03-02 18:33:01 +0100 | [diff] [blame] | 81 | local check="${CHECK:-$7}" |
Andrew Jones | a61dedd | 2020-04-04 17:47:39 +0200 | [diff] [blame] | 82 | local accel="$8" |
Andrew Jones | fd14935 | 2016-03-02 18:33:02 +0100 | [diff] [blame] | 83 | local timeout="${9:-$TIMEOUT}" # unittests.cfg overrides the default |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 84 | |
Alexandru Elisei | c98ce6e | 2022-02-23 12:55:37 +0000 | [diff] [blame] | 85 | if [ "${CONFIG_EFI}" == "y" ]; then |
Marc Orr | 9509ddf | 2021-11-16 12:40:51 -0800 | [diff] [blame] | 86 | kernel=$(basename $kernel .flat) |
| 87 | fi |
| 88 | |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 89 | if [ -z "$testname" ]; then |
| 90 | return |
| 91 | fi |
| 92 | |
Paolo Bonzini | b373304 | 2020-07-01 11:43:07 +0200 | [diff] [blame] | 93 | if [ -n "$only_tests" ] && ! find_word "$testname" "$only_tests"; then |
Paolo Bonzini | 231a2e7 | 2019-02-14 16:59:20 +0100 | [diff] [blame] | 94 | return |
| 95 | fi |
| 96 | |
Paolo Bonzini | b373304 | 2020-07-01 11:43:07 +0200 | [diff] [blame] | 97 | if [ -n "$only_group" ] && ! find_word "$only_group" "$groups"; then |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 98 | return |
| 99 | fi |
| 100 | |
Paolo Bonzini | b373304 | 2020-07-01 11:43:07 +0200 | [diff] [blame] | 101 | if [ -z "$only_group" ] && find_word nodefault "$groups" && |
Suraj Jitindar Singh | 9a00898 | 2016-08-19 11:10:10 +1000 | [diff] [blame] | 102 | skip_nodefault; then |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 103 | print_result "SKIP" $testname "" "test marked as manual run only" |
Suraj Jitindar Singh | 9a00898 | 2016-08-19 11:10:10 +1000 | [diff] [blame] | 104 | return; |
| 105 | fi |
| 106 | |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 107 | if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 108 | print_result "SKIP" $testname "" "$arch only" |
Andrew Jones | a383126 | 2016-03-02 18:32:58 +0100 | [diff] [blame] | 109 | return 2 |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 110 | fi |
| 111 | |
Andrew Jones | a61dedd | 2020-04-04 17:47:39 +0200 | [diff] [blame] | 112 | 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ář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 119 | # 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 Bonzini | cde27d4 | 2020-09-29 08:23:11 -0400 | [diff] [blame] | 122 | 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ář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 132 | |
Andrew Jones | 8727c88 | 2016-11-15 18:26:24 +0100 | [diff] [blame] | 133 | last_line=$(premature_failure > >(tail -1)) && { |
Marc Orr | 9509ddf | 2021-11-16 12:40:51 -0800 | [diff] [blame] | 134 | skip=true |
Sean Christopherson | 9b33567 | 2022-06-15 23:29:31 +0000 | [diff] [blame] | 135 | if [ "${CONFIG_EFI}" == "y" ] && [[ "${last_line}" =~ "Dummy Hello World!" ]]; then |
Marc Orr | 9509ddf | 2021-11-16 12:40:51 -0800 | [diff] [blame] | 136 | skip=false |
| 137 | fi |
| 138 | if [ ${skip} == true ]; then |
| 139 | print_result "SKIP" $testname "" "$last_line" |
| 140 | return 77 |
| 141 | fi |
Radim Krčmář | d5f55dc | 2016-05-11 18:30:41 +0200 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | cmdline=$(get_cmdline $kernel) |
Andrew Jones | 745f5eb | 2021-11-12 14:37:39 +0100 | [diff] [blame] | 145 | if find_word "migration" "$groups"; then |
Thomas Huth | 37abdda | 2017-03-28 07:50:00 +0200 | [diff] [blame] | 146 | cmdline="MIGRATION=yes $cmdline" |
| 147 | fi |
Andrew Jones | 5b842da | 2016-01-22 15:58:28 +0100 | [diff] [blame] | 148 | if [ "$verbose" = "yes" ]; then |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 149 | echo $cmdline |
| 150 | fi |
| 151 | |
| 152 | # extra_params in the config file may contain backticks that need to be |
Radim Krčmář | e9ae961 | 2016-05-11 18:12:51 +0200 | [diff] [blame] | 153 | # expanded, so use eval to start qemu. Use "> >(foo)" instead of a pipe to |
| 154 | # preserve the exit status. |
Marc Hartmayer | e01499d | 2020-08-25 12:20:36 +0200 | [diff] [blame] | 155 | summary=$(eval $cmdline 2> >(RUNTIME_log_stderr $testname) \ |
| 156 | > >(tee >(RUNTIME_log_stdout $testname $kernel) | extract_summary)) |
Radim Krčmář | 5af378d | 2016-01-19 14:24:11 +0100 | [diff] [blame] | 157 | ret=$? |
Thomas Huth | 57ab5a6 | 2022-01-20 19:22:00 +0100 | [diff] [blame] | 158 | [ "$KUT_STANDALONE" != "yes" ] && echo > >(RUNTIME_log_stdout $testname $kernel) |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 159 | |
Andrew Jones | b2a2aa5 | 2016-03-02 18:32:59 +0100 | [diff] [blame] | 160 | if [ $ret -eq 0 ]; then |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 161 | print_result "PASS" $testname "$summary" |
Radim Krčmář | a0833bf | 2016-05-11 18:12:43 +0200 | [diff] [blame] | 162 | elif [ $ret -eq 77 ]; then |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 163 | print_result "SKIP" $testname "$summary" |
Andrew Jones | fd14935 | 2016-03-02 18:33:02 +0100 | [diff] [blame] | 164 | elif [ $ret -eq 124 ]; then |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 165 | print_result "FAIL" $testname "" "timeout; duration=$timeout" |
Nico Boehr | 8375379 | 2022-03-22 14:44:07 +0100 | [diff] [blame] | 166 | if [ "$tap_output" = "yes" ]; then |
| 167 | echo "not ok TEST_NUMBER - ${testname}: timeout; duration=$timeout" >&3 |
| 168 | fi |
Andrew Jones | 8727c88 | 2016-11-15 18:26:24 +0100 | [diff] [blame] | 169 | elif [ $ret -gt 127 ]; then |
Nico Boehr | 8375379 | 2022-03-22 14:44:07 +0100 | [diff] [blame] | 170 | 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ář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 177 | else |
Sergey Bronnikov | 851a00d | 2018-07-18 00:02:22 +0300 | [diff] [blame] | 178 | print_result "FAIL" $testname "$summary" |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 179 | fi |
Radim Krčmář | 5af378d | 2016-01-19 14:24:11 +0100 | [diff] [blame] | 180 | |
| 181 | return $ret |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Andrew Jones | bc52c0c | 2016-01-22 15:58:24 +0100 | [diff] [blame] | 184 | # |
| 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... |
| 193 | while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \ |
| 194 | |& grep -qi 'exceeds max CPUs'; do |
Christoffer Dall | 97b3ae9 | 2018-09-03 12:58:45 +0200 | [diff] [blame] | 195 | MAX_SMP=$((MAX_SMP >> 1)) |
Radim Krčmář | 6a53fc2 | 2016-01-19 14:24:05 +0100 | [diff] [blame] | 196 | done |