blob: 63d668f379696c0c0c0681f60f67feae9dd35d97 [file] [log] [blame]
Pascal Brandc639ac82015-07-02 08:53:34 +02001/*
2 * Copyright (c) 2014, STMicroelectronics International N.V.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <stdio.h>
15#include <string.h>
16#include <stdlib.h>
17#include <sys/types.h>
18#include <unistd.h>
19
20#include "xtest_test.h"
21#include "xtest_helpers.h"
Pascal Brandc639ac82015-07-02 08:53:34 +020022#include "tee_api_defines.h"
23#include "tee_client_api.h"
24
25#define OFFSET0 0
26
27#define PARAM_0 0
28#define PARAM_1 1
29#define PARAM_2 2
30#define PARAM_3 3
31
32struct xtest_session {
33 ADBG_Case_t *c;
34 TEEC_Session session;
35 TEEC_Context context;
36};
37
38/* Compares two memories and checks if their length and content is the same */
39#define EXPECT_SHARED_MEM_BUFFER(c, exp_buf, exp_blen, op, param_num, shrm) \
40 do { \
41 if ((exp_buf) == NULL) { \
42 ADBG_EXPECT((c), exp_blen, \
43 (op)->params[(param_num)].memref.size); \
44 } else { \
45 ADBG_EXPECT_COMPARE_POINTER((c), (shrm), ==, \
46 (op)->params[(param_num)].memref.parent); \
47 ADBG_EXPECT_BUFFER((c), (exp_buf), (exp_blen), \
48 (shrm)->buffer, \
49 (op)->params[(param_num)].memref.size); \
50 } \
51 } while (0)
52
53/*
54 * Compares the content of the memory cells in OP with the expected value
55 * contained.
56 */
57#define EXPECT_OP_TMP_MEM_BUFFER(c, exp_buf, exp_blen, op, param_num, buf) \
58 do { \
59 if ((exp_buf) == NULL) { \
60 ADBG_EXPECT((c), exp_blen, \
61 (op)->params[(param_num)].tmpref.size); \
62 } else { \
63 ADBG_EXPECT_COMPARE_POINTER((c), (buf), ==, \
64 (op)->params[(param_num)].tmpref.buffer); \
65 ADBG_EXPECT_BUFFER((c), (exp_buf), (exp_blen), \
66 (buf), \
67 (op)->params[(param_num)].memref.size); \
68 } \
69 } while (0)
70
71/* Initiates the memory and allocates size uint32_t. */
72
73/* Registers the TEEC_SharedMemory to the TEE. */
74static TEEC_Result RegisterSharedMemory(TEEC_Context *ctx,
75 TEEC_SharedMemory *shm, uint32_t size,
76 uint32_t flags)
77{
78 shm->flags = flags;
79 shm->size = size;
80 return TEEC_RegisterSharedMemory(ctx, shm);
81}
82
83/* Allocates shared memory inside of the TEE. */
84static TEEC_Result AllocateSharedMemory(TEEC_Context *ctx,
85 TEEC_SharedMemory *shm, uint32_t size,
86 uint32_t flags)
87{
88 shm->flags = flags;
89 shm->size = size;
90 return TEEC_AllocateSharedMemory(ctx, shm);
91}
92
93static void CloseSession_null(struct xtest_session *cs)
94{
95 Do_ADBG_BeginSubCase(cs->c, "CloseSession_null");
96 {
97 /* In reality doesn't test anything. */
98 TEEC_CloseSession(NULL);
99 }
100 Do_ADBG_EndSubCase(cs->c, "CloseSession_null");
101}
102
103static void Allocate_In(struct xtest_session *cs)
104{
105 Do_ADBG_BeginSubCase(cs->c, "Allocate_In");
106 {
107 TEEC_SharedMemory shm;
108 uint32_t size = 1024;
109
Jens Wiklander72c55452016-10-27 20:44:35 +0200110 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
111 TEEC_InitializeContext(_device, &cs->context)))
112 goto out;
113
114 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200115 AllocateSharedMemory(&cs->context, &shm, size,
Jens Wiklander72c55452016-10-27 20:44:35 +0200116 TEEC_MEM_INPUT)))
117 goto out_final;
118
Pascal Brandc639ac82015-07-02 08:53:34 +0200119 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200120out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200121 TEEC_FinalizeContext(&cs->context);
122 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200123out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200124 Do_ADBG_EndSubCase(cs->c, "Allocate_In");
125}
126
127static void Allocate_out_of_memory(struct xtest_session *cs)
128{
129 Do_ADBG_BeginSubCase(cs->c, "Allocate_out_of_memory");
130 {
131 TEEC_SharedMemory shm;
132 uint32_t SIZE_OVER_MEMORY_CAPACITY = INT32_MAX;
133
Jens Wiklander72c55452016-10-27 20:44:35 +0200134 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
135 TEEC_InitializeContext(_device, &cs->context)))
136 goto out;
137
Pascal Brandc639ac82015-07-02 08:53:34 +0200138 ADBG_EXPECT_TEEC_RESULT(cs->c, TEEC_ERROR_OUT_OF_MEMORY,
139 AllocateSharedMemory(&cs->context, &shm,
140 SIZE_OVER_MEMORY_CAPACITY,
141 TEEC_MEM_INPUT));
Pascal Brandc639ac82015-07-02 08:53:34 +0200142 TEEC_FinalizeContext(&cs->context);
143 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200144out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200145 Do_ADBG_EndSubCase(cs->c, "Allocate_out_of_memory");
146}
147
148static void OpenSession_error_notExistingTA(struct xtest_session *cs)
149{
150 Do_ADBG_BeginSubCase(cs->c, "OpenSession_error_notExistingTA");
151 {
152 TEEC_UUID NONEXISTING_TA_UUID = { 0x534D1192, 0x6143, 0x234C,
153 { 0x47, 0x55, 0x53, 0x52,
154 0x54, 0x4F, 0x4F, 0x59 } };
155 uint32_t ret_orig;
156
Jens Wiklander72c55452016-10-27 20:44:35 +0200157 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
158 TEEC_InitializeContext(_device, &cs->context)))
159 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200160
161 ADBG_EXPECT_COMPARE_UNSIGNED(cs->c, TEEC_SUCCESS, !=,
162 TEEC_OpenSession(&cs->context, &cs->session,
163 &NONEXISTING_TA_UUID,
164 TEEC_LOGIN_PUBLIC, NULL, NULL,
165 &ret_orig));
166 ADBG_EXPECT_COMPARE_UNSIGNED(cs->c, TEEC_ORIGIN_TRUSTED_APP, !=,
167 ret_orig);
168 TEEC_FinalizeContext(&cs->context);
169 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200170out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200171 Do_ADBG_EndSubCase(cs->c, "OpenSession_error_notExistingTA");
172}
173
174static void Allocate_InOut(struct xtest_session *cs)
175{
176 Do_ADBG_BeginSubCase(cs->c, "Allocate_InOut");
177 {
178 TEEC_SharedMemory shm;
179 uint8_t val[] = { 54, 76, 98, 32 };
180
Jens Wiklander72c55452016-10-27 20:44:35 +0200181 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
182 TEEC_InitializeContext(_device, &cs->context)))
183 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200184
Jens Wiklander72c55452016-10-27 20:44:35 +0200185 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200186 AllocateSharedMemory(&cs->context, &shm, sizeof(val),
Jens Wiklander72c55452016-10-27 20:44:35 +0200187 TEEC_MEM_INPUT | TEEC_MEM_OUTPUT)))
188 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200189
190 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200191out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200192 TEEC_FinalizeContext(&cs->context);
193 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200194out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200195 Do_ADBG_EndSubCase(cs->c, "Allocate_InOut");
196}
197
198static void Register_In(struct xtest_session *cs)
199{
200 Do_ADBG_BeginSubCase(cs->c, "Register_In");
201 {
202 TEEC_SharedMemory shm;
203 uint8_t val[] = { 32, 65, 43, 21, 98 };
204
Jens Wiklander72c55452016-10-27 20:44:35 +0200205 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
206 TEEC_InitializeContext(_device, &cs->context)))
207 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200208
209 shm.buffer = val;
210
Jens Wiklander72c55452016-10-27 20:44:35 +0200211 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200212 RegisterSharedMemory(&cs->context, &shm, sizeof(val),
Jens Wiklander72c55452016-10-27 20:44:35 +0200213 TEEC_MEM_INPUT)))
214 goto out_final;
215
Pascal Brandc639ac82015-07-02 08:53:34 +0200216 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200217out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200218 TEEC_FinalizeContext(&cs->context);
219 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200220out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200221 Do_ADBG_EndSubCase(cs->c, "Register_In");
222}
223
224static void Register_notZeroLength_Out(struct xtest_session *cs)
225{
226 Do_ADBG_BeginSubCase(cs->c, "Register_notZeroLength_Out");
227 {
228 TEEC_SharedMemory shm;
229 uint8_t val[] = { 56, 67, 78, 99 };
230
Jens Wiklander72c55452016-10-27 20:44:35 +0200231 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
232 TEEC_InitializeContext(_device, &cs->context)))
233 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200234
235 shm.buffer = val;
236
Jens Wiklander72c55452016-10-27 20:44:35 +0200237 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
238 RegisterSharedMemory(&cs->context, &shm, sizeof(val),
239 TEEC_MEM_OUTPUT)))
240 goto out_final;
241
Pascal Brandc639ac82015-07-02 08:53:34 +0200242 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200243out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200244 TEEC_FinalizeContext(&cs->context);
245 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200246out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200247 Do_ADBG_EndSubCase(cs->c, "Register_notZeroLength_Out");
248}
249
250static void Register_InOut(struct xtest_session *cs)
251{
252 Do_ADBG_BeginSubCase(cs->c, "Register_InOut");
253 {
254 TEEC_SharedMemory shm;
255 uint8_t val[] = { 54, 76, 23, 98, 255, 23, 86 };
256
Jens Wiklander72c55452016-10-27 20:44:35 +0200257 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
258 TEEC_InitializeContext(_device, &cs->context)))
259 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200260
261 shm.buffer = val;
Jens Wiklander72c55452016-10-27 20:44:35 +0200262 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200263 RegisterSharedMemory(&cs->context, &shm, sizeof(val),
Jens Wiklander72c55452016-10-27 20:44:35 +0200264 TEEC_MEM_INPUT | TEEC_MEM_OUTPUT)))
265 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200266
267 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200268out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200269 TEEC_FinalizeContext(&cs->context);
270 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200271out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200272 Do_ADBG_EndSubCase(cs->c, "Register_InOut");
273}
274
275static void Register_zeroLength_Out(struct xtest_session *cs)
276{
277 Do_ADBG_BeginSubCase(cs->c, "Register_zeroLength_Out");
278 {
279 uint8_t val[] = { 65, 76, 98, 32 };
280 TEEC_SharedMemory shm;
281
Jens Wiklander72c55452016-10-27 20:44:35 +0200282 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
283 TEEC_InitializeContext(_device, &cs->context)))
284 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200285
286 shm.buffer = val;
Jens Wiklander72c55452016-10-27 20:44:35 +0200287 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
288 RegisterSharedMemory(&cs->context, &shm, 0,
289 TEEC_MEM_OUTPUT)))
290 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200291
292 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200293out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200294 TEEC_FinalizeContext(&cs->context);
295 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200296out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200297 Do_ADBG_EndSubCase(cs->c, "Register_zeroLength_Out");
298}
299
300static void Allocate_Out(struct xtest_session *cs)
301{
302 Do_ADBG_BeginSubCase(cs->c, "Allocate_Out");
303 {
304 TEEC_SharedMemory shm;
305
Jens Wiklander72c55452016-10-27 20:44:35 +0200306 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
307 TEEC_InitializeContext(_device, &cs->context)))
308 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200309
Jens Wiklander72c55452016-10-27 20:44:35 +0200310 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200311 AllocateSharedMemory(&cs->context, &shm, 0,
Jens Wiklander72c55452016-10-27 20:44:35 +0200312 TEEC_MEM_OUTPUT)))
313 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200314
315 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200316out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200317 TEEC_FinalizeContext(&cs->context);
318 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200319out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200320 Do_ADBG_EndSubCase(cs->c, "Allocate_Out");
321}
322
323static void FinalizeContext_null(struct xtest_session *cs)
324{
325 Do_ADBG_BeginSubCase(cs->c, "FinalizeContext_null");
326 {
327 TEEC_FinalizeContext(NULL);
328 }
329 Do_ADBG_EndSubCase(cs->c, "FinalizeContext_null");
330}
331
332static void InitializeContext_NotExistingTEE(struct xtest_session *cs)
333{
334 Do_ADBG_BeginSubCase(cs->c, "InitializeContext_NotExistingTEE");
335 {
Jens Wiklander72c55452016-10-27 20:44:35 +0200336 if (!ADBG_EXPECT_COMPARE_UNSIGNED(cs->c, TEEC_SUCCESS, !=,
Pascal Brandc639ac82015-07-02 08:53:34 +0200337 TEEC_InitializeContext("Invalid TEE name",
Jens Wiklander72c55452016-10-27 20:44:35 +0200338 &cs->context)))
339 TEEC_FinalizeContext(&cs->context);
Pascal Brandc639ac82015-07-02 08:53:34 +0200340 }
341 Do_ADBG_EndSubCase(cs->c, "InitializeContext_NotExistingTEE");
342}
343
344static void AllocateThenRegister_SameMemory(struct xtest_session *cs)
345{
346 Do_ADBG_BeginSubCase(cs->c, "AllocateThenRegister_SameMemory");
347 {
348 TEEC_SharedMemory shm;
349 uint32_t size_allocation = 32;
350
Jens Wiklander72c55452016-10-27 20:44:35 +0200351 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
352 TEEC_InitializeContext(_device, &cs->context)))
353 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200354
Jens Wiklander72c55452016-10-27 20:44:35 +0200355 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200356 AllocateSharedMemory(&cs->context, &shm,
Jens Wiklander72c55452016-10-27 20:44:35 +0200357 size_allocation, TEEC_MEM_INPUT)))
358 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200359
360 ADBG_EXPECT_TEEC_SUCCESS(cs->c,
361 RegisterSharedMemory(&cs->context, &shm,
362 size_allocation, TEEC_MEM_INPUT));
Jens Wiklander72c55452016-10-27 20:44:35 +0200363
364 TEEC_ReleaseSharedMemory(&shm);
365out_final:
366 TEEC_FinalizeContext(&cs->context);
Pascal Brandc639ac82015-07-02 08:53:34 +0200367 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200368out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200369 Do_ADBG_EndSubCase(cs->c, "AllocateThenRegister_SameMemory");
370}
371
372static void AllocateSameMemory_twice(struct xtest_session *cs)
373{
374 Do_ADBG_BeginSubCase(cs->c, "AllocateSameMemory_twice");
375 {
376 TEEC_SharedMemory shm;
377 uint32_t size_allocation = 32;
378
Jens Wiklander72c55452016-10-27 20:44:35 +0200379 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
380 TEEC_InitializeContext(_device, &cs->context)))
381 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200382
Jens Wiklander72c55452016-10-27 20:44:35 +0200383 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200384 AllocateSharedMemory(&cs->context, &shm,
Jens Wiklander72c55452016-10-27 20:44:35 +0200385 size_allocation, TEEC_MEM_INPUT)))
386 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200387
388 ADBG_EXPECT_TEEC_SUCCESS(cs->c,
389 AllocateSharedMemory(&cs->context, &shm,
390 size_allocation, TEEC_MEM_INPUT));
391
392 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200393out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200394 TEEC_FinalizeContext(&cs->context);
395 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200396out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200397 Do_ADBG_EndSubCase(cs->c, "AllocateSameMemory_twice");
398}
399
400static void RegisterSameMemory_twice(struct xtest_session *cs)
401{
402 Do_ADBG_BeginSubCase(cs->c, "RegisterSameMemory_twice");
403 {
404 uint8_t val[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
405 TEEC_SharedMemory shm;
406
Jens Wiklander72c55452016-10-27 20:44:35 +0200407 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
408 TEEC_InitializeContext(_device, &cs->context)))
409 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200410
411 shm.buffer = val;
Jens Wiklander72c55452016-10-27 20:44:35 +0200412 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200413 RegisterSharedMemory(&cs->context, &shm, sizeof(val),
Jens Wiklander72c55452016-10-27 20:44:35 +0200414 TEEC_MEM_INPUT)))
415 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200416
417 ADBG_EXPECT_TEEC_SUCCESS(cs->c,
418 RegisterSharedMemory(&cs->context, &shm, sizeof(val),
419 TEEC_MEM_INPUT));
420
421 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200422out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200423 TEEC_FinalizeContext(&cs->context);
424 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200425out:
Pascal Brandc639ac82015-07-02 08:53:34 +0200426 Do_ADBG_EndSubCase(cs->c, "RegisterSameMemory_twice");
427}
428
Jerome Forissiercefbe022017-05-23 11:02:35 +0200429#ifndef MIN
430#define MIN(a,b) ((a) < (b) ? (a) : (b))
431#endif
432
433static void Allocate_sharedMemory_32k(struct xtest_session *cs)
Pascal Brandc639ac82015-07-02 08:53:34 +0200434{
Jerome Forissiercefbe022017-05-23 11:02:35 +0200435 Do_ADBG_BeginSubCase(cs->c, "Allocate_sharedMemory_32k");
Pascal Brandc639ac82015-07-02 08:53:34 +0200436 {
Jerome Forissiercefbe022017-05-23 11:02:35 +0200437 uint32_t size = MIN(32 * 1024,
438 TEEC_CONFIG_SHAREDMEM_MAX_SIZE);
Pascal Brandc639ac82015-07-02 08:53:34 +0200439 TEEC_SharedMemory shm;
440
Jens Wiklander72c55452016-10-27 20:44:35 +0200441 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
442 TEEC_InitializeContext(_device, &cs->context)))
443 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200444
Jens Wiklander72c55452016-10-27 20:44:35 +0200445 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Jerome Forissiercefbe022017-05-23 11:02:35 +0200446 AllocateSharedMemory(&cs->context, &shm, size,
Jens Wiklander72c55452016-10-27 20:44:35 +0200447 TEEC_MEM_INPUT)))
448 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200449
450 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200451out_final:
452 TEEC_FinalizeContext(&cs->context);
Pascal Brandc639ac82015-07-02 08:53:34 +0200453 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200454out:
Jerome Forissiercefbe022017-05-23 11:02:35 +0200455 Do_ADBG_EndSubCase(cs->c, "Allocate_sharedMemory_32k");
Pascal Brandc639ac82015-07-02 08:53:34 +0200456}
457
Jerome Forissiercefbe022017-05-23 11:02:35 +0200458static void Register_sharedMemory_32k(struct xtest_session *cs)
Pascal Brandc639ac82015-07-02 08:53:34 +0200459{
Jerome Forissiercefbe022017-05-23 11:02:35 +0200460 Do_ADBG_BeginSubCase(cs->c, "Register_sharedMemory_32k");
Pascal Brandc639ac82015-07-02 08:53:34 +0200461 {
Jerome Forissiercefbe022017-05-23 11:02:35 +0200462 uint32_t size = MIN(32 * 1024,
463 TEEC_CONFIG_SHAREDMEM_MAX_SIZE);
464 uint8_t val[size];
Pascal Brandc639ac82015-07-02 08:53:34 +0200465 TEEC_SharedMemory shm;
466
Jens Wiklander72c55452016-10-27 20:44:35 +0200467 if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS,
468 TEEC_InitializeContext(_device, &cs->context)))
469 goto out;
Pascal Brandc639ac82015-07-02 08:53:34 +0200470
471 shm.buffer = val;
Jens Wiklander72c55452016-10-27 20:44:35 +0200472 if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c,
Jerome Forissiercefbe022017-05-23 11:02:35 +0200473 RegisterSharedMemory(&cs->context, &shm, size,
Jens Wiklander72c55452016-10-27 20:44:35 +0200474 TEEC_MEM_INPUT)))
475 goto out_final;
Pascal Brandc639ac82015-07-02 08:53:34 +0200476
477 TEEC_ReleaseSharedMemory(&shm);
Jens Wiklander72c55452016-10-27 20:44:35 +0200478out_final:
Pascal Brandc639ac82015-07-02 08:53:34 +0200479 TEEC_FinalizeContext(&cs->context);
480 }
Jens Wiklander72c55452016-10-27 20:44:35 +0200481out:
Jerome Forissiercefbe022017-05-23 11:02:35 +0200482 Do_ADBG_EndSubCase(cs->c, "Register_sharedMemory_32k");
Pascal Brandc639ac82015-07-02 08:53:34 +0200483}
484
485static void xtest_teec_TEE(ADBG_Case_t *c)
486{
487 struct xtest_session connection = { c };
488
489 CloseSession_null(&connection);
490
491 Allocate_In(&connection);
492
493 Allocate_out_of_memory(&connection);
494
495 OpenSession_error_notExistingTA(&connection);
496
497 Allocate_InOut(&connection);
498
499 Register_In(&connection);
500
501 Register_notZeroLength_Out(&connection);
502
503 Register_InOut(&connection);
504
505 Register_zeroLength_Out(&connection);
506
507 Allocate_Out(&connection);
508
509 FinalizeContext_null(&connection);
510
511 InitializeContext_NotExistingTEE(&connection);
512
513 AllocateThenRegister_SameMemory(&connection);
514
515 AllocateSameMemory_twice(&connection);
516
517 RegisterSameMemory_twice(&connection);
518
Jerome Forissiercefbe022017-05-23 11:02:35 +0200519 Allocate_sharedMemory_32k(&connection);
Pascal Brandc639ac82015-07-02 08:53:34 +0200520
Jerome Forissiercefbe022017-05-23 11:02:35 +0200521 Register_sharedMemory_32k(&connection);
Pascal Brandc639ac82015-07-02 08:53:34 +0200522}
523
Jens Wiklander74abfe32017-01-03 14:17:47 +0100524ADBG_CASE_DEFINE(regression, 5006, xtest_teec_TEE,
Jens Wiklander25a57fe2016-12-26 21:46:24 +0100525 "Tests for Global platform TEEC");