• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
25
26verbose_run () {
27    if [ -z "$QUIET_TEST" ]; then
28	"$@"
29    else
30	"$@" > /dev/null 2> /dev/null
31    fi
32}
33
34verbose_run_check () {
35    verbose_run "$@"
36    ret="$?"
37    FAIL_IF_SIGNAL $ret
38    if [ $ret != 0 ]; then
39	FAIL "Returned error code $ret"
40    fi
41}
42
43verbose_run_log () {
44    LOG="$1"
45    shift
46    "$@" > "$LOG" 2>&1
47    ret=$?
48    if [ -z "$QUIET_TEST" ]; then
49	cat "$LOG" >&2
50    fi
51    return $ret
52}
53
54verbose_run_log_check () {
55    verbose_run_log "$@"
56    ret="$?"
57    FAIL_IF_SIGNAL $ret
58    if [ $ret != 0 ]; then
59	FAIL "Returned error code $ret"
60    fi
61}
62
63