Skip to content

Commit 369f230

Browse files
tomchyrlubos
authored andcommitted
suit: Add tests for suit_execution_mode_failed
Add tests that verify execution mode transitions as a result of suit_execution_mode_failed API call. Ref: NCSDK-29623 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent e7c5c43 commit 369f230

File tree

6 files changed

+264
-0
lines changed

6 files changed

+264
-0
lines changed

tests/subsys/suit/orchestrator/orchestrator_sdfw/src/test_boot_mode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ ZTEST(orchestrator_boot_tests, test_boot_invalid_exec_mode)
161161
/* ... and the execution mode remains unchanged */
162162
zassert_equal(EXECUTION_MODE_POST_INVOKE, suit_execution_mode_get(),
163163
"Execution mode modified");
164+
/* ... and execution mode does not indicate a failed state */
165+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
166+
/* ... and execution mode does not indicate boot mode */
167+
zassert_equal(false, suit_execution_mode_booting(), "The device did not left boot mode");
168+
/* ... and execution mode does not indicate update mode */
169+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
164170
}
165171

166172
ZTEST(orchestrator_boot_tests, test_no_root_envelope)
@@ -191,6 +197,12 @@ ZTEST(orchestrator_boot_tests, test_no_root_envelope)
191197
"Emergency flag not set");
192198
/* ... and the execution mode remains unchanged */
193199
zassert_equal(EXECUTION_MODE_INVOKE, suit_execution_mode_get(), "Execution mode modified");
200+
/* ... and execution mode does not indicate a failed state */
201+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
202+
/* ... and execution mode indicates boot mode */
203+
zassert_equal(true, suit_execution_mode_booting(), "The device left boot mode");
204+
/* ... and execution mode does not indicate update mode */
205+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
194206
}
195207

196208
ZTEST(orchestrator_boot_tests, test_invalid_root_envelope)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
9+
#include <suit_execution_mode.h>
10+
11+
void check_startup_failure(void)
12+
{
13+
suit_execution_mode_t mode_before = suit_execution_mode_get();
14+
bool has_failed = suit_execution_mode_failed();
15+
16+
if (suit_execution_mode_booting()) {
17+
/* Update execution mode to leave transient states. */
18+
suit_execution_mode_startup_failed();
19+
20+
/* If the device was booting - it should enter EXECUTION_MODE_FAIL_STARTUP state. */
21+
zassert_equal(false, suit_execution_mode_booting(),
22+
"The device did not left boot mode");
23+
zassert_equal(false, suit_execution_mode_updating(),
24+
"The device entered update mode");
25+
zassert_equal(true, suit_execution_mode_failed(),
26+
"The device did not enter failed mode");
27+
zassert_equal(EXECUTION_MODE_FAIL_STARTUP, suit_execution_mode_get(),
28+
"FAILED state not set after boot startup failed");
29+
} else if (suit_execution_mode_updating()) {
30+
/* Update execution mode to leave transient states. */
31+
suit_execution_mode_startup_failed();
32+
33+
/* If the device was updating - it should enter EXECUTION_MODE_FAIL_STARTUP state.
34+
*/
35+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
36+
zassert_equal(false, suit_execution_mode_updating(),
37+
"The device did not left update mode");
38+
zassert_equal(true, suit_execution_mode_failed(),
39+
"The device did not enter failed mode");
40+
zassert_equal(EXECUTION_MODE_FAIL_STARTUP, suit_execution_mode_get(),
41+
"FAILED state not set after update startup failed");
42+
} else {
43+
/* Update execution mode to leave transient states. */
44+
suit_execution_mode_startup_failed();
45+
46+
/* If the device was in final state - it should stay in the same state state. */
47+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
48+
zassert_equal(false, suit_execution_mode_updating(),
49+
"The device entered update mode");
50+
zassert_equal(has_failed, suit_execution_mode_failed(),
51+
"The device changed failed mode");
52+
zassert_equal(mode_before, suit_execution_mode_get(),
53+
"Unexpected execution mode change");
54+
}
55+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef TEST_STARTUP_FAILURE_COMMON_H__
8+
#define TEST_STARTUP_FAILURE_COMMON_H__
9+
10+
/**
11+
* @brief Assert that calling @ref suit_execution_mode_startup_failed in the current state
12+
* is correctly handled.
13+
*/
14+
void check_startup_failure(void);
15+
16+
#endif /* TEST_STARTUP_FAILURE_COMMON_H__ */

tests/subsys/suit/orchestrator/orchestrator_sdfw/src/test_init.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/drivers/flash.h>
1414
#include <zephyr/storage/flash_map.h>
1515
#include <suit_plat_mem_util.h>
16+
#include "test_common.h"
1617

1718
#if DT_NODE_EXISTS(DT_NODELABEL(cpuapp_suit_storage))
1819
#define SUIT_STORAGE_OFFSET FIXED_PARTITION_OFFSET(cpuapp_suit_storage)
@@ -94,6 +95,14 @@ ZTEST(orchestrator_init_tests, test_empty_storage)
9495
"Regular boot not triggered");
9596
/* ... and orchestrator is initialized */
9697
zassert_equal(0, err, "Orchestrator not initialized");
98+
/* ... and execution mode does not indicate a failed state */
99+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
100+
/* ... and execution mode indicates boot mode */
101+
zassert_equal(true, suit_execution_mode_booting(), "The device did not enter boot mode");
102+
/* ... and execution mode does not indicate update mode */
103+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
104+
/* ... and the startup failure is correctly handled */
105+
check_startup_failure();
97106
}
98107

