From 402b0da99a8abf80f0184b0f000630ef5e655f2a Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Wed, 17 Jan 2024 16:18:52 +0100 Subject: [PATCH] twister: pytest: Update MCUmgr helper method Update helper method used by pytest fixtures. Extended upload method with 'slot' parameter. Added searching of uploaded images that can be tested or confirmed. (cherry picked from commit 3e234966dc46e41b1fa55a9a0e92589a6a9e7fdc) Original-Signed-off-by: Grzegorz Chwierut GitOrigin-RevId: 3e234966dc46e41b1fa55a9a0e92589a6a9e7fdc Change-Id: I503b073a4c67d75fc60960258c76f8d90910e8f2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5233911 Tested-by: ChromeOS Prod (Robot) Reviewed-by: Tristan Honscheid Commit-Queue: Tristan Honscheid Tested-by: Tristan Honscheid --- .../src/twister_harness/helpers/mcumgr.py | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py index b6cab6475c1..c1cb109524e 100755 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py @@ -54,8 +54,11 @@ def run_command(self, cmd: str) -> str: def reset_device(self): self.run_command('reset') - def image_upload(self, image: Path | str, timeout: int = 30): - self.run_command(f'-t {timeout} image upload {image}') + def image_upload(self, image: Path | str, slot: int | None = None, timeout: int = 30): + command = f'-t {timeout} image upload {image}' + if slot: + command += f' -e -n {slot}' + self.run_command(command) logger.info('Image successfully uploaded') def get_image_list(self) -> list[MCUmgrImage]: @@ -88,10 +91,19 @@ def _parse_image_list(cmd_output: str) -> list[MCUmgrImage]: def get_hash_to_test(self) -> str: image_list = self.get_image_list() - if len(image_list) < 2: - logger.info(image_list) - raise MCUmgrException('Please check image list returned by mcumgr') - return image_list[1].hash + for image in image_list: + if 'active' not in image.flags: + return image.hash + logger.warning(f'Images returned by mcumgr (no not active):\n{image_list}') + raise MCUmgrException('No not active image found') + + def get_hash_to_confirm(self): + image_list = self.mcumgr.get_image_list() + for image in image_list: + if 'confirmed' not in image.flags: + return image.hash + logger.warning(f'Images returned by mcumgr (no not confirmed):\n{image_list}') + raise MCUmgrException('No not confirmed image found') def image_test(self, hash: str | None = None): if not hash: @@ -100,6 +112,5 @@ def image_test(self, hash: str | None = None): def image_confirm(self, hash: str | None = None): if not hash: - image_list = self.get_image_list() - hash = image_list[0].hash + hash = self.get_hash_to_confirm() self.run_command(f'image confirm {hash}')