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 | |
| 26 | #include <ta_crypt.h> |
| 27 | #include <ta_os_test.h> |
| 28 | #include <ta_create_fail_test.h> |
| 29 | #include <ta_rpc_test.h> |
| 30 | #include <ta_sims_test.h> |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 31 | #include <ta_concurrent.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 32 | |
| 33 | static void xtest_tee_test_1001(ADBG_Case_t *Case_p); |
| 34 | static void xtest_tee_test_1004(ADBG_Case_t *Case_p); |
| 35 | static void xtest_tee_test_1005(ADBG_Case_t *Case_p); |
| 36 | static void xtest_tee_test_1006(ADBG_Case_t *Case_p); |
| 37 | static void xtest_tee_test_1007(ADBG_Case_t *Case_p); |
| 38 | static void xtest_tee_test_1008(ADBG_Case_t *Case_p); |
| 39 | static void xtest_tee_test_1009(ADBG_Case_t *Case_p); |
| 40 | static void xtest_tee_test_1010(ADBG_Case_t *Case_p); |
| 41 | static void xtest_tee_test_1011(ADBG_Case_t *Case_p); |
| 42 | static void xtest_tee_test_1012(ADBG_Case_t *Case_p); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 43 | static void xtest_tee_test_1013(ADBG_Case_t *Case_p); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 44 | |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 45 | ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests"); |
| 46 | ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA"); |
| 47 | ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions"); |
| 48 | ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006, |
| 49 | "Test Basic OS features"); |
| 50 | ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic"); |
| 51 | ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 52 | "TEE internal client API"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 53 | ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait"); |
| 54 | ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010, |
| 55 | "Invalid memory access"); |
| 56 | ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011, |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 57 | "Test TA-to-TA features with User Crypt TA"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 58 | ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 59 | "Test Single Instance Multi Session features with SIMS TA"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 60 | ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 61 | "Test concurency with concurrent TA"); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 62 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 63 | struct xtest_crypto_session { |
| 64 | ADBG_Case_t *c; |
| 65 | TEEC_Session *session; |
| 66 | uint32_t cmd_id_sha256; |
| 67 | uint32_t cmd_id_aes256ecb_encrypt; |
| 68 | uint32_t cmd_id_aes256ecb_decrypt; |
| 69 | }; |
| 70 | |
| 71 | static void xtest_crypto_test(struct xtest_crypto_session *cs) |
| 72 | { |
| 73 | uint32_t ret_orig; |
| 74 | uint8_t crypt_out[16]; |
| 75 | uint8_t crypt_in[16] = { 22, 17 }; |
| 76 | |
| 77 | crypt_in[15] = 60; |
| 78 | |
| 79 | Do_ADBG_BeginSubCase(cs->c, "AES encrypt"); |
| 80 | { |
| 81 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 82 | |
| 83 | op.params[0].tmpref.buffer = crypt_in; |
| 84 | op.params[0].tmpref.size = sizeof(crypt_in); |
| 85 | op.params[1].tmpref.buffer = crypt_out; |
| 86 | op.params[1].tmpref.size = sizeof(crypt_out); |
| 87 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 88 | TEEC_MEMREF_TEMP_OUTPUT, |
| 89 | TEEC_NONE, TEEC_NONE); |
| 90 | |
| 91 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 92 | TEEC_InvokeCommand(cs->session, |
| 93 | cs-> |
| 94 | cmd_id_aes256ecb_encrypt, |
| 95 | &op, |
| 96 | &ret_orig)); |
| 97 | } |
| 98 | Do_ADBG_EndSubCase(cs->c, "AES encrypt"); |
| 99 | |
| 100 | Do_ADBG_BeginSubCase(cs->c, "AES decrypt"); |
| 101 | { |
| 102 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 103 | uint8_t out[16]; |
| 104 | |
| 105 | op.params[0].tmpref.buffer = crypt_out; |
| 106 | op.params[0].tmpref.size = sizeof(crypt_out); |
| 107 | op.params[1].tmpref.buffer = out; |
| 108 | op.params[1].tmpref.size = sizeof(out); |
| 109 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 110 | TEEC_MEMREF_TEMP_OUTPUT, |
| 111 | TEEC_NONE, TEEC_NONE); |
| 112 | |
| 113 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 114 | TEEC_InvokeCommand(cs->session, |
| 115 | cs-> |
| 116 | cmd_id_aes256ecb_decrypt, |
| 117 | &op, |
| 118 | &ret_orig)); |
| 119 | |
| 120 | if (!ADBG_EXPECT(cs->c, 0, |
| 121 | memcmp(crypt_in, out, sizeof(crypt_in)))) { |
| 122 | Do_ADBG_Log("crypt_in:"); |
| 123 | Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16); |
| 124 | Do_ADBG_Log("out:"); |
| 125 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 126 | } |
| 127 | } |
| 128 | Do_ADBG_EndSubCase(cs->c, "AES decrypt"); |
| 129 | |
| 130 | Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 131 | { |
| 132 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 133 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 134 | static const uint8_t sha256_out[] = { |
| 135 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 136 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 137 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 138 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 139 | }; |
| 140 | uint8_t out[32] = { 0 }; |
| 141 | |
| 142 | op.params[0].tmpref.buffer = (void *)sha256_in; |
| 143 | op.params[0].tmpref.size = sizeof(sha256_in); |
| 144 | op.params[1].tmpref.buffer = out; |
| 145 | op.params[1].tmpref.size = sizeof(out); |
| 146 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 147 | TEEC_MEMREF_TEMP_OUTPUT, |
| 148 | TEEC_NONE, TEEC_NONE); |
| 149 | |
| 150 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 151 | TEEC_InvokeCommand(cs->session, |
| 152 | cs-> |
| 153 | cmd_id_sha256, |
| 154 | &op, |
| 155 | &ret_orig)); |
| 156 | |
| 157 | if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out, |
| 158 | sizeof(sha256_out)))) { |
| 159 | Do_ADBG_Log("sha256_out:"); |
| 160 | Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16); |
| 161 | Do_ADBG_Log("out:"); |
| 162 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 163 | } |
| 164 | } |
| 165 | Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 166 | |
| 167 | Do_ADBG_BeginSubCase(cs->c, |
| 168 | "AES-256 ECB encrypt test, 32 bytes input, with fixed key"); |
| 169 | { |
| 170 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 171 | static const uint8_t in[] = { |
| 172 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 173 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 174 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 175 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 176 | }; |
| 177 | static const uint8_t exp_out[] = { |
| 178 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 179 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 180 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 181 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 182 | }; |
| 183 | uint8_t out[sizeof(exp_out)]; |
| 184 | |
| 185 | op.params[0].tmpref.buffer = (void *)in; |
| 186 | op.params[0].tmpref.size = sizeof(in); |
| 187 | op.params[1].tmpref.buffer = out; |
| 188 | op.params[1].tmpref.size = sizeof(out); |
| 189 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 190 | TEEC_MEMREF_TEMP_OUTPUT, |
| 191 | TEEC_NONE, TEEC_NONE); |
| 192 | |
| 193 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 194 | TEEC_InvokeCommand(cs->session, |
| 195 | cs-> |
| 196 | cmd_id_aes256ecb_encrypt, |
| 197 | &op, |
| 198 | &ret_orig)); |
| 199 | |
| 200 | if (!ADBG_EXPECT(cs->c, 0, |
| 201 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 202 | Do_ADBG_Log("exp_out:"); |
| 203 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 204 | Do_ADBG_Log("out:"); |
| 205 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 206 | } |
| 207 | } |
| 208 | Do_ADBG_EndSubCase(cs->c, |
| 209 | "AES-256 ECB encrypt test, 32 bytes input, with fixed key"); |
| 210 | |
| 211 | Do_ADBG_BeginSubCase(cs->c, |
| 212 | "AES-256 ECB decrypt test, 32 bytes input, with fixed key"); |
| 213 | { |
| 214 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 215 | static const uint8_t in[] = { |
| 216 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 217 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 218 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 219 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 220 | }; |
| 221 | static const uint8_t exp_out[] = { |
| 222 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 223 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 224 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 225 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 226 | }; |
| 227 | uint8_t out[sizeof(exp_out)]; |
| 228 | |
| 229 | op.params[0].tmpref.buffer = (void *)in; |
| 230 | op.params[0].tmpref.size = sizeof(in); |
| 231 | op.params[1].tmpref.buffer = out; |
| 232 | op.params[1].tmpref.size = sizeof(out); |
| 233 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 234 | TEEC_MEMREF_TEMP_OUTPUT, |
| 235 | TEEC_NONE, TEEC_NONE); |
| 236 | |
| 237 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 238 | TEEC_InvokeCommand(cs->session, |
| 239 | cs-> |
| 240 | cmd_id_aes256ecb_decrypt, |
| 241 | &op, |
| 242 | &ret_orig)); |
| 243 | |
| 244 | if (!ADBG_EXPECT(cs->c, 0, |
| 245 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 246 | Do_ADBG_Log("exp_out:"); |
| 247 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 248 | Do_ADBG_Log("out:"); |
| 249 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 250 | } |
| 251 | } |
| 252 | Do_ADBG_EndSubCase(cs->c, |
| 253 | "AES-256 ECB decrypt test, 32 bytes input, with fixed key"); |
| 254 | } |
| 255 | |
| 256 | static void xtest_tee_test_1001(ADBG_Case_t *c) |
| 257 | { |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 258 | TEEC_Result res; |
| 259 | TEEC_Session session = { 0 }; |
| 260 | uint32_t ret_orig; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 261 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 262 | #define CMD_SELF_TESTS 2 |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 263 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 264 | res = xtest_teec_open_session(&session, &sta_test_ta_uuid, NULL, |
| 265 | &ret_orig); |
| 266 | /* |
| 267 | * If the static TA (which is optional) isn't available, skip this |
| 268 | * test. |
| 269 | */ |
| 270 | if (res != TEEC_SUCCESS) |
| 271 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 272 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 273 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
| 274 | &session, CMD_SELF_TESTS, NULL, &ret_orig)); |
| 275 | TEEC_CloseSession(&session); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | static void xtest_tee_test_1004(ADBG_Case_t *c) |
| 279 | { |
| 280 | TEEC_Session session = { 0 }; |
| 281 | uint32_t ret_orig; |
| 282 | struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256, |
| 283 | TA_CRYPT_CMD_AES256ECB_ENC, |
| 284 | TA_CRYPT_CMD_AES256ECB_DEC }; |
| 285 | |
| 286 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session( |
| 287 | &session, &crypt_user_ta_uuid, |
| 288 | NULL, &ret_orig))) |
| 289 | return; |
| 290 | |
| 291 | /* Run the "complete crypto test suite" */ |
| 292 | xtest_crypto_test(&cs); |
| 293 | |
| 294 | TEEC_CloseSession(&session); |
| 295 | } |
| 296 | |
| 297 | #ifndef TEEC_ERROR_TARGET_DEAD |
| 298 | /* To be removed when we have TEEC_ERROR_TARGET_DEAD from tee_client_api.h */ |
| 299 | #define TEEC_ERROR_TARGET_DEAD 0xFFFF3024 |
| 300 | #endif |
| 301 | |
| 302 | static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, uint32_t n) |
| 303 | { |
| 304 | TEEC_Session session = { 0 }; |
| 305 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 306 | uint32_t ret_orig; |
| 307 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 308 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 309 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 310 | &ret_orig))) |
| 311 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 312 | |
| 313 | op.params[0].value.a = n; |
| 314 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 315 | TEEC_NONE); |
| 316 | |
| 317 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 318 | TEEC_ERROR_TARGET_DEAD, |
| 319 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 320 | &ret_orig)); |
| 321 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 322 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 323 | TEEC_ERROR_TARGET_DEAD, |
| 324 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 325 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 326 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 327 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 328 | |
| 329 | TEEC_CloseSession(&session); |
| 330 | } |
| 331 | |
| 332 | static void xtest_tee_test_1005(ADBG_Case_t *c) |
| 333 | { |
| 334 | uint32_t ret_orig; |
| 335 | #define MAX_SESSIONS 3 |
| 336 | TEEC_Session sessions[MAX_SESSIONS]; |
| 337 | int i; |
| 338 | |
| 339 | for (i = 0; i < MAX_SESSIONS; i++) { |
| 340 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jens Wiklander | eb6bce7 | 2016-09-23 11:37:33 +0200 | [diff] [blame] | 341 | xtest_teec_open_session(&sessions[i], |
| 342 | &concurrent_ta_uuid, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 343 | NULL, &ret_orig))) |
| 344 | break; |
| 345 | } |
| 346 | |
| 347 | for (; --i >= 0; ) |
| 348 | TEEC_CloseSession(&sessions[i]); |
| 349 | } |
| 350 | |
| 351 | static void xtest_tee_test_1006(ADBG_Case_t *c) |
| 352 | { |
| 353 | TEEC_Session session = { 0 }; |
| 354 | uint32_t ret_orig; |
| 355 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 356 | uint8_t buf[32]; |
| 357 | |
| 358 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 359 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 360 | &ret_orig))) |
| 361 | return; |
| 362 | |
| 363 | op.params[0].tmpref.buffer = buf; |
| 364 | op.params[0].tmpref.size = sizeof(buf); |
| 365 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 366 | TEEC_NONE, TEEC_NONE); |
| 367 | |
| 368 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 369 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op, |
| 370 | &ret_orig)); |
| 371 | |
| 372 | TEEC_CloseSession(&session); |
| 373 | } |
| 374 | |
| 375 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 376 | { |
| 377 | TEEC_Session session = { 0 }; |
| 378 | uint32_t ret_orig; |
| 379 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 380 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 381 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 382 | &ret_orig))) |
| 383 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 384 | |
| 385 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 386 | TEEC_ERROR_TARGET_DEAD, |
| 387 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL, |
| 388 | &ret_orig)); |
| 389 | |
| 390 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 391 | |
| 392 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 393 | TEEC_ERROR_TARGET_DEAD, |
| 394 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL, |
| 395 | &ret_orig)); |
| 396 | |
| 397 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 398 | |
| 399 | TEEC_CloseSession(&session); |
| 400 | } |
| 401 | |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 402 | #ifndef TA_DIR |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame^] | 403 | # ifdef __ANDROID__ |
| 404 | #define TA_DIR "/system/lib/optee_armtz" |
| 405 | # else |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 406 | #define TA_DIR "/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame^] | 407 | # endif |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 408 | #endif |
| 409 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 410 | #ifndef TA_TEST_DIR |
| 411 | # ifdef __ANDROID__ |
Zoltan Kuscsik | d579615 | 2016-10-27 10:09:12 +0200 | [diff] [blame] | 412 | # define TA_TEST_DIR "/data/tee/optee_armtz" |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 413 | # else |
| 414 | # define TA_TEST_DIR "/tmp/optee_armtz" |
| 415 | # endif |
| 416 | #endif |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 417 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 418 | static void make_test_ta_dir(void) |
| 419 | { |
| 420 | #ifdef __ANDROID__ |
Zoltan Kuscsik | d579615 | 2016-10-27 10:09:12 +0200 | [diff] [blame] | 421 | (void)mkdir("/data/tee", 0755); |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 422 | #endif |
| 423 | (void)mkdir(TA_TEST_DIR, 0755); |
| 424 | } |
| 425 | |
| 426 | static void uuid_to_full_name(char *buf, size_t blen, const TEEC_UUID *uuid, |
| 427 | bool for_write) |
| 428 | { |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 429 | snprintf(buf, blen, |
Jens Wiklander | 6203b87 | 2016-12-08 19:18:29 +0100 | [diff] [blame] | 430 | "%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] | 431 | for_write ? TA_TEST_DIR : TA_DIR, |
| 432 | uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 433 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 434 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 435 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 436 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 437 | } |
| 438 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 439 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode, |
| 440 | bool for_write) |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 441 | { |
| 442 | char buf[PATH_MAX]; |
| 443 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 444 | uuid_to_full_name(buf, sizeof(buf), uuid, for_write); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 445 | return fopen(buf, mode); |
| 446 | } |
| 447 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 448 | static bool rm_file(const TEEC_UUID *uuid) |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 449 | { |
| 450 | char buf[PATH_MAX]; |
| 451 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 452 | uuid_to_full_name(buf, sizeof(buf), uuid, true); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 453 | return !unlink(buf); |
| 454 | } |
| 455 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 456 | 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] | 457 | { |
| 458 | char buf[4 * 1024]; |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 459 | FILE *src = open_ta_file(src_uuid, "r", false); |
| 460 | FILE *dst = open_ta_file(dst_uuid, "w", true); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 461 | size_t r; |
| 462 | size_t w; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 463 | bool ret = false; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 464 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 465 | if (src && dst) { |
| 466 | do { |
| 467 | r = fread(buf, 1, sizeof(buf), src); |
| 468 | if (!r) { |
| 469 | ret = !!feof(src); |
| 470 | break; |
| 471 | } |
| 472 | w = fwrite(buf, 1, r, dst); |
| 473 | } while (w == r); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 474 | } |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 475 | |
| 476 | if (src) |
| 477 | fclose(src); |
| 478 | if (dst) |
| 479 | fclose(dst); |
| 480 | return ret; |
| 481 | } |
| 482 | |
| 483 | static bool corrupt_file(FILE *f, long offs, uint8_t mask) |
| 484 | { |
| 485 | uint8_t b; |
| 486 | |
| 487 | if (fseek(f, offs, SEEK_SET)) |
| 488 | return false; |
| 489 | |
| 490 | if (fread(&b, 1, 1, f) != 1) |
| 491 | return false; |
| 492 | |
| 493 | b ^= mask; |
| 494 | |
| 495 | if (fseek(f, offs, SEEK_SET)) |
| 496 | return false; |
| 497 | |
| 498 | if (fwrite(&b, 1, 1, f) != 1) |
| 499 | return false; |
| 500 | |
| 501 | return true; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | static void load_fake_ta(ADBG_Case_t *c) |
| 505 | { |
| 506 | static const TEEC_UUID fake_uuid = { |
| 507 | 0x7e0a0900, 0x586b, 0x11e5, |
| 508 | { 0x93, 0x1f, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } |
| 509 | }; |
| 510 | TEEC_Session session = { 0 }; |
| 511 | TEEC_Result res; |
| 512 | uint32_t ret_orig; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 513 | bool r; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 514 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 515 | r = copy_file(&create_fail_test_ta_uuid, &fake_uuid); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 516 | |
| 517 | if (ADBG_EXPECT_TRUE(c, r)) { |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 518 | res = xtest_teec_open_session(&session, &fake_uuid, NULL, |
| 519 | &ret_orig); |
| 520 | if (res == TEEC_SUCCESS) |
| 521 | TEEC_CloseSession(&session); |
| 522 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 523 | } |
| 524 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 525 | ADBG_EXPECT_TRUE(c, rm_file(&fake_uuid)); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 528 | static bool load_corrupt_ta(ADBG_Case_t *c, long offs, uint8_t mask) |
| 529 | { |
| 530 | TEEC_Session session = { 0 }; |
| 531 | TEEC_Result res; |
| 532 | uint32_t ret_orig; |
| 533 | FILE *f; |
| 534 | bool r; |
| 535 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 536 | 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] | 537 | if (!ADBG_EXPECT_TRUE(c, r)) { |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 538 | rm_file(&create_fail_test_ta_uuid); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 539 | return false; |
| 540 | } |
| 541 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 542 | f = open_ta_file(&create_fail_test_ta_uuid, "r+", true); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 543 | if (!ADBG_EXPECT_NOT_NULL(c, f)) { |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 544 | rm_file(&create_fail_test_ta_uuid); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | r = corrupt_file(f, offs, mask); |
| 548 | fclose(f); |
| 549 | |
| 550 | if (ADBG_EXPECT_TRUE(c, r)) { |
| 551 | res = xtest_teec_open_session(&session, |
| 552 | &create_fail_test_ta_uuid, |
| 553 | NULL, &ret_orig); |
| 554 | if (res == TEEC_SUCCESS) |
| 555 | TEEC_CloseSession(&session); |
| 556 | r &= ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res); |
| 557 | } |
| 558 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 559 | r &= ADBG_EXPECT_TRUE(c, rm_file(&create_fail_test_ta_uuid)); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 560 | return r; |
| 561 | } |
| 562 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 563 | static void xtest_tee_test_1008(ADBG_Case_t *c) |
| 564 | { |
| 565 | TEEC_Session session = { 0 }; |
| 566 | TEEC_Session session_crypt = { 0 }; |
| 567 | uint32_t ret_orig; |
| 568 | |
| 569 | Do_ADBG_BeginSubCase(c, "Invoke command"); |
| 570 | { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 571 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 572 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 573 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 574 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 575 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 576 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT, |
| 577 | NULL, &ret_orig)); |
| 578 | TEEC_CloseSession(&session); |
| 579 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 580 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 581 | } |
| 582 | Do_ADBG_EndSubCase(c, "Invoke command"); |
| 583 | |
| 584 | Do_ADBG_BeginSubCase(c, "Invoke command with timeout"); |
| 585 | { |
| 586 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 587 | |
| 588 | op.params[0].value.a = 2000; |
| 589 | op.paramTypes = TEEC_PARAM_TYPES( |
| 590 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 591 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 592 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 593 | xtest_teec_open_session(&session, |
| 594 | &os_test_ta_uuid, |
| 595 | NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 596 | &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 597 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 598 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 599 | TEEC_InvokeCommand(&session, |
| 600 | TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT, |
| 601 | &op, &ret_orig)); |
| 602 | TEEC_CloseSession(&session); |
| 603 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 604 | } |
| 605 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 606 | |
| 607 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 608 | { |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 609 | size_t n; |
| 610 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 611 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 612 | xtest_teec_open_session(&session_crypt, |
| 613 | &create_fail_test_ta_uuid, NULL, |
| 614 | &ret_orig)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 615 | /* |
| 616 | * Run this several times to see that there's no memory leakage. |
| 617 | */ |
| 618 | for (n = 0; n < 100; n++) { |
| 619 | Do_ADBG_Log("n = %zu", n); |
| 620 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 621 | xtest_teec_open_session(&session_crypt, |
| 622 | &create_fail_test_ta_uuid, |
| 623 | NULL, &ret_orig)); |
| 624 | } |
| 625 | } |
| 626 | Do_ADBG_EndSubCase(c, "Create session fail"); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 627 | |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 628 | make_test_ta_dir(); |
| 629 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 630 | Do_ADBG_BeginSubCase(c, "Load fake uuid TA"); |
| 631 | load_fake_ta(c); |
| 632 | Do_ADBG_EndSubCase(c, "Load fake uuid TA"); |
| 633 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 634 | Do_ADBG_BeginSubCase(c, "Load corrupt TA"); |
| 635 | ADBG_EXPECT_TRUE(c, |
| 636 | load_corrupt_ta(c, offsetof(struct shdr, magic), 1)); |
| 637 | ADBG_EXPECT_TRUE(c, |
| 638 | load_corrupt_ta(c, offsetof(struct shdr, img_type), 1)); |
| 639 | ADBG_EXPECT_TRUE(c, |
| 640 | load_corrupt_ta(c, offsetof(struct shdr, img_size), 1)); |
| 641 | ADBG_EXPECT_TRUE(c, |
| 642 | load_corrupt_ta(c, offsetof(struct shdr, algo), 1)); |
| 643 | ADBG_EXPECT_TRUE(c, |
| 644 | load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1)); |
| 645 | ADBG_EXPECT_TRUE(c, |
| 646 | load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1)); |
| 647 | ADBG_EXPECT_TRUE(c, |
| 648 | load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */ |
| 649 | ADBG_EXPECT_TRUE(c, |
| 650 | load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */ |
| 651 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */ |
| 652 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 30000, 1)); /* payload */ |
| 653 | Do_ADBG_EndSubCase(c, "Load corrupt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 654 | } |
| 655 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 656 | static void *cancellation_thread(void *arg) |
| 657 | { |
| 658 | /* |
| 659 | * Sleep 0.5 seconds before cancellation to make sure that the other |
| 660 | * thread is in RPC_WAIT. |
| 661 | */ |
| 662 | (void)usleep(500000); |
| 663 | TEEC_RequestCancellation(arg); |
| 664 | return NULL; |
| 665 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 666 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 667 | static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase, |
| 668 | uint32_t timeout, bool cancel) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 669 | { |
| 670 | TEEC_Session session = { 0 }; |
| 671 | uint32_t ret_orig; |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 672 | pthread_t thr; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 673 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 674 | Do_ADBG_BeginSubCase(c, "%s", subcase); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 675 | { |
| 676 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 677 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 678 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 679 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 680 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 681 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 682 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, |
| 683 | TEEC_ORIGIN_TRUSTED_APP, |
| 684 | ret_orig); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 685 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 686 | op.params[0].value.a = timeout; |
| 687 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 688 | TEEC_NONE, |
| 689 | TEEC_NONE, TEEC_NONE); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 690 | if (cancel) { |
| 691 | (void)ADBG_EXPECT(c, 0, |
| 692 | pthread_create(&thr, NULL, |
| 693 | cancellation_thread, &op)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 694 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 695 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 696 | TEEC_ERROR_CANCEL, |
| 697 | TEEC_InvokeCommand(&session, |
| 698 | TA_OS_TEST_CMD_WAIT, |
| 699 | &op, |
| 700 | &ret_orig)); |
| 701 | } else |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 702 | |
| 703 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 704 | TEEC_InvokeCommand(&session, |
| 705 | TA_OS_TEST_CMD_WAIT, |
| 706 | &op, |
| 707 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 708 | if (cancel) |
| 709 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 710 | |
| 711 | TEEC_CloseSession(&session); |
| 712 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 713 | } |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 714 | Do_ADBG_EndSubCase(c, "%s", subcase); |
| 715 | } |
| 716 | |
| 717 | static void xtest_tee_test_1009(ADBG_Case_t *c) |
| 718 | { |
| 719 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false); |
| 720 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 721 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 722 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | static void xtest_tee_test_1010(ADBG_Case_t *c) |
| 726 | { |
| 727 | unsigned n; |
| 728 | |
| 729 | for (n = 1; n <= 5; n++) { |
| 730 | Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n); |
| 731 | xtest_tee_test_invalid_mem_access(c, n); |
| 732 | Do_ADBG_EndSubCase(c, "Invalid memory access %u", n); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | static void xtest_tee_test_1011(ADBG_Case_t *c) |
| 737 | { |
| 738 | TEEC_Session session = { 0 }; |
| 739 | uint32_t ret_orig; |
| 740 | struct xtest_crypto_session cs = { |
| 741 | c, &session, TA_RPC_CMD_CRYPT_SHA256, |
| 742 | TA_RPC_CMD_CRYPT_AES256ECB_ENC, |
| 743 | TA_RPC_CMD_CRYPT_AES256ECB_DEC |
| 744 | }; |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 745 | struct xtest_crypto_session cs_privmem = { |
| 746 | c, &session, |
| 747 | TA_RPC_CMD_CRYPT_PRIVMEM_SHA256, |
| 748 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC, |
| 749 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC |
| 750 | }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 751 | TEEC_UUID uuid = rpc_test_ta_uuid; |
| 752 | |
| 753 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 754 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 755 | return; |
| 756 | |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 757 | Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 758 | /* |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 759 | * Run the "complete crypto test suite" using TA-to-TA |
| 760 | * communication |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 761 | */ |
| 762 | xtest_crypto_test(&cs); |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 763 | Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory"); |
| 764 | |
| 765 | Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory"); |
| 766 | /* |
| 767 | * Run the "complete crypto test suite" using TA-to-TA |
| 768 | * communication via TA private memory. |
| 769 | */ |
| 770 | xtest_crypto_test(&cs_privmem); |
| 771 | Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory"); |
| 772 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 773 | TEEC_CloseSession(&session); |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Note that this test is failing when |
| 778 | * - running twice in a raw |
| 779 | * - and the user TA is statically linked |
| 780 | * This is because the counter is not reseted when opening the first session |
| 781 | * in case the TA is statically linked |
| 782 | */ |
| 783 | static void xtest_tee_test_1012(ADBG_Case_t *c) |
| 784 | { |
| 785 | TEEC_Session session1 = { 0 }; |
| 786 | TEEC_Session session2 = { 0 }; |
| 787 | uint32_t ret_orig; |
| 788 | TEEC_UUID uuid = sims_test_ta_uuid; |
| 789 | |
| 790 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Session"); |
| 791 | { |
| 792 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 793 | static const uint8_t in[] = { |
| 794 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 795 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 796 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 797 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 798 | }; |
| 799 | uint8_t out[32] = { 0 }; |
| 800 | int i; |
| 801 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 802 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 803 | xtest_teec_open_session(&session1, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 804 | &ret_orig))) |
| 805 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 806 | |
| 807 | op.params[0].value.a = 0; |
| 808 | op.params[1].tmpref.buffer = (void *)in; |
| 809 | op.params[1].tmpref.size = sizeof(in); |
| 810 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 811 | TEEC_MEMREF_TEMP_INPUT, |
| 812 | TEEC_NONE, TEEC_NONE); |
| 813 | |
| 814 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 815 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op, |
| 816 | &ret_orig)); |
| 817 | |
| 818 | for (i = 1; i < 1000; i++) { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 819 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 820 | xtest_teec_open_session(&session2, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 821 | &ret_orig))) |
| 822 | continue; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 823 | |
| 824 | op.params[0].value.a = 0; |
| 825 | op.params[1].tmpref.buffer = out; |
| 826 | op.params[1].tmpref.size = sizeof(out); |
| 827 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 828 | TEEC_MEMREF_TEMP_OUTPUT, |
| 829 | TEEC_NONE, TEEC_NONE); |
| 830 | |
| 831 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 832 | TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ, |
| 833 | &op, &ret_orig)); |
| 834 | |
| 835 | if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out, |
| 836 | sizeof(out))) { |
| 837 | Do_ADBG_Log("in:"); |
| 838 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 839 | Do_ADBG_Log("out:"); |
| 840 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 841 | } |
| 842 | |
| 843 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 844 | TEEC_NONE, TEEC_NONE, |
| 845 | TEEC_NONE); |
| 846 | |
| 847 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 848 | TEEC_InvokeCommand(&session1, |
| 849 | TA_SIMS_CMD_GET_COUNTER, |
| 850 | &op, &ret_orig)); |
| 851 | |
| 852 | (void)ADBG_EXPECT(c, 0, op.params[0].value.a); |
| 853 | |
| 854 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 855 | TEEC_InvokeCommand(&session2, |
| 856 | TA_SIMS_CMD_GET_COUNTER, &op, |
| 857 | &ret_orig)); |
| 858 | |
| 859 | (void)ADBG_EXPECT(c, i, op.params[0].value.a); |
| 860 | TEEC_CloseSession(&session2); |
| 861 | } |
| 862 | |
| 863 | memset(out, 0, sizeof(out)); |
| 864 | op.params[0].value.a = 0; |
| 865 | op.params[1].tmpref.buffer = out; |
| 866 | op.params[1].tmpref.size = sizeof(out); |
| 867 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 868 | TEEC_MEMREF_TEMP_OUTPUT, |
| 869 | TEEC_NONE, TEEC_NONE); |
| 870 | |
| 871 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 872 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op, |
| 873 | &ret_orig)); |
| 874 | |
| 875 | if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) { |
| 876 | Do_ADBG_Log("in:"); |
| 877 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 878 | Do_ADBG_Log("out:"); |
| 879 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 880 | } |
| 881 | |
| 882 | TEEC_CloseSession(&session1); |
| 883 | } |
| 884 | } |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 885 | |
| 886 | struct test_1013_thread_arg { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 887 | const TEEC_UUID *uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 888 | uint32_t cmd; |
| 889 | uint32_t repeat; |
| 890 | TEEC_SharedMemory *shm; |
| 891 | uint32_t error_orig; |
| 892 | TEEC_Result res; |
| 893 | uint32_t max_concurrency; |
| 894 | const uint8_t *in; |
| 895 | size_t in_len; |
| 896 | uint8_t *out; |
| 897 | size_t out_len; |
| 898 | }; |
| 899 | |
| 900 | static void *test_1013_thread(void *arg) |
| 901 | { |
| 902 | struct test_1013_thread_arg *a = arg; |
| 903 | TEEC_Session session = { 0 }; |
| 904 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 905 | uint8_t p2 = TEEC_NONE; |
| 906 | uint8_t p3 = TEEC_NONE; |
| 907 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 908 | a->res = xtest_teec_open_session(&session, a->uuid, NULL, |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 909 | &a->error_orig); |
| 910 | if (a->res != TEEC_SUCCESS) |
| 911 | return NULL; |
| 912 | |
| 913 | op.params[0].memref.parent = a->shm; |
| 914 | op.params[0].memref.size = a->shm->size; |
| 915 | op.params[0].memref.offset = 0; |
| 916 | op.params[1].value.a = a->repeat; |
| 917 | op.params[1].value.b = 0; |
| 918 | op.params[2].tmpref.buffer = (void *)a->in; |
| 919 | op.params[2].tmpref.size = a->in_len; |
| 920 | op.params[3].tmpref.buffer = a->out; |
| 921 | op.params[3].tmpref.size = a->out_len; |
| 922 | |
| 923 | if (a->in_len) |
| 924 | p2 = TEEC_MEMREF_TEMP_INPUT; |
| 925 | if (a->out_len) |
| 926 | p3 = TEEC_MEMREF_TEMP_OUTPUT; |
| 927 | |
| 928 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, |
| 929 | TEEC_VALUE_INOUT, p2, p3); |
| 930 | |
| 931 | a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig); |
| 932 | a->max_concurrency = op.params[1].value.b; |
| 933 | a->out_len = op.params[3].tmpref.size; |
| 934 | TEEC_CloseSession(&session); |
| 935 | return NULL; |
| 936 | } |
| 937 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 938 | #define NUM_THREADS 3 |
| 939 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 940 | static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency, |
| 941 | const TEEC_UUID *uuid) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 942 | { |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 943 | size_t num_threads = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 944 | size_t nt; |
| 945 | size_t n; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 946 | size_t repeat = 1000; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 947 | pthread_t thr[num_threads]; |
| 948 | TEEC_SharedMemory shm; |
| 949 | size_t max_concurrency; |
| 950 | struct test_1013_thread_arg arg[num_threads]; |
| 951 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 952 | static const uint8_t sha256_out[] = { |
| 953 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 954 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 955 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 956 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 957 | }; |
| 958 | uint8_t out[32] = { 0 }; |
| 959 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 960 | Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 961 | *mean_concurrency = 0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 962 | |
| 963 | memset(&shm, 0, sizeof(shm)); |
| 964 | shm.size = sizeof(struct ta_concurrent_shm); |
| 965 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 966 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 967 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 968 | return; |
| 969 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 970 | memset(shm.buffer, 0, shm.size); |
| 971 | memset(arg, 0, sizeof(arg)); |
| 972 | max_concurrency = 0; |
| 973 | nt = num_threads; |
| 974 | |
| 975 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 976 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 977 | arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 978 | arg[n].repeat = repeat * 10; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 979 | arg[n].shm = &shm; |
| 980 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 981 | test_1013_thread, arg + n))) |
| 982 | nt = n; /* break loop and start cleanup */ |
| 983 | } |
| 984 | |
| 985 | for (n = 0; n < nt; n++) { |
| 986 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 987 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); |
| 988 | if (arg[n].max_concurrency > max_concurrency) |
| 989 | max_concurrency = arg[n].max_concurrency; |
| 990 | } |
| 991 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 992 | /* |
| 993 | * Concurrency can be limited by several factors, for instance in a |
| 994 | * single CPU system it's dependent on the Preemtion Model used by |
| 995 | * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the |
| 996 | * best result there). |
| 997 | */ |
| 998 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0); |
| 999 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, num_threads); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1000 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1001 | Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1002 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1003 | Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1004 | memset(shm.buffer, 0, shm.size); |
| 1005 | memset(arg, 0, sizeof(arg)); |
| 1006 | max_concurrency = 0; |
| 1007 | nt = num_threads; |
| 1008 | |
| 1009 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1010 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1011 | arg[n].cmd = TA_CONCURRENT_CMD_SHA256; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1012 | arg[n].repeat = repeat; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1013 | arg[n].shm = &shm; |
| 1014 | arg[n].in = sha256_in; |
| 1015 | arg[n].in_len = sizeof(sha256_in); |
| 1016 | arg[n].out = out; |
| 1017 | arg[n].out_len = sizeof(out); |
| 1018 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1019 | test_1013_thread, arg + n))) |
| 1020 | nt = n; /* break loop and start cleanup */ |
| 1021 | } |
| 1022 | |
| 1023 | for (n = 0; n < nt; n++) { |
| 1024 | if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) && |
| 1025 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 1026 | ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out), |
| 1027 | arg[n].out, arg[n].out_len); |
| 1028 | if (arg[n].max_concurrency > max_concurrency) |
| 1029 | max_concurrency = arg[n].max_concurrency; |
| 1030 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1031 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1032 | Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1033 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1034 | *mean_concurrency /= 2.0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1035 | TEEC_ReleaseSharedMemory(&shm); |
| 1036 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1037 | |
| 1038 | static void xtest_tee_test_1013(ADBG_Case_t *c) |
| 1039 | { |
| 1040 | int i; |
| 1041 | double mean_concurrency; |
| 1042 | double concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1043 | int nb_loops = 24; |
Jens Wiklander | 6a9d15a | 2016-02-01 10:29:42 +0100 | [diff] [blame] | 1044 | |
| 1045 | if (level == 0) |
| 1046 | nb_loops /= 2; |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1047 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1048 | Do_ADBG_BeginSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1049 | mean_concurrency = 0; |
| 1050 | for (i = 0; i < nb_loops; i++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1051 | xtest_tee_test_1013_single(c, &concurrency, |
| 1052 | &concurrent_ta_uuid); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1053 | mean_concurrency += concurrency; |
| 1054 | } |
| 1055 | mean_concurrency /= nb_loops; |
| 1056 | |
| 1057 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1058 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1059 | Do_ADBG_EndSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1060 | |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1061 | #ifndef CFG_PAGED_USER_TA |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1062 | Do_ADBG_BeginSubCase(c, "Using large concurrency TA"); |
| 1063 | mean_concurrency = 0; |
| 1064 | for (i = 0; i < nb_loops; i++) { |
| 1065 | xtest_tee_test_1013_single(c, &concurrency, |
| 1066 | &concurrent_large_ta_uuid); |
| 1067 | mean_concurrency += concurrency; |
| 1068 | } |
| 1069 | mean_concurrency /= nb_loops; |
| 1070 | |
| 1071 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1072 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
| 1073 | Do_ADBG_EndSubCase(c, "Using large concurrency TA"); |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1074 | #endif |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1075 | } |