Skip to content

Commit ee5b5f3

Browse files
fabiobaltierijhedberg
authored andcommitted
twister: always call flash directly
Drop the logic to use the generator "flash" target, that is using west anyway, always call flash directly anyway so that those targets can be deprecated. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 77a62d1 commit ee5b5f3

File tree

6 files changed

+64
-126
lines changed

6 files changed

+64
-126
lines changed

scripts/pylib/twister/twisterlib/environment.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -818,14 +818,12 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
818818

819819
parser.add_argument(
820820
"--west-flash", nargs='?', const=[],
821-
help="""Uses west instead of ninja or make to flash when running with
822-
--device-testing. Supports comma-separated argument list.
821+
help="""Comma separated list of additional flags passed to west when
822+
running with --device-testing.
823823
824824
E.g "twister --device-testing --device-serial /dev/ttyACM0
825825
--west-flash="--board-id=foobar,--erase"
826826
will translate to "west flash -- --board-id=foobar --erase"
827-
828-
NOTE: device-testing must be enabled to use this option.
829827
"""
830828
)
831829
parser.add_argument(
@@ -836,8 +834,6 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
836834
E.g "twister --device-testing --device-serial /dev/ttyACM0
837835
--west-flash --west-runner=pyocd"
838836
will translate to "west flash --runner pyocd"
839-
840-
NOTE: west-flash must be enabled to use this option.
841837
"""
842838
)
843839

@@ -897,14 +893,6 @@ def parse_arguments(
897893
logger.error("--device-serial-pty is not supported on Windows OS")
898894
sys.exit(1)
899895

900-
if options.west_runner and options.west_flash is None:
901-
logger.error("west-runner requires west-flash to be enabled")
902-
sys.exit(1)
903-
904-
if options.west_flash and not options.device_testing:
905-
logger.error("west-flash requires device-testing to be enabled")
906-
sys.exit(1)
907-
908896
if not options.testsuite_root:
909897
# if we specify a test scenario which is part of a suite directly, do
910898
# not set testsuite root to default, just point to the test directory

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -545,68 +545,65 @@ def run_custom_script(script, timeout):
545545
logger.error(f"{script} timed out")
546546

547547
def _create_command(self, runner, hardware):
548-
if (self.options.west_flash is not None) or runner:
549-
command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir]
550-
command_extra_args = []
551-
552-
# There are three ways this option is used.
553-
# 1) bare: --west-flash
554-
# This results in options.west_flash == []
555-
# 2) with a value: --west-flash="--board-id=42"
556-
# This results in options.west_flash == "--board-id=42"
557-
# 3) Multiple values: --west-flash="--board-id=42,--erase"
558-
# This results in options.west_flash == "--board-id=42 --erase"
559-
if self.options.west_flash and self.options.west_flash != []:
560-
command_extra_args.extend(self.options.west_flash.split(','))
561-
562-
if runner:
563-
command.append("--runner")
564-
command.append(runner)
565-
566-
board_id = hardware.probe_id or hardware.id
567-
product = hardware.product
568-
if board_id is not None:
569-
if runner in ("pyocd", "nrfjprog", "nrfutil", "nrfutil_next"):
570-
command_extra_args.append("--dev-id")
571-
command_extra_args.append(board_id)
572-
elif runner == "esp32":
573-
command_extra_args.append("--esp-device")
574-
command_extra_args.append(board_id)
575-
elif (
576-
runner == "openocd"
577-
and product == "STM32 STLink"
578-
or runner == "openocd"
579-
and product == "STLINK-V3"
580-
):
581-
command_extra_args.append("--cmd-pre-init")
582-
command_extra_args.append(f"hla_serial {board_id}")
583-
elif runner == "openocd" and product == "EDBG CMSIS-DAP":
584-
command_extra_args.append("--cmd-pre-init")
585-
command_extra_args.append(f"cmsis_dap_serial {board_id}")
586-
elif runner == "openocd" and product == "LPC-LINK2 CMSIS-DAP":
587-
command_extra_args.append("--cmd-pre-init")
588-
command_extra_args.append(f"adapter serial {board_id}")
589-
elif runner == "jlink":
590-
command.append("--dev-id")
591-
command.append(board_id)
592-
elif runner == "linkserver":
593-
# for linkserver
594-
# --probe=#<number> select by probe index
595-
# --probe=<serial number> select by probe serial number
596-
command.append(f"--probe={board_id}")
597-
elif runner == "stm32cubeprogrammer" and product != "BOOT-SERIAL":
598-
command.append(f"--tool-opt=sn={board_id}")
599-
600-
# Receive parameters from runner_params field.
601-
if hardware.runner_params:
602-
for param in hardware.runner_params:
603-
command.append(param)
604-
605-
if command_extra_args:
606-
command.append('--')
607-
command.extend(command_extra_args)
608-
else:
609-
command = [self.generator_cmd, "-C", self.build_dir, "flash"]
548+
command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir]
549+
command_extra_args = []
550+
551+
# There are three ways this option is used.
552+
# 1) bare: default flags
553+
# This results in options.west_flash == []
554+
# 2) with a value: --west-flash="--board-id=42"
555+
# This results in options.west_flash == "--board-id=42"
556+
# 3) Multiple values: --west-flash="--board-id=42,--erase"
557+
# This results in options.west_flash == "--board-id=42 --erase"
558+
if self.options.west_flash and self.options.west_flash != []:
559+
command_extra_args.extend(self.options.west_flash.split(','))
560+
561+
if runner:
562+
command.append("--runner")
563+
command.append(runner)
564+
565+
board_id = hardware.probe_id or hardware.id
566+
product = hardware.product
567+
if board_id is not None:
568+
if runner in ("pyocd", "nrfjprog", "nrfutil", "nrfutil_next"):
569+
command_extra_args.append("--dev-id")
570+
command_extra_args.append(board_id)
571+
elif runner == "esp32":
572+
command_extra_args.append("--esp-device")
573+
command_extra_args.append(board_id)
574+
elif (
575+
runner == "openocd"
576+
and product == "STM32 STLink"
577+
or runner == "openocd"
578+
and product == "STLINK-V3"
579+
):
580+
command_extra_args.append("--cmd-pre-init")
581+
command_extra_args.append(f"hla_serial {board_id}")
582+
elif runner == "openocd" and product == "EDBG CMSIS-DAP":
583+
command_extra_args.append("--cmd-pre-init")
584+
command_extra_args.append(f"cmsis_dap_serial {board_id}")
585+
elif runner == "openocd" and product == "LPC-LINK2 CMSIS-DAP":
586+
command_extra_args.append("--cmd-pre-init")
587+
command_extra_args.append(f"adapter serial {board_id}")
588+
elif runner == "jlink":
589+
command.append("--dev-id")
590+
command.append(board_id)
591+
elif runner == "linkserver":
592+
# for linkserver
593+
# --probe=#<number> select by probe index
594+
# --probe=<serial number> select by probe serial number
595+
command.append(f"--probe={board_id}")
596+
elif runner == "stm32cubeprogrammer" and product != "BOOT-SERIAL":
597+
command.append(f"--tool-opt=sn={board_id}")
598+
599+
# Receive parameters from runner_params field.
600+
if hardware.runner_params:
601+
for param in hardware.runner_params:
602+
command.append(param)
603+
604+
if command_extra_args:
605+
command.append('--')
606+
command.extend(command_extra_args)
610607