99108
ZTEST(orchestrator_init_tests, test_empty_storage_with_update_flag)
@@ -112,6 +121,14 @@ ZTEST(orchestrator_init_tests, test_empty_storage_with_update_flag)
112121
"Regular update not triggered");
113122
/* ... and orchestrator is initialized */
114123
zassert_equal(0, err, "Orchestrator not initialized");
124+
/* ... and execution mode does not indicate a failed state */
125+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
126+
/* ... and execution mode does not indicate boot mode */
127+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
128+
/* ... and execution mode indicates update mode */
129+
zassert_equal(true, suit_execution_mode_updating(), "The device did not enter update mode");
130+
/* ... and the startup failure is correctly handled */
131+
check_startup_failure();
115132
}
116133

117134
ZTEST(orchestrator_init_tests, test_empty_storage_with_recovery_flag)
@@ -130,6 +147,14 @@ ZTEST(orchestrator_init_tests, test_empty_storage_with_recovery_flag)
130147
"Recovery mode not triggered");
131148
/* ... and orchestrator is initialized */
132149
zassert_equal(0, err, "Orchestrator not initialized");
150+
/* ... and execution mode does not indicate a failed state */
151+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
152+
/* ... and execution mode indicates boot mode */
153+
zassert_equal(true, suit_execution_mode_booting(), "The device did not enter boot mode");
154+
/* ... and execution mode does not indicate update mode */
155+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
156+
/* ... and the startup failure is correctly handled */
157+
check_startup_failure();
133158
}
134159

135160
ZTEST(orchestrator_init_tests, test_empty_storage_with_update_recovery_flag)
@@ -149,4 +174,12 @@ ZTEST(orchestrator_init_tests, test_empty_storage_with_update_recovery_flag)
149174
"Emergency recovery update not triggered");
150175
/* ... and orchestrator is initialized */
151176
zassert_equal(0, err, "Orchestrator not initialized");
177+
/* ... and execution mode does not indicate a failed state */
178+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
179+
/* ... and execution mode does not indicate boot mode */
180+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
181+
/* ... and execution mode indicates update mode */
182+
zassert_equal(true, suit_execution_mode_updating(), "The device did not enter update mode");
183+
/* ... and the startup failure is correctly handled */
184+
check_startup_failure();
152185
}

tests/subsys/suit/orchestrator/orchestrator_sdfw/src/test_recovery_boot_mode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ ZTEST(orchestrator_recovery_boot_tests, test_rec_no_recovery_envelope)
164164
/* ... and the execution mode is set to the FAIL INVOKE RECOVERY */
165165
zassert_equal(EXECUTION_MODE_FAIL_INVOKE_RECOVERY, suit_execution_mode_get(),
166166
"Execution mode not changed to the FAIL INVOKE RECOVERY");
167+
/* ... and execution mode indicates a failed state */
168+
zassert_equal(true, suit_execution_mode_failed(), "The device does not enter failed mode");
169+
/* ... and execution mode does not indicate boot mode */
170+
zassert_equal(false, suit_execution_mode_booting(), "The device did not left boot mode");
171+
/* ... and execution mode does not indicate update mode */
172+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
167173
}
168174

169175
ZTEST(orchestrator_recovery_boot_tests, test_rec_invalid_recovery_envelope)
@@ -230,6 +236,12 @@ ZTEST(orchestrator_recovery_boot_tests, test_rec_valid_recovery_envelope)
230236
/* ... and the execution mode is set to the POST INVOKE RECOVERY */
231237
zassert_equal(EXECUTION_MODE_POST_INVOKE_RECOVERY, suit_execution_mode_get(),
232238
"Execution mode not changed to the POST INVOKE RECOVERY");
239+
/* ... and execution mode does not indicate a failed state */
240+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
241+
/* ... and execution mode does not indicate boot mode */
242+
zassert_equal(false, suit_execution_mode_booting(), "The device did not left boot mode");
243+
/* ... and execution mode does not indicate update mode */
244+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
233245
}
234246

