ctdbd: Pass event name to hung script debugger
[Samba.git] / ctdb / tests / scripts / unit.sh
blobc7c2b7a27363156f089f3a31346f9aff46d17432
1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 . "${TEST_SCRIPTS_DIR}/common.sh"
5 # Common variables and functions for CTDB unit tests.
7 # Set the required result for a test.
8 # - Argument 1 is exit code.
9 # - Argument 2, if present is the required test output but "--"
10 # indicates empty output.
11 # If argument 2 is not present or null then read required test output
12 # from stdin.
13 required_result ()
15 required_rc="${1:-0}"
16 if [ -n "$2" ] ; then
17 if [ "$2" = "--" ] ; then
18 required_output=""
19 else
20 required_output="$2"
22 else
23 if ! tty -s ; then
24 required_output=$(cat)
25 else
26 required_output=""
31 ok ()
33 required_result 0 "$@"
36 ok_null ()
38 ok --
41 result_print ()
43 _passed="$1"
44 _out="$2"
45 _rc="$3"
46 _extra_header="$4"
48 if "$TEST_VERBOSE" || ! $_passed ; then
49 if [ -n "$_extra_header" ] ; then
50 cat <<EOF
52 ##################################################
53 $_extra_header
54 EOF
57 cat <<EOF
58 --------------------------------------------------
59 Output (Exit status: ${_rc}):
60 --------------------------------------------------
61 EOF
62 echo "$_out" | cat $TEST_CAT_RESULTS_OPTS
65 if ! $_passed ; then
66 cat <<EOF
67 --------------------------------------------------
68 Required output (Exit status: ${required_rc}):
69 --------------------------------------------------
70 EOF
71 echo "$required_output" | cat $TEST_CAT_RESULTS_OPTS
73 if $TEST_DIFF_RESULTS ; then
74 _outr=$(mktemp)
75 echo "$required_output" >"$_outr"
77 _outf=$(mktemp)
78 echo "$_fout" >"$_outf"
80 cat <<EOF
81 --------------------------------------------------
82 Diff:
83 --------------------------------------------------
84 EOF
85 diff -u "$_outr" "$_outf" | cat -A
86 rm "$_outr" "$_outf"
91 result_footer ()
93 _passed="$1"
94 _extra_footer="$2"
96 if "$TEST_VERBOSE" || ! $_passed ; then
97 if [ -n "$_extra_footer" ] ; then
98 cat <<EOF
99 --------------------------------------------------
100 $_extra_footer
101 --------------------------------------------------
106 if $_passed ; then
107 echo "PASSED"
108 return 0
109 else
110 echo
111 echo "FAILED"
112 return 1
116 result_check ()
118 _rc=$?
120 _extra_header="$1"
122 if [ -n "$OUT_FILTER" ] ; then
123 _fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
124 else
125 _fout="$_out"
128 if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
129 _passed=true
130 else
131 _passed=false
134 result_print "$_passed" "$_out" "$_rc" "$_extra_header"
135 result_footer "$_passed"
138 local="${TEST_SUBDIR}/scripts/local.sh"
139 if [ -r "$local" ] ; then
140 . "$local"