1: "${RUNTIME_arch_run?}" 2: ${MAX_SMP:=$(getconf _NPROCESSORS_CONF)} 3: ${TIMEOUT:=90s} 4 5PASS() { echo -ne "\e[32mPASS\e[0m"; } 6SKIP() { echo -ne "\e[33mSKIP\e[0m"; } 7FAIL() { echo -ne "\e[31mFAIL\e[0m"; } 8 9extract_summary() 10{ 11 local cr=$'\r' 12 tail -3 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/'"$cr"'\{0,1\}$/)/' 13} 14 15# 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)" 19 20 echo "$log" | grep "_NO_FILE_4Uhere_" | 21 grep -q -e "could not load kernel" -e "error loading" && 22 return 1 23 24 RUNTIME_log_stderr <<< "$log" 25 26 echo "$log" 27 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 36skip_nodefault() 37{ 38 [ "$run_all_tests" = "yes" ] && return 1 39 [ "$STANDALONE" != "yes" ] && return 0 40 41 while true; do 42 read -r -p "Test marked not to be run by default, are you sure (y/N)? " yn 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 54function run() 55{ 56 local testname="$1" 57 local groups="$2" 58 local smp="$3" 59 local kernel="$4" 60 local opts="$5" 61 local arch="$6" 62 local check="${CHECK:-$7}" 63 local accel="${ACCEL:-$8}" 64 local timeout="${9:-$TIMEOUT}" # unittests.cfg overrides the default 65 66 if [ -z "$testname" ]; then 67 return 68 fi 69 70 if [ -n "$only_group" ] && ! grep -qw "$only_group" <<<$groups; then 71 return 72 fi 73 74 if [ -z "$only_group" ] && grep -qw "nodefault" <<<$groups && 75 skip_nodefault; then 76 echo -e "`SKIP` $testname (test marked as manual run only)" 77 return; 78 fi 79 80 if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then 81 echo "`SKIP` $1 ($arch only)" 82 return 2 83 fi 84 85 # check a file for a particular value before running a test 86 # the check line can contain multiple files to check separated by a space 87 # but each check parameter needs to be of the form <path>=<value> 88 for check_param in "${check[@]}"; do 89 path=${check_param%%=*} 90 value=${check_param#*=} 91 if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then 92 echo "`SKIP` $1 ($path not equal to $value)" 93 return 2 94 fi 95 done 96 97 last_line=$(premature_failure > >(tail -1)) && { 98 echo "`SKIP` $1 ($last_line)" 99 return 77 100 } 101 102 cmdline=$(get_cmdline $kernel) 103 if grep -qw "migration" <<<$groups ; then 104 cmdline="MIGRATION=yes $cmdline" 105 fi 106 if [ "$verbose" = "yes" ]; then 107 echo $cmdline 108 fi 109 110 # extra_params in the config file may contain backticks that need to be 111 # expanded, so use eval to start qemu. Use "> >(foo)" instead of a pipe to 112 # preserve the exit status. 113 summary=$(eval $cmdline 2> >(RUNTIME_log_stderr) \ 114 > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary)) 115 ret=$? 116 [ "$STANDALONE" != "yes" ] && echo > >(RUNTIME_log_stdout $kernel) 117 118 if [ $ret -eq 0 ]; then 119 echo "`PASS` $1 $summary" 120 elif [ $ret -eq 77 ]; then 121 echo "`SKIP` $1 $summary" 122 elif [ $ret -eq 124 ]; then 123 echo "`FAIL` $1 (timeout; duration=$timeout)" 124 elif [ $ret -gt 127 ]; then 125 echo "`FAIL` $1 (terminated on SIG$(kill -l $(($ret - 128))))" 126 else 127 echo "`FAIL` $1 $summary" 128 fi 129 130 return $ret 131} 132 133# 134# Probe for MAX_SMP, in case it's less than the number of host cpus. 135# 136# This probing currently only works for ARM, as x86 bails on another 137# error first. Also, this probing isn't necessary for any ARM hosts 138# running kernels later than v4.3, i.e. those including ef748917b52 139# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some 140# point when maintaining the while loop gets too tiresome, we can 141# just remove it... 142while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \ 143 |& grep -qi 'exceeds max CPUs'; do 144 ((--MAX_SMP)) 145done 146