Skip to content

Commit

Permalink
tests: Enable IPUC in write directive tests
Browse files Browse the repository at this point in the history
Enable IPUC in SUIT write directive tests.

Signed-off-by: Sylwester Konczyk <[email protected]>
  • Loading branch information
SylwesterKonczyk authored and rlubos committed Sep 17, 2024
1 parent 7bfc2f5 commit e0f30d5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/subsys/suit/write/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Include and define MOCK_* Kconfigs
rsource "../mocks/Kconfig"

source "Kconfig.zephyr"
3 changes: 3 additions & 0 deletions tests/subsys/suit/write/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ CONFIG_ZCBOR_CANONICAL=y

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y

CONFIG_SUIT_IPUC=y
CONFIG_MOCK_SDFW_ARBITER=y
50 changes: 49 additions & 1 deletion tests/subsys/suit/write/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,29 @@
#include <suit_types.h>
#include <suit_memptr_storage.h>
#include <suit_platform_internal.h>
#include <suit_plat_ipuc.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/storage/flash_map.h>
#include <suit_plat_mem_util.h>
#include <suit_memory_layout.h>
#include <mocks.h>

#define DFU_PARTITION_OFFSET FIXED_PARTITION_OFFSET(dfu_partition)
#define FLASH_WRITE_ADDR (suit_plat_mem_nvm_ptr_get(DFU_PARTITION_OFFSET))
#define RAM_WRITE_ADDR ((uint8_t *)suit_memory_global_address_to_ram_address(0x2003EC00))

static uint8_t test_data[] = {0xDE, 0xAD, 0xBE, 0xEF};

ZTEST_SUITE(write_tests, NULL, NULL, NULL, NULL, NULL);
static void test_before(void *data)
{
/* Reset mocks */
mocks_reset();

/* Reset common FFF internal structures */
FFF_RESET_HISTORY();
}

ZTEST_SUITE(write_tests, NULL, NULL, test_before, NULL, NULL);

ZTEST(write_tests, test_write_to_flash_sink_OK)
{
Expand All @@ -42,9 +53,28 @@ ZTEST(write_tests, test_write_to_flash_sink_OK)

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

arbiter_mem_access_check_fake.return_val = ARBITER_STATUS_OK;
arbiter_mem_access_check_fake.call_count = 0;

struct zcbor_string *ipuc_component_id = suit_plat_find_sdfw_mirror_ipuc(1);

zassert_is_null(ipuc_component_id, "in-place updateable component found");

ret = suit_plat_ipuc_declare(dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "suit_plat_ipuc_declare failed - error %i", ret);

ipuc_component_id = suit_plat_find_sdfw_mirror_ipuc(1);
zassert_not_null(ipuc_component_id, "in-place updateable component not found");

ret = suit_plat_write(dst_handle, &source, NULL);
zassert_equal(ret, SUIT_SUCCESS, "suit_plat_write failed - error %i", ret);

ipuc_component_id = suit_plat_find_sdfw_mirror_ipuc(1);
zassert_is_null(ipuc_component_id, "in-place updateable component found");

zassert_equal(arbiter_mem_access_check_fake.call_count, 1,
"Incorrect number of arbiter_mem_access_check() calls");

ret = suit_plat_release_component_handle(dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "dst_handle release failed - error %i", ret);
zassert_mem_equal(FLASH_WRITE_ADDR, test_data, sizeof(test_data),
Expand Down Expand Up @@ -73,6 +103,9 @@ ZTEST(write_tests, test_write_to_ram_sink_OK)
ret = suit_plat_write(dst_handle, &source, NULL);
zassert_equal(ret, SUIT_SUCCESS, "suit_plat_write failed - error %i", ret);

zassert_equal(arbiter_mem_access_check_fake.call_count, 0,
"Incorrect number of arbiter_mem_access_check() calls");

ret = suit_plat_release_component_handle(dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "dst_handle release failed - error %i", ret);
zassert_mem_equal(RAM_WRITE_ADDR, test_data, sizeof(test_data),
Expand Down Expand Up @@ -101,6 +134,9 @@ ZTEST(write_tests, test_write_flash_sink_NOK_size_not_aligned)
ret = suit_plat_write(dst_handle, &source, NULL);
zassert_not_equal(ret, SUIT_SUCCESS, "suit_plat_write should have failed on erase");

zassert_equal(arbiter_mem_access_check_fake.call_count, 0,
"Incorrect number of arbiter_mem_access_check() calls");

ret = suit_plat_release_component_handle(dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "dst_handle release failed - error %i", ret);
}
Expand All @@ -114,6 +150,9 @@ ZTEST(write_tests, test_write_flash_sink_NOK_handle_released)

int ret = suit_plat_write(dst_handle, &source, NULL);

zassert_equal(arbiter_mem_access_check_fake.call_count, 0,
"Incorrect number of arbiter_mem_access_check() calls");

zassert_not_equal(ret, SUIT_SUCCESS, "suit_plat_write should have failed - invalid handle");
}

Expand All @@ -137,6 +176,9 @@ ZTEST(write_tests, test_write_to_flash_sink_NOK_source_null)
ret = suit_plat_write(dst_handle, NULL, NULL);
zassert_not_equal(ret, SUIT_SUCCESS, "suit_plat_write should have failed - source null");

zassert_equal(arbiter_mem_access_check_fake.call_count, 0,
"Incorrect number of arbiter_mem_access_check() calls");

ret = suit_plat_release_component_handle(dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "dst_handle release failed - error %i", ret);
}
Expand Down Expand Up @@ -164,6 +206,9 @@ ZTEST(write_tests, test_write_to_flash_sink_NOK_source_value_null)
zassert_not_equal(ret, SUIT_SUCCESS,
"suit_plat_write should have failed - source value null");

zassert_equal(arbiter_mem_access_check_fake.call_count, 0,
"Incorrect number of arbiter_mem_access_check() calls");

ret = suit_plat_release_component_handle(dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "dst_handle release failed - error %i", ret);
}
Expand All @@ -190,6 +235,9 @@ ZTEST(write_tests, test_write_to_flash_sink_NOK_source_len_0)
ret = suit_plat_write(dst_handle, &source, NULL);
zassert_not_equal(ret, SUIT_SUCCESS, "suit_plat_write should have failed - source len 0");

zassert_equal(arbiter_mem_access_check_fake.call_count, 0,
"Incorrect number of arbiter_mem_access_check() calls");

ret = suit_plat_release_component_handle(dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "dst_handle release failed - error %i", ret);
}

0 comments on commit e0f30d5

Please sign in to comment.