16 #define TEST_019_CYCLES 3U
18 static const uint8_t write_asset_data[ITS_MAX_ASSET_SIZE] = {0xBF};
19 static uint8_t read_asset_data[ITS_MAX_ASSET_SIZE] = {0};
26 const size_t data_len = 0;
27 const uint8_t write_data[] = {0};
30 status =
psa_its_set(uid, data_len, write_data, flags);
32 TEST_FAIL(
"Set should not fail with valid UID");
37 status =
psa_its_set(uid, data_len, write_data, flags);
39 TEST_FAIL(
"Set should not fail the second time with valid UID");
46 TEST_FAIL(
"Set should not succeed with an invalid UID");
53 TEST_FAIL(
"Remove should not fail with valid UID");
79 TEST_FAIL(
"Set should not fail with valid flags (existing UID)");
87 TEST_LOG(
"Note: The UID in this test has already been created with\r\n"
88 "the PSA_STORAGE_FLAG_WRITE_ONCE flag in a previous test\r\n"
89 "run. Wipe the storage area to run the full test.\r\n");
91 TEST_FAIL(
"Set should not fail with no flags");
98 TEST_FAIL(
"Set should not succeed with invalid flags");
110 const size_t data_len = 0;
115 TEST_FAIL(
"Set should succeed with NULL data pointer and zero length");
129 const size_t offset = 0;
132 size_t read_data_length = 0;
136 status =
psa_its_set(uid, write_len, write_data, flags);
138 TEST_FAIL(
"Set should not rewrite a write once UID");
157 if (comp_result != 0) {
158 TEST_FAIL(
"Write once data should not have changed");
163 if (read_data_length != read_len) {
164 TEST_FAIL(
"Write once data length should not have changed");
180 const uint8_t *p_read_data = read_data;
181 size_t read_data_length = 0;
184 status =
psa_its_set(uid, data_len, write_data, flags);
204 if (comp_result != 0) {
205 TEST_FAIL(
"Read data should be equal to result data");
210 if (read_data_length != data_len) {
211 TEST_FAIL(
"Read data length should be equal to requested data length");
224 data_len -= offset + 2;
239 if (comp_result != 0) {
240 TEST_FAIL(
"Read data contains illegal pre-data");
247 comp_result =
memcmp(p_read_data, write_data + offset, data_len);
249 comp_result =
tfm_memcmp(p_read_data, write_data + offset, data_len);
251 if (comp_result != 0) {
256 p_read_data += data_len;
263 if (comp_result != 0) {
264 TEST_FAIL(
"Read data contains illegal post-data");
271 TEST_FAIL(
"Remove should not fail with valid UID");
284 const size_t read_len = 0;
288 size_t read_data_length = 1;
291 status =
psa_its_set(uid, write_len, write_data, flags);
301 TEST_FAIL(
"Get should not fail with zero data len");
311 if (comp_result != 0) {
312 TEST_FAIL(
"Read data should be equal to original read data");
317 if (read_data_length != 0) {
318 TEST_FAIL(
"Read data length should be equal to zero");
323 read_data_length = 1;
339 if (comp_result != 0) {
340 TEST_FAIL(
"Read data should be equal to original read data");
345 if (read_data_length != 0) {
346 TEST_FAIL(
"Read data length should be equal to zero");
353 TEST_FAIL(
"Remove should not fail with valid UID");
364 const size_t data_len = 1;
365 const size_t offset = 0;
367 size_t read_data_length = 0;
374 TEST_FAIL(
"Get succeeded with non-existant UID");
384 if (comp_result != 0) {
385 TEST_FAIL(
"Read data not equal to original read data");
393 TEST_FAIL(
"Get succeeded with invalid UID");
403 if (comp_result != 0) {
404 TEST_FAIL(
"Read data not equal to original read data");
421 size_t read_data_length = 0;
424 status =
psa_its_set(uid, write_len, write_data, flags);
432 offset = write_len + 1;
437 TEST_FAIL(
"Get should not succeed with offset too large");
447 if (comp_result != 0) {
448 TEST_FAIL(
"Read data should be equal to original read data");
453 read_len = write_len + 1;
459 TEST_FAIL(
"Get should succeed with data length larger than UID's "
464 if (read_data_length != write_len) {
465 TEST_FAIL(
"Read data length should be equal to UID's length");
475 if (comp_result != 0) {
476 TEST_FAIL(
"Read data should be equal to newly read data");
489 read_len = write_len;
496 TEST_FAIL(
"Get should succeed with offset + data length too large, "
497 "but individually valid");
501 if (read_data_length != write_len - offset) {
502 TEST_FAIL(
"Read data length should be equal to the UID's remaining "
503 "size starting from offset");
513 if (comp_result != 0) {
514 TEST_FAIL(
"Read data should be equal to newly read data starting at "
522 TEST_FAIL(
"Remove should not fail with valid UID");
535 const size_t offset = 0;
537 size_t read_data_length = 0;
539 status =
psa_its_set(uid, data_len, write_data, flags);
546 status =
psa_its_get(uid, offset, 0, NULL, &read_data_length);
548 TEST_FAIL(
"Get should succeed with NULL data pointer and zero length");
553 if (read_data_length != 0) {
554 TEST_FAIL(
"Read data length should be 0 with NULL data pointer and "
562 TEST_FAIL(
"Remove should not fail with valid UID");
578 TEST_FAIL(
"Get info should not fail for write once UID");
584 TEST_FAIL(
"Size incorrect for write once UID");
589 TEST_FAIL(
"Capacity incorrect for write once UID");
594 TEST_FAIL(
"Flags incorrect for write once UID");
610 status =
psa_its_set(uid, data_len, write_data, flags);
619 TEST_FAIL(
"Get info should not fail with valid UID");
624 if (info.
size != data_len) {
625 TEST_FAIL(
"Size incorrect for valid UID");
630 TEST_FAIL(
"Capacity incorrect for valid UID");
634 if (info.
flags != flags) {
635 TEST_FAIL(
"Flags incorrect for valid UID");
642 TEST_FAIL(
"Remove should not fail with valid UID");
658 TEST_FAIL(
"Get info should not succeed with unset UID");
663 if (info.
size != 0) {
664 TEST_FAIL(
"Size should not have changed");
671 TEST_FAIL(
"Get info should not succeed with invalid UID");
676 if (info.
size != 0) {
677 TEST_FAIL(
"Size should not have changed");
682 TEST_FAIL(
"Capacity should not have changed");
687 TEST_FAIL(
"Flags should not have changed");
701 const size_t offset = 0;
704 size_t read_data_length = 0;
706 status =
psa_its_set(uid, data_len, write_data, flags);
715 TEST_FAIL(
"Remove should not fail with valid UID");
722 TEST_FAIL(
"Get info should not succeed with removed UID");
727 status =
psa_its_get(uid, offset, data_len, read_data, &read_data_length);
729 TEST_FAIL(
"Get should not succeed with removed UID");
736 TEST_FAIL(
"Remove should not succeed with removed UID");
751 TEST_FAIL(
"Remove should not succeed with write once UID");
766 TEST_FAIL(
"Remove should not succeed with invalid UID");
780 const size_t offset = 0;
781 const uint8_t write_data_1[] =
"UID 1 DATA";
784 size_t read_data_length = 0;
788 status =
psa_its_set(uid_1,
sizeof(write_data_1), write_data_1, flags);
790 TEST_FAIL(
"Set should not fail for UID 1");
795 status =
psa_its_set(uid_2, data_len_2, write_data_2, flags);
797 TEST_FAIL(
"Set should not fail for UID 2");
806 TEST_FAIL(
"Remove should not fail for UID 1");
816 TEST_FAIL(
"Get should not fail for UID 2");
825 if (comp_result != 0) {
826 TEST_FAIL(
"Read buffer has incorrect data");
831 TEST_FAIL(
"Read data length should be equal to result data length");
838 TEST_FAIL(
"Remove should not fail for UID 2");
854 size_t read_data_length = 0;
858 status =
psa_its_set(uid, data_len, write_data, flags);
865 for (offset = 0; offset < data_len; ++offset) {
870 TEST_FAIL(
"Get should not fail for partial read");
880 if (comp_result != 0) {
881 TEST_FAIL(
"Read buffer has incorrect data");
900 const size_t offset = 0;
901 const uint8_t write_data_1[] =
"ONE";
902 const uint8_t write_data_2[] =
"TWO";
903 const uint8_t write_data_3[] =
"THREE";
905 size_t read_data_length = 0;
909 status =
psa_its_set(uid,
sizeof(write_data_1), write_data_1, flags);
916 status =
psa_its_set(uid,
sizeof(write_data_2), write_data_2, flags);
923 status =
psa_its_set(uid,
sizeof(write_data_3), write_data_3, flags);
929 status =
psa_its_get(uid, offset,
sizeof(write_data_3), read_data,
938 comp_result =
memcmp(read_data, write_data_3,
sizeof(write_data_3));
940 comp_result =
tfm_memcmp(read_data, write_data_3,
sizeof(write_data_3));
942 if (comp_result != 0) {
943 TEST_FAIL(
"Read buffer has incorrect data");
947 if (read_data_length !=
sizeof(write_data_3)) {
948 TEST_FAIL(
"Read data length should be equal to result data length");
967 size_t read_data_length = 0;
973 ITS_MAX_ASSET_SIZE >> 2,
974 ITS_MAX_ASSET_SIZE >> 1,
979 size_t data_size = test_asset_sizes[cycle];
984 memset(read_asset_data, 0x00,
sizeof(read_asset_data));
986 tfm_memset(read_asset_data, 0x00,
sizeof(read_asset_data));
995 TEST_FAIL(
"Set should not fail with valid UID");
1002 TEST_FAIL(
"Get info should not fail with valid UID");
1007 if (info.
size != data_size) {
1008 TEST_FAIL(
"Size incorrect for valid UID");
1013 TEST_FAIL(
"Flags incorrect for valid UID");
1018 status =
psa_its_get(uid, 0, data_size, read_asset_data,
1021 TEST_FAIL(
"Get should not fail with valid UID");
1027 comp_result =
memcmp(read_asset_data, write_asset_data, data_size);
1029 comp_result =
tfm_memcmp(read_asset_data, write_asset_data, data_size);
1031 if (comp_result != 0) {
1032 TEST_FAIL(
"Read data should be equal to original write data");
1036 if (read_data_length != data_size) {
1037 TEST_FAIL(
"Read data length should be equal to result data length");
1044 TEST_FAIL(
"Remove should not fail with valid UID");
void tfm_its_test_common_019(struct test_result_t *ret)
Tests set, get_info, get and remove function with:
#define WRITE_ONCE_READ_DATA
__STATIC_INLINE void * tfm_memset(void *ptr, int value, size_t num)
#define TEST_FAIL(info_msg)
void tfm_its_test_common_016(struct test_result_t *ret)
Tests data block compact feature. Set UID 1 to locate it at the beginning of the block. Then set UID 2 to be located after UID 1 and remove UID 1. UID 2 will be compacted to the beginning of the block. This test verifies that the compaction works correctly by reading back UID 2.
void tfm_its_test_common_007(struct test_result_t *ret)
Tests get function with:
void tfm_its_test_common_012(struct test_result_t *ret)
Tests get info function with:
void tfm_its_test_common_010(struct test_result_t *ret)
Tests get info function with:
void tfm_its_test_common_002(struct test_result_t *ret)
Tests set function with:
void tfm_its_test_common_017(struct test_result_t *ret)
Tests set and multiple partial gets.
psa_status_t psa_its_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info)
Retrieve the metadata about the provided uid.
void tfm_its_test_common_011(struct test_result_t *ret)
Tests get info function with:
#define WRITE_ONCE_DATA_SIZE
#define WRITE_ONCE_RESULT_DATA
#define PSA_STORAGE_FLAG_WRITE_ONCE
psa_status_t psa_its_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.
void tfm_its_test_common_008(struct test_result_t *ret)
Tests get function with:
psa_status_t psa_its_remove(psa_storage_uid_t uid)
Remove the provided uid and its associated data from the storage.
void tfm_its_test_common_005(struct test_result_t *ret)
Tests get function with:
void tfm_its_test_common_004(struct test_result_t *ret)
Tests set function with:
#define PSA_ERROR_INVALID_ARGUMENT
psa_status_t psa_its_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 PSA_ERROR_NOT_PERMITTED
void tfm_its_test_common_001(struct test_result_t *ret)
Tests set function with:
int memcmp(const void *s1, const void *s2, size_t n)
#define PSA_ERROR_NOT_SUPPORTED
#define HALF_PADDING_SIZE
__STATIC_INLINE void * tfm_memcpy(void *dest, const void *src, size_t num)
void * memcpy(void *dest, const void *src, size_t n)
void tfm_its_test_common_015(struct test_result_t *ret)
Tests remove function with:
uint64_t psa_storage_uid_t
void tfm_its_test_common_003(struct test_result_t *ret)
Tests set function with:
void tfm_its_test_common_013(struct test_result_t *ret)
Tests remove function with:
__STATIC_INLINE int tfm_memcmp(const void *ptr1, const void *ptr2, size_t num)
#define OFFSET_RESULT_DATA
psa_storage_create_flags_t flags
#define PSA_STORAGE_FLAG_NONE
void tfm_its_test_common_018(struct test_result_t *ret)
Tests multiple sets to the same UID.
#define PSA_ERROR_DOES_NOT_EXIST
uint32_t psa_storage_create_flags_t
void tfm_its_test_common_009(struct test_result_t *ret)
Tests get function with:
int32_t psa_status_t
Function return status.
void tfm_its_test_common_014(struct test_result_t *ret)
Tests remove function with:
void * memset(void *s, int c, size_t n)
void tfm_its_test_common_006(struct test_result_t *ret)
Tests get function with: