blob: 45aca3ec64d93ec0e0e62f2905c7d198e56fb677 [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
692static void load_fake_ta(ADBG_Case_t *c)
693{
694 static const TEEC_UUID fake_uuid = {
695 0x7e0a0900, 0x586b, 0x11e5,
696 { 0x93, 0x1f, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }
697 };
698 TEEC_Session session = { 0 };
699 TEEC_Result res;
700 uint32_t ret_orig;
Jens Wiklanderb7940892015-10-23 16:02:40 +0200701 bool r;
Jens Wiklanderb7940892015-10-23 16:02:40 +0200702
David Brownb2865ab2016-08-02 11:44:41 -0600703 r = copy_file(&create_fail_test_ta_uuid, &fake_uuid);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200704
705 if (ADBG_EXPECT_TRUE(c, r)) {
Jens Wiklander4441fe22015-10-23 16:53:02 +0200706 res = xtest_teec_open_session(&session, &fake_uuid, NULL,
707 &ret_orig);
708 if (res == TEEC_SUCCESS)
709 TEEC_CloseSession(&session);
710 ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200711 }
712
David Brownb2865ab2016-08-02 11:44:41 -0600713 ADBG_EXPECT_TRUE(c, rm_file(&fake_uuid));
Jens Wiklanderb7940892015-10-23 16:02:40 +0200714}
715
Jens Wiklander4441fe22015-10-23 16:53:02 +0200716static bool load_corrupt_ta(ADBG_Case_t *c, long offs, uint8_t mask)
717{
718 TEEC_Session session = { 0 };
719 TEEC_Result res;
720 uint32_t ret_orig;
721 FILE *f;
722 bool r;
723
David Brownb2865ab2016-08-02 11:44:41 -0600724 r = copy_file(&create_fail_test_ta_uuid, &create_fail_test_ta_uuid);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200725 if (!ADBG_EXPECT_TRUE(c, r)) {
David Brownb2865ab2016-08-02 11:44:41 -0600726 rm_file(&create_fail_test_ta_uuid);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200727 return false;
728 }
729
David Brownb2865ab2016-08-02 11:44:41 -0600730 f = open_ta_file(&create_fail_test_ta_uuid, "r+", true);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200731 if (!ADBG_EXPECT_NOT_NULL(c, f)) {
David Brownb2865ab2016-08-02 11:44:41 -0600732 rm_file(&create_fail_test_ta_uuid);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200733 return false;
734 }
735 r = corrupt_file(f, offs, mask);
736 fclose(f);
737
738 if (ADBG_EXPECT_TRUE(c, r)) {
739 res = xtest_teec_open_session(&session,
740 &create_fail_test_ta_uuid,
741 NULL, &ret_orig);
742 if (res == TEEC_SUCCESS)
743 TEEC_CloseSession(&session);
744 r &= ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res);
745 }
746
David Brownb2865ab2016-08-02 11:44:41 -0600747 r &= ADBG_EXPECT_TRUE(c, rm_file(&create_fail_test_ta_uuid));
Jens Wiklander4441fe22015-10-23 16:53:02 +0200748 return r;
749}
750
Pascal Brandc639ac82015-07-02 08:53:34 +0200751static void xtest_tee_test_1008(ADBG_Case_t *c)
752{
753 TEEC_Session session = { 0 };
754 TEEC_Session session_crypt = { 0 };
755 uint32_t ret_orig;
756
757 Do_ADBG_BeginSubCase(c, "Invoke command");
758 {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300759 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200760 xtest_teec_open_session(&session, &os_test_ta_uuid,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300761 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200762
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300763 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
764 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT,
765 NULL, &ret_orig));
766 TEEC_CloseSession(&session);
767 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200768
Pascal Brandc639ac82015-07-02 08:53:34 +0200769 }
770 Do_ADBG_EndSubCase(c, "Invoke command");
771
772 Do_ADBG_BeginSubCase(c, "Invoke command with timeout");
773 {
774 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
775
776 op.params[0].value.a = 2000;
777 op.paramTypes = TEEC_PARAM_TYPES(
778 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
779
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300780 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200781 xtest_teec_open_session(&session,
782 &os_test_ta_uuid,
783 NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300784 &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200785
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300786 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
787 TEEC_InvokeCommand(&session,
788 TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT,
789 &op, &ret_orig));
790 TEEC_CloseSession(&session);
791 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200792 }
793 Do_ADBG_EndSubCase(c, "Invoke command with timeout");
794
795 Do_ADBG_BeginSubCase(c, "Create session fail");
796 {
Jens Wiklanderb7940892015-10-23 16:02:40 +0200797 size_t n;
798
Pascal Brandc639ac82015-07-02 08:53:34 +0200799 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
800 xtest_teec_open_session(&session_crypt,
801 &create_fail_test_ta_uuid, NULL,
802 &ret_orig));
Pascal Brandc639ac82015-07-02 08:53:34 +0200803 /*
804 * Run this several times to see that there's no memory leakage.
805 */
806 for (n = 0; n < 100; n++) {
807 Do_ADBG_Log("n = %zu", n);
808 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
809 xtest_teec_open_session(&session_crypt,
810 &create_fail_test_ta_uuid,
811 NULL, &ret_orig));
812 }
813 }
814 Do_ADBG_EndSubCase(c, "Create session fail");
Jens Wiklanderb7940892015-10-23 16:02:40 +0200815
David Brownb2865ab2016-08-02 11:44:41 -0600816 make_test_ta_dir();
817
Jens Wiklanderb7940892015-10-23 16:02:40 +0200818 Do_ADBG_BeginSubCase(c, "Load fake uuid TA");
819 load_fake_ta(c);
820 Do_ADBG_EndSubCase(c, "Load fake uuid TA");
821
Jens Wiklander4441fe22015-10-23 16:53:02 +0200822 Do_ADBG_BeginSubCase(c, "Load corrupt TA");
823 ADBG_EXPECT_TRUE(c,
824 load_corrupt_ta(c, offsetof(struct shdr, magic), 1));
825 ADBG_EXPECT_TRUE(c,
826 load_corrupt_ta(c, offsetof(struct shdr, img_type), 1));
827 ADBG_EXPECT_TRUE(c,
828 load_corrupt_ta(c, offsetof(struct shdr, img_size), 1));
829 ADBG_EXPECT_TRUE(c,
830 load_corrupt_ta(c, offsetof(struct shdr, algo), 1));
831 ADBG_EXPECT_TRUE(c,
832 load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1));
833 ADBG_EXPECT_TRUE(c,
834 load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1));
835 ADBG_EXPECT_TRUE(c,
836 load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */
837 ADBG_EXPECT_TRUE(c,
838 load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */
839 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */
840 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 30000, 1)); /* payload */
841 Do_ADBG_EndSubCase(c, "Load corrupt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200842}
843
Pascal Brandc639ac82015-07-02 08:53:34 +0200844static void *cancellation_thread(void *arg)
845{
846 /*
847 * Sleep 0.5 seconds before cancellation to make sure that the other
848 * thread is in RPC_WAIT.
849 */
850 (void)usleep(500000);
851 TEEC_RequestCancellation(arg);
852 return NULL;
853}
Pascal Brandc639ac82015-07-02 08:53:34 +0200854
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300855static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase,
856 uint32_t timeout, bool cancel)
Pascal Brandc639ac82015-07-02 08:53:34 +0200857{
858 TEEC_Session session = { 0 };
859 uint32_t ret_orig;
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300860 pthread_t thr;
Pascal Brandc639ac82015-07-02 08:53:34 +0200861
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300862 Do_ADBG_BeginSubCase(c, "%s", subcase);
Pascal Brandc639ac82015-07-02 08:53:34 +0200863 {
864 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
865
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300866 if (ADBG_EXPECT_TEEC_SUCCESS(c,
867 xtest_teec_open_session(&session, &os_test_ta_uuid,
868 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200869
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300870 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c,
871 TEEC_ORIGIN_TRUSTED_APP,
872 ret_orig);
Pascal Brandc639ac82015-07-02 08:53:34 +0200873
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300874 op.params[0].value.a = timeout;
875 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
876 TEEC_NONE,
877 TEEC_NONE, TEEC_NONE);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300878 if (cancel) {
879 (void)ADBG_EXPECT(c, 0,
880 pthread_create(&thr, NULL,
881 cancellation_thread, &op));
Pascal Brandc639ac82015-07-02 08:53:34 +0200882
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300883 (void)ADBG_EXPECT_TEEC_RESULT(c,
884 TEEC_ERROR_CANCEL,
885 TEEC_InvokeCommand(&session,
886 TA_OS_TEST_CMD_WAIT,
887 &op,
888 &ret_orig));
889 } else
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300890
891 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
892 TEEC_InvokeCommand(&session,
893 TA_OS_TEST_CMD_WAIT,
894 &op,
895 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300896 if (cancel)
897 (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300898
899 TEEC_CloseSession(&session);
900 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200901 }
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300902 Do_ADBG_EndSubCase(c, "%s", subcase);
903}
904
905static void xtest_tee_test_1009(ADBG_Case_t *c)
906{
907 xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false);
908 xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300909 xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300910 xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false);
Pascal Brandc639ac82015-07-02 08:53:34 +0200911}
912
913static void xtest_tee_test_1010(ADBG_Case_t *c)
914{
915 unsigned n;
916
917 for (n = 1; n <= 5; n++) {
918 Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n);
919 xtest_tee_test_invalid_mem_access(c, n);
920 Do_ADBG_EndSubCase(c, "Invalid memory access %u", n);
921 }
922}
923
924static void xtest_tee_test_1011(ADBG_Case_t *c)
925{
926 TEEC_Session session = { 0 };
927 uint32_t ret_orig;
928 struct xtest_crypto_session cs = {
929 c, &session, TA_RPC_CMD_CRYPT_SHA256,
930 TA_RPC_CMD_CRYPT_AES256ECB_ENC,
931 TA_RPC_CMD_CRYPT_AES256ECB_DEC
932 };
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100933 struct xtest_crypto_session cs_privmem = {
934 c, &session,
935 TA_RPC_CMD_CRYPT_PRIVMEM_SHA256,
936 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC,
937 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC
938 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200939 TEEC_UUID uuid = rpc_test_ta_uuid;
940
941 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
942 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
943 return;
944
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100945 Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory");
Pascal Brandc639ac82015-07-02 08:53:34 +0200946 /*
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100947 * Run the "complete crypto test suite" using TA-to-TA
948 * communication
Pascal Brandc639ac82015-07-02 08:53:34 +0200949 */
950 xtest_crypto_test(&cs);
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100951 Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory");
952
953 Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory");
954 /*
955 * Run the "complete crypto test suite" using TA-to-TA
956 * communication via TA private memory.
957 */
958 xtest_crypto_test(&cs_privmem);
959 Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory");
960
Pascal Brandc639ac82015-07-02 08:53:34 +0200961 TEEC_CloseSession(&session);
962}
963
964/*
965 * Note that this test is failing when
966 * - running twice in a raw
967 * - and the user TA is statically linked
968 * This is because the counter is not reseted when opening the first session
969 * in case the TA is statically linked
970 */
971static void xtest_tee_test_1012(ADBG_Case_t *c)
972{
973 TEEC_Session session1 = { 0 };
974 TEEC_Session session2 = { 0 };
975 uint32_t ret_orig;
976 TEEC_UUID uuid = sims_test_ta_uuid;
977
978 Do_ADBG_BeginSubCase(c, "Single Instance Multi Session");
979 {
980 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
981 static const uint8_t in[] = {
982 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
983 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
984 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
985 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
986 };
987 uint8_t out[32] = { 0 };
988 int i;
989
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300990 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200991 xtest_teec_open_session(&session1, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300992 &ret_orig)))
993 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200994
995 op.params[0].value.a = 0;
996 op.params[1].tmpref.buffer = (void *)in;
997 op.params[1].tmpref.size = sizeof(in);
998 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
999 TEEC_MEMREF_TEMP_INPUT,
1000 TEEC_NONE, TEEC_NONE);
1001
1002 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1003 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op,
1004 &ret_orig));
1005
1006 for (i = 1; i < 1000; i++) {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +03001007 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +02001008 xtest_teec_open_session(&session2, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +03001009 &ret_orig)))
1010 continue;
Pascal Brandc639ac82015-07-02 08:53:34 +02001011
1012 op.params[0].value.a = 0;
1013 op.params[1].tmpref.buffer = out;
1014 op.params[1].tmpref.size = sizeof(out);
1015 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1016 TEEC_MEMREF_TEMP_OUTPUT,
1017 TEEC_NONE, TEEC_NONE);
1018
1019 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1020 TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ,
1021 &op, &ret_orig));
1022
1023 if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out,
1024 sizeof(out))) {
1025 Do_ADBG_Log("in:");
1026 Do_ADBG_HexLog(in, sizeof(in), 16);
1027 Do_ADBG_Log("out:");
1028 Do_ADBG_HexLog(out, sizeof(out), 16);
1029 }
1030
1031 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
1032 TEEC_NONE, TEEC_NONE,
1033 TEEC_NONE);
1034
1035 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1036 TEEC_InvokeCommand(&session1,
1037 TA_SIMS_CMD_GET_COUNTER,
1038 &op, &ret_orig));
1039
1040 (void)ADBG_EXPECT(c, 0, op.params[0].value.a);
1041
1042 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1043 TEEC_InvokeCommand(&session2,
1044 TA_SIMS_CMD_GET_COUNTER, &op,
1045 &ret_orig));
1046
1047 (void)ADBG_EXPECT(c, i, op.params[0].value.a);
1048 TEEC_CloseSession(&session2);
1049 }
1050
1051 memset(out, 0, sizeof(out));
1052 op.params[0].value.a = 0;
1053 op.params[1].tmpref.buffer = out;
1054 op.params[1].tmpref.size = sizeof(out);
1055 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1056 TEEC_MEMREF_TEMP_OUTPUT,
1057 TEEC_NONE, TEEC_NONE);
1058
1059 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1060 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op,
1061 &ret_orig));
1062
1063 if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) {
1064 Do_ADBG_Log("in:");
1065 Do_ADBG_HexLog(in, sizeof(in), 16);
1066 Do_ADBG_Log("out:");
1067 Do_ADBG_HexLog(out, sizeof(out), 16);
1068 }
1069
1070 TEEC_CloseSession(&session1);
1071 }
1072}
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001073
1074struct test_1013_thread_arg {
Jens Wiklander70672972016-04-06 00:01:45 +02001075 const TEEC_UUID *uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001076 uint32_t cmd;
1077 uint32_t repeat;
1078 TEEC_SharedMemory *shm;
1079 uint32_t error_orig;
1080 TEEC_Result res;
1081 uint32_t max_concurrency;
1082 const uint8_t *in;
1083 size_t in_len;
1084 uint8_t *out;
1085 size_t out_len;
1086};
1087
1088static void *test_1013_thread(void *arg)
1089{
1090 struct test_1013_thread_arg *a = arg;
1091 TEEC_Session session = { 0 };
1092 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1093 uint8_t p2 = TEEC_NONE;
1094 uint8_t p3 = TEEC_NONE;
1095
Jens Wiklander70672972016-04-06 00:01:45 +02001096 a->res = xtest_teec_open_session(&session, a->uuid, NULL,
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001097 &a->error_orig);
1098 if (a->res != TEEC_SUCCESS)
1099 return NULL;
1100
1101 op.params[0].memref.parent = a->shm;
1102 op.params[0].memref.size = a->shm->size;
1103 op.params[0].memref.offset = 0;
1104 op.params[1].value.a = a->repeat;
1105 op.params[1].value.b = 0;
1106 op.params[2].tmpref.buffer = (void *)a->in;
1107 op.params[2].tmpref.size = a->in_len;
1108 op.params[3].tmpref.buffer = a->out;
1109 op.params[3].tmpref.size = a->out_len;
1110
1111 if (a->in_len)
1112 p2 = TEEC_MEMREF_TEMP_INPUT;
1113 if (a->out_len)
1114 p3 = TEEC_MEMREF_TEMP_OUTPUT;
1115
1116 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT,
1117 TEEC_VALUE_INOUT, p2, p3);
1118
1119 a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig);
1120 a->max_concurrency = op.params[1].value.b;
1121 a->out_len = op.params[3].tmpref.size;
1122 TEEC_CloseSession(&session);
1123 return NULL;
1124}
1125
Pascal Brand4fa35582015-12-17 10:59:12 +01001126#define NUM_THREADS 3
1127
Jens Wiklander70672972016-04-06 00:01:45 +02001128static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency,
1129 const TEEC_UUID *uuid)
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001130{
Pascal Brand4fa35582015-12-17 10:59:12 +01001131 size_t num_threads = NUM_THREADS;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001132 size_t nt;
1133 size_t n;
Jens Wiklander70672972016-04-06 00:01:45 +02001134 size_t repeat = 1000;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001135 pthread_t thr[num_threads];
1136 TEEC_SharedMemory shm;
1137 size_t max_concurrency;
1138 struct test_1013_thread_arg arg[num_threads];
1139 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
1140 static const uint8_t sha256_out[] = {
1141 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
1142 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
1143 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
1144 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
1145 };
1146 uint8_t out[32] = { 0 };
1147
Jens Wiklander70672972016-04-06 00:01:45 +02001148 Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10);
Pascal Brand4fa35582015-12-17 10:59:12 +01001149 *mean_concurrency = 0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001150
1151 memset(&shm, 0, sizeof(shm));
1152 shm.size = sizeof(struct ta_concurrent_shm);
1153 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1154 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1155 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
1156 return;
1157
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001158 memset(shm.buffer, 0, shm.size);
1159 memset(arg, 0, sizeof(arg));
1160 max_concurrency = 0;
1161 nt = num_threads;
1162
1163 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001164 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001165 arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP;
Jens Wiklander70672972016-04-06 00:01:45 +02001166 arg[n].repeat = repeat * 10;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001167 arg[n].shm = &shm;
1168 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1169 test_1013_thread, arg + n)))
1170 nt = n; /* break loop and start cleanup */
1171 }
1172
1173 for (n = 0; n < nt; n++) {
1174 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
1175 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res);
1176 if (arg[n].max_concurrency > max_concurrency)
1177 max_concurrency = arg[n].max_concurrency;
1178 }
1179
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001180 /*
1181 * Concurrency can be limited by several factors, for instance in a
1182 * single CPU system it's dependent on the Preemtion Model used by
1183 * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the
1184 * best result there).
1185 */
1186 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0);
1187 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, num_threads);
Pascal Brand4fa35582015-12-17 10:59:12 +01001188 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001189 Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001190
Jens Wiklander70672972016-04-06 00:01:45 +02001191 Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001192 memset(shm.buffer, 0, shm.size);
1193 memset(arg, 0, sizeof(arg));
1194 max_concurrency = 0;
1195 nt = num_threads;
1196
1197 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001198 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001199 arg[n].cmd = TA_CONCURRENT_CMD_SHA256;
Jens Wiklander70672972016-04-06 00:01:45 +02001200 arg[n].repeat = repeat;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001201 arg[n].shm = &shm;
1202 arg[n].in = sha256_in;
1203 arg[n].in_len = sizeof(sha256_in);
1204 arg[n].out = out;
1205 arg[n].out_len = sizeof(out);
1206 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1207 test_1013_thread, arg + n)))
1208 nt = n; /* break loop and start cleanup */
1209 }
1210
1211 for (n = 0; n < nt; n++) {
1212 if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) &&
1213 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
1214 ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out),
1215 arg[n].out, arg[n].out_len);
1216 if (arg[n].max_concurrency > max_concurrency)
1217 max_concurrency = arg[n].max_concurrency;
1218 }
Pascal Brand4fa35582015-12-17 10:59:12 +01001219 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001220 Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001221
Pascal Brand4fa35582015-12-17 10:59:12 +01001222 *mean_concurrency /= 2.0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001223 TEEC_ReleaseSharedMemory(&shm);
1224}
Pascal Brand4fa35582015-12-17 10:59:12 +01001225
1226static void xtest_tee_test_1013(ADBG_Case_t *c)
1227{
1228 int i;
1229 double mean_concurrency;
1230 double concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001231 int nb_loops = 24;
Jens Wiklander6a9d15a2016-02-01 10:29:42 +01001232
1233 if (level == 0)
1234 nb_loops /= 2;
Pascal Brand4fa35582015-12-17 10:59:12 +01001235
Jens Wiklander70672972016-04-06 00:01:45 +02001236 Do_ADBG_BeginSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001237 mean_concurrency = 0;
1238 for (i = 0; i < nb_loops; i++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001239 xtest_tee_test_1013_single(c, &concurrency,
1240 &concurrent_ta_uuid);
Pascal Brand4fa35582015-12-17 10:59:12 +01001241 mean_concurrency += concurrency;
1242 }
1243 mean_concurrency /= nb_loops;
1244
1245 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1246 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
Jens Wiklander70672972016-04-06 00:01:45 +02001247 Do_ADBG_EndSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001248
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001249#ifndef CFG_PAGED_USER_TA
Jens Wiklander70672972016-04-06 00:01:45 +02001250 Do_ADBG_BeginSubCase(c, "Using large concurrency TA");
1251 mean_concurrency = 0;
1252 for (i = 0; i < nb_loops; i++) {
1253 xtest_tee_test_1013_single(c, &concurrency,
1254 &concurrent_large_ta_uuid);
1255 mean_concurrency += concurrency;
1256 }
1257 mean_concurrency /= nb_loops;
1258
1259 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1260 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
1261 Do_ADBG_EndSubCase(c, "Using large concurrency TA");
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001262#endif
Jens Wiklander70672972016-04-06 00:01:45 +02001263}
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001264
1265#ifdef CFG_SECURE_DATA_PATH
1266static void xtest_tee_test_1014(ADBG_Case_t *c)
1267{
1268 UNUSED(c);
1269
1270 int size = 17000;
1271 int loop = 10;
1272 int ion_heap = DEFAULT_ION_HEAP_TYPE;
1273 int rnd_offset = 1;
1274 int test;
1275 int ret;
1276
1277 test = TEST_NS_TO_TA;
1278 Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001279 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001280 ADBG_EXPECT(c, 0, ret);
1281 Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA");
1282
1283 test = TEST_TA_TO_TA;
1284 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001285 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001286 ADBG_EXPECT(c, 0, ret);
1287 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA");
1288
1289 test = TEST_TA_TO_PTA;
1290 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP pTA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001291 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001292 ADBG_EXPECT(c, 0, ret);
1293 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP pTA");
1294
1295 test = TEST_NS_TO_PTA;
Etienne Carrierea3198522017-10-26 09:48:55 +02001296 Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001297 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001298 ADBG_EXPECT(c, 1, ret);
Etienne Carrierea3198522017-10-26 09:48:55 +02001299 Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001300}
1301#endif
Jens Wiklander272d3642017-04-03 13:03:47 +02001302
1303static void xtest_tee_test_1015(ADBG_Case_t *c)
1304{
1305 TEEC_Result res;
1306 TEEC_Session session = { 0 };
1307 uint32_t ret_orig;
1308
Etienne Carriere11093162017-10-26 09:49:04 +02001309 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander272d3642017-04-03 13:03:47 +02001310 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
1311 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +02001312 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
1313 Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found");
Jens Wiklander272d3642017-04-03 13:03:47 +02001314 return;
Etienne Carriere11093162017-10-26 09:49:04 +02001315 }
1316 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander272d3642017-04-03 13:03:47 +02001317
1318 ADBG_EXPECT_TEEC_SUCCESS(c,
1319 TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE,
1320 NULL, &ret_orig));
1321 TEEC_CloseSession(&session);
1322}
Jerome Forissiere916b102017-06-07 17:55:52 +02001323
1324static void xtest_tee_test_1016(ADBG_Case_t *c)
1325{
1326 TEEC_Session session = { 0 };
1327 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1328 uint32_t ret_orig;
1329
1330 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1331 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1332 &ret_orig)))
1333 return;
1334
1335 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE,
1336 TEEC_NONE);
1337
1338 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1339 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op,
1340 &ret_orig));
1341
1342 TEEC_CloseSession(&session);
1343}