From 7058c2283f06f6eb23ce5dde2dd019b14261bd84 Mon Sep 17 00:00:00 2001 From: Hake Huang Date: Wed, 20 Mar 2024 12:20:06 +0800 Subject: [PATCH] twister: unify test scenario path to backslash Winodws user may use the `\` as path, but in twister we use the common `/` as path separated, to avoid the mis-use, convert it to `/` in twister first normpath, and then replace the os.sep tested by: For Linux Like: west twister -p disco_l475_iot1 -s samples/hello_world/... For Windows: west twister -p disco_l475_iot1 -s samples\hello_world\... fixing: #70310 Signed-off-by: Hake Huang --- scripts/pylib/twister/twisterlib/environment.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 86770eb4bf8ce6..adf31a4e499ade 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -43,6 +43,9 @@ installed_packages = [pkg.project_name for pkg in pkg_resources.working_set] # pylint: disable=not-an-iterable PYTEST_PLUGIN_INSTALLED = 'pytest-twister-harness' in installed_packages +def norm_path(astring): + newstring = os.path.normpath(astring).replace(os.sep, '/') + return newstring def add_parse_arguments(parser = None): if parser is None: @@ -96,7 +99,7 @@ def add_parse_arguments(parser = None): help="Load a list of tests and platforms to be run from file.") case_select.add_argument( - "-T", "--testsuite-root", action="append", default=[], + "-T", "--testsuite-root", action="append", default=[], type = norm_path, help="Base directory to recursively search for test cases. All " "testcase.yaml files under here will be processed. May be " "called multiple times. Defaults to the 'samples/' and " @@ -209,7 +212,7 @@ def add_parse_arguments(parser = None): and global timeout multiplier (this parameter)""") test_xor_subtest.add_argument( - "-s", "--test", "--scenario", action="append", + "-s", "--test", "--scenario", action="append", type = norm_path, help="Run only the specified testsuite scenario. These are named by " "")