Skip to content

Commit 39f973c

Browse files
tomchydegjorva
authored andcommitted
tests: Add cases for checking MFST_VAR content
Add test cases for that verify if it is possible to check content of manifest variables. Ref: NCSDK-30807 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 173dc66 commit 39f973c

File tree

8 files changed

+194
-0
lines changed

8 files changed

+194
-0
lines changed

tests/subsys/suit/check_content/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ include(../cmake/test_template.cmake)
1414
zephyr_library_link_libraries(suit_platform_interface)
1515
zephyr_library_link_libraries(suit_memptr_storage_interface)
1616
zephyr_library_link_libraries(suit_stream_sinks_interface)
17+
zephyr_library_link_libraries(suit_manifest_variables)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_FLASH_SIMULATOR=y
8+
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&flash0 {
8+
partitions {
9+
compatible = "fixed-partitions";
10+
#address-cells = <1>;
11+
#size-cells = <1>;
12+
13+
/* Use the last 48KB of NVM as suit storage. */
14+
suit_storage: partition@f4000 {
15+
reg = <0xf4000 DT_SIZE_K(48)>;
16+
};
17+
};
18+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_FLASH_SIMULATOR=y
8+
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&flash0 {
8+
partitions {
9+
compatible = "fixed-partitions";
10+
#address-cells = <1>;
11+
#size-cells = <1>;
12+
13+
/* Use the last 48KB of NVM as suit storage. */
14+
suit_storage: partition@f4000 {
15+
reg = <0xf4000 DT_SIZE_K(48)>;
16+
};
17+
};
18+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&flash0 {
8+
partitions {
9+
compatible = "fixed-partitions";
10+
#address-cells = <1>;
11+
#size-cells = <1>;
12+
13+
/* Use the last 48KB of NVM as suit storage. */
14+
suit_storage: partition@f4000 {
15+
reg = <0xf4000 DT_SIZE_K(48)>;
16+
};
17+
};
18+
};

tests/subsys/suit/check_content/prj.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ CONFIG_SUIT_STREAM_SINK_DIGEST=y
1717
CONFIG_SUIT_UTILS=y
1818
CONFIG_SUIT_MEMPTR_STORAGE=y
1919
CONFIG_SUIT_STREAM_SOURCE_MEMPTR=y
20+
CONFIG_SUIT_MANIFEST_VARIABLES=y
21+
CONFIG_SUIT_STORAGE=y
2022

2123
CONFIG_ZCBOR=y
2224
CONFIG_ZCBOR_CANONICAL=y
2325

26+
CONFIG_FLASH=y
27+
CONFIG_FLASH_MAP=y
28+
2429
CONFIG_SUIT_DIGEST=y
2530
CONFIG_SUIT_DIGEST_CACHE=y
2631
CONFIG_SUIT_CRYPTO=y

tests/subsys/suit/check_content/src/main.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <suit_plat_decode_util.h>
1111
#include <suit_memptr_storage.h>
1212
#include <suit_sink.h>
13+
#include <suit_manifest_variables.h>
14+
15+
#define TEST_MFST_VAR_NVM_ID 0
16+
#define TEST_MFST_VAR_NVM_VALUE 0xAB
1317

1418
/* Data used as component content for a MEM component */
1519
static uint8_t data_mem[] = {0xde, 0xad, 0xbe, 0xef};
@@ -153,3 +157,117 @@ ZTEST(suit_check_content_tests, test_mem_not_matching)
153157
zassert_equal(SUIT_SUCCESS, err, "test error - failed to cleanup component handle: %d",
154158
err);
155159
}
160+
161+
ZTEST(suit_check_content_tests, test_mfst_var_nvm_matching)
162+
{
163+
/* [h'MFST_VAR', h'00'] */
164+
uint8_t component_id_value[] = {0x82, 0x49, 0x68, 'M', 'F', 'S', 'T',
165+
'_', 'V', 'A', 'R', 0x41, 0x00};
166+
struct zcbor_string src_component_id = {
167+
.value = component_id_value,
168+
.len = sizeof(component_id_value),
169+
};
170+
/* 0xAB */
171+
uint8_t test_value[] = {0x18, TEST_MFST_VAR_NVM_VALUE};
172+
struct zcbor_string test_value_zcbor = {
173+
.value = test_value,
174+
.len = sizeof(test_value),
175+
};
176+
suit_component_t component;
177+
int ret;
178+
179+
/* GIVEN that MFST_VAR/0 value is initialized with sample value... */
180+
zassert_equal(suit_mfst_var_set(TEST_MFST_VAR_NVM_ID, TEST_MFST_VAR_NVM_VALUE),
181+
SUIT_PLAT_SUCCESS, "Unable to set MFST_VAR value before the test");
182+
183+
/* ... and the component handle for the MFST_VAR/0 is successfully created */
184+
zassert_equal(suit_plat_create_component_handle(&src_component_id, false, &component),
185+
SUIT_SUCCESS, "Unable to create MFST_VAR component");
186+
187+
/* WHEN a check content function is called */
188+
ret = suit_plat_check_content(component, &test_value_zcbor);
189+
190+
/* THEN the component contents match its content parameter */
191+
zassert_equal(ret, SUIT_SUCCESS, "Unexpected error code: %d", ret);
192+
193+
/* ... and the component can be safely released */
194+
ret = suit_plat_release_component_handle(component);
195+
zassert_equal(ret, SUIT_SUCCESS, "Failed to release component handle after the test: %d",
196+
ret);
197+
}
198+
199+
ZTEST(suit_check_content_tests, test_mfst_var_nvm_not_matching)
200+
{
201+
/* [h'MFST_VAR', h'00'] */
202+
uint8_t component_id_value[] = {0x82, 0x49, 0x68, 'M', 'F', 'S', 'T',
203+
'_', 'V', 'A', 'R', 0x41, 0x00};
204+
struct zcbor_string src_component_id = {
205+
.value = component_id_value,
206+
.len = sizeof(component_id_value),
207+
};
208+
/* 0xBA */
209+
uint8_t test_value[] = {0x18, 0xBA};
210+
struct zcbor_string test_value_zcbor = {
211+
.value = test_value,
212+
.len = sizeof(test_value),
213+
};
214+
suit_component_t component;
215+
int ret;
216+
217+
/* GIVEN that MFST_VAR/0 value is initialized with sample value... */
218+
zassert_equal(suit_mfst_var_set(TEST_MFST_VAR_NVM_ID, TEST_MFST_VAR_NVM_VALUE),
219+
SUIT_PLAT_SUCCESS, "Unable to set MFST_VAR value before the test");
220+
221+
/* ... and the component handle for the MFST_VAR/0 is successfully created */
222+
zassert_equal(suit_plat_create_component_handle(&src_component_id, false, &component),
223+
SUIT_SUCCESS, "Unable to create MFST_VAR component");
224+
225+
/* WHEN a check content function is called */
226+
ret = suit_plat_check_content(component, &test_value_zcbor);
227+
228+
/* THEN the component contents does not match its content parameter */
229+
zassert_equal(ret, SUIT_FAIL_CONDITION, "Unexpected error code: %d", ret);
230+
231+
/* ... and the component can be safely released */
232+
ret = suit_plat_release_component_handle(component);
233+
zassert_equal(ret, SUIT_SUCCESS, "Failed to release component handle after the test: %d",
234+
ret);
235+
}
236+
237+
ZTEST(suit_check_content_tests, test_mfst_var_invalid_content)
238+
{
239+
/* [h'MFST_VAR', h'00'] */
240+
uint8_t component_id_value[] = {0x82, 0x49, 0x68, 'M', 'F', 'S', 'T',
241+
'_', 'V', 'A', 'R', 0x41, 0x00};
242+
struct zcbor_string src_component_id = {
243+
.value = component_id_value,
244+
.len = sizeof(component_id_value),
245+
};
246+
/* [0x00] */
247+
uint8_t test_value[] = {0x81, 0x00};
248+
struct zcbor_string test_value_zcbor = {
249+
.value = test_value,
250+
.len = sizeof(test_value),
251+
};
252+
suit_component_t component;
253+
int ret;
254+
255+
/* GIVEN that MFST_VAR/0 value is initialized with sample value... */
256+
zassert_equal(suit_mfst_var_set(TEST_MFST_VAR_NVM_ID, TEST_MFST_VAR_NVM_VALUE),
257+
SUIT_PLAT_SUCCESS, "Unable to set MFST_VAR value before the test");
258+
259+
/* ... and the component handle for the MFST_VAR/0 is successfully created */
260+
zassert_equal(suit_plat_create_component_handle(&src_component_id, false, &component),
261+
SUIT_SUCCESS, "Unable to create MFST_VAR component");
262+
263+
/* WHEN a check content function is called */
264+
ret = suit_plat_check_content(component, &test_value_zcbor);
265+
266+
/* THEN the component contents does not match its content parameter */
267+
zassert_equal(ret, SUIT_ERR_UNSUPPORTED_PARAMETER, "Unexpected error code: %d", ret);
268+
269+
/* ... and the component can be safely released */
270+
ret = suit_plat_release_component_handle(component);
271+
zassert_equal(ret, SUIT_SUCCESS, "Failed to release component handle after the test: %d",
272+
ret);
273+
}

0 commit comments

Comments
 (0)