1# Copyright (c) 2023 Nordic Semiconductor ASA 2# 3# SPDX-License-Identifier: Apache-2.0 4 5import textwrap 6 7from twister_harness.helpers.shell import ShellMCUbootArea, ShellMCUbootCommandParsed 8 9 10def test_if_mcuboot_command_output_is_parsed_two_areas() -> None: 11 cmd_output = textwrap.dedent(""" 12 \x1b[1;32muart:~$ \x1b[mmcuboot 13 swap type: revert 14 confirmed: 0 15 primary area (1): 16 version: 0.0.2+0 17 image size: 68240 18 magic: good 19 swap type: test 20 copy done: set 21 image ok: unset 22 secondary area (3): 23 version: 0.0.0+0 24 image size: 68240 25 magic: unset 26 swap type: none 27 copy done: unset 28 image ok: unset 29 \x1b[1;32muart:~$ \x1b[m 30 """) 31 mcuboot_parsed = ShellMCUbootCommandParsed.create_from_cmd_output(cmd_output.splitlines()) 32 assert isinstance(mcuboot_parsed, ShellMCUbootCommandParsed) 33 assert isinstance(mcuboot_parsed.areas[0], ShellMCUbootArea) 34 assert len(mcuboot_parsed.areas) == 2 35 assert mcuboot_parsed.areas[0].version == '0.0.2+0' 36 assert mcuboot_parsed.areas[0].swap_type == 'test' 37 38 39def test_if_mcuboot_command_output_is_parsed_with_failed_area() -> None: 40 cmd_output = textwrap.dedent(""" 41 \x1b[1;32muart:~$ \x1b[mmcuboot 42 swap type: revert 43 confirmed: 0 44 primary area (1): 45 version: 1.1.1+1 46 image size: 68240 47 magic: good 48 swap type: test 49 copy done: set 50 image ok: unset 51 failed to read secondary area (1) header: -5 52 \x1b[1;32muart:~$ \x1b[m 53 """) 54 mcuboot_parsed = ShellMCUbootCommandParsed.create_from_cmd_output(cmd_output.splitlines()) 55 assert len(mcuboot_parsed.areas) == 1 56 assert mcuboot_parsed.areas[0].version == '1.1.1+1' 57