Skip to content

Commit 3a4d05d

Browse files
committed
tests: secure_storage: test mbedtls ITS backend
Ensure that the mbedtls backend passes the same tests as TF-M and the zephyr backend, with minor exceptions. Signed-off-by: Jordan Yates <[email protected]>
1 parent 3a43350 commit 3a4d05d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

tests/subsys/secure_storage/psa/its/src/main.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
/* The flash must be erased after this test suite is run for the write-once entry test to pass. */
88
ZTEST_SUITE(secure_storage_psa_its, NULL, NULL, NULL, NULL, NULL);
99

10-
#ifdef CONFIG_SECURE_STORAGE
10+
#if defined(CONFIG_SECURE_STORAGE)
1111
#define MAX_DATA_SIZE CONFIG_SECURE_STORAGE_ITS_MAX_DATA_SIZE
12+
#elif defined(CONFIG_MBEDTLS_PSA_ITS_BACKEND_MBEDTLS_FILE)
13+
/* The backend supports arbitrarily large files, limit the value here for array sizes */
14+
#define MAX_DATA_SIZE 256
1215
#else
1316
#define MAX_DATA_SIZE CONFIG_TFM_ITS_MAX_ASSET_SIZE
1417
#endif
@@ -32,7 +35,7 @@ ZTEST(secure_storage_psa_its, test_all_sizes)
3235

3336
fill_data_buffer(written_data);
3437

35-
for (unsigned int i = 0; i <= sizeof(written_data); ++i) {
38+
for (unsigned int i = 1; i <= sizeof(written_data); ++i) {
3639

3740
ret = psa_its_set(UID, i, written_data, PSA_STORAGE_FLAG_NONE);
3841
zassert_equal(ret, PSA_SUCCESS);
@@ -41,9 +44,11 @@ ZTEST(secure_storage_psa_its, test_all_sizes)
4144
zassert_equal(ret, PSA_SUCCESS);
4245
zassert_equal(info.flags, PSA_STORAGE_FLAG_NONE);
4346
zassert_equal(info.size, i);
47+
#ifndef CONFIG_MBEDTLS_PSA_ITS_BACKEND_MBEDTLS_FILE
4448
zassert_equal(info.capacity, i);
49+
#endif
4550

46-
ret = psa_its_get(UID, 0, sizeof(read_data), read_data, &data_length);
51+
ret = psa_its_get(UID, 0, i, read_data, &data_length);
4752
zassert_equal(ret, PSA_SUCCESS);
4853
zassert_equal(data_length, i);
4954
zassert_mem_equal(read_data, written_data, data_length);
@@ -78,6 +83,14 @@ ZTEST(secure_storage_psa_its, test_all_offsets)
7883

7984
ZTEST(secure_storage_psa_its, test_max_num_entries)
8085
{
86+
if (IS_ENABLED(CONFIG_MBEDTLS_PSA_ITS_BACKEND_MBEDTLS_FILE)) {
87+
/* The mbedtls file backend will happily fill your hard drive
88+
* with as many entries as you have space. Skip this test.
89+
*/
90+
ztest_test_skip();
91+
return;
92+
}
93+
8194
psa_status_t ret = PSA_SUCCESS;
8295
unsigned int i;
8396
struct psa_storage_info_t info;
@@ -118,6 +131,12 @@ ZTEST(secure_storage_psa_its, test_write_once_flag)
118131
const uint8_t data[MAX_DATA_SIZE] = {};
119132
struct psa_storage_info_t info;
120133

134+
if (IS_ENABLED(CONFIG_MBEDTLS_PSA_ITS_BACKEND_MBEDTLS_FILE)) {
135+
/* The mbedtls file backend does not support this option */
136+
ztest_test_skip();
137+
return;
138+
}
139+
121140
ret = psa_its_set(uid, sizeof(data), data, PSA_STORAGE_FLAG_WRITE_ONCE);
122141
zassert_equal(ret, PSA_SUCCESS, "%s%d", (ret == PSA_ERROR_NOT_PERMITTED) ?
123142
"Has the flash been erased since this test ran? " : "", ret);

tests/subsys/secure_storage/psa/its/testcase.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ tests:
5252
integration_platforms:
5353
- nrf9151dk/nrf9151/ns
5454
extra_args: EXTRA_CONF_FILE=overlay-tfm.conf
55+
56+
secure_storage.psa.its.mbedtls_file:
57+
platform_allow:
58+
- native_sim
59+
extra_configs:
60+
- CONFIG_MBEDTLS_PSA_ITS_BACKEND_MBEDTLS_FILE=y

0 commit comments

Comments
 (0)