diff --git a/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/prj.conf b/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/prj.conf index ef7b5abe82d7..338eac6f2f43 100644 --- a/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/prj.conf +++ b/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/prj.conf @@ -10,3 +10,4 @@ CONFIG_MOCK_DFU_CACHE_STREAMER=y CONFIG_MOCK_DFU_CACHE_SINK=y CONFIG_MOCK_FETCH_SOURCE_STREAMER=y CONFIG_MOCK_GENERIC_ADDRESS_STREAMER=y +CONFIG_MOCK_SUIT_UTILS=y diff --git a/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/src/main.c b/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/src/main.c index 0281ba768adf..9000d2e5e021 100644 --- a/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/src/main.c +++ b/tests/subsys/suit/unit/app_specific/suit_plat_fetch_app/src/main.c @@ -11,6 +11,39 @@ #define TEST_COMPONENT_HANDLE ((suit_component_t)0x123) +/* clang-format off */ +static const uint8_t valid_manifest_component[] = { + 0x82, /* array: 2 elements */ + 0x4c, /* byte string: 12 bytes */ + 0x6b, /* string: 11 characters */ + 'I', 'N', 'S', 'T', 'L', 'D', '_', 'M', 'F', 'S', 'T', + 0x50, /* byte string: 16 bytes */ + /* RFC4122 uuid5(nordic_vid, 'test_sample_root') */ + 0x97, 0x05, 0x48, 0x23, 0x4c, 0x3d, 0x59, 0xa1, + 0x89, 0x86, 0xa5, 0x46, 0x60, 0xa1, 0x4b, 0x0a, + +}; +/* clang-format on */ + +static struct zcbor_string valid_manifest_component_id = { + .value = valid_manifest_component, + .len = sizeof(valid_manifest_component), +}; + +static suit_plat_err_t suit_dfu_cache_sink_get_dummy(struct stream_sink *sink, + uint8_t cache_partition_id, const uint8_t *uri, + size_t uri_size, bool write_enabled) +{ + struct stream_sink dummy_sink = {0}; + + zassert_not_equal(sink, NULL, + "The API must provide a valid pointer, to fill sink structure"); + zassert_equal(write_enabled, true, "Dry-run flag enabled in regular scenario"); + *sink = dummy_sink; + + return SUIT_PLAT_SUCCESS; +} + static void test_before(void *data) { /* Reset mocks */ @@ -24,11 +57,11 @@ ZTEST_SUITE(suit_platform_app_fetch_tests, NULL, NULL, test_before, NULL, NULL); ZTEST(suit_platform_app_fetch_tests, test_fetch_type_supported) { - zassert_true( + zassert_false( suit_plat_fetch_domain_specific_is_type_supported(SUIT_COMPONENT_TYPE_CAND_IMG), "suit_plat_fetch_domain_specific_is_type_supported returned false for supported " "type"); - zassert_true( + zassert_false( suit_plat_fetch_domain_specific_is_type_supported(SUIT_COMPONENT_TYPE_CAND_MFST), "suit_plat_fetch_domain_specific_is_type_supported returned false for supported " "type"); @@ -56,14 +89,14 @@ ZTEST(suit_platform_app_fetch_tests, test_fetch_type_supported) ZTEST(suit_platform_app_fetch_tests, test_fetch_integrated_type_supported) { - zassert_true(suit_plat_fetch_integrated_domain_specific_is_type_supported( - SUIT_COMPONENT_TYPE_CAND_IMG), - "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false " - "for supported type"); - zassert_true(suit_plat_fetch_integrated_domain_specific_is_type_supported( - SUIT_COMPONENT_TYPE_CAND_MFST), - "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false " - "for supported type"); + zassert_false(suit_plat_fetch_integrated_domain_specific_is_type_supported( + SUIT_COMPONENT_TYPE_CAND_IMG), + "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false " + "for supported type"); + zassert_false(suit_plat_fetch_integrated_domain_specific_is_type_supported( + SUIT_COMPONENT_TYPE_CAND_MFST), + "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false " + "for supported type"); zassert_false(suit_plat_fetch_integrated_domain_specific_is_type_supported( SUIT_COMPONENT_TYPE_CACHE_POOL), @@ -89,200 +122,67 @@ ZTEST(suit_platform_app_fetch_tests, test_fetch_integrated_type_supported) ZTEST(suit_platform_app_fetch_tests, test_fetch_unsupported_component_type) { - struct stream_sink dummy_sink = {0}; struct zcbor_string dummy_uri = {.value = (const uint8_t *)"test", .len = 4}; zassert_equal(suit_plat_fetch_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_UNSUPPORTED, &dummy_sink, - &dummy_uri), + SUIT_COMPONENT_TYPE_UNSUPPORTED, &dummy_uri, + &valid_manifest_component_id, NULL), SUIT_ERR_UNSUPPORTED_COMPONENT_ID, "Unsupported component type returned incorrect error code"); } -ZTEST(suit_platform_app_fetch_tests, test_fetch_dfu_cache_streamer_fail) -{ - struct stream_sink dummy_sink = {0}; - struct zcbor_string dummy_uri = {.value = (const uint8_t *)"test", .len = 4}; - - suit_dfu_cache_streamer_stream_fake.return_val = SUIT_PLAT_ERR_IO; - - zassert_equal(suit_plat_fetch_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_CAND_IMG, &dummy_sink, - &dummy_uri), - SUIT_SUCCESS, "Failed when URI not found in cache (should succeed)"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.call_count, 1, - "Incorrect number of suit_dfu_cache_streamer_stream() calls"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.arg0_val, dummy_uri.value, - "Incorrect value streamer argument"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.arg1_val, dummy_uri.len, - "Incorrect value of streamer argument"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.arg2_val, &dummy_sink, - "Incorrect value of streamer argument"); - - zassert_equal(suit_dfu_cache_sink_commit_fake.call_count, 0, - "Incorrect number of suit_dfu_cache_sink_commit() calls"); - zassert_equal(suit_fetch_source_stream_fake.call_count, 0, - "Incorrect number of suit_fetch_source_stream() calls"); -} - -ZTEST(suit_platform_app_fetch_tests, test_fetch_dfu_cache_streamer_success) -{ - struct stream_sink dummy_sink = {0}; - struct zcbor_string dummy_uri = {.value = (const uint8_t *)"test", .len = 4}; - - suit_component_type_t types[] = {SUIT_COMPONENT_TYPE_CAND_IMG, - SUIT_COMPONENT_TYPE_CAND_MFST}; - - for (size_t i = 0; i < ARRAY_SIZE(types); i++) { - mocks_reset(); - FFF_RESET_HISTORY(); - - suit_dfu_cache_streamer_stream_fake.return_val = SUIT_PLAT_SUCCESS; - - zassert_equal(suit_plat_fetch_domain_specific(TEST_COMPONENT_HANDLE, types[i], - &dummy_sink, &dummy_uri), - SUIT_SUCCESS, "suit_plat_fetch_domain_specific() failed"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.call_count, 1, - "Incorrect number of suit_dfu_cache_streamer_stream() calls"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.arg0_val, dummy_uri.value, - "Incorrect value streamer argument"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.arg1_val, dummy_uri.len, - "Incorrect value of streamer argument"); - zassert_equal(suit_dfu_cache_streamer_stream_fake.arg2_val, &dummy_sink, - "Incorrect value of streamer argument"); - - zassert_equal(suit_dfu_cache_sink_commit_fake.call_count, 0, - "Incorrect number of suit_dfu_cache_sink_commit() calls"); - zassert_equal(suit_fetch_source_stream_fake.call_count, 0, - "Incorrect number of suit_fetch_source_stream() calls"); - } -} - ZTEST(suit_platform_app_fetch_tests, test_fetch_fetch_source_streamer_fail) { - struct stream_sink dummy_sink = {0}; struct zcbor_string dummy_uri = {.value = (const uint8_t *)"test", .len = 4}; + /* Pretend that component handle is valid. */ + suit_plat_component_id_get_fake.return_val = SUIT_SUCCESS; + suit_plat_decode_component_number_fake.return_val = SUIT_PLAT_SUCCESS; + suit_dfu_cache_sink_get_fake.custom_fake = suit_dfu_cache_sink_get_dummy; suit_fetch_source_stream_fake.return_val = SUIT_PLAT_ERR_IO; zassert_equal(suit_plat_fetch_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_CACHE_POOL, &dummy_sink, - &dummy_uri), - SUIT_SUCCESS, "Failed when unable to fetch payload (should succeed)"); + SUIT_COMPONENT_TYPE_CACHE_POOL, &dummy_uri, + &valid_manifest_component_id, NULL), + SUIT_SUCCESS, "Failed when URI not found in cache (should succeed)"); zassert_equal(suit_fetch_source_stream_fake.call_count, 1, "Incorrect number of suit_fetch_source_stream() calls"); zassert_equal(suit_fetch_source_stream_fake.arg0_val, dummy_uri.value, "Incorrect value streamer argument"); zassert_equal(suit_fetch_source_stream_fake.arg1_val, dummy_uri.len, "Incorrect value of streamer argument"); - zassert_equal(suit_fetch_source_stream_fake.arg2_val, &dummy_sink, - "Incorrect value of streamer argument"); zassert_equal(suit_dfu_cache_sink_commit_fake.call_count, 0, "Incorrect number of suit_dfu_cache_sink_commit() calls"); zassert_equal(suit_dfu_cache_streamer_stream_fake.call_count, 0, - "Incorrect number of suit_fetch_source_stream() calls"); + "Incorrect number of suit_dfu_cache_streamer_stream() calls"); } -ZTEST(suit_platform_app_fetch_tests, test_fetch_cache_pool_type) +ZTEST(suit_platform_app_fetch_tests, test_fetch_fetch_source_streamer_success) { - uint8_t dummy_ctx = 0; - struct stream_sink dummy_sink = {.ctx = &dummy_ctx}; struct zcbor_string dummy_uri = {.value = (const uint8_t *)"test", .len = 4}; - suit_fetch_source_stream_fake.return_val = SUIT_PLAT_SUCCESS; - - zassert_equal(suit_plat_fetch_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_CACHE_POOL, &dummy_sink, - &dummy_uri), - SUIT_SUCCESS, "Failed to return correct error code"); - zassert_equal(suit_fetch_source_stream_fake.call_count, 1, - "Incorrect number of suit_fetch_source_stream() calls"); - zassert_equal(suit_fetch_source_stream_fake.arg0_val, dummy_uri.value, - "Incorrect value streamer argument"); - zassert_equal(suit_fetch_source_stream_fake.arg1_val, dummy_uri.len, - "Incorrect value of streamer argument"); - zassert_equal(suit_fetch_source_stream_fake.arg2_val, &dummy_sink, - "Incorrect value of streamer argument"); - - zassert_equal(suit_dfu_cache_sink_commit_fake.call_count, 1, - "Incorrect number of suit_dfu_cache_sink_commit() calls"); - zassert_equal(suit_dfu_cache_sink_commit_fake.arg0_val, &dummy_ctx, - "Incorrect value suit_dfu_cache_sink_commit argument"); - - zassert_equal(suit_dfu_cache_streamer_stream_fake.call_count, 0, - "Incorrect number of suit_fetch_source_stream() calls"); -} - -ZTEST(suit_platform_app_fetch_tests, test_fetch_mem_type) -{ - uint8_t dummy_ctx = 0; - struct stream_sink dummy_sink = {.ctx = &dummy_ctx}; - struct zcbor_string dummy_uri = {.value = (const uint8_t *)"test", .len = 4}; + suit_dfu_cache_streamer_stream_fake.return_val = SUIT_PLAT_SUCCESS; + /* Pretend that component handle is valid. */ + suit_plat_component_id_get_fake.return_val = SUIT_SUCCESS; + suit_plat_decode_component_number_fake.return_val = SUIT_PLAT_SUCCESS; + suit_dfu_cache_sink_get_fake.custom_fake = suit_dfu_cache_sink_get_dummy; suit_fetch_source_stream_fake.return_val = SUIT_PLAT_SUCCESS; zassert_equal(suit_plat_fetch_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_MEM, &dummy_sink, - &dummy_uri), - SUIT_SUCCESS, "Failed to return correct error code"); + SUIT_COMPONENT_TYPE_CACHE_POOL, &dummy_uri, + &valid_manifest_component_id, NULL), + SUIT_SUCCESS, "suit_plat_fetch_domain_specific() failed"); zassert_equal(suit_fetch_source_stream_fake.call_count, 1, "Incorrect number of suit_fetch_source_stream() calls"); zassert_equal(suit_fetch_source_stream_fake.arg0_val, dummy_uri.value, "Incorrect value streamer argument"); zassert_equal(suit_fetch_source_stream_fake.arg1_val, dummy_uri.len, "Incorrect value of streamer argument"); - zassert_equal(suit_fetch_source_stream_fake.arg2_val, &dummy_sink, - "Incorrect value of streamer argument"); - - zassert_equal(suit_dfu_cache_sink_commit_fake.call_count, 0, + zassert_equal(suit_dfu_cache_sink_commit_fake.call_count, 1, "Incorrect number of suit_dfu_cache_sink_commit() calls"); zassert_equal(suit_dfu_cache_streamer_stream_fake.call_count, 0, - "Incorrect number of suit_fetch_source_stream() calls"); -} - -ZTEST(suit_platform_app_fetch_tests, test_fetch_integrated_domain_specific_no_payload) -{ - struct stream_sink dummy_sink = {0}; - - zassert_equal(suit_plat_fetch_integrated_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_CACHE_POOL, - &dummy_sink, NULL), - SUIT_ERR_UNAVAILABLE_PAYLOAD, - "suit_plat_fetch_integrated_domain_specific did not fail"); -} - -ZTEST(suit_platform_app_fetch_tests, test_fetch_integrated_domain_specific_streamer_fail) -{ - struct stream_sink dummy_sink = {0}; - uint8_t dummy_payload[] = {0, 1, 2, 3, 4}; - struct zcbor_string payload = { - .value = dummy_payload, - .len = sizeof(dummy_payload), - }; - - suit_generic_address_streamer_stream_fake.return_val = SUIT_PLAT_ERR_NOT_FOUND; - - zassert_equal(suit_plat_fetch_integrated_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_CACHE_POOL, - &dummy_sink, &payload), - SUIT_ERR_CRASH, "suit_plat_fetch_integrated_domain_specific did not fail"); -} - -ZTEST(suit_platform_app_fetch_tests, test_fetch_integrated_domain_specific) -{ - struct stream_sink dummy_sink = {0}; - uint8_t dummy_payload[] = {0, 1, 2, 3, 4}; - struct zcbor_string payload = { - .value = dummy_payload, - .len = sizeof(dummy_payload), - }; - - suit_generic_address_streamer_stream_fake.return_val = SUIT_PLAT_SUCCESS; - - zassert_equal(suit_plat_fetch_integrated_domain_specific(TEST_COMPONENT_HANDLE, - SUIT_COMPONENT_TYPE_CACHE_POOL, - &dummy_sink, &payload), - SUIT_SUCCESS, "suit_plat_fetch_integrated_domain_specific ail"); + "Incorrect number of suit_dfu_cache_streamer_stream() calls"); } diff --git a/tests/subsys/suit/unit/mocks/CMakeLists.txt b/tests/subsys/suit/unit/mocks/CMakeLists.txt index b17d1c3ca037..8eb28f8e4f30 100644 --- a/tests/subsys/suit/unit/mocks/CMakeLists.txt +++ b/tests/subsys/suit/unit/mocks/CMakeLists.txt @@ -113,7 +113,7 @@ if (CONFIG_MOCK_DFU_CACHE_STREAMER) endif() if (CONFIG_MOCK_DFU_CACHE_SINK) - target_compile_options(test_interface INTERFACE -DCONFIG_SUIT_STREAM) + target_compile_options(test_interface INTERFACE -DCONFIG_SUIT_STREAM -DCONFIG_SUIT_STREAM_SINK_CACHE) target_include_directories(testbinary PRIVATE ${SUIT_SUBSYS_DIR}/stream/stream_sinks/include) endif()