twister: Use natural sort when generating hardware map

Use the natural sort of list when generating a hardware map. The
list is sorted with a serial port as a key. When more than 10 ports
are active and some of devices use more than one port, the ports
of one device may be listed in wrong sequence, which may cause
futher problems with selecting the right port for listening to
the device.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
This commit is contained in:
Grzegorz Chwierut 2023-06-06 14:12:37 +02:00 committed by Anas Nashif
commit c37deeb0c4
2 changed files with 3 additions and 1 deletions

View file

@ -13,6 +13,7 @@ import yaml
import scl
import logging
from pathlib import Path
from natsort import natsorted
from twisterlib.environment import ZEPHYR_BASE
@ -321,7 +322,7 @@ class HardwareMap:
def save(self, hwm_file):
# use existing map
self.detected.sort(key=lambda x: x.serial or '')
self.detected = natsorted(self.detected, key=lambda x: x.serial or '')
if os.path.exists(hwm_file):
with open(hwm_file, 'r') as yaml_file:
hwm = yaml.load(yaml_file, Loader=SafeLoader)

View file

@ -7,6 +7,7 @@ pyocd>=0.35.0
# used by twister for board/hardware map
tabulate
natsort
# used by mcuboot
cbor>=1.0.0