]>
Commit | Line | Data |
---|---|---|
02e6f2f7 AZ |
1 | AT_TESTED([ovs-vswitchd]) |
2 | AT_TESTED([ovs-vsctl]) | |
3 | AT_TESTED([perl]) | |
4 | ||
12878bc4 | 5 | m4_include([m4/compat.m4]) |
02e6f2f7 | 6 | |
6132b241 BP |
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($@) | |
11 | ovs_init | |
12 | ]) | |
02e6f2f7 AZ |
13 | m4_divert_push([PREPARE_TESTS]) |
14 | [ | |
6132b241 BP |
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 | |
17 | # directory. | |
18 | ovs_init() { | |
19 | ovs_base=`pwd` | |
53eb8cb8 BP |
20 | trap '. "$ovs_base/cleanup"' 0 |
21 | : > cleanup | |
f295c17b BP |
22 | ovs_setenv |
23 | } | |
24 | ||
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. | |
28 | # | |
29 | # With a parameter, sets them to $ovs_base/$1. | |
30 | ovs_setenv() { | |
31 | sandbox=$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 | |
6132b241 BP |
38 | } |
39 | ||
02e6f2f7 | 40 | ovs_wait () { |
4c619f4d BP |
41 | # First try the condition without waiting. |
42 | ovs_wait_cond && return 0 | |
43 | ||
44 | # Try a quick sleep, so that the test completes very quickly | |
02e6f2f7 AZ |
45 | # in the normal case. POSIX doesn't require fractional times to |
46 | # work, so this might not work. | |
47 | sleep 0.1 | |
2c920d9d BP |
48 | ovs_wait_cond && return 0 |
49 | ||
02e6f2f7 AZ |
50 | # Then wait up to 10 seconds. |
51 | for d in 0 1 2 3 4 5 6 7 8 9; do | |
52 | sleep 1 | |
2c920d9d | 53 | ovs_wait_cond && return 0 |
02e6f2f7 | 54 | done |
2c920d9d | 55 | return 1 |
02e6f2f7 AZ |
56 | } |
57 | ||
58 | # Prints the integers from $1 to $2, increasing by $3 (default 1) on stdout. | |
59 | seq () { | |
60 | while test $1 -le $2; do | |
61 | echo $1 | |
62 | set `expr $1 + ${3-1}` $2 $3 | |
63 | done | |
64 | } | |
65 | ||
66 | if test "$IS_WIN32" = "yes"; then | |
67 | pwd () { | |
68 | command pwd -W "$@" | |
69 | } | |
70 | ||
71 | diff () { | |
72 | command diff --strip-trailing-cr "$@" | |
73 | } | |
74 | ||
099772c0 BP |
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; } | |
78 | fi | |
79 | ||
02e6f2f7 | 80 | kill () { |
099772c0 BP |
81 | signal= |
82 | retval=0 | |
83 | for arg; do | |
84 | case $arg in | |
85 | -*) signal=$arg ;; | |
02e6f2f7 | 86 | [1-9][0-9]*) |
099772c0 BP |
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 | |
91 | tskill $arg | |
5e65e080 | 92 | fi |
099772c0 BP |
93 | else |
94 | retval=1 | |
95 | fi | |
02e6f2f7 | 96 | ;; |
099772c0 BP |
97 | esac |
98 | done | |
99 | return $retval | |
02e6f2f7 AZ |
100 | } |
101 | fi | |
102 | ] | |
103 | m4_divert_pop([PREPARE_TESTS]) | |
104 | ||
2c920d9d BP |
105 | m4_define([OVS_WAIT], [dnl |
106 | ovs_wait_cond () { | |
107 | $1 | |
02e6f2f7 | 108 | } |
2c920d9d BP |
109 | if ovs_wait; then : |
110 | else | |
111 | $2 | |
112 | AT_FAIL_IF([:]) | |
113 | fi | |
114 | ]) | |
3ee7cc6c AA |
115 | |
116 | dnl OVS_WAIT_UNTIL(COMMAND) | |
117 | dnl | |
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 | |
121 | dnl the test fails. | |
02e6f2f7 | 122 | m4_define([OVS_WAIT_UNTIL], [OVS_WAIT([$1], [$2])]) |
3ee7cc6c AA |
123 | |
124 | dnl OVS_WAIT_WHILE(COMMAND) | |
125 | dnl | |
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 | |
129 | dnl the test fails. | |
02e6f2f7 AZ |
130 | m4_define([OVS_WAIT_WHILE], |
131 | [OVS_WAIT([if $1; then return 1; else return 0; fi], [$2])]) | |
132 | ||
133 | dnl OVS_APP_EXIT_AND_WAIT(DAEMON) | |
134 | dnl | |
135 | dnl Ask the daemon named DAEMON to exit, via ovs-appctl, and then waits for it | |
136 | dnl to exit. | |
137 | m4_define([OVS_APP_EXIT_AND_WAIT], | |
75623797 | 138 | [TMPPID=$(cat "$OVS_RUNDIR"/$1.pid 2>/dev/null) |
f9b11f2a LR |
139 | AT_CHECK([ovs-appctl -t $1 exit]) |
140 | OVS_WAIT_WHILE([kill -0 $TMPPID 2>/dev/null])]) | |
02e6f2f7 | 141 | |
60bdd011 RM |
142 | dnl OVS_APP_EXIT_AND_WAIT_BY_TARGET(DAEMON) |
143 | dnl | |
144 | dnl Ask the daemon named DAEMON to exit, via ovs-appctl (using the target | |
145 | dnl argument), and then waits for it to exit. | |
146 | m4_define([OVS_APP_EXIT_AND_WAIT_BY_TARGET], | |
147 | [TMPPID=`cat "$OVS_RUNDIR"/$1.pid 2>/dev/null` | |
148 | AT_CHECK([ovs-appctl --target=$OVS_RUNDIR/ovsdb-server.$TMPPID.ctl exit]) | |
149 | OVS_WAIT_WHILE([kill -0 $TMPPID 2>/dev/null])]) | |
150 | ||
53eb8cb8 | 151 | dnl on_exit "COMMAND" |
02e6f2f7 | 152 | dnl |
53eb8cb8 | 153 | dnl Add the shell COMMAND to a collection executed when the current test |
02e6f2f7 AZ |
154 | dnl completes, as a cleanup action. (The most common use is to kill a |
155 | dnl daemon started by the test. This is important to prevent tests that | |
156 | dnl start daemons from hanging at exit.) | |
5e65e080 | 157 | dnl |
53eb8cb8 BP |
158 | dnl Cleanup commands are executed in the reverse order of calls to this |
159 | dnl function. | |
160 | m4_divert_text([PREPARE_TESTS], [dnl | |
161 | on_exit () { | |
162 | (echo "$1"; cat cleanup) > cleanup.tmp | |
163 | mv cleanup.tmp cleanup | |
164 | } | |
165 | ]) | |
fc99370f BP |
166 | |
167 | dnl Autoconf 2.63 compatibility verison of macro introduced in Autoconf 2.64: | |
168 | m4_ifndef([AS_VAR_APPEND], | |
169 | [m4_divert_text([PREPARE_TESTS], | |
170 | [as_var_append () { | |
171 | eval $1=\$$1\$2 | |
172 | } | |
173 | ]) | |
174 | m4_define([AS_VAR_APPEND], [as_var_append $1 $2])]) | |
47b31247 BP |
175 | |
176 | dnl Autoconf 2.63 compatibility verison of macro introduced in Autoconf 2.64: | |
177 | m4_ifndef([AT_CHECK_UNQUOTED], | |
178 | [m4_define([AT_CHECK_UNQUOTED], | |
179 | [_AT_CHECK([$1], [$2], AS_ESCAPE(m4_dquote(m4_expand([$3])), [""]), | |
180 | AS_ESCAPE(m4_dquote(m4_expand([$4])),[""]), [$5], [$6])])]) | |
181 | ||
182 | dnl Autoconf 2.63 compatibility verison of macro introduced in Autoconf 2.64: | |
183 | m4_ifndef([AT_SKIP_IF], | |
184 | [m4_define([AT_SKIP_IF], | |
185 | [AT_CHECK([($1) \ | |
186 | && exit 77 || exit 0], [0], [ignore], [ignore])])]) | |
187 | ||
188 | dnl Autoconf 2.63 compatibility verison of macro introduced in Autoconf 2.64: | |
189 | m4_ifndef([AT_FAIL_IF], | |
190 | [m4_define([AT_FAIL_IF], | |
191 | [AT_CHECK([($1) \ | |
192 | && exit 99 || exit 0], [0], [ignore], [ignore])])]) |