ctdb-logging: Change LogLevel to DEBUGLEVEL
[Samba.git] / ctdb / tests / scripts / unit.sh
blob38b7e21c8ccac941230232fa453d7c7208338618
1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 . "${TEST_SCRIPTS_DIR}/common.sh"
5 # Common variables and functions for CTDB unit tests.
7 trap -- '' PIPE
9 # Set the required result for a test.
10 # - Argument 1 is exit code.
11 # - Argument 2, if present is the required test output but "--"
12 # indicates empty output.
13 # If argument 2 is not present or null then read required test output
14 # from stdin.
15 required_result ()
17 required_rc="${1:-0}"
18 if [ -n "$2" ] ; then
19 if [ "$2" = "--" ] ; then
20 required_output=""
21 else
22 required_output="$2"
24 else
25 if ! tty -s ; then
26 required_output=$(cat)
27 else
28 required_output=""
33 ok ()
35 required_result 0 "$@"
38 ok_null ()
40 ok --
43 result_print ()
45 _passed="$1"
46 _out="$2"
47 _rc="$3"
48 _extra_header="$4"
50 if "$TEST_VERBOSE" || ! $_passed ; then
51 if [ -n "$_extra_header" ] ; then
52 cat <<EOF
54 ##################################################
55 $_extra_header
56 EOF
59 cat <<EOF
60 --------------------------------------------------
61 Output (Exit status: ${_rc}):
62 --------------------------------------------------
63 EOF
64 echo "$_out" | cat $TEST_CAT_RESULTS_OPTS
67 if ! $_passed ; then
68 cat <<EOF
69 --------------------------------------------------
70 Required output (Exit status: ${required_rc}):
71 --------------------------------------------------
72 EOF
73 echo "$required_output" | cat $TEST_CAT_RESULTS_OPTS
75 if $TEST_DIFF_RESULTS ; then
76 _outr=$(mktemp)
77 echo "$required_output" >"$_outr"
79 _outf=$(mktemp)
80 echo "$_fout" >"$_outf"
82 cat <<EOF
83 --------------------------------------------------
84 Diff:
85 --------------------------------------------------
86 EOF
87 diff -u "$_outr" "$_outf" | cat -A
88 rm "$_outr" "$_outf"
93 result_footer ()
95 _passed="$1"
96 _extra_footer="$2"
98 if "$TEST_VERBOSE" || ! $_passed ; then
99 if [ -n "$_extra_footer" ] ; then
100 cat <<EOF
101 --------------------------------------------------
102 $_extra_footer
103 --------------------------------------------------
108 if $_passed ; then
109 echo "PASSED"
110 return 0
111 else
112 echo
113 echo "FAILED"
114 return 1
118 # Result filtering is (usually) used to replace the date/time/PID
119 # prefix on some CTDB tool/client log messages with the literal string
120 # "DATE TIME [PID]". This allows tests to loosely match this output,
121 # since it can't otherwise be matched.
122 result_filter_default ()
124 _date_time_pid='[0-9/][0-9/]*\ [0-9:\.][0-9:\.]*\ \[[\ 0-9][\ 0-9]*\]'
125 sed -e "s@^${_date_time_pid}:@DATE\ TIME\ \[PID\]:@"
127 TEST_DATE_STAMP=""
129 # Override this function to customise output filtering.
130 result_filter ()
132 result_filter_default
135 result_check ()
137 _rc=$?
139 _extra_header="$1"
141 _fout=$(echo "$_out" | result_filter)
143 if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
144 _passed=true
145 else
146 _passed=false
149 result_print "$_passed" "$_out" "$_rc" "$_extra_header"
150 result_footer "$_passed"
153 local="${TEST_SUBDIR}/scripts/local.sh"
154 if [ -r "$local" ] ; then
155 . "$local"