diff options
author | Martin Schwenke <martin@meltin.net> | 2012-04-18 15:04:50 +1000 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2012-04-27 15:40:43 +1000 |
commit | c2d1f8752c8b8c41238cf41ee94785199cea77ef (patch) | |
tree | 1c7e925af0f7064180d32dcf12a985203e2549ae | |
parent | bf197d097f86ed5c75622778332a7c85c4684a12 (diff) | |
download | samba-c2d1f8752c8b8c41238cf41ee94785199cea77ef.tar.gz samba-c2d1f8752c8b8c41238cf41ee94785199cea77ef.tar.xz samba-c2d1f8752c8b8c41238cf41ee94785199cea77ef.zip |
tests: Rationalise integration test infrastructure
* run_tests no longer includes common.sh, which is only to be included
by test cases. Therefore, it defines its own die() function.
* TEST_SUBDIR is now set in common.sh
* Move complex-only functions to complex/scripts/local.bash
Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit bfa1d6638d3e116640eb4e3bb71b21ba6ef8cae5)
-rw-r--r-- | ctdb/tests/complex/scripts/local.bash | 129 | ||||
-rw-r--r-- | ctdb/tests/scripts/common.sh | 2 | ||||
-rw-r--r-- | ctdb/tests/scripts/integration.bash | 140 | ||||
-rwxr-xr-x | ctdb/tests/scripts/run_tests | 10 |
4 files changed, 144 insertions, 137 deletions
diff --git a/ctdb/tests/complex/scripts/local.bash b/ctdb/tests/complex/scripts/local.bash new file mode 100644 index 0000000000..3ed03ba708 --- /dev/null +++ b/ctdb/tests/complex/scripts/local.bash @@ -0,0 +1,129 @@ +# Hey Emacs, this is a -*- shell-script -*- !!! :-) + +get_src_socket () +{ + local proto="$1" + local dst_socket="$2" + local pid="$3" + local prog="$4" + + local pat="^${proto}[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[^[:space:]]+[[:space:]]+${dst_socket//./\\.}[[:space:]]+ESTABLISHED[[:space:]]+${pid}/${prog}[[:space:]]*\$" + out=$(netstat -tanp | + egrep "$pat" | + awk '{ print $4 }') + + [ -n "$out" ] +} + +wait_until_get_src_socket () +{ + local proto="$1" + local dst_socket="$2" + local pid="$3" + local prog="$4" + + echo "Waiting for ${prog} to establish connection to ${dst_socket}..." + + wait_until 5 get_src_socket "$@" +} + +####################################### + +# filename will be in $tcpdump_filename, pid in $tcpdump_pid +tcpdump_start () +{ + tcpdump_filter="$1" # global + + echo "Running tcpdump..." + tcpdump_filename=$(mktemp) + ctdb_test_exit_hook_add "rm -f $tcpdump_filename" + + # The only way of being sure that tcpdump is listening is to send + # some packets that it will see. So we use dummy pings - the -U + # option to tcpdump ensures that packets are flushed to the file + # as they are captured. + local dummy_addr="127.3.2.1" + local dummy="icmp and dst host ${dummy_addr} and icmp[icmptype] == icmp-echo" + tcpdump -n -p -s 0 -e -U -w $tcpdump_filename -i any "($tcpdump_filter) or ($dummy)" & + ctdb_test_exit_hook_add "kill $! >/dev/null 2>&1" + + echo "Waiting for tcpdump output file to be ready..." + ping -q "$dummy_addr" >/dev/null 2>&1 & + ctdb_test_exit_hook_add "kill $! >/dev/null 2>&1" + + tcpdump_listen_for_dummy () + { + tcpdump -n -r $tcpdump_filename -c 1 "$dummy" >/dev/null 2>&1 + } + + wait_until 10 tcpdump_listen_for_dummy +} + +# By default, wait for 1 matching packet. +tcpdump_wait () +{ + local count="${1:-1}" + local filter="${2:-${tcpdump_filter}}" + + tcpdump_check () + { + local found=$(tcpdump -n -r $tcpdump_filename "$filter" 2>/dev/null | wc -l) + [ $found -ge $count ] + } + + echo "Waiting for tcpdump to capture some packets..." + if ! wait_until 30 tcpdump_check ; then + echo "DEBUG AT $(date '+%F %T'):" + local i + for i in "onnode -q 0 $CTDB status" "netstat -tanp" "tcpdump -n -e -r $tcpdump_filename" ; do + echo "$i" + $i || true + done + return 1 + fi +} + +tcpdump_show () +{ + local filter="${1:-${tcpdump_filter}}" + + tcpdump -n -r $tcpdump_filename "$filter" 2>/dev/null +} + +tcptickle_sniff_start () +{ + local src="$1" + local dst="$2" + + local in="src host ${dst%:*} and tcp src port ${dst##*:} and dst host ${src%:*} and tcp dst port ${src##*:}" + local out="src host ${src%:*} and tcp src port ${src##*:} and dst host ${dst%:*} and tcp dst port ${dst##*:}" + local tickle_ack="${in} and (tcp[tcpflags] & tcp-ack != 0) and (tcp[14] == 4) and (tcp[15] == 210)" # win == 1234 + local ack_ack="${out} and (tcp[tcpflags] & tcp-ack != 0)" + tcptickle_reset="${in} and tcp[tcpflags] & tcp-rst != 0" + local filter="(${tickle_ack}) or (${ack_ack}) or (${tcptickle_reset})" + + tcpdump_start "$filter" +} + +tcptickle_sniff_wait_show () +{ + tcpdump_wait 1 "$tcptickle_reset" + + echo "GOOD: here are some TCP tickle packets:" + tcpdump_show +} + +gratarp_sniff_start () +{ + tcpdump_start "arp host ${test_ip}" +} + +gratarp_sniff_wait_show () +{ + tcpdump_wait 2 + + echo "GOOD: this should be the some gratuitous ARPs:" + tcpdump_show +} + + diff --git a/ctdb/tests/scripts/common.sh b/ctdb/tests/scripts/common.sh index 581663c438..725b2a89fc 100644 --- a/ctdb/tests/scripts/common.sh +++ b/ctdb/tests/scripts/common.sh @@ -2,6 +2,8 @@ # Common variables and functions for all CTDB tests. +export TEST_SUBDIR=$(dirname $0) + # Print a message and exit. die () { diff --git a/ctdb/tests/scripts/integration.bash b/ctdb/tests/scripts/integration.bash index 70c5b5d10b..ea8aeb8b5a 100644 --- a/ctdb/tests/scripts/integration.bash +++ b/ctdb/tests/scripts/integration.bash @@ -1,10 +1,6 @@ # Hey Emacs, this is a -*- shell-script -*- !!! :-) -fail () -{ - echo "$*" - exit 1 -} +. "${TEST_SCRIPTS_DIR}/common.sh" ###################################################################### @@ -120,7 +116,7 @@ EOF ctdb_test_version () { - [ -n "$CTDB_DIR" ] || fail "Can not determine version." + [ -n "$CTDB_DIR" ] || die "Can not determine version." (cd "$CTDB_DIR" && git describe) } @@ -501,133 +497,6 @@ wait_until_node_has_some_ips () wait_until 60 node_has_some_ips "$@" } -get_src_socket () -{ - local proto="$1" - local dst_socket="$2" - local pid="$3" - local prog="$4" - - local pat="^${proto}[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[^[:space:]]+[[:space:]]+${dst_socket//./\\.}[[:space:]]+ESTABLISHED[[:space:]]+${pid}/${prog}[[:space:]]*\$" - out=$(netstat -tanp | - egrep "$pat" | - awk '{ print $4 }') - - [ -n "$out" ] -} - -wait_until_get_src_socket () -{ - local proto="$1" - local dst_socket="$2" - local pid="$3" - local prog="$4" - - echo "Waiting for ${prog} to establish connection to ${dst_socket}..." - - wait_until 5 get_src_socket "$@" -} - -####################################### - -# filename will be in $tcpdump_filename, pid in $tcpdump_pid -tcpdump_start () -{ - tcpdump_filter="$1" # global - - echo "Running tcpdump..." - tcpdump_filename=$(mktemp) - ctdb_test_exit_hook_add "rm -f $tcpdump_filename" - - # The only way of being sure that tcpdump is listening is to send - # some packets that it will see. So we use dummy pings - the -U - # option to tcpdump ensures that packets are flushed to the file - # as they are captured. - local dummy_addr="127.3.2.1" - local dummy="icmp and dst host ${dummy_addr} and icmp[icmptype] == icmp-echo" - tcpdump -n -p -s 0 -e -U -w $tcpdump_filename -i any "($tcpdump_filter) or ($dummy)" & - ctdb_test_exit_hook_add "kill $! >/dev/null 2>&1" - - echo "Waiting for tcpdump output file to be ready..." - ping -q "$dummy_addr" >/dev/null 2>&1 & - ctdb_test_exit_hook_add "kill $! >/dev/null 2>&1" - - tcpdump_listen_for_dummy () - { - tcpdump -n -r $tcpdump_filename -c 1 "$dummy" >/dev/null 2>&1 - } - - wait_until 10 tcpdump_listen_for_dummy -} - -# By default, wait for 1 matching packet. -tcpdump_wait () -{ - local count="${1:-1}" - local filter="${2:-${tcpdump_filter}}" - - tcpdump_check () - { - local found=$(tcpdump -n -r $tcpdump_filename "$filter" 2>/dev/null | wc -l) - [ $found -ge $count ] - } - - echo "Waiting for tcpdump to capture some packets..." - if ! wait_until 30 tcpdump_check ; then - echo "DEBUG AT $(date '+%F %T'):" - local i - for i in "onnode -q 0 $CTDB status" "netstat -tanp" "tcpdump -n -e -r $tcpdump_filename" ; do - echo "$i" - $i || true - done - return 1 - fi -} - -tcpdump_show () -{ - local filter="${1:-${tcpdump_filter}}" - - tcpdump -n -r $tcpdump_filename "$filter" 2>/dev/null -} - -tcptickle_sniff_start () -{ - local src="$1" - local dst="$2" - - local in="src host ${dst%:*} and tcp src port ${dst##*:} and dst host ${src%:*} and tcp dst port ${src##*:}" - local out="src host ${src%:*} and tcp src port ${src##*:} and dst host ${dst%:*} and tcp dst port ${dst##*:}" - local tickle_ack="${in} and (tcp[tcpflags] & tcp-ack != 0) and (tcp[14] == 4) and (tcp[15] == 210)" # win == 1234 - local ack_ack="${out} and (tcp[tcpflags] & tcp-ack != 0)" - tcptickle_reset="${in} and tcp[tcpflags] & tcp-rst != 0" - local filter="(${tickle_ack}) or (${ack_ack}) or (${tcptickle_reset})" - - tcpdump_start "$filter" -} - -tcptickle_sniff_wait_show () -{ - tcpdump_wait 1 "$tcptickle_reset" - - echo "GOOD: here are some TCP tickle packets:" - tcpdump_show -} - -gratarp_sniff_start () -{ - tcpdump_start "arp host ${test_ip}" -} - -gratarp_sniff_wait_show () -{ - tcpdump_wait 2 - - echo "GOOD: this should be the some gratuitous ARPs:" - tcpdump_show -} - - ####################################### daemons_stop () @@ -1051,3 +920,8 @@ wait_for_monitor_event () # Make sure that $CTDB is set. : ${CTDB:=ctdb} + +local="${TEST_SUBDIR}/scripts/local.bash" +if [ -r "$local" ] ; then + . "$local" +fi diff --git a/ctdb/tests/scripts/run_tests b/ctdb/tests/scripts/run_tests index 3a5ec96b74..a65ba878b1 100755 --- a/ctdb/tests/scripts/run_tests +++ b/ctdb/tests/scripts/run_tests @@ -5,8 +5,6 @@ # the arguments that it sees. . $(dirname $0)/ctdb_test_env : -. "${TEST_SCRIPTS_DIR}/common.sh" - usage() { cat <<EOF Usage: run_tests [OPTIONS] [TESTS] @@ -24,6 +22,12 @@ EOF exit 1 } +# Print a message and exit. +die () +{ + echo "$1" >&2 ; exit ${2:-1} +} + ###################################################################### with_summary=false @@ -141,8 +145,6 @@ run_one_test () [ -x "$_f" ] || die "test \"$_f\" is not executable" tests_total=$(($tests_total + 1)) - export TEST_SUBDIR=$(dirname "$_f") - ctdb_test_run "$_f" | tee "$tf" | show_progress status=$? if $with_summary ; then |