scripts: pytest: unify timeouts

Add possibility of passing timeouts from Twister to pytest and unify
various timeouts used in adapters to point to one main timeout.

Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
This commit is contained in:
Piotr Golyzniak 2023-07-04 16:09:21 +02:00 committed by Anas Nashif
commit b486b2acab
9 changed files with 52 additions and 55 deletions

View file

@ -45,13 +45,13 @@ def test_if_qemu_adapter_raises_exception_for_empty_command(device) -> None:
device.command = []
exception_msg = 'Run simulation command is empty, please verify if it was generated properly.'
with pytest.raises(TwisterHarnessException, match=exception_msg):
device.flash_and_run(timeout=0.1)
device.flash_and_run()
def test_if_qemu_adapter_raises_exception_file_not_found(device) -> None:
device.command = ['dummy']
with pytest.raises(TwisterHarnessException, match='File not found: dummy'):
device.flash_and_run(timeout=0.1)
device.flash_and_run()
device.stop()
assert device._exc is not None
assert isinstance(device._exc, TwisterHarnessException)
@ -61,7 +61,7 @@ def test_if_qemu_adapter_raises_exception_file_not_found(device) -> None:
def test_if_qemu_adapter_raises_exception_when_subprocess_raised_an_error(patched_run, device):
device.command = ['echo', 'TEST']
with pytest.raises(TwisterHarnessException, match='Exception message'):
device.flash_and_run(timeout=0.1)
device.flash_and_run()
device.stop()
@ -69,11 +69,12 @@ def test_if_qemu_adapter_runs_without_errors(resources, tmp_path) -> None:
fifo_file_path = str(tmp_path / 'qemu-fifo')
script_path = resources.joinpath('fifo_mock.py')
device = QemuAdapter(DeviceConfig(build_dir=str(tmp_path)))
device.connection_timeout = 1
device.booting_timeout_in_ms = 1000
device.command = ['python', str(script_path), fifo_file_path]
device.connect()
device.initialize_log_files()
device.flash_and_run(timeout=1)
device.flash_and_run()
lines = list(device.iter_stdout)
assert 'Readability counts.' in lines
assert os.path.isfile(device.handler_log_file.filename)
@ -84,8 +85,9 @@ def test_if_qemu_adapter_runs_without_errors(resources, tmp_path) -> None:
def test_if_qemu_adapter_finishes_after_timeout(device) -> None:
device.connection_timeout = 0.1
device.command = ['sleep', '0.3']
device.flash_and_run(timeout=0.1)
device.flash_and_run()
device.stop()
assert device._process_ended_with_timeout is True