blob: 99718ee43c37c990114ae65dbc040970fed4a4f9 [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>
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +080016#include <pthread.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020017
18#include <adbg.h>
19#include <xtest_test.h>
20#include <xtest_helpers.h>
21
22#include <tee_client_api.h>
23#include <ta_storage.h>
24#include <tee_api_defines.h>
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020025#include <tee_api_defines_extensions.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020026#include <tee_api_types.h>
Jerome Forissiere3688342015-09-24 10:45:17 -070027#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +020028#include <TTA_DS_protocol.h>
29#endif
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020030#include <util.h>
31
32static uint32_t storage_ids[] = {
33 TEE_STORAGE_PRIVATE,
34#ifdef CFG_REE_FS
35 TEE_STORAGE_PRIVATE_REE,
36#endif
37#ifdef CFG_RPMB_FS
38 TEE_STORAGE_PRIVATE_RPMB,
39#endif
Jerome Forissiera966bb42016-08-16 16:41:47 +020040#ifdef CFG_SQL_FS
41 TEE_STORAGE_PRIVATE_SQL,
42#endif
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020043};
Pascal Brandc639ac82015-07-02 08:53:34 +020044
45static uint8_t file_00[] = {
46 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
47 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
48 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
49 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
50};
51
52static uint8_t file_01[] = {
53 0x01, 0x00
54};
55
56static uint8_t file_02[] = {
57 0x02, 0x11, 0x02
58};
59
60static uint8_t file_03[] = {
61 0x03, 0x13, 0x03
62};
63
Pascal Brandeb84c442016-04-19 17:49:49 +020064static uint8_t file_04[] = {
65 0x00, 0x01, 0x02
66};
67
Pascal Brandc639ac82015-07-02 08:53:34 +020068static uint8_t data_00[] = {
69 0x00, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
70 0x00, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
71 0x00, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
72 0x00, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x00
73};
74
75static uint8_t data_01[] = {
76 0x01, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
77 0x01, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
78 0x01, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
79 0x01, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x01
80};
81
82static TEEC_Result fs_open(TEEC_Session *sess, void *id, uint32_t id_size,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020083 uint32_t flags, uint32_t *obj, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +020084{
Aijun Sun473d9072015-08-06 15:24:49 +080085 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +020086 TEEC_Result res;
87 uint32_t org;
88
89 op.params[0].tmpref.buffer = id;
90 op.params[0].tmpref.size = id_size;
91 op.params[1].value.a = flags;
92 op.params[1].value.b = 0;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020093 op.params[2].value.a = storage_id;
Pascal Brandc639ac82015-07-02 08:53:34 +020094
95 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +020096 TEEC_VALUE_INOUT, TEEC_VALUE_INPUT,
Pascal Brandc639ac82015-07-02 08:53:34 +020097 TEEC_NONE);
98
99 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_OPEN, &op, &org);
100
101 if (res == TEEC_SUCCESS)
102 *obj = op.params[1].value.b;
103
104 return res;
105}
106
107static TEEC_Result fs_create(TEEC_Session *sess, void *id, uint32_t id_size,
108 uint32_t flags, uint32_t attr, void *data,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200109 uint32_t data_size, uint32_t *obj,
110 uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200111{
Aijun Sun473d9072015-08-06 15:24:49 +0800112 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200113 TEEC_Result res;
114 uint32_t org;
115
116 op.params[0].tmpref.buffer = id;
117 op.params[0].tmpref.size = id_size;
118 op.params[1].value.a = flags;
119 op.params[1].value.b = 0;
120 op.params[2].value.a = attr;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200121 op.params[2].value.b = storage_id;
Pascal Brandc639ac82015-07-02 08:53:34 +0200122 op.params[3].tmpref.buffer = data;
123 op.params[3].tmpref.size = data_size;
124
125 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
126 TEEC_VALUE_INOUT, TEEC_VALUE_INPUT,
127 TEEC_MEMREF_TEMP_INPUT);
128
129 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE, &op, &org);
130
131 if (res == TEEC_SUCCESS)
132 *obj = op.params[1].value.b;
133
134 return res;
135}
136
Pascal Brandeb84c442016-04-19 17:49:49 +0200137static TEEC_Result fs_create_overwrite(TEEC_Session *sess, void *id,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200138 uint32_t id_size, uint32_t storage_id)
Pascal Brandeb84c442016-04-19 17:49:49 +0200139{
140 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
141 TEEC_Result res;
142 uint32_t org;
143
144 op.params[0].tmpref.buffer = id;
145 op.params[0].tmpref.size = id_size;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200146 op.params[1].value.a = storage_id;
Pascal Brandeb84c442016-04-19 17:49:49 +0200147
148 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200149 TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brandeb84c442016-04-19 17:49:49 +0200150 TEEC_NONE);
151
152 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CREATE_OVERWRITE, &op, &org);
153
154 return res;
155}
156
Pascal Brandc639ac82015-07-02 08:53:34 +0200157static TEEC_Result fs_close(TEEC_Session *sess, uint32_t obj)
158{
Aijun Sun473d9072015-08-06 15:24:49 +0800159 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200160 uint32_t org;
161
162 op.params[0].value.a = obj;
163
164 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
165 TEEC_NONE, TEEC_NONE);
166
167 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_CLOSE, &op, &org);
168}
169
170static TEEC_Result fs_read(TEEC_Session *sess, uint32_t obj, void *data,
171 uint32_t data_size, uint32_t *count)
172{
173 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800174 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200175 uint32_t org;
176
177 op.params[0].tmpref.buffer = data;
178 op.params[0].tmpref.size = data_size;
179 op.params[1].value.a = obj;
180 op.params[1].value.b = 0;
181
182 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT,
183 TEEC_VALUE_INOUT, TEEC_NONE,
184 TEEC_NONE);
185
186 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_READ, &op, &org);
187
188 if (res == TEEC_SUCCESS)
189 *count = op.params[1].value.b;
190
191 return res;
192}
193
194static TEEC_Result fs_write(TEEC_Session *sess, uint32_t obj, void *data,
195 uint32_t data_size)
196{
Aijun Sun473d9072015-08-06 15:24:49 +0800197 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200198 uint32_t org;
199
200 op.params[0].tmpref.buffer = data;
201 op.params[0].tmpref.size = data_size;
202 op.params[1].value.a = obj;
203 op.params[1].value.b = 0;
204
205 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
206 TEEC_VALUE_INPUT, TEEC_NONE,
207 TEEC_NONE);
208
209 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_WRITE, &op, &org);
210}
211
212static TEEC_Result fs_seek(TEEC_Session *sess, uint32_t obj, int32_t offset,
213 int32_t whence)
214{
Aijun Sun473d9072015-08-06 15:24:49 +0800215 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200216 uint32_t org;
217
218 op.params[0].value.a = obj;
219 op.params[0].value.b = offset;
220 op.params[1].value.a = whence;
221
222 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_INOUT,
223 TEEC_NONE, TEEC_NONE);
224
225 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_SEEK, &op, &org);
226}
227
228static TEEC_Result fs_unlink(TEEC_Session *sess, uint32_t obj)
229{
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.params[0].value.a = obj;
234
235 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
236 TEEC_NONE, TEEC_NONE);
237
238 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_UNLINK, &op, &org);
239}
240
241static TEEC_Result fs_trunc(TEEC_Session *sess, uint32_t obj, uint32_t len)
242{
Aijun Sun473d9072015-08-06 15:24:49 +0800243 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200244 uint32_t org;
245
246 op.params[0].value.a = obj;
247 op.params[0].value.b = len;
248
249 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
250 TEEC_NONE, TEEC_NONE);
251
252 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_TRUNC, &op, &org);
253}
254
255static TEEC_Result fs_rename(TEEC_Session *sess, uint32_t obj, void *id,
256 uint32_t id_size)
257{
Aijun Sun473d9072015-08-06 15:24:49 +0800258 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200259 uint32_t org;
260
261 op.params[0].value.a = obj;
262 op.params[1].tmpref.buffer = id;
263 op.params[1].tmpref.size = id_size;
264
265 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
266 TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
267 TEEC_NONE);
268
269 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_RENAME, &op, &org);
270}
271
272static TEEC_Result fs_alloc_enum(TEEC_Session *sess, uint32_t *e)
273{
274 TEEC_Result res;
Aijun Sun473d9072015-08-06 15:24:49 +0800275 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200276 uint32_t org;
277
278 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
279 TEEC_NONE, TEEC_NONE);
280
281 res = TEEC_InvokeCommand(sess, TA_STORAGE_CMD_ALLOC_ENUM, &op, &org);
282
283 if (res == TEEC_SUCCESS)
284 *e = op.params[0].value.a;
285
286 return res;
287}
288
289static TEEC_Result fs_free_enum(TEEC_Session *sess, uint32_t e)
290{
Aijun Sun473d9072015-08-06 15:24:49 +0800291 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200292 uint32_t org;
293
294 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
295 TEEC_NONE);
296
297 op.params[0].value.a = e;
298
299 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_FREE_ENUM, &op, &org);
300}
301
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200302static TEEC_Result fs_start_enum(TEEC_Session *sess, uint32_t e,
303 uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200304{
Aijun Sun473d9072015-08-06 15:24:49 +0800305 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200306 uint32_t org;
307
308 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
309 TEEC_NONE, TEEC_NONE);
310
311 op.params[0].value.a = e;
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200312 op.params[0].value.b = storage_id;
Pascal Brandc639ac82015-07-02 08:53:34 +0200313
314 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_START_ENUM, &op, &org);
315}
316
317static TEEC_Result fs_next_enum(TEEC_Session *sess, uint32_t e, void *obj_info,
318 size_t info_size, void *id, uint32_t id_size)
319{
Aijun Sun473d9072015-08-06 15:24:49 +0800320 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Pascal Brandc639ac82015-07-02 08:53:34 +0200321 uint32_t org;
322
Pascal Brandc603e0d2016-04-25 12:37:18 +0200323 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brandc639ac82015-07-02 08:53:34 +0200324 TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE);
Pascal Brandc603e0d2016-04-25 12:37:18 +0200325 if (obj_info && info_size)
326 op.paramTypes |= (TEEC_MEMREF_TEMP_OUTPUT << 4);
Pascal Brandc639ac82015-07-02 08:53:34 +0200327
328 op.params[0].value.a = e;
329 op.params[1].tmpref.buffer = obj_info;
330 op.params[1].tmpref.size = info_size;
331 op.params[2].tmpref.buffer = id;
332 op.params[2].tmpref.size = id_size;
333
334 return TEEC_InvokeCommand(sess, TA_STORAGE_CMD_NEXT_ENUM, &op, &org);
335}
336
James Kung98c0ba12015-09-09 15:51:59 +0800337/* trunc */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200338static void test_truncate_file_length(ADBG_Case_t *c, uint32_t storage_id)
James Kung98c0ba12015-09-09 15:51:59 +0800339{
340 TEEC_Session sess;
341 uint32_t obj;
342 uint8_t out[10] = { 0 };
343 uint32_t count;
344 uint32_t orig;
345
346 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
347 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
348 return;
349
350 /* create */
351 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
352 fs_create(&sess, file_01, sizeof(file_01),
353 TEE_DATA_FLAG_ACCESS_WRITE |
354 TEE_DATA_FLAG_ACCESS_READ |
355 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200356 sizeof(data_00), &obj, storage_id)))
James Kung98c0ba12015-09-09 15:51:59 +0800357 goto exit;
358
359 /* trunc */
360 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 10)))
361 goto exit;
362
363 /* seek */
364 if (!ADBG_EXPECT_TEEC_SUCCESS(
365 c, fs_seek(&sess, obj, 5, TEE_DATA_SEEK_SET)))
366 goto exit;
367
368 /* verify */
369 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
370 goto exit;
371
372 /* check buffer */
373 (void)ADBG_EXPECT_BUFFER(c, &data_00[5], 5, out, count);
374
375 /* clean */
376 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
377 goto exit;
378
379exit:
380 TEEC_CloseSession(&sess);
381}
382
383/* extend */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200384static void test_extend_file_length(ADBG_Case_t *c, uint32_t storage_id)
James Kung98c0ba12015-09-09 15:51:59 +0800385{
386 TEEC_Session sess;
387 uint32_t obj;
388 uint8_t out[10] = { 0 };
389 uint8_t expect[10] = { 0 };
390 uint32_t count;
391 uint32_t orig;
392
393 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
394 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
395 return;
396
397 /* create */
398 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
399 fs_create(&sess, file_01, sizeof(file_01),
400 TEE_DATA_FLAG_ACCESS_WRITE |
401 TEE_DATA_FLAG_ACCESS_READ |
402 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200403 sizeof(data_00), &obj, storage_id)))
James Kung98c0ba12015-09-09 15:51:59 +0800404 goto exit;
405
406 /* extend */
407 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_trunc(&sess, obj, 40)))
408 goto exit;
409
410 /* seek */
411 if (!ADBG_EXPECT_TEEC_SUCCESS(
412 c, fs_seek(&sess, obj, 30, TEE_DATA_SEEK_SET)))
413 goto exit;
414
415 /* verify */
416 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
417 goto exit;
418
419 /* check buffer */
420 expect[0] = data_00[30];
421 expect[1] = data_00[31];
422 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
423
424 /* clean */
425 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
426 goto exit;
427
428exit:
429 TEEC_CloseSession(&sess);
430}
431
432/* file hole */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200433static void test_file_hole(ADBG_Case_t *c, uint32_t storage_id)
James Kung98c0ba12015-09-09 15:51:59 +0800434{
435 TEEC_Session sess;
436 uint32_t obj;
437 uint8_t out[10] = { 0 };
438 uint8_t expect[10] = { 0 };
439 uint32_t count;
440 uint32_t orig;
441
442 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
443 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
444 return;
445
446 /* create */
447 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
448 fs_create(&sess, file_01, sizeof(file_01),
449 TEE_DATA_FLAG_ACCESS_WRITE |
450 TEE_DATA_FLAG_ACCESS_READ |
451 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200452 sizeof(data_00), &obj, storage_id)))
James Kung98c0ba12015-09-09 15:51:59 +0800453 goto exit;
454
455 /* seek */
456 if (!ADBG_EXPECT_TEEC_SUCCESS(
457 c, fs_seek(&sess, obj, 80, TEE_DATA_SEEK_SET)))
458 goto exit;
459
460 /* write */
461 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_write(&sess, obj, data_00,
462 sizeof(data_00))))
463 goto exit;
464
465 /* seek */
466 if (!ADBG_EXPECT_TEEC_SUCCESS(
467 c, fs_seek(&sess, obj, 74, TEE_DATA_SEEK_SET)))
468 goto exit;
469
470 /* verify */
471 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
472 goto exit;
473
474 /* check buffer */
475 expect[6] = data_00[0];
476 expect[7] = data_00[1];
477 expect[8] = data_00[2];
478 expect[9] = data_00[3];
479 (void)ADBG_EXPECT_BUFFER(c, &expect[0], 10, out, count);
480
481 /* clean */
482 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
483 goto exit;
484
485exit:
486 TEEC_CloseSession(&sess);
487}
488
Jerome Forissiere3688342015-09-24 10:45:17 -0700489#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +0200490static TEEC_Result ds_open_access_conf(TEEC_Session *sess)
491{
492 TEEC_Operation op;
493 uint32_t org;
494
495 op.paramTypes = TEEC_PARAM_TYPES(
496 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
497
498 return TEEC_InvokeCommand(
499 sess, CMD_CreatePersistentObject_AccessConflict, &op, &org);
500}
501
502static TEEC_Result ds_res_obj_panic(TEEC_Session *sess)
503{
504 TEEC_Operation op;
505 uint32_t org;
506
507 op.paramTypes = TEEC_PARAM_TYPES(
508 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
509
510 return TEEC_InvokeCommand(
511 sess, CMD_RestrictObjectUsagePanic, &op, &org);
512}
513
514static TEEC_Result ds_seek_obj_inv_handle(TEEC_Session *sess)
515{
516 TEEC_Operation op;
517 uint32_t org;
518
519 op.paramTypes = TEEC_PARAM_TYPES(
520 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
521
522 op.params[0].value.a = CASE_DATA_OBJECT_NOT_PERSISTENT;
523
524 return TEEC_InvokeCommand(
525 sess, CMD_SeekObjectData_panic, &op, &org);
526}
527
528static TEEC_Result ds_seek_obj_bad_handle(TEEC_Session *sess)
529{
530 TEEC_Operation op;
531 uint32_t org;
532
533 op.paramTypes = TEEC_PARAM_TYPES(
534 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
535
536 op.params[0].value.a = CASE_DATA_BAD_HANDLE;
537
538 return TEEC_InvokeCommand(
539 sess, CMD_SeekObjectData_panic, &op, &org);
540}
541
542static TEEC_Result ds_seek_gp(
543 TEEC_Session *sess, TEE_Whence wh, uint32_t wh_off, uint32_t set_off,
544 void *in, size_t in_size, void *out, size_t out_size)
545{
546 TEEC_Operation op;
547 uint32_t org;
548
549 op.paramTypes = TEEC_PARAM_TYPES(
550 TEEC_VALUE_INPUT, TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
551 TEEC_MEMREF_TEMP_OUTPUT);
552
553 op.params[0].value.a = wh;
554 op.params[0].value.b = wh_off;
555 op.params[1].value.a = set_off;
556 op.params[2].tmpref.buffer = in;
557 op.params[2].tmpref.size = in_size;
558 op.params[3].tmpref.buffer = out;
559 op.params[3].tmpref.size = out_size;
560
561 return TEEC_InvokeCommand(sess, CMD_SeekWriteReadObjectData, &op, &org);
562}
563
564static TEEC_Result ds_init_object_and_attributes(TEEC_Session *sess,
565 uint32_t obj_type, uint32_t obj_size, const void *attr_meta,
566 size_t attr_meta_len, const void *attr_data, size_t attr_data_len,
567 uint32_t option)
568{
569 TEEC_Operation op;
570 uint32_t org;
571
572 op.paramTypes = TEEC_PARAM_TYPES(
573 TEEC_VALUE_INPUT, TEEC_MEMREF_TEMP_INPUT,
574 TEEC_MEMREF_TEMP_INPUT, TEEC_VALUE_INPUT);
575
576 op.params[0].value.a = obj_type;
577 op.params[0].value.b = obj_size;
578 op.params[1].tmpref.buffer = (void *)attr_meta;
579 op.params[1].tmpref.size = attr_meta_len;
580 op.params[2].tmpref.buffer = (void *)attr_data;
581 op.params[2].tmpref.size = attr_data_len;
582 op.params[3].value.a = option;
583
584 return TEEC_InvokeCommand(sess, CMD_InitObjectAndAttributes, &op, &org);
585}
586
587static TEEC_Result ds_rename_access_conflict(TEEC_Session *sess)
588{
589 TEEC_Operation op;
590 uint32_t org;
591
592 op.paramTypes = TEEC_PARAM_TYPES(
593 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
594
595 return TEEC_InvokeCommand(
596 sess, CMD_RenamePersistentObject_AccessConflict, &op, &org);
597}
598
599static TEEC_Result ds_start_enum_no_item(TEEC_Session *sess)
600{
601 TEEC_Operation op;
602 uint32_t org;
603 TEEC_Result res;
604
605 op.paramTypes = TEEC_PARAM_TYPES(
606 TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
607
608 res = TEEC_InvokeCommand(
609 sess, CMD_StartNGetPersistentObjectEnumerator_itemNotFound, &op, &org);
610
611 if (res != TEEC_SUCCESS)
612 return res;
613
614 if (op.params[0].value.a != 0 || op.params[0].value.b != 0)
615 return TEEC_ERROR_GENERIC;
616
617 return res;
618}
619
620static TEEC_Result ds_rename_success(TEEC_Session *sess)
621{
622 TEEC_Operation op;
623 uint32_t org;
624
625 op.paramTypes = TEEC_PARAM_TYPES(
626 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
627
628 return TEEC_InvokeCommand(
629 sess, CMD_RenamePersistentObject_Success, &op, &org);
630}
631
632static TEEC_Result ds_null_close_free_reset(TEEC_Session *sess)
633{
634 TEEC_Operation op;
635 uint32_t org;
636
637 op.paramTypes = TEEC_PARAM_TYPES(
638 TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
639
640 return TEEC_InvokeCommand(
641 sess, CMD_CloseFreeAndResetObjectSuccessHandleNull, &op, &org);
642}
643#endif
644
Pascal Brandc639ac82015-07-02 08:53:34 +0200645/* create */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200646static void xtest_tee_test_6001_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200647{
648 TEEC_Session sess;
649 uint32_t obj;
650 uint32_t orig;
651
652 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
653 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
654 return;
655
656 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
657 fs_create(&sess, file_00, sizeof(file_00),
658 TEE_DATA_FLAG_ACCESS_WRITE |
659 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200660 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200661 goto exit;
662
663 /* clean */
664 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
665 goto exit;
666
667exit:
668 TEEC_CloseSession(&sess);
669}
670
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200671#define DEFINE_TEST_MULTIPLE_STORAGE_IDS(test_name) \
672static void test_name(ADBG_Case_t *c) \
673{ \
674 size_t i; \
675 \
676 for (i = 0; i < ARRAY_SIZE(storage_ids); i++) { \
677 Do_ADBG_BeginSubCase(c, "Storage id: %08x", storage_ids[i]); \
678 test_name##_single(c, storage_ids[i]); \
679 Do_ADBG_EndSubCase(c, "Storage id: %08x", storage_ids[i]); \
680 } \
681}
682
683DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6001)
684
Pascal Brandc639ac82015-07-02 08:53:34 +0200685/* open */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200686static void xtest_tee_test_6002_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200687{
688 TEEC_Session sess;
689 uint32_t obj;
690 uint32_t orig;
691
692 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
693 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
694 return;
695
696 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
697 fs_create(&sess, file_01, sizeof(file_01),
698 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200699 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200700 goto exit;
701
702 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
703 goto exit;
704
705 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
706 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200707 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200708 goto exit;
709
710 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
711 goto exit;
712
713 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
714 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200715 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200716 goto exit;
717
718 /* clean */
719 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
720 goto exit;
721
722exit:
723 TEEC_CloseSession(&sess);
724}
725
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200726DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6002)
727
Pascal Brandc639ac82015-07-02 08:53:34 +0200728/* read */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200729static void xtest_tee_test_6003_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200730{
731 TEEC_Session sess;
732 uint32_t obj;
733 uint8_t out[10] = { 0 };
734 uint32_t count;
735 uint32_t orig;
736
737 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
738 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
739 return;
740
741 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
742 fs_create(&sess, file_02, sizeof(file_02),
743 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200744 sizeof(data_01), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200745 goto exit;
746
747 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
748 goto exit;
749
750 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
751 fs_open(&sess, file_02, sizeof(file_02),
752 TEE_DATA_FLAG_ACCESS_READ |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200753 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200754 goto exit;
755
756 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
757 goto exit;
758
759 (void)ADBG_EXPECT_BUFFER(c, data_01, 10, out, count);
760
761 /* clean */
762 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
763 goto exit;
764
765exit:
766 TEEC_CloseSession(&sess);
767}
768
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200769DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6003)
770
Pascal Brandc639ac82015-07-02 08:53:34 +0200771/* write */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200772static void xtest_tee_test_6004_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200773{
774 TEEC_Session sess;
775 uint32_t obj;
776 uint8_t out[10] = { 0 };
777 uint32_t count;
778 uint32_t orig;
779
780 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
781 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
782 return;
783
784 /* create */
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,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200788 sizeof(data_01), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200789 goto exit;
790
791 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
792 goto exit;
793
794 /* write new data */
795 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
796 fs_open(&sess, file_02, sizeof(file_02),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200797 TEE_DATA_FLAG_ACCESS_WRITE, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200798 goto exit;
799
800 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
801 fs_write(&sess, obj, data_00, sizeof(data_00))))
802 goto exit;
803
804 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
805 goto exit;
806
807 /* verify */
808 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
809 fs_open(&sess, file_02, sizeof(file_02),
810 TEE_DATA_FLAG_ACCESS_READ |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200811 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200812 goto exit;
813
814 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
815 goto exit;
816
817 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
818
819 /* clean */
820 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
821 goto exit;
822
823exit:
824 TEEC_CloseSession(&sess);
825}
826
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200827DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6004)
828
Pascal Brandc639ac82015-07-02 08:53:34 +0200829/* seek */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200830static void xtest_tee_test_6005_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200831{
832 TEEC_Session sess;
833 uint32_t obj;
834 uint8_t out[10] = { 0 };
835 uint32_t count;
836 uint32_t orig;
837
838 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
839 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
840 return;
841
842 /* create */
843 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
844 fs_create(&sess, file_01, sizeof(file_01),
845 TEE_DATA_FLAG_ACCESS_WRITE |
846 TEE_DATA_FLAG_ACCESS_READ |
847 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200848 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200849 goto exit;
850
851 /* seek */
852 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
853 fs_seek(&sess, obj, 10, TEE_DATA_SEEK_SET)))
854 goto exit;
855
856 /* verify */
857 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
858 goto exit;
859
860 (void)ADBG_EXPECT_BUFFER(c, &data_00[10], 10, out, count);
861
862 /* clean */
863 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
864 goto exit;
865
866exit:
867 TEEC_CloseSession(&sess);
868}
869
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200870DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6005)
871
Pascal Brandc639ac82015-07-02 08:53:34 +0200872/* unlink */
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200873static void xtest_tee_test_6006_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200874{
875 TEEC_Session sess;
876 uint32_t obj;
877 uint32_t orig;
878
879 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
880 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
881 return;
882
883 /* create */
884 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
885 fs_create(&sess, file_01, sizeof(file_01),
886 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200887 sizeof(data_00), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200888 goto exit;
889
890 /* del & close */
891 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
892 goto exit;
893
894 /* check result */
895 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
896 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200897 TEE_DATA_FLAG_ACCESS_READ, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200898 goto exit;
899
900exit:
901 TEEC_CloseSession(&sess);
902}
903
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200904DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6006)
905
906static void xtest_tee_test_6007_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200907{
James Kung98c0ba12015-09-09 15:51:59 +0800908 Do_ADBG_BeginSubCase(c, "Test truncate file length");
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200909 test_truncate_file_length(c, storage_id);
James Kung98c0ba12015-09-09 15:51:59 +0800910 Do_ADBG_EndSubCase(c, "Test truncate file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200911
James Kung98c0ba12015-09-09 15:51:59 +0800912 Do_ADBG_BeginSubCase(c, "Test extend file length");
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200913 test_extend_file_length(c, storage_id);
James Kung98c0ba12015-09-09 15:51:59 +0800914 Do_ADBG_EndSubCase(c, "Test extend file length");
Pascal Brandc639ac82015-07-02 08:53:34 +0200915
James Kung98c0ba12015-09-09 15:51:59 +0800916 Do_ADBG_BeginSubCase(c, "Test file hole");
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200917 test_file_hole(c, storage_id);
James Kung98c0ba12015-09-09 15:51:59 +0800918 Do_ADBG_EndSubCase(c, "Test file hole");
Pascal Brandc639ac82015-07-02 08:53:34 +0200919}
920
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200921DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6007)
922
923static void xtest_tee_test_6008_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200924{
925 TEEC_Session sess;
926 uint32_t obj;
927 uint8_t out[10] = { 0 };
928 uint32_t count;
929 uint32_t orig;
930
931 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
932 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
933 return;
934
935 /* create */
936 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
937 fs_create(&sess, file_02, sizeof(file_02),
938 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200939 sizeof(data_01), &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200940 goto exit;
941
942 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
943 goto exit;
944
945 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
946 fs_open(&sess, file_02, sizeof(file_02),
947 TEE_DATA_FLAG_ACCESS_WRITE |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200948 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200949 goto exit;
950
951 /* write new data */
952 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
953 fs_write(&sess, obj, data_00, sizeof(data_00))))
954 goto exit;
955
956 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
957 fs_rename(&sess, obj, file_03, sizeof(file_03))))
958 goto exit;
959
960 /* close */
961 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj)))
962 goto exit;
963
964 /* verify */
965 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
966 fs_open(&sess, file_03, sizeof(file_03),
967 TEE_DATA_FLAG_ACCESS_READ |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200968 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +0200969 goto exit;
970
971 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_read(&sess, obj, out, 10, &count)))
972 goto exit;
973
974 /* check buffer */
975 (void)ADBG_EXPECT_BUFFER(c, data_00, 10, out, count);
976
977 /* clean */
978 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
979 goto exit;
980
981exit:
982 TEEC_CloseSession(&sess);
983}
984
Jerome Forissier0e99d6a2016-07-25 14:21:43 +0200985DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6008)
986
987static void xtest_tee_test_6009_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandc639ac82015-07-02 08:53:34 +0200988{
989 TEEC_Session sess;
990 uint32_t obj0;
991 uint32_t obj1;
992 uint32_t obj2;
993 uint32_t e = 0;
994 uint8_t info[200];
995 uint8_t id[200];
996 uint32_t orig;
997
998 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
999 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1000 return;
1001
1002 /* create file 00 */
1003 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1004 fs_create(&sess, file_00, sizeof(file_00),
1005 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001006 sizeof(data_01), &obj0, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001007 goto exit;
1008
1009 /* create file 01 */
1010 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1011 fs_create(&sess, file_01, sizeof(file_01),
1012 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001013 sizeof(data_01), &obj1, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001014 goto exit;
1015
1016 /* create file 02 */
1017 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1018 fs_create(&sess, file_02, sizeof(file_02),
1019 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001020 sizeof(data_01), &obj2, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001021 goto exit;
1022
1023 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj0)))
1024 goto exit;
1025
1026 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj1)))
1027 goto exit;
1028
1029 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_close(&sess, obj2)))
1030 goto exit;
1031
1032 /* iterate */
1033 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_alloc_enum(&sess, &e)))
1034 goto exit;
1035
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001036 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_start_enum(&sess, e, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001037 goto exit;
1038
1039 /* get 00 */
1040 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1041 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1042 goto exit;
1043
1044 /* get 01 */
1045 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc603e0d2016-04-25 12:37:18 +02001046 fs_next_enum(&sess, e, NULL, 0, id, sizeof(id))))
Pascal Brandc639ac82015-07-02 08:53:34 +02001047 goto exit;
1048
1049 /* get 02 */
1050 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1051 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1052 goto exit;
1053
1054 /* we should not have more files */
1055 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
1056 fs_next_enum(&sess, e, info, sizeof(info), id, sizeof(id))))
1057 goto exit;
1058
1059 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_free_enum(&sess, e)))
1060 goto exit;
1061
1062 /* clean */
1063 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1064 fs_open(&sess, file_00, sizeof(file_00),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001065 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj0, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001066 goto exit;
1067
1068 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj0)))
1069 goto exit;
1070
1071 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1072 fs_open(&sess, file_01, sizeof(file_01),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001073 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj1, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001074 goto exit;
1075
1076 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj1)))
1077 goto exit;
1078
1079 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1080 fs_open(&sess, file_02, sizeof(file_02),
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001081 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj2, storage_id)))
Pascal Brandc639ac82015-07-02 08:53:34 +02001082 goto exit;
1083
1084 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj2)))
1085 goto exit;
1086
1087exit:
1088 TEEC_CloseSession(&sess);
1089}
1090
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001091DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6009)
1092
Jerome Forissiere3688342015-09-24 10:45:17 -07001093#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001094static void xtest_tee_test_6010(ADBG_Case_t *c)
1095{
1096 TEEC_Session sess;
1097 uint32_t orig;
1098 uint8_t out[4000] = {0};
1099 uint8_t in[0x12c] = {'b'};
Pascal Brand30844922015-09-17 12:12:42 +02001100 int i;
1101
1102 for (i=0; i<sizeof(in); i++)
1103 in[i] = i;
Pascal Brand8a74e362015-09-10 12:41:52 +02001104
1105 if (!ADBG_EXPECT_TEEC_SUCCESS(
1106 c, xtest_teec_open_session(
1107 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1108 return;
1109
1110 Do_ADBG_BeginSubCase(
1111 c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)");
1112
1113 if (!ADBG_EXPECT_TEEC_RESULT(
1114 c, TEEC_ERROR_ACCESS_CONFLICT, ds_open_access_conf(&sess)))
1115 goto exit;
1116
1117 Do_ADBG_EndSubCase(
1118 c, "GP DS CreatePersistentObject AccessConflict (9d-1d-62)");
1119 Do_ADBG_BeginSubCase(
1120 c, "GP DS RestrictObjectUsagePanic (9d-5d-46)");
1121
1122 if (!ADBG_EXPECT_TEEC_RESULT(
1123 c, TEE_ERROR_TARGET_DEAD, ds_res_obj_panic(&sess)))
1124 goto exit;
1125
1126 TEEC_CloseSession(&sess);
1127
1128 Do_ADBG_EndSubCase(
1129 c, "GP DS RestrictObjectUsagePanic (9d-5d-46)");
1130 Do_ADBG_BeginSubCase(
1131 c, "GP DS SeekObjectData BadHandle (9d-c3-c8)");
1132
1133 if (!ADBG_EXPECT_TEEC_SUCCESS(
1134 c, xtest_teec_open_session(
1135 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1136 return;
1137
1138 if (!ADBG_EXPECT_TEEC_RESULT(
1139 c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_bad_handle(&sess)))
1140 goto exit;
1141
1142 TEEC_CloseSession(&sess);
1143
1144 Do_ADBG_EndSubCase(
1145 c, "GP DS SeekObjectData BadHandle (9d-c3-c8)");
1146 Do_ADBG_BeginSubCase(
1147 c, "GP DS SeekObjectData NotPersist (9d-db-4a)");
1148
1149 if (!ADBG_EXPECT_TEEC_SUCCESS(
1150 c, xtest_teec_open_session(
1151 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1152 return;
1153
1154 if (!ADBG_EXPECT_TEEC_RESULT(
1155 c, TEE_ERROR_TARGET_DEAD, ds_seek_obj_inv_handle(&sess)))
1156 goto exit;
1157
1158 TEEC_CloseSession(&sess);
1159
1160 Do_ADBG_EndSubCase(
1161 c, "GP DS SeekObjectData NotPersist (9d-db-4a)");
1162 Do_ADBG_BeginSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)");
1163
1164 if (!ADBG_EXPECT_TEEC_SUCCESS(
1165 c, xtest_teec_open_session(
1166 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1167 return;
1168
1169 if (!ADBG_EXPECT_TEEC_SUCCESS(
1170 c, ds_seek_gp(
1171 &sess, TEE_DATA_SEEK_END, 0, 2, data_00, sizeof(data_00), out,
1172 sizeof(out))))
1173 goto exit;
1174
1175 /* check buffer */
1176 (void)ADBG_EXPECT_BUFFER(
1177 c, data_00, sizeof(data_00), out, sizeof(data_00));
Pascal Brand30844922015-09-17 12:12:42 +02001178 memset(out, 0xab, sizeof(out));
Pascal Brand8a74e362015-09-10 12:41:52 +02001179
1180 if (!ADBG_EXPECT_TEEC_SUCCESS(
1181 c, ds_seek_gp(
Pascal Brand30844922015-09-17 12:12:42 +02001182 &sess, TEE_DATA_SEEK_END, sizeof(in)/2, 0, in, sizeof(in), out,
Pascal Brand8a74e362015-09-10 12:41:52 +02001183 sizeof(out))))
1184 goto exit;
1185
Pascal Brand30844922015-09-17 12:12:42 +02001186 (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2,
1187 out + (sizeof(in) / 2), sizeof(in) / 2);
1188 memset(in, 0, sizeof(in));
1189 (void)ADBG_EXPECT_BUFFER(c, in, sizeof(in) / 2,
1190 out, sizeof(in)/2);
1191 memset(out, 0xab, sizeof(out));
Pascal Brand8a74e362015-09-10 12:41:52 +02001192
1193 Do_ADBG_EndSubCase(c, "GP DS SeekWriteRead SEEK_END (9d-e4-58)");
1194 Do_ADBG_BeginSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)");
1195
1196 if (!ADBG_EXPECT_TEEC_RESULT(
1197 c, TEE_ERROR_ACCESS_CONFLICT, ds_rename_access_conflict(&sess)))
1198 goto exit;
1199
1200 Do_ADBG_EndSubCase(c, "GP DS Rename Access Conflict (9d-29-d1)");
1201 Do_ADBG_BeginSubCase(
1202 c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)");
1203
1204 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_start_enum_no_item(&sess)))
1205 goto exit;
1206
1207 Do_ADBG_EndSubCase(
1208 c, "GP DS StartPersistentObjectEnumerator ItemNotFound (9d-52-ec)");
1209 Do_ADBG_BeginSubCase(
1210 c, "GP DS RenamePersistent ReadWrite (9d-19-88)");
1211
1212 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_rename_success(&sess)))
1213 goto exit;
1214
1215 Do_ADBG_EndSubCase(
1216 c, "GP DS RenamePersistent ReadWrite (9d-19-88)");
1217 Do_ADBG_BeginSubCase(
1218 c, "GP DS Close Free Reset Null (9d-6d-87)");
1219
1220 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_null_close_free_reset(&sess)))
1221 goto exit;
1222
1223 Do_ADBG_EndSubCase(
1224 c, "GP DS Close Free Reset Null (9d-6d-87)");
1225
1226exit:
1227 TEEC_CloseSession(&sess);
1228}
1229
1230static void xtest_tee_test_6011(ADBG_Case_t *c)
1231{
1232 TEEC_Session sess;
1233 uint32_t orig;
1234 /*
1235 * Test data from
1236 * Invoke_InitObjectAndAttributes_TEE_TYPE_AES_success_attribute_
1237 * TEE_ATTR_SECRET_VALUE_correct_size (9d-9a-91)
1238 */
1239 static const uint8_t attr_meta[] = {
12400xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
12410x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
12420x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
12430x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1244 };
1245 static const uint8_t attr_data[] = {
12460x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,
12470x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,
12480xdf,0xf4,
1249 };
1250
1251 if (!ADBG_EXPECT_TEEC_SUCCESS(
1252 c, xtest_teec_open_session(
1253 &sess, &gp_tta_ds_uuid, NULL, &orig)))
1254 return;
1255
1256 if (!ADBG_EXPECT_TEEC_SUCCESS(c, ds_init_object_and_attributes(&sess,
1257 0xa0000010, 0x100, attr_meta, sizeof(attr_meta), attr_data,
1258 sizeof(attr_data), 0)))
1259 goto exit;
1260
1261exit:
1262 TEEC_CloseSession(&sess);
1263}
1264#endif
1265
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001266static void xtest_tee_test_6012_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brandeb84c442016-04-19 17:49:49 +02001267{
1268 TEEC_Session sess;
1269 uint32_t orig;
1270 uint32_t obj;
1271
1272 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1273 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1274 return;
1275
1276 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001277 fs_create_overwrite(&sess, file_04, sizeof(file_04), storage_id)))
Pascal Brandeb84c442016-04-19 17:49:49 +02001278 goto exit;
1279
1280 TEEC_CloseSession(&sess);
1281
1282 /* re-create the same */
1283 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1284 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1285 return;
1286
1287 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001288 fs_create_overwrite(&sess, file_04, sizeof(file_04),
1289 storage_id)))
Pascal Brandeb84c442016-04-19 17:49:49 +02001290 goto exit;
1291
1292 /*
1293 * recreate it with an object, and remove it so that xtest 6009
1294 * can be replayed
1295 */
1296 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1297 fs_create(&sess, file_04, sizeof(file_04),
1298 TEE_DATA_FLAG_ACCESS_WRITE |
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001299 TEE_DATA_FLAG_ACCESS_WRITE_META |
1300 TEE_DATA_FLAG_OVERWRITE, 0, NULL, 0, &obj,
1301 storage_id)))
Pascal Brandeb84c442016-04-19 17:49:49 +02001302 goto exit;
1303
1304 /* clean */
1305 if (!ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj)))
1306 goto exit;
1307
1308exit:
1309 TEEC_CloseSession(&sess);
1310}
1311
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001312DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6012)
1313
1314static void xtest_tee_test_6013_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brand90f23352016-05-19 15:15:47 +02001315{
1316 TEEC_Session sess;
1317 uint32_t orig;
1318 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1319
1320 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1321 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1322 return;
1323
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001324 op.params[0].value.a = storage_id;
1325 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brand90f23352016-05-19 15:15:47 +02001326 TEEC_NONE, TEEC_NONE);
1327
1328 ADBG_EXPECT_TEEC_SUCCESS(c,
1329 TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_KEY_IN_PERSISTENT,
1330 &op, &orig));
1331
1332 TEEC_CloseSession(&sess);
1333}
1334
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001335DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6013)
1336
1337static void xtest_tee_test_6014_single(ADBG_Case_t *c, uint32_t storage_id)
Pascal Brand29ee18f2016-05-23 14:13:56 +02001338{
1339 TEEC_Session sess;
1340 uint32_t orig;
1341 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1342
1343 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1344 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1345 return;
1346
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001347 op.params[0].value.a = storage_id;
1348 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE,
Pascal Brand29ee18f2016-05-23 14:13:56 +02001349 TEEC_NONE, TEEC_NONE);
1350
1351 ADBG_EXPECT_TEEC_SUCCESS(c,
1352 TEEC_InvokeCommand(&sess, TA_STORAGE_CMD_LOOP, &op, &orig));
1353
1354 TEEC_CloseSession(&sess);
1355}
1356
Jerome Forissier0e99d6a2016-07-25 14:21:43 +02001357DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6014)
1358
Jerome Forissiere3854162016-08-12 12:40:12 +02001359static int get_ta_storage_path(TEEC_UUID *p_uuid, char *buffer, uint32_t len)
1360{
1361 int s;
1362
1363 if (!p_uuid || !buffer)
1364 return -1;
1365
1366 s = snprintf(buffer, len, "/data/tee/");
1367 if (s < 0 || s >= (int)len)
1368 return -1;
1369
1370 len -= s;
1371 buffer += s;
1372
1373 s = ree_fs_get_ta_dirname(p_uuid, buffer, len);
1374 return s;
1375}
1376
1377static int rename_data_dir(TEEC_UUID *old, TEEC_UUID *nw)
1378{
1379 char opath[150];
1380 char npath[150];
1381 int s;
1382
1383 s = get_ta_storage_path(old, opath, sizeof(opath));
1384 if (s < 0 || s >= (int)sizeof(opath)) {
1385 s = -1;
1386 goto exit;
1387 }
1388 s = get_ta_storage_path(nw, npath, sizeof(npath));
1389 if (s < 0 || s >= (int)sizeof(opath)) {
1390 s = -1;
1391 goto exit;
1392 }
1393 s = rename(opath, npath);
1394exit:
1395 if (s < 0)
1396 fprintf(stderr, "Warning: could not rename %s -> %s\n", opath,
1397 npath);
1398 return s;
1399}
1400
1401static void xtest_tee_test_6015_single(ADBG_Case_t *c, uint32_t storage_id)
1402{
1403 TEEC_Session sess;
1404 TEEC_Session sess2;
1405 uint32_t orig;
1406 uint32_t obj;
1407 uint32_t obj2;
1408 TEEC_UUID uuid = TA_STORAGE_UUID;
1409 TEEC_UUID uuid2 = TA_STORAGE2_UUID;
1410
1411 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1412 xtest_teec_open_session(&sess, &storage_ta_uuid, NULL, &orig)))
1413 return;
1414
1415 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1416 xtest_teec_open_session(&sess2, &storage2_ta_uuid, NULL,
1417 &orig)))
1418 goto exit2;
1419
1420 /* TA #1 creates a persistent object */
1421 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1422 fs_create(&sess, file_01, sizeof(file_01),
1423 TEE_DATA_FLAG_ACCESS_WRITE |
1424 TEE_DATA_FLAG_ACCESS_READ |
1425 TEE_DATA_FLAG_ACCESS_WRITE_META, 0, data_00,
1426 sizeof(data_00), &obj, storage_id)))
1427 goto exit;
1428
1429 /* TA #2 tries to open the object created by TA #1 */
1430 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
1431 fs_open(&sess2, file_01, sizeof(file_01),
1432 TEE_DATA_FLAG_ACCESS_READ, &obj2, storage_id)))
1433 goto clean;
1434
1435 if (storage_id == TEE_STORAGE_PRIVATE_REE) {
1436 /*
1437 * When the storage backend is the REE filesystem, we can
1438 * simulate a hack attempt by renaming the TA storage. Should
1439 * be detected by the TEE.
1440 */
1441 if (rename_data_dir(&uuid, &uuid2) < 0)
1442 goto clean;
1443
1444 /* TA #2 tries to open the object created by TA #1 */
1445 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_CORRUPT_OBJECT,
1446 fs_open(&sess2, file_01, sizeof(file_01),
1447 TEE_DATA_FLAG_ACCESS_READ, &obj2, storage_id));
1448 /*
1449 * At this point, the TEE is expected to have removed the
1450 * corrupt object, so there is no need to try and restore the
1451 * directory name.
1452 */
1453 goto exit;
1454 }
1455
1456clean:
1457 ADBG_EXPECT_TEEC_SUCCESS(c, fs_unlink(&sess, obj));
1458exit:
1459 TEEC_CloseSession(&sess2);
1460exit2:
1461 TEEC_CloseSession(&sess);
1462}
1463
1464DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6015)
1465
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001466
1467struct test_6016_thread_arg {
1468 ADBG_Case_t *case_t;
1469 uint32_t storage_id;
1470 uint8_t file_name[8];
1471 TEEC_Session session;
1472};
1473
1474static void *test_6016_thread(void *arg)
1475{
1476 struct test_6016_thread_arg *a = arg;
1477 TEEC_Session sess = a->session;
1478 uint32_t obj;
1479 uint8_t out[10] = { 0 };
1480 uint32_t count;
1481
1482 /* create */
1483 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1484 fs_create(&sess, a->file_name, sizeof(a->file_name),
1485 TEE_DATA_FLAG_ACCESS_WRITE, 0, data_01,
1486 sizeof(data_01), &obj, a->storage_id)))
1487 goto exit;
1488
1489 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_close(&sess, obj)))
1490 goto exit;
1491
1492 /* write new data */
1493 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1494 fs_open(&sess, a->file_name, sizeof(a->file_name),
1495 TEE_DATA_FLAG_ACCESS_WRITE, &obj, a->storage_id)))
1496 goto exit;
1497
1498 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1499 fs_write(&sess, obj, data_00, sizeof(data_00))))
1500 goto exit;
1501
1502 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_close(&sess, obj)))
1503 goto exit;
1504
1505 /* verify */
1506 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1507 fs_open(&sess, a->file_name, sizeof(a->file_name),
1508 TEE_DATA_FLAG_ACCESS_READ |
1509 TEE_DATA_FLAG_ACCESS_WRITE_META, &obj, a->storage_id)))
1510 goto exit;
1511
1512 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t,
1513 fs_read(&sess, obj, out, 10, &count)))
1514 goto exit;
1515
1516 (void)ADBG_EXPECT_BUFFER(a->case_t, data_00, 10, out, count);
1517
1518 /* clean */
1519 if (!ADBG_EXPECT_TEEC_SUCCESS(a->case_t, fs_unlink(&sess, obj)))
1520 goto exit;
1521
1522exit:
1523 return NULL;
1524}
1525
1526
1527#define NUM_THREADS 4
1528static void xtest_tee_test_6016_loop(ADBG_Case_t *c, uint32_t storage_id)
1529{
1530 size_t num_threads = NUM_THREADS;
1531 struct test_6016_thread_arg arg[num_threads];
1532 pthread_t thr[num_threads];
1533 uint32_t orig;
1534 size_t i;
1535 size_t n = 0;
1536 size_t m;
1537
1538 memset(arg, 0, sizeof(arg));
1539
1540 for (m = 0; m < num_threads; m++)
1541 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1542 xtest_teec_open_session(&arg[m].session,
1543 &storage_ta_uuid, NULL, &orig)))
1544 goto out;
1545
1546 for (n = 0; n < num_threads; n++) {
1547 arg[n].case_t = c;
1548 arg[n].storage_id = storage_id;
1549 snprintf(&arg[n].file_name, sizeof(arg[n].file_name),
1550 "file_%d", n);
1551 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1552 test_6016_thread, arg + n)))
1553 goto out;
1554 }
1555
1556out:
1557 for (i = 0; i < n; i++)
1558 ADBG_EXPECT(c, 0, pthread_join(thr[i], NULL));
1559 for (i = 0; i < m; i++)
1560 TEEC_CloseSession(&arg[i].session);
1561}
1562
1563/* concurency */
1564static void xtest_tee_test_6016_single(ADBG_Case_t *c, uint32_t storage_id)
1565{
1566 int i;
1567 int loops = 8;
1568
1569 Do_ADBG_Log(" threads: %d, loops: %d", NUM_THREADS, loops);
1570 for (i = 0; i < loops; i++)
1571 xtest_tee_test_6016_loop(c, storage_id);
1572}
1573
1574/*
1575 * To be replaced with: DEFINE_TEST_MULTIPLE_STORAGE_IDS(xtest_tee_test_6016)
1576 * when all filesystems support concurrency
1577 */
1578static void xtest_tee_test_6016(ADBG_Case_t *c)
1579{
1580#ifdef CFG_RPMB_FS
1581 Do_ADBG_BeginSubCase(c, "Storage id: %08x", TEE_STORAGE_PRIVATE_RPMB);
1582 xtest_tee_test_6016_single(c, TEE_STORAGE_PRIVATE_RPMB);
1583 Do_ADBG_EndSubCase(c, "Storage id: %08x", TEE_STORAGE_PRIVATE_RPMB);
1584#else
1585 Do_ADBG_Log(" Only RPMB supports concurrency. Test disabled.");
1586#endif
1587}
1588
1589
Pascal Brandc639ac82015-07-02 08:53:34 +02001590ADBG_CASE_DEFINE(
1591 XTEST_TEE_6001, xtest_tee_test_6001,
1592 /* Title */
1593 "Test TEE_CreatePersistentObject",
1594 /* Short description */
1595 "Short description ...",
1596 /* Requirement IDs */
1597 "TEE-??",
1598 /* How to implement */
1599 "Description of how to implement ..."
1600 );
1601
1602ADBG_CASE_DEFINE(
1603 XTEST_TEE_6002, xtest_tee_test_6002,
1604 /* Title */
1605 "Test TEE_OpenPersistentObject",
1606 /* Short description */
1607 "Short description ...",
1608 /* Requirement IDs */
1609 "TEE-??",
1610 /* How to implement */
1611 "Description of how to implement ..."
1612 );
1613
1614ADBG_CASE_DEFINE(
1615 XTEST_TEE_6003, xtest_tee_test_6003,
1616 /* Title */
1617 "Test TEE_ReadObjectData",
1618 /* Short description */
1619 "Short description ...",
1620 /* Requirement IDs */
1621 "TEE-??",
1622 /* How to implement */
1623 "Description of how to implement ..."
1624 );
1625
1626ADBG_CASE_DEFINE(
1627 XTEST_TEE_6004, xtest_tee_test_6004,
1628 /* Title */
1629 "Test TEE_WriteObjectData",
1630 /* Short description */
1631 "Short description ...",
1632 /* Requirement IDs */
1633 "TEE-??",
1634 /* How to implement */
1635 "Description of how to implement ..."
1636 );
1637
1638ADBG_CASE_DEFINE(
1639 XTEST_TEE_6005, xtest_tee_test_6005,
1640 /* Title */
1641 "Test TEE_SeekObjectData",
1642 /* Short description */
1643 "Short description ...",
1644 /* Requirement IDs */
1645 "TEE-??",
1646 /* How to implement */
1647 "Description of how to implement ..."
1648 );
1649
1650ADBG_CASE_DEFINE(
1651 XTEST_TEE_6006, xtest_tee_test_6006,
1652 /* Title */
1653 "Test TEE_CloseAndDeletePersistentObject",
1654 /* Short description */
1655 "Short description ...",
1656 /* Requirement IDs */
1657 "TEE-??",
1658 /* How to implement */
1659 "Description of how to implement ..."
1660 );
1661
1662ADBG_CASE_DEFINE(
1663 XTEST_TEE_6007, xtest_tee_test_6007,
1664 /* Title */
1665 "Test TEE_TruncateObjectData",
1666 /* Short description */
1667 "Short description ...",
1668 /* Requirement IDs */
1669 "TEE-??",
1670 /* How to implement */
1671 "Description of how to implement ..."
1672 );
1673
1674ADBG_CASE_DEFINE(
1675 XTEST_TEE_6008, xtest_tee_test_6008,
1676 /* Title */
1677 "Test TEE_RenamePersistentObject",
1678 /* Short description */
1679 "Short description ...",
1680 /* Requirement IDs */
1681 "TEE-??",
1682 /* How to implement */
1683 "Description of how to implement ..."
1684 );
1685
1686ADBG_CASE_DEFINE(
1687 XTEST_TEE_6009, xtest_tee_test_6009,
1688 /* Title */
1689 "Test TEE Internal API Persistent Object Enumeration Functions",
1690 /* Short description */
1691 "Short description ...",
1692 /* Requirement IDs */
1693 "TEE-??",
1694 /* How to implement */
1695 "Description of how to implement ..."
1696 );
Pascal Brand8a74e362015-09-10 12:41:52 +02001697
Jerome Forissiere3688342015-09-24 10:45:17 -07001698#ifdef WITH_GP_TESTS
Pascal Brand8a74e362015-09-10 12:41:52 +02001699ADBG_CASE_DEFINE(
1700 XTEST_TEE_6010, xtest_tee_test_6010,
1701 /* Title */
1702 "Test TEE GP TTA DS storage",
1703 /* Short description */
1704 "Short description ...",
1705 /* Requirement IDs */
1706 "TEE-??",
1707 /* How to implement */
1708 "Description of how to implement ..."
1709);
1710
1711ADBG_CASE_DEFINE(
1712 XTEST_TEE_6011, xtest_tee_test_6011,
1713 /* Title */
1714 "Test TEE GP TTA DS init objects",
1715 /* Short description */
1716 "Short description ...",
1717 /* Requirement IDs */
1718 "TEE-??",
1719 /* How to implement */
1720 "Description of how to implement ..."
1721);
1722#endif
Pascal Brandeb84c442016-04-19 17:49:49 +02001723
1724ADBG_CASE_DEFINE(
1725 XTEST_TEE_6012, xtest_tee_test_6012,
1726 /* Title */
1727 "Test TEE GP TTA DS init objects",
1728 /* Short description */
1729 "Short description ...",
1730 /* Requirement IDs */
1731 "TEE-??",
1732 /* How to implement */
1733 "Description of how to implement ..."
1734);
Pascal Brand90f23352016-05-19 15:15:47 +02001735
1736ADBG_CASE_DEFINE(
1737 XTEST_TEE_6013, xtest_tee_test_6013,
1738 /* Title */
1739 "Key usage in Persistent objects",
1740 /* Short description */
1741 "Short description ...",
1742 /* Requirement IDs */
1743 "TEE-??",
1744 /* How to implement */
1745 "Description of how to implement ..."
1746);
Pascal Brand29ee18f2016-05-23 14:13:56 +02001747
1748ADBG_CASE_DEFINE(
1749 XTEST_TEE_6014, xtest_tee_test_6014,
1750 /* Title */
1751 "Loop on Persistent objects",
1752 /* Short description */
1753 "Short description ...",
1754 /* Requirement IDs */
1755 "TEE-??",
1756 /* How to implement */
1757 "Description of how to implement ..."
1758);
Jerome Forissiere3854162016-08-12 12:40:12 +02001759
1760ADBG_CASE_DEFINE(
1761 XTEST_TEE_6015, xtest_tee_test_6015,
1762 /* Title */
1763 "Storage isolation",
1764 /* Short description */
1765 "TA #2 tries to open object created by TA #1, should fail",
1766 /* Requirement IDs */
1767 "",
1768 /* How to implement */
1769 ""
1770);
Lijianhui (Airbak)29d7c7a2016-08-24 17:35:55 +08001771
1772ADBG_CASE_DEFINE(
1773 XTEST_TEE_6016, xtest_tee_test_6016,
1774 /* Title */
1775 "Storage concurency",
1776 /* Short description */
1777 "Multiple thread operate secure storage",
1778 /* Requirement IDs */
1779 "",
1780 /* How to implement */
1781 ""
1782);