blob: 3ca872ee72b975fb70cbbee5ec4c4c693f588250 [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 <string.h>
15#include <stdio.h>
16
17#include <adbg.h>
18#include <xtest_test.h>
19#include <xtest_helpers.h>
20
21#include <tee_client_api.h>
22#include <ta_storage.h>
23#include <tee_api_defines.h>
24#include <tee_api_types.h>
Jerome Forissiere3688342015-09-24 10:45:17 -070025#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +020026#include <TTA_DS_protocol.h>
27#endif
Pascal Brandc639ac82015-07-02 08:53:34 +020028
29static uint8_t file_00[] = {
30 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
31 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
32 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
33 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
34};
35
36static uint8_t file_01[] = {
37 0x01, 0x00
38};
39
40static uint8_t file_02[] = {
41 0x02, 0x11, 0x02
42};
43
44static uint8_t file_03[] = {
45 0x03, 0x13, 0x03
46};
47
Pascal Brandeb84c442016-04-19 17:49:49 +020048static uint8_t file_04[] = {
49 0x00, 0x01, 0x02
50};
51
Pascal Brandc639ac82015-07-02 08:53:34 +020052static uint8_t data_00[] = {
53 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
54 0x00, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
55 0x00, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
56 0x00, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x00
57};
58
59static uint8_t data_01[] = {
60 0x01, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
61 0x01, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
62 0x01, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
63 0x01, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x01
64};
65
66static TEEC_Result fs_open(TEEC_Session *sess, void *id, uint32_t id_size,
67 uint32_t flags, uint32_t *obj)
68{
Aijun Sun473d9072015-08-06 15:24:49 +080069 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020070 TEEC_Result res;
71 uint32_t org;
72
73 op.params[0].tmpref.buffer = id;
74 op.params[0].tmpref.size = id_size;
75 op.params[1].value.a = flags;
76 op.params[1].value.b = 0;
77
78 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
79 TEEC_VALUE_INOUT, TEEC_NONE,
80 TEEC_NONE);
81
82 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_OPEN, &op, &org);
83
84 if (res == TEEC_SUCCESS)
85 *obj = op.params[1].value.b;
86
87 return res;
88}
89
90static TEEC_Result fs_create(TEEC_Session *sess, void *id, uint32_t id_size,
91 uint32_t flags, uint32_t attr, void *data,
92 uint32_t data_size, uint32_t *obj)
93{
Aijun Sun473d9072015-08-06 15:24:49 +080094 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020095 TEEC_Result res;
96 uint32_t org;
97
98 op.params[0].tmpref.buffer = id;
99 op.params[0].tmpref.size = id_size;
100 op.params[1].value.a = flags;
101 op.params[1].value.b = 0;
102 op.params[2].value.a = attr;
103 op.params[2].value.b = 0;
104 op.params[3].tmpref.buffer = data;
105 op.params[3].tmpref.size = data_size;
106
107 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
108 TEEC_VALUE_INOUT, TEEC_VALUE_INPUT,
109 TEEC_MEMREF_TEMP_INPUT);
110
111 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE, &op, &org);
112
113 if (res == TEEC_SUCCESS)
114 *obj = op.params[1].value.b;
115
116 return res;
117}
118
Pascal Brandeb84c442016-04-19 17:49:49 +0200119static TEEC_Result fs_create_overwrite(TEEC_Session *sess, void *id,
120 uint32_t id_size)
121{
122 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
123 TEEC_Result res;
124 uint32_t org;
125
126 op.params[0].tmpref.buffer = id;
127 op.params[0].tmpref.size = id_size;
128
129 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
130 TEEC_NONE, TEEC_NONE,
131 TEEC_NONE);
132
133 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE_OVERWRITE, &op, &org);
134
135 return res;
136}
137
Pascal Brandc639ac82015-07-02 08:53:34 +0200138static TEEC_Result fs_close(TEEC_Session *sess, uint32_t obj)
139{
Aijun Sun473d9072015-08-06 15:24:49 +0800140 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200141 uint32_t org;
142
143 op.params[0].value.a = obj;
144
145 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
146 TEEC_NONE, TEEC_NONE);
147
148 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CLOSE, &op, &org);
149}
150
151static TEEC_Result fs_read(TEEC_Session *sess, uint32_t obj, void *data,
152 uint32_t data_size, uint32_t *count)
153{
154 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800155 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200156 uint32_t org;
157
158 op.params[0].tmpref.buffer = data;
159 op.params[0].tmpref.size = data_size;
160 op.params[1].value.a = obj;
161 op.params[1].value.b = 0;
162
163 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT,
164 TEEC_VALUE_INOUT, TEEC_NONE,
165 TEEC_NONE);
166
167 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_READ, &op, &org);
168
169 if (res == TEEC_SUCCESS)
170 *count = op.params[1].value.b;
171
172 return res;
173}
174
175static TEEC_Result fs_write(TEEC_Session *sess, uint32_t obj, void *data,
176 uint32_t data_size)
177{
Aijun Sun473d9072015-08-06 15:24:49 +0800178 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200179 uint32_t org;
180
181 op.params[0].tmpref.buffer = data;
182 op.params[0].tmpref.size = data_size;
183 op.params[1].value.a = obj;
184 op.params[1].value.b = 0;
185
186 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
187 TEEC_VALUE_INPUT, TEEC_NONE,
188 TEEC_NONE);
189
190 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_WRITE, &op, &org);
191}
192
193static TEEC_Result fs_seek(TEEC_Session *sess, uint32_t obj, int32_t offset,
194 int32_t whence)
195{
Aijun Sun473d9072015-08-06 15:24:49 +0800196 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200197 uint32_t org;
198
199 op.params[0].value.a = obj;
200 op.params[0].value.b = offset;
201 op.params[1].value.a = whence;
202
203 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_INOUT,
204 TEEC_NONE, TEEC_NONE);
205
206 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_SEEK, &op, &org);
207}
208
209static TEEC_Result fs_unlink(TEEC_Session *sess, uint32_t obj)
210{
Aijun Sun473d9072015-08-06 15:24:49 +0800211 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200212 uint32_t org;
213
214 op.params[0].value.a = obj;
215
216 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
217 TEEC_NONE, TEEC_NONE);
218
219 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_UNLINK, &op, &org);
220}
221
222static TEEC_Result fs_trunc(TEEC_Session *sess, uint32_t obj, uint32_t len)
223{
Aijun Sun473d9072015-08-06 15:24:49 +0800224 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200225 uint32_t org;
226
227 op.params[0].value.a = obj;
228 op.params[0].value.b = len;
229
230 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
231 TEEC_NONE, TEEC_NONE);
232
233 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_TRUNC, &op, &org);
234}
235
236static TEEC_Result fs_rename(TEEC_Session *sess, uint32_t obj, void *id,
237 uint32_t id_size)
238{
Aijun Sun473d9072015-08-06 15:24:49 +0800239 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200240 uint32_t org;
241
242 op.params[0].value.a = obj;
243 op.params[1].tmpref.buffer = id;
244 op.params[1].tmpref.size = id_size;
245
246 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
247 TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
248 TEEC_NONE);
249
250 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RENAME, &op, &org);
251}
252
253static TEEC_Result fs_alloc_enum(TEEC_Session *sess, uint32_t *e)
254{
255 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800256 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200257 uint32_t org;
258
259 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
260 TEEC_NONE, TEEC_NONE);
261
262 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_ALLOC_ENUM, &op, &org);
263
264 if (res == TEEC_SUCCESS)
265 *e = op.params[0].value.a;
266
267 return res;
268}
269
270static TEEC_Result fs_free_enum(TEEC_Session *sess, uint32_t e)
271{
Aijun Sun473d9072015-08-06 15:24:49 +0800272 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200273 uint32_t org;
274
275 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
276 TEEC_NONE);
277
278 op.params[0].value.a = e;
279
280 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_FREE_ENUM, &op, &org);
281}
282
283static TEEC_Result fs_start_enum(TEEC_Session *sess, uint32_t e)
284{
Aijun Sun473d9072015-08-06 15:24:49 +0800285 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200286 uint32_t org;
287
288 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
289 TEEC_NONE, TEEC_NONE);
290
291 op.params[0].value.a = e;
292
293 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_START_ENUM, &op, &org);
294}
295
296static TEEC_Result fs_next_enum(TEEC_Session *sess, uint32_t e, void *obj_info,
297 size_t info_size, void *id, uint32_t id_size)
298{
Aijun Sun473d9072015-08-06 15:24:49 +0800299 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200300 uint32_t org;
301
302 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
303 TEEC_MEMREF_TEMP_OUTPUT,
304 TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE);
305
306 op.params[0].value.a = e;
307 op.params[1].tmpref.buffer = obj_info;
308 op.params[1].tmpref.size = info_size;
309 op.params[2].tmpref.buffer = id;
310 op.params[2].tmpref.size = id_size;
311
312 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_NEXT_ENUM, &op, &org);
313}
314
James Kung98c0ba12015-09-09 15:51:59 +0800315/* trunc */
316static void test_truncate_file_length(ADBG_Case_t *c)
317{
318 TEEC_Session sess;
319 uint32_t obj;
320 uint8_t out[10] = { 0 };
321 uint32_t count;
322 uint32_t orig;
323
324 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
325 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
326 return;
327
328 /* create */
329 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
330 fs_create(&sess, file_01, sizeof(file_01),
331 TEE_DATA_FLAG_ACCESS_WRITE |
332 TEE_DATA_FLAG_ACCESS_READ |
333 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
334 sizeof(data_00), &obj)))
335 goto exit;
336
337 /* trunc */
338 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 10)))
339 goto exit;
340
341 /* seek */
342 if (!ADBG_EXPECT_TEEC_SUCCESS(
343 c, fs_seek(&sess, obj, 5, TEE_DATA_SEEK_SET)))
344 goto exit;
345
346 /* verify */
347 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
348 goto exit;
349
350 /* check buffer */
351 (void)ADBG_EXPECT_BUFFER(c, &data_00[5], 5, out, count);
352
353 /* clean */
354 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
355 goto exit;
356
357exit:
358 TEEC_CloseSession(&sess);
359}
360
361/* extend */
362static void test_extend_file_length(ADBG_Case_t *c)
363{
364 TEEC_Session sess;
365 uint32_t obj;
366 uint8_t out[10] = { 0 };
367 uint8_t expect[10] = { 0 };
368 uint32_t count;
369 uint32_t orig;
370
371 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
372 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
373 return;
374
375 /* create */
376 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
377 fs_create(&sess, file_01, sizeof(file_01),
378 TEE_DATA_FLAG_ACCESS_WRITE |
379 TEE_DATA_FLAG_ACCESS_READ |
380 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
381 sizeof(data_00), &obj)))
382 goto exit;
383
384 /* extend */
385 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 40)))
386 goto exit;
387
388 /* seek */
389 if (!ADBG_EXPECT_TEEC_SUCCESS(
390 c, fs_seek(&sess, obj, 30, TEE_DATA_SEEK_SET)))
391 goto exit;
392
393 /* verify */
394 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
395 goto exit;
396
397 /* check buffer */
398 expect[0] = data_00[30];
399 expect[1] = data_00[31];
400 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
401
402 /* clean */
403 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
404 goto exit;
405
406exit:
407 TEEC_CloseSession(&sess);
408}
409
410/* file hole */
411static void test_file_hole(ADBG_Case_t *c)
412{
413 TEEC_Session sess;
414 uint32_t obj;
415 uint8_t out[10] = { 0 };
416 uint8_t expect[10] = { 0 };
417 uint32_t count;
418 uint32_t orig;
419
420 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
421 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
422 return;
423
424 /* create */
425 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
426 fs_create(&sess, file_01, sizeof(file_01),
427 TEE_DATA_FLAG_ACCESS_WRITE |
428 TEE_DATA_FLAG_ACCESS_READ |
429 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
430 sizeof(data_00), &obj)))
431 goto exit;
432
433 /* seek */
434 if (!ADBG_EXPECT_TEEC_SUCCESS(
435 c, fs_seek(&sess, obj, 80, TEE_DATA_SEEK_SET)))
436 goto exit;
437
438 /* write */
439 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_write(&sess, obj, data_00,
440 sizeof(data_00))))
441 goto exit;
442
443 /* seek */
444 if (!ADBG_EXPECT_TEEC_SUCCESS(
445 c, fs_seek(&sess, obj, 74, TEE_DATA_SEEK_SET)))
446 goto exit;
447
448 /* verify */
449 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
450 goto exit;
451
452 /* check buffer */
453 expect[6] = data_00[0];
454 expect[7] = data_00[1];
455 expect[8] = data_00[2];
456 expect[9] = data_00[3];
457 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
458
459 /* clean */
460 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
461 goto exit;
462
463exit:
464 TEEC_CloseSession(&sess);
465}
466
Jerome Forissiere3688342015-09-24 10:45:17 -0700467#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +0200468static TEEC_Result ds_open_access_conf(TEEC_Session *sess)
469{
470 TEEC_Operation op;
471 uint32_t org;
472
473 op.paramTypes = TEEC_PARAM_TYPES(
474 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
475
476 return TEEC_InvokeCommand(
477 sess, CMD_CreatePersistentObject_AccessConflict, &op, &org);
478}
479
480static TEEC_Result ds_res_obj_panic(TEEC_Session *sess)
481{
482 TEEC_Operation op;
483 uint32_t org;
484
485 op.paramTypes = TEEC_PARAM_TYPES(
486 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
487
488 return TEEC_InvokeCommand(
489 sess, CMD_RestrictObjectUsagePanic, &op, &org);
490}
491
492static TEEC_Result ds_seek_obj_inv_handle(TEEC_Session *sess)
493{
494 TEEC_Operation op;
495 uint32_t org;
496
497 op.paramTypes = TEEC_PARAM_TYPES(
498 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
499
500 op.params[0].value.a = CASE_DATA_OBJECT_NOT_PERSISTENT;
501
502 return TEEC_InvokeCommand(
503 sess, CMD_SeekObjectData_panic, &op, &org);
504}
505
506static TEEC_Result ds_seek_obj_bad_handle(TEEC_Session *sess)
507{
508 TEEC_Operation op;
509 uint32_t org;
510
511 op.paramTypes = TEEC_PARAM_TYPES(
512 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
513
514 op.params[0].value.a = CASE_DATA_BAD_HANDLE;
515
516 return TEEC_InvokeCommand(
517 sess, CMD_SeekObjectData_panic, &op, &org);
518}
519
520static TEEC_Result ds_seek_gp(
521 TEEC_Session *sess, TEE_Whence wh, uint32_t wh_off, uint32_t set_off,
522 void *in, size_t in_size, void *out, size_t out_size)
523{
524 TEEC_Operation op;
525 uint32_t org;
526
527 op.paramTypes = TEEC_PARAM_TYPES(
528 TEEC_VALUE_INPUT, TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
529 TEEC_MEMREF_TEMP_OUTPUT);
530
531 op.params[0].value.a = wh;
532 op.params[0].value.b = wh_off;
533 op.params[1].value.a = set_off;
534 op.params[2].tmpref.buffer = in;
535 op.params[2].tmpref.size = in_size;
536 op.params[3].tmpref.buffer = out;
537 op.params[3].tmpref.size = out_size;
538
539 return TEEC_InvokeCommand(sess, CMD_SeekWriteReadObjectData, &op, &org);
540}
541
542static TEEC_Result ds_init_object_and_attributes(TEEC_Session *sess,
543 uint32_t obj_type, uint32_t obj_size, const void *attr_meta,
544 size_t attr_meta_len, const void *attr_data, size_t attr_data_len,
545 uint32_t option)
546{
547 TEEC_Operation op;
548 uint32_t org;
549
550 op.paramTypes = TEEC_PARAM_TYPES(
551 TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
552 TEEC_MEMREF_TEMP_INPUT, TEEC_VALUE_INPUT);
553
554 op.params[0].value.a = obj_type;
555 op.params[0].value.b = obj_size;
556 op.params[1].tmpref.buffer = (void *)attr_meta;
557 op.params[1].tmpref.size = attr_meta_len;
558 op.params[2].tmpref.buffer = (void *)attr_data;
559 op.params[2].tmpref.size = attr_data_len;
560 op.params[3].value.a = option;
561
562 return TEEC_InvokeCommand(sess, CMD_InitObjectAndAttributes, &op, &org);
563}
564
565static TEEC_Result ds_rename_access_conflict(TEEC_Session *sess)
566{
567 TEEC_Operation op;
568 uint32_t org;
569
570 op.paramTypes = TEEC_PARAM_TYPES(
571 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
572
573 return TEEC_InvokeCommand(
574 sess, CMD_RenamePersistentObject_AccessConflict, &op, &org);
575}
576
577static TEEC_Result ds_start_enum_no_item(TEEC_Session *sess)
578{
579 TEEC_Operation op;
580 uint32_t org;
581 TEEC_Result res;
582
583 op.paramTypes = TEEC_PARAM_TYPES(
584 TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
585
586 res = TEEC_InvokeCommand(
587 sess, CMD_StartNGetPersistentObjectEnumerator_itemNotFound, &op, &org);
588
589 if (res != TEEC_SUCCESS)
590 return res;
591
592 if (op.params[0].value.a != 0 || op.params[0].value.b != 0)
593 return TEEC_ERROR_GENERIC;
594
595 return res;
596}
597
598static TEEC_Result ds_rename_success(TEEC_Session *sess)
599{
600 TEEC_Operation op;
601 uint32_t org;
602
603 op.paramTypes = TEEC_PARAM_TYPES(
604 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
605
606 return TEEC_InvokeCommand(
607 sess, CMD_RenamePersistentObject_Success, &op, &org);
608}
609
610static TEEC_Result ds_null_close_free_reset(TEEC_Session *sess)
611{
612 TEEC_Operation op;
613 uint32_t org;
614
615 op.paramTypes = TEEC_PARAM_TYPES(
616 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
617
618 return TEEC_InvokeCommand(
619 sess, CMD_CloseFreeAndResetObjectSuccessHandleNull, &op, &org);
620}
621#endif
622
Pascal Brandc639ac82015-07-02 08:53:34 +0200623/* create */
624static void xtest_tee_test_6001(ADBG_Case_t *c)
625{
626 TEEC_Session sess;
627 uint32_t obj;
628 uint32_t orig;
629
630 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
631 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
632 return;
633
634 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
635 fs_create(&sess, file_00, sizeof(file_00),
636 TEE_DATA_FLAG_ACCESS_WRITE |
637 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
638 sizeof(data_00), &obj)))
639 goto exit;
640
641 /* clean */
642 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
643 goto exit;
644
645exit:
646 TEEC_CloseSession(&sess);
647}
648
649/* open */
650static void xtest_tee_test_6002(ADBG_Case_t *c)
651{
652 TEEC_Session sess;
653 uint32_t obj;
654 uint32_t orig;
655
656 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
657 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
658 return;
659
660 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
661 fs_create(&sess, file_01, sizeof(file_01),
662 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_00,
663 sizeof(data_00), &obj)))
664 goto exit;
665
666 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
667 goto exit;
668
669 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
670 fs_open(&sess, file_01, sizeof(file_01),
671 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
672 goto exit;
673
674 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
675 goto exit;
676
677 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
678 fs_open(&sess, file_01, sizeof(file_01),
679 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
680 goto exit;
681
682 /* clean */
683 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
684 goto exit;
685
686exit:
687 TEEC_CloseSession(&sess);
688}
689
690/* read */
691static void xtest_tee_test_6003(ADBG_Case_t *c)
692{
693 TEEC_Session sess;
694 uint32_t obj;
695 uint8_t out[10] = { 0 };
696 uint32_t count;
697 uint32_t orig;
698
699 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
700 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
701 return;
702
703 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
704 fs_create(&sess, file_02, sizeof(file_02),
705 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
706 sizeof(data_01), &obj)))
707 goto exit;
708
709 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
710 goto exit;
711
712 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
713 fs_open(&sess, file_02, sizeof(file_02),
714 TEE_DATA_FLAG_ACCESS_READ |
715 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
716 goto exit;
717
718 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
719 goto exit;
720
721 (void)ADBG_EXPECT_BUFFER(c, data_01, 10, out, count);
722
723 /* clean */
724 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
725 goto exit;
726
727exit:
728 TEEC_CloseSession(&sess);
729}
730
731/* write */
732static void xtest_tee_test_6004(ADBG_Case_t *c)
733{
734 TEEC_Session sess;
735 uint32_t obj;
736 uint8_t out[10] = { 0 };
737 uint32_t count;
738 uint32_t orig;
739
740 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
741 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
742 return;
743
744 /* create */
745 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
746 fs_create(&sess, file_02, sizeof(file_02),
747 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
748 sizeof(data_01), &obj)))
749 goto exit;
750
751 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
752 goto exit;
753
754 /* write new data */
755 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
756 fs_open(&sess, file_02, sizeof(file_02),
757 TEE_DATA_FLAG_ACCESS_WRITE, &obj)))
758 goto exit;
759
760 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
761 fs_write(&sess, obj, data_00, sizeof(data_00))))
762 goto exit;
763
764 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
765 goto exit;
766
767 /* verify */
768 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
769 fs_open(&sess, file_02, sizeof(file_02),
770 TEE_DATA_FLAG_ACCESS_READ |
771 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
772 goto exit;
773
774 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
775 goto exit;
776
777 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
778
779 /* clean */
780 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
781 goto exit;
782
783exit:
784 TEEC_CloseSession(&sess);
785}
786
787/* seek */
788static void xtest_tee_test_6005(ADBG_Case_t *c)
789{
790 TEEC_Session sess;
791 uint32_t obj;
792 uint8_t out[10] = { 0 };
793 uint32_t count;
794 uint32_t orig;
795
796 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
797 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
798 return;
799
800 /* create */
801 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
802 fs_create(&sess, file_01, sizeof(file_01),
803 TEE_DATA_FLAG_ACCESS_WRITE |
804 TEE_DATA_FLAG_ACCESS_READ |
805 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
806 sizeof(data_00), &obj)))
807 goto exit;
808
809 /* seek */
810 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
811 fs_seek(&sess, obj, 10, TEE_DATA_SEEK_SET)))
812 goto exit;
813
814 /* verify */
815 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
816 goto exit;
817
818 (void)ADBG_EXPECT_BUFFER(c, &data_00[10], 10, out, count);
819
820 /* clean */
821 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
822 goto exit;
823
824exit:
825 TEEC_CloseSession(&sess);
826}
827
828/* unlink */
829static void xtest_tee_test_6006(ADBG_Case_t *c)
830{
831 TEEC_Session sess;
832 uint32_t obj;
833 uint32_t orig;
834
835 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
836 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
837 return;
838
839 /* create */
840 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
841 fs_create(&sess, file_01, sizeof(file_01),
842 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
843 sizeof(data_00), &obj)))
844 goto exit;
845
846 /* del & close */
847 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
848 goto exit;
849
850 /* check result */
851 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
852 fs_open(&sess, file_01, sizeof(file_01),
853 TEE_DATA_FLAG_ACCESS_READ, &obj)))
854 goto exit;
855
856exit:
857 TEEC_CloseSession(&sess);
858}
859
Pascal Brandc639ac82015-07-02 08:53:34 +0200860static void xtest_tee_test_6007(ADBG_Case_t *c)
861{
James Kung98c0ba12015-09-09 15:51:59 +0800862 Do_ADBG_BeginSubCase(c, "Test truncate file length");
863 test_truncate_file_length(c);
864 Do_ADBG_EndSubCase(c, "Test truncate file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200865
James Kung98c0ba12015-09-09 15:51:59 +0800866 Do_ADBG_BeginSubCase(c, "Test extend file length");
867 test_extend_file_length(c);
868 Do_ADBG_EndSubCase(c, "Test extend file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200869
James Kung98c0ba12015-09-09 15:51:59 +0800870 Do_ADBG_BeginSubCase(c, "Test file hole");
871 test_file_hole(c);
872 Do_ADBG_EndSubCase(c, "Test file hole");
Pascal Brandc639ac82015-07-02 08:53:34 +0200873}
874
875static void xtest_tee_test_6008(ADBG_Case_t *c)
876{
877 TEEC_Session sess;
878 uint32_t obj;
879 uint8_t out[10] = { 0 };
880 uint32_t count;
881 uint32_t orig;
882
883 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
884 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
885 return;
886
887 /* create */
888 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
889 fs_create(&sess, file_02, sizeof(file_02),
890 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
891 sizeof(data_01), &obj)))
892 goto exit;
893
894 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
895 goto exit;
896
897 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
898 fs_open(&sess, file_02, sizeof(file_02),
899 TEE_DATA_FLAG_ACCESS_WRITE |
900 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
901 goto exit;
902
903 /* write new data */
904 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
905 fs_write(&sess, obj, data_00, sizeof(data_00))))
906 goto exit;
907
908 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
909 fs_rename(&sess, obj, file_03, sizeof(file_03))))
910 goto exit;
911
912 /* close */
913 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
914 goto exit;
915
916 /* verify */
917 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
918 fs_open(&sess, file_03, sizeof(file_03),
919 TEE_DATA_FLAG_ACCESS_READ |
920 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
921 goto exit;
922
923 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
924 goto exit;
925
926 /* check buffer */
927 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
928
929 /* clean */
930 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
931 goto exit;
932
933exit:
934 TEEC_CloseSession(&sess);
935}
936
937static void xtest_tee_test_6009(ADBG_Case_t *c)
938{
939 TEEC_Session sess;
940 uint32_t obj0;
941 uint32_t obj1;
942 uint32_t obj2;
943 uint32_t e = 0;
944 uint8_t info[200];
945 uint8_t id[200];
946 uint32_t orig;
947
948 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
949 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
950 return;
951
952 /* create file 00 */
953 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
954 fs_create(&sess, file_00, sizeof(file_00),
955 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
956 sizeof(data_01), &obj0)))
957 goto exit;
958
959 /* create file 01 */
960 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
961 fs_create(&sess, file_01, sizeof(file_01),
962 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
963 sizeof(data_01), &obj1)))
964 goto exit;
965
966 /* create file 02 */
967 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
968 fs_create(&sess, file_02, sizeof(file_02),
969 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
970 sizeof(data_01), &obj2)))
971 goto exit;
972
973 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj0)))
974 goto exit;
975
976 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj1)))
977 goto exit;
978
979 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj2)))
980 goto exit;
981
982 /* iterate */
983 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_alloc_enum(&sess, &e)))
984 goto exit;
985
986 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_start_enum(&sess, e)))
987 goto exit;
988
989 /* get 00 */
990 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
991 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
992 goto exit;
993
994 /* get 01 */
995 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
996 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
997 goto exit;
998
999 /* get 02 */
1000 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1001 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1002 goto exit;
1003
1004 /* we should not have more files */
1005 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
1006 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1007 goto exit;
1008
1009 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_enum(&sess, e)))
1010 goto exit;
1011
1012 /* clean */
1013 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1014 fs_open(&sess, file_00, sizeof(file_00),
1015 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj0)))
1016 goto exit;
1017
1018 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj0)))
1019 goto exit;
1020
1021 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1022 fs_open(&sess, file_01, sizeof(file_01),
1023 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj1)))
1024 goto exit;
1025
1026 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj1)))
1027 goto exit;
1028
1029 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1030 fs_open(&sess, file_02, sizeof(file_02),
1031 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj2)))
1032 goto exit;
1033
1034 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj2)))
1035 goto exit;
1036
1037exit:
1038 TEEC_CloseSession(&sess);
1039}
1040
Jerome Forissiere3688342015-09-24 10:45:17 -07001041#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001042static void xtest_tee_test_6010(ADBG_Case_t *c)
1043{
1044 TEEC_Session sess;
1045 uint32_t orig;
1046 uint8_t out[4000] = {0};
1047 uint8_t in[0x12c] = {'b'};
Pascal Brand30844922015-09-17 12:12:42 +02001048 int i;
1049
1050 for (i=0; i<sizeof(in); i++)
1051 in[i] = i;
Pascal Brand8a74e362015-09-10 12:41:52 +02001052
1053 if (!ADBG_EXPECT_TEEC_SUCCESS(
1054 c, xtest_teec_open_session(
1055 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1056 return;
1057
1058 Do_ADBG_BeginSubCase(
1059 c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)");
1060
1061 if (!ADBG_EXPECT_TEEC_RESULT(
1062 c, TEEC_ERROR_ACCESS_CONFLICT, ds_open_access_conf(&sess)))
1063 goto exit;
1064
1065 Do_ADBG_EndSubCase(
1066 c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)");
1067 Do_ADBG_BeginSubCase(
1068 c, "GP DS RestrictObjectUsagePanic (9d-5d-46)");
1069
1070 if (!ADBG_EXPECT_TEEC_RESULT(
1071 c, TEE_ERROR_TARGET_DEAD, ds_res_obj_panic(&sess)))
1072 goto exit;
1073
1074 TEEC_CloseSession(&sess);
1075
1076 Do_ADBG_EndSubCase(
1077 c, "GP DS RestrictObjectUsagePanic (9d-5d-46)");
1078 Do_ADBG_BeginSubCase(
1079 c, "GP DS SeekObjectData BadHandle (9d-c3-c8)");
1080
1081 if (!ADBG_EXPECT_TEEC_SUCCESS(
1082 c, xtest_teec_open_session(
1083 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1084 return;
1085
1086 if (!ADBG_EXPECT_TEEC_RESULT(
1087 c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_bad_handle(&sess)))
1088 goto exit;
1089
1090 TEEC_CloseSession(&sess);
1091
1092 Do_ADBG_EndSubCase(
1093 c, "GP DS SeekObjectData BadHandle (9d-c3-c8)");
1094 Do_ADBG_BeginSubCase(
1095 c, "GP DS SeekObjectData NotPersist (9d-db-4a)");
1096
1097 if (!ADBG_EXPECT_TEEC_SUCCESS(
1098 c, xtest_teec_open_session(
1099 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1100 return;
1101
1102 if (!ADBG_EXPECT_TEEC_RESULT(
1103 c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_inv_handle(&sess)))
1104 goto exit;
1105
1106 TEEC_CloseSession(&sess);
1107
1108 Do_ADBG_EndSubCase(
1109 c, "GP DS SeekObjectData NotPersist (9d-db-4a)");
1110 Do_ADBG_BeginSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)");
1111
1112 if (!ADBG_EXPECT_TEEC_SUCCESS(
1113 c, xtest_teec_open_session(
1114 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1115 return;
1116
1117 if (!ADBG_EXPECT_TEEC_SUCCESS(
1118 c, ds_seek_gp(
1119 &sess, TEE_DATA_SEEK_END, 0, 2, data_00, sizeof(data_00), out,
1120 sizeof(out))))
1121 goto exit;
1122
1123 /* check buffer */
1124 (void)ADBG_EXPECT_BUFFER(
1125 c, data_00, sizeof(data_00), out, sizeof(data_00));
Pascal Brand30844922015-09-17 12:12:42 +02001126 memset(out, 0xab, sizeof(out));
Pascal Brand8a74e362015-09-10 12:41:52 +02001127
1128 if (!ADBG_EXPECT_TEEC_SUCCESS(
1129 c, ds_seek_gp(
Pascal Brand30844922015-09-17 12:12:42 +02001130 &sess, TEE_DATA_SEEK_END, sizeof(in)/2, 0, in, sizeof(in), out,
Pascal Brand8a74e362015-09-10 12:41:52 +02001131 sizeof(out))))
1132 goto exit;
1133
Pascal Brand30844922015-09-17 12:12:42 +02001134 (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2,
1135 out + (sizeof(in) / 2), sizeof(in) / 2);
1136 memset(in, 0, sizeof(in));
1137 (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2,
1138 out, sizeof(in)/2);
1139 memset(out, 0xab, sizeof(out));
Pascal Brand8a74e362015-09-10 12:41:52 +02001140
1141 Do_ADBG_EndSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)");
1142 Do_ADBG_BeginSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)");
1143
1144 if (!ADBG_EXPECT_TEEC_RESULT(
1145 c, TEE_ERROR_ACCESS_CONFLICT, ds_rename_access_conflict(&sess)))
1146 goto exit;
1147
1148 Do_ADBG_EndSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)");
1149 Do_ADBG_BeginSubCase(
1150 c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)");
1151
1152 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_start_enum_no_item(&sess)))
1153 goto exit;
1154
1155 Do_ADBG_EndSubCase(
1156 c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)");
1157 Do_ADBG_BeginSubCase(
1158 c, "GP DS RenamePersistent ReadWrite (9d-19-88)");
1159
1160 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_rename_success(&sess)))
1161 goto exit;
1162
1163 Do_ADBG_EndSubCase(
1164 c, "GP DS RenamePersistent ReadWrite (9d-19-88)");
1165 Do_ADBG_BeginSubCase(
1166 c, "GP DS Close Free Reset Null (9d-6d-87)");
1167
1168 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_null_close_free_reset(&sess)))
1169 goto exit;
1170
1171 Do_ADBG_EndSubCase(
1172 c, "GP DS Close Free Reset Null (9d-6d-87)");
1173
1174exit:
1175 TEEC_CloseSession(&sess);
1176}
1177
1178static void xtest_tee_test_6011(ADBG_Case_t *c)
1179{
1180 TEEC_Session sess;
1181 uint32_t orig;
1182 /*
1183 * Test data from
1184 * Invoke_InitObjectAndAttributes_TEE_TYPE_AES_success_attribute_
1185 * TEE_ATTR_SECRET_VALUE_correct_size (9d-9a-91)
1186 */
1187 static const uint8_t attr_meta[] = {
11880xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
11890x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11900x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
11910x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1192 };
1193 static const uint8_t attr_data[] = {
11940x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,
11950x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,
11960xdf,0xf4,
1197 };
1198
1199 if (!ADBG_EXPECT_TEEC_SUCCESS(
1200 c, xtest_teec_open_session(
1201 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1202 return;
1203
1204 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_init_object_and_attributes(&sess,
1205 0xa0000010, 0x100, attr_meta, sizeof(attr_meta), attr_data,
1206 sizeof(attr_data), 0)))
1207 goto exit;
1208
1209exit:
1210 TEEC_CloseSession(&sess);
1211}
1212#endif
1213
Pascal Brandeb84c442016-04-19 17:49:49 +02001214static void xtest_tee_test_6012(ADBG_Case_t *c)
1215{
1216 TEEC_Session sess;
1217 uint32_t orig;
1218 uint32_t obj;
1219
1220 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1221 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1222 return;
1223
1224 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1225 fs_create_overwrite(&sess, file_04, sizeof(file_04))))
1226 goto exit;
1227
1228 TEEC_CloseSession(&sess);
1229
1230 /* re-create the same */
1231 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1232 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1233 return;
1234
1235 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1236 fs_create_overwrite(&sess, file_04, sizeof(file_04))))
1237 goto exit;
1238
1239 /*
1240 * recreate it with an object, and remove it so that xtest 6009
1241 * can be replayed
1242 */
1243 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1244 fs_create(&sess, file_04, sizeof(file_04),
1245 TEE_DATA_FLAG_ACCESS_WRITE |
1246 TEE_DATA_FLAG_ACCESS_WRITE_META | TEE_DATA_FLAG_OVERWRITE, 0, NULL, 0, &obj)))
1247 goto exit;
1248
1249 /* clean */
1250 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
1251 goto exit;
1252
1253exit:
1254 TEEC_CloseSession(&sess);
1255}
1256
Pascal Brandc639ac82015-07-02 08:53:34 +02001257ADBG_CASE_DEFINE(
1258 XTEST_TEE_6001, xtest_tee_test_6001,
1259 /* Title */
1260 "Test TEE_CreatePersistentObject",
1261 /* Short description */
1262 "Short description ...",
1263 /* Requirement IDs */
1264 "TEE-??",
1265 /* How to implement */
1266 "Description of how to implement ..."
1267 );
1268
1269ADBG_CASE_DEFINE(
1270 XTEST_TEE_6002, xtest_tee_test_6002,
1271 /* Title */
1272 "Test TEE_OpenPersistentObject",
1273 /* Short description */
1274 "Short description ...",
1275 /* Requirement IDs */
1276 "TEE-??",
1277 /* How to implement */
1278 "Description of how to implement ..."
1279 );
1280
1281ADBG_CASE_DEFINE(
1282 XTEST_TEE_6003, xtest_tee_test_6003,
1283 /* Title */
1284 "Test TEE_ReadObjectData",
1285 /* Short description */
1286 "Short description ...",
1287 /* Requirement IDs */
1288 "TEE-??",
1289 /* How to implement */
1290 "Description of how to implement ..."
1291 );
1292
1293ADBG_CASE_DEFINE(
1294 XTEST_TEE_6004, xtest_tee_test_6004,
1295 /* Title */
1296 "Test TEE_WriteObjectData",
1297 /* Short description */
1298 "Short description ...",
1299 /* Requirement IDs */
1300 "TEE-??",
1301 /* How to implement */
1302 "Description of how to implement ..."
1303 );
1304
1305ADBG_CASE_DEFINE(
1306 XTEST_TEE_6005, xtest_tee_test_6005,
1307 /* Title */
1308 "Test TEE_SeekObjectData",
1309 /* Short description */
1310 "Short description ...",
1311 /* Requirement IDs */
1312 "TEE-??",
1313 /* How to implement */
1314 "Description of how to implement ..."
1315 );
1316
1317ADBG_CASE_DEFINE(
1318 XTEST_TEE_6006, xtest_tee_test_6006,
1319 /* Title */
1320 "Test TEE_CloseAndDeletePersistentObject",
1321 /* Short description */
1322 "Short description ...",
1323 /* Requirement IDs */
1324 "TEE-??",
1325 /* How to implement */
1326 "Description of how to implement ..."
1327 );
1328
1329ADBG_CASE_DEFINE(
1330 XTEST_TEE_6007, xtest_tee_test_6007,
1331 /* Title */
1332 "Test TEE_TruncateObjectData",
1333 /* Short description */
1334 "Short description ...",
1335 /* Requirement IDs */
1336 "TEE-??",
1337 /* How to implement */
1338 "Description of how to implement ..."
1339 );
1340
1341ADBG_CASE_DEFINE(
1342 XTEST_TEE_6008, xtest_tee_test_6008,
1343 /* Title */
1344 "Test TEE_RenamePersistentObject",
1345 /* Short description */
1346 "Short description ...",
1347 /* Requirement IDs */
1348 "TEE-??",
1349 /* How to implement */
1350 "Description of how to implement ..."
1351 );
1352
1353ADBG_CASE_DEFINE(
1354 XTEST_TEE_6009, xtest_tee_test_6009,
1355 /* Title */
1356 "Test TEE Internal API Persistent Object Enumeration Functions",
1357 /* Short description */
1358 "Short description ...",
1359 /* Requirement IDs */
1360 "TEE-??",
1361 /* How to implement */
1362 "Description of how to implement ..."
1363 );
Pascal Brand8a74e362015-09-10 12:41:52 +02001364
Jerome Forissiere3688342015-09-24 10:45:17 -07001365#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001366ADBG_CASE_DEFINE(
1367 XTEST_TEE_6010, xtest_tee_test_6010,
1368 /* Title */
1369 "Test TEE GP TTA DS storage",
1370 /* Short description */
1371 "Short description ...",
1372 /* Requirement IDs */
1373 "TEE-??",
1374 /* How to implement */
1375 "Description of how to implement ..."
1376);
1377
1378ADBG_CASE_DEFINE(
1379 XTEST_TEE_6011, xtest_tee_test_6011,
1380 /* Title */
1381 "Test TEE GP TTA DS init objects",
1382 /* Short description */
1383 "Short description ...",
1384 /* Requirement IDs */
1385 "TEE-??",
1386 /* How to implement */
1387 "Description of how to implement ..."
1388);
1389#endif
Pascal Brandeb84c442016-04-19 17:49:49 +02001390
1391ADBG_CASE_DEFINE(
1392 XTEST_TEE_6012, xtest_tee_test_6012,
1393 /* Title */
1394 "Test TEE GP TTA DS init objects",
1395 /* Short description */
1396 "Short description ...",
1397 /* Requirement IDs */
1398 "TEE-??",
1399 /* How to implement */
1400 "Description of how to implement ..."
1401);