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