611608
return command
612609

scripts/pylib/twister/twisterlib/runner.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -828,23 +828,6 @@ def parse_generated(self, filter_stages=None):
828828
filter_data.update(self.defconfig)
829829
filter_data.update(self.cmake_cache)
830830

831-
# Verify that twister's arguments support sysbuild.
832-
# Twister sysbuild flashing currently only works with west,
833-
# so --west-flash must be passed.
834-
if (
835-
self.instance.sysbuild
836-
and self.env.options.device_testing
837-
and self.env.options.west_flash is None
838-
):
839-
logger.warning("Sysbuild test will be skipped. West must be used for flashing.")
840-
return {
841-
os.path.join(
842-
self.platform.name,
843-
self.instance.toolchain,
844-
self.testsuite.name
845-
): True
846-
}
847-
848831
if self.testsuite and self.testsuite.filter:
849832
try:
850833
if os.path.exists(edt_pickle):

scripts/tests/twister/test_environment.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@
3232
['--device-serial-pty', 'dummy'],
3333
'--device-serial-pty is not supported on Windows OS'
3434
),
35-
(
36-
None,
37-
None,
38-
None,
39-
['--west-runner=dummy'],
40-
'west-runner requires west-flash to be enabled'
41-
),
42-
(
43-
None,
44-
None,
45-
None,
46-
['--west-flash=\"--board-id=dummy\"'],
47-
'west-flash requires device-testing to be enabled'
48-
),
4935
(
5036
None,
5137
{
@@ -136,8 +122,6 @@
136122
ids=[
137123
'short build path without ninja',
138124
'device-serial-pty on Windows',
139-
'west runner without west flash',
140-
'west-flash without device-testing',
141125
'valgrind without executable',
142126
'device serial without platform',
143127
'device serial with multiple platforms',

scripts/tests/twister/test_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ def mock_availability(handler, instance, no=num_of_failures):
10611061
None,
10621062
None,
10631063
None,
1064-
['generator_cmd', '-C', '$build_dir', 'flash']
1064+
['west', 'flash', '--skip-rebuild', '-d', '$build_dir']
10651065
),
10661066
(
10671067
[],
@@ -1155,7 +1155,7 @@ def mock_availability(handler, instance, no=num_of_failures):
11551155
'self_west_flash, runner,' \
11561156
' hardware_product_name, expected',
11571157
TESTDATA_13,
1158-
ids=['generator', '--west-flash', 'one west flash value',
1158+
ids=['default', '--west-flash', 'one west flash value',
11591159
'multiple west flash values', 'generic runner', 'pyocd',
11601160
'nrfjprog', 'openocd, STM32 STLink', 'openocd, STLINK-v3',
11611161
'openocd, EDBG CMSIS-DAP', 'jlink', 'stm32cubeprogrammer']

scripts/tests/twister/test_runner.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -557,19 +557,6 @@ def mock_popen(*args, **kwargs):
557557
[],
558558
{os.path.join('other', 'zephyr', 'dummy.testsuite.name'): False}
559559
),
560-
(
561-
'other', ['other'], True,
562-
False, None, True,
563-
'Dummy parse results', True,
564-
None,
565-
None,
566-
{},
567-
{},
568-
{},
569-
None,
570-
['Sysbuild test will be skipped. West must be used for flashing.'],
571-
{os.path.join('other', 'zephyr', 'dummy.testsuite.name'): True}
572-
),
573560
(
574561
'other', ['other'], False,
575562
True, None, False,
@@ -652,8 +639,7 @@ def mock_popen(*args, **kwargs):
652639
' expected_edt,' \
653640
' expected_logs, expected_return',
654641
TESTDATA_3,
655-
ids=['unit testing', 'domain', 'kconfig', 'no cache',
656-
'no west options', 'no edt',
642+
ids=['unit testing', 'domain', 'kconfig', 'no cache', 'no edt',
657643
'parse result', 'no parse result', 'no testsuite filter', 'parse err']
658644
)
659645
def test_filterbuilder_parse_generated(

0 commit comments

Comments
 (0)