1# Common functions for shell testcases 2 3PASS () { 4 echo "PASS" 5 exit 0 6} 7 8FAIL () { 9 echo "FAIL" "$@" 10 exit 2 11} 12 13FAIL_IF_SIGNAL () { 14 ret="$1" 15 if [ "$ret" -gt 127 ]; then 16 signame=$(kill -l $((ret - 128))) 17 FAIL "Killed by SIG$signame" 18 fi 19} 20 21DTC=../dtc 22DTGET=../fdtget 23DTPUT=../fdtput 24FDTDUMP=../fdtdump 25FDTOVERLAY=../fdtoverlay 26 27verbose_run () { 28 if [ -z "$QUIET_TEST" ]; then 29 "$@" 30 else 31 "$@" > /dev/null 2> /dev/null 32 fi 33} 34 35verbose_run_check () { 36 verbose_run "$@" 37 ret="$?" 38 FAIL_IF_SIGNAL $ret 39 if [ $ret != 0 ]; then 40 FAIL "Returned error code $ret" 41 fi 42} 43 44verbose_run_log () { 45 LOG="$1" 46 shift 47 "$@" > "$LOG" 2>&1 48 ret=$? 49 if [ -z "$QUIET_TEST" ]; then 50 cat "$LOG" >&2 51 fi 52 return $ret 53} 54 55verbose_run_log_check () { 56 verbose_run_log "$@" 57 ret="$?" 58 FAIL_IF_SIGNAL $ret 59 if [ $ret != 0 ]; then 60 FAIL "Returned error code $ret" 61 fi 62} 63 64