]> git.proxmox.com Git - mirror_ovs.git/blobdiff - tests/ovs-macros.at
ofp-print: Abbreviate lists of fields in table features output.
[mirror_ovs.git] / tests / ovs-macros.at
index 97ecc52a71a863f0ae93dec68f3d68813b5f74d3..d2239e38656f04115ee8be6d221a083b6c6c7f4d 100644 (file)
@@ -1,6 +1,5 @@
 AT_TESTED([ovs-vswitchd])
 AT_TESTED([ovs-vsctl])
-AT_TESTED([perl])
 
 m4_include([m4/compat.m4])
 
@@ -10,6 +9,25 @@ m4_rename([AT_SETUP], [OVS_AT_SETUP])
 m4_define([AT_SETUP], [OVS_AT_SETUP($@)
 ovs_init
 ])
+
+dnl Make AT_CLEANUP check for Address Sanitizer errors as the last step
+dnl in every test.
+m4_rename([AT_CLEANUP], [OVS_AT_CLEANUP])
+m4_define([AT_CLEANUP], [ovs_cleanup
+OVS_AT_CLEANUP($@)
+])
+
+dnl OVS_START_SHELL_HELPERS...OVS_END_SHELL_HELPERS may bracket shell
+dnl function definitions that invoke AT_CHECK and other Autotest macros
+dnl that can ordinarily be run only within AT_SETUP...AT_CLEANUP.
+m4_define([OVS_START_SHELL_HELPERS],
+  [m4_ifdef([AT_ingroup], [m4_fatal([$0: AT_SETUP and OVS_DEFINE_SHELL_HELPERS may not nest])])
+   m4_define([AT_ingroup])
+   m4_divert_push([PREPARE_TESTS])])
+m4_define([OVS_END_SHELL_HELPERS], [
+   m4_divert_pop([PREPARE_TESTS])
+   m4_undefine([AT_ingroup])])
+
 m4_divert_push([PREPARE_TESTS])
 [
 # Set ovs_base to the base directory in which the test is running and
@@ -17,11 +35,33 @@ m4_divert_push([PREPARE_TESTS])
 # directory.
 ovs_init() {
     ovs_base=`pwd`
-    trap '. "$ovs_base/cleanup"' 0
+    trap ovs_on_exit 0
     : > cleanup
     ovs_setenv
 }
 
+# Catch testsuite error condition and cleanup test environment by tearing down
+# all interfaces and processes spawned.
+# User has an option to leave the test environment in error state so that system
+# can be poked around to get more information. User can enable this option by setting
+# environment variable OVS_PAUSE_TEST=1. User needs to press CTRL-D to resume the
+# cleanup operation.
+ovs_pause() {
+    echo "====================================================="
+    echo "Set following environment variable to use various ovs utilities"
+    echo "export OVS_RUNDIR=$ovs_base"
+    echo "Press ENTER to continue: "
+    read
+}
+
+ovs_on_exit () {
+    if [ ! -z "${OVS_PAUSE_TEST}" ] && [ -z $at_verbose ]; then
+        trap '' INT
+        ovs_pause
+    fi
+    . "$ovs_base/cleanup"
+}
+
 # With no parameter or an empty parameter, sets the OVS_*DIR
 # environment variables to point to $ovs_base, the base directory in
 # which the test is running.
@@ -37,24 +77,6 @@ ovs_setenv() {
     OVS_PKGDATADIR=$ovs_dir; export OVS_PKGDATADIR
 }
 
-ovs_wait () {
-    # First try the condition without waiting.
-    ovs_wait_cond && return 0
-
-    # Try a quick sleep, so that the test completes very quickly
-    # in the normal case.  POSIX doesn't require fractional times to
-    # work, so this might not work.
-    sleep 0.1
-    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 && return 0
-    done
-    return 1
-}
-
 # Prints the integers from $1 to $2, increasing by $3 (default 1) on stdout.
 seq () {
     if test $# = 1; then
@@ -133,7 +155,7 @@ kill_ovs_vswitchd () {
     fi
 
     # Tell the daemon to terminate gracefully
-    ovs-appctl --timeout=10 -t ovs-vswitchd exit --cleanup 2>/dev/null
+    ovs-appctl -t ovs-vswitchd exit --cleanup 2>/dev/null
 
     # Nothing else to be done if there is no PID
     test -z "$TMPPID" && return
@@ -160,18 +182,74 @@ kill_ovs_vswitchd () {
 wc () {
    command wc "$@" | tr -s ' ' ' ' | sed 's/^ *//'
 }
+
+uuidfilt () {
+    $PYTHON3 "$top_srcdir"/tests/uuidfilt.py "$@"
+}
+
+# run_as PROGRAM_NAME COMMAND [ARG...]
+#
+# Runs a command with argv[0] set to PROGRAM_NAME, if possible, in a
+# subshell.  Most utilities print argc[0] as part of their messages,
+# so this makes it easier to figure out which particular utility
+# prints a message if a bunch of identical processes are running.
+#
+# Not all shells support "exec -a NAME", so test for it.
+if (exec -a myname true 2>/dev/null); then
+    run_as () {
+        (exec -a "$@")
+    }
+else
+    run_as () {
+        shift
+        (exec "$@")
+    }
+fi
 ]
 m4_divert_pop([PREPARE_TESTS])
 
+OVS_START_SHELL_HELPERS
+ovs_cleanup() {
+    if test "$(echo asan.*)" != 'asan.*'; then
+        echo "Address Sanitizer reported errors in:" asan.*
+        cat asan.*
+        AT_FAIL_IF([:])
+    fi
+}
+
+ovs_wait () {
+    echo "$1: waiting $2..." >&AS_MESSAGE_LOG_FD
+
+    # First try the condition without waiting.
+    if ovs_wait_cond; then echo "$1: wait succeeded immediately" >&AS_MESSAGE_LOG_FD; return 0; fi
+
+    # Try a quick sleep, so that the test completes very quickly
+    # in the normal case.  POSIX doesn't require fractional times to
+    # work, so this might not work.
+    sleep 0.1
+    if ovs_wait_cond; then echo "$1: wait succeeded quickly" >&AS_MESSAGE_LOG_FD; return 0; fi
+
+    # Then wait up to OVS_CTL_TIMEOUT seconds.
+    local d
+    for d in `seq 1 "$OVS_CTL_TIMEOUT"`; do
+        sleep 1
+        if ovs_wait_cond; then echo "$1: wait succeeded after $d seconds" >&AS_MESSAGE_LOG_FD; return 0; fi
+    done
+
+    echo "$1: wait failed after $d seconds" >&AS_MESSAGE_LOG_FD
+    ovs_wait_failed
+    AT_FAIL_IF([:])
+}
+OVS_END_SHELL_HELPERS
 m4_define([OVS_WAIT], [dnl
 ovs_wait_cond () {
     $1
 }
-if ovs_wait; then :
-else
+ovs_wait_failed () {
+    :
     $2
-    AT_FAIL_IF([:])
-fi
+}
+ovs_wait "AS_ESCAPE([$3])" "AS_ESCAPE([$4])"
 ])
 
 dnl OVS_WAIT_UNTIL(COMMAND)
@@ -180,7 +258,8 @@ dnl Executes shell COMMAND in a loop until it returns
 dnl zero return code.  If COMMAND did not return
 dnl zero code within reasonable time limit, then
 dnl the test fails.
-m4_define([OVS_WAIT_UNTIL], [OVS_WAIT([$1], [$2])])
+m4_define([OVS_WAIT_UNTIL],
+  [OVS_WAIT([$1], [$2], [AT_LINE], [until $1])])
 
 dnl OVS_WAIT_WHILE(COMMAND)
 dnl
@@ -189,7 +268,8 @@ dnl non-zero return code.  If COMMAND did not return
 dnl non-zero code within reasonable time limit, then
 dnl the test fails.
 m4_define([OVS_WAIT_WHILE],
-  [OVS_WAIT([if $1; then return 1; else return 0; fi], [$2])])
+  [OVS_WAIT([if $1; then return 1; else return 0; fi], [$2],
+            [AT_LINE], [while $1])])
 
 dnl OVS_APP_EXIT_AND_WAIT(DAEMON)
 dnl
@@ -199,8 +279,8 @@ m4_define([OVS_APP_EXIT_AND_WAIT],
   [AT_CHECK([test -e $OVS_RUNDIR/$1.pid])
    TMPPID=$(cat $OVS_RUNDIR/$1.pid)
    AT_CHECK(m4_if([$1],[ovs-vswitchd],
-                  [ovs-appctl --timeout=10 -t $1 exit --cleanup],
-                  [ovs-appctl --timeout=10 -t $1 exit]))
+                  [ovs-appctl -t $1 exit --cleanup],
+                  [ovs-appctl -t $1 exit]))
    OVS_WAIT_WHILE([kill -0 $TMPPID 2>/dev/null])])
 
 dnl OVS_APP_EXIT_AND_WAIT_BY_TARGET(TARGET, PIDFILE)
@@ -210,7 +290,7 @@ dnl argument), and then wait for it to exit.
 m4_define([OVS_APP_EXIT_AND_WAIT_BY_TARGET],
   [AT_CHECK([test -e $2])
    TMPPID=$(cat $2)
-   AT_CHECK([ovs-appctl --timeout=10 --target=$1 exit])
+   AT_CHECK([ovs-appctl --target=$1 exit])
    OVS_WAIT_WHILE([kill -0 $TMPPID 2>/dev/null])])
 
 dnl on_exit "COMMAND"