<eventscript>.<event>.NNN.sh
The test helper functions will run <eventscript> with specified
-options. If using the simple_test() or iterate_test() helper
-functions then the 1st <event> argument is automatically passed. When
-simple_test_event() is used the event name must be explicitly passed
-as the 1st argument - this is more flexible and supports multiple
-events per test.
+options. If using the simple_test() helper function then the 1st
+<event> argument is automatically passed. When simple_test_event() is
+used the event name must be explicitly passed as the 1st argument -
+this is more flexible and supports multiple events per test.
Examples:
unit_test "$@"
}
-# Run an eventscript iteratively.
-# - 1st argument is the number of iterations.
-# - 2nd argument is something to eval to do setup for every iteration.
-# The easiest thing to do here is to define a function and pass it
-# here.
-# - Subsequent arguments come in pairs: an iteration number and
-# something to eval for that iteration. Each time an iteration
-# number is matched the associated argument is given to eval after
-# the default setup is done. The iteration numbers need to be given
-# in ascending order.
-#
-# Some optional args can be given *before* these, surrounded by extra
-# "--" args. These args are passed to the eventscript. Quoting is
-# lost.
-#
-# One use of the 2nd and further arguments is to call
-# required_result() to change what is expected of a particular
-# iteration.
-iterate_test ()
-{
- [ -n "$event" ] || die 'simple_test: $event not set'
-
- args=""
- if [ "$1" = "--" ] ; then
- shift
- while [ "$1" != "--" ] ; do
- args="${args}${args:+ }$1"
- shift
- done
- shift
- fi
-
- _repeats="$1"
- _setup_default="$2"
- shift 2
-
- echo "Running $_repeats iterations of \"$script $event\" $args"
-
- _result=true
-
- extra_footer ()
- {
- cat <<EOF
---------------------------------------------------
-CTDB_BASE="$CTDB_BASE"
-CTDB_ETCDIR="$CTDB_ETCDIR"
-ctdb client is "$(which ctdb)"
-ip command is "$(which ip)"
---------------------------------------------------
-EOF
- }
-
- for iteration in $(seq 1 $_repeats) ; do
- # This is inefficient because the iteration-specific setup
- # might completely replace the default one. However, running
- # the default is good because it allows you to revert to a
- # particular result without needing to specify it explicitly.
- eval $_setup_default
- if [ $iteration = "$1" ] ; then
- eval $2
- shift 2
- fi
-
- extra_header ()
- {
- cat <<EOF
-
-##################################################
-Iteration $iteration
-EOF
- }
-
- _shell=""
- if $TEST_COMMAND_TRACE ; then
- _shell="sh -x"
- else
- _shell="sh"
- fi
- _out=$($_shell "${script_dir}/${script}" "$event" $args 2>&1)
- _rc=$?
-
- _fout=$(echo "$_out" | result_filter)
-
- if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
- _passed=true
- else
- _passed=false
- _result=false
- fi
-
- result_print "$_passed" "$_out" "$_rc"
- done
-
- result_footer "$_result"
-}
-
# Run an NFS eventscript iteratively.
#
# - 1st argument is the number of iterations.