1 AT_TESTED([ovs-vswitchd])
5 m4_include([m4/compat.at])
7 dnl Make AT_SETUP automatically run the ovs_init() shell function
8 dnl as the first step in every test.
9 m4_rename([AT_SETUP], [OVS_AT_SETUP])
10 m4_define([AT_SETUP], [OVS_AT_SETUP($@)
13 m4_divert_push([PREPARE_TESTS])
15 # Set ovs_base to the base directory in which the test is running and
16 # initialize the OVS_*DIR environment variables to point to this
20 trap '. "$ovs_base/cleanup"' 0
25 # With no parameter or an empty parameter, sets the OVS_*DIR
26 # environment variables to point to $ovs_base, the base directory in
27 # which the test is running.
29 # With a parameter, sets them to $ovs_base/$1.
32 ovs_dir=$ovs_base${1:+/$1}
33 OVS_RUNDIR=$ovs_dir; export OVS_RUNDIR
34 OVS_LOGDIR=$ovs_dir; export OVS_LOGDIR
35 OVS_DBDIR=$ovs_dir; export OVS_DBDIR
36 OVS_SYSCONFDIR=$ovs_dir; export OVS_SYSCONFDIR
37 OVS_PKGDATADIR=$ovs_dir; export OVS_PKGDATADIR
41 # First try the condition without waiting.
42 ovs_wait_cond && return 0
44 # Try a quick sleep, so that the test completes very quickly
45 # in the normal case. POSIX doesn't require fractional times to
46 # work, so this might not work.
48 ovs_wait_cond && return 0
50 # Then wait up to 10 seconds.
51 for d in 0 1 2 3 4 5 6 7 8 9; do
53 ovs_wait_cond && return 0
58 # Prints the integers from $1 to $2, increasing by $3 (default 1) on stdout.
60 while test $1 -le $2; do
62 set `expr $1 + ${3-1}` $2 $3
66 if test "$IS_WIN32" = "yes"; then
72 command diff --strip-trailing-cr "$@"
75 # tskill is more effective than taskkill but it isn't always installed.
76 if (tskill //?) >/dev/null 2>&1; then :; else
77 tskill () { taskkill //F //PID $1 >/dev/null; }
87 # tasklist always returns 0.
88 # If pid does exist, there will be a line with the pid.
89 if tasklist //fi "PID eq $arg" | grep $arg >/dev/null; then
90 if test "X$signal" != "X-0"; then
103 m4_divert_pop([PREPARE_TESTS])
105 m4_define([OVS_WAIT], [dnl
116 dnl OVS_WAIT_UNTIL(COMMAND)
118 dnl Executes shell COMMAND in a loop until it returns
119 dnl zero return code. If COMMAND did not return
120 dnl zero code within reasonable time limit, then
122 m4_define([OVS_WAIT_UNTIL], [OVS_WAIT([$1], [$2])])
124 dnl OVS_WAIT_WHILE(COMMAND)
126 dnl Executes shell COMMAND in a loop until it returns
127 dnl non-zero return code. If COMMAND did not return
128 dnl non-zero code within reasonable time limit, then
130 m4_define([OVS_WAIT_WHILE],
131 [OVS_WAIT([if $1; then return 1; else return 0; fi], [$2])])
133 dnl OVS_APP_EXIT_AND_WAIT(DAEMON)
135 dnl Ask the daemon named DAEMON to exit, via ovs-appctl, and then waits for it
137 m4_define([OVS_APP_EXIT_AND_WAIT],
138 [ovs-appctl -t $1 exit
139 OVS_WAIT_WHILE([test -e $1.pid])])
141 dnl on_exit "COMMAND"
143 dnl Add the shell COMMAND to a collection executed when the current test
144 dnl completes, as a cleanup action. (The most common use is to kill a
145 dnl daemon started by the test. This is important to prevent tests that
146 dnl start daemons from hanging at exit.)
148 dnl Cleanup commands are executed in the reverse order of calls to this
150 m4_divert_text([PREPARE_TESTS], [dnl
152 (echo "$1"; cat cleanup) > cleanup.tmp
153 mv cleanup.tmp cleanup