[PATCH] tests: Support globs for tests in run-all.sh / run-tests.py
Karsten Sperling
ksperling at apple.com
Sun Oct 11 16:15:14 PDT 2026
This is a strict superset of the trailing * syntax that is currently
supported. Tests still run in the order given on the command line, but
tests matching multiple arguments now run only once.
Signed-off-by: Karsten Sperling <ksperling at apple.com>
---
tests/hwsim/run-all.sh | 4 ++++
tests/hwsim/run-tests.py | 28 ++++++++++------------------
2 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/tests/hwsim/run-all.sh b/tests/hwsim/run-all.sh
index 507488041..861c6af49 100755
--- a/tests/hwsim/run-all.sh
+++ b/tests/hwsim/run-all.sh
@@ -134,7 +134,11 @@ if [ "$(id -u)" != 0 ]; then
else
SUDO=
fi
+# RUN_TEST_ARGS may contain shell glob patterns (e.g. "*eap_tls*"),
+# disable pathname expansion so they reach run-tests.py unexpanded.
+set -f
${SUDO} env VM=$VM ./run-tests.py -D --logdir "$LOGDIR" $TRACE_ARGS -q $DB $RUN_TEST_ARGS || errors=1
+set +f
./stop.sh
diff --git a/tests/hwsim/run-tests.py b/tests/hwsim/run-tests.py
index 52d64828c..599709686 100755
--- a/tests/hwsim/run-tests.py
+++ b/tests/hwsim/run-tests.py
@@ -8,6 +8,7 @@
import os
import re
+import fnmatch
import gc
import sys
import time
@@ -326,7 +327,9 @@ def main():
parser.add_argument('-i', action='store_true', dest='stdin_ctrl',
help='stdin-controlled test case execution')
parser.add_argument('tests', metavar='<test>', nargs='*', type=str,
- help='tests to run (only valid without -f)')
+ help='tests to run (only valid without -f); '
+ 'shell-style glob patterns (*, ?, [seq]) are '
+ 'supported, e.g. "*eap_tls*"')
args = parser.parse_args()
@@ -337,18 +340,8 @@ def main():
if args.tests:
fail = False
for t in args.tests:
- if t.endswith('*'):
- prefix = t.rstrip('*')
- found = False
- for tn in test_names:
- if tn.startswith(prefix):
- found = True
- break
- if not found:
- print('Invalid arguments - test "%s" wildcard did not match' % t)
- fail = True
- elif t not in test_names:
- print('Invalid arguments - test "%s" not known' % t)
+ if not any(fnmatch.fnmatchcase(tn, t) for tn in test_names):
+ print('Invalid arguments - test "%s" did not match any known test' % t)
fail = True
if fail:
sys.exit(2)
@@ -379,14 +372,13 @@ def main():
tests_to_run = []
if args.tests:
+ selected_names = set()
for selected in args.tests:
for t in tests:
name = t.__name__.replace('test_', '', 1)
- if selected.endswith('*'):
- prefix = selected.rstrip('*')
- if name.startswith(prefix):
- tests_to_run.append(t)
- elif name == selected:
+ if name not in selected_names and \
+ fnmatch.fnmatchcase(name, selected):
+ selected_names.add(name)
tests_to_run.append(t)
else:
for t in tests:
--
2.50.1 (Apple Git-155)
More information about the Hostap
mailing list