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> |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 17 | #include <stdlib.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 18 | #include <string.h> |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 19 | #include <sys/stat.h> |
| 20 | #include <sys/types.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 21 | #include <unistd.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 22 | |
| 23 | #include "xtest_test.h" |
| 24 | #include "xtest_helpers.h" |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 25 | #include <signed_hdr.h> |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame^] | 26 | #include <util.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 27 | |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 28 | #include <pta_invoke_tests.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 29 | #include <ta_crypt.h> |
| 30 | #include <ta_os_test.h> |
| 31 | #include <ta_create_fail_test.h> |
| 32 | #include <ta_rpc_test.h> |
| 33 | #include <ta_sims_test.h> |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 34 | #include <ta_concurrent.h> |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 35 | #include <sdp_basic.h> |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 36 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
| 37 | #include <pta_secstor_ta_mgmt.h> |
| 38 | #endif |
| 39 | |
| 40 | #ifndef MIN |
| 41 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 42 | #endif |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 43 | |
| 44 | static void xtest_tee_test_1001(ADBG_Case_t *Case_p); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 45 | static void xtest_tee_test_1002(ADBG_Case_t *Case_p); |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 46 | static void xtest_tee_test_1003(ADBG_Case_t *Case_p); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 47 | static void xtest_tee_test_1004(ADBG_Case_t *Case_p); |
| 48 | static void xtest_tee_test_1005(ADBG_Case_t *Case_p); |
| 49 | static void xtest_tee_test_1006(ADBG_Case_t *Case_p); |
| 50 | static void xtest_tee_test_1007(ADBG_Case_t *Case_p); |
| 51 | static void xtest_tee_test_1008(ADBG_Case_t *Case_p); |
| 52 | static void xtest_tee_test_1009(ADBG_Case_t *Case_p); |
| 53 | static void xtest_tee_test_1010(ADBG_Case_t *Case_p); |
| 54 | static void xtest_tee_test_1011(ADBG_Case_t *Case_p); |
| 55 | static void xtest_tee_test_1012(ADBG_Case_t *Case_p); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 56 | static void xtest_tee_test_1013(ADBG_Case_t *Case_p); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 57 | #ifdef CFG_SECURE_DATA_PATH |
| 58 | static void xtest_tee_test_1014(ADBG_Case_t *Case_p); |
| 59 | #endif |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 60 | static void xtest_tee_test_1015(ADBG_Case_t *Case_p); |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 61 | static void xtest_tee_test_1016(ADBG_Case_t *Case_p); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 62 | |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 63 | ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 64 | ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters"); |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 65 | ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003, |
| 66 | "Core internal read/write mutex"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 67 | ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA"); |
| 68 | ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions"); |
| 69 | ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006, |
| 70 | "Test Basic OS features"); |
| 71 | ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic"); |
| 72 | ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 73 | "TEE internal client API"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 74 | ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait"); |
| 75 | ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010, |
| 76 | "Invalid memory access"); |
| 77 | ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011, |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 78 | "Test TA-to-TA features with User Crypt TA"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 79 | ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 80 | "Test Single Instance Multi Session features with SIMS TA"); |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 81 | ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 82 | "Test concurency with concurrent TA"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 83 | #ifdef CFG_SECURE_DATA_PATH |
| 84 | ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014, |
| 85 | "Test secure data path against SDP TAs and pTAs"); |
| 86 | #endif |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 87 | ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015, |
| 88 | "FS hash-tree corner cases"); |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 89 | ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016, |
| 90 | "Test TA to TA transfers (in/out/inout memrefs on the stack)"); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 91 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 92 | struct xtest_crypto_session { |
| 93 | ADBG_Case_t *c; |
| 94 | TEEC_Session *session; |
| 95 | uint32_t cmd_id_sha256; |
| 96 | uint32_t cmd_id_aes256ecb_encrypt; |
| 97 | uint32_t cmd_id_aes256ecb_decrypt; |
| 98 | }; |
| 99 | |
| 100 | static void xtest_crypto_test(struct xtest_crypto_session *cs) |
| 101 | { |
| 102 | uint32_t ret_orig; |
| 103 | uint8_t crypt_out[16]; |
| 104 | uint8_t crypt_in[16] = { 22, 17 }; |
| 105 | |
| 106 | crypt_in[15] = 60; |
| 107 | |
| 108 | Do_ADBG_BeginSubCase(cs->c, "AES encrypt"); |
| 109 | { |
| 110 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 111 | |
| 112 | op.params[0].tmpref.buffer = crypt_in; |
| 113 | op.params[0].tmpref.size = sizeof(crypt_in); |
| 114 | op.params[1].tmpref.buffer = crypt_out; |
| 115 | op.params[1].tmpref.size = sizeof(crypt_out); |
| 116 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 117 | TEEC_MEMREF_TEMP_OUTPUT, |
| 118 | TEEC_NONE, TEEC_NONE); |
| 119 | |
| 120 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 121 | TEEC_InvokeCommand(cs->session, |
| 122 | cs-> |
| 123 | cmd_id_aes256ecb_encrypt, |
| 124 | &op, |
| 125 | &ret_orig)); |
| 126 | } |
| 127 | Do_ADBG_EndSubCase(cs->c, "AES encrypt"); |
| 128 | |
| 129 | Do_ADBG_BeginSubCase(cs->c, "AES decrypt"); |
| 130 | { |
| 131 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 132 | uint8_t out[16]; |
| 133 | |
| 134 | op.params[0].tmpref.buffer = crypt_out; |
| 135 | op.params[0].tmpref.size = sizeof(crypt_out); |
| 136 | op.params[1].tmpref.buffer = out; |
| 137 | op.params[1].tmpref.size = sizeof(out); |
| 138 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 139 | TEEC_MEMREF_TEMP_OUTPUT, |
| 140 | TEEC_NONE, TEEC_NONE); |
| 141 | |
| 142 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 143 | TEEC_InvokeCommand(cs->session, |
| 144 | cs-> |
| 145 | cmd_id_aes256ecb_decrypt, |
| 146 | &op, |
| 147 | &ret_orig)); |
| 148 | |
| 149 | if (!ADBG_EXPECT(cs->c, 0, |
| 150 | memcmp(crypt_in, out, sizeof(crypt_in)))) { |
| 151 | Do_ADBG_Log("crypt_in:"); |
| 152 | Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16); |
| 153 | Do_ADBG_Log("out:"); |
| 154 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 155 | } |
| 156 | } |
| 157 | Do_ADBG_EndSubCase(cs->c, "AES decrypt"); |
| 158 | |
| 159 | Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 160 | { |
| 161 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 162 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 163 | static const uint8_t sha256_out[] = { |
| 164 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 165 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 166 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 167 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 168 | }; |
| 169 | uint8_t out[32] = { 0 }; |
| 170 | |
| 171 | op.params[0].tmpref.buffer = (void *)sha256_in; |
| 172 | op.params[0].tmpref.size = sizeof(sha256_in); |
| 173 | op.params[1].tmpref.buffer = out; |
| 174 | op.params[1].tmpref.size = sizeof(out); |
| 175 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 176 | TEEC_MEMREF_TEMP_OUTPUT, |
| 177 | TEEC_NONE, TEEC_NONE); |
| 178 | |
| 179 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 180 | TEEC_InvokeCommand(cs->session, |
| 181 | cs-> |
| 182 | cmd_id_sha256, |
| 183 | &op, |
| 184 | &ret_orig)); |
| 185 | |
| 186 | if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out, |
| 187 | sizeof(sha256_out)))) { |
| 188 | Do_ADBG_Log("sha256_out:"); |
| 189 | Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16); |
| 190 | Do_ADBG_Log("out:"); |
| 191 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 192 | } |
| 193 | } |
| 194 | Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 195 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 196 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 197 | { |
| 198 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 199 | static const uint8_t in[] = { |
| 200 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 201 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 202 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 203 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 204 | }; |
| 205 | static const uint8_t exp_out[] = { |
| 206 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 207 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 208 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 209 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 210 | }; |
| 211 | uint8_t out[sizeof(exp_out)]; |
| 212 | |
| 213 | op.params[0].tmpref.buffer = (void *)in; |
| 214 | op.params[0].tmpref.size = sizeof(in); |
| 215 | op.params[1].tmpref.buffer = out; |
| 216 | op.params[1].tmpref.size = sizeof(out); |
| 217 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 218 | TEEC_MEMREF_TEMP_OUTPUT, |
| 219 | TEEC_NONE, TEEC_NONE); |
| 220 | |
| 221 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 222 | TEEC_InvokeCommand(cs->session, |
| 223 | cs-> |
| 224 | cmd_id_aes256ecb_encrypt, |
| 225 | &op, |
| 226 | &ret_orig)); |
| 227 | |
| 228 | if (!ADBG_EXPECT(cs->c, 0, |
| 229 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 230 | Do_ADBG_Log("exp_out:"); |
| 231 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 232 | Do_ADBG_Log("out:"); |
| 233 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 234 | } |
| 235 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 236 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 237 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 238 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 239 | { |
| 240 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 241 | static const uint8_t in[] = { |
| 242 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 243 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 244 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 245 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 246 | }; |
| 247 | static const uint8_t exp_out[] = { |
| 248 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 249 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 250 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 251 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 252 | }; |
| 253 | uint8_t out[sizeof(exp_out)]; |
| 254 | |
| 255 | op.params[0].tmpref.buffer = (void *)in; |
| 256 | op.params[0].tmpref.size = sizeof(in); |
| 257 | op.params[1].tmpref.buffer = out; |
| 258 | op.params[1].tmpref.size = sizeof(out); |
| 259 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 260 | TEEC_MEMREF_TEMP_OUTPUT, |
| 261 | TEEC_NONE, TEEC_NONE); |
| 262 | |
| 263 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 264 | TEEC_InvokeCommand(cs->session, |
| 265 | cs-> |
| 266 | cmd_id_aes256ecb_decrypt, |
| 267 | &op, |
| 268 | &ret_orig)); |
| 269 | |
| 270 | if (!ADBG_EXPECT(cs->c, 0, |
| 271 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 272 | Do_ADBG_Log("exp_out:"); |
| 273 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 274 | Do_ADBG_Log("out:"); |
| 275 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 276 | } |
| 277 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 278 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static void xtest_tee_test_1001(ADBG_Case_t *c) |
| 282 | { |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 283 | TEEC_Result res; |
| 284 | TEEC_Session session = { 0 }; |
| 285 | uint32_t ret_orig; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 286 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 287 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 288 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 289 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 290 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 291 | Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found"); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 292 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 293 | } |
| 294 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 295 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 296 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 297 | &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig)); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 298 | TEEC_CloseSession(&session); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 301 | static void xtest_tee_test_1002(ADBG_Case_t *c) |
| 302 | { |
| 303 | TEEC_Result res; |
| 304 | TEEC_Session session = { 0 }; |
| 305 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 306 | uint32_t ret_orig; |
| 307 | uint8_t buf[16 * 1024]; |
| 308 | uint8_t exp_sum = 0; |
| 309 | size_t n; |
| 310 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 311 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 312 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 313 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 314 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 315 | Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 316 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 317 | } |
| 318 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 319 | |
| 320 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, |
| 321 | TEEC_NONE, TEEC_NONE); |
| 322 | op.params[0].tmpref.size = sizeof(buf); |
| 323 | op.params[0].tmpref.buffer = buf; |
| 324 | |
| 325 | for (n = 0; n < sizeof(buf); n++) |
| 326 | buf[n] = n + 1; |
| 327 | for (n = 0; n < sizeof(buf); n++) |
| 328 | exp_sum += buf[n]; |
| 329 | |
| 330 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
| 331 | &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig))) |
| 332 | goto out; |
| 333 | |
| 334 | ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]); |
| 335 | out: |
| 336 | TEEC_CloseSession(&session); |
| 337 | } |
| 338 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 339 | struct test_1003_arg { |
| 340 | uint32_t test_type; |
| 341 | size_t repeat; |
| 342 | size_t max_before_lockers; |
| 343 | size_t max_during_lockers; |
| 344 | size_t before_lockers; |
| 345 | size_t during_lockers; |
| 346 | TEEC_Result res; |
| 347 | uint32_t error_orig; |
| 348 | }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 349 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 350 | static void *test_1003_thread(void *arg) |
| 351 | { |
| 352 | struct test_1003_arg *a = arg; |
| 353 | TEEC_Session session = { 0 }; |
| 354 | size_t rounds = 64 * 1024; |
| 355 | size_t n; |
| 356 | |
| 357 | a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, |
| 358 | NULL, &a->error_orig); |
| 359 | if (a->res != TEEC_SUCCESS) |
| 360 | return NULL; |
| 361 | |
| 362 | for (n = 0; n < a->repeat; n++) { |
| 363 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 364 | |
| 365 | op.params[0].value.a = a->test_type; |
| 366 | op.params[0].value.b = rounds; |
| 367 | |
| 368 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 369 | TEEC_VALUE_OUTPUT, |
| 370 | TEEC_NONE, TEEC_NONE); |
| 371 | a->res = TEEC_InvokeCommand(&session, |
| 372 | PTA_INVOKE_TESTS_CMD_MUTEX, |
| 373 | &op, &a->error_orig); |
| 374 | if (a->test_type == PTA_MUTEX_TEST_WRITER && |
| 375 | op.params[1].value.b != 1) { |
| 376 | Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b); |
| 377 | a->res = TEEC_ERROR_BAD_STATE; |
| 378 | a->error_orig = 42; |
| 379 | break; |
| 380 | } |
| 381 | |
| 382 | if (a->test_type == PTA_MUTEX_TEST_READER) { |
| 383 | if (op.params[1].value.a > a->max_before_lockers) |
| 384 | a->max_before_lockers = op.params[1].value.a; |
| 385 | |
| 386 | if (op.params[1].value.b > a->max_during_lockers) |
| 387 | a->max_during_lockers = op.params[1].value.b; |
| 388 | |
| 389 | a->before_lockers += op.params[1].value.a; |
| 390 | a->during_lockers += op.params[1].value.b; |
| 391 | } |
| 392 | } |
| 393 | TEEC_CloseSession(&session); |
| 394 | |
| 395 | return NULL; |
| 396 | } |
| 397 | |
| 398 | static void xtest_tee_test_1003(ADBG_Case_t *c) |
| 399 | { |
| 400 | size_t num_threads = 3 * 2; |
| 401 | TEEC_Result res; |
| 402 | TEEC_Session session = { 0 }; |
| 403 | uint32_t ret_orig; |
| 404 | size_t repeat = 20; |
| 405 | pthread_t thr[num_threads]; |
| 406 | struct test_1003_arg arg[num_threads]; |
| 407 | size_t max_read_concurrency = 0; |
| 408 | size_t max_read_waiters = 0; |
| 409 | size_t num_concurrent_read_lockers = 0; |
| 410 | size_t num_concurrent_read_waiters = 0; |
| 411 | size_t n; |
| 412 | size_t nt = num_threads; |
| 413 | double mean_read_concurrency; |
| 414 | double mean_read_waiters; |
| 415 | size_t num_writers = 0; |
| 416 | size_t num_readers = 0; |
| 417 | |
| 418 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 419 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 420 | &ret_orig); |
| 421 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 422 | Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found"); |
| 423 | return; |
| 424 | } |
| 425 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 426 | TEEC_CloseSession(&session); |
| 427 | |
| 428 | memset(arg, 0, sizeof(arg)); |
| 429 | |
| 430 | for (n = 0; n < nt; n++) { |
| 431 | if (n % 3) { |
| 432 | arg[n].test_type = PTA_MUTEX_TEST_READER; |
| 433 | num_readers++; |
| 434 | } else { |
| 435 | arg[n].test_type = PTA_MUTEX_TEST_WRITER; |
| 436 | num_writers++; |
| 437 | } |
| 438 | arg[n].repeat = repeat; |
| 439 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 440 | test_1003_thread, arg + n))) |
| 441 | nt = n; /* break loop and start cleanup */ |
| 442 | } |
| 443 | |
| 444 | for (n = 0; n < nt; n++) { |
| 445 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 446 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 447 | Do_ADBG_Log("error origin %" PRIu32, |
| 448 | arg[n].error_orig); |
| 449 | if (arg[n].test_type == PTA_MUTEX_TEST_READER) { |
| 450 | if (arg[n].max_during_lockers > max_read_concurrency) |
| 451 | max_read_concurrency = |
| 452 | arg[n].max_during_lockers; |
| 453 | |
| 454 | if (arg[n].max_before_lockers > max_read_waiters) |
| 455 | max_read_waiters = arg[n].max_before_lockers; |
| 456 | |
| 457 | num_concurrent_read_lockers += arg[n].during_lockers; |
| 458 | num_concurrent_read_waiters += arg[n].before_lockers; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | mean_read_concurrency = (double)num_concurrent_read_lockers / |
| 463 | (double)(repeat * num_readers); |
| 464 | mean_read_waiters = (double)num_concurrent_read_waiters / |
| 465 | (double)(repeat * num_readers); |
| 466 | |
| 467 | Do_ADBG_Log(" Number of parallel threads: %zu (%zu writers and %zu readers)", |
| 468 | num_threads, num_writers, num_readers); |
| 469 | Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency); |
| 470 | Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters); |
| 471 | Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency); |
| 472 | Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters); |
| 473 | } |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 474 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 475 | static void xtest_tee_test_1004(ADBG_Case_t *c) |
| 476 | { |
| 477 | TEEC_Session session = { 0 }; |
| 478 | uint32_t ret_orig; |
| 479 | struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256, |
| 480 | TA_CRYPT_CMD_AES256ECB_ENC, |
| 481 | TA_CRYPT_CMD_AES256ECB_DEC }; |
| 482 | |
| 483 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session( |
| 484 | &session, &crypt_user_ta_uuid, |
| 485 | NULL, &ret_orig))) |
| 486 | return; |
| 487 | |
| 488 | /* Run the "complete crypto test suite" */ |
| 489 | xtest_crypto_test(&cs); |
| 490 | |
| 491 | TEEC_CloseSession(&session); |
| 492 | } |
| 493 | |
| 494 | #ifndef TEEC_ERROR_TARGET_DEAD |
| 495 | /* To be removed when we have TEEC_ERROR_TARGET_DEAD from tee_client_api.h */ |
| 496 | #define TEEC_ERROR_TARGET_DEAD 0xFFFF3024 |
| 497 | #endif |
| 498 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame^] | 499 | static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, unsigned int n) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 500 | { |
| 501 | TEEC_Session session = { 0 }; |
| 502 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 503 | uint32_t ret_orig; |
| 504 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 505 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 506 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 507 | &ret_orig))) |
| 508 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 509 | |
| 510 | op.params[0].value.a = n; |
| 511 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 512 | TEEC_NONE); |
| 513 | |
| 514 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 515 | TEEC_ERROR_TARGET_DEAD, |
| 516 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 517 | &ret_orig)); |
| 518 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 519 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 520 | TEEC_ERROR_TARGET_DEAD, |
| 521 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 522 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 523 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 524 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 525 | |
| 526 | TEEC_CloseSession(&session); |
| 527 | } |
| 528 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame^] | 529 | static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n, |
| 530 | size_t size) |
| 531 | { |
| 532 | TEEC_Session session = { 0 }; |
| 533 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 534 | uint32_t ret_orig; |
| 535 | TEEC_SharedMemory shm; |
| 536 | |
| 537 | memset(&shm, 0, sizeof(shm)); |
| 538 | shm.size = size; |
| 539 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 540 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 541 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 542 | return; |
| 543 | |
| 544 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 545 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 546 | &ret_orig))) |
| 547 | return; |
| 548 | |
| 549 | op.params[0].value.a = (uint32_t)n; |
| 550 | op.params[1].memref.parent = &shm; |
| 551 | op.params[1].memref.size = size; |
| 552 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_MEMREF_WHOLE, |
| 553 | TEEC_NONE, TEEC_NONE); |
| 554 | |
| 555 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 556 | TEEC_ERROR_TARGET_DEAD, |
| 557 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 558 | &ret_orig)); |
| 559 | |
| 560 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 561 | TEEC_ERROR_TARGET_DEAD, |
| 562 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 563 | &ret_orig)); |
| 564 | |
| 565 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 566 | |
| 567 | TEEC_CloseSession(&session); |
| 568 | } |
| 569 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 570 | static void xtest_tee_test_1005(ADBG_Case_t *c) |
| 571 | { |
| 572 | uint32_t ret_orig; |
| 573 | #define MAX_SESSIONS 3 |
| 574 | TEEC_Session sessions[MAX_SESSIONS]; |
| 575 | int i; |
| 576 | |
| 577 | for (i = 0; i < MAX_SESSIONS; i++) { |
| 578 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jens Wiklander | eb6bce7 | 2016-09-23 11:37:33 +0200 | [diff] [blame] | 579 | xtest_teec_open_session(&sessions[i], |
| 580 | &concurrent_ta_uuid, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 581 | NULL, &ret_orig))) |
| 582 | break; |
| 583 | } |
| 584 | |
| 585 | for (; --i >= 0; ) |
| 586 | TEEC_CloseSession(&sessions[i]); |
| 587 | } |
| 588 | |
| 589 | static void xtest_tee_test_1006(ADBG_Case_t *c) |
| 590 | { |
| 591 | TEEC_Session session = { 0 }; |
| 592 | uint32_t ret_orig; |
| 593 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 594 | uint8_t buf[32]; |
| 595 | |
| 596 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 597 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 598 | &ret_orig))) |
| 599 | return; |
| 600 | |
| 601 | op.params[0].tmpref.buffer = buf; |
| 602 | op.params[0].tmpref.size = sizeof(buf); |
| 603 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 604 | TEEC_NONE, TEEC_NONE); |
| 605 | |
| 606 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 607 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op, |
| 608 | &ret_orig)); |
| 609 | |
| 610 | TEEC_CloseSession(&session); |
| 611 | } |
| 612 | |
| 613 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 614 | { |
| 615 | TEEC_Session session = { 0 }; |
| 616 | uint32_t ret_orig; |
| 617 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 618 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 619 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 620 | &ret_orig))) |
| 621 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 622 | |
| 623 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 624 | TEEC_ERROR_TARGET_DEAD, |
| 625 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL, |
| 626 | &ret_orig)); |
| 627 | |
| 628 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 629 | |
| 630 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 631 | TEEC_ERROR_TARGET_DEAD, |
| 632 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL, |
| 633 | &ret_orig)); |
| 634 | |
| 635 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 636 | |
| 637 | TEEC_CloseSession(&session); |
| 638 | } |
| 639 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 640 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 641 | #ifndef TA_DIR |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 642 | # ifdef __ANDROID__ |
| 643 | #define TA_DIR "/system/lib/optee_armtz" |
| 644 | # else |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 645 | #define TA_DIR "/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 646 | # endif |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 647 | #endif |
| 648 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 649 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode) |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 650 | { |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 651 | char buf[PATH_MAX]; |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 652 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 653 | snprintf(buf, sizeof(buf), |
Jens Wiklander | 6203b87 | 2016-12-08 19:18:29 +0100 | [diff] [blame] | 654 | "%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta", |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 655 | TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 656 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 657 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 658 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 659 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 660 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 661 | return fopen(buf, mode); |
| 662 | } |
| 663 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 664 | static bool load_corrupt_ta(ADBG_Case_t *c, size_t offs, uint8_t mask) |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 665 | { |
| 666 | TEEC_Session session = { 0 }; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 667 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 668 | TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 669 | TEEC_Result res; |
| 670 | uint32_t ret_orig; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 671 | FILE *f = NULL; |
| 672 | bool r = false; |
| 673 | uint8_t *buf = NULL; |
| 674 | size_t sz; |
| 675 | size_t fread_res; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 676 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 677 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 678 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 679 | goto out; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 680 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 681 | f = open_ta_file(&create_fail_test_ta_uuid, "rb"); |
| 682 | if (!ADBG_EXPECT_NOT_NULL(c, f)) |
| 683 | goto out; |
| 684 | if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END))) |
| 685 | goto out; |
| 686 | sz = ftell(f); |
| 687 | rewind(f); |
| 688 | |
| 689 | buf = malloc(sz); |
| 690 | if (!ADBG_EXPECT_NOT_NULL(c, buf)) |
| 691 | goto out; |
| 692 | |
| 693 | fread_res = fread(buf, 1, sz, f); |
| 694 | if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz)) |
| 695 | goto out; |
| 696 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 697 | fclose(f); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 698 | f = NULL; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 699 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 700 | buf[MIN(offs, sz)] ^= mask; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 701 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 702 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 703 | TEEC_NONE, TEEC_NONE); |
| 704 | op.params[0].tmpref.buffer = buf; |
| 705 | op.params[0].tmpref.size = sz; |
| 706 | |
| 707 | res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op, |
| 708 | &ret_orig); |
| 709 | r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res); |
| 710 | out: |
| 711 | free(buf); |
| 712 | if (f) |
| 713 | fclose(f); |
| 714 | TEEC_CloseSession(&session); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 715 | return r; |
| 716 | } |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 717 | #endif /*CFG_SECSTOR_TA_MGMT_PTA*/ |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 718 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 719 | static void xtest_tee_test_1008(ADBG_Case_t *c) |
| 720 | { |
| 721 | TEEC_Session session = { 0 }; |
| 722 | TEEC_Session session_crypt = { 0 }; |
| 723 | uint32_t ret_orig; |
| 724 | |
| 725 | Do_ADBG_BeginSubCase(c, "Invoke command"); |
| 726 | { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 727 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 728 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 729 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 730 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 731 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 732 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT, |
| 733 | NULL, &ret_orig)); |
| 734 | TEEC_CloseSession(&session); |
| 735 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 736 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 737 | } |
| 738 | Do_ADBG_EndSubCase(c, "Invoke command"); |
| 739 | |
| 740 | Do_ADBG_BeginSubCase(c, "Invoke command with timeout"); |
| 741 | { |
| 742 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 743 | |
| 744 | op.params[0].value.a = 2000; |
| 745 | op.paramTypes = TEEC_PARAM_TYPES( |
| 746 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 747 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 748 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 749 | xtest_teec_open_session(&session, |
| 750 | &os_test_ta_uuid, |
| 751 | NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 752 | &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 753 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 754 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 755 | TEEC_InvokeCommand(&session, |
| 756 | TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT, |
| 757 | &op, &ret_orig)); |
| 758 | TEEC_CloseSession(&session); |
| 759 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 760 | } |
| 761 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 762 | |
| 763 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 764 | { |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 765 | size_t n; |
| 766 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 767 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 768 | xtest_teec_open_session(&session_crypt, |
| 769 | &create_fail_test_ta_uuid, NULL, |
| 770 | &ret_orig)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 771 | /* |
| 772 | * Run this several times to see that there's no memory leakage. |
| 773 | */ |
| 774 | for (n = 0; n < 100; n++) { |
| 775 | Do_ADBG_Log("n = %zu", n); |
| 776 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 777 | xtest_teec_open_session(&session_crypt, |
| 778 | &create_fail_test_ta_uuid, |
| 779 | NULL, &ret_orig)); |
| 780 | } |
| 781 | } |
| 782 | Do_ADBG_EndSubCase(c, "Create session fail"); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 783 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 784 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 785 | Do_ADBG_BeginSubCase(c, "Load corrupt TA"); |
| 786 | ADBG_EXPECT_TRUE(c, |
| 787 | load_corrupt_ta(c, offsetof(struct shdr, magic), 1)); |
| 788 | ADBG_EXPECT_TRUE(c, |
| 789 | load_corrupt_ta(c, offsetof(struct shdr, img_type), 1)); |
| 790 | ADBG_EXPECT_TRUE(c, |
| 791 | load_corrupt_ta(c, offsetof(struct shdr, img_size), 1)); |
| 792 | ADBG_EXPECT_TRUE(c, |
| 793 | load_corrupt_ta(c, offsetof(struct shdr, algo), 1)); |
| 794 | ADBG_EXPECT_TRUE(c, |
| 795 | load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1)); |
| 796 | ADBG_EXPECT_TRUE(c, |
| 797 | load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1)); |
| 798 | ADBG_EXPECT_TRUE(c, |
| 799 | load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */ |
| 800 | ADBG_EXPECT_TRUE(c, |
| 801 | load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */ |
| 802 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */ |
| 803 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 30000, 1)); /* payload */ |
| 804 | Do_ADBG_EndSubCase(c, "Load corrupt TA"); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 805 | #endif /*CFG_SECSTOR_TA_MGMT_PTA*/ |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 806 | } |
| 807 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 808 | static void *cancellation_thread(void *arg) |
| 809 | { |
| 810 | /* |
| 811 | * Sleep 0.5 seconds before cancellation to make sure that the other |
| 812 | * thread is in RPC_WAIT. |
| 813 | */ |
| 814 | (void)usleep(500000); |
| 815 | TEEC_RequestCancellation(arg); |
| 816 | return NULL; |
| 817 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 818 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 819 | static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase, |
| 820 | uint32_t timeout, bool cancel) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 821 | { |
| 822 | TEEC_Session session = { 0 }; |
| 823 | uint32_t ret_orig; |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 824 | pthread_t thr; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 825 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 826 | Do_ADBG_BeginSubCase(c, "%s", subcase); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 827 | { |
| 828 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 829 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 830 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 831 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 832 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 833 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 834 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, |
| 835 | TEEC_ORIGIN_TRUSTED_APP, |
| 836 | ret_orig); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 837 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 838 | op.params[0].value.a = timeout; |
| 839 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 840 | TEEC_NONE, |
| 841 | TEEC_NONE, TEEC_NONE); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 842 | if (cancel) { |
| 843 | (void)ADBG_EXPECT(c, 0, |
| 844 | pthread_create(&thr, NULL, |
| 845 | cancellation_thread, &op)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 846 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 847 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 848 | TEEC_ERROR_CANCEL, |
| 849 | TEEC_InvokeCommand(&session, |
| 850 | TA_OS_TEST_CMD_WAIT, |
| 851 | &op, |
| 852 | &ret_orig)); |
| 853 | } else |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 854 | |
| 855 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 856 | TEEC_InvokeCommand(&session, |
| 857 | TA_OS_TEST_CMD_WAIT, |
| 858 | &op, |
| 859 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 860 | if (cancel) |
| 861 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 862 | |
| 863 | TEEC_CloseSession(&session); |
| 864 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 865 | } |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 866 | Do_ADBG_EndSubCase(c, "%s", subcase); |
| 867 | } |
| 868 | |
| 869 | static void xtest_tee_test_1009(ADBG_Case_t *c) |
| 870 | { |
| 871 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false); |
| 872 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 873 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 874 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static void xtest_tee_test_1010(ADBG_Case_t *c) |
| 878 | { |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame^] | 879 | unsigned int n; |
| 880 | unsigned int idx; |
| 881 | size_t memref_sz[] = { 1024, 65536 }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 882 | |
| 883 | for (n = 1; n <= 5; n++) { |
| 884 | Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n); |
| 885 | xtest_tee_test_invalid_mem_access(c, n); |
| 886 | Do_ADBG_EndSubCase(c, "Invalid memory access %u", n); |
| 887 | } |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame^] | 888 | |
| 889 | for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) { |
| 890 | for (n = 1; n <= 5; n++) { |
| 891 | Do_ADBG_BeginSubCase(c, |
| 892 | "Invalid memory access %u with %d bytes memref", |
| 893 | n, memref_sz[idx]); |
| 894 | xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]); |
| 895 | Do_ADBG_EndSubCase(c, |
| 896 | "Invalid memory access %u with %d bytes memref", |
| 897 | n, memref_sz[idx]); |
| 898 | } |
| 899 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | static void xtest_tee_test_1011(ADBG_Case_t *c) |
| 903 | { |
| 904 | TEEC_Session session = { 0 }; |
| 905 | uint32_t ret_orig; |
| 906 | struct xtest_crypto_session cs = { |
| 907 | c, &session, TA_RPC_CMD_CRYPT_SHA256, |
| 908 | TA_RPC_CMD_CRYPT_AES256ECB_ENC, |
| 909 | TA_RPC_CMD_CRYPT_AES256ECB_DEC |
| 910 | }; |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 911 | struct xtest_crypto_session cs_privmem = { |
| 912 | c, &session, |
| 913 | TA_RPC_CMD_CRYPT_PRIVMEM_SHA256, |
| 914 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC, |
| 915 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC |
| 916 | }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 917 | TEEC_UUID uuid = rpc_test_ta_uuid; |
| 918 | |
| 919 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 920 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 921 | return; |
| 922 | |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 923 | Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 924 | /* |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 925 | * Run the "complete crypto test suite" using TA-to-TA |
| 926 | * communication |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 927 | */ |
| 928 | xtest_crypto_test(&cs); |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 929 | Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory"); |
| 930 | |
| 931 | Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory"); |
| 932 | /* |
| 933 | * Run the "complete crypto test suite" using TA-to-TA |
| 934 | * communication via TA private memory. |
| 935 | */ |
| 936 | xtest_crypto_test(&cs_privmem); |
| 937 | Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory"); |
| 938 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 939 | TEEC_CloseSession(&session); |
| 940 | } |
| 941 | |
| 942 | /* |
| 943 | * Note that this test is failing when |
| 944 | * - running twice in a raw |
| 945 | * - and the user TA is statically linked |
| 946 | * This is because the counter is not reseted when opening the first session |
| 947 | * in case the TA is statically linked |
| 948 | */ |
| 949 | static void xtest_tee_test_1012(ADBG_Case_t *c) |
| 950 | { |
| 951 | TEEC_Session session1 = { 0 }; |
| 952 | TEEC_Session session2 = { 0 }; |
| 953 | uint32_t ret_orig; |
| 954 | TEEC_UUID uuid = sims_test_ta_uuid; |
| 955 | |
| 956 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Session"); |
| 957 | { |
| 958 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 959 | static const uint8_t in[] = { |
| 960 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 961 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 962 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 963 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 964 | }; |
| 965 | uint8_t out[32] = { 0 }; |
| 966 | int i; |
| 967 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 968 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 969 | xtest_teec_open_session(&session1, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 970 | &ret_orig))) |
| 971 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 972 | |
| 973 | op.params[0].value.a = 0; |
| 974 | op.params[1].tmpref.buffer = (void *)in; |
| 975 | op.params[1].tmpref.size = sizeof(in); |
| 976 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 977 | TEEC_MEMREF_TEMP_INPUT, |
| 978 | TEEC_NONE, TEEC_NONE); |
| 979 | |
| 980 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 981 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op, |
| 982 | &ret_orig)); |
| 983 | |
Jerome Forissier | 3cc0a42 | 2017-12-14 09:53:24 +0100 | [diff] [blame] | 984 | for (i = 1; i < 3; i++) { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 985 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 986 | xtest_teec_open_session(&session2, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 987 | &ret_orig))) |
| 988 | continue; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 989 | |
| 990 | op.params[0].value.a = 0; |
| 991 | op.params[1].tmpref.buffer = out; |
| 992 | op.params[1].tmpref.size = sizeof(out); |
| 993 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 994 | TEEC_MEMREF_TEMP_OUTPUT, |
| 995 | TEEC_NONE, TEEC_NONE); |
| 996 | |
| 997 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 998 | TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ, |
| 999 | &op, &ret_orig)); |
| 1000 | |
| 1001 | if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out, |
| 1002 | sizeof(out))) { |
| 1003 | Do_ADBG_Log("in:"); |
| 1004 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1005 | Do_ADBG_Log("out:"); |
| 1006 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1007 | } |
| 1008 | |
| 1009 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 1010 | TEEC_NONE, TEEC_NONE, |
| 1011 | TEEC_NONE); |
| 1012 | |
| 1013 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1014 | TEEC_InvokeCommand(&session1, |
| 1015 | TA_SIMS_CMD_GET_COUNTER, |
| 1016 | &op, &ret_orig)); |
| 1017 | |
| 1018 | (void)ADBG_EXPECT(c, 0, op.params[0].value.a); |
| 1019 | |
| 1020 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1021 | TEEC_InvokeCommand(&session2, |
| 1022 | TA_SIMS_CMD_GET_COUNTER, &op, |
| 1023 | &ret_orig)); |
| 1024 | |
| 1025 | (void)ADBG_EXPECT(c, i, op.params[0].value.a); |
| 1026 | TEEC_CloseSession(&session2); |
| 1027 | } |
| 1028 | |
| 1029 | memset(out, 0, sizeof(out)); |
| 1030 | op.params[0].value.a = 0; |
| 1031 | op.params[1].tmpref.buffer = out; |
| 1032 | op.params[1].tmpref.size = sizeof(out); |
| 1033 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 1034 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1035 | TEEC_NONE, TEEC_NONE); |
| 1036 | |
| 1037 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1038 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op, |
| 1039 | &ret_orig)); |
| 1040 | |
| 1041 | if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) { |
| 1042 | Do_ADBG_Log("in:"); |
| 1043 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1044 | Do_ADBG_Log("out:"); |
| 1045 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1046 | } |
| 1047 | |
| 1048 | TEEC_CloseSession(&session1); |
| 1049 | } |
| 1050 | } |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1051 | |
| 1052 | struct test_1013_thread_arg { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1053 | const TEEC_UUID *uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1054 | uint32_t cmd; |
| 1055 | uint32_t repeat; |
| 1056 | TEEC_SharedMemory *shm; |
| 1057 | uint32_t error_orig; |
| 1058 | TEEC_Result res; |
| 1059 | uint32_t max_concurrency; |
| 1060 | const uint8_t *in; |
| 1061 | size_t in_len; |
| 1062 | uint8_t *out; |
| 1063 | size_t out_len; |
| 1064 | }; |
| 1065 | |
| 1066 | static void *test_1013_thread(void *arg) |
| 1067 | { |
| 1068 | struct test_1013_thread_arg *a = arg; |
| 1069 | TEEC_Session session = { 0 }; |
| 1070 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1071 | uint8_t p2 = TEEC_NONE; |
| 1072 | uint8_t p3 = TEEC_NONE; |
| 1073 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1074 | a->res = xtest_teec_open_session(&session, a->uuid, NULL, |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1075 | &a->error_orig); |
| 1076 | if (a->res != TEEC_SUCCESS) |
| 1077 | return NULL; |
| 1078 | |
| 1079 | op.params[0].memref.parent = a->shm; |
| 1080 | op.params[0].memref.size = a->shm->size; |
| 1081 | op.params[0].memref.offset = 0; |
| 1082 | op.params[1].value.a = a->repeat; |
| 1083 | op.params[1].value.b = 0; |
| 1084 | op.params[2].tmpref.buffer = (void *)a->in; |
| 1085 | op.params[2].tmpref.size = a->in_len; |
| 1086 | op.params[3].tmpref.buffer = a->out; |
| 1087 | op.params[3].tmpref.size = a->out_len; |
| 1088 | |
| 1089 | if (a->in_len) |
| 1090 | p2 = TEEC_MEMREF_TEMP_INPUT; |
| 1091 | if (a->out_len) |
| 1092 | p3 = TEEC_MEMREF_TEMP_OUTPUT; |
| 1093 | |
| 1094 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, |
| 1095 | TEEC_VALUE_INOUT, p2, p3); |
| 1096 | |
| 1097 | a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig); |
| 1098 | a->max_concurrency = op.params[1].value.b; |
| 1099 | a->out_len = op.params[3].tmpref.size; |
| 1100 | TEEC_CloseSession(&session); |
| 1101 | return NULL; |
| 1102 | } |
| 1103 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1104 | #define NUM_THREADS 3 |
| 1105 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1106 | static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency, |
| 1107 | const TEEC_UUID *uuid) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1108 | { |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1109 | size_t num_threads = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1110 | size_t nt; |
| 1111 | size_t n; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1112 | size_t repeat = 1000; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1113 | pthread_t thr[num_threads]; |
| 1114 | TEEC_SharedMemory shm; |
| 1115 | size_t max_concurrency; |
| 1116 | struct test_1013_thread_arg arg[num_threads]; |
| 1117 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 1118 | static const uint8_t sha256_out[] = { |
| 1119 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 1120 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 1121 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 1122 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 1123 | }; |
| 1124 | uint8_t out[32] = { 0 }; |
| 1125 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1126 | Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1127 | *mean_concurrency = 0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1128 | |
| 1129 | memset(&shm, 0, sizeof(shm)); |
| 1130 | shm.size = sizeof(struct ta_concurrent_shm); |
| 1131 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1132 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1133 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1134 | return; |
| 1135 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1136 | memset(shm.buffer, 0, shm.size); |
| 1137 | memset(arg, 0, sizeof(arg)); |
| 1138 | max_concurrency = 0; |
| 1139 | nt = num_threads; |
| 1140 | |
| 1141 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1142 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1143 | arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1144 | arg[n].repeat = repeat * 10; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1145 | arg[n].shm = &shm; |
| 1146 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1147 | test_1013_thread, arg + n))) |
| 1148 | nt = n; /* break loop and start cleanup */ |
| 1149 | } |
| 1150 | |
| 1151 | for (n = 0; n < nt; n++) { |
| 1152 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 1153 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); |
| 1154 | if (arg[n].max_concurrency > max_concurrency) |
| 1155 | max_concurrency = arg[n].max_concurrency; |
| 1156 | } |
| 1157 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1158 | /* |
| 1159 | * Concurrency can be limited by several factors, for instance in a |
| 1160 | * single CPU system it's dependent on the Preemtion Model used by |
| 1161 | * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the |
| 1162 | * best result there). |
| 1163 | */ |
| 1164 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0); |
| 1165 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, num_threads); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1166 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1167 | Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1168 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1169 | Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1170 | memset(shm.buffer, 0, shm.size); |
| 1171 | memset(arg, 0, sizeof(arg)); |
| 1172 | max_concurrency = 0; |
| 1173 | nt = num_threads; |
| 1174 | |
| 1175 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1176 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1177 | arg[n].cmd = TA_CONCURRENT_CMD_SHA256; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1178 | arg[n].repeat = repeat; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1179 | arg[n].shm = &shm; |
| 1180 | arg[n].in = sha256_in; |
| 1181 | arg[n].in_len = sizeof(sha256_in); |
| 1182 | arg[n].out = out; |
| 1183 | arg[n].out_len = sizeof(out); |
| 1184 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1185 | test_1013_thread, arg + n))) |
| 1186 | nt = n; /* break loop and start cleanup */ |
| 1187 | } |
| 1188 | |
| 1189 | for (n = 0; n < nt; n++) { |
| 1190 | if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) && |
| 1191 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 1192 | ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out), |
| 1193 | arg[n].out, arg[n].out_len); |
| 1194 | if (arg[n].max_concurrency > max_concurrency) |
| 1195 | max_concurrency = arg[n].max_concurrency; |
| 1196 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1197 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1198 | Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1199 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1200 | *mean_concurrency /= 2.0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1201 | TEEC_ReleaseSharedMemory(&shm); |
| 1202 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1203 | |
| 1204 | static void xtest_tee_test_1013(ADBG_Case_t *c) |
| 1205 | { |
| 1206 | int i; |
| 1207 | double mean_concurrency; |
| 1208 | double concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1209 | int nb_loops = 24; |
Jens Wiklander | 6a9d15a | 2016-02-01 10:29:42 +0100 | [diff] [blame] | 1210 | |
| 1211 | if (level == 0) |
| 1212 | nb_loops /= 2; |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1213 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1214 | Do_ADBG_BeginSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1215 | mean_concurrency = 0; |
| 1216 | for (i = 0; i < nb_loops; i++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1217 | xtest_tee_test_1013_single(c, &concurrency, |
| 1218 | &concurrent_ta_uuid); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1219 | mean_concurrency += concurrency; |
| 1220 | } |
| 1221 | mean_concurrency /= nb_loops; |
| 1222 | |
| 1223 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1224 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1225 | Do_ADBG_EndSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1226 | |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1227 | #ifndef CFG_PAGED_USER_TA |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1228 | Do_ADBG_BeginSubCase(c, "Using large concurrency TA"); |
| 1229 | mean_concurrency = 0; |
| 1230 | for (i = 0; i < nb_loops; i++) { |
| 1231 | xtest_tee_test_1013_single(c, &concurrency, |
| 1232 | &concurrent_large_ta_uuid); |
| 1233 | mean_concurrency += concurrency; |
| 1234 | } |
| 1235 | mean_concurrency /= nb_loops; |
| 1236 | |
| 1237 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1238 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
| 1239 | Do_ADBG_EndSubCase(c, "Using large concurrency TA"); |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1240 | #endif |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1241 | } |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1242 | |
| 1243 | #ifdef CFG_SECURE_DATA_PATH |
| 1244 | static void xtest_tee_test_1014(ADBG_Case_t *c) |
| 1245 | { |
| 1246 | UNUSED(c); |
| 1247 | |
| 1248 | int size = 17000; |
| 1249 | int loop = 10; |
| 1250 | int ion_heap = DEFAULT_ION_HEAP_TYPE; |
| 1251 | int rnd_offset = 1; |
| 1252 | int test; |
| 1253 | int ret; |
| 1254 | |
| 1255 | test = TEST_NS_TO_TA; |
| 1256 | Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1257 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1258 | ADBG_EXPECT(c, 0, ret); |
| 1259 | Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
| 1260 | |
| 1261 | test = TEST_TA_TO_TA; |
| 1262 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1263 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1264 | ADBG_EXPECT(c, 0, ret); |
| 1265 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
| 1266 | |
| 1267 | test = TEST_TA_TO_PTA; |
| 1268 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP pTA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1269 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1270 | ADBG_EXPECT(c, 0, ret); |
| 1271 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP pTA"); |
| 1272 | |
| 1273 | test = TEST_NS_TO_PTA; |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1274 | Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1275 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1276 | ADBG_EXPECT(c, 1, ret); |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1277 | Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1278 | } |
| 1279 | #endif |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1280 | |
| 1281 | static void xtest_tee_test_1015(ADBG_Case_t *c) |
| 1282 | { |
| 1283 | TEEC_Result res; |
| 1284 | TEEC_Session session = { 0 }; |
| 1285 | uint32_t ret_orig; |
| 1286 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1287 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1288 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1289 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1290 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1291 | Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found"); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1292 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1293 | } |
| 1294 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1295 | |
| 1296 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1297 | TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE, |
| 1298 | NULL, &ret_orig)); |
| 1299 | TEEC_CloseSession(&session); |
| 1300 | } |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1301 | |
| 1302 | static void xtest_tee_test_1016(ADBG_Case_t *c) |
| 1303 | { |
| 1304 | TEEC_Session session = { 0 }; |
| 1305 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1306 | uint32_t ret_orig; |
| 1307 | |
| 1308 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1309 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1310 | &ret_orig))) |
| 1311 | return; |
| 1312 | |
| 1313 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 1314 | TEEC_NONE); |
| 1315 | |
| 1316 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1317 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op, |
| 1318 | &ret_orig)); |
| 1319 | |
| 1320 | TEEC_CloseSession(&session); |
| 1321 | } |