235247
ZTEST(orchestrator_recovery_boot_tests, test_rec_seq_no_validate)

tests/subsys/suit/orchestrator/orchestrator_sdfw_nrf54h20/src/test_init.c

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,67 @@ static void setup_erased_flash(void *f)
4444
"Unable to clear recovery flag before test execution");
4545
}
4646

47+
static void setup_update_candidate(const uint8_t *buf, size_t len)
48+
{
49+
zassert_not_null(buf, "NULL buf");
50+
51+
suit_plat_mreg_t update_candidate[1] = {{
52+
.mem = buf,
53+
.size = len,
54+
}};
55+
56+
int err = suit_storage_update_cand_set(update_candidate, ARRAY_SIZE(update_candidate));
57+
58+
zassert_equal(SUIT_PLAT_SUCCESS, err,
59+
"Unable to set update candidate before test execution (0x%x, %d)", buf, len);
60+
}
61+
62+
static void check_startup_failure(void)
63+
{
64+
suit_execution_mode_t mode_before = suit_execution_mode_get();
65+
bool has_failed = suit_execution_mode_failed();
66+
67+
if (suit_execution_mode_booting()) {
68+
/* Update execution mode to leave transient states. */
69+
suit_execution_mode_startup_failed();
70+
71+
/* If the device was booting - it should enter EXECUTION_MODE_FAIL_STARTUP state. */
72+
zassert_equal(false, suit_execution_mode_booting(),
73+
"The device did not left boot mode");
74+
zassert_equal(false, suit_execution_mode_updating(),
75+
"The device entered update mode");
76+
zassert_equal(true, suit_execution_mode_failed(),
77+
"The device did not enter failed mode");
78+
zassert_equal(EXECUTION_MODE_FAIL_STARTUP, suit_execution_mode_get(),
79+
"FAILED state not set after boot startup failed");
80+
} else if (suit_execution_mode_updating()) {
81+
/* Update execution mode to leave transient states. */
82+
suit_execution_mode_startup_failed();
83+
84+
/* If the device was updating - it should enter EXECUTION_MODE_FAIL_STARTUP state.
85+
*/
86+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
87+
zassert_equal(false, suit_execution_mode_updating(),
88+
"The device did not left update mode");
89+
zassert_equal(true, suit_execution_mode_failed(),
90+
"The device did not enter failed mode");
91+
zassert_equal(EXECUTION_MODE_FAIL_STARTUP, suit_execution_mode_get(),
92+
"FAILED state not set after update startup failed");
93+
} else {
94+
/* Update execution mode to leave transient states. */
95+
suit_execution_mode_startup_failed();
96+
97+
/* If the device was in final state - it should stay in the same state state. */
98+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
99+
zassert_equal(false, suit_execution_mode_updating(),
100+
"The device entered update mode");
101+
zassert_equal(has_failed, suit_execution_mode_failed(),
102+
"The device changed failed mode");
103+
zassert_equal(mode_before, suit_execution_mode_get(),
104+
"Unexpected execution mode change");
105+
}
106+
}
107+
47108
static void write_empty_mpi_area_app(void)
48109
{
49110
/* Digest of the content defined in assert_empty_mpi_area_app(). */
@@ -252,6 +313,14 @@ ZTEST(orchestrator_nrf54h20_init_tests, test_no_mpi)
252313
"Lack of MPIs not detected");
253314
/* ... and orchestrator is initialized */
254315
zassert_equal(0, err, "Orchestrator not initialized");
316+
/* ... and execution mode indicates a failed state */
317+
zassert_equal(true, suit_execution_mode_failed(), "The device did not enter failed mode");
318+
/* ... and execution mode does not indicate boot mode */
319+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
320+
/* ... and execution mode does not indicate update mode */
321+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
322+
/* ... and the startup failure is correctly handled */
323+
check_startup_failure();
255324
}
256325

257326
ZTEST(orchestrator_nrf54h20_init_tests, test_no_root_mpi)
@@ -269,6 +338,14 @@ ZTEST(orchestrator_nrf54h20_init_tests, test_no_root_mpi)
269338
"Lack of ROOT MPIs not detected");
270339
/* ... and orchestrator is initialized */
271340
zassert_equal(0, err, "Orchestrator not initialized");
341+
/* ... and execution mode indicates a failed state */
342+
zassert_equal(true, suit_execution_mode_failed(), "The device did not enter failed mode");
343+
/* ... and execution mode does not indicate boot mode */
344+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
345+
/* ... and execution mode does not indicate update mode */
346+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
347+
/* ... and the startup failure is correctly handled */
348+
check_startup_failure();
272349
}
273350

