blob: 0fa9d661d3a9497bc09a94fb32a0abef798865cc [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>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010017#include <stdlib.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020018#include <string.h>
David Brownb2865ab2016-08-02 11:44:41 -060019#include <sys/stat.h>
20#include <sys/types.h>
Etienne Carrierea4653552017-01-11 10:04:24 +010021#include <unistd.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020022
23#include "xtest_test.h"
24#include "xtest_helpers.h"
Jens Wiklander4441fe22015-10-23 16:53:02 +020025#include <signed_hdr.h>
Etienne Carriere92c34422018-02-09 13:11:40 +010026#include <util.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020027
Etienne Carriere726d8bc2017-03-21 15:45:59 +010028#include <pta_invoke_tests.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020029#include <ta_crypt.h>
30#include <ta_os_test.h>
31#include <ta_create_fail_test.h>
32#include <ta_rpc_test.h>
33#include <ta_sims_test.h>
Jens Wiklanderac27ec12015-07-15 15:23:14 +020034#include <ta_concurrent.h>
Etienne Carriere50abf9a2017-03-24 11:33:50 +010035#include <sdp_basic.h>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010036#ifdef CFG_SECSTOR_TA_MGMT_PTA
37#include <pta_secstor_ta_mgmt.h>
38#endif
39
40#ifndef MIN
41#define MIN(a, b) ((a) < (b) ? (a) : (b))
42#endif
Pascal Brandc639ac82015-07-02 08:53:34 +020043
44static void xtest_tee_test_1001(ADBG_Case_t *Case_p);
Jens Wiklander1d70a112017-10-16 15:16:39 +020045static void xtest_tee_test_1002(ADBG_Case_t *Case_p);
Jens Wiklander0c86bc32017-11-13 19:52:03 +010046static void xtest_tee_test_1003(ADBG_Case_t *Case_p);
Pascal Brandc639ac82015-07-02 08:53:34 +020047static void xtest_tee_test_1004(ADBG_Case_t *Case_p);
48static void xtest_tee_test_1005(ADBG_Case_t *Case_p);
49static void xtest_tee_test_1006(ADBG_Case_t *Case_p);
50static void xtest_tee_test_1007(ADBG_Case_t *Case_p);
51static void xtest_tee_test_1008(ADBG_Case_t *Case_p);
52static void xtest_tee_test_1009(ADBG_Case_t *Case_p);
53static void xtest_tee_test_1010(ADBG_Case_t *Case_p);
54static void xtest_tee_test_1011(ADBG_Case_t *Case_p);
55static void xtest_tee_test_1012(ADBG_Case_t *Case_p);
Jens Wiklanderac27ec12015-07-15 15:23:14 +020056static void xtest_tee_test_1013(ADBG_Case_t *Case_p);
Etienne Carriere50abf9a2017-03-24 11:33:50 +010057#ifdef CFG_SECURE_DATA_PATH
58static void xtest_tee_test_1014(ADBG_Case_t *Case_p);
59#endif
Jens Wiklander272d3642017-04-03 13:03:47 +020060static void xtest_tee_test_1015(ADBG_Case_t *Case_p);
Jerome Forissiere916b102017-06-07 17:55:52 +020061static void xtest_tee_test_1016(ADBG_Case_t *Case_p);
Pascal Brandc639ac82015-07-02 08:53:34 +020062
Jens Wiklander74abfe32017-01-03 14:17:47 +010063ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests");
Jens Wiklander1d70a112017-10-16 15:16:39 +020064ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters");
Jens Wiklander0c86bc32017-11-13 19:52:03 +010065ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003,
66 "Core internal read/write mutex");
Jens Wiklander74abfe32017-01-03 14:17:47 +010067ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA");
68ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions");
69ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006,
70 "Test Basic OS features");
71ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic");
72ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008,
Jens Wiklander25a57fe2016-12-26 21:46:24 +010073 "TEE internal client API");
Jens Wiklander74abfe32017-01-03 14:17:47 +010074ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait");
75ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010,
76 "Invalid memory access");
77ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011,
Jens Wiklanderf7b9c632017-01-03 17:32:26 +010078 "Test TA-to-TA features with User Crypt TA");
Jens Wiklander74abfe32017-01-03 14:17:47 +010079ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012,
Jens Wiklander25a57fe2016-12-26 21:46:24 +010080 "Test Single Instance Multi Session features with SIMS TA");
Jens Wiklander74abfe32017-01-03 14:17:47 +010081ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013,
Jens Wiklander25a57fe2016-12-26 21:46:24 +010082 "Test concurency with concurrent TA");
Etienne Carriere50abf9a2017-03-24 11:33:50 +010083#ifdef CFG_SECURE_DATA_PATH
84ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014,
85 "Test secure data path against SDP TAs and pTAs");
86#endif
Jens Wiklander272d3642017-04-03 13:03:47 +020087ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015,
88 "FS hash-tree corner cases");
Jerome Forissiere916b102017-06-07 17:55:52 +020089ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016,
90 "Test TA to TA transfers (in/out/inout memrefs on the stack)");
Jens Wiklanderac27ec12015-07-15 15:23:14 +020091
Pascal Brandc639ac82015-07-02 08:53:34 +020092struct xtest_crypto_session {
93 ADBG_Case_t *c;
94 TEEC_Session *session;
95 uint32_t cmd_id_sha256;
96 uint32_t cmd_id_aes256ecb_encrypt;
97 uint32_t cmd_id_aes256ecb_decrypt;
98};
99
100static void xtest_crypto_test(struct xtest_crypto_session *cs)
101{
102 uint32_t ret_orig;
103 uint8_t crypt_out[16];
104 uint8_t crypt_in[16] = { 22, 17 };
105
106 crypt_in[15] = 60;
107
108 Do_ADBG_BeginSubCase(cs->c, "AES encrypt");
109 {
110 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
111
112 op.params[0].tmpref.buffer = crypt_in;
113 op.params[0].tmpref.size = sizeof(crypt_in);
114 op.params[1].tmpref.buffer = crypt_out;
115 op.params[1].tmpref.size = sizeof(crypt_out);
116 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
117 TEEC_MEMREF_TEMP_OUTPUT,
118 TEEC_NONE, TEEC_NONE);
119
120 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
121 TEEC_InvokeCommand(cs->session,
122 cs->
123 cmd_id_aes256ecb_encrypt,
124 &op,
125 &ret_orig));
126 }
127 Do_ADBG_EndSubCase(cs->c, "AES encrypt");
128
129 Do_ADBG_BeginSubCase(cs->c, "AES decrypt");
130 {
131 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
132 uint8_t out[16];
133
134 op.params[0].tmpref.buffer = crypt_out;
135 op.params[0].tmpref.size = sizeof(crypt_out);
136 op.params[1].tmpref.buffer = out;
137 op.params[1].tmpref.size = sizeof(out);
138 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
139 TEEC_MEMREF_TEMP_OUTPUT,
140 TEEC_NONE, TEEC_NONE);
141
142 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
143 TEEC_InvokeCommand(cs->session,
144 cs->
145 cmd_id_aes256ecb_decrypt,
146 &op,
147 &ret_orig));
148
149 if (!ADBG_EXPECT(cs->c, 0,
150 memcmp(crypt_in, out, sizeof(crypt_in)))) {
151 Do_ADBG_Log("crypt_in:");
152 Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16);
153 Do_ADBG_Log("out:");
154 Do_ADBG_HexLog(out, sizeof(out), 16);
155 }
156 }
157 Do_ADBG_EndSubCase(cs->c, "AES decrypt");
158
159 Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input");
160 {
161 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
162 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
163 static const uint8_t sha256_out[] = {
164 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
165 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
166 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
167 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
168 };
169 uint8_t out[32] = { 0 };
170
171 op.params[0].tmpref.buffer = (void *)sha256_in;
172 op.params[0].tmpref.size = sizeof(sha256_in);
173 op.params[1].tmpref.buffer = out;
174 op.params[1].tmpref.size = sizeof(out);
175 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
176 TEEC_MEMREF_TEMP_OUTPUT,
177 TEEC_NONE, TEEC_NONE);
178
179 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
180 TEEC_InvokeCommand(cs->session,
181 cs->
182 cmd_id_sha256,
183 &op,
184 &ret_orig));
185
186 if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out,
187 sizeof(sha256_out)))) {
188 Do_ADBG_Log("sha256_out:");
189 Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16);
190 Do_ADBG_Log("out:");
191 Do_ADBG_HexLog(out, sizeof(out), 16);
192 }
193 }
194 Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input");
195
Etienne Carrierea3198522017-10-26 09:48:55 +0200196 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200197 {
198 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
199 static const uint8_t in[] = {
200 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
201 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
202 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
203 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
204 };
205 static const uint8_t exp_out[] = {
206 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
207 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
208 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
209 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
210 };
211 uint8_t out[sizeof(exp_out)];
212
213 op.params[0].tmpref.buffer = (void *)in;
214 op.params[0].tmpref.size = sizeof(in);
215 op.params[1].tmpref.buffer = out;
216 op.params[1].tmpref.size = sizeof(out);
217 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
218 TEEC_MEMREF_TEMP_OUTPUT,
219 TEEC_NONE, TEEC_NONE);
220
221 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
222 TEEC_InvokeCommand(cs->session,
223 cs->
224 cmd_id_aes256ecb_encrypt,
225 &op,
226 &ret_orig));
227
228 if (!ADBG_EXPECT(cs->c, 0,
229 memcmp(exp_out, out, sizeof(exp_out)))) {
230 Do_ADBG_Log("exp_out:");
231 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
232 Do_ADBG_Log("out:");
233 Do_ADBG_HexLog(out, sizeof(out), 16);
234 }
235 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200236 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200237
Etienne Carrierea3198522017-10-26 09:48:55 +0200238 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200239 {
240 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
241 static const uint8_t in[] = {
242 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
243 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
244 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
245 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
246 };
247 static const uint8_t exp_out[] = {
248 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
249 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
250 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
251 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
252 };
253 uint8_t out[sizeof(exp_out)];
254
255 op.params[0].tmpref.buffer = (void *)in;
256 op.params[0].tmpref.size = sizeof(in);
257 op.params[1].tmpref.buffer = out;
258 op.params[1].tmpref.size = sizeof(out);
259 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
260 TEEC_MEMREF_TEMP_OUTPUT,
261 TEEC_NONE, TEEC_NONE);
262
263 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
264 TEEC_InvokeCommand(cs->session,
265 cs->
266 cmd_id_aes256ecb_decrypt,
267 &op,
268 &ret_orig));
269
270 if (!ADBG_EXPECT(cs->c, 0,
271 memcmp(exp_out, out, sizeof(exp_out)))) {
272 Do_ADBG_Log("exp_out:");
273 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
274 Do_ADBG_Log("out:");
275 Do_ADBG_HexLog(out, sizeof(out), 16);
276 }
277 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200278 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200279}
280
281static void xtest_tee_test_1001(ADBG_Case_t *c)
282{
Jens Wiklandercf16e842016-02-10 09:07:09 +0100283 TEEC_Result res;
284 TEEC_Session session = { 0 };
285 uint32_t ret_orig;
Pascal Brandc639ac82015-07-02 08:53:34 +0200286
Etienne Carriere11093162017-10-26 09:49:04 +0200287 /* Pseudo TA is optional: warn and nicely exit if not found */
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100288 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
Jens Wiklandercf16e842016-02-10 09:07:09 +0100289 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200290 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
291 Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found");
Jens Wiklandercf16e842016-02-10 09:07:09 +0100292 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200293 }
294 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Pascal Brandc639ac82015-07-02 08:53:34 +0200295
Jens Wiklandercf16e842016-02-10 09:07:09 +0100296 (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100297 &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig));
Jens Wiklandercf16e842016-02-10 09:07:09 +0100298 TEEC_CloseSession(&session);
Pascal Brandc639ac82015-07-02 08:53:34 +0200299}
300
Jens Wiklander1d70a112017-10-16 15:16:39 +0200301static void xtest_tee_test_1002(ADBG_Case_t *c)
302{
303 TEEC_Result res;
304 TEEC_Session session = { 0 };
305 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
306 uint32_t ret_orig;
307 uint8_t buf[16 * 1024];
308 uint8_t exp_sum = 0;
309 size_t n;
310
Etienne Carriere11093162017-10-26 09:49:04 +0200311 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander1d70a112017-10-16 15:16:39 +0200312 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
313 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200314 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
315 Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200316 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200317 }
318 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander1d70a112017-10-16 15:16:39 +0200319
320 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE,
321 TEEC_NONE, TEEC_NONE);
322 op.params[0].tmpref.size = sizeof(buf);
323 op.params[0].tmpref.buffer = buf;
324
325 for (n = 0; n < sizeof(buf); n++)
326 buf[n] = n + 1;
327 for (n = 0; n < sizeof(buf); n++)
328 exp_sum += buf[n];
329
330 if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
331 &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig)))
332 goto out;
333
334 ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]);
335out:
336 TEEC_CloseSession(&session);
337}
338
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100339struct test_1003_arg {
340 uint32_t test_type;
341 size_t repeat;
342 size_t max_before_lockers;
343 size_t max_during_lockers;
344 size_t before_lockers;
345 size_t during_lockers;
346 TEEC_Result res;
347 uint32_t error_orig;
348};
Jens Wiklander1d70a112017-10-16 15:16:39 +0200349
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100350static void *test_1003_thread(void *arg)
351{
352 struct test_1003_arg *a = arg;
353 TEEC_Session session = { 0 };
354 size_t rounds = 64 * 1024;
355 size_t n;
356
357 a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid,
358 NULL, &a->error_orig);
359 if (a->res != TEEC_SUCCESS)
360 return NULL;
361
362 for (n = 0; n < a->repeat; n++) {
363 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
364
365 op.params[0].value.a = a->test_type;
366 op.params[0].value.b = rounds;
367
368 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
369 TEEC_VALUE_OUTPUT,
370 TEEC_NONE, TEEC_NONE);
371 a->res = TEEC_InvokeCommand(&session,
372 PTA_INVOKE_TESTS_CMD_MUTEX,
373 &op, &a->error_orig);
374 if (a->test_type == PTA_MUTEX_TEST_WRITER &&
375 op.params[1].value.b != 1) {
376 Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b);
377 a->res = TEEC_ERROR_BAD_STATE;
378 a->error_orig = 42;
379 break;
380 }
381
382 if (a->test_type == PTA_MUTEX_TEST_READER) {
383 if (op.params[1].value.a > a->max_before_lockers)
384 a->max_before_lockers = op.params[1].value.a;
385
386 if (op.params[1].value.b > a->max_during_lockers)
387 a->max_during_lockers = op.params[1].value.b;
388
389 a->before_lockers += op.params[1].value.a;
390 a->during_lockers += op.params[1].value.b;
391 }
392 }
393 TEEC_CloseSession(&session);
394
395 return NULL;
396}
397
398static void xtest_tee_test_1003(ADBG_Case_t *c)
399{
400 size_t num_threads = 3 * 2;
401 TEEC_Result res;
402 TEEC_Session session = { 0 };
403 uint32_t ret_orig;
404 size_t repeat = 20;
405 pthread_t thr[num_threads];
406 struct test_1003_arg arg[num_threads];
407 size_t max_read_concurrency = 0;
408 size_t max_read_waiters = 0;
409 size_t num_concurrent_read_lockers = 0;
410 size_t num_concurrent_read_waiters = 0;
411 size_t n;
412 size_t nt = num_threads;
413 double mean_read_concurrency;
414 double mean_read_waiters;
415 size_t num_writers = 0;
416 size_t num_readers = 0;
417
418 /* Pseudo TA is optional: warn and nicely exit if not found */
419 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
420 &ret_orig);
421 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
422 Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found");
423 return;
424 }
425 ADBG_EXPECT_TEEC_SUCCESS(c, res);
426 TEEC_CloseSession(&session);
427
428 memset(arg, 0, sizeof(arg));
429
430 for (n = 0; n < nt; n++) {
431 if (n % 3) {
432 arg[n].test_type = PTA_MUTEX_TEST_READER;
433 num_readers++;
434 } else {
435 arg[n].test_type = PTA_MUTEX_TEST_WRITER;
436 num_writers++;
437 }
438 arg[n].repeat = repeat;
439 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
440 test_1003_thread, arg + n)))
441 nt = n; /* break loop and start cleanup */
442 }
443
444 for (n = 0; n < nt; n++) {
445 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
446 if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
447 Do_ADBG_Log("error origin %" PRIu32,
448 arg[n].error_orig);
449 if (arg[n].test_type == PTA_MUTEX_TEST_READER) {
450 if (arg[n].max_during_lockers > max_read_concurrency)
451 max_read_concurrency =
452 arg[n].max_during_lockers;
453
454 if (arg[n].max_before_lockers > max_read_waiters)
455 max_read_waiters = arg[n].max_before_lockers;
456
457 num_concurrent_read_lockers += arg[n].during_lockers;
458 num_concurrent_read_waiters += arg[n].before_lockers;
459 }
460 }
461
462 mean_read_concurrency = (double)num_concurrent_read_lockers /
463 (double)(repeat * num_readers);
464 mean_read_waiters = (double)num_concurrent_read_waiters /
465 (double)(repeat * num_readers);
466
467 Do_ADBG_Log(" Number of parallel threads: %zu (%zu writers and %zu readers)",
468 num_threads, num_writers, num_readers);
469 Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency);
470 Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters);
471 Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency);
472 Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters);
473}
Jens Wiklander1d70a112017-10-16 15:16:39 +0200474
Pascal Brandc639ac82015-07-02 08:53:34 +0200475static void xtest_tee_test_1004(ADBG_Case_t *c)
476{
477 TEEC_Session session = { 0 };
478 uint32_t ret_orig;
479 struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256,
480 TA_CRYPT_CMD_AES256ECB_ENC,
481 TA_CRYPT_CMD_AES256ECB_DEC };
482
483 if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session(
484 &session, &crypt_user_ta_uuid,
485 NULL, &ret_orig)))
486 return;
487
488 /* Run the "complete crypto test suite" */
489 xtest_crypto_test(&cs);
490
491 TEEC_CloseSession(&session);
492}
493
494#ifndef TEEC_ERROR_TARGET_DEAD
495/* To be removed when we have TEEC_ERROR_TARGET_DEAD from tee_client_api.h */
496#define TEEC_ERROR_TARGET_DEAD 0xFFFF3024
497#endif
498
Etienne Carriere92c34422018-02-09 13:11:40 +0100499static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, unsigned int n)
Pascal Brandc639ac82015-07-02 08:53:34 +0200500{
501 TEEC_Session session = { 0 };
502 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
503 uint32_t ret_orig;
504
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300505 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200506 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300507 &ret_orig)))
508 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200509
510 op.params[0].value.a = n;
511 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
512 TEEC_NONE);
513
514 (void)ADBG_EXPECT_TEEC_RESULT(c,
515 TEEC_ERROR_TARGET_DEAD,
516 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
517 &ret_orig));
518
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300519 (void)ADBG_EXPECT_TEEC_RESULT(c,
520 TEEC_ERROR_TARGET_DEAD,
521 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
Pascal Brandc639ac82015-07-02 08:53:34 +0200522 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300523
Pascal Brandc639ac82015-07-02 08:53:34 +0200524 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
525
526 TEEC_CloseSession(&session);
527}
528
Etienne Carriere92c34422018-02-09 13:11:40 +0100529static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n,
530 size_t size)
531{
532 TEEC_Session session = { 0 };
533 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
534 uint32_t ret_orig;
535 TEEC_SharedMemory shm;
536
537 memset(&shm, 0, sizeof(shm));
538 shm.size = size;
539 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
540 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
541 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
542 return;
543
544 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
545 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
546 &ret_orig)))
547 return;
548
549 op.params[0].value.a = (uint32_t)n;
550 op.params[1].memref.parent = &shm;
551 op.params[1].memref.size = size;
552 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_MEMREF_WHOLE,
553 TEEC_NONE, TEEC_NONE);
554
555 (void)ADBG_EXPECT_TEEC_RESULT(c,
556 TEEC_ERROR_TARGET_DEAD,
557 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
558 &ret_orig));
559
560 (void)ADBG_EXPECT_TEEC_RESULT(c,
561 TEEC_ERROR_TARGET_DEAD,
562 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
563 &ret_orig));
564
565 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
566
567 TEEC_CloseSession(&session);
568}
569
Pascal Brandc639ac82015-07-02 08:53:34 +0200570static void xtest_tee_test_1005(ADBG_Case_t *c)
571{
572 uint32_t ret_orig;
573#define MAX_SESSIONS 3
574 TEEC_Session sessions[MAX_SESSIONS];
575 int i;
576
577 for (i = 0; i < MAX_SESSIONS; i++) {
578 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jens Wiklandereb6bce72016-09-23 11:37:33 +0200579 xtest_teec_open_session(&sessions[i],
580 &concurrent_ta_uuid,
Pascal Brandc639ac82015-07-02 08:53:34 +0200581 NULL, &ret_orig)))
582 break;
583 }
584
585 for (; --i >= 0; )
586 TEEC_CloseSession(&sessions[i]);
587}
588
589static void xtest_tee_test_1006(ADBG_Case_t *c)
590{
591 TEEC_Session session = { 0 };
592 uint32_t ret_orig;
593 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
594 uint8_t buf[32];
595
596 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
597 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
598 &ret_orig)))
599 return;
600
601 op.params[0].tmpref.buffer = buf;
602 op.params[0].tmpref.size = sizeof(buf);
603 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
604 TEEC_NONE, TEEC_NONE);
605
606 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
607 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op,
608 &ret_orig));
609
610 TEEC_CloseSession(&session);
611}
612
613static void xtest_tee_test_1007(ADBG_Case_t *c)
614{
615 TEEC_Session session = { 0 };
616 uint32_t ret_orig;
617
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300618 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200619 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300620 &ret_orig)))
621 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200622
623 (void)ADBG_EXPECT_TEEC_RESULT(c,
624 TEEC_ERROR_TARGET_DEAD,
625 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL,
626 &ret_orig));
627
628 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
629
630 (void)ADBG_EXPECT_TEEC_RESULT(c,
631 TEEC_ERROR_TARGET_DEAD,
632 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL,
633 &ret_orig));
634
635 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
636
637 TEEC_CloseSession(&session);
638}
639
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100640#ifdef CFG_SECSTOR_TA_MGMT_PTA
Jerome Forissierf02a2212015-10-29 14:33:35 +0100641#ifndef TA_DIR
Victor Chong3d8798f2017-03-01 18:31:48 +0000642# ifdef __ANDROID__
643#define TA_DIR "/system/lib/optee_armtz"
644# else
Jerome Forissierf02a2212015-10-29 14:33:35 +0100645#define TA_DIR "/lib/optee_armtz"
Victor Chong3d8798f2017-03-01 18:31:48 +0000646# endif
Jerome Forissierf02a2212015-10-29 14:33:35 +0100647#endif
648
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100649static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode)
David Brownb2865ab2016-08-02 11:44:41 -0600650{
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100651 char buf[PATH_MAX];
David Brownb2865ab2016-08-02 11:44:41 -0600652
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100653 snprintf(buf, sizeof(buf),
Jens Wiklander6203b872016-12-08 19:18:29 +0100654 "%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta",
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100655 TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion,
Jens Wiklanderb7940892015-10-23 16:02:40 +0200656 uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1],
657 uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3],
658 uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5],
David Brownb2865ab2016-08-02 11:44:41 -0600659 uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200660
Jens Wiklanderb7940892015-10-23 16:02:40 +0200661 return fopen(buf, mode);
662}
663
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100664static bool load_corrupt_ta(ADBG_Case_t *c, size_t offs, uint8_t mask)
Jens Wiklander4441fe22015-10-23 16:53:02 +0200665{
666 TEEC_Session session = { 0 };
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100667 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
668 TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200669 TEEC_Result res;
670 uint32_t ret_orig;
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100671 FILE *f = NULL;
672 bool r = false;
673 uint8_t *buf = NULL;
674 size_t sz;
675 size_t fread_res;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200676
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100677 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
678 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
679 goto out;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200680
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100681 f = open_ta_file(&create_fail_test_ta_uuid, "rb");
682 if (!ADBG_EXPECT_NOT_NULL(c, f))
683 goto out;
684 if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END)))
685 goto out;
686 sz = ftell(f);
687 rewind(f);
688
689 buf = malloc(sz);
690 if (!ADBG_EXPECT_NOT_NULL(c, buf))
691 goto out;
692
693 fread_res = fread(buf, 1, sz, f);
694 if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz))
695 goto out;
696
Jens Wiklander4441fe22015-10-23 16:53:02 +0200697 fclose(f);
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100698 f = NULL;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200699
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100700 buf[MIN(offs, sz)] ^= mask;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200701
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100702 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
703 TEEC_NONE, TEEC_NONE);
704 op.params[0].tmpref.buffer = buf;
705 op.params[0].tmpref.size = sz;
706
707 res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op,
708 &ret_orig);
709 r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res);
710out:
711 free(buf);
712 if (f)
713 fclose(f);
714 TEEC_CloseSession(&session);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200715 return r;
716}
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100717#endif /*CFG_SECSTOR_TA_MGMT_PTA*/
Jens Wiklander4441fe22015-10-23 16:53:02 +0200718
Pascal Brandc639ac82015-07-02 08:53:34 +0200719static void xtest_tee_test_1008(ADBG_Case_t *c)
720{
721 TEEC_Session session = { 0 };
722 TEEC_Session session_crypt = { 0 };
723 uint32_t ret_orig;
724
725 Do_ADBG_BeginSubCase(c, "Invoke command");
726 {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300727 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200728 xtest_teec_open_session(&session, &os_test_ta_uuid,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300729 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200730
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300731 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
732 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT,
733 NULL, &ret_orig));
734 TEEC_CloseSession(&session);
735 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200736
Pascal Brandc639ac82015-07-02 08:53:34 +0200737 }
738 Do_ADBG_EndSubCase(c, "Invoke command");
739
740 Do_ADBG_BeginSubCase(c, "Invoke command with timeout");
741 {
742 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
743
744 op.params[0].value.a = 2000;
745 op.paramTypes = TEEC_PARAM_TYPES(
746 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
747
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300748 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200749 xtest_teec_open_session(&session,
750 &os_test_ta_uuid,
751 NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300752 &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200753
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300754 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
755 TEEC_InvokeCommand(&session,
756 TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT,
757 &op, &ret_orig));
758 TEEC_CloseSession(&session);
759 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200760 }
761 Do_ADBG_EndSubCase(c, "Invoke command with timeout");
762
763 Do_ADBG_BeginSubCase(c, "Create session fail");
764 {
Jens Wiklanderb7940892015-10-23 16:02:40 +0200765 size_t n;
766
Pascal Brandc639ac82015-07-02 08:53:34 +0200767 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
768 xtest_teec_open_session(&session_crypt,
769 &create_fail_test_ta_uuid, NULL,
770 &ret_orig));
Pascal Brandc639ac82015-07-02 08:53:34 +0200771 /*
772 * Run this several times to see that there's no memory leakage.
773 */
774 for (n = 0; n < 100; n++) {
775 Do_ADBG_Log("n = %zu", n);
776 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
777 xtest_teec_open_session(&session_crypt,
778 &create_fail_test_ta_uuid,
779 NULL, &ret_orig));
780 }
781 }
782 Do_ADBG_EndSubCase(c, "Create session fail");
Jens Wiklanderb7940892015-10-23 16:02:40 +0200783
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100784#ifdef CFG_SECSTOR_TA_MGMT_PTA
Jens Wiklander4441fe22015-10-23 16:53:02 +0200785 Do_ADBG_BeginSubCase(c, "Load corrupt TA");
786 ADBG_EXPECT_TRUE(c,
787 load_corrupt_ta(c, offsetof(struct shdr, magic), 1));
788 ADBG_EXPECT_TRUE(c,
789 load_corrupt_ta(c, offsetof(struct shdr, img_type), 1));
790 ADBG_EXPECT_TRUE(c,
791 load_corrupt_ta(c, offsetof(struct shdr, img_size), 1));
792 ADBG_EXPECT_TRUE(c,
793 load_corrupt_ta(c, offsetof(struct shdr, algo), 1));
794 ADBG_EXPECT_TRUE(c,
795 load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1));
796 ADBG_EXPECT_TRUE(c,
797 load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1));
798 ADBG_EXPECT_TRUE(c,
799 load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */
800 ADBG_EXPECT_TRUE(c,
801 load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */
802 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */
803 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 30000, 1)); /* payload */
804 Do_ADBG_EndSubCase(c, "Load corrupt TA");
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100805#endif /*CFG_SECSTOR_TA_MGMT_PTA*/
Pascal Brandc639ac82015-07-02 08:53:34 +0200806}
807
Pascal Brandc639ac82015-07-02 08:53:34 +0200808static void *cancellation_thread(void *arg)
809{
810 /*
811 * Sleep 0.5 seconds before cancellation to make sure that the other
812 * thread is in RPC_WAIT.
813 */
814 (void)usleep(500000);
815 TEEC_RequestCancellation(arg);
816 return NULL;
817}
Pascal Brandc639ac82015-07-02 08:53:34 +0200818
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300819static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase,
820 uint32_t timeout, bool cancel)
Pascal Brandc639ac82015-07-02 08:53:34 +0200821{
822 TEEC_Session session = { 0 };
823 uint32_t ret_orig;
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300824 pthread_t thr;
Pascal Brandc639ac82015-07-02 08:53:34 +0200825
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300826 Do_ADBG_BeginSubCase(c, "%s", subcase);
Pascal Brandc639ac82015-07-02 08:53:34 +0200827 {
828 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
829
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300830 if (ADBG_EXPECT_TEEC_SUCCESS(c,
831 xtest_teec_open_session(&session, &os_test_ta_uuid,
832 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200833
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300834 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c,
835 TEEC_ORIGIN_TRUSTED_APP,
836 ret_orig);
Pascal Brandc639ac82015-07-02 08:53:34 +0200837
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300838 op.params[0].value.a = timeout;
839 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
840 TEEC_NONE,
841 TEEC_NONE, TEEC_NONE);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300842 if (cancel) {
843 (void)ADBG_EXPECT(c, 0,
844 pthread_create(&thr, NULL,
845 cancellation_thread, &op));
Pascal Brandc639ac82015-07-02 08:53:34 +0200846
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300847 (void)ADBG_EXPECT_TEEC_RESULT(c,
848 TEEC_ERROR_CANCEL,
849 TEEC_InvokeCommand(&session,
850 TA_OS_TEST_CMD_WAIT,
851 &op,
852 &ret_orig));
853 } else
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300854
855 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
856 TEEC_InvokeCommand(&session,
857 TA_OS_TEST_CMD_WAIT,
858 &op,
859 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300860 if (cancel)
861 (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300862
863 TEEC_CloseSession(&session);
864 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200865 }
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300866 Do_ADBG_EndSubCase(c, "%s", subcase);
867}
868
869static void xtest_tee_test_1009(ADBG_Case_t *c)
870{
871 xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false);
872 xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300873 xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300874 xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false);
Pascal Brandc639ac82015-07-02 08:53:34 +0200875}
876
877static void xtest_tee_test_1010(ADBG_Case_t *c)
878{
Etienne Carriere92c34422018-02-09 13:11:40 +0100879 unsigned int n;
880 unsigned int idx;
881 size_t memref_sz[] = { 1024, 65536 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200882
883 for (n = 1; n <= 5; n++) {
884 Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n);
885 xtest_tee_test_invalid_mem_access(c, n);
886 Do_ADBG_EndSubCase(c, "Invalid memory access %u", n);
887 }
Etienne Carriere92c34422018-02-09 13:11:40 +0100888
889 for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) {
890 for (n = 1; n <= 5; n++) {
891 Do_ADBG_BeginSubCase(c,
Igor Opaniuke8236ac2018-02-12 12:26:25 +0200892 "Invalid memory access %u with %zu bytes memref",
Etienne Carriere92c34422018-02-09 13:11:40 +0100893 n, memref_sz[idx]);
894 xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]);
895 Do_ADBG_EndSubCase(c,
Igor Opaniuke8236ac2018-02-12 12:26:25 +0200896 "Invalid memory access %u with %zu bytes memref",
Etienne Carriere92c34422018-02-09 13:11:40 +0100897 n, memref_sz[idx]);
898 }
899 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200900}
901
902static void xtest_tee_test_1011(ADBG_Case_t *c)
903{
904 TEEC_Session session = { 0 };
905 uint32_t ret_orig;
906 struct xtest_crypto_session cs = {
907 c, &session, TA_RPC_CMD_CRYPT_SHA256,
908 TA_RPC_CMD_CRYPT_AES256ECB_ENC,
909 TA_RPC_CMD_CRYPT_AES256ECB_DEC
910 };
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100911 struct xtest_crypto_session cs_privmem = {
912 c, &session,
913 TA_RPC_CMD_CRYPT_PRIVMEM_SHA256,
914 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC,
915 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC
916 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200917 TEEC_UUID uuid = rpc_test_ta_uuid;
918
919 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
920 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
921 return;
922
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100923 Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory");
Pascal Brandc639ac82015-07-02 08:53:34 +0200924 /*
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100925 * Run the "complete crypto test suite" using TA-to-TA
926 * communication
Pascal Brandc639ac82015-07-02 08:53:34 +0200927 */
928 xtest_crypto_test(&cs);
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100929 Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory");
930
931 Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory");
932 /*
933 * Run the "complete crypto test suite" using TA-to-TA
934 * communication via TA private memory.
935 */
936 xtest_crypto_test(&cs_privmem);
937 Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory");
938
Pascal Brandc639ac82015-07-02 08:53:34 +0200939 TEEC_CloseSession(&session);
940}
941
942/*
943 * Note that this test is failing when
944 * - running twice in a raw
945 * - and the user TA is statically linked
946 * This is because the counter is not reseted when opening the first session
947 * in case the TA is statically linked
948 */
949static void xtest_tee_test_1012(ADBG_Case_t *c)
950{
951 TEEC_Session session1 = { 0 };
952 TEEC_Session session2 = { 0 };
953 uint32_t ret_orig;
954 TEEC_UUID uuid = sims_test_ta_uuid;
955
956 Do_ADBG_BeginSubCase(c, "Single Instance Multi Session");
957 {
958 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
959 static const uint8_t in[] = {
960 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
961 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
962 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
963 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
964 };
965 uint8_t out[32] = { 0 };
966 int i;
967
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300968 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200969 xtest_teec_open_session(&session1, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300970 &ret_orig)))
971 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200972
973 op.params[0].value.a = 0;
974 op.params[1].tmpref.buffer = (void *)in;
975 op.params[1].tmpref.size = sizeof(in);
976 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
977 TEEC_MEMREF_TEMP_INPUT,
978 TEEC_NONE, TEEC_NONE);
979
980 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
981 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op,
982 &ret_orig));
983
Jerome Forissier3cc0a422017-12-14 09:53:24 +0100984 for (i = 1; i < 3; i++) {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300985 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200986 xtest_teec_open_session(&session2, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300987 &ret_orig)))
988 continue;
Pascal Brandc639ac82015-07-02 08:53:34 +0200989
990 op.params[0].value.a = 0;
991 op.params[1].tmpref.buffer = out;
992 op.params[1].tmpref.size = sizeof(out);
993 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
994 TEEC_MEMREF_TEMP_OUTPUT,
995 TEEC_NONE, TEEC_NONE);
996
997 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
998 TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ,
999 &op, &ret_orig));
1000
1001 if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out,
1002 sizeof(out))) {
1003 Do_ADBG_Log("in:");
1004 Do_ADBG_HexLog(in, sizeof(in), 16);
1005 Do_ADBG_Log("out:");
1006 Do_ADBG_HexLog(out, sizeof(out), 16);
1007 }
1008
1009 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
1010 TEEC_NONE, TEEC_NONE,
1011 TEEC_NONE);
1012
1013 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1014 TEEC_InvokeCommand(&session1,
1015 TA_SIMS_CMD_GET_COUNTER,
1016 &op, &ret_orig));
1017
1018 (void)ADBG_EXPECT(c, 0, op.params[0].value.a);
1019
1020 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1021 TEEC_InvokeCommand(&session2,
1022 TA_SIMS_CMD_GET_COUNTER, &op,
1023 &ret_orig));
1024
1025 (void)ADBG_EXPECT(c, i, op.params[0].value.a);
1026 TEEC_CloseSession(&session2);
1027 }
1028
1029 memset(out, 0, sizeof(out));
1030 op.params[0].value.a = 0;
1031 op.params[1].tmpref.buffer = out;
1032 op.params[1].tmpref.size = sizeof(out);
1033 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1034 TEEC_MEMREF_TEMP_OUTPUT,
1035 TEEC_NONE, TEEC_NONE);
1036
1037 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1038 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op,
1039 &ret_orig));
1040
1041 if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) {
1042 Do_ADBG_Log("in:");
1043 Do_ADBG_HexLog(in, sizeof(in), 16);
1044 Do_ADBG_Log("out:");
1045 Do_ADBG_HexLog(out, sizeof(out), 16);
1046 }
1047
1048 TEEC_CloseSession(&session1);
1049 }
1050}
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001051
1052struct test_1013_thread_arg {
Jens Wiklander70672972016-04-06 00:01:45 +02001053 const TEEC_UUID *uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001054 uint32_t cmd;
1055 uint32_t repeat;
1056 TEEC_SharedMemory *shm;
1057 uint32_t error_orig;
1058 TEEC_Result res;
1059 uint32_t max_concurrency;
1060 const uint8_t *in;
1061 size_t in_len;
1062 uint8_t *out;
1063 size_t out_len;
1064};
1065
1066static void *test_1013_thread(void *arg)
1067{
1068 struct test_1013_thread_arg *a = arg;
1069 TEEC_Session session = { 0 };
1070 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1071 uint8_t p2 = TEEC_NONE;
1072 uint8_t p3 = TEEC_NONE;
1073
Jens Wiklander70672972016-04-06 00:01:45 +02001074 a->res = xtest_teec_open_session(&session, a->uuid, NULL,
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001075 &a->error_orig);
1076 if (a->res != TEEC_SUCCESS)
1077 return NULL;
1078
1079 op.params[0].memref.parent = a->shm;
1080 op.params[0].memref.size = a->shm->size;
1081 op.params[0].memref.offset = 0;
1082 op.params[1].value.a = a->repeat;
1083 op.params[1].value.b = 0;
1084 op.params[2].tmpref.buffer = (void *)a->in;
1085 op.params[2].tmpref.size = a->in_len;
1086 op.params[3].tmpref.buffer = a->out;
1087 op.params[3].tmpref.size = a->out_len;
1088
1089 if (a->in_len)
1090 p2 = TEEC_MEMREF_TEMP_INPUT;
1091 if (a->out_len)
1092 p3 = TEEC_MEMREF_TEMP_OUTPUT;
1093
1094 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT,
1095 TEEC_VALUE_INOUT, p2, p3);
1096
1097 a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig);
1098 a->max_concurrency = op.params[1].value.b;
1099 a->out_len = op.params[3].tmpref.size;
1100 TEEC_CloseSession(&session);
1101 return NULL;
1102}
1103
Pascal Brand4fa35582015-12-17 10:59:12 +01001104#define NUM_THREADS 3
1105
Jens Wiklander70672972016-04-06 00:01:45 +02001106static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency,
1107 const TEEC_UUID *uuid)
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001108{
Pascal Brand4fa35582015-12-17 10:59:12 +01001109 size_t num_threads = NUM_THREADS;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001110 size_t nt;
1111 size_t n;
Jens Wiklander70672972016-04-06 00:01:45 +02001112 size_t repeat = 1000;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001113 pthread_t thr[num_threads];
1114 TEEC_SharedMemory shm;
1115 size_t max_concurrency;
1116 struct test_1013_thread_arg arg[num_threads];
1117 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
1118 static const uint8_t sha256_out[] = {
1119 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
1120 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
1121 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
1122 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
1123 };
1124 uint8_t out[32] = { 0 };
1125
Jens Wiklander70672972016-04-06 00:01:45 +02001126 Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10);
Pascal Brand4fa35582015-12-17 10:59:12 +01001127 *mean_concurrency = 0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001128
1129 memset(&shm, 0, sizeof(shm));
1130 shm.size = sizeof(struct ta_concurrent_shm);
1131 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1132 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1133 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
1134 return;
1135
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001136 memset(shm.buffer, 0, shm.size);
1137 memset(arg, 0, sizeof(arg));
1138 max_concurrency = 0;
1139 nt = num_threads;
1140
1141 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001142 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001143 arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP;
Jens Wiklander70672972016-04-06 00:01:45 +02001144 arg[n].repeat = repeat * 10;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001145 arg[n].shm = &shm;
1146 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1147 test_1013_thread, arg + n)))
1148 nt = n; /* break loop and start cleanup */
1149 }
1150
1151 for (n = 0; n < nt; n++) {
1152 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
1153 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res);
1154 if (arg[n].max_concurrency > max_concurrency)
1155 max_concurrency = arg[n].max_concurrency;
1156 }
1157
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001158 /*
1159 * Concurrency can be limited by several factors, for instance in a
1160 * single CPU system it's dependent on the Preemtion Model used by
1161 * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the
1162 * best result there).
1163 */
1164 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0);
1165 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, num_threads);
Pascal Brand4fa35582015-12-17 10:59:12 +01001166 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001167 Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001168
Jens Wiklander70672972016-04-06 00:01:45 +02001169 Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001170 memset(shm.buffer, 0, shm.size);
1171 memset(arg, 0, sizeof(arg));
1172 max_concurrency = 0;
1173 nt = num_threads;
1174
1175 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001176 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001177 arg[n].cmd = TA_CONCURRENT_CMD_SHA256;
Jens Wiklander70672972016-04-06 00:01:45 +02001178 arg[n].repeat = repeat;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001179 arg[n].shm = &shm;
1180 arg[n].in = sha256_in;
1181 arg[n].in_len = sizeof(sha256_in);
1182 arg[n].out = out;
1183 arg[n].out_len = sizeof(out);
1184 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1185 test_1013_thread, arg + n)))
1186 nt = n; /* break loop and start cleanup */
1187 }
1188
1189 for (n = 0; n < nt; n++) {
1190 if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) &&
1191 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
1192 ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out),
1193 arg[n].out, arg[n].out_len);
1194 if (arg[n].max_concurrency > max_concurrency)
1195 max_concurrency = arg[n].max_concurrency;
1196 }
Pascal Brand4fa35582015-12-17 10:59:12 +01001197 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001198 Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001199
Pascal Brand4fa35582015-12-17 10:59:12 +01001200 *mean_concurrency /= 2.0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001201 TEEC_ReleaseSharedMemory(&shm);
1202}
Pascal Brand4fa35582015-12-17 10:59:12 +01001203
1204static void xtest_tee_test_1013(ADBG_Case_t *c)
1205{
1206 int i;
1207 double mean_concurrency;
1208 double concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001209 int nb_loops = 24;
Jens Wiklander6a9d15a2016-02-01 10:29:42 +01001210
1211 if (level == 0)
1212 nb_loops /= 2;
Pascal Brand4fa35582015-12-17 10:59:12 +01001213
Jens Wiklander70672972016-04-06 00:01:45 +02001214 Do_ADBG_BeginSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001215 mean_concurrency = 0;
1216 for (i = 0; i < nb_loops; i++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001217 xtest_tee_test_1013_single(c, &concurrency,
1218 &concurrent_ta_uuid);
Pascal Brand4fa35582015-12-17 10:59:12 +01001219 mean_concurrency += concurrency;
1220 }
1221 mean_concurrency /= nb_loops;
1222
1223 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1224 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
Jens Wiklander70672972016-04-06 00:01:45 +02001225 Do_ADBG_EndSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001226
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001227#ifndef CFG_PAGED_USER_TA
Jens Wiklander70672972016-04-06 00:01:45 +02001228 Do_ADBG_BeginSubCase(c, "Using large concurrency TA");
1229 mean_concurrency = 0;
1230 for (i = 0; i < nb_loops; i++) {
1231 xtest_tee_test_1013_single(c, &concurrency,
1232 &concurrent_large_ta_uuid);
1233 mean_concurrency += concurrency;
1234 }
1235 mean_concurrency /= nb_loops;
1236
1237 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1238 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
1239 Do_ADBG_EndSubCase(c, "Using large concurrency TA");
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001240#endif
Jens Wiklander70672972016-04-06 00:01:45 +02001241}
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001242
1243#ifdef CFG_SECURE_DATA_PATH
1244static void xtest_tee_test_1014(ADBG_Case_t *c)
1245{
1246 UNUSED(c);
1247
1248 int size = 17000;
1249 int loop = 10;
1250 int ion_heap = DEFAULT_ION_HEAP_TYPE;
1251 int rnd_offset = 1;
1252 int test;
1253 int ret;
1254
1255 test = TEST_NS_TO_TA;
1256 Do_ADBG_BeginSubCase(c, "SDP: NonSecure client 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: NonSecure client invokes a SDP TA");
1260
1261 test = TEST_TA_TO_TA;
1262 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA");
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 TA");
1266
1267 test = TEST_TA_TO_PTA;
1268 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP pTA");
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, 0, ret);
1271 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP pTA");
1272
1273 test = TEST_NS_TO_PTA;
Etienne Carrierea3198522017-10-26 09:48:55 +02001274 Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001275 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001276 ADBG_EXPECT(c, 1, ret);
Etienne Carrierea3198522017-10-26 09:48:55 +02001277 Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001278}
1279#endif
Jens Wiklander272d3642017-04-03 13:03:47 +02001280
1281static void xtest_tee_test_1015(ADBG_Case_t *c)
1282{
1283 TEEC_Result res;
1284 TEEC_Session session = { 0 };
1285 uint32_t ret_orig;
1286
Etienne Carriere11093162017-10-26 09:49:04 +02001287 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander272d3642017-04-03 13:03:47 +02001288 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
1289 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +02001290 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
1291 Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found");
Jens Wiklander272d3642017-04-03 13:03:47 +02001292 return;
Etienne Carriere11093162017-10-26 09:49:04 +02001293 }
1294 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander272d3642017-04-03 13:03:47 +02001295
1296 ADBG_EXPECT_TEEC_SUCCESS(c,
1297 TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE,
1298 NULL, &ret_orig));
1299 TEEC_CloseSession(&session);
1300}
Jerome Forissiere916b102017-06-07 17:55:52 +02001301
1302static void xtest_tee_test_1016(ADBG_Case_t *c)
1303{
1304 TEEC_Session session = { 0 };
1305 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1306 uint32_t ret_orig;
1307
1308 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1309 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1310 &ret_orig)))
1311 return;
1312
1313 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE,
1314 TEEC_NONE);
1315
1316 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1317 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op,
1318 &ret_orig));
1319
1320 TEEC_CloseSession(&session);
1321}