Skip to content

Commit

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

Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
  • Loading branch information
tomchy authored and rlubos committed Sep 17, 2024
1 parent e0f30d5 commit c31c744
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 8 deletions.
5 changes: 5 additions & 0 deletions tests/subsys/suit/unit/mocks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ if (CONFIG_MOCK_SUIT_PLATFORM)
target_include_directories(testbinary PRIVATE ${SUIT_SUBSYS_DIR}/platform/include)
endif()

if (CONFIG_MOCK_SUIT_IPUC)
target_compile_options(test_interface INTERFACE -DCONFIG_SUIT_IPUC)
target_include_directories(testbinary PRIVATE ${SUIT_SUBSYS_DIR}/platform/include)
endif()

if (CONFIG_MOCK_DIGEST_SINK)
target_compile_options(test_interface INTERFACE -DCONFIG_SUIT_STREAM)
target_include_directories(testbinary PRIVATE ${SUIT_SUBSYS_DIR}/stream/stream_sinks/include)
Expand Down
3 changes: 3 additions & 0 deletions tests/subsys/suit/unit/mocks/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ config MOCK_SUIT_PLATFORM_INTERNAL
config MOCK_SUIT_PLATFORM
bool "Mock suit_plat_retrieve_manifest"

config MOCK_SUIT_IPUC
bool "Mock in-place updateable componenets"

config MOCK_DIGEST_SINK
bool "Mock stream sinks"

Expand Down
23 changes: 23 additions & 0 deletions tests/subsys/suit/unit/mocks/include/mock_suit_plat_ipuc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef MOCK_SUIT_PLAT_IPUC_H__
#define MOCK_SUIT_PLAT_IPUC_H__

#include <zephyr/fff.h>
#include <mock_globals.h>
#include <suit_plat_ipuc.h>

FAKE_VALUE_FUNC(int, suit_plat_ipuc_declare, suit_component_t);
FAKE_VALUE_FUNC(int, suit_plat_ipuc_revoke, suit_component_t);

static inline void mock_suit_plat_ipuc_reset(void)
{
RESET_FAKE(suit_plat_ipuc_declare);
RESET_FAKE(suit_plat_ipuc_revoke);
}

#endif /* MOCK_SUIT_PLAT_IPUC_H__ */
8 changes: 8 additions & 0 deletions tests/subsys/suit/unit/mocks/include/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#include <mock_suit_platform.h>
#endif /* CONFIG_MOCK_SUIT_PLATFORM */

#ifdef CONFIG_MOCK_SUIT_IPUC
#include <mock_suit_plat_ipuc.h>
#endif /* CONFIG_MOCK_SUIT_IPUC */

#ifdef CONFIG_MOCK_DIGEST_SINK
#include <mock_digest_sink.h>
#endif /* CONFIG_MOCK_DIGEST_SINK */
Expand Down Expand Up @@ -128,6 +132,10 @@ static inline void mocks_reset(void)
mock_suit_platform_reset();
#endif /* CONFIG_MOCK_SUIT_PLATFORM */

#ifdef CONFIG_MOCK_SUIT_IPUC
mock_suit_plat_ipuc_reset();
#endif /* CONFIG_MOCK_SUIT_IPUC */

#ifdef CONFIG_MOCK_DIGEST_SINK
mock_digest_sink_reset();
#endif /* CONFIG_MOCK_DIGEST_SINK */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ CONFIG_MOCK_SUIT_UTILS=y
CONFIG_MOCK_SUIT_MEMPTR_STORAGE=y
CONFIG_MOCK_SUIT_PLAT_DECODE_UTIL=y
CONFIG_MOCK_SUIT_LOG=y
CONFIG_MOCK_SUIT_IPUC=y
106 changes: 98 additions & 8 deletions tests/subsys/suit/unit/suit_plat_override_image_size/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_siz

zassert_equal(SUIT_SUCCESS, err, "Failed to override image size: %d", err);

/* THEN memptr_storage size should be updated to given value */
/* THEN memptr_storage size should be updated to given value... */
expected_call_count = 2;
expected_size = TEST_FAKE_SIZE;
zassert_equal(suit_memptr_storage_ptr_store_fake.call_count, expected_call_count,
Expand All @@ -126,6 +126,54 @@ ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_siz
zassert_equal(suit_memptr_storage_ptr_store_fake.arg2_history[1], expected_size,
"Wrong size: %d instead of %d",
suit_memptr_storage_ptr_store_fake.arg2_history[1], expected_size);

/* ... and IPUC component should be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 1,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_revoke_fake.arg0_history[0], component,
"Wrong component handle: %d instead of %d",
suit_plat_ipuc_revoke_fake.arg0_history[0], component);
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");
}

ZTEST(suit_platform_override_image_size_tests, test_suit_override_size_and_declare_ipuc)
{
/* GIVEN a MEM-type component */
/* WHEN a component handle is created (in test setup step) */
/* THEN memptr_storage size should be set to 0 */
int expected_call_count = 1;
size_t expected_size = 0;

zassert_equal(suit_memptr_storage_ptr_store_fake.call_count, expected_call_count,
"Wrong initial size store call count",
suit_memptr_storage_ptr_store_fake.call_count, expected_call_count);
zassert_equal(suit_memptr_storage_ptr_store_fake.arg2_history[0], expected_size,
"Wrong initial size: %d instead of %d",
suit_memptr_storage_ptr_store_fake.arg2_history[0], expected_size);

/* WHEN size override is called */
int err = suit_plat_override_image_size(component, 0);

zassert_equal(SUIT_SUCCESS, err, "Failed to override image size: %d", err);

/* THEN memptr_storage size should be updated to given value... */
expected_call_count = 2;
zassert_equal(suit_memptr_storage_ptr_store_fake.call_count, expected_call_count,
"Wrong size store call count: %d instead of %d",
suit_memptr_storage_ptr_store_fake.call_count, expected_call_count);
zassert_equal(suit_memptr_storage_ptr_store_fake.arg2_history[1], expected_size,
"Wrong size: %d instead of %d",
suit_memptr_storage_ptr_store_fake.arg2_history[1], expected_size);

/* ... and IPUC component should be revoked */
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 1,
"Incorrect number of suit_plat_ipuc_declare() calls");
zassert_equal(suit_plat_ipuc_declare_fake.arg0_history[0], component,
"Wrong component handle: %d instead of %d",
suit_plat_ipuc_declare_fake.arg0_history[0], component);
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
}