274351
ZTEST(orchestrator_nrf54h20_init_tests, test_invalid_mpi_version)
@@ -286,6 +363,14 @@ ZTEST(orchestrator_nrf54h20_init_tests, test_invalid_mpi_version)
286363
"Malformed ROOT MPI not detected");
287364
/* ... and orchestrator is initialized */
288365
zassert_equal(0, err, "Orchestrator not initialized");
366+
/* ... and execution mode indicates a failed state */
367+
zassert_equal(true, suit_execution_mode_failed(), "The device did not enter failed mode");
368+
/* ... and execution mode does not indicate boot mode */
369+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
370+
/* ... and execution mode does not indicate update mode */
371+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
372+
/* ... and the startup failure is correctly handled */
373+
check_startup_failure();
289374
}
290375

291376
ZTEST(orchestrator_nrf54h20_init_tests, test_duplicate_class_id)
@@ -303,6 +388,14 @@ ZTEST(orchestrator_nrf54h20_init_tests, test_duplicate_class_id)
303388
"Malformed ROOT MPI not detected");
304389
/* ... and orchestrator is initialized */
305390
zassert_equal(0, err, "Orchestrator not initialized");
391+
/* ... and execution mode indicates a failed state */
392+
zassert_equal(true, suit_execution_mode_failed(), "The device did not enter failed mode");
393+
/* ... and execution mode does not indicate boot mode */
394+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
395+
/* ... and execution mode does not indicate update mode */
396+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
397+
/* ... and the startup failure is correctly handled */
398+
check_startup_failure();
306399
}
307400

308401
ZTEST(orchestrator_nrf54h20_init_tests, test_unupdateable_root)
@@ -320,6 +413,41 @@ ZTEST(orchestrator_nrf54h20_init_tests, test_unupdateable_root)
320413
"Non-updateable ROOT MPI not detected");
321414
/* ... and orchestrator is initialized */
322415
zassert_equal(0, err, "Orchestrator not initialized");
416+
/* ... and execution mode indicates a failed state */
417+
zassert_equal(true, suit_execution_mode_failed(), "The device did not enter failed mode");
418+
/* ... and execution mode does not indicate boot mode */
419+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
420+
/* ... and execution mode does not indicate update mode */
421+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
422+
/* ... and the startup failure is correctly handled */
423+
check_startup_failure();
424+
}
425+
426+
ZTEST(orchestrator_nrf54h20_init_tests, test_no_mpi_sdsc_update)
427+
{
428+
const uint8_t update_candidate[] = {0xA, 0xB, 0xC, 0xD};
429+
430+
/* GIVEN empty flash (suit storage and backup is erased)... */
431+
/* ... and update candidate flag is set... */
432+
setup_update_candidate(update_candidate, ARRAY_SIZE(update_candidate));
433+
/* ... and emergency flag is not set */
434+
435+
/* WHEN orchestrator is initialized */
436+
int err = suit_orchestrator_init();
437+
438+
/* THEN failed state with Nordic top update is triggered... */
439+
zassert_equal(EXECUTION_MODE_FAIL_INSTALL_NORDIC_TOP, suit_execution_mode_get(),
440+
"Nordic top update in failed state blocked");
441+
/* ... and orchestrator is initialized */
442+
zassert_equal(0, err, "Orchestrator not initialized");
443+
/* ... and execution mode does not indicate a failed state */
444+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
445+
/* ... and execution mode does not indicate boot mode */
446+
zassert_equal(false, suit_execution_mode_booting(), "The device entered boot mode");
447+
/* ... and execution mode does indicates update mode */
448+
zassert_equal(true, suit_execution_mode_updating(), "The device did not enter update mode");
449+
/* ... and the startup failure is correctly handled */
450+
check_startup_failure();
323451
}
324452

325453
ZTEST(orchestrator_nrf54h20_init_tests, test_valid_root)
@@ -337,4 +465,12 @@ ZTEST(orchestrator_nrf54h20_init_tests, test_valid_root)
337465
"Valid ROOT MPI not accepted");
338466
/* ... and orchestrator is initialized */
339467
zassert_equal(0, err, "Orchestrator not initialized");
468+
/* ... and execution mode does not indicate a failed state */
469+
zassert_equal(false, suit_execution_mode_failed(), "The device entered failed mode");
470+
/* ... and execution mode indicates boot mode */
471+
zassert_equal(true, suit_execution_mode_booting(), "The device did not enter boot mode");
472+
/* ... and execution mode does not indicate update mode */
473+
zassert_equal(false, suit_execution_mode_updating(), "The device entered update mode");
474+
/* ... and the startup failure is correctly handled */
475+
check_startup_failure();
340476
}

0 commit comments

Comments
 (0)