Skip to content

Commit 3e36539

Browse files
committed
[fix-up] core: pta: add self tests for transfer list
Misc fixes to address review comments. Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
1 parent 74b1121 commit 3e36539

3 files changed

Lines changed: 29 additions & 27 deletions

File tree

core/pta/tests/invoke.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,8 @@ static TEE_Result invoke_command(void *pSessionContext __unused,
433433
return core_aes_perf_tests(nParamTypes, pParams);
434434
case PTA_INVOKE_TESTS_CMD_DT_DRIVER_TESTS:
435435
return core_dt_driver_tests(nParamTypes, pParams);
436-
#if defined(CFG_TRANSFER_LIST_TEST)
437436
case PTA_INVOKE_TESTS_CMD_TRANSFER_LIST_TESTS:
438437
return core_transfer_list_tests(nParamTypes, pParams);
439-
#endif
440438
default:
441439
break;
442440
}

core/pta/tests/misc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ TEE_Result core_aes_perf_tests(uint32_t param_types,
3737
TEE_Result core_dt_driver_tests(uint32_t param_types,
3838
TEE_Param params[TEE_NUM_PARAMS]);
3939

40+
#if defined(CFG_TRANSFER_LIST_TEST)
4041
TEE_Result core_transfer_list_tests(uint32_t nParamTypes,
4142
TEE_Param pParams[TEE_NUM_PARAMS]);
43+
#else
44+
static inline TEE_Result
45+
core_transfer_list_tests(uint32_t nParamTypes __unused,
46+
TEE_Param pParams[TEE_NUM_PARAMS] __unused)
47+
{
48+
return TEE_ERROR_NOT_SUPPORTED;
49+
}
50+
#endif
4251

4352
#endif /*CORE_PTA_TESTS_MISC_H*/

core/pta/tests/transfer_list.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55

66
#include <kernel/transfer_list.h>
7-
#include <mm/core_memprot.h>
7+
#include <mm/core_mmu.h>
8+
#include <mm/phys_mem.h>
89
#include <pta_invoke_tests.h>
910
#include <stdlib.h>
1011
#include <string.h>
@@ -28,13 +29,12 @@ static TEE_Result test_add_te(struct transfer_list_header *tl,
2829
const void *data, uint8_t align,
2930
struct transfer_list_entry **tle)
3031
{
31-
uint8_t *te_dat;
32-
bool new_max_align = false;
32+
uint8_t *te_dat = NULL;
33+
uint8_t old_tl_align = 0;
3334
vaddr_t old_tl_ev = (vaddr_t)tl + tl->size;
34-
struct transfer_list_entry *tl_e;
35+
struct transfer_list_entry *tl_e = NULL;
3536

36-
if (align > tl->alignment)
37-
new_max_align = true;
37+
old_tl_align = tl->alignment;
3838

3939
if (!align)
4040
tl_e = transfer_list_add(tl, tag_id, data_size, data);
@@ -45,8 +45,7 @@ static TEE_Result test_add_te(struct transfer_list_header *tl,
4545
if (!tl_e)
4646
return TEE_ERROR_GENERIC;
4747

48-
/* tl->alignment keeps the max entry data alignment of the TL */
49-
if (new_max_align && tl->alignment != align)
48+
if (tl->alignment != MAX(old_tl_align, align))
5049
return TEE_ERROR_CORRUPT_OBJECT;
5150

5251
if (tl_e->tag_id != tag_id || tl_e->hdr_size != sizeof(*tl_e) ||
@@ -87,7 +86,7 @@ static TEE_Result test_add_te(struct transfer_list_header *tl,
8786
static TEE_Result test_rm_te(struct transfer_list_header *tl,
8887
uint16_t tag_id)
8988
{
90-
struct transfer_list_entry *tl_e;
89+
struct transfer_list_entry *tl_e = NULL;
9190

9291
tl_e = transfer_list_find(tl, tag_id);
9392
if (!tl_e)
@@ -109,9 +108,9 @@ static TEE_Result test_set_te_data_size(struct transfer_list_header *tl,
109108
struct transfer_list_entry *tl_e,
110109
uint32_t new_data_size)
111110
{
112-
struct transfer_list_entry *old_te_next;
113-
struct transfer_list_entry *new_te_next;
114-
size_t mov_dis;
111+
struct transfer_list_entry *old_te_next = NULL;
112+
struct transfer_list_entry *new_te_next = NULL;
113+
size_t mov_dis = 0;
115114

116115
old_te_next = transfer_list_next(tl, tl_e);
117116

@@ -144,20 +143,16 @@ static TEE_Result test_set_te_data_size(struct transfer_list_header *tl,
144143

145144
static TEE_Result transfer_list_tests(void)
146145
{
147-
uint8_t *va_tl;
148-
paddr_t pa_tl;
149-
struct transfer_list_header *tl;
150-
struct transfer_list_entry *te1, *te2, *te3;
151-
TEE_Result ret;
152-
153-
va_tl = memalign(TL_ALIGNMENT_FROM_ORDER(TRANSFER_LIST_INIT_MAX_ALIGN),
154-
TEST_TL_MAX_SIZE);
155-
if (!va_tl)
156-
return TEE_ERROR_OUT_OF_MEMORY;
146+
struct transfer_list_header *tl = NULL;
147+
struct transfer_list_entry *te1 = NULL, *te2 = NULL, *te3 = NULL;
148+
TEE_Result ret = TEE_SUCCESS;
149+
tee_mm_entry_t *mm = NULL;
157150

158-
pa_tl = virt_to_phys(va_tl);
151+
mm = phys_mem_core_alloc(SMALL_PAGE_SIZE);
152+
if (!mm)
153+
return TEE_ERROR_OUT_OF_MEMORY;
159154

160-
tl = transfer_list_init(pa_tl, TEST_TL_MAX_SIZE);
155+
tl = transfer_list_init(tee_mm_get_smem(mm), TEST_TL_MAX_SIZE);
161156
if (!tl) {
162157
ret = TEE_ERROR_GENERIC;
163158
goto free_tl;
@@ -232,7 +227,7 @@ static TEE_Result transfer_list_tests(void)
232227
transfer_list_unmap_sync(tl);
233228

234229
free_tl:
235-
free(va_tl);
230+
tee_mm_free(mm);
236231
return ret;
237232
}
238233

0 commit comments

Comments
 (0)