Skip to content

Commit

Permalink
twister: pytest: Update MCUmgr helper method
Browse files Browse the repository at this point in the history
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 3e23496)

Original-Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
GitOrigin-RevId: 3e23496
Change-Id: I503b073a4c67d75fc60960258c76f8d90910e8f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5233911
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Tristan Honscheid <honscheid@google.com>
Commit-Queue: Tristan Honscheid <honscheid@google.com>
Tested-by: Tristan Honscheid <honscheid@google.com>
  • Loading branch information
gchwier authored and Chromeos LUCI committed Feb 3, 2024
1 parent 25d981d commit 402b0da
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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:
Expand All @@ -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}')

0 comments on commit 402b0da

Please sign in to comment.