summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlavio Leitner <fbl@redhat.com>2017-06-09 12:58:57 -0300
committerBen Pfaff <blp@ovn.org>2017-06-12 21:34:47 -0700
commit7689bcf0db82386bb8abb6050e3ee90d0a4fba16 (patch)
treebb60f2a3bfd7985f5b6dd4b4724e2cec9d9c2594 /tests
parent75e55899022c87b1fc1d964217a6e88b99b9534d (diff)
downloadopenvswitch-7689bcf0db82386bb8abb6050e3ee90d0a4fba16.tar.gz
testsuite: exit gracefully if it fails.
The daemon is killed leaving resources behind when a test fails. This fixes to first signal the daemon to exit gracefully. Fixes: 0f28164be02ac ("netdev-linux: make tap devices persistent") Suggested-by: Joe Stringer <joe@ovn.org> Co-authored-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Flavio Leitner <fbl@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Joe Stringer <joe@ovn.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/ofproto-macros.at2
-rw-r--r--tests/ovs-macros.at33
2 files changed, 34 insertions, 1 deletions
diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
index faff5b0a8..30a8b2148 100644
--- a/tests/ofproto-macros.at
+++ b/tests/ofproto-macros.at
@@ -322,7 +322,7 @@ m4_define([_OVS_VSWITCHD_START],
dnl Start ovs-vswitchd.
AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr])
AT_CAPTURE_FILE([ovs-vswitchd.log])
- on_exit "kill `cat ovs-vswitchd.pid`"
+ on_exit "kill_ovs_vswitchd `cat ovs-vswitchd.pid`"
AT_CHECK([[sed < stderr '
/ovs_numa|INFO|Discovered /d
/vlog|INFO|opened log file/d
diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
index 047d0ddc4..dbce0a501 100644
--- a/tests/ovs-macros.at
+++ b/tests/ovs-macros.at
@@ -115,6 +115,39 @@ parent_pid () {
fi
}
+# kill_ovs_vswitchd [PID]
+#
+# Signal the ovs-vswitchd daemon to exit gracefully and wait for it to
+# terminate or kill it if that takes too long.
+#
+# It is used to cleanup all sorts of tests and results. It can't assume
+# any state, including the availability of PID file which can be provided.
+kill_ovs_vswitchd () {
+ # Use provided PID or save the current PID if available.
+ TMPPID=$1
+ if test -z "$TMPPID"; then
+ TMPPID=$(cat $OVS_RUNDIR/ovs-vswitchd.pid 2>/dev/null)
+ fi
+
+ # Tell the daemon to terminate gracefully
+ ovs-appctl --timeout=10 -t ovs-vswitchd exit --cleanup 2>/dev/null
+
+ # Nothing else to be done if there is no PID
+ test -z "$TMPPID" && return
+
+ for i in 1 2 3 4 5 6 7 8 9; do
+ # Check if the daemon is alive.
+ kill -0 $TMPPID 2>/dev/null || return
+
+ # Fallback to whole number since POSIX doesn't require
+ # fractional times to work.
+ sleep 0.1 || sleep 1
+ done
+
+ # Make sure it is terminated.
+ kill $TMPPID
+}
+
# Normalize the output of 'wc' to match POSIX.
# POSIX says 'wc' should print "%d %d %d", but GNU prints "%7d %7d %7d".
# POSIX says 'wc -l' should print "%d %s", but BSD prints "%8d".