Merge branch 'master' of ctdb into 'master' of samba
[samba.git] / ctdb / tests / tool / scripts / local.sh
1 # Hey Emacs, this is a -*- shell-script -*- !!!  :-)
2
3 if "$TEST_VERBOSE" ; then
4     debug () { echo "$@" ; }
5 else
6     debug () { : ; }
7 fi
8
9 define_test ()
10 {
11     _f=$(basename "$0" ".sh")
12
13     case "$_f" in
14         func.*)
15             _func="${_f#func.}"
16             _func="${_func%.*}" # Strip test number
17             test_prog="ctdb_functest ${_func}"
18             ;;
19         stubby.*)
20             _cmd="${_f#stubby.}"
21             _cmd="${_cmd%.*}" # Strip test number
22             test_prog="ctdb_stubtest ${_cmd}"
23             ;;
24         *)
25             die "Unknown pattern for testcase \"$_f\""
26     esac
27
28     printf "%-28s - %s\n" "$_f" "$1"
29 }
30
31 setup_natgw ()
32 {
33     debug "Setting up NAT gateway"
34
35     natgw_config_dir="${TEST_VAR_DIR}/natgw_config"
36     mkdir -p "$natgw_config_dir"
37
38     # These will accumulate, 1 per test... but will be cleaned up at
39     # the end.
40     export CTDB_NATGW_NODES=$(mktemp --tmpdir="$natgw_config_dir")
41
42     cat >"$CTDB_NATGW_NODES"
43 }
44
45 simple_test ()
46 {
47     # Most of the tests when the tool fails will have a date/time/pid
48     # prefix.  Strip that because it isn't possible to match it.
49     if [ $required_rc -ne 0 ]  ; then
50         OUT_FILTER='s@^[0-9/]+\ [0-9:\.]+\ \[[\ 0-9]+\]:@DATE\ TIME\ \[PID\]:@'
51     fi
52
53     _out=$($VALGRIND $test_prog "$@" 2>&1)
54
55     result_check
56 }