Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1 | /* |
| 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 Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 14 | #include <limits.h> |
| 15 | #include <pthread.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <string.h> |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 18 | #include <sys/stat.h> |
| 19 | #include <sys/types.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 20 | #include <unistd.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 21 | |
| 22 | #include "xtest_test.h" |
| 23 | #include "xtest_helpers.h" |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 24 | #include <signed_hdr.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 25 | |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 26 | #include <pta_invoke_tests.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 27 | #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 Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 32 | #include <ta_concurrent.h> |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 33 | #include <sdp_basic.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 34 | |
| 35 | static void xtest_tee_test_1001(ADBG_Case_t *Case_p); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 36 | static void xtest_tee_test_1002(ADBG_Case_t *Case_p); |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame^] | 37 | static void xtest_tee_test_1003(ADBG_Case_t *Case_p); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 38 | static void xtest_tee_test_1004(ADBG_Case_t *Case_p); |
| 39 | static void xtest_tee_test_1005(ADBG_Case_t *Case_p); |
| 40 | static void xtest_tee_test_1006(ADBG_Case_t *Case_p); |
| 41 | static void xtest_tee_test_1007(ADBG_Case_t *Case_p); |
| 42 | static void xtest_tee_test_1008(ADBG_Case_t *Case_p); |
| 43 | static void xtest_tee_test_1009(ADBG_Case_t *Case_p); |
| 44 | static void xtest_tee_test_1010(ADBG_Case_t *Case_p); |
| 45 | static void xtest_tee_test_1011(ADBG_Case_t *Case_p); |
| 46 | static void xtest_tee_test_1012(ADBG_Case_t *Case_p); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 47 | static void xtest_tee_test_1013(ADBG_Case_t *Case_p); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 48 | #ifdef CFG_SECURE_DATA_PATH |
| 49 | static void xtest_tee_test_1014(ADBG_Case_t *Case_p); |
| 50 | #endif |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 51 | static void xtest_tee_test_1015(ADBG_Case_t *Case_p); |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 52 | static void xtest_tee_test_1016(ADBG_Case_t *Case_p); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 53 | |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 54 | ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 55 | ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters"); |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame^] | 56 | ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003, |
| 57 | "Core internal read/write mutex"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 58 | ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA"); |
| 59 | ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions"); |
| 60 | ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006, |
| 61 | "Test Basic OS features"); |
| 62 | ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic"); |
| 63 | ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 64 | "TEE internal client API"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 65 | ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait"); |
| 66 | ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010, |
| 67 | "Invalid memory access"); |
| 68 | ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011, |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 69 | "Test TA-to-TA features with User Crypt TA"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 70 | ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 71 | "Test Single Instance Multi Session features with SIMS TA"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 72 | ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 73 | "Test concurency with concurrent TA"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 74 | #ifdef CFG_SECURE_DATA_PATH |
| 75 | ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014, |
| 76 | "Test secure data path against SDP TAs and pTAs"); |
| 77 | #endif |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 78 | ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015, |
| 79 | "FS hash-tree corner cases"); |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 80 | ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016, |
| 81 | "Test TA to TA transfers (in/out/inout memrefs on the stack)"); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 82 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 83 | struct 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 | |
| 91 | static 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 Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 187 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 188 | { |
| 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 Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 227 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 228 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 229 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 230 | { |
| 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 Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 269 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static void xtest_tee_test_1001(ADBG_Case_t *c) |
| 273 | { |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 274 | TEEC_Result res; |
| 275 | TEEC_Session session = { 0 }; |
| 276 | uint32_t ret_orig; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 277 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 278 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 279 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 280 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 281 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 282 | Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found"); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 283 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 284 | } |
| 285 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 286 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 287 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 288 | &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig)); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 289 | TEEC_CloseSession(&session); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 292 | static 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 Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 302 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 303 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 304 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 305 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 306 | Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 307 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 308 | } |
| 309 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 310 | |
| 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]); |
| 326 | out: |
| 327 | TEEC_CloseSession(&session); |
| 328 | } |
| 329 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame^] | 330 | struct 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 Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 340 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame^] | 341 | static 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 | |
| 389 | static 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 Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 465 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 466 | static 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 | |
| 490 | static 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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 496 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 497 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 498 | &ret_orig))) |
| 499 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 500 | |
| 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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 510 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 511 | TEEC_ERROR_TARGET_DEAD, |
| 512 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 513 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 514 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 515 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 516 | |
| 517 | TEEC_CloseSession(&session); |
| 518 | } |
| 519 | |
| 520 | static 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 Wiklander | eb6bce7 | 2016-09-23 11:37:33 +0200 | [diff] [blame] | 529 | xtest_teec_open_session(&sessions[i], |
| 530 | &concurrent_ta_uuid, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 531 | NULL, &ret_orig))) |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | for (; --i >= 0; ) |
| 536 | TEEC_CloseSession(&sessions[i]); |
| 537 | } |
| 538 | |
| 539 | static 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 | |
| 563 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 564 | { |
| 565 | TEEC_Session session = { 0 }; |
| 566 | uint32_t ret_orig; |
| 567 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 568 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 569 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 570 | &ret_orig))) |
| 571 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 572 | |
| 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 Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 590 | #ifndef TA_DIR |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 591 | # ifdef __ANDROID__ |
| 592 | #define TA_DIR "/system/lib/optee_armtz" |
| 593 | # else |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 594 | #define TA_DIR "/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 595 | # endif |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 596 | #endif |
| 597 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 598 | #ifndef TA_TEST_DIR |
| 599 | # ifdef __ANDROID__ |
Zoltan Kuscsik | d579615 | 2016-10-27 10:09:12 +0200 | [diff] [blame] | 600 | # define TA_TEST_DIR "/data/tee/optee_armtz" |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 601 | # else |
| 602 | # define TA_TEST_DIR "/tmp/optee_armtz" |
| 603 | # endif |
| 604 | #endif |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 605 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 606 | static void make_test_ta_dir(void) |
| 607 | { |
| 608 | #ifdef __ANDROID__ |
Zoltan Kuscsik | d579615 | 2016-10-27 10:09:12 +0200 | [diff] [blame] | 609 | (void)mkdir("/data/tee", 0755); |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 610 | #endif |
| 611 | (void)mkdir(TA_TEST_DIR, 0755); |
| 612 | } |
| 613 | |
| 614 | static void uuid_to_full_name(char *buf, size_t blen, const TEEC_UUID *uuid, |
| 615 | bool for_write) |
| 616 | { |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 617 | snprintf(buf, blen, |
Jens Wiklander | 6203b87 | 2016-12-08 19:18:29 +0100 | [diff] [blame] | 618 | "%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta", |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 619 | for_write ? TA_TEST_DIR : TA_DIR, |
| 620 | uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 621 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 622 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 623 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 624 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 625 | } |
| 626 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 627 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode, |
| 628 | bool for_write) |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 629 | { |
| 630 | char buf[PATH_MAX]; |
| 631 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 632 | uuid_to_full_name(buf, sizeof(buf), uuid, for_write); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 633 | return fopen(buf, mode); |
| 634 | } |
| 635 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 636 | static bool rm_file(const TEEC_UUID *uuid) |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 637 | { |
| 638 | char buf[PATH_MAX]; |
| 639 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 640 | uuid_to_full_name(buf, sizeof(buf), uuid, true); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 641 | return !unlink(buf); |
| 642 | } |
| 643 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 644 | static bool copy_file(const TEEC_UUID *src_uuid, const TEEC_UUID *dst_uuid) |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 645 | { |
| 646 | char buf[4 * 1024]; |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 647 | FILE *src = open_ta_file(src_uuid, "r", false); |
| 648 | FILE *dst = open_ta_file(dst_uuid, "w", true); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 649 | size_t r; |
| 650 | size_t w; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 651 | bool ret = false; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 652 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 653 | 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 Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 662 | } |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 663 | |
| 664 | if (src) |
| 665 | fclose(src); |
| 666 | if (dst) |
| 667 | fclose(dst); |
| 668 | return ret; |
| 669 | } |
| 670 | |
| 671 | static 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 Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static 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 Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 701 | bool r; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 702 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 703 | r = copy_file(&create_fail_test_ta_uuid, &fake_uuid); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 704 | |
| 705 | if (ADBG_EXPECT_TRUE(c, r)) { |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 706 | 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 Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 711 | } |
| 712 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 713 | ADBG_EXPECT_TRUE(c, rm_file(&fake_uuid)); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 714 | } |
| 715 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 716 | static 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 Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 724 | r = copy_file(&create_fail_test_ta_uuid, &create_fail_test_ta_uuid); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 725 | if (!ADBG_EXPECT_TRUE(c, r)) { |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 726 | rm_file(&create_fail_test_ta_uuid); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 727 | return false; |
| 728 | } |
| 729 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 730 | f = open_ta_file(&create_fail_test_ta_uuid, "r+", true); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 731 | if (!ADBG_EXPECT_NOT_NULL(c, f)) { |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 732 | rm_file(&create_fail_test_ta_uuid); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 733 | 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 Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 747 | r &= ADBG_EXPECT_TRUE(c, rm_file(&create_fail_test_ta_uuid)); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 748 | return r; |
| 749 | } |
| 750 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 751 | static 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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 759 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 760 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 761 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 762 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 763 | (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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 768 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 769 | } |
| 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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 780 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 781 | xtest_teec_open_session(&session, |
| 782 | &os_test_ta_uuid, |
| 783 | NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 784 | &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 785 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 786 | (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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 792 | } |
| 793 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 794 | |
| 795 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 796 | { |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 797 | size_t n; |
| 798 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 799 | (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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 803 | /* |
| 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 Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 815 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 816 | make_test_ta_dir(); |
| 817 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 818 | Do_ADBG_BeginSubCase(c, "Load fake uuid TA"); |
| 819 | load_fake_ta(c); |
| 820 | Do_ADBG_EndSubCase(c, "Load fake uuid TA"); |
| 821 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 822 | 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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 842 | } |
| 843 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 844 | static 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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 854 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 855 | static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase, |
| 856 | uint32_t timeout, bool cancel) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 857 | { |
| 858 | TEEC_Session session = { 0 }; |
| 859 | uint32_t ret_orig; |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 860 | pthread_t thr; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 861 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 862 | Do_ADBG_BeginSubCase(c, "%s", subcase); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 863 | { |
| 864 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 865 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 866 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 867 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 868 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 869 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 870 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, |
| 871 | TEEC_ORIGIN_TRUSTED_APP, |
| 872 | ret_orig); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 873 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 874 | op.params[0].value.a = timeout; |
| 875 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 876 | TEEC_NONE, |
| 877 | TEEC_NONE, TEEC_NONE); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 878 | if (cancel) { |
| 879 | (void)ADBG_EXPECT(c, 0, |
| 880 | pthread_create(&thr, NULL, |
| 881 | cancellation_thread, &op)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 882 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 883 | (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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 890 | |
| 891 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 892 | TEEC_InvokeCommand(&session, |
| 893 | TA_OS_TEST_CMD_WAIT, |
| 894 | &op, |
| 895 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 896 | if (cancel) |
| 897 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 898 | |
| 899 | TEEC_CloseSession(&session); |
| 900 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 901 | } |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 902 | Do_ADBG_EndSubCase(c, "%s", subcase); |
| 903 | } |
| 904 | |
| 905 | static 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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 909 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 910 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | static 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 | |
| 924 | static 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 Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 933 | 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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 939 | 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 Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 945 | Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 946 | /* |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 947 | * Run the "complete crypto test suite" using TA-to-TA |
| 948 | * communication |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 949 | */ |
| 950 | xtest_crypto_test(&cs); |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 951 | 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 Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 961 | 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 | */ |
| 971 | static 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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 990 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 991 | xtest_teec_open_session(&session1, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 992 | &ret_orig))) |
| 993 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 994 | |
| 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 Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 1007 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1008 | xtest_teec_open_session(&session2, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 1009 | &ret_orig))) |
| 1010 | continue; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1011 | |
| 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 Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1073 | |
| 1074 | struct test_1013_thread_arg { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1075 | const TEEC_UUID *uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1076 | 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 | |
| 1088 | static 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 Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1096 | a->res = xtest_teec_open_session(&session, a->uuid, NULL, |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1097 | &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 Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1126 | #define NUM_THREADS 3 |
| 1127 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1128 | static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency, |
| 1129 | const TEEC_UUID *uuid) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1130 | { |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1131 | size_t num_threads = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1132 | size_t nt; |
| 1133 | size_t n; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1134 | size_t repeat = 1000; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1135 | 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 Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1148 | Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1149 | *mean_concurrency = 0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1150 | |
| 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 Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1158 | 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 Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1164 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1165 | arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1166 | arg[n].repeat = repeat * 10; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1167 | 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 Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1180 | /* |
| 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 Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1188 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1189 | Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1190 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1191 | Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1192 | 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 Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1198 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1199 | arg[n].cmd = TA_CONCURRENT_CMD_SHA256; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1200 | arg[n].repeat = repeat; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1201 | 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 Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1219 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1220 | Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1221 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1222 | *mean_concurrency /= 2.0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1223 | TEEC_ReleaseSharedMemory(&shm); |
| 1224 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1225 | |
| 1226 | static void xtest_tee_test_1013(ADBG_Case_t *c) |
| 1227 | { |
| 1228 | int i; |
| 1229 | double mean_concurrency; |
| 1230 | double concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1231 | int nb_loops = 24; |
Jens Wiklander | 6a9d15a | 2016-02-01 10:29:42 +0100 | [diff] [blame] | 1232 | |
| 1233 | if (level == 0) |
| 1234 | nb_loops /= 2; |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1235 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1236 | Do_ADBG_BeginSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1237 | mean_concurrency = 0; |
| 1238 | for (i = 0; i < nb_loops; i++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1239 | xtest_tee_test_1013_single(c, &concurrency, |
| 1240 | &concurrent_ta_uuid); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1241 | 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 Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1247 | Do_ADBG_EndSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1248 | |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1249 | #ifndef CFG_PAGED_USER_TA |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1250 | 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 Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1262 | #endif |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1263 | } |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1264 | |
| 1265 | #ifdef CFG_SECURE_DATA_PATH |
| 1266 | static 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 Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1279 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1280 | 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 Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1285 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1286 | 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 Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1291 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1292 | 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 Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1296 | Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1297 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1298 | ADBG_EXPECT(c, 1, ret); |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1299 | Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1300 | } |
| 1301 | #endif |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1302 | |
| 1303 | static 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 Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1309 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1310 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1311 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1312 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1313 | Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found"); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1314 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1315 | } |
| 1316 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1317 | |
| 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 Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1323 | |
| 1324 | static 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 | } |