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 21if [ -z "$TEST_BINDIR" ]; then 22 TEST_BINDIR=.. 23fi 24 25DTC=${TEST_BINDIR}/dtc 26DTGET=${TEST_BINDIR}/fdtget 27DTPUT=${TEST_BINDIR}/fdtput 28FDTDUMP=${TEST_BINDIR}/fdtdump 29FDTOVERLAY=${TEST_BINDIR}/fdtoverlay 30 31verbose_run () { 32 if [ -z "$QUIET_TEST" ]; then 33 "$@" 34 else 35 "$@" > /dev/null 2> /dev/null 36 fi 37} 38 39verbose_run_check () { 40 verbose_run "$@" 41 ret="$?" 42 FAIL_IF_SIGNAL $ret 43 if [ $ret != 0 ]; then 44 FAIL "Returned error code $ret" 45 fi 46} 47 48verbose_run_log () { 49 LOG="$1" 50 shift 51 "$@" > "$LOG" 2>&1 52 ret=$? 53 if [ -z "$QUIET_TEST" ]; then 54 cat "$LOG" >&2 55 fi 56 return $ret 57} 58 59verbose_run_log_check () { 60 verbose_run_log "$@" 61 ret="$?" 62 FAIL_IF_SIGNAL $ret 63 if [ $ret != 0 ]; then 64 FAIL "Returned error code $ret" 65 fi 66} 67 68