ZTEST(suit_platform_override_image_size_tests,
Expand All @@ -139,11 +187,17 @@ ZTEST(suit_platform_override_image_size_tests,
/* WHEN size override is called */
int err = suit_plat_override_image_size(component, TEST_FAKE_SIZE);

/* THEN appropriate error code is returned */
/* THEN appropriate error code is returned... */
int expected_error = SUIT_ERR_DECODING;

zassert_equal(expected_error, err, "Unexpected error code: %d instead of %d", err,
expected_error);

/* ... and IPUC component should not be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");
}

ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_size_fail_get)
Expand All @@ -155,11 +209,17 @@ ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_siz

/* WHEN size override is called */
int err = suit_plat_override_image_size(component, TEST_FAKE_SIZE);
/* THEN appropriate error code is returned */
/* THEN appropriate error code is returned... */
int expected_error = SUIT_ERR_CRASH;

zassert_equal(expected_error, err, "Unexpected error code: %d instead of %d", err,
expected_error);

/* ... and IPUC component should not be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");
}

ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_size_fail_store)
Expand All @@ -170,11 +230,17 @@ ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_siz
suit_memptr_storage_ptr_store_fake_unallocated_record;
/* WHEN size override is called */
int err = suit_plat_override_image_size(component, TEST_FAKE_SIZE);
/* THEN appropriate error code is returned */
/* THEN appropriate error code is returned... */
int expected_error = SUIT_ERR_CRASH;

zassert_equal(expected_error, err, "Unexpected error code: %d instead of %d", err,
expected_error);

/* ... and IPUC component should not be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");
}

ZTEST(suit_platform_override_image_size_tests,
Expand All @@ -186,12 +252,18 @@ ZTEST(suit_platform_override_image_size_tests,

/* WHEN size override is called */
int err = suit_plat_override_image_size(component, TEST_FAKE_SIZE);
/* THEN appropriate error code is returned */
/* THEN appropriate error code is returned... */
int expected_error = SUIT_ERR_UNSUPPORTED_COMPONENT_ID;

zassert_equal(expected_error, err, "Unexpected error code: %d instead of %d", err,
expected_error);

/* ... and IPUC component should not be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");

/* Cleanup: create component to satisfy test_after */
suit_plat_decode_component_type_fake.custom_fake =
suit_plat_decode_component_type_fake_mem_ok;
Expand All @@ -211,11 +283,17 @@ ZTEST(suit_platform_override_image_size_tests,

/* WHEN size override is called */
int err = suit_plat_override_image_size(component, TEST_FAKE_SIZE);
/* THEN appropriate error code is returned */
/* THEN appropriate error code is returned... */
int expected_error = SUIT_ERR_UNSUPPORTED_COMMAND;

zassert_equal(expected_error, err, "Unexpected error code: %d instead of %d", err,
expected_error);

/* ... and IPUC component should not be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");
}

ZTEST(suit_platform_override_image_size_tests,
Expand All @@ -227,21 +305,33 @@ ZTEST(suit_platform_override_image_size_tests,
suit_plat_decode_address_size_fake.return_val = SUIT_PLAT_ERR_CBOR_DECODING;
/* WHEN size override is called */
int err = suit_plat_override_image_size(component, TEST_FAKE_SIZE);
/* THEN appropriate error code is returned */
/* THEN appropriate error code is returned... */
int expected_error = SUIT_ERR_UNSUPPORTED_COMPONENT_ID;

zassert_equal(expected_error, err, "Unexpected error code: %d instead of %d", err,
expected_error);

/* ... and IPUC component should not be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");
}

ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_size_exceeding_size)
{
/* GIVEN a MEM-type component (created in test setup step)*/
/* WHEN size override is called with size exceeding the boundaries */
int err = suit_plat_override_image_size(component, TEST_FAKE_SIZE + 1);
/* THEN appropriate error code is returned */
/* THEN appropriate error code is returned... */
int expected_error = SUIT_ERR_UNSUPPORTED_PARAMETER;

zassert_equal(expected_error, err, "Unexpected error code: %d instead of %d", err,
expected_error);

/* ... and IPUC component should not be revoked */
zassert_equal(suit_plat_ipuc_revoke_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_revoke() calls");
zassert_equal(suit_plat_ipuc_declare_fake.call_count, 0,
"Incorrect number of suit_plat_ipuc_declare() calls");
}

0 comments on commit c31c744

Please sign in to comment.