1010import pytest
1111from twister_harness import DeviceAdapter
1212from twister_harness .helpers .utils import match_lines , match_no_lines , find_in_config
13- from common import (
14- provision_keys_for_kmu ,
15- reset_board ,
16- APP_KEYS_FOR_KMU
17- )
13+ from common import provision_keys_for_kmu , reset_board , APP_KEYS_FOR_KMU
1814
1915logger = logging .getLogger (__name__ )
2016
@@ -25,30 +21,32 @@ def test_kmu_policy_revokable(dut: DeviceAdapter):
2521 revoke keys and verify that the device does not boot.
2622 """
2723 logger .info ("Provision keys with 'revokable' policy" )
28- sysbuild_config = Path (dut .device_config .build_dir ) / ' zephyr' / ' .config'
29- key_file = find_in_config (sysbuild_config , ' SB_CONFIG_BOOT_SIGNATURE_KEY_FILE' )
24+ sysbuild_config = Path (dut .device_config .build_dir ) / " zephyr" / " .config"
25+ key_file = find_in_config (sysbuild_config , " SB_CONFIG_BOOT_SIGNATURE_KEY_FILE" )
3026 provision_keys_for_kmu (
3127 keys = [key_file ],
3228 keyname = "UROT_PUBKEY" ,
33- policy = ' revokable' ,
34- dev_id = dut .device_config .id
29+ policy = " revokable" ,
30+ dev_id = dut .device_config .id ,
3531 )
3632 dut .clear_buffer ()
3733 reset_board (dut .device_config .id )
3834
3935 lines = dut .readlines_until (
40- regex = ' Unable to find bootable image|Destroy ok' ,
41- print_output = True , timeout = 20 )
42- match_lines (lines , [' Destroy ok' ])
43- match_no_lines (lines , [' Unable to find bootable image' ])
36+ regex = " Unable to find bootable image|Destroy ok" , print_output = True , timeout = 20
37+ )
38+ match_lines (lines , [" Destroy ok" ])
39+ match_no_lines (lines , [" Unable to find bootable image" ])
4440 logger .info ("Revoked keys, reboot once again" )
4541
4642 dut .clear_buffer ()
4743 reset_board (dut .device_config .id )
4844 lines = dut .readlines_until (
49- regex = 'Unable to find bootable image|Destroy ok|Destroy failed' ,
50- print_output = True , timeout = 20 )
51- match_lines (lines , ['Unable to find bootable image' ])
45+ regex = "Unable to find bootable image|Image version" ,
46+ print_output = True ,
47+ timeout = 20 ,
48+ )
49+ match_lines (lines , ["Unable to find bootable image" ])
5250 logger .info ("Passed: not booted with revoked keys" )
5351
5452
@@ -59,36 +57,38 @@ def test_kmu_policy_lock(dut: DeviceAdapter):
5957 and the device boots successfully.
6058 """
6159 logger .info ("Provision keys with 'lock' policy" )
62- sysbuild_config = Path (dut .device_config .build_dir ) / ' zephyr' / ' .config'
63- key_file = find_in_config (sysbuild_config , ' SB_CONFIG_BOOT_SIGNATURE_KEY_FILE' )
60+ sysbuild_config = Path (dut .device_config .build_dir ) / " zephyr" / " .config"
61+ key_file = find_in_config (sysbuild_config , " SB_CONFIG_BOOT_SIGNATURE_KEY_FILE" )
6462 provision_keys_for_kmu (
6563 keys = [key_file ],
6664 keyname = "UROT_PUBKEY" ,
67- policy = ' lock' ,
68- dev_id = dut .device_config .id
65+ policy = " lock" ,
66+ dev_id = dut .device_config .id ,
6967 )
7068 dut .clear_buffer ()
7169 reset_board (dut .device_config .id )
7270
7371 lines = dut .readlines_until (
74- regex = 'Unable to find bootable image|Destroy ok|Destroy failed' ,
75- print_output = True , timeout = 20 )
76- match_lines (lines , ['Destroy failed' ])
77- match_no_lines (lines , ['Unable to find bootable image' ])
72+ regex = "Unable to find bootable image|Destroy ok|Destroy failed" ,
73+ print_output = True ,
74+ timeout = 20 ,
75+ )
76+ match_lines (lines , ["Destroy failed" ])
77+ match_no_lines (lines , ["Unable to find bootable image" ])
7878 logger .info ("Keys not destroyed, reboot once again" )
7979
8080 dut .clear_buffer ()
8181 reset_board (dut .device_config .id )
8282 lines = dut .readlines_until (
83- regex = 'Unable to find bootable image|Destroy ok|Destroy failed' ,
84- print_output = True , timeout = 20 )
85- match_no_lines (lines , ['Unable to find bootable image' ])
83+ regex = "Unable to find bootable image|Destroy ok|Destroy failed" ,
84+ print_output = True ,
85+ timeout = 20 ,
86+ )
87+ match_no_lines (lines , ["Unable to find bootable image" ])
8688 logger .info ("Passed: locked keys not destroyed, booted successfully" )
8789
8890
89- @pytest .mark .parametrize (
90- 'test_option' , ['use_last_key' , 'use_revoked_key' ]
91- )
91+ @pytest .mark .parametrize ("test_option" , ["use_last_key" , "use_revoked_key" ])
9292def test_kmu_policy_lock_last (dut : DeviceAdapter , test_option ):
9393 """
9494 Upload keys using 'lock-last' policy,
@@ -97,48 +97,52 @@ def test_kmu_policy_lock_last(dut: DeviceAdapter, test_option):
9797 and not booted if revoked key is used.
9898 """
9999 logger .info ("Provision keys with revokable policy" )
100- sysbuild_config = Path (dut .device_config .build_dir ) / ' zephyr' / ' .config'
101- key_file = find_in_config (sysbuild_config , ' SB_CONFIG_BOOT_SIGNATURE_KEY_FILE' )
100+ sysbuild_config = Path (dut .device_config .build_dir ) / " zephyr" / " .config"
101+ key_file = find_in_config (sysbuild_config , " SB_CONFIG_BOOT_SIGNATURE_KEY_FILE" )
102102
103- if test_option == ' use_last_key' :
103+ if test_option == " use_last_key" :
104104 keys = [
105- APP_KEYS_FOR_KMU / ' root-ed25519-1.pem' ,
106- APP_KEYS_FOR_KMU / ' root-ed25519-2.pem' ,
107- key_file
105+ APP_KEYS_FOR_KMU / " root-ed25519-1.pem" ,
106+ APP_KEYS_FOR_KMU / " root-ed25519-2.pem" ,
107+ key_file ,
108108 ]
109109 else :
110110 keys = [
111111 key_file ,
112- APP_KEYS_FOR_KMU / ' root-ed25519-1.pem' ,
113- APP_KEYS_FOR_KMU / ' root-ed25519-2.pem'
112+ APP_KEYS_FOR_KMU / " root-ed25519-1.pem" ,
113+ APP_KEYS_FOR_KMU / " root-ed25519-2.pem" ,
114114 ]
115115
116116 provision_keys_for_kmu (
117117 keys = keys ,
118118 keyname = "UROT_PUBKEY" ,
119- policy = ' lock-last' ,
120- dev_id = dut .device_config .id
119+ policy = " lock-last" ,
120+ dev_id = dut .device_config .id ,
121121 )
122122 dut .clear_buffer ()
123123 reset_board (dut .device_config .id )
124124
125125 lines = dut .readlines_until (
126- regex = 'Unable to find bootable image|Destroy failed' ,
127- print_output = True , timeout = 20 )
128- match_lines (lines , ['Destroy ok' , 'Destroy failed' ])
129- match_no_lines (lines , ['Unable to find bootable image' ])
126+ regex = "Unable to find bootable image|Destroy failed" ,
127+ print_output = True ,
128+ timeout = 20 ,
129+ )
130+ match_lines (lines , ["Destroy ok" , "Destroy failed" ])
131+ match_no_lines (lines , ["Unable to find bootable image" ])
130132 logger .info ("Revoked keys but not all, reboot once again" )
131133
132134 dut .clear_buffer ()
133135 reset_board (dut .device_config .id )
134136
135137 lines = dut .readlines_until (
136- regex = 'Unable to find bootable image|Destroy ok|Destroy failed' ,
137- print_output = True , timeout = 20 )
138+ regex = "Unable to find bootable image|Destroy ok|Destroy failed" ,
139+ print_output = True ,
140+ timeout = 20 ,
141+ )
138142
139- if test_option == ' use_last_key' :
140- match_no_lines (lines , [' Unable to find bootable image' ])
143+ if test_option == " use_last_key" :
144+ match_no_lines (lines , [" Unable to find bootable image" ])
141145 logger .info ("Passed: last key not destroyed, booted successfully" )
142146 else :
143- match_lines (lines , [' Unable to find bootable image' ])
147+ match_lines (lines , [" Unable to find bootable image" ])
144148 logger .info ("Passed: not booted with revoked key" )
0 commit comments