|
10 | 10 | #include <suit_plat_decode_util.h> |
11 | 11 | #include <suit_memptr_storage.h> |
12 | 12 | #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 |
13 | 17 |
|
14 | 18 | /* Data used as component content for a MEM component */ |
15 | 19 | static uint8_t data_mem[] = {0xde, 0xad, 0xbe, 0xef}; |
@@ -153,3 +157,117 @@ ZTEST(suit_check_content_tests, test_mem_not_matching) |
153 | 157 | zassert_equal(SUIT_SUCCESS, err, "test error - failed to cleanup component handle: %d", |
154 | 158 | err); |
155 | 159 | } |
| 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