Skip to content

Commit

Permalink
suit: Aligned tests after adding validator
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ahasztag committed Jul 4, 2024
1 parent 9fece3a commit e359632
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/subsys/suit/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#

add_subdirectory(mci_test)
add_subdirectory(validator_test)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/include)

if (CONFIG_MBEDTLS)
Expand Down
12 changes: 12 additions & 0 deletions tests/subsys/suit/common/validator_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

if (CONFIG_SUIT_VALIDATOR_IMPL_CUSTOM)
zephyr_library_named(validator_test)
zephyr_library_sources(validator_test.c)
zephyr_library_link_libraries(suit_validator)

target_link_libraries(app PUBLIC validator_test)
endif()
34 changes: 34 additions & 0 deletions tests/subsys/suit/common/validator_test/validator_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <suit_validator.h>

static suit_plat_err_t validate_candidate_location_common(uintptr_t address,
size_t size)
{

/* For the purpose of the "mock" in tests, set the forbidden
address range to 0x0001000 - 0x0001FFF */

Check warning on line 14 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BLOCK_COMMENT_STYLE

tests/subsys/suit/common/validator_test/validator_test.c:14 Block comments use * on subsequent lines

Check warning on line 14 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BLOCK_COMMENT_STYLE

tests/subsys/suit/common/validator_test/validator_test.c:14 Block comments use a trailing */ on a separate line
if(((uint32_t) address >= 0x0001000 && (uint32_t) address <= 0x0001FFF)

Check failure on line 15 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

tests/subsys/suit/common/validator_test/validator_test.c:15 that open brace { should be on the previous line

Check failure on line 15 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

tests/subsys/suit/common/validator_test/validator_test.c:15 space required before the open parenthesis '('
|| ((uint32_t) address + size >= 0x0001000 && (uint32_t) address + size <= 0x0001FFF))
{
return SUIT_PLAT_ERR_ACCESS;
}

return SUIT_PLAT_SUCCESS;
}

suit_plat_err_t suit_validator_validate_update_candidate_location(const uint8_t *address,
size_t size)
{
return validate_candidate_location_common((uintptr_t) address, size);

Check failure on line 27 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

tests/subsys/suit/common/validator_test/validator_test.c:27 code indent should use tabs where possible

Check warning on line 27 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

tests/subsys/suit/common/validator_test/validator_test.c:27 please, no space before tabs

Check warning on line 27 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

tests/subsys/suit/common/validator_test/validator_test.c:27 please, no spaces at the start of a line
}

suit_plat_err_t suit_validator_validate_dfu_partition_location(const uint8_t *address,
size_t size)
{
return validate_candidate_location_common((uintptr_t) address, size);

Check failure on line 33 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

tests/subsys/suit/common/validator_test/validator_test.c:33 code indent should use tabs where possible

Check warning on line 33 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACE_BEFORE_TAB

tests/subsys/suit/common/validator_test/validator_test.c:33 please, no space before tabs

Check warning on line 33 in tests/subsys/suit/common/validator_test/validator_test.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

tests/subsys/suit/common/validator_test/validator_test.c:33 please, no spaces at the start of a line
}
2 changes: 2 additions & 0 deletions tests/subsys/suit/orchestrator/orchestrator_sdfw/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CONFIG_SUIT=y
CONFIG_SUIT_CRYPTO=y
CONFIG_SUIT_MCI=y
CONFIG_SUIT_MCI_IMPL_CUSTOM=y
CONFIG_SUIT_VALIDATOR=y
CONFIG_SUIT_VALIDATOR_IMPL_CUSTOM=y
CONFIG_SUIT_METADATA=y
CONFIG_SUIT_ORCHESTRATOR=y
CONFIG_SUIT_PROCESSOR=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,58 @@ ZTEST(orchestrator_update_tests, test_seq_cand_varification_install)
/* ... and the candidate availability flag is cleared */
assert_post_install_state();
}

ZTEST(orchestrator_update_tests, test_invalid_update_candidate_address)
{
/* GIVEN update candidate with invalid address... */
setup_update_candidate((uint8_t *) 0x00000FF0, 0x50);
/* ... and suit orchestrator is initialized... */
zassert_equal(0, suit_orchestrator_init(), "Orchestrator not initialized");
/* ... and the execution mode is set to install mode */
zassert_equal(EXECUTION_MODE_INSTALL, suit_execution_mode_get(),
"Unexpected execution mode before test execution");

/* WHEN orchestrator is launched */
int err = suit_orchestrator_entry();

/* THEN orchestrator returns error code... */
zassert_equal(-EACCES, err, "Unexpected error code");
/* ... and the candidate availability flag is cleared */
assert_post_install_state();
}

ZTEST(orchestrator_update_tests, test_invalid_dfu_partition_address)
{
/* GIVEN update candidate with valid address, cache partition with invalid address... */
suit_plat_mreg_t update_candidate[2] = {
{
.mem = manifest_valid_buf,
.size = manifest_valid_len,
},
{
.mem = (uint8_t *) 0x00000FF0,
.size = 0x50,
}
};

setup_erased_flash();

int err = suit_storage_update_cand_set(update_candidate, ARRAY_SIZE(update_candidate));

zassert_equal(SUIT_PLAT_SUCCESS, err,
"Unable to set update candidate before test execution");

/* ... and suit orchestrator is initialized... */
zassert_equal(0, suit_orchestrator_init(), "Orchestrator not initialized");
/* ... and the execution mode is set to install mode */
zassert_equal(EXECUTION_MODE_INSTALL, suit_execution_mode_get(),
"Unexpected execution mode before test execution");

/* WHEN orchestrator is launched */
err = suit_orchestrator_entry();

/* THEN orchestrator returns error code... */
zassert_equal(-EACCES, err, "Unexpected error code");
/* ... and the candidate availability flag is cleared */
assert_post_install_state();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CONFIG_SUIT=y
CONFIG_SUIT_CRYPTO=y
CONFIG_SUIT_MCI=y
CONFIG_SUIT_MCI_IMPL_CUSTOM=y
CONFIG_SUIT_VALIDATOR=y
CONFIG_SUIT_VALIDATOR_IMPL_CUSTOM=y
CONFIG_SUIT_METADATA=y
CONFIG_SUIT_ORCHESTRATOR=y
CONFIG_SUIT_PROCESSOR=y
Expand Down

0 comments on commit e359632

Please sign in to comment.