~ubuntu-branches/ubuntu/vivid/ctdb/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/takeover/common.sh

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2011-11-06 15:18:59 UTC
  • mto: (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20111106151859-84nk51h3enndlo4q
Tags: upstream-1.11+git20111102
ImportĀ upstreamĀ versionĀ 1.11+git20111102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Hey Emacs, this is a -*- shell-script -*- !!!  :-)
 
2
 
 
3
# Print a message and exit.
 
4
die () { echo "$@" >&2 ; exit 1 ; }
 
5
 
 
6
test_prog="$(dirname ${TAKEOVER_TESTS_DIR})/bin/ctdb_takeover_tests ctdb_takeover_run_core"
 
7
 
 
8
define_test ()
 
9
{
 
10
    _f="$0"
 
11
    _f="${_f#./}"  # strip leading ./
 
12
    _f="${_f#testcases/}"  # strip leading testcases/
 
13
    _f="${_f%.sh}" # strip off .sh suffix if any
 
14
 
 
15
    case "$_f" in
 
16
        nondet.*)
 
17
            algorithm="nondet"
 
18
            CTDB_LCP2="no"
 
19
            ;;
 
20
        lcp2.*)
 
21
            algorithm="lcp2"
 
22
            export CTDB_LCP2="yes"
 
23
            ;;
 
24
        *)
 
25
            die "Unknown algorithm for testcase \"$_f\""
 
26
    esac
 
27
 
 
28
    printf "%-12s - %s\n" "$_f" "$1"
 
29
}
 
30
 
 
31
required_result ()
 
32
{
 
33
    required_rc="${1:-0}"
 
34
    required_output=$(cat)
 
35
}
 
36
 
 
37
simple_test ()
 
38
{
 
39
    _states="$1"
 
40
    _out=$($test_prog $_states 2>&1)
 
41
    _rc=$?
 
42
 
 
43
    if [ "$algorithm" = "lcp2" -a -n "$CTDB_TEST_LOGLEVEL" ] ; then
 
44
        OUT_FILTER='s@^.*:@DATE TIME \[PID\]:@'
 
45
    fi
 
46
 
 
47
    if [ -n "$OUT_FILTER" ] ; then
 
48
        _fout=$(echo "$_out" | sed -r "$OUT_FILTER")
 
49
    else
 
50
        _fout="$_out"
 
51
    fi
 
52
 
 
53
    if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
 
54
        echo "PASSED"
 
55
    else
 
56
        cat <<EOF
 
57
Algorithm: $algorithm
 
58
 
 
59
##################################################
 
60
Required output (Exit status: ${required_rc}):
 
61
##################################################
 
62
$required_output
 
63
##################################################
 
64
Actual output (Exit status: ${_rc}):
 
65
##################################################
 
66
$_out
 
67
EOF
 
68
        return 1
 
69
    fi
 
70
}