@@ -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+
47108static 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
257326ZTEST (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
274351ZTEST (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
291376ZTEST (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
308401ZTEST (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
325453ZTEST (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