scripts: pytest: align adapters API

Select and place common code of three adapters (HardwareAdapter,
BinaryAdapterBase and QemuAdapter) into basic DeviceAdapter class.

Introduce new way of reading device output by run separate thread which
try to read device output and place it into internal python queue.
Thanks to this, now it is possible to create readline method for all
adapters, which can be unblock when timeout occur.

Collect all common steps which have to be done before setup device in
launch method. The same was done for teardown operations which were
placed into close method.

Additionally some protection mechanisms were introduced to prevent for
undesirable side-effects when user could try to launch to already
launched device or try to send some data to disconnected device.

iter_stdout method was replaced by two new methods: readline and
readlines. To make it possible to remove all read output from internal
buffer (queue), clear_buffer method was introduced.

Also unit tests were rewritten to work properly with current version
of adapters.

Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
This commit is contained in:
Piotr Golyzniak 2023-08-04 15:23:34 +02:00 committed by Anas Nashif
commit f22c2d6388
17 changed files with 754 additions and 780 deletions

View file

@ -231,7 +231,7 @@ class Pytest(Harness):
def pytest_run(self, timeout):
try:
cmd = self.generate_command(timeout)
cmd = self.generate_command()
self.run_command(cmd, timeout)
except PytestHarnessException as pytest_exception:
logger.error(str(pytest_exception))
@ -242,7 +242,7 @@ class Pytest(Harness):
self.instance.handler.make_device_available(self.reserved_serial)
self._update_test_status()
def generate_command(self, timeout):
def generate_command(self):
config = self.instance.testsuite.harness_config
pytest_root = config.get('pytest_root', 'pytest') if config else 'pytest'
pytest_args = config.get('pytest_args', []) if config else []
@ -253,8 +253,7 @@ class Pytest(Harness):
'-q',
os.path.join(self.source_dir, pytest_root),
f'--build-dir={self.running_dir}',
f'--junit-xml={self.report_file}',
f'--connection-timeout={timeout}'
f'--junit-xml={self.report_file}'
]
command.extend(pytest_args)