blob: 14f90880676ab720f5b40302ea388245a63fda35 [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>
25
26static uint8_t file_00[] = {
27 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
28 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
29 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
30 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
31};
32
33static uint8_t file_01[] = {
34 0x01, 0x00
35};
36
37static uint8_t file_02[] = {
38 0x02, 0x11, 0x02
39};
40
41static uint8_t file_03[] = {
42 0x03, 0x13, 0x03
43};
44
45static uint8_t data_00[] = {
46 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
47 0x00, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
48 0x00, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
49 0x00, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x00
50};
51
52static uint8_t data_01[] = {
53 0x01, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
54 0x01, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
55 0x01, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
56 0x01, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x01
57};
58
59static TEEC_Result fs_open(TEEC_Session *sess, void *id, uint32_t id_size,
60 uint32_t flags, uint32_t *obj)
61{
Aijun Sun473d9072015-08-06 15:24:49 +080062 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020063 TEEC_Result res;
64 uint32_t org;
65
66 op.params[0].tmpref.buffer = id;
67 op.params[0].tmpref.size = id_size;
68 op.params[1].value.a = flags;
69 op.params[1].value.b = 0;
70
71 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
72 TEEC_VALUE_INOUT, TEEC_NONE,
73 TEEC_NONE);
74
75 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_OPEN, &op, &org);
76
77 if (res == TEEC_SUCCESS)
78 *obj = op.params[1].value.b;
79
80 return res;
81}
82
83static TEEC_Result fs_create(TEEC_Session *sess, void *id, uint32_t id_size,
84 uint32_t flags, uint32_t attr, void *data,
85 uint32_t data_size, uint32_t *obj)
86{
Aijun Sun473d9072015-08-06 15:24:49 +080087 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020088 TEEC_Result res;
89 uint32_t org;
90
91 op.params[0].tmpref.buffer = id;
92 op.params[0].tmpref.size = id_size;
93 op.params[1].value.a = flags;
94 op.params[1].value.b = 0;
95 op.params[2].value.a = attr;
96 op.params[2].value.b = 0;
97 op.params[3].tmpref.buffer = data;
98 op.params[3].tmpref.size = data_size;
99
100 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
101 TEEC_VALUE_INOUT, TEEC_VALUE_INPUT,
102 TEEC_MEMREF_TEMP_INPUT);
103
104 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE, &op, &org);
105
106 if (res == TEEC_SUCCESS)
107 *obj = op.params[1].value.b;
108
109 return res;
110}
111
112static TEEC_Result fs_close(TEEC_Session *sess, uint32_t obj)
113{
Aijun Sun473d9072015-08-06 15:24:49 +0800114 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200115 uint32_t org;
116
117 op.params[0].value.a = obj;
118
119 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
120 TEEC_NONE, TEEC_NONE);
121
122 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CLOSE, &op, &org);
123}
124
125static TEEC_Result fs_read(TEEC_Session *sess, uint32_t obj, void *data,
126 uint32_t data_size, uint32_t *count)
127{
128 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800129 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200130 uint32_t org;
131
132 op.params[0].tmpref.buffer = data;
133 op.params[0].tmpref.size = data_size;
134 op.params[1].value.a = obj;
135 op.params[1].value.b = 0;
136
137 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT,
138 TEEC_VALUE_INOUT, TEEC_NONE,
139 TEEC_NONE);
140
141 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_READ, &op, &org);
142
143 if (res == TEEC_SUCCESS)
144 *count = op.params[1].value.b;
145
146 return res;
147}
148
149static TEEC_Result fs_write(TEEC_Session *sess, uint32_t obj, void *data,
150 uint32_t data_size)
151{
Aijun Sun473d9072015-08-06 15:24:49 +0800152 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200153 uint32_t org;
154
155 op.params[0].tmpref.buffer = data;
156 op.params[0].tmpref.size = data_size;
157 op.params[1].value.a = obj;
158 op.params[1].value.b = 0;
159
160 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
161 TEEC_VALUE_INPUT, TEEC_NONE,
162 TEEC_NONE);
163
164 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_WRITE, &op, &org);
165}
166
167static TEEC_Result fs_seek(TEEC_Session *sess, uint32_t obj, int32_t offset,
168 int32_t whence)
169{
Aijun Sun473d9072015-08-06 15:24:49 +0800170 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200171 uint32_t org;
172
173 op.params[0].value.a = obj;
174 op.params[0].value.b = offset;
175 op.params[1].value.a = whence;
176
177 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_INOUT,
178 TEEC_NONE, TEEC_NONE);
179
180 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_SEEK, &op, &org);
181}
182
183static TEEC_Result fs_unlink(TEEC_Session *sess, uint32_t obj)
184{
Aijun Sun473d9072015-08-06 15:24:49 +0800185 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200186 uint32_t org;
187
188 op.params[0].value.a = obj;
189
190 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
191 TEEC_NONE, TEEC_NONE);
192
193 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_UNLINK, &op, &org);
194}
195
196static TEEC_Result fs_trunc(TEEC_Session *sess, uint32_t obj, uint32_t len)
197{
Aijun Sun473d9072015-08-06 15:24:49 +0800198 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200199 uint32_t org;
200
201 op.params[0].value.a = obj;
202 op.params[0].value.b = len;
203
204 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
205 TEEC_NONE, TEEC_NONE);
206
207 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_TRUNC, &op, &org);
208}
209
210static TEEC_Result fs_rename(TEEC_Session *sess, uint32_t obj, void *id,
211 uint32_t id_size)
212{
Aijun Sun473d9072015-08-06 15:24:49 +0800213 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200214 uint32_t org;
215
216 op.params[0].value.a = obj;
217 op.params[1].tmpref.buffer = id;
218 op.params[1].tmpref.size = id_size;
219
220 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
221 TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
222 TEEC_NONE);
223
224 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RENAME, &op, &org);
225}
226
227static TEEC_Result fs_alloc_enum(TEEC_Session *sess, uint32_t *e)
228{
229 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800230 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200231 uint32_t org;
232
233 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
234 TEEC_NONE, TEEC_NONE);
235
236 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_ALLOC_ENUM, &op, &org);
237
238 if (res == TEEC_SUCCESS)
239 *e = op.params[0].value.a;
240
241 return res;
242}
243
244static TEEC_Result fs_free_enum(TEEC_Session *sess, uint32_t e)
245{
Aijun Sun473d9072015-08-06 15:24:49 +0800246 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200247 uint32_t org;
248
249 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
250 TEEC_NONE);
251
252 op.params[0].value.a = e;
253
254 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_FREE_ENUM, &op, &org);
255}
256
257static TEEC_Result fs_start_enum(TEEC_Session *sess, uint32_t e)
258{
Aijun Sun473d9072015-08-06 15:24:49 +0800259 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200260 uint32_t org;
261
262 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
263 TEEC_NONE, TEEC_NONE);
264
265 op.params[0].value.a = e;
266
267 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_START_ENUM, &op, &org);
268}
269
270static TEEC_Result fs_next_enum(TEEC_Session *sess, uint32_t e, void *obj_info,
271 size_t info_size, void *id, uint32_t id_size)
272{
Aijun Sun473d9072015-08-06 15:24:49 +0800273 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200274 uint32_t org;
275
276 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
277 TEEC_MEMREF_TEMP_OUTPUT,
278 TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE);
279
280 op.params[0].value.a = e;
281 op.params[1].tmpref.buffer = obj_info;
282 op.params[1].tmpref.size = info_size;
283 op.params[2].tmpref.buffer = id;
284 op.params[2].tmpref.size = id_size;
285
286 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_NEXT_ENUM, &op, &org);
287}
288
James Kung98c0ba12015-09-09 15:51:59 +0800289/* trunc */
290static void test_truncate_file_length(ADBG_Case_t *c)
291{
292 TEEC_Session sess;
293 uint32_t obj;
294 uint8_t out[10] = { 0 };
295 uint32_t count;
296 uint32_t orig;
297
298 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
299 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
300 return;
301
302 /* create */
303 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
304 fs_create(&sess, file_01, sizeof(file_01),
305 TEE_DATA_FLAG_ACCESS_WRITE |
306 TEE_DATA_FLAG_ACCESS_READ |
307 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
308 sizeof(data_00), &obj)))
309 goto exit;
310
311 /* trunc */
312 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 10)))
313 goto exit;
314
315 /* seek */
316 if (!ADBG_EXPECT_TEEC_SUCCESS(
317 c, fs_seek(&sess, obj, 5, TEE_DATA_SEEK_SET)))
318 goto exit;
319
320 /* verify */
321 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
322 goto exit;
323
324 /* check buffer */
325 (void)ADBG_EXPECT_BUFFER(c, &data_00[5], 5, out, count);
326
327 /* clean */
328 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
329 goto exit;
330
331exit:
332 TEEC_CloseSession(&sess);
333}
334
335/* extend */
336static void test_extend_file_length(ADBG_Case_t *c)
337{
338 TEEC_Session sess;
339 uint32_t obj;
340 uint8_t out[10] = { 0 };
341 uint8_t expect[10] = { 0 };
342 uint32_t count;
343 uint32_t orig;
344
345 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
346 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
347 return;
348
349 /* create */
350 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
351 fs_create(&sess, file_01, sizeof(file_01),
352 TEE_DATA_FLAG_ACCESS_WRITE |
353 TEE_DATA_FLAG_ACCESS_READ |
354 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
355 sizeof(data_00), &obj)))
356 goto exit;
357
358 /* extend */
359 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 40)))
360 goto exit;
361
362 /* seek */
363 if (!ADBG_EXPECT_TEEC_SUCCESS(
364 c, fs_seek(&sess, obj, 30, TEE_DATA_SEEK_SET)))
365 goto exit;
366
367 /* verify */
368 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
369 goto exit;
370
371 /* check buffer */
372 expect[0] = data_00[30];
373 expect[1] = data_00[31];
374 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
375
376 /* clean */
377 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
378 goto exit;
379
380exit:
381 TEEC_CloseSession(&sess);
382}
383
384/* file hole */
385static void test_file_hole(ADBG_Case_t *c)
386{
387 TEEC_Session sess;
388 uint32_t obj;
389 uint8_t out[10] = { 0 };
390 uint8_t expect[10] = { 0 };
391 uint32_t count;
392 uint32_t orig;
393
394 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
395 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
396 return;
397
398 /* create */
399 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
400 fs_create(&sess, file_01, sizeof(file_01),
401 TEE_DATA_FLAG_ACCESS_WRITE |
402 TEE_DATA_FLAG_ACCESS_READ |
403 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
404 sizeof(data_00), &obj)))
405 goto exit;
406
407 /* seek */
408 if (!ADBG_EXPECT_TEEC_SUCCESS(
409 c, fs_seek(&sess, obj, 80, TEE_DATA_SEEK_SET)))
410 goto exit;
411
412 /* write */
413 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_write(&sess, obj, data_00,
414 sizeof(data_00))))
415 goto exit;
416
417 /* seek */
418 if (!ADBG_EXPECT_TEEC_SUCCESS(
419 c, fs_seek(&sess, obj, 74, TEE_DATA_SEEK_SET)))
420 goto exit;
421
422 /* verify */
423 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
424 goto exit;
425
426 /* check buffer */
427 expect[6] = data_00[0];
428 expect[7] = data_00[1];
429 expect[8] = data_00[2];
430 expect[9] = data_00[3];
431 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
432
433 /* clean */
434 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
435 goto exit;
436
437exit:
438 TEEC_CloseSession(&sess);
439}
440
Pascal Brandc639ac82015-07-02 08:53:34 +0200441/* create */
442static void xtest_tee_test_6001(ADBG_Case_t *c)
443{
444 TEEC_Session sess;
445 uint32_t obj;
446 uint32_t orig;
447
448 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
449 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
450 return;
451
452 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
453 fs_create(&sess, file_00, sizeof(file_00),
454 TEE_DATA_FLAG_ACCESS_WRITE |
455 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
456 sizeof(data_00), &obj)))
457 goto exit;
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
467/* open */
468static void xtest_tee_test_6002(ADBG_Case_t *c)
469{
470 TEEC_Session sess;
471 uint32_t obj;
472 uint32_t orig;
473
474 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
475 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
476 return;
477
478 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
479 fs_create(&sess, file_01, sizeof(file_01),
480 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_00,
481 sizeof(data_00), &obj)))
482 goto exit;
483
484 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
485 goto exit;
486
487 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
488 fs_open(&sess, file_01, sizeof(file_01),
489 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
490 goto exit;
491
492 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
493 goto exit;
494
495 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
496 fs_open(&sess, file_01, sizeof(file_01),
497 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
498 goto exit;
499
500 /* clean */
501 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
502 goto exit;
503
504exit:
505 TEEC_CloseSession(&sess);
506}
507
508/* read */
509static void xtest_tee_test_6003(ADBG_Case_t *c)
510{
511 TEEC_Session sess;
512 uint32_t obj;
513 uint8_t out[10] = { 0 };
514 uint32_t count;
515 uint32_t orig;
516
517 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
518 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
519 return;
520
521 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
522 fs_create(&sess, file_02, sizeof(file_02),
523 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
524 sizeof(data_01), &obj)))
525 goto exit;
526
527 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
528 goto exit;
529
530 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
531 fs_open(&sess, file_02, sizeof(file_02),
532 TEE_DATA_FLAG_ACCESS_READ |
533 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
534 goto exit;
535
536 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
537 goto exit;
538
539 (void)ADBG_EXPECT_BUFFER(c, data_01, 10, out, count);
540
541 /* clean */
542 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
543 goto exit;
544
545exit:
546 TEEC_CloseSession(&sess);
547}
548
549/* write */
550static void xtest_tee_test_6004(ADBG_Case_t *c)
551{
552 TEEC_Session sess;
553 uint32_t obj;
554 uint8_t out[10] = { 0 };
555 uint32_t count;
556 uint32_t orig;
557
558 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
559 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
560 return;
561
562 /* create */
563 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
564 fs_create(&sess, file_02, sizeof(file_02),
565 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
566 sizeof(data_01), &obj)))
567 goto exit;
568
569 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
570 goto exit;
571
572 /* write new data */
573 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
574 fs_open(&sess, file_02, sizeof(file_02),
575 TEE_DATA_FLAG_ACCESS_WRITE, &obj)))
576 goto exit;
577
578 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
579 fs_write(&sess, obj, data_00, sizeof(data_00))))
580 goto exit;
581
582 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
583 goto exit;
584
585 /* verify */
586 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
587 fs_open(&sess, file_02, sizeof(file_02),
588 TEE_DATA_FLAG_ACCESS_READ |
589 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
590 goto exit;
591
592 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
593 goto exit;
594
595 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
596
597 /* clean */
598 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
599 goto exit;
600
601exit:
602 TEEC_CloseSession(&sess);
603}
604
605/* seek */
606static void xtest_tee_test_6005(ADBG_Case_t *c)
607{
608 TEEC_Session sess;
609 uint32_t obj;
610 uint8_t out[10] = { 0 };
611 uint32_t count;
612 uint32_t orig;
613
614 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
615 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
616 return;
617
618 /* create */
619 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
620 fs_create(&sess, file_01, sizeof(file_01),
621 TEE_DATA_FLAG_ACCESS_WRITE |
622 TEE_DATA_FLAG_ACCESS_READ |
623 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
624 sizeof(data_00), &obj)))
625 goto exit;
626
627 /* seek */
628 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
629 fs_seek(&sess, obj, 10, TEE_DATA_SEEK_SET)))
630 goto exit;
631
632 /* verify */
633 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
634 goto exit;
635
636 (void)ADBG_EXPECT_BUFFER(c, &data_00[10], 10, out, count);
637
638 /* clean */
639 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
640 goto exit;
641
642exit:
643 TEEC_CloseSession(&sess);
644}
645
646/* unlink */
647static void xtest_tee_test_6006(ADBG_Case_t *c)
648{
649 TEEC_Session sess;
650 uint32_t obj;
651 uint32_t orig;
652
653 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
654 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
655 return;
656
657 /* create */
658 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
659 fs_create(&sess, file_01, sizeof(file_01),
660 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
661 sizeof(data_00), &obj)))
662 goto exit;
663
664 /* del & close */
665 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
666 goto exit;
667
668 /* check result */
669 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
670 fs_open(&sess, file_01, sizeof(file_01),
671 TEE_DATA_FLAG_ACCESS_READ, &obj)))
672 goto exit;
673
674exit:
675 TEEC_CloseSession(&sess);
676}
677
Pascal Brandc639ac82015-07-02 08:53:34 +0200678static void xtest_tee_test_6007(ADBG_Case_t *c)
679{
James Kung98c0ba12015-09-09 15:51:59 +0800680 Do_ADBG_BeginSubCase(c, "Test truncate file length");
681 test_truncate_file_length(c);
682 Do_ADBG_EndSubCase(c, "Test truncate file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200683
James Kung98c0ba12015-09-09 15:51:59 +0800684 Do_ADBG_BeginSubCase(c, "Test extend file length");
685 test_extend_file_length(c);
686 Do_ADBG_EndSubCase(c, "Test extend file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200687
James Kung98c0ba12015-09-09 15:51:59 +0800688 Do_ADBG_BeginSubCase(c, "Test file hole");
689 test_file_hole(c);
690 Do_ADBG_EndSubCase(c, "Test file hole");
Pascal Brandc639ac82015-07-02 08:53:34 +0200691}
692
693static void xtest_tee_test_6008(ADBG_Case_t *c)
694{
695 TEEC_Session sess;
696 uint32_t obj;
697 uint8_t out[10] = { 0 };
698 uint32_t count;
699 uint32_t orig;
700
701 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
702 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
703 return;
704
705 /* create */
706 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
707 fs_create(&sess, file_02, sizeof(file_02),
708 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
709 sizeof(data_01), &obj)))
710 goto exit;
711
712 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
713 goto exit;
714
715 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
716 fs_open(&sess, file_02, sizeof(file_02),
717 TEE_DATA_FLAG_ACCESS_WRITE |
718 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
719 goto exit;
720
721 /* write new data */
722 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
723 fs_write(&sess, obj, data_00, sizeof(data_00))))
724 goto exit;
725
726 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
727 fs_rename(&sess, obj, file_03, sizeof(file_03))))
728 goto exit;
729
730 /* close */
731 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
732 goto exit;
733
734 /* verify */
735 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
736 fs_open(&sess, file_03, sizeof(file_03),
737 TEE_DATA_FLAG_ACCESS_READ |
738 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj)))
739 goto exit;
740
741 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
742 goto exit;
743
744 /* check buffer */
745 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
746
747 /* clean */
748 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
749 goto exit;
750
751exit:
752 TEEC_CloseSession(&sess);
753}
754
755static void xtest_tee_test_6009(ADBG_Case_t *c)
756{
757 TEEC_Session sess;
758 uint32_t obj0;
759 uint32_t obj1;
760 uint32_t obj2;
761 uint32_t e = 0;
762 uint8_t info[200];
763 uint8_t id[200];
764 uint32_t orig;
765
766 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
767 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
768 return;
769
770 /* create file 00 */
771 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
772 fs_create(&sess, file_00, sizeof(file_00),
773 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
774 sizeof(data_01), &obj0)))
775 goto exit;
776
777 /* create file 01 */
778 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
779 fs_create(&sess, file_01, sizeof(file_01),
780 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
781 sizeof(data_01), &obj1)))
782 goto exit;
783
784 /* create file 02 */
785 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
786 fs_create(&sess, file_02, sizeof(file_02),
787 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
788 sizeof(data_01), &obj2)))
789 goto exit;
790
791 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj0)))
792 goto exit;
793
794 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj1)))
795 goto exit;
796
797 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj2)))
798 goto exit;
799
800 /* iterate */
801 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_alloc_enum(&sess, &e)))
802 goto exit;
803
804 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_start_enum(&sess, e)))
805 goto exit;
806
807 /* get 00 */
808 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
809 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
810 goto exit;
811
812 /* get 01 */
813 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
814 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
815 goto exit;
816
817 /* get 02 */
818 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
819 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
820 goto exit;
821
822 /* we should not have more files */
823 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
824 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
825 goto exit;
826
827 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_enum(&sess, e)))
828 goto exit;
829
830 /* clean */
831 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
832 fs_open(&sess, file_00, sizeof(file_00),
833 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj0)))
834 goto exit;
835
836 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj0)))
837 goto exit;
838
839 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
840 fs_open(&sess, file_01, sizeof(file_01),
841 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj1)))
842 goto exit;
843
844 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj1)))
845 goto exit;
846
847 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
848 fs_open(&sess, file_02, sizeof(file_02),
849 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj2)))
850 goto exit;
851
852 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj2)))
853 goto exit;
854
855exit:
856 TEEC_CloseSession(&sess);
857}
858
859ADBG_CASE_DEFINE(
860 XTEST_TEE_6001, xtest_tee_test_6001,
861 /* Title */
862 "Test TEE_CreatePersistentObject",
863 /* Short description */
864 "Short description ...",
865 /* Requirement IDs */
866 "TEE-??",
867 /* How to implement */
868 "Description of how to implement ..."
869 );
870
871ADBG_CASE_DEFINE(
872 XTEST_TEE_6002, xtest_tee_test_6002,
873 /* Title */
874 "Test TEE_OpenPersistentObject",
875 /* Short description */
876 "Short description ...",
877 /* Requirement IDs */
878 "TEE-??",
879 /* How to implement */
880 "Description of how to implement ..."
881 );
882
883ADBG_CASE_DEFINE(
884 XTEST_TEE_6003, xtest_tee_test_6003,
885 /* Title */
886 "Test TEE_ReadObjectData",
887 /* Short description */
888 "Short description ...",
889 /* Requirement IDs */
890 "TEE-??",
891 /* How to implement */
892 "Description of how to implement ..."
893 );
894
895ADBG_CASE_DEFINE(
896 XTEST_TEE_6004, xtest_tee_test_6004,
897 /* Title */
898 "Test TEE_WriteObjectData",
899 /* Short description */
900 "Short description ...",
901 /* Requirement IDs */
902 "TEE-??",
903 /* How to implement */
904 "Description of how to implement ..."
905 );
906
907ADBG_CASE_DEFINE(
908 XTEST_TEE_6005, xtest_tee_test_6005,
909 /* Title */
910 "Test TEE_SeekObjectData",
911 /* Short description */
912 "Short description ...",
913 /* Requirement IDs */
914 "TEE-??",
915 /* How to implement */
916 "Description of how to implement ..."
917 );
918
919ADBG_CASE_DEFINE(
920 XTEST_TEE_6006, xtest_tee_test_6006,
921 /* Title */
922 "Test TEE_CloseAndDeletePersistentObject",
923 /* Short description */
924 "Short description ...",
925 /* Requirement IDs */
926 "TEE-??",
927 /* How to implement */
928 "Description of how to implement ..."
929 );
930
931ADBG_CASE_DEFINE(
932 XTEST_TEE_6007, xtest_tee_test_6007,
933 /* Title */
934 "Test TEE_TruncateObjectData",
935 /* Short description */
936 "Short description ...",
937 /* Requirement IDs */
938 "TEE-??",
939 /* How to implement */
940 "Description of how to implement ..."
941 );
942
943ADBG_CASE_DEFINE(
944 XTEST_TEE_6008, xtest_tee_test_6008,
945 /* Title */
946 "Test TEE_RenamePersistentObject",
947 /* Short description */
948 "Short description ...",
949 /* Requirement IDs */
950 "TEE-??",
951 /* How to implement */
952 "Description of how to implement ..."
953 );
954
955ADBG_CASE_DEFINE(
956 XTEST_TEE_6009, xtest_tee_test_6009,
957 /* Title */
958 "Test TEE Internal API Persistent Object Enumeration Functions",
959 /* Short description */
960 "Short description ...",
961 /* Requirement IDs */
962 "TEE-??",
963 /* How to implement */
964 "Description of how to implement ..."
965 );