18 #define WRITE_ONCE_UID 1U
24 #define INVALID_UID 0U
25 #define INVALID_DATA_LEN UINT32_MAX
26 #define INVALID_OFFSET UINT32_MAX
27 #define INVALID_FLAG (1U << 31)
28 #define INVALID_THREAD_NAME "Thread_INVALID"
31 #define WRITE_ONCE_DATA "THE_FIVE_BOXING_WIZARDS_JUMP_QUICKLY"
32 #define WRITE_ONCE_DATA_SIZE (sizeof(WRITE_ONCE_DATA) - 1)
33 #define WRITE_ONCE_READ_DATA "############################################"
34 #define WRITE_ONCE_RESULT_DATA ("####" WRITE_ONCE_DATA "####")
36 #define WRITE_DATA "THEQUICKBROWNFOXJUMPSOVERALAZYDOG"
37 #define WRITE_DATA_SIZE (sizeof(WRITE_DATA) - 1)
38 #define READ_DATA "_________________________________________"
39 #define RESULT_DATA ("____" WRITE_DATA "____")
40 #define OFFSET_READ_DATA "HEQUICKBROWNFOXJUMPSOVERALAZYDOG"
41 #define OFFSET_RESULT_DATA ("____" OFFSET_READ_DATA "_____")
43 #define TEST_1022_CYCLES 3U
45 static const uint8_t write_asset_data[PS_MAX_ASSET_SIZE] = {0xBF};
46 static uint8_t read_asset_data[PS_MAX_ASSET_SIZE] = {0};
47 static size_t read_asset_datal_len = 0;
73 static struct test_t psa_ps_s_tests[] = {
74 {&tfm_ps_test_2001,
"TFM_PS_TEST_2001",
76 {&tfm_ps_test_2002,
"TFM_PS_TEST_2002",
77 "Set interface with create flags"},
78 {&tfm_ps_test_2003,
"TFM_PS_TEST_2003",
79 "Set interface with NULL data pointer"},
80 {&tfm_ps_test_2004,
"TFM_PS_TEST_2004",
81 "Set interface with invalid data length"},
82 {&tfm_ps_test_2005,
"TFM_PS_TEST_2005",
83 "Set interface with write once UID"},
84 {&tfm_ps_test_2006,
"TFM_PS_TEST_2006",
85 "Get interface with valid data"},
86 {&tfm_ps_test_2007,
"TFM_PS_TEST_2007",
87 "Get interface with zero data length"},
88 {&tfm_ps_test_2008,
"TFM_PS_TEST_2008",
89 "Get interface with invalid UIDs"},
90 {&tfm_ps_test_2009,
"TFM_PS_TEST_2009",
91 "Get interface with invalid data lengths and offsets"},
92 {&tfm_ps_test_2010,
"TFM_PS_TEST_2010",
93 "Get interface with NULL data pointer"},
94 {&tfm_ps_test_2011,
"TFM_PS_TEST_2011",
95 "Get info interface with write once UID"},
96 {&tfm_ps_test_2012,
"TFM_PS_TEST_2012",
97 "Get info interface with valid UID"},
98 {&tfm_ps_test_2013,
"TFM_PS_TEST_2013",
99 "Get info interface with invalid UIDs"},
100 {&tfm_ps_test_2014,
"TFM_PS_TEST_2014",
101 "Get info interface with NULL info pointer"},
102 {&tfm_ps_test_2015,
"TFM_PS_TEST_2015",
103 "Remove interface with valid UID"},
104 {&tfm_ps_test_2016,
"TFM_PS_TEST_2016",
105 "Remove interface with write once UID"},
106 {&tfm_ps_test_2017,
"TFM_PS_TEST_2017",
107 "Remove interface with invalid UID"},
108 {&tfm_ps_test_2018,
"TFM_PS_TEST_2018",
109 "Block compaction after remove"},
110 {&tfm_ps_test_2019,
"TFM_PS_TEST_2019",
111 "Multiple partial gets"},
112 {&tfm_ps_test_2020,
"TFM_PS_TEST_2020",
113 "Multiple sets to same UID from same thread"},
114 {&tfm_ps_test_2021,
"TFM_PS_TEST_2021",
115 "Get support interface"},
116 {&tfm_ps_test_2022,
"TFM_PS_TEST_2022",
117 "Set, get and remove interface with different asset sizes"},
124 list_size = (
sizeof(psa_ps_s_tests) /
sizeof(psa_ps_s_tests[0]));
126 set_testsuite(
"PSA protected storage S interface tests (TFM_PS_TEST_2XXX)",
127 psa_ps_s_tests, list_size, p_test_suite);
140 const uint32_t data_len = 0;
141 const uint8_t write_data[] = {0};
144 status =
psa_ps_set(uid, data_len, write_data, flags);
146 TEST_FAIL(
"Set should not fail with valid UID");
151 status =
psa_ps_set(uid, data_len, write_data, flags);
153 TEST_FAIL(
"Set should not fail the second time with valid UID");
160 TEST_FAIL(
"Set should not succeed with an invalid UID");
167 TEST_FAIL(
"Remove should not fail with valid UID");
199 TEST_FAIL(
"Set should not fail with valid flags (existing UID)");
207 TEST_LOG(
"Note: The UID in this test has already been created with\r\n"
208 "the PSA_STORAGE_FLAG_WRITE_ONCE flag in a previous test\r\n"
209 "run. Wipe the storage area to run the full test.\r\n");
211 TEST_FAIL(
"Set should not fail with no flags");
218 TEST_FAIL(
"Set should not succeed with invalid flags");
239 const uint32_t data_len = 0;
242 status =
psa_ps_set(uid, data_len, NULL, flags);
244 TEST_FAIL(
"Set should succeed with NULL data pointer and zero length");
272 status =
psa_ps_set(uid, data_len, write_data, flags);
274 TEST_FAIL(
"Set should not succeed with invalid data length");
293 const uint32_t offset = 0;
296 size_t read_data_len = 0;
299 status =
psa_ps_set(uid, write_len, write_data, flags);
301 TEST_FAIL(
"Set should not rewrite a write once UID");
315 TEST_FAIL(
"Write once data should not have changed");
336 const uint8_t *p_read_data = read_data;
337 size_t read_data_len = 0;
339 status =
psa_ps_set(uid, data_len, write_data, flags);
355 TEST_FAIL(
"Read data should be equal to result data");
364 data_len -= offset + 2;
375 TEST_FAIL(
"Read data contains illegal pre-data");
381 if (
tfm_memcmp(p_read_data, write_data + offset, data_len) != 0) {
386 p_read_data += data_len;
389 TEST_FAIL(
"Read data contains illegal post-data");
396 TEST_FAIL(
"Remove should not fail with valid UID");
414 const uint32_t read_len = 0;
418 size_t read_data_len = 0;
420 status =
psa_ps_set(uid, write_len, write_data, flags);
430 TEST_FAIL(
"Get should not fail with zero data len");
436 TEST_FAIL(
"Read data should be equal to original read data");
452 TEST_FAIL(
"Read data should be equal to original read data");
459 TEST_FAIL(
"Remove should not fail with valid UID");
475 const uint32_t data_len = 1;
476 const uint32_t offset = 0;
478 size_t read_data_len = 0;
484 TEST_FAIL(
"Get succeeded with non-existant UID");
490 TEST_FAIL(
"Read data not equal to original read data");
498 TEST_FAIL(
"Get succeeded with invalid UID");
504 TEST_FAIL(
"Read data not equal to original read data");
528 size_t read_data_len = 0;
530 status =
psa_ps_set(uid, write_len, write_data, flags);
538 offset = write_len + 1;
543 TEST_FAIL(
"Get should not succeed with offset too large");
549 TEST_FAIL(
"Read data should be equal to original read data");
554 read_len = write_len + 1;
560 TEST_FAIL(
"Get should succeed with data length larger than UID's "
565 if (read_data_len != write_len) {
566 TEST_FAIL(
"Read data length should be equal to UID's length");
572 TEST_FAIL(
"Read data should be equal to original read data");
579 read_len = write_len;
588 TEST_FAIL(
"Get should succeed with offset + data length too large, "
589 "but individually valid");
593 if (read_data_len != write_len - offset) {
594 TEST_FAIL(
"Read data length should be equal to the UID's remaining "
595 "size starting from offset");
601 TEST_FAIL(
"Read data should be equal to original read data");
623 TEST_FAIL(
"Get should not succeed with invalid arguments");
629 TEST_FAIL(
"Read data should be equal to original read data");
637 TEST_FAIL(
"Remove should not fail with valid UID");
659 const uint32_t offset = 0;
661 size_t read_data_len = 0;
663 status =
psa_ps_set(uid, data_len, write_data, flags);
670 status =
psa_ps_get(uid, offset, 0, NULL, &read_data_len);
672 TEST_FAIL(
"Get should succeed with NULL data pointer and zero length");
679 TEST_FAIL(
"Remove should not fail with valid UID");
699 TEST_FAIL(
"Get info should not fail for write once UID");
705 TEST_FAIL(
"Size incorrect for write once UID");
710 TEST_FAIL(
"Flags incorrect for write once UID");
730 status =
psa_ps_set(uid, data_len, write_data, flags);
739 TEST_FAIL(
"Get info should not fail with valid UID");
744 if (info.
size != data_len) {
745 TEST_FAIL(
"Size incorrect for valid UID");
749 if (info.
flags != flags) {
750 TEST_FAIL(
"Flags incorrect for valid UID");
757 TEST_FAIL(
"Remove should not fail with valid UID");
778 TEST_FAIL(
"Get info should not succeed with unset UID");
783 if (info.
size != 0) {
784 TEST_FAIL(
"Size should not have changed");
788 if (info.
flags != 0) {
789 TEST_FAIL(
"Flags should not have changed");
796 TEST_FAIL(
"Get info should not succeed with invalid UID");
801 if (info.
size != 0) {
802 TEST_FAIL(
"Size should not have changed");
806 if (info.
flags != 0) {
807 TEST_FAIL(
"Flags should not have changed");
826 status =
psa_ps_set(uid, data_len, write_data, flags);
842 TEST_FAIL(
"Get info should not succeed with NULL info pointer");
850 TEST_FAIL(
"Remove should not fail with valid UID");
868 const uint32_t offset = 0;
871 size_t read_data_len = 0;
873 status =
psa_ps_set(uid, data_len, write_data, flags);
882 TEST_FAIL(
"Remove should not fail with valid UID");
889 TEST_FAIL(
"Get info should not succeed with removed UID");
894 status =
psa_ps_get(uid, offset, data_len, read_data, &read_data_len);
896 TEST_FAIL(
"Get should not succeed with removed UID");
903 TEST_FAIL(
"Remove should not succeed with removed UID");
922 TEST_FAIL(
"Remove should not succeed with write once UID");
941 TEST_FAIL(
"Remove should not succeed with invalid UID");
962 const uint32_t offset = 0;
963 const uint8_t write_data_1[] =
"UID 1 DATA";
966 size_t read_data_len = 0;
969 status =
psa_ps_set(uid_1,
sizeof(write_data_1), write_data_1, flags);
971 TEST_FAIL(
"Set should not fail for UID 1");
976 status =
psa_ps_set(uid_2, data_len_2, write_data_2, flags);
978 TEST_FAIL(
"Set should not fail for UID 2");
987 TEST_FAIL(
"Remove should not fail for UID 1");
994 status =
psa_ps_get(uid_2, offset, data_len_2,
997 TEST_FAIL(
"Get should not fail for UID 2");
1002 TEST_FAIL(
"Read buffer has incorrect data");
1009 TEST_FAIL(
"Remove should not fail for UID 2");
1026 uint32_t offset = 0;
1029 size_t read_data_len = 0;
1032 status =
psa_ps_set(uid, data_len, write_data, flags);
1039 for (i = 0; i < data_len; ++i) {
1044 TEST_FAIL(
"Get should not fail for partial read");
1052 TEST_FAIL(
"Read buffer has incorrect data");
1074 const uint32_t offset = 0;
1075 const uint8_t write_data_1[] =
"ONE";
1076 const uint8_t write_data_2[] =
"TWO";
1077 const uint8_t write_data_3[] =
"THREE";
1079 size_t read_data_len = 0;
1082 status =
psa_ps_set(uid,
sizeof(write_data_1), write_data_1, flags);
1089 status =
psa_ps_set(uid,
sizeof(write_data_2), write_data_2, flags);
1091 TEST_FAIL(
"Second set should not fail");
1096 status =
psa_ps_set(uid,
sizeof(write_data_3), write_data_3, flags);
1102 status =
psa_ps_get(uid, offset,
sizeof(write_data_3), read_data,
1110 if (
tfm_memcmp(read_data, write_data_3,
sizeof(write_data_3)) != 0) {
1111 TEST_FAIL(
"Read buffer has incorrect data");
1130 uint32_t support_flags;
1133 if (support_flags != 0) {
1156 PS_MAX_ASSET_SIZE >> 2,
1157 PS_MAX_ASSET_SIZE >> 1,
1162 uint32_t data_size = test_asset_sizes[cycle];
1166 tfm_memset(read_asset_data, 0x00,
sizeof(read_asset_data));
1174 TEST_FAIL(
"Set should not fail with valid UID");
1181 TEST_FAIL(
"Get info should not fail with valid UID");
1186 if (info.
size != data_size) {
1187 TEST_FAIL(
"Size incorrect for valid UID");
1192 TEST_FAIL(
"Flags incorrect for valid UID");
1197 status =
psa_ps_get(uid, 0, data_size, read_asset_data,
1198 &read_asset_datal_len);
1200 TEST_FAIL(
"Get should not fail with valid UID");
1205 if (
tfm_memcmp(read_asset_data, write_asset_data, data_size) != 0) {
1206 TEST_FAIL(
"Read data should be equal to original write data");
1213 TEST_FAIL(
"Remove should not fail with valid UID");
void register_testsuite_s_psa_ps_interface(struct test_suite_t *p_test_suite)
Register testsuite for the PSA protected storage S interface tests.
psa_status_t psa_ps_get(psa_storage_uid_t uid, size_t data_offset, size_t data_size, void *p_data, size_t *p_data_length)
Retrieve data associated with a provided uid.
__STATIC_INLINE void * tfm_memset(void *ptr, int value, size_t num)
#define TEST_FAIL(info_msg)
enum test_suite_err_t set_testsuite(const char *name, struct test_t *test_list, uint32_t size, struct test_suite_t *p_ts)
Sets test suite parameters.
psa_status_t psa_ps_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, psa_storage_create_flags_t create_flags)
Create a new, or modify an existing, uid/value pair.
#define OFFSET_RESULT_DATA
#define PSA_STORAGE_FLAG_WRITE_ONCE
#define WRITE_ONCE_DATA_SIZE
#define PSA_ERROR_INVALID_ARGUMENT
psa_status_t psa_ps_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info)
Retrieve the metadata about the provided uid.
#define PSA_ERROR_NOT_PERMITTED
psa_status_t psa_ps_remove(psa_storage_uid_t uid)
Remove the provided uid and its associated data from the storage.
#define PSA_ERROR_NOT_SUPPORTED
#define HALF_PADDING_SIZE
__STATIC_INLINE void * tfm_memcpy(void *dest, const void *src, size_t num)
#define WRITE_ONCE_RESULT_DATA
uint32_t psa_ps_get_support(void)
Lists optional features.
uint64_t psa_storage_uid_t
__STATIC_INLINE int tfm_memcmp(const void *ptr1, const void *ptr2, size_t num)
psa_storage_create_flags_t flags
#define PSA_STORAGE_FLAG_NONE
#define PSA_ERROR_DOES_NOT_EXIST
uint32_t psa_storage_create_flags_t
int32_t psa_status_t
Function return status.
#define WRITE_ONCE_READ_DATA