Skip to content

Commit 4966de2

Browse files
enjiamainashif
authored andcommitted
twister: add a hardware map support for using serial pty
The hardware map feature can be used with serial pty mode in this change. And also add an runner_params option for passing more parameters from hardware map file to west runner. Note that you need to create this map file manually because it cannot be scanned out correctly due to pty is not a physical HW device existing in system. And also update doc/develop/test/twister.rst for the usage. Signed-off-by: Enjia Mai <[email protected]>
1 parent 5af3c6c commit 4966de2

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

doc/develop/test/twister.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,16 @@ only one board at a time, specified using the ``--platform`` option.
525525
The ``--device-serial-baud`` option is only needed if your device does not run at
526526
115200 baud.
527527

528+
To support devices without a physical serial port, use the ``--device-serial-pty``
529+
option. In this cases, log messages are captured for example using a script.
530+
In this case you can run twister with the following options::
531+
532+
scripts/twister --device-testing --device-serial-pty "script.py" \
533+
-p intel_adsp_cavs25 -T tests/kernel
534+
535+
The script is user-defined and handles delivering the messages which can be
536+
used by twister to determine the test execution status.
537+
528538

529539
Executing tests on multiple devices
530540
===================================
@@ -594,6 +604,46 @@ on those platforms.
594604
with the hardware map features. Boards that require other runners to flash the
595605
Zephyr binary are still work in progress.
596606

607+
Serial PTY support using ``--device-serial-pty`` can also be used in the
608+
hardware map::
609+
610+
- connected: true
611+
id: None
612+
platform: intel_adsp_cavs18
613+
product: None
614+
runner: intel_adsp
615+
serial_pty: path/to/script.py
616+
runner_params:
617+
- --remote-host=remote_host_ip_addr
618+
- --key=/path/to/key.pem
619+
- connected: true
620+
id: None
621+
platform: intel_adsp_cavs25
622+
product: None
623+
runner: intel_adsp
624+
serial_pty: path/to/script.py
625+
runner_params:
626+
- --remote-host=remote_host_ip_addr
627+
- --key=/path/to/key.pem
628+
629+
630+
The runner_params field indicates the parameters you want to pass to the
631+
west runner. For some boards the west runner needs some extra parameters to
632+
work. It is equivalent to following west and twister commands::
633+
634+
west flash --remote-host remote_host_ip_addr --key /path/to/key.pem
635+
636+
twister -p intel_adsp_cavs18 --device-testing --device-serial-pty script.py
637+
--west-flash="--remote-host=remote_host_ip_addr,--key=/path/to/key.pem"
638+
639+
640+
.. note::
641+
642+
For serial PTY, the "--generate-hardware-map" option cannot scan it out
643+
and generate a correct hardware map automatically. You have to edit it
644+
manually according to above example. This is because the serial port
645+
of the PTY is not fixed and being allocated in the system at runtime.
646+
597647
Fixtures
598648
+++++++++
599649

scripts/pylib/twister/twisterlib.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def device_is_available(self, instance):
790790

791791
def make_device_available(self, serial):
792792
for d in self.suite.duts:
793-
if d.serial == serial or d.serial_pty:
793+
if serial in [d.serial_pty, d.serial]:
794794
d.available = 1
795795

796796
@staticmethod
@@ -876,6 +876,13 @@ def handle(self):
876876
elif runner == "stm32cubeprogrammer":
877877
command.append("--tool-opt=sn=%s" % (board_id))
878878

879+
# Receive parameters from an runner_params field
880+
# of the specified hardware map file.
881+
for d in self.suite.duts:
882+
if (d.platform == self.instance.platform.name) and d.runner_params:
883+
for param in d.runner_params:
884+
command.append(param)
885+
879886
if command_extra_args != []:
880887
command.append('--')
881888
command.extend(command_extra_args)
@@ -908,7 +915,10 @@ def handle(self):
908915
outs, errs = ser_pty_process.communicate()
909916
logger.debug("Process {} terminated outs: {} errs {}".format(serial_pty, outs, errs))
910917

911-
self.make_device_available(serial_device)
918+
if serial_pty:
919+
self.make_device_available(serial_pty)
920+
else:
921+
self.make_device_available(serial_device)
912922
return
913923

914924
ser.flush()
@@ -1003,8 +1013,10 @@ def handle(self):
10031013
if post_script:
10041014
self.run_custom_script(post_script, 30)
10051015

1006-
self.make_device_available(serial_device)
1007-
1016+
if serial_pty:
1017+
self.make_device_available(serial_pty)
1018+
else:
1019+
self.make_device_available(serial_device)
10081020

10091021
class QEMUHandler(Handler):
10101022
"""Spawns a thread to monitor QEMU output from pipes
@@ -4360,6 +4372,7 @@ def __init__(self,
43604372
product=None,
43614373
serial_pty=None,
43624374
connected=False,
4375+
runner_params=None,
43634376
pre_script=None,
43644377
post_script=None,
43654378
post_flash_script=None,
@@ -4376,6 +4389,7 @@ def __init__(self,
43764389
self.id = id
43774390
self.product = product
43784391
self.runner = runner
4392+
self.runner_params = runner_params
43794393
self.fixtures = []
43804394
self.post_flash_script = post_flash_script
43814395
self.post_script = post_script
@@ -4478,17 +4492,22 @@ def load(self, map_file):
44784492
platform = dut.get('platform')
44794493
id = dut.get('id')
44804494
runner = dut.get('runner')
4495+
runner_params = dut.get('runner_params')
4496+
serial_pty = dut.get('serial_pty')
44814497
serial = dut.get('serial')
44824498
baud = dut.get('baud', None)
44834499
product = dut.get('product')
44844500
fixtures = dut.get('fixtures', [])
4501+
connected= dut.get('connected') and ((serial or serial_pty) is not None)
44854502
new_dut = DUT(platform=platform,
44864503
product=product,
44874504
runner=runner,
4505+
runner_params=runner_params,
44884506
id=id,
4507+
serial_pty=serial_pty,
44894508
serial=serial,
44904509
serial_baud=baud,
4491-
connected=serial is not None,
4510+
connected=connected,
44924511
pre_script=pre_script,
44934512
post_script=post_script,
44944513
post_flash_script=post_flash_script)

scripts/schemas/twister/hwmap-schema.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ sequence:
2727
"runner":
2828
type: str
2929
required: true
30+
"runner_params":
31+
type: seq
32+
required: false
33+
sequence:
34+
- type: str
35+
"serial_pty":
36+
type: str
37+
required: false
3038
"serial":
3139
type: str
3240
required: false

0 commit comments

Comments
 (0)