diff mbox series

[05/15] testrunner: Fix parsing for some arguments

Message ID 20220616000231.1966008-5-andrew.zaborowski@intel.com (mailing list archive)
State Accepted, archived
Headers show
Series [01/15] netconfig: Fix address format validation | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

Andrew Zaborowski June 16, 2022, 12:02 a.m. UTC
Currently the parameter values reach run-tests by first being parsed by
runner.py's RunnerArgParser, then the resulting object members being
encoded as a commandline string, then as environment variables, then the
environment being converted to a python string list and passed to
RunnerCoreArgParser again.  Where argument names (like --sub-tests) had
dashes, the object members had underscores (.sub_tests), this wasn't
taken into account when building the python string list from environment
variables so convert all underscores to dashes and hope that all the
names match now.

Additionally some arguments used nargs='1' or nargs='*' which resulted
in their python values becoming lists.  They were converted back to command
line arguments such as: --sub_tests ['static_test.py'], and when parsed
by RunnerCoreArgParser again, the values ended up being lists of lists.
In all three cases it seems the actual user of the parsed value actually
expects a single string with comma-separated substrings in it so just drop
the nargs= uses.
---
 tools/runner.py | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Denis Kenzior June 22, 2022, 8:58 p.m. UTC | #1
Hi Andrew,

On 6/15/22 19:02, Andrew Zaborowski wrote:
> Currently the parameter values reach run-tests by first being parsed by
> runner.py's RunnerArgParser, then the resulting object members being
> encoded as a commandline string, then as environment variables, then the
> environment being converted to a python string list and passed to
> RunnerCoreArgParser again.  Where argument names (like --sub-tests) had
> dashes, the object members had underscores (.sub_tests), this wasn't
> taken into account when building the python string list from environment
> variables so convert all underscores to dashes and hope that all the
> names match now.
> 
> Additionally some arguments used nargs='1' or nargs='*' which resulted
> in their python values becoming lists.  They were converted back to command
> line arguments such as: --sub_tests ['static_test.py'], and when parsed
> by RunnerCoreArgParser again, the values ended up being lists of lists.
> In all three cases it seems the actual user of the parsed value actually
> expects a single string with comma-separated substrings in it so just drop
> the nargs= uses.
> ---
>   tools/runner.py | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 

Patches 5,8-12 applied, thanks.

Regards,
-Denis
diff mbox series

Patch

diff --git a/tools/runner.py b/tools/runner.py
index 2ce26de0..b018a0ad 100644
--- a/tools/runner.py
+++ b/tools/runner.py
@@ -108,7 +108,7 @@  class RunnerCoreArgParse(ArgumentParser):
 				help='Enables iwmon output to file')
 		self.add_argument('--sub-tests', '-S',
 				metavar='<subtests>',
-				type=str, nargs=1, help='List of subtests to run',
+				type=str, help='List of subtests to run',
 				default=None, dest='sub_tests')
 		self.add_argument('--result', '-e',
 				type=os.path.abspath,
@@ -131,8 +131,6 @@  class RunnerCoreArgParse(ArgumentParser):
 		auto_unit_group.add_argument('--unit-tests', '-U',
 				metavar='<tests>',
 				type=str,
-				nargs='?',
-				const='*',
 				help='List of unit tests to run',
 				dest='unit_tests')
 
@@ -141,7 +139,6 @@  class RunnerCoreArgParse(ArgumentParser):
 		valgrind_gdb_group.add_argument('--gdb', '-g',
 				metavar='<exec>',
 				type=str,
-				nargs=1,
 				help='Run gdb on specified executable',
 				dest='gdb')
 		valgrind_gdb_group.add_argument('--valgrind', '-V',
@@ -156,7 +153,7 @@  class RunnerCoreArgParse(ArgumentParser):
 
 		options = []
 		for k, v in os.environ.items():
-			options.append('--' + k)
+			options.append('--' + k.replace('_', '-'))
 			options.append(v)
 
 		return self.parse_known_args(args=options, namespace=RunnerNamespace())[0]