blob: 678b0e08c3823f4669acb05e1d33e4aeb522f4fe [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
Etienne Carrierea4653552017-01-11 10:04:24 +010014#include <limits.h>
15#include <pthread.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020016#include <stdio.h>
17#include <string.h>
David Brownb2865ab2016-08-02 11:44:41 -060018#include <sys/stat.h>
19#include <sys/types.h>
Etienne Carrierea4653552017-01-11 10:04:24 +010020#include <unistd.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020021
22#include "xtest_test.h"
23#include "xtest_helpers.h"
Jens Wiklander4441fe22015-10-23 16:53:02 +020024#include <signed_hdr.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020025
Etienne Carriere726d8bc2017-03-21 15:45:59 +010026#include <pta_invoke_tests.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020027#include <ta_crypt.h>
28#include <ta_os_test.h>
29#include <ta_create_fail_test.h>
30#include <ta_rpc_test.h>
31#include <ta_sims_test.h>
Jens Wiklanderac27ec12015-07-15 15:23:14 +020032#include <ta_concurrent.h>
Etienne Carriere50abf9a2017-03-24 11:33:50 +010033#include <sdp_basic.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020034
35static void xtest_tee_test_1001(ADBG_Case_t *Case_p);
Jens Wiklander1d70a112017-10-16 15:16:39 +020036static void xtest_tee_test_1002(ADBG_Case_t *Case_p);
Jens Wiklander0c86bc32017-11-13 19:52:03 +010037static void xtest_tee_test_1003(ADBG_Case_t *Case_p);
Pascal Brandc639ac82015-07-02 08:53:34 +020038static void xtest_tee_test_1004(ADBG_Case_t *Case_p);
39static void xtest_tee_test_1005(ADBG_Case_t *Case_p);
40static void xtest_tee_test_1006(ADBG_Case_t *Case_p);
41static void xtest_tee_test_1007(ADBG_Case_t *Case_p);
42static void xtest_tee_test_1008(ADBG_Case_t *Case_p);
43static void xtest_tee_test_1009(ADBG_Case_t *Case_p);
44static void xtest_tee_test_1010(ADBG_Case_t *Case_p);
45static void xtest_tee_test_1011(ADBG_Case_t *Case_p);
46static void xtest_tee_test_1012(ADBG_Case_t *Case_p);
Jens Wiklanderac27ec12015-07-15 15:23:14 +020047static void xtest_tee_test_1013(ADBG_Case_t *Case_p);
Etienne Carriere50abf9a2017-03-24 11:33:50 +010048#ifdef CFG_SECURE_DATA_PATH
49static void xtest_tee_test_1014(ADBG_Case_t *Case_p);
50#endif
Jens Wiklander272d3642017-04-03 13:03:47 +020051static void xtest_tee_test_1015(ADBG_Case_t *Case_p);
Jerome Forissiere916b102017-06-07 17:55:52 +020052static void xtest_tee_test_1016(ADBG_Case_t *Case_p);
Pascal Brandc639ac82015-07-02 08:53:34 +020053
Jens Wiklander74abfe32017-01-03 14:17:47 +010054ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests");
Jens Wiklander1d70a112017-10-16 15:16:39 +020055ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters");
Jens Wiklander0c86bc32017-11-13 19:52:03 +010056ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003,
57 "Core internal read/write mutex");
Jens Wiklander74abfe32017-01-03 14:17:47 +010058ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA");
59ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions");
60ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006,
61 "Test Basic OS features");
62ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic");
63ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008,
Jens Wiklander25a57fe2016-12-26 21:46:24 +010064 "TEE internal client API");
Jens Wiklander74abfe32017-01-03 14:17:47 +010065ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait");
66ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010,
67 "Invalid memory access");
68ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011,
Jens Wiklanderf7b9c632017-01-03 17:32:26 +010069 "Test TA-to-TA features with User Crypt TA");
Jens Wiklander74abfe32017-01-03 14:17:47 +010070ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012,
Jens Wiklander25a57fe2016-12-26 21:46:24 +010071 "Test Single Instance Multi Session features with SIMS TA");
Jens Wiklander74abfe32017-01-03 14:17:47 +010072ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013,
Jens Wiklander25a57fe2016-12-26 21:46:24 +010073 "Test concurency with concurrent TA");
Etienne Carriere50abf9a2017-03-24 11:33:50 +010074#ifdef CFG_SECURE_DATA_PATH
75ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014,
76 "Test secure data path against SDP TAs and pTAs");
77#endif
Jens Wiklander272d3642017-04-03 13:03:47 +020078ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015,
79 "FS hash-tree corner cases");
Jerome Forissiere916b102017-06-07 17:55:52 +020080ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016,
81 "Test TA to TA transfers (in/out/inout memrefs on the stack)");
Jens Wiklanderac27ec12015-07-15 15:23:14 +020082
Pascal Brandc639ac82015-07-02 08:53:34 +020083struct xtest_crypto_session {
84 ADBG_Case_t *c;
85 TEEC_Session *session;
86 uint32_t cmd_id_sha256;
87 uint32_t cmd_id_aes256ecb_encrypt;
88 uint32_t cmd_id_aes256ecb_decrypt;
89};
90
91static void xtest_crypto_test(struct xtest_crypto_session *cs)
92{
93 uint32_t ret_orig;
94 uint8_t crypt_out[16];
95 uint8_t crypt_in[16] = { 22, 17 };
96
97 crypt_in[15] = 60;
98
99 Do_ADBG_BeginSubCase(cs->c, "AES encrypt");
100 {
101 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
102
103 op.params[0].tmpref.buffer = crypt_in;
104 op.params[0].tmpref.size = sizeof(crypt_in);
105 op.params[1].tmpref.buffer = crypt_out;
106 op.params[1].tmpref.size = sizeof(crypt_out);
107 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
108 TEEC_MEMREF_TEMP_OUTPUT,
109 TEEC_NONE, TEEC_NONE);
110
111 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
112 TEEC_InvokeCommand(cs->session,
113 cs->
114 cmd_id_aes256ecb_encrypt,
115 &op,
116 &ret_orig));
117 }
118 Do_ADBG_EndSubCase(cs->c, "AES encrypt");
119
120 Do_ADBG_BeginSubCase(cs->c, "AES decrypt");
121 {
122 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
123 uint8_t out[16];
124
125 op.params[0].tmpref.buffer = crypt_out;
126 op.params[0].tmpref.size = sizeof(crypt_out);
127 op.params[1].tmpref.buffer = out;
128 op.params[1].tmpref.size = sizeof(out);
129 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
130 TEEC_MEMREF_TEMP_OUTPUT,
131 TEEC_NONE, TEEC_NONE);
132
133 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
134 TEEC_InvokeCommand(cs->session,
135 cs->
136 cmd_id_aes256ecb_decrypt,
137 &op,
138 &ret_orig));
139
140 if (!ADBG_EXPECT(cs->c, 0,
141 memcmp(crypt_in, out, sizeof(crypt_in)))) {
142 Do_ADBG_Log("crypt_in:");
143 Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16);
144 Do_ADBG_Log("out:");
145 Do_ADBG_HexLog(out, sizeof(out), 16);
146 }
147 }
148 Do_ADBG_EndSubCase(cs->c, "AES decrypt");
149
150 Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input");
151 {
152 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
153 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
154 static const uint8_t sha256_out[] = {
155 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
156 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
157 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
158 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
159 };
160 uint8_t out[32] = { 0 };
161
162 op.params[0].tmpref.buffer = (void *)sha256_in;
163 op.params[0].tmpref.size = sizeof(sha256_in);
164 op.params[1].tmpref.buffer = out;
165 op.params[1].tmpref.size = sizeof(out);
166 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
167 TEEC_MEMREF_TEMP_OUTPUT,
168 TEEC_NONE, TEEC_NONE);
169
170 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
171 TEEC_InvokeCommand(cs->session,
172 cs->
173 cmd_id_sha256,
174 &op,
175 &ret_orig));
176
177 if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out,
178 sizeof(sha256_out)))) {
179 Do_ADBG_Log("sha256_out:");
180 Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16);
181 Do_ADBG_Log("out:");
182 Do_ADBG_HexLog(out, sizeof(out), 16);
183 }
184 }
185 Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input");
186
Etienne Carrierea3198522017-10-26 09:48:55 +0200187 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200188 {
189 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
190 static const uint8_t in[] = {
191 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
192 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
193 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
194 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
195 };
196 static const uint8_t exp_out[] = {
197 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
198 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
199 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
200 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
201 };
202 uint8_t out[sizeof(exp_out)];
203
204 op.params[0].tmpref.buffer = (void *)in;
205 op.params[0].tmpref.size = sizeof(in);
206 op.params[1].tmpref.buffer = out;
207 op.params[1].tmpref.size = sizeof(out);
208 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
209 TEEC_MEMREF_TEMP_OUTPUT,
210 TEEC_NONE, TEEC_NONE);
211
212 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
213 TEEC_InvokeCommand(cs->session,
214 cs->
215 cmd_id_aes256ecb_encrypt,
216 &op,
217 &ret_orig));
218
219 if (!ADBG_EXPECT(cs->c, 0,
220 memcmp(exp_out, out, sizeof(exp_out)))) {
221 Do_ADBG_Log("exp_out:");
222 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
223 Do_ADBG_Log("out:");
224 Do_ADBG_HexLog(out, sizeof(out), 16);
225 }
226 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200227 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200228
Etienne Carrierea3198522017-10-26 09:48:55 +0200229 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200230 {
231 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
232 static const uint8_t in[] = {
233 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
234 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
235 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
236 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
237 };
238 static const uint8_t exp_out[] = {
239 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
240 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
241 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
242 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
243 };
244 uint8_t out[sizeof(exp_out)];
245
246 op.params[0].tmpref.buffer = (void *)in;
247 op.params[0].tmpref.size = sizeof(in);
248 op.params[1].tmpref.buffer = out;
249 op.params[1].tmpref.size = sizeof(out);
250 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
251 TEEC_MEMREF_TEMP_OUTPUT,
252 TEEC_NONE, TEEC_NONE);
253
254 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
255 TEEC_InvokeCommand(cs->session,
256 cs->
257 cmd_id_aes256ecb_decrypt,
258 &op,
259 &ret_orig));
260
261 if (!ADBG_EXPECT(cs->c, 0,
262 memcmp(exp_out, out, sizeof(exp_out)))) {
263 Do_ADBG_Log("exp_out:");
264 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
265 Do_ADBG_Log("out:");
266 Do_ADBG_HexLog(out, sizeof(out), 16);
267 }
268 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200269 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200270}
271
272static void xtest_tee_test_1001(ADBG_Case_t *c)
273{
Jens Wiklandercf16e842016-02-10 09:07:09 +0100274 TEEC_Result res;
275 TEEC_Session session = { 0 };
276 uint32_t ret_orig;
Pascal Brandc639ac82015-07-02 08:53:34 +0200277
Etienne Carriere11093162017-10-26 09:49:04 +0200278 /* Pseudo TA is optional: warn and nicely exit if not found */
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100279 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
Jens Wiklandercf16e842016-02-10 09:07:09 +0100280 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200281 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
282 Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found");
Jens Wiklandercf16e842016-02-10 09:07:09 +0100283 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200284 }
285 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Pascal Brandc639ac82015-07-02 08:53:34 +0200286
Jens Wiklandercf16e842016-02-10 09:07:09 +0100287 (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100288 &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig));
Jens Wiklandercf16e842016-02-10 09:07:09 +0100289 TEEC_CloseSession(&session);
Pascal Brandc639ac82015-07-02 08:53:34 +0200290}
291
Jens Wiklander1d70a112017-10-16 15:16:39 +0200292static void xtest_tee_test_1002(ADBG_Case_t *c)
293{
294 TEEC_Result res;
295 TEEC_Session session = { 0 };
296 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
297 uint32_t ret_orig;
298 uint8_t buf[16 * 1024];
299 uint8_t exp_sum = 0;
300 size_t n;
301
Etienne Carriere11093162017-10-26 09:49:04 +0200302 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander1d70a112017-10-16 15:16:39 +0200303 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
304 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200305 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
306 Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200307 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200308 }
309 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander1d70a112017-10-16 15:16:39 +0200310
311 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE,
312 TEEC_NONE, TEEC_NONE);
313 op.params[0].tmpref.size = sizeof(buf);
314 op.params[0].tmpref.buffer = buf;
315
316 for (n = 0; n < sizeof(buf); n++)
317 buf[n] = n + 1;
318 for (n = 0; n < sizeof(buf); n++)
319 exp_sum += buf[n];
320
321 if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
322 &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig)))
323 goto out;
324
325 ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]);
326out:
327 TEEC_CloseSession(&session);
328}
329
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100330struct test_1003_arg {
331 uint32_t test_type;
332 size_t repeat;
333 size_t max_before_lockers;
334 size_t max_during_lockers;
335 size_t before_lockers;
336 size_t during_lockers;
337 TEEC_Result res;
338 uint32_t error_orig;
339};
Jens Wiklander1d70a112017-10-16 15:16:39 +0200340
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100341static void *test_1003_thread(void *arg)
342{
343 struct test_1003_arg *a = arg;
344 TEEC_Session session = { 0 };
345 size_t rounds = 64 * 1024;
346 size_t n;
347
348 a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid,
349 NULL, &a->error_orig);
350 if (a->res != TEEC_SUCCESS)
351 return NULL;
352
353 for (n = 0; n < a->repeat; n++) {
354 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
355
356 op.params[0].value.a = a->test_type;
357 op.params[0].value.b = rounds;
358
359 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
360 TEEC_VALUE_OUTPUT,
361 TEEC_NONE, TEEC_NONE);
362 a->res = TEEC_InvokeCommand(&session,
363 PTA_INVOKE_TESTS_CMD_MUTEX,
364 &op, &a->error_orig);
365 if (a->test_type == PTA_MUTEX_TEST_WRITER &&
366 op.params[1].value.b != 1) {
367 Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b);
368 a->res = TEEC_ERROR_BAD_STATE;
369 a->error_orig = 42;
370 break;
371 }
372
373 if (a->test_type == PTA_MUTEX_TEST_READER) {
374 if (op.params[1].value.a > a->max_before_lockers)
375 a->max_before_lockers = op.params[1].value.a;
376
377 if (op.params[1].value.b > a->max_during_lockers)
378 a->max_during_lockers = op.params[1].value.b;
379
380 a->before_lockers += op.params[1].value.a;
381 a->during_lockers += op.params[1].value.b;
382 }
383 }
384 TEEC_CloseSession(&session);
385
386 return NULL;
387}
388
389static void xtest_tee_test_1003(ADBG_Case_t *c)
390{
391 size_t num_threads = 3 * 2;
392 TEEC_Result res;
393 TEEC_Session session = { 0 };
394 uint32_t ret_orig;
395 size_t repeat = 20;
396 pthread_t thr[num_threads];
397 struct test_1003_arg arg[num_threads];
398 size_t max_read_concurrency = 0;
399 size_t max_read_waiters = 0;
400 size_t num_concurrent_read_lockers = 0;
401 size_t num_concurrent_read_waiters = 0;
402 size_t n;
403 size_t nt = num_threads;
404 double mean_read_concurrency;
405 double mean_read_waiters;
406 size_t num_writers = 0;
407 size_t num_readers = 0;
408
409 /* Pseudo TA is optional: warn and nicely exit if not found */
410 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
411 &ret_orig);
412 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
413 Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found");
414 return;
415 }
416 ADBG_EXPECT_TEEC_SUCCESS(c, res);
417 TEEC_CloseSession(&session);
418
419 memset(arg, 0, sizeof(arg));
420
421 for (n = 0; n < nt; n++) {
422 if (n % 3) {
423 arg[n].test_type = PTA_MUTEX_TEST_READER;
424 num_readers++;
425 } else {
426 arg[n].test_type = PTA_MUTEX_TEST_WRITER;
427 num_writers++;
428 }
429 arg[n].repeat = repeat;
430 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
431 test_1003_thread, arg + n)))
432 nt = n; /* break loop and start cleanup */
433 }
434
435 for (n = 0; n < nt; n++) {
436 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
437 if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
438 Do_ADBG_Log("error origin %" PRIu32,
439 arg[n].error_orig);
440 if (arg[n].test_type == PTA_MUTEX_TEST_READER) {
441 if (arg[n].max_during_lockers > max_read_concurrency)
442 max_read_concurrency =
443 arg[n].max_during_lockers;
444
445 if (arg[n].max_before_lockers > max_read_waiters)
446 max_read_waiters = arg[n].max_before_lockers;
447
448 num_concurrent_read_lockers += arg[n].during_lockers;
449 num_concurrent_read_waiters += arg[n].before_lockers;
450 }
451 }
452
453 mean_read_concurrency = (double)num_concurrent_read_lockers /
454 (double)(repeat * num_readers);
455 mean_read_waiters = (double)num_concurrent_read_waiters /
456 (double)(repeat * num_readers);
457
458 Do_ADBG_Log(" Number of parallel threads: %zu (%zu writers and %zu readers)",
459 num_threads, num_writers, num_readers);
460 Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency);
461 Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters);
462 Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency);
463 Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters);
464}
Jens Wiklander1d70a112017-10-16 15:16:39 +0200465
Pascal Brandc639ac82015-07-02 08:53:34 +0200466static void xtest_tee_test_1004(ADBG_Case_t *c)
467{
468 TEEC_Session session = { 0 };
469 uint32_t ret_orig;
470 struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256,
471 TA_CRYPT_CMD_AES256ECB_ENC,
472 TA_CRYPT_CMD_AES256ECB_DEC };
473
474 if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session(
475 &session, &crypt_user_ta_uuid,
476 NULL, &ret_orig)))
477 return;
478
479 /* Run the "complete crypto test suite" */
480 xtest_crypto_test(&cs);
481
482 TEEC_CloseSession(&session);
483}
484
485#ifndef TEEC_ERROR_TARGET_DEAD
486/* To be removed when we have TEEC_ERROR_TARGET_DEAD from tee_client_api.h */
487#define TEEC_ERROR_TARGET_DEAD 0xFFFF3024
488#endif
489
490static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, uint32_t n)
491{
492 TEEC_Session session = { 0 };
493 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
494 uint32_t ret_orig;
495
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300496 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200497 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300498 &ret_orig)))
499 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200500
501 op.params[0].value.a = n;
502 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
503 TEEC_NONE);
504
505 (void)ADBG_EXPECT_TEEC_RESULT(c,
506 TEEC_ERROR_TARGET_DEAD,
507 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
508 &ret_orig));
509
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300510 (void)ADBG_EXPECT_TEEC_RESULT(c,
511 TEEC_ERROR_TARGET_DEAD,
512 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
Pascal Brandc639ac82015-07-02 08:53:34 +0200513 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300514
Pascal Brandc639ac82015-07-02 08:53:34 +0200515 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
516
517 TEEC_CloseSession(&session);
518}
519
520static void xtest_tee_test_1005(ADBG_Case_t *c)
521{
522 uint32_t ret_orig;
523#define MAX_SESSIONS 3
524 TEEC_Session sessions[MAX_SESSIONS];
525 int i;
526
527 for (i = 0; i < MAX_SESSIONS; i++) {
528 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jens Wiklandereb6bce72016-09-23 11:37:33 +0200529 xtest_teec_open_session(&sessions[i],
530 &concurrent_ta_uuid,
Pascal Brandc639ac82015-07-02 08:53:34 +0200531 NULL, &ret_orig)))
532 break;
533 }
534
535 for (; --i >= 0; )
536 TEEC_CloseSession(&sessions[i]);
537}
538
539static void xtest_tee_test_1006(ADBG_Case_t *c)
540{
541 TEEC_Session session = { 0 };
542 uint32_t ret_orig;
543 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
544 uint8_t buf[32];
545
546 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
547 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
548 &ret_orig)))
549 return;
550
551 op.params[0].tmpref.buffer = buf;
552 op.params[0].tmpref.size = sizeof(buf);
553 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
554 TEEC_NONE, TEEC_NONE);
555
556 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
557 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op,
558 &ret_orig));
559
560 TEEC_CloseSession(&session);
561}
562
563static void xtest_tee_test_1007(ADBG_Case_t *c)
564{
565 TEEC_Session session = { 0 };
566 uint32_t ret_orig;
567
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300568 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200569 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300570 &ret_orig)))
571 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200572
573 (void)ADBG_EXPECT_TEEC_RESULT(c,
574 TEEC_ERROR_TARGET_DEAD,
575 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL,
576 &ret_orig));
577
578 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
579
580 (void)ADBG_EXPECT_TEEC_RESULT(c,
581 TEEC_ERROR_TARGET_DEAD,
582 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL,
583 &ret_orig));
584
585 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
586
587 TEEC_CloseSession(&session);
588}
589
Jerome Forissierf02a2212015-10-29 14:33:35 +0100590#ifndef TA_DIR
Victor Chong3d8798f2017-03-01 18:31:48 +0000591# ifdef __ANDROID__
592#define TA_DIR "/system/lib/optee_armtz"
593# else
Jerome Forissierf02a2212015-10-29 14:33:35 +0100594#define TA_DIR "/lib/optee_armtz"
Victor Chong3d8798f2017-03-01 18:31:48 +0000595# endif
Jerome Forissierf02a2212015-10-29 14:33:35 +0100596#endif
597
David Brownb2865ab2016-08-02 11:44:41 -0600598#ifndef TA_TEST_DIR
599# ifdef __ANDROID__
Zoltan Kuscsikd5796152016-10-27 10:09:12 +0200600# define TA_TEST_DIR "/data/tee/optee_armtz"
David Brownb2865ab2016-08-02 11:44:41 -0600601# else
602# define TA_TEST_DIR "/tmp/optee_armtz"
603# endif
604#endif
Jens Wiklanderb7940892015-10-23 16:02:40 +0200605
David Brownb2865ab2016-08-02 11:44:41 -0600606static void make_test_ta_dir(void)
607{
608#ifdef __ANDROID__
Zoltan Kuscsikd5796152016-10-27 10:09:12 +0200609 (void)mkdir("/data/tee", 0755);
David Brownb2865ab2016-08-02 11:44:41 -0600610#endif
611 (void)mkdir(TA_TEST_DIR, 0755);
612}
613
614static void uuid_to_full_name(char *buf, size_t blen, const TEEC_UUID *uuid,
615 bool for_write)
616{
Jens Wiklanderb7940892015-10-23 16:02:40 +0200617 snprintf(buf, blen,
Jens Wiklander6203b872016-12-08 19:18:29 +0100618 "%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta",
David Brownb2865ab2016-08-02 11:44:41 -0600619 for_write ? TA_TEST_DIR : TA_DIR,
620 uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion,
Jens Wiklanderb7940892015-10-23 16:02:40 +0200621 uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1],
622 uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3],
623 uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5],
David Brownb2865ab2016-08-02 11:44:41 -0600624 uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200625}
626
David Brownb2865ab2016-08-02 11:44:41 -0600627static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode,
628 bool for_write)
Jens Wiklanderb7940892015-10-23 16:02:40 +0200629{
630 char buf[PATH_MAX];
631
David Brownb2865ab2016-08-02 11:44:41 -0600632 uuid_to_full_name(buf, sizeof(buf), uuid, for_write);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200633 return fopen(buf, mode);
634}
635
David Brownb2865ab2016-08-02 11:44:41 -0600636static bool rm_file(const TEEC_UUID *uuid)
Jens Wiklanderb7940892015-10-23 16:02:40 +0200637{
638 char buf[PATH_MAX];
639
David Brownb2865ab2016-08-02 11:44:41 -0600640 uuid_to_full_name(buf, sizeof(buf), uuid, true);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200641 return !unlink(buf);
642}
643
David Brownb2865ab2016-08-02 11:44:41 -0600644static bool copy_file(const TEEC_UUID *src_uuid, const TEEC_UUID *dst_uuid)
Jens Wiklanderb7940892015-10-23 16:02:40 +0200645{
646 char buf[4 * 1024];
David Brownb2865ab2016-08-02 11:44:41 -0600647 FILE *src = open_ta_file(src_uuid, "r", false);
648 FILE *dst = open_ta_file(dst_uuid, "w", true);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200649 size_t r;
650 size_t w;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200651 bool ret = false;
Jens Wiklanderb7940892015-10-23 16:02:40 +0200652
Jens Wiklander4441fe22015-10-23 16:53:02 +0200653 if (src && dst) {
654 do {
655 r = fread(buf, 1, sizeof(buf), src);
656 if (!r) {
657 ret = !!feof(src);
658 break;
659 }
660 w = fwrite(buf, 1, r, dst);
661 } while (w == r);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200662 }
Jens Wiklander4441fe22015-10-23 16:53:02 +0200663
664 if (src)
665 fclose(src);
666 if (dst)
667 fclose(dst);
668 return ret;
669}
670
671static bool corrupt_file(FILE *f, long offs, uint8_t mask)
672{
673 uint8_t b;
674
675 if (fseek(f, offs, SEEK_SET))
676 return false;
677
678 if (fread(&b, 1, 1, f) != 1)
679 return false;
680
681 b ^= mask;
682
683 if (fseek(f, offs, SEEK_SET))
684 return false;
685
686 if (fwrite(&b, 1, 1, f) != 1)
687 return false;
688
689 return true;
Jens Wiklanderb7940892015-10-23 16:02:40 +0200690}
691
Jens Wiklander4441fe22015-10-23 16:53:02 +0200692static bool load_corrupt_ta(ADBG_Case_t *c, long offs, uint8_t mask)
693{
694 TEEC_Session session = { 0 };
695 TEEC_Result res;
696 uint32_t ret_orig;
697 FILE *f;
698 bool r;
699
David Brownb2865ab2016-08-02 11:44:41 -0600700 r = copy_file(&create_fail_test_ta_uuid, &create_fail_test_ta_uuid);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200701 if (!ADBG_EXPECT_TRUE(c, r)) {
David Brownb2865ab2016-08-02 11:44:41 -0600702 rm_file(&create_fail_test_ta_uuid);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200703 return false;
704 }
705
David Brownb2865ab2016-08-02 11:44:41 -0600706 f = open_ta_file(&create_fail_test_ta_uuid, "r+", true);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200707 if (!ADBG_EXPECT_NOT_NULL(c, f)) {
David Brownb2865ab2016-08-02 11:44:41 -0600708 rm_file(&create_fail_test_ta_uuid);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200709 return false;
710 }
711 r = corrupt_file(f, offs, mask);
712 fclose(f);
713
714 if (ADBG_EXPECT_TRUE(c, r)) {
715 res = xtest_teec_open_session(&session,
716 &create_fail_test_ta_uuid,
717 NULL, &ret_orig);
718 if (res == TEEC_SUCCESS)
719 TEEC_CloseSession(&session);
720 r &= ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res);
721 }
722
David Brownb2865ab2016-08-02 11:44:41 -0600723 r &= ADBG_EXPECT_TRUE(c, rm_file(&create_fail_test_ta_uuid));
Jens Wiklander4441fe22015-10-23 16:53:02 +0200724 return r;
725}
726
Pascal Brandc639ac82015-07-02 08:53:34 +0200727static void xtest_tee_test_1008(ADBG_Case_t *c)
728{
729 TEEC_Session session = { 0 };
730 TEEC_Session session_crypt = { 0 };
731 uint32_t ret_orig;
732
733 Do_ADBG_BeginSubCase(c, "Invoke command");
734 {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300735 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200736 xtest_teec_open_session(&session, &os_test_ta_uuid,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300737 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200738
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300739 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
740 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT,
741 NULL, &ret_orig));
742 TEEC_CloseSession(&session);
743 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200744
Pascal Brandc639ac82015-07-02 08:53:34 +0200745 }
746 Do_ADBG_EndSubCase(c, "Invoke command");
747
748 Do_ADBG_BeginSubCase(c, "Invoke command with timeout");
749 {
750 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
751
752 op.params[0].value.a = 2000;
753 op.paramTypes = TEEC_PARAM_TYPES(
754 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
755
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300756 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200757 xtest_teec_open_session(&session,
758 &os_test_ta_uuid,
759 NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300760 &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200761
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300762 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
763 TEEC_InvokeCommand(&session,
764 TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT,
765 &op, &ret_orig));
766 TEEC_CloseSession(&session);
767 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200768 }
769 Do_ADBG_EndSubCase(c, "Invoke command with timeout");
770
771 Do_ADBG_BeginSubCase(c, "Create session fail");
772 {
Jens Wiklanderb7940892015-10-23 16:02:40 +0200773 size_t n;
774
Pascal Brandc639ac82015-07-02 08:53:34 +0200775 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
776 xtest_teec_open_session(&session_crypt,
777 &create_fail_test_ta_uuid, NULL,
778 &ret_orig));
Pascal Brandc639ac82015-07-02 08:53:34 +0200779 /*
780 * Run this several times to see that there's no memory leakage.
781 */
782 for (n = 0; n < 100; n++) {
783 Do_ADBG_Log("n = %zu", n);
784 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
785 xtest_teec_open_session(&session_crypt,
786 &create_fail_test_ta_uuid,
787 NULL, &ret_orig));
788 }
789 }
790 Do_ADBG_EndSubCase(c, "Create session fail");
Jens Wiklanderb7940892015-10-23 16:02:40 +0200791
David Brownb2865ab2016-08-02 11:44:41 -0600792 make_test_ta_dir();
793
Jens Wiklander4441fe22015-10-23 16:53:02 +0200794 Do_ADBG_BeginSubCase(c, "Load corrupt TA");
795 ADBG_EXPECT_TRUE(c,
796 load_corrupt_ta(c, offsetof(struct shdr, magic), 1));
797 ADBG_EXPECT_TRUE(c,
798 load_corrupt_ta(c, offsetof(struct shdr, img_type), 1));
799 ADBG_EXPECT_TRUE(c,
800 load_corrupt_ta(c, offsetof(struct shdr, img_size), 1));
801 ADBG_EXPECT_TRUE(c,
802 load_corrupt_ta(c, offsetof(struct shdr, algo), 1));
803 ADBG_EXPECT_TRUE(c,
804 load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1));
805 ADBG_EXPECT_TRUE(c,
806 load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1));
807 ADBG_EXPECT_TRUE(c,
808 load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */
809 ADBG_EXPECT_TRUE(c,
810 load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */
811 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */
812 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 30000, 1)); /* payload */
813 Do_ADBG_EndSubCase(c, "Load corrupt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200814}
815
Pascal Brandc639ac82015-07-02 08:53:34 +0200816static void *cancellation_thread(void *arg)
817{
818 /*
819 * Sleep 0.5 seconds before cancellation to make sure that the other
820 * thread is in RPC_WAIT.
821 */
822 (void)usleep(500000);
823 TEEC_RequestCancellation(arg);
824 return NULL;
825}
Pascal Brandc639ac82015-07-02 08:53:34 +0200826
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300827static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase,
828 uint32_t timeout, bool cancel)
Pascal Brandc639ac82015-07-02 08:53:34 +0200829{
830 TEEC_Session session = { 0 };
831 uint32_t ret_orig;
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300832 pthread_t thr;
Pascal Brandc639ac82015-07-02 08:53:34 +0200833
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300834 Do_ADBG_BeginSubCase(c, "%s", subcase);
Pascal Brandc639ac82015-07-02 08:53:34 +0200835 {
836 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
837
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300838 if (ADBG_EXPECT_TEEC_SUCCESS(c,
839 xtest_teec_open_session(&session, &os_test_ta_uuid,
840 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200841
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300842 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c,
843 TEEC_ORIGIN_TRUSTED_APP,
844 ret_orig);
Pascal Brandc639ac82015-07-02 08:53:34 +0200845
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300846 op.params[0].value.a = timeout;
847 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
848 TEEC_NONE,
849 TEEC_NONE, TEEC_NONE);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300850 if (cancel) {
851 (void)ADBG_EXPECT(c, 0,
852 pthread_create(&thr, NULL,
853 cancellation_thread, &op));
Pascal Brandc639ac82015-07-02 08:53:34 +0200854
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300855 (void)ADBG_EXPECT_TEEC_RESULT(c,
856 TEEC_ERROR_CANCEL,
857 TEEC_InvokeCommand(&session,
858 TA_OS_TEST_CMD_WAIT,
859 &op,
860 &ret_orig));
861 } else
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300862
863 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
864 TEEC_InvokeCommand(&session,
865 TA_OS_TEST_CMD_WAIT,
866 &op,
867 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300868 if (cancel)
869 (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300870
871 TEEC_CloseSession(&session);
872 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200873 }
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300874 Do_ADBG_EndSubCase(c, "%s", subcase);
875}
876
877static void xtest_tee_test_1009(ADBG_Case_t *c)
878{
879 xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false);
880 xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300881 xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300882 xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false);
Pascal Brandc639ac82015-07-02 08:53:34 +0200883}
884
885static void xtest_tee_test_1010(ADBG_Case_t *c)
886{
887 unsigned n;
888
889 for (n = 1; n <= 5; n++) {
890 Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n);
891 xtest_tee_test_invalid_mem_access(c, n);
892 Do_ADBG_EndSubCase(c, "Invalid memory access %u", n);
893 }
894}
895
896static void xtest_tee_test_1011(ADBG_Case_t *c)
897{
898 TEEC_Session session = { 0 };
899 uint32_t ret_orig;
900 struct xtest_crypto_session cs = {
901 c, &session, TA_RPC_CMD_CRYPT_SHA256,
902 TA_RPC_CMD_CRYPT_AES256ECB_ENC,
903 TA_RPC_CMD_CRYPT_AES256ECB_DEC
904 };
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100905 struct xtest_crypto_session cs_privmem = {
906 c, &session,
907 TA_RPC_CMD_CRYPT_PRIVMEM_SHA256,
908 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC,
909 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC
910 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200911 TEEC_UUID uuid = rpc_test_ta_uuid;
912
913 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
914 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
915 return;
916
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100917 Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory");
Pascal Brandc639ac82015-07-02 08:53:34 +0200918 /*
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100919 * Run the "complete crypto test suite" using TA-to-TA
920 * communication
Pascal Brandc639ac82015-07-02 08:53:34 +0200921 */
922 xtest_crypto_test(&cs);
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100923 Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory");
924
925 Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory");
926 /*
927 * Run the "complete crypto test suite" using TA-to-TA
928 * communication via TA private memory.
929 */
930 xtest_crypto_test(&cs_privmem);
931 Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory");
932
Pascal Brandc639ac82015-07-02 08:53:34 +0200933 TEEC_CloseSession(&session);
934}
935
936/*
937 * Note that this test is failing when
938 * - running twice in a raw
939 * - and the user TA is statically linked
940 * This is because the counter is not reseted when opening the first session
941 * in case the TA is statically linked
942 */
943static void xtest_tee_test_1012(ADBG_Case_t *c)
944{
945 TEEC_Session session1 = { 0 };
946 TEEC_Session session2 = { 0 };
947 uint32_t ret_orig;
948 TEEC_UUID uuid = sims_test_ta_uuid;
949
950 Do_ADBG_BeginSubCase(c, "Single Instance Multi Session");
951 {
952 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
953 static const uint8_t in[] = {
954 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
955 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
956 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
957 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
958 };
959 uint8_t out[32] = { 0 };
960 int i;
961
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300962 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200963 xtest_teec_open_session(&session1, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300964 &ret_orig)))
965 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200966
967 op.params[0].value.a = 0;
968 op.params[1].tmpref.buffer = (void *)in;
969 op.params[1].tmpref.size = sizeof(in);
970 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
971 TEEC_MEMREF_TEMP_INPUT,
972 TEEC_NONE, TEEC_NONE);
973
974 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
975 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op,
976 &ret_orig));
977
978 for (i = 1; i < 1000; i++) {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300979 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200980 xtest_teec_open_session(&session2, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300981 &ret_orig)))
982 continue;
Pascal Brandc639ac82015-07-02 08:53:34 +0200983
984 op.params[0].value.a = 0;
985 op.params[1].tmpref.buffer = out;
986 op.params[1].tmpref.size = sizeof(out);
987 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
988 TEEC_MEMREF_TEMP_OUTPUT,
989 TEEC_NONE, TEEC_NONE);
990
991 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
992 TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ,
993 &op, &ret_orig));
994
995 if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out,
996 sizeof(out))) {
997 Do_ADBG_Log("in:");
998 Do_ADBG_HexLog(in, sizeof(in), 16);
999 Do_ADBG_Log("out:");
1000 Do_ADBG_HexLog(out, sizeof(out), 16);
1001 }
1002
1003 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
1004 TEEC_NONE, TEEC_NONE,
1005 TEEC_NONE);
1006
1007 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1008 TEEC_InvokeCommand(&session1,
1009 TA_SIMS_CMD_GET_COUNTER,
1010 &op, &ret_orig));
1011
1012 (void)ADBG_EXPECT(c, 0, op.params[0].value.a);
1013
1014 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1015 TEEC_InvokeCommand(&session2,
1016 TA_SIMS_CMD_GET_COUNTER, &op,
1017 &ret_orig));
1018
1019 (void)ADBG_EXPECT(c, i, op.params[0].value.a);
1020 TEEC_CloseSession(&session2);
1021 }
1022
1023 memset(out, 0, sizeof(out));
1024 op.params[0].value.a = 0;
1025 op.params[1].tmpref.buffer = out;
1026 op.params[1].tmpref.size = sizeof(out);
1027 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1028 TEEC_MEMREF_TEMP_OUTPUT,
1029 TEEC_NONE, TEEC_NONE);
1030
1031 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1032 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op,
1033 &ret_orig));
1034
1035 if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) {
1036 Do_ADBG_Log("in:");
1037 Do_ADBG_HexLog(in, sizeof(in), 16);
1038 Do_ADBG_Log("out:");
1039 Do_ADBG_HexLog(out, sizeof(out), 16);
1040 }
1041
1042 TEEC_CloseSession(&session1);
1043 }
1044}
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001045
1046struct test_1013_thread_arg {
Jens Wiklander70672972016-04-06 00:01:45 +02001047 const TEEC_UUID *uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001048 uint32_t cmd;
1049 uint32_t repeat;
1050 TEEC_SharedMemory *shm;
1051 uint32_t error_orig;
1052 TEEC_Result res;
1053 uint32_t max_concurrency;
1054 const uint8_t *in;
1055 size_t in_len;
1056 uint8_t *out;
1057 size_t out_len;
1058};
1059
1060static void *test_1013_thread(void *arg)
1061{
1062 struct test_1013_thread_arg *a = arg;
1063 TEEC_Session session = { 0 };
1064 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1065 uint8_t p2 = TEEC_NONE;
1066 uint8_t p3 = TEEC_NONE;
1067
Jens Wiklander70672972016-04-06 00:01:45 +02001068 a->res = xtest_teec_open_session(&session, a->uuid, NULL,
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001069 &a->error_orig);
1070 if (a->res != TEEC_SUCCESS)
1071 return NULL;
1072
1073 op.params[0].memref.parent = a->shm;
1074 op.params[0].memref.size = a->shm->size;
1075 op.params[0].memref.offset = 0;
1076 op.params[1].value.a = a->repeat;
1077 op.params[1].value.b = 0;
1078 op.params[2].tmpref.buffer = (void *)a->in;
1079 op.params[2].tmpref.size = a->in_len;
1080 op.params[3].tmpref.buffer = a->out;
1081 op.params[3].tmpref.size = a->out_len;
1082
1083 if (a->in_len)
1084 p2 = TEEC_MEMREF_TEMP_INPUT;
1085 if (a->out_len)
1086 p3 = TEEC_MEMREF_TEMP_OUTPUT;
1087
1088 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT,
1089 TEEC_VALUE_INOUT, p2, p3);
1090
1091 a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig);
1092 a->max_concurrency = op.params[1].value.b;
1093 a->out_len = op.params[3].tmpref.size;
1094 TEEC_CloseSession(&session);
1095 return NULL;
1096}
1097
Pascal Brand4fa35582015-12-17 10:59:12 +01001098#define NUM_THREADS 3
1099
Jens Wiklander70672972016-04-06 00:01:45 +02001100static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency,
1101 const TEEC_UUID *uuid)
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001102{
Pascal Brand4fa35582015-12-17 10:59:12 +01001103 size_t num_threads = NUM_THREADS;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001104 size_t nt;
1105 size_t n;
Jens Wiklander70672972016-04-06 00:01:45 +02001106 size_t repeat = 1000;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001107 pthread_t thr[num_threads];
1108 TEEC_SharedMemory shm;
1109 size_t max_concurrency;
1110 struct test_1013_thread_arg arg[num_threads];
1111 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
1112 static const uint8_t sha256_out[] = {
1113 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
1114 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
1115 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
1116 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
1117 };
1118 uint8_t out[32] = { 0 };
1119
Jens Wiklander70672972016-04-06 00:01:45 +02001120 Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10);
Pascal Brand4fa35582015-12-17 10:59:12 +01001121 *mean_concurrency = 0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001122
1123 memset(&shm, 0, sizeof(shm));
1124 shm.size = sizeof(struct ta_concurrent_shm);
1125 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1126 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1127 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
1128 return;
1129
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001130 memset(shm.buffer, 0, shm.size);
1131 memset(arg, 0, sizeof(arg));
1132 max_concurrency = 0;
1133 nt = num_threads;
1134
1135 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001136 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001137 arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP;
Jens Wiklander70672972016-04-06 00:01:45 +02001138 arg[n].repeat = repeat * 10;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001139 arg[n].shm = &shm;
1140 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1141 test_1013_thread, arg + n)))
1142 nt = n; /* break loop and start cleanup */
1143 }
1144
1145 for (n = 0; n < nt; n++) {
1146 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
1147 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res);
1148 if (arg[n].max_concurrency > max_concurrency)
1149 max_concurrency = arg[n].max_concurrency;
1150 }
1151
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001152 /*
1153 * Concurrency can be limited by several factors, for instance in a
1154 * single CPU system it's dependent on the Preemtion Model used by
1155 * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the
1156 * best result there).
1157 */
1158 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0);
1159 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, num_threads);
Pascal Brand4fa35582015-12-17 10:59:12 +01001160 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001161 Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001162
Jens Wiklander70672972016-04-06 00:01:45 +02001163 Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001164 memset(shm.buffer, 0, shm.size);
1165 memset(arg, 0, sizeof(arg));
1166 max_concurrency = 0;
1167 nt = num_threads;
1168
1169 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001170 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001171 arg[n].cmd = TA_CONCURRENT_CMD_SHA256;
Jens Wiklander70672972016-04-06 00:01:45 +02001172 arg[n].repeat = repeat;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001173 arg[n].shm = &shm;
1174 arg[n].in = sha256_in;
1175 arg[n].in_len = sizeof(sha256_in);
1176 arg[n].out = out;
1177 arg[n].out_len = sizeof(out);
1178 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1179 test_1013_thread, arg + n)))
1180 nt = n; /* break loop and start cleanup */
1181 }
1182
1183 for (n = 0; n < nt; n++) {
1184 if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) &&
1185 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
1186 ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out),
1187 arg[n].out, arg[n].out_len);
1188 if (arg[n].max_concurrency > max_concurrency)
1189 max_concurrency = arg[n].max_concurrency;
1190 }
Pascal Brand4fa35582015-12-17 10:59:12 +01001191 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001192 Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001193
Pascal Brand4fa35582015-12-17 10:59:12 +01001194 *mean_concurrency /= 2.0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001195 TEEC_ReleaseSharedMemory(&shm);
1196}
Pascal Brand4fa35582015-12-17 10:59:12 +01001197
1198static void xtest_tee_test_1013(ADBG_Case_t *c)
1199{
1200 int i;
1201 double mean_concurrency;
1202 double concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001203 int nb_loops = 24;
Jens Wiklander6a9d15a2016-02-01 10:29:42 +01001204
1205 if (level == 0)
1206 nb_loops /= 2;
Pascal Brand4fa35582015-12-17 10:59:12 +01001207
Jens Wiklander70672972016-04-06 00:01:45 +02001208 Do_ADBG_BeginSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001209 mean_concurrency = 0;
1210 for (i = 0; i < nb_loops; i++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001211 xtest_tee_test_1013_single(c, &concurrency,
1212 &concurrent_ta_uuid);
Pascal Brand4fa35582015-12-17 10:59:12 +01001213 mean_concurrency += concurrency;
1214 }
1215 mean_concurrency /= nb_loops;
1216
1217 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1218 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
Jens Wiklander70672972016-04-06 00:01:45 +02001219 Do_ADBG_EndSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001220
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001221#ifndef CFG_PAGED_USER_TA
Jens Wiklander70672972016-04-06 00:01:45 +02001222 Do_ADBG_BeginSubCase(c, "Using large concurrency TA");
1223 mean_concurrency = 0;
1224 for (i = 0; i < nb_loops; i++) {
1225 xtest_tee_test_1013_single(c, &concurrency,
1226 &concurrent_large_ta_uuid);
1227 mean_concurrency += concurrency;
1228 }
1229 mean_concurrency /= nb_loops;
1230
1231 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1232 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
1233 Do_ADBG_EndSubCase(c, "Using large concurrency TA");
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001234#endif
Jens Wiklander70672972016-04-06 00:01:45 +02001235}
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001236
1237#ifdef CFG_SECURE_DATA_PATH
1238static void xtest_tee_test_1014(ADBG_Case_t *c)
1239{
1240 UNUSED(c);
1241
1242 int size = 17000;
1243 int loop = 10;
1244 int ion_heap = DEFAULT_ION_HEAP_TYPE;
1245 int rnd_offset = 1;
1246 int test;
1247 int ret;
1248
1249 test = TEST_NS_TO_TA;
1250 Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001251 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001252 ADBG_EXPECT(c, 0, ret);
1253 Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA");
1254
1255 test = TEST_TA_TO_TA;
1256 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001257 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001258 ADBG_EXPECT(c, 0, ret);
1259 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA");
1260
1261 test = TEST_TA_TO_PTA;
1262 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP pTA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001263 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001264 ADBG_EXPECT(c, 0, ret);
1265 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP pTA");
1266
1267 test = TEST_NS_TO_PTA;
Etienne Carrierea3198522017-10-26 09:48:55 +02001268 Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001269 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001270 ADBG_EXPECT(c, 1, ret);
Etienne Carrierea3198522017-10-26 09:48:55 +02001271 Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001272}
1273#endif
Jens Wiklander272d3642017-04-03 13:03:47 +02001274
1275static void xtest_tee_test_1015(ADBG_Case_t *c)
1276{
1277 TEEC_Result res;
1278 TEEC_Session session = { 0 };
1279 uint32_t ret_orig;
1280
Etienne Carriere11093162017-10-26 09:49:04 +02001281 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander272d3642017-04-03 13:03:47 +02001282 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
1283 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +02001284 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
1285 Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found");
Jens Wiklander272d3642017-04-03 13:03:47 +02001286 return;
Etienne Carriere11093162017-10-26 09:49:04 +02001287 }
1288 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander272d3642017-04-03 13:03:47 +02001289
1290 ADBG_EXPECT_TEEC_SUCCESS(c,
1291 TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE,
1292 NULL, &ret_orig));
1293 TEEC_CloseSession(&session);
1294}
Jerome Forissiere916b102017-06-07 17:55:52 +02001295
1296static void xtest_tee_test_1016(ADBG_Case_t *c)
1297{
1298 TEEC_Session session = { 0 };
1299 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1300 uint32_t ret_orig;
1301
1302 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1303 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1304 &ret_orig)))
1305 return;
1306
1307 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE,
1308 TEEC_NONE);
1309
1310 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1311 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op,
1312 &ret_orig));
1313
1314 TEEC_CloseSession(&session);
1315}