1############################################################################## 2# run_qemu translates the ambiguous exit status in Table1 to that in Table2. 3# 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############################################################################## 27run_qemu () 28{ 29 local stdout errors ret sig 30 31 # stdout to {stdout}, stderr to $errors 32 exec {stdout}>&1 33 errors=$("${@}" 2>&1 1>&${stdout}) 34 ret=$? 35 exec {stdout}>&- 36 37 if [ "$errors" ]; then 38 printf "%s\n" "$errors" >&2 39 sig=$(grep 'terminating on signal' <<<"$errors") 40 if [ "$sig" ]; then 41 sig=$(sed 's/.*terminating on signal \([0-9][0-9]*\).*/\1/' <<<"$sig") 42 fi 43 fi 44 45 if [ $ret -eq 0 ]; then 46 # Some signals result in a zero return status, but the 47 # error log tells the truth. 48 if [ "$sig" ]; then 49 ((ret=sig+128)) 50 else 51 # Exiting with zero (non-debugexit) is an error 52 ret=1 53 fi 54 elif [ $ret -eq 1 ]; then 55 # Even when ret==1 (unittest success) if we also got stderr 56 # logs, then we assume a QEMU failure. Otherwise we translate 57 # status of 1 to 0 (SUCCESS) 58 if [ -z "$(echo "$errors" | grep -vi warning)" ]; then 59 ret=0 60 fi 61 fi 62 63 return $ret 64} 65 66timeout_cmd () 67{ 68 if [ "$TIMEOUT" ] && [ "$TIMEOUT" != "0" ]; then 69 echo "timeout -k 1s --foreground $TIMEOUT" 70 fi 71} 72