1818from collections .abc import Generator
1919from datetime import datetime , timezone
2020from importlib import metadata
21- from pathlib import Path
2221
2322import zephyr_module
2423from twisterlib .constants import SUPPORTED_SIMS
2524from twisterlib .coverage import supported_coverage_formats
2625from twisterlib .error import TwisterRuntimeError
2726from twisterlib .log_helper import log_command
27+ from twisterlib .twister_path import TPath
2828
2929logger = logging .getLogger ('twister' )
3030logger .setLevel (logging .DEBUG )
@@ -133,7 +133,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
133133 )
134134
135135 case_select .add_argument (
136- "-T" , "--testsuite-root" , action = "append" , default = [], type = norm_path ,
136+ "-T" , "--testsuite-root" , action = "append" , default = [], type = TPath ,
137137 help = "Base directory to recursively search for test cases. All "
138138 "testcase.yaml files under here will be processed. May be "
139139 "called multiple times. Defaults to the 'samples/' and "
@@ -248,7 +248,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
248248 and global timeout multiplier (this parameter)""" )
249249
250250 test_xor_subtest .add_argument (
251- "-s" , "--test" , "--scenario" , action = "append" , type = norm_path ,
251+ "-s" , "--test" , "--scenario" , action = "append" , type = TPath ,
252252 help = """Run only the specified test suite scenario. These are named by
253253 'path/relative/to/Zephyr/base/section.subsection_in_testcase_yaml',
254254 or just 'section.subsection' identifier. With '--testsuite-root' option
@@ -293,16 +293,19 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
293293
294294 # Start of individual args place them in alpha-beta order
295295
296- board_root_list = [f"{ ZEPHYR_BASE } /boards" , f"{ ZEPHYR_BASE } /subsys/testsuite/boards" ]
296+ board_root_list = [
297+ TPath (f"{ ZEPHYR_BASE } /boards" ),
298+ TPath (f"{ ZEPHYR_BASE } /subsys/testsuite/boards" )
299+ ]
297300
298301 modules = zephyr_module .parse_modules (ZEPHYR_BASE )
299302 for module in modules :
300303 board_root = module .meta .get ("build" , {}).get ("settings" , {}).get ("board_root" )
301304 if board_root :
302- board_root_list .append (os .path .join (module .project , board_root , "boards" ))
305+ board_root_list .append (TPath ( os .path .join (module .project , board_root , "boards" ) ))
303306
304307 parser .add_argument (
305- "-A" , "--board-root" , action = "append" , default = board_root_list ,
308+ "-A" , "--board-root" , action = "append" , default = board_root_list , type = TPath ,
306309 help = """Directory to search for board configuration files. All .yaml
307310files in the directory will be processed. The directory should have the same
308311structure in the main Zephyr tree: boards/<vendor>/<board_name>/""" )
@@ -349,7 +352,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
349352 "--cmake-only" , action = "store_true" ,
350353 help = "Only run cmake, do not build or run." )
351354
352- parser .add_argument ("--coverage-basedir" , default = ZEPHYR_BASE ,
355+ parser .add_argument ("--coverage-basedir" , default = ZEPHYR_BASE , type = TPath ,
353356 help = "Base source directory for coverage report." )
354357
355358 parser .add_argument ("--coverage-platform" , action = "append" , default = [],
@@ -374,7 +377,8 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
374377 parser .add_argument (
375378 "--test-config" ,
376379 action = "store" ,
377- default = os .path .join (ZEPHYR_BASE , "tests" , "test_config.yaml" ),
380+ type = TPath ,
381+ default = TPath (os .path .join (ZEPHYR_BASE , "tests" , "test_config.yaml" )),
378382 help = "Path to file with plans and test configurations."
379383 )
380384
@@ -431,7 +435,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
431435 help = "Do not filter based on toolchain, use the set "
432436 " toolchain unconditionally" )
433437
434- parser .add_argument ("--gcov-tool" , type = Path , default = None ,
438+ parser .add_argument ("--gcov-tool" , type = TPath , default = None ,
435439 help = "Path to the gcov tool to use for code coverage "
436440 "reports" )
437441
@@ -513,6 +517,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
513517 "-z" , "--size" ,
514518 action = "append" ,
515519 metavar = 'FILENAME' ,
520+ type = TPath ,
516521 help = "Ignore all other command line options and just produce a report to "
517522 "stdout with ROM/RAM section sizes on the specified binary images." )
518523
@@ -543,7 +548,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
543548 test_plan_report_xor .add_argument ("--list-tags" , action = "store_true" ,
544549 help = "List all tags occurring in selected tests." )
545550
546- parser .add_argument ("--log-file" , metavar = "FILENAME" , action = "store" ,
551+ parser .add_argument ("--log-file" , metavar = "FILENAME" , action = "store" , type = TPath ,
547552 help = "Specify a file where to save logs." )
548553
549554 parser .add_argument (
@@ -604,15 +609,15 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
604609 )
605610
606611 parser .add_argument (
607- "-O" , "--outdir" ,
608- default = os .path .join (os .getcwd (), "twister-out" ),
612+ "-O" , "--outdir" , type = TPath ,
613+ default = TPath ( os .path .join (os .getcwd (), "twister-out" ) ),
609614 help = "Output directory for logs and binaries. "
610615 "Default is 'twister-out' in the current directory. "
611616 "This directory will be cleaned unless '--no-clean' is set. "
612617 "The '--clobber-output' option controls what cleaning does." )
613618
614619 parser .add_argument (
615- "-o" , "--report-dir" ,
620+ "-o" , "--report-dir" , type = TPath ,
616621 help = """Output reports containing results of the test run into the
617622 specified directory.
618623 The output will be both in JSON and JUNIT format
@@ -663,6 +668,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
663668 "--quarantine-list" ,
664669 action = "append" ,
665670 metavar = "FILENAME" ,
671+ type = TPath ,
666672 help = "Load list of test scenarios under quarantine. The entries in "
667673 "the file need to correspond to the test scenarios names as in "
668674 "corresponding tests .yaml files. These scenarios "
@@ -831,7 +837,7 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
831837 parser .add_argument ("extra_test_args" , nargs = argparse .REMAINDER ,
832838 help = "Additional args following a '--' are passed to the test binary" )
833839
834- parser .add_argument ("--alt-config-root" , action = "append" , default = [],
840+ parser .add_argument ("--alt-config-root" , action = "append" , default = [], type = TPath ,
835841 help = "Alternative test configuration root/s. When a test is found, "
836842 "Twister will check if a test configuration file exist in any of "
837843 "the alternative test configuration root folders. For example, "
@@ -878,8 +884,8 @@ def parse_arguments(
878884
879885 # check again and make sure we have something set
880886 if not options .testsuite_root :
881- options .testsuite_root = [os .path .join (ZEPHYR_BASE , "tests" ),
882- os .path .join (ZEPHYR_BASE , "samples" )]
887+ options .testsuite_root = [TPath ( os .path .join (ZEPHYR_BASE , "tests" ) ),
888+ TPath ( os .path .join (ZEPHYR_BASE , "samples" ) )]
883889
884890 if options .last_metrics or options .compare_report :
885891 options .enable_size_report = True
@@ -1019,34 +1025,38 @@ def __init__(self, options : argparse.Namespace, default_options=None) -> None:
10191025
10201026 self .test_roots = options .testsuite_root
10211027
1022- if not isinstance (options .board_root , list ):
1023- self .board_roots = [options .board_root ]
1028+ if options :
1029+ if not isinstance (options .board_root , list ):
1030+ self .board_roots = [self .options .board_root ]
1031+ else :
1032+ self .board_roots = self .options .board_root
1033+ self .outdir = TPath (os .path .abspath (options .outdir ))
10241034 else :
10251035 self .board_roots = options .board_root
10261036 self .outdir = os .path .abspath (options .outdir )
10271037
1028- self .snippet_roots = [Path (ZEPHYR_BASE )]
1038+ self .snippet_roots = [TPath (ZEPHYR_BASE )]
10291039 modules = zephyr_module .parse_modules (ZEPHYR_BASE )
10301040 for module in modules :
10311041 snippet_root = module .meta .get ("build" , {}).get ("settings" , {}).get ("snippet_root" )
10321042 if snippet_root :
1033- self .snippet_roots .append (Path (module .project ) / snippet_root )
1043+ self .snippet_roots .append (TPath (module .project ) / snippet_root )
10341044
10351045
1036- self .soc_roots = [Path (ZEPHYR_BASE ), Path (ZEPHYR_BASE ) / 'subsys' / 'testsuite' ]
1037- self .dts_roots = [Path (ZEPHYR_BASE )]
1038- self .arch_roots = [Path (ZEPHYR_BASE )]
1046+ self .soc_roots = [TPath (ZEPHYR_BASE ), TPath (ZEPHYR_BASE ) / 'subsys' / 'testsuite' ]
1047+ self .dts_roots = [TPath (ZEPHYR_BASE )]
1048+ self .arch_roots = [TPath (ZEPHYR_BASE )]
10391049
10401050 for module in modules :
10411051 soc_root = module .meta .get ("build" , {}).get ("settings" , {}).get ("soc_root" )
10421052 if soc_root :
1043- self .soc_roots .append (Path (module .project ) / Path (soc_root ))
1053+ self .soc_roots .append (TPath (module .project ) / TPath (soc_root ))
10441054 dts_root = module .meta .get ("build" , {}).get ("settings" , {}).get ("dts_root" )
10451055 if dts_root :
1046- self .dts_roots .append (Path (module .project ) / Path (dts_root ))
1056+ self .dts_roots .append (TPath (module .project ) / TPath (dts_root ))
10471057 arch_root = module .meta .get ("build" , {}).get ("settings" , {}).get ("arch_root" )
10481058 if arch_root :
1049- self .arch_roots .append (Path (module .project ) / Path (arch_root ))
1059+ self .arch_roots .append (TPath (module .project ) / TPath (arch_root ))
10501060
10511061 self .hwm = None
10521062
@@ -1143,7 +1153,7 @@ def run_cmake_script(args=None):
11431153 return results
11441154
11451155 def get_toolchain (self ):
1146- toolchain_script = Path (ZEPHYR_BASE ) / Path ('cmake/verify-toolchain.cmake' )
1156+ toolchain_script = TPath (ZEPHYR_BASE ) / TPath ('cmake/verify-toolchain.cmake' )
11471157 result = self .run_cmake_script ([toolchain_script , "FORMAT=json" ])
11481158
11491159 try :
0 commit comments