Skip to content

Commit f1f83de

Browse files
ahasztagrlubos
authored andcommitted
suit: Aligned tests after adding validator
Aligned suit orchestrator tests after making it use the validator module. Also added two tests for verifying this part of the orchestrator. Signed-off-by: Artur Hadasz <[email protected]>
1 parent 6cb6ef9 commit f1f83de

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

tests/subsys/suit/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66

77
add_subdirectory(mci_test)
8+
add_subdirectory(validator_test)
89
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
910

1011
if (CONFIG_MBEDTLS)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4+
#
5+
6+
if (CONFIG_SUIT_VALIDATOR_IMPL_CUSTOM)
7+
zephyr_library_named(validator_test)
8+
zephyr_library_sources(validator_test.c)
9+
zephyr_library_link_libraries(suit_validator)
10+
11+
target_link_libraries(app PUBLIC validator_test)
12+
endif()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <suit_validator.h>
8+
9+
static suit_plat_err_t validate_candidate_location_common(uintptr_t address,
10+
size_t size)
11+
{
12+
/* For the purpose of the "mock" in tests, set the forbidden
13+
* address range to 0x0001000 - 0x0001FFF
14+
*/
15+
if (((uint32_t) address >= 0x0001000 && (uint32_t) address <= 0x0001FFF)
16+
|| ((uint32_t) address + size >= 0x0001000 && (uint32_t) address + size <= 0x0001FFF)) {
17+
return SUIT_PLAT_ERR_ACCESS;
18+
}
19+
20+
return SUIT_PLAT_SUCCESS;
21+
}
22+
23+
suit_plat_err_t suit_validator_validate_update_candidate_location(const uint8_t *address,
24+
size_t size)
25+
{
26+
return validate_candidate_location_common((uintptr_t) address, size);
27+
}
28+
29+
suit_plat_err_t suit_validator_validate_cache_pool_location(const uint8_t *address,
30+
size_t size)
31+
{
32+
return validate_candidate_location_common((uintptr_t) address, size);
33+
}

tests/subsys/suit/orchestrator/orchestrator_sdfw/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ CONFIG_SUIT=y
1111
CONFIG_SUIT_CRYPTO=y
1212
CONFIG_SUIT_MCI=y
1313
CONFIG_SUIT_MCI_IMPL_CUSTOM=y
14+
CONFIG_SUIT_VALIDATOR=y
15+
CONFIG_SUIT_VALIDATOR_IMPL_CUSTOM=y
1416
CONFIG_SUIT_METADATA=y
1517
CONFIG_SUIT_ORCHESTRATOR=y
1618
CONFIG_SUIT_PROCESSOR=y

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,58 @@ ZTEST(orchestrator_update_tests, test_seq_cand_varification_install)
562562
/* ... and the candidate availability flag is cleared */
563563
assert_post_install_state();
564564
}
565+
566+
ZTEST(orchestrator_update_tests, test_invalid_update_candidate_address)
567+
{
568+
/* GIVEN update candidate with invalid address... */
569+
setup_update_candidate((uint8_t *) 0x00000FF0, 0x50);
570+
/* ... and suit orchestrator is initialized... */
571+
zassert_equal(0, suit_orchestrator_init(), "Orchestrator not initialized");
572+
/* ... and the execution mode is set to install mode */
573+
zassert_equal(EXECUTION_MODE_INSTALL, suit_execution_mode_get(),
574+
"Unexpected execution mode before test execution");
575+
576+
/* WHEN orchestrator is launched */
577+
int err = suit_orchestrator_entry();
578+
579+
/* THEN orchestrator returns error code... */
580+
zassert_equal(-EACCES, err, "Unexpected error code");
581+
/* ... and the candidate availability flag is cleared */
582+
assert_post_install_state();
583+
}
584+
585+
ZTEST(orchestrator_update_tests, test_invalid_dfu_partition_address)
586+
{
587+
/* GIVEN update candidate with valid address, cache partition with invalid address... */
588+
suit_plat_mreg_t update_candidate[2] = {
589+
{
590+
.mem = manifest_valid_buf,
591+
.size = manifest_valid_len,
592+
},
593+
{
594+
.mem = (uint8_t *) 0x00000FF0,
595+
.size = 0x50,
596+
}
597+
};
598+
599+
setup_erased_flash();
600+
601+
int err = suit_storage_update_cand_set(update_candidate, ARRAY_SIZE(update_candidate));
602+
603+
zassert_equal(SUIT_PLAT_SUCCESS, err,
604+
"Unable to set update candidate before test execution");
605+
606+
/* ... and suit orchestrator is initialized... */
607+
zassert_equal(0, suit_orchestrator_init(), "Orchestrator not initialized");
608+
/* ... and the execution mode is set to install mode */
609+
zassert_equal(EXECUTION_MODE_INSTALL, suit_execution_mode_get(),
610+
"Unexpected execution mode before test execution");
611+
612+
/* WHEN orchestrator is launched */
613+
err = suit_orchestrator_entry();
614+
615+
/* THEN orchestrator returns error code... */
616+
zassert_equal(-EACCES, err, "Unexpected error code");
617+
/* ... and the candidate availability flag is cleared */
618+
assert_post_install_state();
619+
}

tests/subsys/suit/orchestrator/orchestrator_sdfw_nrf54h20/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ CONFIG_SUIT=y
1111
CONFIG_SUIT_CRYPTO=y
1212
CONFIG_SUIT_MCI=y
1313
CONFIG_SUIT_MCI_IMPL_CUSTOM=y
14+
CONFIG_SUIT_VALIDATOR=y
15+
CONFIG_SUIT_VALIDATOR_IMPL_CUSTOM=y
1416
CONFIG_SUIT_METADATA=y
1517
CONFIG_SUIT_ORCHESTRATOR=y
1618
CONFIG_SUIT_PROCESSOR=y

0 commit comments

Comments
 (0)