summaryrefslogtreecommitdiffstats
path: root/tests/shell/run-tests.sh
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-09-06 13:52:04 +0200
committerFlorian Westphal <fw@strlen.de>2023-09-07 19:35:20 +0200
commitdfe443ff3db2ff886d519f4704c270627a9cff5a (patch)
tree406f96ae96edfa5475fe2e0e5f8b93f40562bc7c /tests/shell/run-tests.sh
parent2a9c395e70b439be0d59b96c65e02c81c4f2fbe3 (diff)
tests/shell: rework command line parsing in "run-tests.sh"
Parse the arguments in a loop, so that their order does not matter. Also, soon more command line arguments will be added, and this way of parsing seems more maintainable and flexible. Currently this is still after the is-root check and after unshare. That will be addressed later. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'tests/shell/run-tests.sh')
-rwxr-xr-xtests/shell/run-tests.sh98
1 files changed, 68 insertions, 30 deletions
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index b66ef4fa..a1576493 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -1,10 +1,5 @@
#!/bin/bash
-# Configuration
-TESTDIR="./$(dirname $0)/testcases"
-SRC_NFT="$(dirname $0)/../../src/nft"
-DIFF=$(which diff)
-
msg_error() {
echo "E: $1 ..." >&2
exit 1
@@ -18,6 +13,32 @@ msg_info() {
echo "I: $1"
}
+usage() {
+ echo " $0 [OPTIONS]"
+ echo
+ echo "OPTIONS:"
+ echo " -h|--help : Print usage."
+ echo " -v : Sets VERBOSE=y."
+ echo " -g : Sets DUMPGEN=y."
+ echo " -V : Sets VALGRIND=y."
+ echo " -K : Sets KMEMLEAK=y."
+ echo
+ echo "ENVIRONMENT VARIABLES:"
+ echo " NFT=<CMD> : Path to nft executable. Will be called as \`\$NFT [...]\` so"
+ echo " it can be a command with parameters. Note that in this mode quoting"
+ echo " does not work, so the usage is limited and the command cannot contain"
+ echo " spaces."
+ echo " VERBOSE=*|y : Enable verbose output."
+ echo " DUMPGEN=*|y : Regenerate dump files."
+ echo " VALGRIND=*|y : Run \$NFT in valgrind."
+ echo " KMEMLEAK=*|y : Check for kernel memleaks."
+}
+
+# Configuration
+TESTDIR="./$(dirname $0)/testcases"
+SRC_NFT="$(dirname $0)/../../src/nft"
+DIFF=$(which diff)
+
if [ "$(id -u)" != "0" ] ; then
msg_error "this requires root!"
fi
@@ -31,6 +52,48 @@ if [ "${1}" != "run" ]; then
fi
shift
+VERBOSE="$VERBOSE"
+DUMPGEN="$DUMPGEN"
+VALGRIND="$VALGRIND"
+KMEMLEAK="$KMEMLEAK"
+
+TESTS=()
+
+while [ $# -gt 0 ] ; do
+ A="$1"
+ shift
+ case "$A" in
+ -v)
+ VERBOSE=y
+ ;;
+ -g)
+ DUMPGEN=y
+ ;;
+ -V)
+ VALGRIND=y
+ ;;
+ -K)
+ KMEMLEAK=y
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ --)
+ TESTS+=( "$@" )
+ shift $#
+ ;;
+ *)
+ # Any unrecognized option is treated as a test name, and also
+ # enable verbose tests.
+ TESTS+=( "$A" )
+ VERBOSE=y
+ ;;
+ esac
+done
+
+SINGLE="${TESTS[*]}"
+
[ -z "$NFT" ] && NFT=$SRC_NFT
${NFT} > /dev/null 2>&1
ret=$?
@@ -59,31 +122,6 @@ if [ ! -x "$DIFF" ] ; then
DIFF=true
fi
-if [ "$1" == "-v" ] ; then
- VERBOSE=y
- shift
-fi
-
-if [ "$1" == "-g" ] ; then
- DUMPGEN=y
- shift
-fi
-
-if [ "$1" == "-V" ] ; then
- VALGRIND=y
- shift
-fi
-
-if [ "$1" == "-K" ]; then
- KMEMLEAK=y
- shift
-fi
-
-for arg in "$@"; do
- SINGLE+=" $arg"
- VERBOSE=y
-done
-
kernel_cleanup() {
$NFT flush ruleset
$MODPROBE -raq \