summary refs log tree commit diff
path: root/tools/run-nm-test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/run-nm-test.sh')
-rwxr-xr-xtools/run-nm-test.sh68
1 files changed, 60 insertions, 8 deletions
diff --git a/tools/run-nm-test.sh b/tools/run-nm-test.sh
index f452d9d4..6d835a8f 100755
--- a/tools/run-nm-test.sh
+++ b/tools/run-nm-test.sh
@@ -23,6 +23,43 @@ _is_true() {
     esac
 }
 
+usage() {
+    echo "$0 [\$OPTIONS] [--] \$TEST [\$TEST_OPTIONS]"
+    echo ""
+    echo "  Runs the unit test with setting up dbus-session (as necessary),"
+    echo "  optionally build the test first, and run valgrind"
+    echo ""
+    echo "  --help|-h: help"
+    echo "  --launch-dbus: the test runner by default automatically launches a D-Bus session"
+    echo "        depending on a hard-coded list of tests that require it. This flag overwrites"
+    echo "        the automatism to always launch a D-Bus session"
+    echo "  --no-launch-dbus|-D: prevent launching a D-Bus session"
+    echo "  --no-libtool: when running with valgrind, the script tries automatically to"
+    echo "        use libtool as necessary. This disables libtool usage" 
+    echo "  --make-first|-m: before running the test, make it (only works with autotools build)"
+    echo "  --valgrind|-v: run under valgrind"
+    echo "  --no-valgrind|-V: disable running under valgrind (overrides NMTST_USE_VALGRIND=1)"
+    echo "  -d: set NMTST_DEBUG=d"
+    echo "  --test|-t \$TEST: set the test that should be run"
+    echo ""
+    echo " With \"--test\" and \"--\" you can select the test and which arguments are"
+    echo " passed to the test. You can omit these, in which case the first unknown parameter"
+    echo " is the test and all other unknown parameters are passed to the test. For example"
+    echo "   $0 -m --test src/core/tests/test-core -- -p /general/match-spec/device"
+    echo " can also be called as"
+    echo "   $0 src/core/tests/test-core -p /general/match-spec/device -m"
+    echo ""
+    echo "  The following environment variables are honored:"
+    echo "    NMTST_USE_VALGRIND=0|1: enable/disable valgrind"
+    echo "    NMTST_LIBTOOL=: libtool path (or disable)"
+    echo "    NMTST_LAUNCH_DBUS=0|1: whether to lounch a D-Bus session"
+    echo "    NMTST_SET_DEBUG=0|1: saet NMTST_DEBUG=d"
+    echo ""
+    echo " This script is also called by the build system as test wrapper. In that case"
+    echo " different, internal command line syntax is used. In that case, environment variables"
+    echo " are still honored, so \`NMTST_USE_VALGRIND=1 make check\` works as expected"
+}
+
 SCRIPT_PATH="${SCRIPT_PATH:-$(readlink -f "$(dirname "$0")")}"
 
 VALGRIND_ERROR=37
@@ -90,6 +127,7 @@ if [ "$CALLED_FROM_MAKE" == 1 ]; then
     TEST="$1"; shift
     NMTST_MAKE_FIRST=0
 
+    TEST_ARGV=("$@")
 else
     if [[ -z "${NMTST_USE_VALGRIND+x}" ]]; then
         # by default, disable valgrind checks.
@@ -103,9 +141,14 @@ else
     else
         NMTST_LIBTOOL=("$NMTST_LIBTOOL" "--mode=execute")
     fi
+    TEST_ARGV=()
     unset TEST
     while test $# -gt 0; do
         case "$1" in
+        --help|-h)
+            usage
+            exit 0
+            ;;
         "--launch-dbus")
             NMTST_LAUNCH_DBUS=1
             shift
@@ -141,19 +184,26 @@ else
             ;;
         "--")
             shift
+            if test -z "${TEST+x}"; then
+                TEST="$1";
+                shift
+            fi
+            TEST_ARGV+=("$@")
             break
             ;;
         *)
-            break
+            if test -z "${TEST+x}"; then
+                TEST="$1";
+            else
+                TEST_ARGV+=("$1")
+            fi
+            shift
             ;;
         esac
     done
 
     # we support calling the script directly. In this case,
     # only pass the path to the test to run.
-    if test -z "${TEST+x}"; then
-        TEST="$1"; shift
-    fi
     if [[ -z "${NMTST_SUPPRESSIONS+x}" ]]; then
         NMTST_SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions"
     fi
@@ -178,6 +228,8 @@ if [ "$NMTST_SET_DEBUG" == 1 -a -z "${NMTST_DEBUG+x}" ]; then
     export NMTST_DEBUG=d
 fi
 
+[ -n "$TEST" ] || die "Missing test name. Specify it on the command line."
+
 if _is_true "$NMTST_MAKE_FIRST" 0; then
     git_dir="$(readlink -f "$(git rev-parse --show-toplevel)")"
     rel_path="$(realpath --relative-to="$git_dir" -m "$TEST" 2>/dev/null)" || die "cannot resolve test-name \"$TEST\". Did you call the script properly?"
@@ -207,7 +259,7 @@ fi
 
 NMTST_DBUS_RUN_SESSION=()
 if _is_true "$NMTST_LAUNCH_DBUS"; then
-    if ! which dbus-run-session &>/dev/null ; then
+    if ! command -v dbus-run-session &>/dev/null ; then
         eval `dbus-launch --sh-syntax`
         trap "kill $DBUS_SESSION_BUS_PID" EXIT
     else
@@ -244,12 +296,12 @@ fi
 if ! _is_true "$NMTST_USE_VALGRIND" 0; then
     export NM_TEST_UNDER_VALGRIND=0
     exec "${NMTST_DBUS_RUN_SESSION[@]}" \
-    "$TEST" "$@"
+    "$TEST" "${TEST_ARGV[@]}"
     die "exec \"$TEST\" failed"
 fi
 
 if [[ -z "${NMTST_VALGRIND}" ]]; then
-    NMTST_VALGRIND=`which valgrind` || die "cannot find valgrind binary. Set \$NMTST_VALGRIND"
+    NMTST_VALGRIND="$(command -v valgrind)" || die "cannot find valgrind binary. Set \$NMTST_VALGRIND"
 else
     test -e "${NMTST_VALGRIND}" || die "cannot find valgrind binary from NMTST_VALGRIND=\"${NMTST_VALGRIND}\""
 fi
@@ -276,7 +328,7 @@ export NM_TEST_UNDER_VALGRIND=1
     --num-callers=100 \
     --log-file="$LOGFILE" \
     "$TEST" \
-    "$@"
+    "${TEST_ARGV[@]}"
 RESULT=$?
 
 test -s "$LOGFILE"