blob: 210c55d8ad48b0096dbe5ec67a2f4a33783ba9be [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#include "xtest_test.h"
20#include "xtest_helpers.h"
21#include "tee_internal_api.h"
22#include "tee_api_defines.h"
23#include "tee_client_api.h"
24#include "xml_client_api.h"
25
26static bool xtest_init = false;
27
28static bool xtest_tee_init(ADBG_Case_t *c)
29{
30 if (xtest_init)
31 return true;
32
33 SHARE_MEM01 = malloc(sizeof(TEEC_SharedMemory));
34 if (!ADBG_EXPECT_NOT_NULL(c, SHARE_MEM01))
35 goto exit;
36
37 SHARE_MEM02 = malloc(sizeof(TEEC_SharedMemory));
38 if (!ADBG_EXPECT_NOT_NULL(c, SHARE_MEM02))
39 goto exit;
40
41 SESSION01 = malloc(sizeof(TEEC_Session));
42 if (!ADBG_EXPECT_NOT_NULL(c, SESSION01))
43 goto exit;
44
45 CONTEXT01 = malloc(sizeof(TEEC_Context));
46 if (!ADBG_EXPECT_NOT_NULL(c, CONTEXT01))
47 goto exit;
48
49 OPERATION01 = malloc(sizeof(TEEC_Operation));
50 if (!ADBG_EXPECT_NOT_NULL(c, OPERATION01))
51 goto exit;
52
53 OPERATION02 = malloc(sizeof(TEEC_Operation));
54 if (!ADBG_EXPECT_NOT_NULL(c, OPERATION02))
55 goto exit;
56
57 xtest_init = true;
58
59 return xtest_init;
60
61exit:
62 if (SHARE_MEM01) {
63 free(SHARE_MEM01);
64 SHARE_MEM01 = NULL;
65 }
66 if (SHARE_MEM02) {
67 free(SHARE_MEM02);
68 SHARE_MEM02 = NULL;
69 }
70 if (SESSION01) {
71 free(SESSION01);
72 SESSION01 = NULL;
73 }
74 if (CONTEXT01) {
75 free(CONTEXT01);
76 CONTEXT01 = NULL;
77 }
78 if (OPERATION01) {
79 free(OPERATION01);
80 OPERATION01 = NULL;
81 }
82 if (OPERATION02) {
83 free(OPERATION02);
84 OPERATION02 = NULL;
85 }
86
87 xtest_init = false;
88 return xtest_init;
89}
90
91/*29-84-6d*/
92static void xtest_tee_7001(ADBG_Case_t *c)
93{
94 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
95 return;
96 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
97 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
98 ADBG_EXPECT(c, TEEC_SUCCESS,
99 AllocateSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01,
100 TEEC_MEM_INPUT));
101 TEEC_ReleaseSharedMemory(SHARE_MEM01);
102 TEEC_FinalizeContext(CONTEXT01);
103}
104
105/*29-c2-4c*/
106static void xtest_tee_7002(ADBG_Case_t *c)
107{
108 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
109 return;
110 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
111 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
112 ADBG_EXPECT(c, TEEC_ERROR_OUT_OF_MEMORY,
113 AllocateSharedMemory(CONTEXT01, SHARE_MEM01,
114 SIZE_OVER_MEMORY, TEEC_MEM_INPUT));
115 TEEC_FinalizeContext(CONTEXT01);
116}
117
118/*29-b0-da*/
119static void xtest_tee_7003(ADBG_Case_t *c)
120{
121 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
122 return;
123 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
124 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
125 ADBG_EXPECT(c, TEEC_SUCCESS,
126 AllocateSharedMemory(CONTEXT01, SHARE_MEM01, BIG_SIZE,
127 TEEC_MEM_OUTPUT));
128 TEEC_ReleaseSharedMemory(NULL);
129 TEEC_ReleaseSharedMemory(SHARE_MEM01);
130 TEEC_FinalizeContext(CONTEXT01);
131}
132
133/*29-1c-00*/
134static void xtest_tee_7004(ADBG_Case_t *c)
135{
136 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
137 return;
138 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
139 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
140 ADBG_EXPECT(c, TEEC_SUCCESS,
141 AllocateSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01,
142 TEEC_MEM_INOUT));
143 TEEC_ReleaseSharedMemory(SHARE_MEM01);
144 TEEC_FinalizeContext(CONTEXT01);
145}
146
147/*29-9f-a2*/
148static void xtest_tee_7005(ADBG_Case_t *c)
149{
150 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
151 return;
152 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
153 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
154 ADBG_EXPECT(c, TEEC_SUCCESS,
155 RegisterSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01,
156 TEEC_MEM_INPUT));
157 TEEC_ReleaseSharedMemory(SHARE_MEM01);
158 TEEC_FinalizeContext(CONTEXT01);
159}
160
161/*29-11-02*/
162static void xtest_tee_7006(ADBG_Case_t *c)
163{
164 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
165 return;
166 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
167 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
168 ADBG_EXPECT(c, TEEC_SUCCESS,
169 RegisterSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01,
170 TEEC_MEM_OUTPUT));
171 TEEC_ReleaseSharedMemory(SHARE_MEM01);
172 TEEC_FinalizeContext(CONTEXT01);
173}
174
175/*29-1f-a2*/
176static void xtest_tee_7007(ADBG_Case_t *c)
177{
178 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
179 return;
180 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
181 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
182 ADBG_EXPECT(c, TEEC_SUCCESS,
183 RegisterSharedMemory(CONTEXT01, SHARE_MEM01, BIG_SIZE,
184 TEEC_MEM_INOUT));
185 TEEC_ReleaseSharedMemory(SHARE_MEM01);
186 TEEC_FinalizeContext(CONTEXT01);
187}
188
189/*29-2e-8d*/
190static void xtest_tee_7008(ADBG_Case_t *c)
191{
192 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
193 return;
194 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
195 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
196 ADBG_EXPECT(c, TEEC_SUCCESS,
197 RegisterSharedMemory(CONTEXT01, SHARE_MEM01, ZERO,
198 TEEC_MEM_OUTPUT));
199 TEEC_ReleaseSharedMemory(SHARE_MEM01);
200 TEEC_FinalizeContext(CONTEXT01);
201}
202
203/*29-2b-3f*/
204static void xtest_tee_7009(ADBG_Case_t *c)
205{
206 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
207 return;
208 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
209 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
210 XML_OpenSession(c, CONTEXT01, SESSION01, &UUID_Unknown,
211 TEEC_LOGIN_PUBLIC, NULL, NULL,
212 TEEC_ORIGIN_ANY_NOT_TRUSTED_APP, TEEC_UNDEFINED_ERROR);
213 TEEC_FinalizeContext(CONTEXT01);
214}
215
216/*29-cd-39*/
217static void xtest_tee_7010(ADBG_Case_t *c)
218{
219 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
220 return;
221 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
222 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
223 ADBG_EXPECT(c, TEEC_SUCCESS,
224 AllocateSharedMemory(CONTEXT01, SHARE_MEM01, ZERO,
225 TEEC_MEM_OUTPUT));
226 TEEC_ReleaseSharedMemory(SHARE_MEM01);
227 TEEC_FinalizeContext(CONTEXT01);
228}
229
230/*29-f0-9c*/
231static void xtest_tee_7011(ADBG_Case_t *c)
232{
233 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
234 return;
235 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
236 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
237 XML_OpenSession(c, CONTEXT01, SESSION01,
238 &UUID_TTA_answerSuccessTo_OpenSession_Invoke,
239 TEEC_LOGIN_PUBLIC, NULL, NULL, 0, TEEC_SUCCESS);
240 TEEC_CloseSession(SESSION01);
241 TEEC_FinalizeContext(CONTEXT01);
242}
243
244/*29-4d-b0*/
245static void xtest_tee_7012(ADBG_Case_t *c)
246{
247 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
248 return;
249 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
250 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
251 XML_OpenSession(c, CONTEXT01, SESSION01,
252 &UUID_TTA_answerErrorTo_OpenSession, TEEC_LOGIN_PUBLIC,
253 NULL, NULL, TEEC_ORIGIN_TRUSTED_APP,
254 TEEC_ERROR_GENERIC);
255 TEEC_FinalizeContext(CONTEXT01);
256}
257
258/*29-a2-e3*/
259static void xtest_tee_7013(ADBG_Case_t *c)
260{
261 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
262 return;
263 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
264 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
265 XML_OpenSession(c, CONTEXT01, SESSION01,
266 &UUID_TTA_answerSuccessTo_OpenSession_Invoke,
267 INVALID_CONNECTION_METHODS, NULL, NULL,
268 TEEC_ORIGIN_ANY_NOT_TRUSTED_APP, TEEC_UNDEFINED_ERROR);
269 TEEC_FinalizeContext(CONTEXT01);
270}
271
272/*29-5d-d8*/
273static void xtest_tee_7014(ADBG_Case_t *c)
274{
275 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
276 return;
277 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
278 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
279 OPERATION_TEEC_PARAM_TYPES(OPERATION01, TEEC_VALUE_INPUT,
280 TEEC_VALUE_INPUT, TEEC_VALUE_INPUT,
281 TEEC_VALUE_INPUT);
282
283 TEEC_prepare_OperationEachParameter_value(OPERATION01, 0, VALUE01,
284 IGNORE);
285 TEEC_prepare_OperationEachParameter_value(OPERATION01, 1, IGNORE,
286 VALUE01);
287 TEEC_prepare_OperationEachParameter_value(OPERATION01, 2, VALUE01,
288 VALUE01);
289 TEEC_prepare_OperationEachParameter_value(OPERATION01, 3, VALUE01,
290 VALUE02);
291
292 XML_OpenSession(c, CONTEXT01, SESSION01,
293 &UUID_TTA_check_OpenSession_with_4_parameters,
294 TEEC_LOGIN_PUBLIC, NULL, OPERATION01, 0,
295 TEEC_SUCCESS);
296 TEEC_CloseSession(SESSION01);
297 TEEC_FinalizeContext(CONTEXT01);
298}
299
300/*29-82-81*/
301static void xtest_tee_7015(ADBG_Case_t *c)
302{
303 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
304 return;
305 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
306 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
307 XML_OpenSession(c, CONTEXT01, SESSION01,
308 &UUID_TTA_answerSuccessTo_OpenSession_Invoke,
309 TEEC_LOGIN_PUBLIC, NULL, NULL, TEEC_ORIGIN_TRUSTED_APP,
310 TEEC_SUCCESS);
311 TEEC_CloseSession(SESSION01);
312 TEEC_FinalizeContext(CONTEXT01);
313}
314
315/*29-db-48*/
316static void xtest_tee_7016(ADBG_Case_t *c)
317{
318 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
319 return;
320 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
321 TEEC_CloseSession(NULL);
322}
323
324/*29-a1-83*/
325static void xtest_tee_7017(ADBG_Case_t *c)
326{
327 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
328 return;
329 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
330 XML_InitializeContext(c, INVALID_NOT_EXISTING_TEE, CONTEXT01,
331 TEEC_UNDEFINED_ERROR);
332}
333
334/*29-c1-a5*/
335static void xtest_tee_7018(ADBG_Case_t *c)
336{
337 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
338 return;
339 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
340 TEEC_FinalizeContext(NULL);
341}
342
343/*29-91-aa*/
344static void xtest_tee_7019(ADBG_Case_t *c)
345{
346 if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c)))
347 return;
348 TEEC_createThread(CLIENT_APP01, THREAD02);
349 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
350 XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS);
351 TEEC_SelectApp(CLIENT_APP01, THREAD02);
352 thr2_ctx.c = c;
353 thr2_ctx.ctx = CONTEXT01;
354 ctx_init_finalize(thr2_ctx);
355 TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT);
356 TEEC_FinalizeContext(CONTEXT01);
357}
358
359ADBG_CASE_DEFINE(XTEST_TEE_7001, xtest_tee_7001,
360 /* Title */
361 "29-84-6d",
362 /* Short description */
363 "Allocate_In",
364 /* Requirement IDs */
365 "RELEASE_SHARED_MEMORY_WHEN_ALLOCATED",
366 /* How to implement */
367 "Description of how to implement ...");
368ADBG_CASE_DEFINE(XTEST_TEE_7002, xtest_tee_7002,
369 /* Title */
370 "29-c2-4c",
371 /* Short description */
372 "Allocate_out_of_memory",
373 /* Requirement IDs */
374 "INITIALIZE_CONTEXT_NAMES",
375 /* How to implement */
376 "Description of how to implement ...");
377ADBG_CASE_DEFINE(XTEST_TEE_7003, xtest_tee_7003,
378 /* Title */
379 "29-b0-da",
380 /* Short description */
381 "ReleaseSharedMemory_null",
382 /* Requirement IDs */
383 "RELEASE_SHARED_MEMORY_WHEN_ALLOCATED",
384 /* How to implement */
385 "Description of how to implement ...");
386ADBG_CASE_DEFINE(XTEST_TEE_7004, xtest_tee_7004,
387 /* Title */
388 "29-1c-00",
389 /* Short description */
390 "Allocate_InOut",
391 /* Requirement IDs */
392 "RELEASE_SHARED_MEMORY_WHEN_ALLOCATED",
393 /* How to implement */
394 "Description of how to implement ...");
395ADBG_CASE_DEFINE(XTEST_TEE_7005, xtest_tee_7005,
396 /* Title */
397 "29-9f-a2",
398 /* Short description */
399 "Register_In",
400 /* Requirement IDs */
401 "RELEASE_SHARED_MEMORY_WHEN_REGISTERED",
402 /* How to implement */
403 "Description of how to implement ...");
404ADBG_CASE_DEFINE(XTEST_TEE_7006, xtest_tee_7006,
405 /* Title */
406 "29-11-02",
407 /* Short description */
408 "Register_notZeroLength_Out",
409 /* Requirement IDs */
410 "RELEASE_SHARED_MEMORY_WHEN_REGISTERED",
411 /* How to implement */
412 "Description of how to implement ...");
413ADBG_CASE_DEFINE(XTEST_TEE_7007, xtest_tee_7007,
414 /* Title */
415 "29-1f-a2",
416 /* Short description */
417 "Register_InOut",
418 /* Requirement IDs */
419 "RELEASE_SHARED_MEMORY_WHEN_REGISTERED",
420 /* How to implement */
421 "Description of how to implement ...");
422ADBG_CASE_DEFINE(XTEST_TEE_7008, xtest_tee_7008,
423 /* Title */
424 "29-2e-8d",
425 /* Short description */
426 "Register_zeroLength_Out",
427 /* Requirement IDs */
428 "RELEASE_SHARED_MEMORY_WHEN_REGISTERED",
429 /* How to implement */
430 "Description of how to implement ...");
431ADBG_CASE_DEFINE(XTEST_TEE_7009, xtest_tee_7009,
432 /* Title */
433 "29-2b-3f",
434 /* Short description */
435 "OpenSession_error_notExistingTA",
436 /* Requirement IDs */
437 "OPEN_SESSION_TARGET_TRUSTED_APP",
438 /* How to implement */
439 "Description of how to implement ...");
440ADBG_CASE_DEFINE(XTEST_TEE_7010, xtest_tee_7010,
441 /* Title */
442 "29-cd-39",
443 /* Short description */
444 "Allocate_Out",
445 /* Requirement IDs */
446 "RELEASE_SHARED_MEMORY_WHEN_ALLOCATED",
447 /* How to implement */
448 "Description of how to implement ...");
449ADBG_CASE_DEFINE(XTEST_TEE_7011, xtest_tee_7011,
450 /* Title */
451 "29-f0-9c",
452 /* Short description */
453 "OpenSession_success_nullReturnOrigin",
454 /* Requirement IDs */
455 "OPEN_SESSION_TARGET_TRUSTED_APP",
456 /* How to implement */
457 "Description of how to implement ...");
458ADBG_CASE_DEFINE(XTEST_TEE_7012, xtest_tee_7012,
459 /* Title */
460 "29-4d-b0",
461 /* Short description */
462 "OpenSession_error_originTrustedApp",
463 /* Requirement IDs */
464 "OPEN_SESSION_TARGET_TRUSTED_APP",
465 /* How to implement */
466 "Description of how to implement ...");
467ADBG_CASE_DEFINE(XTEST_TEE_7013, xtest_tee_7013,
468 /* Title */
469 "29-a2-e3",
470 /* Short description */
471 "OpenSession_error_originTEE",
472 /* Requirement IDs */
473 "OPEN_SESSION_TARGET_TRUSTED_APP",
474 /* How to implement */
475 "Description of how to implement ...");
476ADBG_CASE_DEFINE(XTEST_TEE_7014, xtest_tee_7014,
477 /* Title */
478 "29-5d-d8",
479 /* Short description */
480 "OpenSession_with_operation_parameters",
481 /* Requirement IDs */
482 "OPEN_SESSION_TARGET_TRUSTED_APP",
483 /* How to implement */
484 "Description of how to implement ...");
485ADBG_CASE_DEFINE(XTEST_TEE_7015, xtest_tee_7015,
486 /* Title */
487 "29-82-81",
488 /* Short description */
489 "OpenSession_success_originTrustedApp",
490 /* Requirement IDs */
491 "OPEN_SESSION_TARGET_TRUSTED_APP",
492 /* How to implement */
493 "Description of how to implement ...");
494ADBG_CASE_DEFINE(XTEST_TEE_7016, xtest_tee_7016,
495 /* Title */
496 "29-db-48",
497 /* Short description */
498 "CloseSession_null",
499 /* Requirement IDs */
500 "CLOSE_SESSION_IGNORE_SESSION_NULL",
501 /* How to implement */
502 "Description of how to implement ...");
503ADBG_CASE_DEFINE(XTEST_TEE_7017, xtest_tee_7017,
504 /* Title */
505 "29-a1-83",
506 /* Short description */
507 "InitializeContext_NotExistingTEE",
508 /* Requirement IDs */
509 "INITIALIZE_CONTEXT_NAMES",
510 /* How to implement */
511 "Description of how to implement ...");
512ADBG_CASE_DEFINE(XTEST_TEE_7018, xtest_tee_7018,
513 /* Title */
514 "29-c1-a5",
515 /* Short description */
516 "FinalizeContext_null",
517 /* Requirement IDs */
518 "FINALIZE_CONTEXT_IGNORE_NULL",
519 /* How to implement */
520 "Description of how to implement ...");
521ADBG_CASE_DEFINE(XTEST_TEE_7019, xtest_tee_7019,
522 /* Title */
523 "29-91-aa",
524 /* Short description */
525 "InitializeContext_concurrentContext",
526 /* Requirement IDs */
527 "INITIALIZE_CONTEXT_NAMES",
528 /* How to implement */
529 "Description of how to implement ...");