Skip to contentSkip to conversation

test-runner: allow regex for verbose option

PATCH Applied James Prestwood 2 participants 2 messages Jun 3, 2022

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/1 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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

'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.

---
 tools/runner.py |  7 +++++--
 tools/utils.py  | 11 +++++++----
 2 files changed, 12 insertions(+), 6 deletions(-)
tools/runner.py +5 -2
index ccc931ff..2ce26de0 100644
@@ -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=[])
tools/utils.py +7 -4
index 55db4227..d16f221f 100644
@@ -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
 
Signature · 1 line
2.34.1
Applied
#1 lore raw

Hi James,

Quoted 13 lines · James Prestwood

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:

Quoted 1 line
Quoted 1 line
Quoted 1 line

'test' in 'this,is,a,test'

True

Quoted 9 lines

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.

---
  tools/runner.py |  7 +++++--
  tools/utils.py  | 11 +++++++----
  2 files changed, 12 insertions(+), 6 deletions(-)

Applied, thanks.

Regards,
-Denis