tests: Run OVS_WAIT_WHILE, OVS_WAIT_UNTIL in main shell environment.
authorBen Pfaff <blp@ovn.org>
Sun, 5 Jul 2015 17:19:30 +0000 (10:19 -0700)
committerBen Pfaff <blp@ovn.org>
Thu, 26 Nov 2015 21:28:24 +0000 (13:28 -0800)
AT_CHECK runs its commands in a subshell.  That means that (among other
effects), any variable assignments within its commands will disappear after
the commands' completion.  That doesn't matter for any of the existing
users, which don't do the sorts of things that affect an outer shell
environment anyhow, but an upcoming user wants to make a shell assignment
that persists.  This commit makes that possible, by using AT_CHECK
(actually AT_FAIL_IF but it's moot) only upon failure instead of bracketing
the entire test.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
tests/ovs-macros.at

index 9195f67..90fb835 100644 (file)
@@ -42,13 +42,14 @@ ovs_wait () {
     # in the normal case.  POSIX doesn't require fractional times to
     # work, so this might not work.
     sleep 0.1
-    ovs_wait_cond && exit 0
+    ovs_wait_cond && return 0
+
     # Then wait up to 10 seconds.
     for d in 0 1 2 3 4 5 6 7 8 9; do
         sleep 1
-        ovs_wait_cond && exit 0
+        ovs_wait_cond && return 0
     done
-    exit 1
+    return 1
 }
 
 # Prints the integers from $1 to $2, increasing by $3 (default 1) on stdout.
@@ -98,11 +99,16 @@ fi
 ]
 m4_divert_pop([PREPARE_TESTS])
 
-m4_define([OVS_WAIT],
-  [AT_CHECK(
-     [ovs_wait_cond () { $1
+m4_define([OVS_WAIT], [dnl
+ovs_wait_cond () {
+    $1
 }
-ovs_wait], [0], [ignore], [ignore], [$2])])
+if ovs_wait; then :
+else
+    $2
+    AT_FAIL_IF([:])
+fi
+])
 
 dnl OVS_WAIT_UNTIL(COMMAND)
 dnl