3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-21 22:09:23 +01:00

test-runner: allow regex for verbose option

The glob match was completely broken for --verbose because globs
are actually path matches, not generally for strings. Instead
match based on regular expressions.

First the verbose option was fixed to store it as an array as well
as write any list arguments into the kernel command line properly
(str() would include []). This has worked up until now because the
'in' keyword in python will work on strings just as well
as lists, for example:

>>> 'test' in 'this,is,a,test'
True

Then, the glob match was replaced with a regex match. Any exceptions
are caught and somewhat ignored (printed, but only seen with --debug).
This only guards against fatal exceptions from a user passing an
invalid expression.
This commit is contained in:
James Prestwood 2022-06-03 16:12:01 -07:00 committed by Denis Kenzior
parent 2ad5e48314
commit db3d6a3652
2 changed files with 12 additions and 6 deletions

View File

@ -72,7 +72,10 @@ class RunnerNamespace(Namespace):
if v in [None, False, [], '']:
continue
ret += '%s=%s ' % (k, str(v))
if type(v) is list:
ret += '%s=%s ' % (k, ','.join(v))
else:
ret += '%s=%s ' % (k, str(v))
return ret.strip()
@ -89,7 +92,7 @@ class RunnerCoreArgParse(ArgumentParser):
default=None,
type=os.path.abspath)
self.add_argument('--verbose', '-v', metavar='<list>',
type=str,
type=lambda x: x.split(','),
help='Comma separated list of applications',
dest='verbose',
default=[])

View File

@ -8,7 +8,7 @@ import dbus
from gi.repository import GLib
from weakref import WeakValueDictionary
from glob import glob
from re import match
from runner import RunnerCoreArgParse
@ -95,10 +95,13 @@ class Process(subprocess.Popen):
if process == 'valgrind' and 'iwd' in Process.testargs.verbose:
return True
# Handle any glob matches
# Handle any regex matches
for item in Process.testargs.verbose:
if process in glob(item):
return True
try:
if match(item, process):
return True
except Exception as e:
print("%s is not a valid regex" % item)
return False