77from __future__ import annotations
88
99import logging
10+ from collections .abc import Generator
1011from pathlib import Path
11- from typing import Generator
1212
1313import pytest
1414from helpers import reset_board
2525def kmu_provision_mcuboot (dut : DeviceAdapter ) -> Generator [DeviceAdapter , None , None ]: # type: ignore
2626 """Provision MCUboot keys using west ncs-provision upload command."""
2727 sysbuild_config = Path (dut .device_config .build_dir ) / "zephyr" / ".config"
28- assert find_in_config (sysbuild_config , "SB_CONFIG_MCUBOOT_SIGNATURE_USING_KMU" ), "KMU keys not configured"
28+ assert find_in_config (sysbuild_config , "SB_CONFIG_MCUBOOT_SIGNATURE_USING_KMU" ), (
29+ "KMU keys not configured"
30+ )
2931
3032 lines = dut .readlines_until (
31- regex = "Unable to find bootable image|Jumping to the first image slot" , print_output = True , timeout = 20
33+ regex = "Unable to find bootable image|Jumping to the first image slot" ,
34+ print_output = True ,
35+ timeout = 20 ,
36+ )
37+ assert not any ("Jumping to the first image slot" in line for line in lines ), (
38+ "MCUboot: already provisioned"
3239 )
33- assert not any ("Jumping to the first image slot" in line for line in lines ), "MCUboot: already provisioned"
3440
35- logger .info ("Provision KMU keys for MCUboot, Second key is a current key.First key should be revoked." )
41+ logger .info (
42+ "Provision KMU keys for MCUboot, Second key is a current key.First key should be revoked."
43+ )
3644 key_file = find_in_config (sysbuild_config , "SB_CONFIG_BOOT_SIGNATURE_KEY_FILE" )
37- keys = [APP_KEYS_FOR_KMU / "root-ed25519-1.pem" , key_file , APP_KEYS_FOR_KMU / "root-ed25519-2.pem" ]
45+ keys = [
46+ APP_KEYS_FOR_KMU / "root-ed25519-1.pem" ,
47+ key_file ,
48+ APP_KEYS_FOR_KMU / "root-ed25519-2.pem" ,
49+ ]
3850
3951 keyname = get_keyname_for_mcuboot (sysbuild_config )
4052 provision_keys_for_kmu (keys = keys , keyname = keyname , dev_id = dut .device_config .id )
@@ -56,7 +68,9 @@ def test_kmu_revoke_old_keys(dut: DeviceAdapter, shell: Shell, mcumgr: MCUmgr):
5668 tm .run_upgrade (updated_app )
5769
5870 lines = dut .readlines_until (
59- regex = "Unable to find bootable image|Jumping to the first image slot" , print_output = True , timeout = 20
71+ regex = "Unable to find bootable image|Jumping to the first image slot" ,
72+ print_output = True ,
73+ timeout = 20 ,
6074 )
6175
6276 match_lines (
@@ -86,7 +100,9 @@ def test_kmu_upgrade_with_new_key_then_with_old(dut: DeviceAdapter, shell: Shell
86100 tm .run_upgrade (updated_app , confirm = True )
87101
88102 lines = dut .readlines_until (
89- regex = "Unable to find bootable image|Jumping to the first image slot" , print_output = True , timeout = 20
103+ regex = "Unable to find bootable image|Jumping to the first image slot" ,
104+ print_output = True ,
105+ timeout = 20 ,
90106 )
91107 match_no_lines (lines , ["Unable to find bootable image" ])
92108
@@ -95,7 +111,9 @@ def test_kmu_upgrade_with_new_key_then_with_old(dut: DeviceAdapter, shell: Shell
95111
96112 logger .info ("Reset DUT to revoke old keys (swap type: none must be applied)" )
97113 tm .reset_device_from_shell ()
98- lines = dut .readlines_until (regex = "Jumping to the first image slot" , print_output = True , timeout = 20 )
114+ lines = dut .readlines_until (
115+ regex = "Jumping to the first image slot" , print_output = True , timeout = 20
116+ )
99117 match_lines (lines , ["Swap type: none" ])
100118
101119 logger .info ("Sign image with second provisioned key, that should be revoked" )
@@ -106,7 +124,9 @@ def test_kmu_upgrade_with_new_key_then_with_old(dut: DeviceAdapter, shell: Shell
106124 tm .run_upgrade (updated_app )
107125
108126 lines = dut .readlines_until (
109- regex = "Unable to find bootable image|Jumping to the first image slot" , print_output = True , timeout = 20
127+ regex = "Unable to find bootable image|Jumping to the first image slot" ,
128+ print_output = True ,
129+ timeout = 20 ,
110130 )
111131
112132 match_lines (
0 commit comments