1############################################################################## 2# qemu_fixup_return_code translates the ambiguous exit status in Table1 to that 3# in Table2. Table3 simply documents the complete status table. 4# 5# Table1: Before fixup 6# -------------------- 7# 0 - Unexpected exit from QEMU (possible signal), or the unittest did 8# not use debug-exit 9# 1 - most likely unittest succeeded, or QEMU failed 10# 11# Table2: After fixup 12# ------------------- 13# 0 - Everything succeeded 14# 1 - most likely QEMU failed 15# 16# Table3: Complete table 17# ---------------------- 18# 0 - SUCCESS 19# 1 - most likely QEMU failed 20# 2 - most likely a run script failed 21# 3 - most likely the unittest failed 22# 124 - most likely the unittest timed out 23# 127 - most likely the unittest called abort() 24# 1..127 - FAILURE (could be QEMU, a run script, or the unittest) 25# >= 128 - Signal (signum = status - 128) 26############################################################################## 27function qemu_fixup_return_code() 28{ 29 local ret=$1 30 # Remove $ret from the list of arguments 31 shift 1 32 local errors=$* 33 local sig 34 35 [ $ret -eq 134 ] && echo "QEMU Aborted" >&2 36 37 if [ "$errors" ]; then 38 sig=$(grep 'terminating on signal' <<<"$errors") 39 if [ "$sig" ]; then 40 # This is too complex for ${var/search/replace} 41 # shellcheck disable=SC2001 42 sig=$(sed 's/.*terminating on signal \([0-9][0-9]*\).*/\1/' <<<"$sig") 43 fi 44 fi 45 46 if [ $ret -eq 0 ]; then 47 # Some signals result in a zero return status, but the 48 # error log tells the truth. 49 if [ "$sig" ]; then 50 ((ret=sig+128)) 51 else 52 # Exiting with zero (non-debugexit) is an error 53 ret=1 54 fi 55 elif [ $ret -eq 1 ]; then 56 # Even when ret==1 (unittest success) if we also got stderr 57 # logs, then we assume a QEMU failure. Otherwise we translate 58 # status of 1 to 0 (SUCCESS) 59 if [ "$errors" ]; then 60 if ! grep -qvi warning <<<"$errors" ; then 61 ret=0 62 fi 63 else 64 ret=0 65 fi 66 fi 67 68 echo $ret 69} 70 71function kvmtool_fixup_return_code() 72{ 73 local ret=$1 74 75 # Force run_test_status() to interpret the STATUS line. 76 if [ $ret -eq 0 ]; then 77 ret=1 78 fi 79 80 echo $ret 81} 82 83declare -A vmm_optname=( 84 [qemu,args]='-append' 85 [qemu,fixup_return_code]=qemu_fixup_return_code 86 [qemu,initrd]='-initrd' 87 [qemu,nr_cpus]='-smp' 88 89 [kvmtool,args]='--params' 90 [kvmtool,fixup_return_code]=kvmtool_fixup_return_code 91 [kvmtool,initrd]='--initrd' 92 [kvmtool,nr_cpus]='--cpus' 93) 94 95function vmm_optname_args() 96{ 97 echo ${vmm_optname[$(vmm_get_target),args]} 98} 99 100function vmm_fixup_return_code() 101{ 102 ${vmm_optname[$(vmm_get_target),fixup_return_code]} "$@" 103} 104 105function vmm_optname_initrd() 106{ 107 echo ${vmm_optname[$(vmm_get_target),initrd]} 108} 109 110function vmm_optname_nr_cpus() 111{ 112 echo ${vmm_optname[$(vmm_get_target),nr_cpus]} 113} 114 115function vmm_get_target() 116{ 117 if [[ -z "$TARGET" ]]; then 118 echo "qemu" 119 else 120 echo "$TARGET" 121 fi 122} 123 124function vmm_check_supported() 125{ 126 # We're not interested in the return code for vmm_get_target(). 127 # shellcheck disable=SC2155 128 local target=$(vmm_get_target) 129 130 case "$target" in 131 qemu) 132 return 0 133 ;; 134 *) 135 echo "$0 does not support target '$target'" 136 exit 2 137 ;; 138 esac 139} 140 141function vmm_unittest_params_name() 142{ 143 # shellcheck disable=SC2155 144 local target=$(vmm_get_target) 145 146 case "$target" in 147 qemu) 148 echo "extra_params|qemu_params" 149 ;; 150 kvmtool) 151 echo "kvmtool_params" 152 ;; 153 *) 154 echo "$0 does not support '$target'" 155 exit 2 156 ;; 157 esac 158} 159