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 | |
| 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <unistd.h> |
| 19 | |
| 20 | #include "xtest_test.h" |
| 21 | #include "xtest_helpers.h" |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 22 | #include "tee_api_defines.h" |
| 23 | #include "tee_client_api.h" |
| 24 | |
| 25 | #define OFFSET0 0 |
| 26 | |
| 27 | #define PARAM_0 0 |
| 28 | #define PARAM_1 1 |
| 29 | #define PARAM_2 2 |
| 30 | #define PARAM_3 3 |
| 31 | |
| 32 | struct xtest_session { |
| 33 | ADBG_Case_t *c; |
| 34 | TEEC_Session session; |
| 35 | TEEC_Context context; |
| 36 | }; |
| 37 | |
| 38 | /* Compares two memories and checks if their length and content is the same */ |
| 39 | #define EXPECT_SHARED_MEM_BUFFER(c, exp_buf, exp_blen, op, param_num, shrm) \ |
| 40 | do { \ |
| 41 | if ((exp_buf) == NULL) { \ |
| 42 | ADBG_EXPECT((c), exp_blen, \ |
| 43 | (op)->params[(param_num)].memref.size); \ |
| 44 | } else { \ |
| 45 | ADBG_EXPECT_COMPARE_POINTER((c), (shrm), ==, \ |
| 46 | (op)->params[(param_num)].memref.parent); \ |
| 47 | ADBG_EXPECT_BUFFER((c), (exp_buf), (exp_blen), \ |
| 48 | (shrm)->buffer, \ |
| 49 | (op)->params[(param_num)].memref.size); \ |
| 50 | } \ |
| 51 | } while (0) |
| 52 | |
| 53 | /* |
| 54 | * Compares the content of the memory cells in OP with the expected value |
| 55 | * contained. |
| 56 | */ |
| 57 | #define EXPECT_OP_TMP_MEM_BUFFER(c, exp_buf, exp_blen, op, param_num, buf) \ |
| 58 | do { \ |
| 59 | if ((exp_buf) == NULL) { \ |
| 60 | ADBG_EXPECT((c), exp_blen, \ |
| 61 | (op)->params[(param_num)].tmpref.size); \ |
| 62 | } else { \ |
| 63 | ADBG_EXPECT_COMPARE_POINTER((c), (buf), ==, \ |
| 64 | (op)->params[(param_num)].tmpref.buffer); \ |
| 65 | ADBG_EXPECT_BUFFER((c), (exp_buf), (exp_blen), \ |
| 66 | (buf), \ |
| 67 | (op)->params[(param_num)].memref.size); \ |
| 68 | } \ |
| 69 | } while (0) |
| 70 | |
| 71 | /* Initiates the memory and allocates size uint32_t. */ |
| 72 | |
| 73 | /* Registers the TEEC_SharedMemory to the TEE. */ |
| 74 | static TEEC_Result RegisterSharedMemory(TEEC_Context *ctx, |
| 75 | TEEC_SharedMemory *shm, uint32_t size, |
| 76 | uint32_t flags) |
| 77 | { |
| 78 | shm->flags = flags; |
| 79 | shm->size = size; |
| 80 | return TEEC_RegisterSharedMemory(ctx, shm); |
| 81 | } |
| 82 | |
| 83 | /* Allocates shared memory inside of the TEE. */ |
| 84 | static TEEC_Result AllocateSharedMemory(TEEC_Context *ctx, |
| 85 | TEEC_SharedMemory *shm, uint32_t size, |
| 86 | uint32_t flags) |
| 87 | { |
| 88 | shm->flags = flags; |
| 89 | shm->size = size; |
| 90 | return TEEC_AllocateSharedMemory(ctx, shm); |
| 91 | } |
| 92 | |
| 93 | static void CloseSession_null(struct xtest_session *cs) |
| 94 | { |
| 95 | Do_ADBG_BeginSubCase(cs->c, "CloseSession_null"); |
| 96 | { |
| 97 | /* In reality doesn't test anything. */ |
| 98 | TEEC_CloseSession(NULL); |
| 99 | } |
| 100 | Do_ADBG_EndSubCase(cs->c, "CloseSession_null"); |
| 101 | } |
| 102 | |
| 103 | static void Allocate_In(struct xtest_session *cs) |
| 104 | { |
| 105 | Do_ADBG_BeginSubCase(cs->c, "Allocate_In"); |
| 106 | { |
| 107 | TEEC_SharedMemory shm; |
| 108 | uint32_t size = 1024; |
| 109 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 110 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 111 | TEEC_InitializeContext(_device, &cs->context))) |
| 112 | goto out; |
| 113 | |
| 114 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 115 | AllocateSharedMemory(&cs->context, &shm, size, |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 116 | TEEC_MEM_INPUT))) |
| 117 | goto out_final; |
| 118 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 119 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 120 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 121 | TEEC_FinalizeContext(&cs->context); |
| 122 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 123 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 124 | Do_ADBG_EndSubCase(cs->c, "Allocate_In"); |
| 125 | } |
| 126 | |
| 127 | static void Allocate_out_of_memory(struct xtest_session *cs) |
| 128 | { |
| 129 | Do_ADBG_BeginSubCase(cs->c, "Allocate_out_of_memory"); |
| 130 | { |
| 131 | TEEC_SharedMemory shm; |
| 132 | uint32_t SIZE_OVER_MEMORY_CAPACITY = INT32_MAX; |
| 133 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 134 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 135 | TEEC_InitializeContext(_device, &cs->context))) |
| 136 | goto out; |
| 137 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 138 | ADBG_EXPECT_TEEC_RESULT(cs->c, TEEC_ERROR_OUT_OF_MEMORY, |
| 139 | AllocateSharedMemory(&cs->context, &shm, |
| 140 | SIZE_OVER_MEMORY_CAPACITY, |
| 141 | TEEC_MEM_INPUT)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 142 | TEEC_FinalizeContext(&cs->context); |
| 143 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 144 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 145 | Do_ADBG_EndSubCase(cs->c, "Allocate_out_of_memory"); |
| 146 | } |
| 147 | |
| 148 | static void OpenSession_error_notExistingTA(struct xtest_session *cs) |
| 149 | { |
| 150 | Do_ADBG_BeginSubCase(cs->c, "OpenSession_error_notExistingTA"); |
| 151 | { |
| 152 | TEEC_UUID NONEXISTING_TA_UUID = { 0x534D1192, 0x6143, 0x234C, |
| 153 | { 0x47, 0x55, 0x53, 0x52, |
| 154 | 0x54, 0x4F, 0x4F, 0x59 } }; |
| 155 | uint32_t ret_orig; |
| 156 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 157 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 158 | TEEC_InitializeContext(_device, &cs->context))) |
| 159 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 160 | |
| 161 | ADBG_EXPECT_COMPARE_UNSIGNED(cs->c, TEEC_SUCCESS, !=, |
| 162 | TEEC_OpenSession(&cs->context, &cs->session, |
| 163 | &NONEXISTING_TA_UUID, |
| 164 | TEEC_LOGIN_PUBLIC, NULL, NULL, |
| 165 | &ret_orig)); |
| 166 | ADBG_EXPECT_COMPARE_UNSIGNED(cs->c, TEEC_ORIGIN_TRUSTED_APP, !=, |
| 167 | ret_orig); |
| 168 | TEEC_FinalizeContext(&cs->context); |
| 169 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 170 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 171 | Do_ADBG_EndSubCase(cs->c, "OpenSession_error_notExistingTA"); |
| 172 | } |
| 173 | |
| 174 | static void Allocate_InOut(struct xtest_session *cs) |
| 175 | { |
| 176 | Do_ADBG_BeginSubCase(cs->c, "Allocate_InOut"); |
| 177 | { |
| 178 | TEEC_SharedMemory shm; |
| 179 | uint8_t val[] = { 54, 76, 98, 32 }; |
| 180 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 181 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 182 | TEEC_InitializeContext(_device, &cs->context))) |
| 183 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 184 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 185 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 186 | AllocateSharedMemory(&cs->context, &shm, sizeof(val), |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 187 | TEEC_MEM_INPUT | TEEC_MEM_OUTPUT))) |
| 188 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 189 | |
| 190 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 191 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 192 | TEEC_FinalizeContext(&cs->context); |
| 193 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 194 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 195 | Do_ADBG_EndSubCase(cs->c, "Allocate_InOut"); |
| 196 | } |
| 197 | |
| 198 | static void Register_In(struct xtest_session *cs) |
| 199 | { |
| 200 | Do_ADBG_BeginSubCase(cs->c, "Register_In"); |
| 201 | { |
| 202 | TEEC_SharedMemory shm; |
| 203 | uint8_t val[] = { 32, 65, 43, 21, 98 }; |
| 204 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 205 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 206 | TEEC_InitializeContext(_device, &cs->context))) |
| 207 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 208 | |
| 209 | shm.buffer = val; |
| 210 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 211 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 212 | RegisterSharedMemory(&cs->context, &shm, sizeof(val), |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 213 | TEEC_MEM_INPUT))) |
| 214 | goto out_final; |
| 215 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 216 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 217 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 218 | TEEC_FinalizeContext(&cs->context); |
| 219 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 220 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 221 | Do_ADBG_EndSubCase(cs->c, "Register_In"); |
| 222 | } |
| 223 | |
| 224 | static void Register_notZeroLength_Out(struct xtest_session *cs) |
| 225 | { |
| 226 | Do_ADBG_BeginSubCase(cs->c, "Register_notZeroLength_Out"); |
| 227 | { |
| 228 | TEEC_SharedMemory shm; |
| 229 | uint8_t val[] = { 56, 67, 78, 99 }; |
| 230 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 231 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 232 | TEEC_InitializeContext(_device, &cs->context))) |
| 233 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 234 | |
| 235 | shm.buffer = val; |
| 236 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 237 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 238 | RegisterSharedMemory(&cs->context, &shm, sizeof(val), |
| 239 | TEEC_MEM_OUTPUT))) |
| 240 | goto out_final; |
| 241 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 242 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 243 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 244 | TEEC_FinalizeContext(&cs->context); |
| 245 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 246 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 247 | Do_ADBG_EndSubCase(cs->c, "Register_notZeroLength_Out"); |
| 248 | } |
| 249 | |
| 250 | static void Register_InOut(struct xtest_session *cs) |
| 251 | { |
| 252 | Do_ADBG_BeginSubCase(cs->c, "Register_InOut"); |
| 253 | { |
| 254 | TEEC_SharedMemory shm; |
| 255 | uint8_t val[] = { 54, 76, 23, 98, 255, 23, 86 }; |
| 256 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 257 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 258 | TEEC_InitializeContext(_device, &cs->context))) |
| 259 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 260 | |
| 261 | shm.buffer = val; |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 262 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 263 | RegisterSharedMemory(&cs->context, &shm, sizeof(val), |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 264 | TEEC_MEM_INPUT | TEEC_MEM_OUTPUT))) |
| 265 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 266 | |
| 267 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 268 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 269 | TEEC_FinalizeContext(&cs->context); |
| 270 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 271 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 272 | Do_ADBG_EndSubCase(cs->c, "Register_InOut"); |
| 273 | } |
| 274 | |
| 275 | static void Register_zeroLength_Out(struct xtest_session *cs) |
| 276 | { |
| 277 | Do_ADBG_BeginSubCase(cs->c, "Register_zeroLength_Out"); |
| 278 | { |
| 279 | uint8_t val[] = { 65, 76, 98, 32 }; |
| 280 | TEEC_SharedMemory shm; |
| 281 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 282 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 283 | TEEC_InitializeContext(_device, &cs->context))) |
| 284 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 285 | |
| 286 | shm.buffer = val; |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 287 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 288 | RegisterSharedMemory(&cs->context, &shm, 0, |
| 289 | TEEC_MEM_OUTPUT))) |
| 290 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 291 | |
| 292 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 293 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 294 | TEEC_FinalizeContext(&cs->context); |
| 295 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 296 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 297 | Do_ADBG_EndSubCase(cs->c, "Register_zeroLength_Out"); |
| 298 | } |
| 299 | |
| 300 | static void Allocate_Out(struct xtest_session *cs) |
| 301 | { |
| 302 | Do_ADBG_BeginSubCase(cs->c, "Allocate_Out"); |
| 303 | { |
| 304 | TEEC_SharedMemory shm; |
| 305 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 306 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 307 | TEEC_InitializeContext(_device, &cs->context))) |
| 308 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 309 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 310 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 311 | AllocateSharedMemory(&cs->context, &shm, 0, |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 312 | TEEC_MEM_OUTPUT))) |
| 313 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 314 | |
| 315 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 316 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 317 | TEEC_FinalizeContext(&cs->context); |
| 318 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 319 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 320 | Do_ADBG_EndSubCase(cs->c, "Allocate_Out"); |
| 321 | } |
| 322 | |
| 323 | static void FinalizeContext_null(struct xtest_session *cs) |
| 324 | { |
| 325 | Do_ADBG_BeginSubCase(cs->c, "FinalizeContext_null"); |
| 326 | { |
| 327 | TEEC_FinalizeContext(NULL); |
| 328 | } |
| 329 | Do_ADBG_EndSubCase(cs->c, "FinalizeContext_null"); |
| 330 | } |
| 331 | |
| 332 | static void InitializeContext_NotExistingTEE(struct xtest_session *cs) |
| 333 | { |
| 334 | Do_ADBG_BeginSubCase(cs->c, "InitializeContext_NotExistingTEE"); |
| 335 | { |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 336 | if (!ADBG_EXPECT_COMPARE_UNSIGNED(cs->c, TEEC_SUCCESS, !=, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 337 | TEEC_InitializeContext("Invalid TEE name", |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 338 | &cs->context))) |
| 339 | TEEC_FinalizeContext(&cs->context); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 340 | } |
| 341 | Do_ADBG_EndSubCase(cs->c, "InitializeContext_NotExistingTEE"); |
| 342 | } |
| 343 | |
| 344 | static void AllocateThenRegister_SameMemory(struct xtest_session *cs) |
| 345 | { |
| 346 | Do_ADBG_BeginSubCase(cs->c, "AllocateThenRegister_SameMemory"); |
| 347 | { |
| 348 | TEEC_SharedMemory shm; |
| 349 | uint32_t size_allocation = 32; |
| 350 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 351 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 352 | TEEC_InitializeContext(_device, &cs->context))) |
| 353 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 354 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 355 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 356 | AllocateSharedMemory(&cs->context, &shm, |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 357 | size_allocation, TEEC_MEM_INPUT))) |
| 358 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 359 | |
| 360 | ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 361 | RegisterSharedMemory(&cs->context, &shm, |
| 362 | size_allocation, TEEC_MEM_INPUT)); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 363 | |
| 364 | TEEC_ReleaseSharedMemory(&shm); |
| 365 | out_final: |
| 366 | TEEC_FinalizeContext(&cs->context); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 367 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 368 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 369 | Do_ADBG_EndSubCase(cs->c, "AllocateThenRegister_SameMemory"); |
| 370 | } |
| 371 | |
| 372 | static void AllocateSameMemory_twice(struct xtest_session *cs) |
| 373 | { |
| 374 | Do_ADBG_BeginSubCase(cs->c, "AllocateSameMemory_twice"); |
| 375 | { |
| 376 | TEEC_SharedMemory shm; |
| 377 | uint32_t size_allocation = 32; |
| 378 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 379 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 380 | TEEC_InitializeContext(_device, &cs->context))) |
| 381 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 382 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 383 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 384 | AllocateSharedMemory(&cs->context, &shm, |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 385 | size_allocation, TEEC_MEM_INPUT))) |
| 386 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 387 | |
| 388 | ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 389 | AllocateSharedMemory(&cs->context, &shm, |
| 390 | size_allocation, TEEC_MEM_INPUT)); |
| 391 | |
| 392 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 393 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 394 | TEEC_FinalizeContext(&cs->context); |
| 395 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 396 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 397 | Do_ADBG_EndSubCase(cs->c, "AllocateSameMemory_twice"); |
| 398 | } |
| 399 | |
| 400 | static void RegisterSameMemory_twice(struct xtest_session *cs) |
| 401 | { |
| 402 | Do_ADBG_BeginSubCase(cs->c, "RegisterSameMemory_twice"); |
| 403 | { |
| 404 | uint8_t val[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; |
| 405 | TEEC_SharedMemory shm; |
| 406 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 407 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 408 | TEEC_InitializeContext(_device, &cs->context))) |
| 409 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 410 | |
| 411 | shm.buffer = val; |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 412 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 413 | RegisterSharedMemory(&cs->context, &shm, sizeof(val), |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 414 | TEEC_MEM_INPUT))) |
| 415 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 416 | |
| 417 | ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 418 | RegisterSharedMemory(&cs->context, &shm, sizeof(val), |
| 419 | TEEC_MEM_INPUT)); |
| 420 | |
| 421 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 422 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 423 | TEEC_FinalizeContext(&cs->context); |
| 424 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 425 | out: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 426 | Do_ADBG_EndSubCase(cs->c, "RegisterSameMemory_twice"); |
| 427 | } |
| 428 | |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 429 | #ifndef MIN |
| 430 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
| 431 | #endif |
| 432 | |
| 433 | static void Allocate_sharedMemory_32k(struct xtest_session *cs) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 434 | { |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 435 | Do_ADBG_BeginSubCase(cs->c, "Allocate_sharedMemory_32k"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 436 | { |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 437 | uint32_t size = MIN(32 * 1024, |
| 438 | TEEC_CONFIG_SHAREDMEM_MAX_SIZE); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 439 | TEEC_SharedMemory shm; |
| 440 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 441 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 442 | TEEC_InitializeContext(_device, &cs->context))) |
| 443 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 444 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 445 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 446 | AllocateSharedMemory(&cs->context, &shm, size, |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 447 | TEEC_MEM_INPUT))) |
| 448 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 449 | |
| 450 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 451 | out_final: |
| 452 | TEEC_FinalizeContext(&cs->context); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 453 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 454 | out: |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 455 | Do_ADBG_EndSubCase(cs->c, "Allocate_sharedMemory_32k"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 456 | } |
| 457 | |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 458 | static void Register_sharedMemory_32k(struct xtest_session *cs) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 459 | { |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 460 | Do_ADBG_BeginSubCase(cs->c, "Register_sharedMemory_32k"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 461 | { |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 462 | uint32_t size = MIN(32 * 1024, |
| 463 | TEEC_CONFIG_SHAREDMEM_MAX_SIZE); |
| 464 | uint8_t val[size]; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 465 | TEEC_SharedMemory shm; |
| 466 | |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 467 | if (!ADBG_EXPECT(cs->c, TEEC_SUCCESS, |
| 468 | TEEC_InitializeContext(_device, &cs->context))) |
| 469 | goto out; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 470 | |
| 471 | shm.buffer = val; |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 472 | if (!ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 473 | RegisterSharedMemory(&cs->context, &shm, size, |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 474 | TEEC_MEM_INPUT))) |
| 475 | goto out_final; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 476 | |
| 477 | TEEC_ReleaseSharedMemory(&shm); |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 478 | out_final: |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 479 | TEEC_FinalizeContext(&cs->context); |
| 480 | } |
Jens Wiklander | 72c5545 | 2016-10-27 20:44:35 +0200 | [diff] [blame] | 481 | out: |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 482 | Do_ADBG_EndSubCase(cs->c, "Register_sharedMemory_32k"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static void xtest_teec_TEE(ADBG_Case_t *c) |
| 486 | { |
| 487 | struct xtest_session connection = { c }; |
| 488 | |
| 489 | CloseSession_null(&connection); |
| 490 | |
| 491 | Allocate_In(&connection); |
| 492 | |
| 493 | Allocate_out_of_memory(&connection); |
| 494 | |
| 495 | OpenSession_error_notExistingTA(&connection); |
| 496 | |
| 497 | Allocate_InOut(&connection); |
| 498 | |
| 499 | Register_In(&connection); |
| 500 | |
| 501 | Register_notZeroLength_Out(&connection); |
| 502 | |
| 503 | Register_InOut(&connection); |
| 504 | |
| 505 | Register_zeroLength_Out(&connection); |
| 506 | |
| 507 | Allocate_Out(&connection); |
| 508 | |
| 509 | FinalizeContext_null(&connection); |
| 510 | |
| 511 | InitializeContext_NotExistingTEE(&connection); |
| 512 | |
| 513 | AllocateThenRegister_SameMemory(&connection); |
| 514 | |
| 515 | AllocateSameMemory_twice(&connection); |
| 516 | |
| 517 | RegisterSameMemory_twice(&connection); |
| 518 | |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 519 | Allocate_sharedMemory_32k(&connection); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 520 | |
Jerome Forissier | cefbe02 | 2017-05-23 11:02:35 +0200 | [diff] [blame^] | 521 | Register_sharedMemory_32k(&connection); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 524 | ADBG_CASE_DEFINE(regression, 5006, xtest_teec_TEE, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 525 | "Tests for Global platform TEEC"); |