twister: pytest: use runner_params from hardware map YAML file
Use 'runner_params' specified in hardware map YAML file. This allows to configure custom params (like openocd's adapter configuration for FT232-based probe) when used with pytest harness. Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
parent
461fcf4cef
commit
8654daeebd
|
@ -66,6 +66,8 @@ class HardwareAdapter(DeviceAdapter):
|
||||||
extra_args: list[str] = []
|
extra_args: list[str] = []
|
||||||
runner = self.device_config.runner
|
runner = self.device_config.runner
|
||||||
base_args.extend(['--runner', runner])
|
base_args.extend(['--runner', runner])
|
||||||
|
for param in self.device_config.runner_params:
|
||||||
|
extra_args.append(param)
|
||||||
if board_id := self.device_config.id:
|
if board_id := self.device_config.id:
|
||||||
if runner == 'pyocd':
|
if runner == 'pyocd':
|
||||||
extra_args.append('--board-id')
|
extra_args.append('--board-id')
|
||||||
|
|
|
@ -67,6 +67,11 @@ def pytest_addoption(parser: pytest.Parser):
|
||||||
'--runner',
|
'--runner',
|
||||||
help='Use the specified west runner (pyocd, nrfjprog, etc.).'
|
help='Use the specified west runner (pyocd, nrfjprog, etc.).'
|
||||||
)
|
)
|
||||||
|
twister_harness_group.addoption(
|
||||||
|
'--runner-params',
|
||||||
|
action='append',
|
||||||
|
help='Use the specified west runner params.'
|
||||||
|
)
|
||||||
twister_harness_group.addoption(
|
twister_harness_group.addoption(
|
||||||
'--device-id',
|
'--device-id',
|
||||||
help='ID of connected hardware device (for example 000682459367).'
|
help='ID of connected hardware device (for example 000682459367).'
|
||||||
|
|
|
@ -22,6 +22,7 @@ class DeviceConfig:
|
||||||
serial: str = ''
|
serial: str = ''
|
||||||
baud: int = 115200
|
baud: int = 115200
|
||||||
runner: str = ''
|
runner: str = ''
|
||||||
|
runner_params: list[str] = field(default_factory=list, repr=False)
|
||||||
id: str = ''
|
id: str = ''
|
||||||
product: str = ''
|
product: str = ''
|
||||||
serial_pty: str = ''
|
serial_pty: str = ''
|
||||||
|
@ -46,6 +47,9 @@ class TwisterHarnessConfig:
|
||||||
west_flash_extra_args: list[str] = []
|
west_flash_extra_args: list[str] = []
|
||||||
if config.option.west_flash_extra_args:
|
if config.option.west_flash_extra_args:
|
||||||
west_flash_extra_args = [w.strip() for w in config.option.west_flash_extra_args.split(',')]
|
west_flash_extra_args = [w.strip() for w in config.option.west_flash_extra_args.split(',')]
|
||||||
|
runner_params: list[str] = []
|
||||||
|
if config.option.runner_params:
|
||||||
|
runner_params = [w.strip() for w in config.option.runner_params]
|
||||||
device_from_cli = DeviceConfig(
|
device_from_cli = DeviceConfig(
|
||||||
type=config.option.device_type,
|
type=config.option.device_type,
|
||||||
build_dir=_cast_to_path(config.option.build_dir),
|
build_dir=_cast_to_path(config.option.build_dir),
|
||||||
|
@ -54,6 +58,7 @@ class TwisterHarnessConfig:
|
||||||
serial=config.option.device_serial,
|
serial=config.option.device_serial,
|
||||||
baud=config.option.device_serial_baud,
|
baud=config.option.device_serial_baud,
|
||||||
runner=config.option.runner,
|
runner=config.option.runner,
|
||||||
|
runner_params=runner_params,
|
||||||
id=config.option.device_id,
|
id=config.option.device_id,
|
||||||
product=config.option.device_product,
|
product=config.option.device_product,
|
||||||
serial_pty=config.option.device_serial_pty,
|
serial_pty=config.option.device_serial_pty,
|
||||||
|
|
|
@ -128,6 +128,43 @@ def test_if_get_command_returns_proper_string_8(patched_which, device: HardwareA
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('shutil.which', return_value='west')
|
||||||
|
def test_if_get_command_returns_proper_string_with_runner_params_1(patched_which, device: HardwareAdapter) -> None:
|
||||||
|
device.device_config.build_dir = Path('build')
|
||||||
|
device.device_config.runner_params = ['--runner-param1', 'runner-param2']
|
||||||
|
device.generate_command()
|
||||||
|
assert isinstance(device.command, list)
|
||||||
|
assert device.command == [
|
||||||
|
'west', 'flash', '--skip-rebuild', '--build-dir', 'build',
|
||||||
|
'--runner', 'runner', '--', '--runner-param1', 'runner-param2'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('shutil.which', return_value='west')
|
||||||
|
def test_if_get_command_returns_proper_string_with_runner_params_2(patched_which, device: HardwareAdapter) -> None:
|
||||||
|
device.device_config.build_dir = Path('build')
|
||||||
|
device.device_config.runner = 'openocd'
|
||||||
|
device.device_config.runner_params = [
|
||||||
|
'--cmd-pre-init', 'adapter serial FT1LRSRD',
|
||||||
|
'--cmd-pre-init', 'source [find interface/ftdi/jtag-lock-pick_tiny_2.cfg]',
|
||||||
|
'--cmd-pre-init', 'transport select swd',
|
||||||
|
'--cmd-pre-init', 'source [find target/nrf52.cfg]',
|
||||||
|
'--cmd-pre-init', 'adapter speed 10000',
|
||||||
|
]
|
||||||
|
device.device_config.product = 'JTAG-lock-pick Tiny 2'
|
||||||
|
device.generate_command()
|
||||||
|
assert isinstance(device.command, list)
|
||||||
|
assert device.command == [
|
||||||
|
'west', 'flash', '--skip-rebuild', '--build-dir', 'build',
|
||||||
|
'--runner', 'openocd', '--',
|
||||||
|
'--cmd-pre-init', 'adapter serial FT1LRSRD',
|
||||||
|
'--cmd-pre-init', 'source [find interface/ftdi/jtag-lock-pick_tiny_2.cfg]',
|
||||||
|
'--cmd-pre-init', 'transport select swd',
|
||||||
|
'--cmd-pre-init', 'source [find target/nrf52.cfg]',
|
||||||
|
'--cmd-pre-init', 'adapter speed 10000',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('shutil.which', return_value='west')
|
@mock.patch('shutil.which', return_value='west')
|
||||||
def test_if_get_command_returns_proper_string_with_west_flash_extra_args(
|
def test_if_get_command_returns_proper_string_with_west_flash_extra_args(
|
||||||
patched_which, device: HardwareAdapter
|
patched_which, device: HardwareAdapter
|
||||||
|
|
|
@ -382,6 +382,9 @@ class Pytest(Harness):
|
||||||
if runner := hardware.runner or options.west_runner:
|
if runner := hardware.runner or options.west_runner:
|
||||||
command.append(f'--runner={runner}')
|
command.append(f'--runner={runner}')
|
||||||
|
|
||||||
|
for param in hardware.runner_params:
|
||||||
|
command.append(f'--runner-params={param}')
|
||||||
|
|
||||||
if options.west_flash and options.west_flash != []:
|
if options.west_flash and options.west_flash != []:
|
||||||
command.append(f'--west-flash-extra-args={options.west_flash}')
|
command.append(f'--west-flash-extra-args={options.west_flash}')
|
||||||
|
|
||||||
|
|
|
@ -316,6 +316,7 @@ def test_pytest__generate_parameters_for_hardware(tmp_path, pty_value, hardware_
|
||||||
hardware.serial = 'serial'
|
hardware.serial = 'serial'
|
||||||
hardware.baud = 115200
|
hardware.baud = 115200
|
||||||
hardware.runner = "runner"
|
hardware.runner = "runner"
|
||||||
|
hardware.runner_params = ["--runner-param1", "runner-param2"]
|
||||||
|
|
||||||
options = handler.options
|
options = handler.options
|
||||||
options.west_flash = "args"
|
options.west_flash = "args"
|
||||||
|
@ -349,6 +350,8 @@ def test_pytest__generate_parameters_for_hardware(tmp_path, pty_value, hardware_
|
||||||
assert '--device-serial=serial' in command
|
assert '--device-serial=serial' in command
|
||||||
assert '--device-serial-baud=115200' in command
|
assert '--device-serial-baud=115200' in command
|
||||||
assert '--runner=runner' in command
|
assert '--runner=runner' in command
|
||||||
|
assert '--runner-params=--runner-param1' in command
|
||||||
|
assert '--runner-params=runner-param2' in command
|
||||||
assert '--west-flash-extra-args=args' in command
|
assert '--west-flash-extra-args=args' in command
|
||||||
assert '--device-id=123' in command
|
assert '--device-id=123' in command
|
||||||
assert '--device-product=product' in command
|
assert '--device-product=product' in command
|
||||||
|
|
Loading…
Reference in a new issue