1# Copyright (c) 2023 Nordic Semiconductor ASA 2# 3# SPDX-License-Identifier: Apache-2.0 4from __future__ import annotations 5 6import logging 7 8from twister_harness import MCUmgr, Shell 9from twister_harness.helpers.shell import ShellMCUbootCommandParsed 10 11logger = logging.getLogger(__name__) 12 13 14def check_with_shell_command(shell: Shell, version: str, swap_type: str | None = None) -> None: 15 mcuboot_areas = ShellMCUbootCommandParsed.create_from_cmd_output(shell.exec_command('mcuboot')) 16 assert mcuboot_areas.areas[0].version == version 17 if swap_type: 18 assert mcuboot_areas.areas[0].swap_type == swap_type 19 20 21def check_with_mcumgr_command(mcumgr: MCUmgr, version: str) -> None: 22 image_list = mcumgr.get_image_list() 23 # version displayed by MCUmgr does not print +0 and changes + to '.' for non-zero values 24 assert image_list[0].version == version.replace('+0', '').replace('+', '.') 25