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 | #include "xtest_test.h" |
| 20 | #include "xtest_helpers.h" |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 21 | #include "tee_api_defines.h" |
| 22 | #include "tee_client_api.h" |
| 23 | #include "xml_client_api.h" |
| 24 | |
| 25 | static bool xtest_init = false; |
| 26 | |
| 27 | static bool xtest_tee_init(ADBG_Case_t *c) |
| 28 | { |
| 29 | if (xtest_init) |
| 30 | return true; |
| 31 | |
| 32 | SHARE_MEM01 = malloc(sizeof(TEEC_SharedMemory)); |
| 33 | if (!ADBG_EXPECT_NOT_NULL(c, SHARE_MEM01)) |
| 34 | goto exit; |
| 35 | |
| 36 | SHARE_MEM02 = malloc(sizeof(TEEC_SharedMemory)); |
| 37 | if (!ADBG_EXPECT_NOT_NULL(c, SHARE_MEM02)) |
| 38 | goto exit; |
| 39 | |
| 40 | SESSION01 = malloc(sizeof(TEEC_Session)); |
| 41 | if (!ADBG_EXPECT_NOT_NULL(c, SESSION01)) |
| 42 | goto exit; |
| 43 | |
| 44 | CONTEXT01 = malloc(sizeof(TEEC_Context)); |
| 45 | if (!ADBG_EXPECT_NOT_NULL(c, CONTEXT01)) |
| 46 | goto exit; |
| 47 | |
| 48 | OPERATION01 = malloc(sizeof(TEEC_Operation)); |
| 49 | if (!ADBG_EXPECT_NOT_NULL(c, OPERATION01)) |
| 50 | goto exit; |
| 51 | |
| 52 | OPERATION02 = malloc(sizeof(TEEC_Operation)); |
| 53 | if (!ADBG_EXPECT_NOT_NULL(c, OPERATION02)) |
| 54 | goto exit; |
| 55 | |
| 56 | xtest_init = true; |
| 57 | |
| 58 | return xtest_init; |
| 59 | |
| 60 | exit: |
| 61 | if (SHARE_MEM01) { |
| 62 | free(SHARE_MEM01); |
| 63 | SHARE_MEM01 = NULL; |
| 64 | } |
| 65 | if (SHARE_MEM02) { |
| 66 | free(SHARE_MEM02); |
| 67 | SHARE_MEM02 = NULL; |
| 68 | } |
| 69 | if (SESSION01) { |
| 70 | free(SESSION01); |
| 71 | SESSION01 = NULL; |
| 72 | } |
| 73 | if (CONTEXT01) { |
| 74 | free(CONTEXT01); |
| 75 | CONTEXT01 = NULL; |
| 76 | } |
| 77 | if (OPERATION01) { |
| 78 | free(OPERATION01); |
| 79 | OPERATION01 = NULL; |
| 80 | } |
| 81 | if (OPERATION02) { |
| 82 | free(OPERATION02); |
| 83 | OPERATION02 = NULL; |
| 84 | } |
| 85 | |
| 86 | xtest_init = false; |
| 87 | return xtest_init; |
| 88 | } |
| 89 | |
| 90 | /*29-84-6d*/ |
| 91 | static void xtest_tee_7001(ADBG_Case_t *c) |
| 92 | { |
| 93 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 94 | return; |
| 95 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 96 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 97 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 98 | AllocateSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01, |
| 99 | TEEC_MEM_INPUT)); |
| 100 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 101 | TEEC_FinalizeContext(CONTEXT01); |
| 102 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 103 | ADBG_CASE_DEFINE(regression, 7001, xtest_tee_7001, |
| 104 | "Allocate_In RELEASE_SHARED_MEMORY_WHEN_ALLOCATED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 105 | |
| 106 | /*29-c2-4c*/ |
| 107 | static void xtest_tee_7002(ADBG_Case_t *c) |
| 108 | { |
| 109 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 110 | return; |
| 111 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 112 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 113 | ADBG_EXPECT(c, TEEC_ERROR_OUT_OF_MEMORY, |
| 114 | AllocateSharedMemory(CONTEXT01, SHARE_MEM01, |
| 115 | SIZE_OVER_MEMORY, TEEC_MEM_INPUT)); |
| 116 | TEEC_FinalizeContext(CONTEXT01); |
| 117 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 118 | ADBG_CASE_DEFINE(regression, 7002, xtest_tee_7002, |
| 119 | "Allocate_out_of_memory INITIALIZE_CONTEXT_NAMES"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 120 | |
| 121 | /*29-b0-da*/ |
| 122 | static void xtest_tee_7003(ADBG_Case_t *c) |
| 123 | { |
| 124 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 125 | return; |
| 126 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 127 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 128 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 129 | AllocateSharedMemory(CONTEXT01, SHARE_MEM01, BIG_SIZE, |
| 130 | TEEC_MEM_OUTPUT)); |
| 131 | TEEC_ReleaseSharedMemory(NULL); |
| 132 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 133 | TEEC_FinalizeContext(CONTEXT01); |
| 134 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 135 | ADBG_CASE_DEFINE(regression, 7003, xtest_tee_7003, |
| 136 | "ReleaseSharedMemory_null RELEASE_SHARED_MEMORY_WHEN_ALLOCATED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 137 | |
| 138 | /*29-1c-00*/ |
| 139 | static void xtest_tee_7004(ADBG_Case_t *c) |
| 140 | { |
| 141 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 142 | return; |
| 143 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 144 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 145 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 146 | AllocateSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01, |
| 147 | TEEC_MEM_INOUT)); |
| 148 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 149 | TEEC_FinalizeContext(CONTEXT01); |
| 150 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 151 | ADBG_CASE_DEFINE(regression, 7004, xtest_tee_7004, |
| 152 | "Allocate_InOut RELEASE_SHARED_MEMORY_WHEN_ALLOCATED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 153 | |
| 154 | /*29-9f-a2*/ |
| 155 | static void xtest_tee_7005(ADBG_Case_t *c) |
| 156 | { |
| 157 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 158 | return; |
| 159 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 160 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 161 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 162 | RegisterSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01, |
| 163 | TEEC_MEM_INPUT)); |
| 164 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 165 | TEEC_FinalizeContext(CONTEXT01); |
| 166 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 167 | ADBG_CASE_DEFINE(regression, 7005, xtest_tee_7005, |
| 168 | "Register_In RELEASE_SHARED_MEMORY_WHEN_REGISTERED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 169 | |
| 170 | /*29-11-02*/ |
| 171 | static void xtest_tee_7006(ADBG_Case_t *c) |
| 172 | { |
| 173 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 174 | return; |
| 175 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 176 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 177 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 178 | RegisterSharedMemory(CONTEXT01, SHARE_MEM01, SIZE_VALUE01, |
| 179 | TEEC_MEM_OUTPUT)); |
| 180 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 181 | TEEC_FinalizeContext(CONTEXT01); |
| 182 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 183 | ADBG_CASE_DEFINE(regression, 7006, xtest_tee_7006, |
| 184 | "Register_notZeroLength_Out RELEASE_SHARED_MEMORY_WHEN_REGISTERED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 185 | |
| 186 | /*29-1f-a2*/ |
| 187 | static void xtest_tee_7007(ADBG_Case_t *c) |
| 188 | { |
| 189 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 190 | return; |
| 191 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 192 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 193 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 194 | RegisterSharedMemory(CONTEXT01, SHARE_MEM01, BIG_SIZE, |
| 195 | TEEC_MEM_INOUT)); |
| 196 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 197 | TEEC_FinalizeContext(CONTEXT01); |
| 198 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 199 | ADBG_CASE_DEFINE(regression, 7007, xtest_tee_7007, |
| 200 | "Register_InOut RELEASE_SHARED_MEMORY_WHEN_REGISTERED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 201 | |
| 202 | /*29-2e-8d*/ |
| 203 | static void xtest_tee_7008(ADBG_Case_t *c) |
| 204 | { |
| 205 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 206 | return; |
| 207 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 208 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 209 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 210 | RegisterSharedMemory(CONTEXT01, SHARE_MEM01, ZERO, |
| 211 | TEEC_MEM_OUTPUT)); |
| 212 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 213 | TEEC_FinalizeContext(CONTEXT01); |
| 214 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 215 | ADBG_CASE_DEFINE(regression, 7008, xtest_tee_7008, |
| 216 | "Register_zeroLength_Out RELEASE_SHARED_MEMORY_WHEN_REGISTERED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 217 | |
| 218 | /*29-2b-3f*/ |
| 219 | static void xtest_tee_7009(ADBG_Case_t *c) |
| 220 | { |
| 221 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 222 | return; |
| 223 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 224 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 225 | XML_OpenSession(c, CONTEXT01, SESSION01, &UUID_Unknown, |
| 226 | TEEC_LOGIN_PUBLIC, NULL, NULL, |
| 227 | TEEC_ORIGIN_ANY_NOT_TRUSTED_APP, TEEC_UNDEFINED_ERROR); |
| 228 | TEEC_FinalizeContext(CONTEXT01); |
| 229 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 230 | ADBG_CASE_DEFINE(regression, 7009, xtest_tee_7009, |
| 231 | "OpenSession_error_notExistingTA OPEN_SESSION_TARGET_TRUSTED_APP"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 232 | |
| 233 | /*29-cd-39*/ |
| 234 | static void xtest_tee_7010(ADBG_Case_t *c) |
| 235 | { |
| 236 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 237 | return; |
| 238 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 239 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 240 | ADBG_EXPECT(c, TEEC_SUCCESS, |
| 241 | AllocateSharedMemory(CONTEXT01, SHARE_MEM01, ZERO, |
| 242 | TEEC_MEM_OUTPUT)); |
| 243 | TEEC_ReleaseSharedMemory(SHARE_MEM01); |
| 244 | TEEC_FinalizeContext(CONTEXT01); |
| 245 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 246 | ADBG_CASE_DEFINE(regression, 7010, xtest_tee_7010, |
| 247 | "Allocate_Out RELEASE_SHARED_MEMORY_WHEN_ALLOCATED"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 248 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 249 | /*29-a2-e3*/ |
| 250 | static void xtest_tee_7013(ADBG_Case_t *c) |
| 251 | { |
| 252 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 253 | return; |
| 254 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 255 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 256 | XML_OpenSession(c, CONTEXT01, SESSION01, |
| 257 | &UUID_TTA_answerSuccessTo_OpenSession_Invoke, |
| 258 | INVALID_CONNECTION_METHODS, NULL, NULL, |
| 259 | TEEC_ORIGIN_ANY_NOT_TRUSTED_APP, TEEC_UNDEFINED_ERROR); |
| 260 | TEEC_FinalizeContext(CONTEXT01); |
| 261 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 262 | ADBG_CASE_DEFINE(regression, 7013, xtest_tee_7013, |
| 263 | "OpenSession_error_originTEE OPEN_SESSION_TARGET_TRUSTED_APP"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 264 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 265 | /*29-db-48*/ |
| 266 | static void xtest_tee_7016(ADBG_Case_t *c) |
| 267 | { |
| 268 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 269 | return; |
| 270 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 271 | TEEC_CloseSession(NULL); |
| 272 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 273 | ADBG_CASE_DEFINE(regression, 7016, xtest_tee_7016, |
| 274 | "CloseSession_null CLOSE_SESSION_IGNORE_SESSION_NULL"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 275 | |
| 276 | /*29-a1-83*/ |
| 277 | static void xtest_tee_7017(ADBG_Case_t *c) |
| 278 | { |
| 279 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 280 | return; |
| 281 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 282 | XML_InitializeContext(c, INVALID_NOT_EXISTING_TEE, CONTEXT01, |
| 283 | TEEC_UNDEFINED_ERROR); |
| 284 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 285 | ADBG_CASE_DEFINE(regression, 7017, xtest_tee_7017, |
| 286 | "InitializeContext_NotExistingTEE INITIALIZE_CONTEXT_NAMES"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 287 | |
| 288 | /*29-c1-a5*/ |
| 289 | static void xtest_tee_7018(ADBG_Case_t *c) |
| 290 | { |
| 291 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 292 | return; |
| 293 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 294 | TEEC_FinalizeContext(NULL); |
| 295 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 296 | ADBG_CASE_DEFINE(regression, 7018, xtest_tee_7018, |
| 297 | "FinalizeContext_null FINALIZE_CONTEXT_IGNORE_NULL"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 298 | |
| 299 | /*29-91-aa*/ |
| 300 | static void xtest_tee_7019(ADBG_Case_t *c) |
| 301 | { |
| 302 | if (!ADBG_EXPECT_TRUE(c, xtest_tee_init(c))) |
| 303 | return; |
| 304 | TEEC_createThread(CLIENT_APP01, THREAD02); |
| 305 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 306 | XML_InitializeContext(c, _device, CONTEXT01, TEEC_SUCCESS); |
| 307 | TEEC_SelectApp(CLIENT_APP01, THREAD02); |
| 308 | thr2_ctx.c = c; |
| 309 | thr2_ctx.ctx = CONTEXT01; |
| 310 | ctx_init_finalize(thr2_ctx); |
| 311 | TEEC_SelectApp(CLIENT_APP01, THREAD01_DEFAULT); |
| 312 | TEEC_FinalizeContext(CONTEXT01); |
| 313 | } |
Jens Wiklander | 74abfe3 | 2017-01-03 14:17:47 +0100 | [diff] [blame] | 314 | ADBG_CASE_DEFINE(regression, 7019, xtest_tee_7019, |
Jens Wiklander | 25a57fe | 2016-12-26 21:46:24 +0100 | [diff] [blame] | 315 | "InitializeContext_concurrentContext INITIALIZE_CONTEXT_NAMES"); |