1111
1212#define TEST_COMPONENT_HANDLE ((suit_component_t)0x123)
1313
14+ /* clang-format off */
15+ static const uint8_t valid_manifest_component [] = {
16+ 0x82 , /* array: 2 elements */
17+ 0x4c , /* byte string: 12 bytes */
18+ 0x6b , /* string: 11 characters */
19+ 'I' , 'N' , 'S' , 'T' , 'L' , 'D' , '_' , 'M' , 'F' , 'S' , 'T' ,
20+ 0x50 , /* byte string: 16 bytes */
21+ /* RFC4122 uuid5(nordic_vid, 'test_sample_root') */
22+ 0x97 , 0x05 , 0x48 , 0x23 , 0x4c , 0x3d , 0x59 , 0xa1 ,
23+ 0x89 , 0x86 , 0xa5 , 0x46 , 0x60 , 0xa1 , 0x4b , 0x0a ,
24+
25+ };
26+ /* clang-format on */
27+
28+ static struct zcbor_string valid_manifest_component_id = {
29+ .value = valid_manifest_component ,
30+ .len = sizeof (valid_manifest_component ),
31+ };
32+
33+ static suit_plat_err_t suit_dfu_cache_sink_get_dummy (struct stream_sink * sink ,
34+ uint8_t cache_partition_id , const uint8_t * uri ,
35+ size_t uri_size , bool write_enabled )
36+ {
37+ struct stream_sink dummy_sink = {0 };
38+
39+ zassert_not_equal (sink , NULL ,
40+ "The API must provide a valid pointer, to fill sink structure" );
41+ zassert_equal (write_enabled , true, "Dry-run flag enabled in regular scenario" );
42+ * sink = dummy_sink ;
43+
44+ return SUIT_PLAT_SUCCESS ;
45+ }
46+
1447static void test_before (void * data )
1548{
1649 /* Reset mocks */
@@ -24,11 +57,11 @@ ZTEST_SUITE(suit_platform_app_fetch_tests, NULL, NULL, test_before, NULL, NULL);
2457
2558ZTEST (suit_platform_app_fetch_tests , test_fetch_type_supported )
2659{
27- zassert_true (
60+ zassert_false (
2861 suit_plat_fetch_domain_specific_is_type_supported (SUIT_COMPONENT_TYPE_CAND_IMG ),
2962 "suit_plat_fetch_domain_specific_is_type_supported returned false for supported "
3063 "type" );
31- zassert_true (
64+ zassert_false (
3265 suit_plat_fetch_domain_specific_is_type_supported (SUIT_COMPONENT_TYPE_CAND_MFST ),
3366 "suit_plat_fetch_domain_specific_is_type_supported returned false for supported "
3467 "type" );
@@ -56,14 +89,14 @@ ZTEST(suit_platform_app_fetch_tests, test_fetch_type_supported)
5689
5790ZTEST (suit_platform_app_fetch_tests , test_fetch_integrated_type_supported )
5891{
59- zassert_true (suit_plat_fetch_integrated_domain_specific_is_type_supported (
60- SUIT_COMPONENT_TYPE_CAND_IMG ),
61- "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false "
62- "for supported type" );
63- zassert_true (suit_plat_fetch_integrated_domain_specific_is_type_supported (
64- SUIT_COMPONENT_TYPE_CAND_MFST ),
65- "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false "
66- "for supported type" );
92+ zassert_false (suit_plat_fetch_integrated_domain_specific_is_type_supported (
93+ SUIT_COMPONENT_TYPE_CAND_IMG ),
94+ "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false "
95+ "for supported type" );
96+ zassert_false (suit_plat_fetch_integrated_domain_specific_is_type_supported (
97+ SUIT_COMPONENT_TYPE_CAND_MFST ),
98+ "suit_plat_fetch_integrated_domain_specific_is_type_supported returned false "
99+ "for supported type" );
67100
68101 zassert_false (suit_plat_fetch_integrated_domain_specific_is_type_supported (
69102 SUIT_COMPONENT_TYPE_CACHE_POOL ),
@@ -89,200 +122,67 @@ ZTEST(suit_platform_app_fetch_tests, test_fetch_integrated_type_supported)
89122
90123ZTEST (suit_platform_app_fetch_tests , test_fetch_unsupported_component_type )
91124{
92- struct stream_sink dummy_sink = {0 };
93125 struct zcbor_string dummy_uri = {.value = (const uint8_t * )"test" , .len = 4 };
94126
95127 zassert_equal (suit_plat_fetch_domain_specific (TEST_COMPONENT_HANDLE ,
96- SUIT_COMPONENT_TYPE_UNSUPPORTED , & dummy_sink ,
97- & dummy_uri ),
128+ SUIT_COMPONENT_TYPE_UNSUPPORTED , & dummy_uri ,
129+ & valid_manifest_component_id , NULL ),
98130 SUIT_ERR_UNSUPPORTED_COMPONENT_ID ,
99131 "Unsupported component type returned incorrect error code" );
100132}
101133
102- ZTEST (suit_platform_app_fetch_tests , test_fetch_dfu_cache_streamer_fail )
103- {
104- struct stream_sink dummy_sink = {0 };
105- struct zcbor_string dummy_uri = {.value = (const uint8_t * )"test" , .len = 4 };
106-
107- suit_dfu_cache_streamer_stream_fake .return_val = SUIT_PLAT_ERR_IO ;
108-
109- zassert_equal (suit_plat_fetch_domain_specific (TEST_COMPONENT_HANDLE ,
110- SUIT_COMPONENT_TYPE_CAND_IMG , & dummy_sink ,
111- & dummy_uri ),
112- SUIT_SUCCESS , "Failed when URI not found in cache (should succeed)" );
113- zassert_equal (suit_dfu_cache_streamer_stream_fake .call_count , 1 ,
114- "Incorrect number of suit_dfu_cache_streamer_stream() calls" );
115- zassert_equal (suit_dfu_cache_streamer_stream_fake .arg0_val , dummy_uri .value ,
116- "Incorrect value streamer argument" );
117- zassert_equal (suit_dfu_cache_streamer_stream_fake .arg1_val , dummy_uri .len ,
118- "Incorrect value of streamer argument" );
119- zassert_equal (suit_dfu_cache_streamer_stream_fake .arg2_val , & dummy_sink ,
120- "Incorrect value of streamer argument" );
121-
122- zassert_equal (suit_dfu_cache_sink_commit_fake .call_count , 0 ,
123- "Incorrect number of suit_dfu_cache_sink_commit() calls" );
124- zassert_equal (suit_fetch_source_stream_fake .call_count , 0 ,
125- "Incorrect number of suit_fetch_source_stream() calls" );
126- }
127-
128- ZTEST (suit_platform_app_fetch_tests , test_fetch_dfu_cache_streamer_success )
129- {
130- struct stream_sink dummy_sink = {0 };
131- struct zcbor_string dummy_uri = {.value = (const uint8_t * )"test" , .len = 4 };
132-
133- suit_component_type_t types [] = {SUIT_COMPONENT_TYPE_CAND_IMG ,
134- SUIT_COMPONENT_TYPE_CAND_MFST };
135-
136- for (size_t i = 0 ; i < ARRAY_SIZE (types ); i ++ ) {
137- mocks_reset ();
138- FFF_RESET_HISTORY ();
139-
140- suit_dfu_cache_streamer_stream_fake .return_val = SUIT_PLAT_SUCCESS ;
141-
142- zassert_equal (suit_plat_fetch_domain_specific (TEST_COMPONENT_HANDLE , types [i ],
143- & dummy_sink , & dummy_uri ),
144- SUIT_SUCCESS , "suit_plat_fetch_domain_specific() failed" );
145- zassert_equal (suit_dfu_cache_streamer_stream_fake .call_count , 1 ,
146- "Incorrect number of suit_dfu_cache_streamer_stream() calls" );
147- zassert_equal (suit_dfu_cache_streamer_stream_fake .arg0_val , dummy_uri .value ,
148- "Incorrect value streamer argument" );
149- zassert_equal (suit_dfu_cache_streamer_stream_fake .arg1_val , dummy_uri .len ,
150- "Incorrect value of streamer argument" );
151- zassert_equal (suit_dfu_cache_streamer_stream_fake .arg2_val , & dummy_sink ,
152- "Incorrect value of streamer argument" );
153-
154- zassert_equal (suit_dfu_cache_sink_commit_fake .call_count , 0 ,
155- "Incorrect number of suit_dfu_cache_sink_commit() calls" );
156- zassert_equal (suit_fetch_source_stream_fake .call_count , 0 ,
157- "Incorrect number of suit_fetch_source_stream() calls" );
158- }
159- }
160-
161134ZTEST (suit_platform_app_fetch_tests , test_fetch_fetch_source_streamer_fail )
162135{
163- struct stream_sink dummy_sink = {0 };
164136 struct zcbor_string dummy_uri = {.value = (const uint8_t * )"test" , .len = 4 };
165137
138+ /* Pretend that component handle is valid. */
139+ suit_plat_component_id_get_fake .return_val = SUIT_SUCCESS ;
140+ suit_plat_decode_component_number_fake .return_val = SUIT_PLAT_SUCCESS ;
141+ suit_dfu_cache_sink_get_fake .custom_fake = suit_dfu_cache_sink_get_dummy ;
166142 suit_fetch_source_stream_fake .return_val = SUIT_PLAT_ERR_IO ;
167143
168144 zassert_equal (suit_plat_fetch_domain_specific (TEST_COMPONENT_HANDLE ,
169- SUIT_COMPONENT_TYPE_CACHE_POOL , & dummy_sink ,
170- & dummy_uri ),
171- SUIT_SUCCESS , "Failed when unable to fetch payload (should succeed)" );
145+ SUIT_COMPONENT_TYPE_CACHE_POOL , & dummy_uri ,
146+ & valid_manifest_component_id , NULL ),
147+ SUIT_SUCCESS , "Failed when URI not found in cache (should succeed)" );
172148 zassert_equal (suit_fetch_source_stream_fake .call_count , 1 ,
173149 "Incorrect number of suit_fetch_source_stream() calls" );
174150 zassert_equal (suit_fetch_source_stream_fake .arg0_val , dummy_uri .value ,
175151 "Incorrect value streamer argument" );
176152 zassert_equal (suit_fetch_source_stream_fake .arg1_val , dummy_uri .len ,
177153 "Incorrect value of streamer argument" );
178- zassert_equal (suit_fetch_source_stream_fake .arg2_val , & dummy_sink ,
179- "Incorrect value of streamer argument" );
180154
181155 zassert_equal (suit_dfu_cache_sink_commit_fake .call_count , 0 ,
182156 "Incorrect number of suit_dfu_cache_sink_commit() calls" );
183157 zassert_equal (suit_dfu_cache_streamer_stream_fake .call_count , 0 ,
184- "Incorrect number of suit_fetch_source_stream () calls" );
158+ "Incorrect number of suit_dfu_cache_streamer_stream () calls" );
185159}
186160
187- ZTEST (suit_platform_app_fetch_tests , test_fetch_cache_pool_type )
161+ ZTEST (suit_platform_app_fetch_tests , test_fetch_fetch_source_streamer_success )
188162{
189- uint8_t dummy_ctx = 0 ;
190- struct stream_sink dummy_sink = {.ctx = & dummy_ctx };
191163 struct zcbor_string dummy_uri = {.value = (const uint8_t * )"test" , .len = 4 };
192164
193- suit_fetch_source_stream_fake .return_val = SUIT_PLAT_SUCCESS ;
194-
195- zassert_equal (suit_plat_fetch_domain_specific (TEST_COMPONENT_HANDLE ,
196- SUIT_COMPONENT_TYPE_CACHE_POOL , & dummy_sink ,
197- & dummy_uri ),
198- SUIT_SUCCESS , "Failed to return correct error code" );
199- zassert_equal (suit_fetch_source_stream_fake .call_count , 1 ,
200- "Incorrect number of suit_fetch_source_stream() calls" );
201- zassert_equal (suit_fetch_source_stream_fake .arg0_val , dummy_uri .value ,
202- "Incorrect value streamer argument" );
203- zassert_equal (suit_fetch_source_stream_fake .arg1_val , dummy_uri .len ,
204- "Incorrect value of streamer argument" );
205- zassert_equal (suit_fetch_source_stream_fake .arg2_val , & dummy_sink ,
206- "Incorrect value of streamer argument" );
207-
208- zassert_equal (suit_dfu_cache_sink_commit_fake .call_count , 1 ,
209- "Incorrect number of suit_dfu_cache_sink_commit() calls" );
210- zassert_equal (suit_dfu_cache_sink_commit_fake .arg0_val , & dummy_ctx ,
211- "Incorrect value suit_dfu_cache_sink_commit argument" );
212-
213- zassert_equal (suit_dfu_cache_streamer_stream_fake .call_count , 0 ,
214- "Incorrect number of suit_fetch_source_stream() calls" );
215- }
216-
217- ZTEST (suit_platform_app_fetch_tests , test_fetch_mem_type )
218- {
219- uint8_t dummy_ctx = 0 ;
220- struct stream_sink dummy_sink = {.ctx = & dummy_ctx };
221- struct zcbor_string dummy_uri = {.value = (const uint8_t * )"test" , .len = 4 };
165+ suit_dfu_cache_streamer_stream_fake .return_val = SUIT_PLAT_SUCCESS ;
222166
167+ /* Pretend that component handle is valid. */
168+ suit_plat_component_id_get_fake .return_val = SUIT_SUCCESS ;
169+ suit_plat_decode_component_number_fake .return_val = SUIT_PLAT_SUCCESS ;
170+ suit_dfu_cache_sink_get_fake .custom_fake = suit_dfu_cache_sink_get_dummy ;
223171 suit_fetch_source_stream_fake .return_val = SUIT_PLAT_SUCCESS ;
224172
225173 zassert_equal (suit_plat_fetch_domain_specific (TEST_COMPONENT_HANDLE ,
226- SUIT_COMPONENT_TYPE_MEM , & dummy_sink ,
227- & dummy_uri ),
228- SUIT_SUCCESS , "Failed to return correct error code " );
174+ SUIT_COMPONENT_TYPE_CACHE_POOL , & dummy_uri ,
175+ & valid_manifest_component_id , NULL ),
176+ SUIT_SUCCESS , "suit_plat_fetch_domain_specific() failed " );
229177 zassert_equal (suit_fetch_source_stream_fake .call_count , 1 ,
230178 "Incorrect number of suit_fetch_source_stream() calls" );
231179 zassert_equal (suit_fetch_source_stream_fake .arg0_val , dummy_uri .value ,
232180 "Incorrect value streamer argument" );
233181 zassert_equal (suit_fetch_source_stream_fake .arg1_val , dummy_uri .len ,
234182 "Incorrect value of streamer argument" );
235- zassert_equal (suit_fetch_source_stream_fake .arg2_val , & dummy_sink ,
236- "Incorrect value of streamer argument" );
237-
238- zassert_equal (suit_dfu_cache_sink_commit_fake .call_count , 0 ,
183+ zassert_equal (suit_dfu_cache_sink_commit_fake .call_count , 1 ,
239184 "Incorrect number of suit_dfu_cache_sink_commit() calls" );
240185
241186 zassert_equal (suit_dfu_cache_streamer_stream_fake .call_count , 0 ,
242- "Incorrect number of suit_fetch_source_stream() calls" );
243- }
244-
245- ZTEST (suit_platform_app_fetch_tests , test_fetch_integrated_domain_specific_no_payload )
246- {
247- struct stream_sink dummy_sink = {0 };
248-
249- zassert_equal (suit_plat_fetch_integrated_domain_specific (TEST_COMPONENT_HANDLE ,
250- SUIT_COMPONENT_TYPE_CACHE_POOL ,
251- & dummy_sink , NULL ),
252- SUIT_ERR_UNAVAILABLE_PAYLOAD ,
253- "suit_plat_fetch_integrated_domain_specific did not fail" );
254- }
255-
256- ZTEST (suit_platform_app_fetch_tests , test_fetch_integrated_domain_specific_streamer_fail )
257- {
258- struct stream_sink dummy_sink = {0 };
259- uint8_t dummy_payload [] = {0 , 1 , 2 , 3 , 4 };
260- struct zcbor_string payload = {
261- .value = dummy_payload ,
262- .len = sizeof (dummy_payload ),
263- };
264-
265- suit_generic_address_streamer_stream_fake .return_val = SUIT_PLAT_ERR_NOT_FOUND ;
266-
267- zassert_equal (suit_plat_fetch_integrated_domain_specific (TEST_COMPONENT_HANDLE ,
268- SUIT_COMPONENT_TYPE_CACHE_POOL ,
269- & dummy_sink , & payload ),
270- SUIT_ERR_CRASH , "suit_plat_fetch_integrated_domain_specific did not fail" );
271- }
272-
273- ZTEST (suit_platform_app_fetch_tests , test_fetch_integrated_domain_specific )
274- {
275- struct stream_sink dummy_sink = {0 };
276- uint8_t dummy_payload [] = {0 , 1 , 2 , 3 , 4 };
277- struct zcbor_string payload = {
278- .value = dummy_payload ,
279- .len = sizeof (dummy_payload ),
280- };
281-
282- suit_generic_address_streamer_stream_fake .return_val = SUIT_PLAT_SUCCESS ;
283-
284- zassert_equal (suit_plat_fetch_integrated_domain_specific (TEST_COMPONENT_HANDLE ,
285- SUIT_COMPONENT_TYPE_CACHE_POOL ,
286- & dummy_sink , & payload ),
287- SUIT_SUCCESS , "suit_plat_fetch_integrated_domain_specific ail" );
187+ "Incorrect number of suit_dfu_cache_streamer_stream() calls" );
288188}
0 commit comments