diff --git a/tests/subsys/suit/unit/mocks/CMakeLists.txt b/tests/subsys/suit/unit/mocks/CMakeLists.txt index 3c810748dd00..1ae2099fbe51 100644 --- a/tests/subsys/suit/unit/mocks/CMakeLists.txt +++ b/tests/subsys/suit/unit/mocks/CMakeLists.txt @@ -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) diff --git a/tests/subsys/suit/unit/mocks/Kconfig b/tests/subsys/suit/unit/mocks/Kconfig index 228a09d40920..e4de4e4f8162 100644 --- a/tests/subsys/suit/unit/mocks/Kconfig +++ b/tests/subsys/suit/unit/mocks/Kconfig @@ -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" diff --git a/tests/subsys/suit/unit/mocks/include/mock_suit_plat_ipuc.h b/tests/subsys/suit/unit/mocks/include/mock_suit_plat_ipuc.h new file mode 100644 index 000000000000..5878b7220f6b --- /dev/null +++ b/tests/subsys/suit/unit/mocks/include/mock_suit_plat_ipuc.h @@ -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 +#include +#include + +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__ */ diff --git a/tests/subsys/suit/unit/mocks/include/mocks.h b/tests/subsys/suit/unit/mocks/include/mocks.h index 7b29c1858e9f..b595546e0d31 100644 --- a/tests/subsys/suit/unit/mocks/include/mocks.h +++ b/tests/subsys/suit/unit/mocks/include/mocks.h @@ -54,6 +54,10 @@ #include #endif /* CONFIG_MOCK_SUIT_PLATFORM */ +#ifdef CONFIG_MOCK_SUIT_IPUC +#include +#endif /* CONFIG_MOCK_SUIT_IPUC */ + #ifdef CONFIG_MOCK_DIGEST_SINK #include #endif /* CONFIG_MOCK_DIGEST_SINK */ @@ -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 */ diff --git a/tests/subsys/suit/unit/suit_plat_override_image_size/prj.conf b/tests/subsys/suit/unit/suit_plat_override_image_size/prj.conf index 8af41aa236e9..7d335d49dbdb 100644 --- a/tests/subsys/suit/unit/suit_plat_override_image_size/prj.conf +++ b/tests/subsys/suit/unit/suit_plat_override_image_size/prj.conf @@ -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 diff --git a/tests/subsys/suit/unit/suit_plat_override_image_size/src/main.c b/tests/subsys/suit/unit/suit_plat_override_image_size/src/main.c index 5e775b2fef6a..c6468b31316c 100644 --- a/tests/subsys/suit/unit/suit_plat_override_image_size/src/main.c +++ b/tests/subsys/suit/unit/suit_plat_override_image_size/src/main.c @@ -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, @@ -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, @@ -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) @@ -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) @@ -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, @@ -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; @@ -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, @@ -227,11 +305,17 @@ 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) @@ -239,9 +323,15 @@ ZTEST(suit_platform_override_image_size_tests, test_suit_plat_override_image_siz /* 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"); }