From c37deeb0c4602dc3eeb700a7dc3ed317283fff17 Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Tue, 6 Jun 2023 14:12:37 +0200 Subject: [PATCH] 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 --- scripts/pylib/twister/twisterlib/hardwaremap.py | 3 ++- scripts/requirements-run-test.txt | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/hardwaremap.py b/scripts/pylib/twister/twisterlib/hardwaremap.py index a0ea7c59a8e..5e90b7c84c6 100644 --- a/scripts/pylib/twister/twisterlib/hardwaremap.py +++ b/scripts/pylib/twister/twisterlib/hardwaremap.py @@ -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) diff --git a/scripts/requirements-run-test.txt b/scripts/requirements-run-test.txt index 3bb0b21c44e..83692128110 100644 --- a/scripts/requirements-run-test.txt +++ b/scripts/requirements-run-test.txt @@ -7,6 +7,7 @@ pyocd>=0.35.0 # used by twister for board/hardware map tabulate +natsort # used by mcuboot cbor>=1.0.0