1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 13 #include <gtest/gtest.h> 14 15 #include <iostream> 16 #include <vector> 17 18 #include <test_defines.h> 19 20 #include <common_test.h> 21 #include <empty_test.h> 22 #include <public_test.h> 23 #include <session_mgr/client_session_mgr.h> 24 #include <tee_client_api.h> 25 #include <tee_client_type.h> 26 27 using namespace std; 28 using namespace testing::ext; 29 30 /** 31 * @testcase.name : Opensession_WithoutContext 32 * @testcase.desc : call TEEC_OpenSession Without Context, 33 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 34 */ 35 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithoutContext, Function | MediumTest | Level0) 36 { 37 TEEC_Result ret; 38 uint32_t origin; 39 TEEC_UUID uuid = CLIENTAPI_UUID_1; 40 TEEC_Operation operation = { 0 }; 41 operation.started = 1; 42 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 43 44 ret = TEEC_OpenSession(NULL, GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 45 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 46 ASSERT_EQ(origin, TEEC_ORIGIN_API); 47 } 48 49 /** 50 * @testcase.name : Opensession_WithoutSession 51 * @testcase.desc : call TEEC_OpenSession Without session, 52 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 53 */ 54 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithoutSession, Function | MediumTest | Level0) 55 { 56 TEEC_Result ret; 57 uint32_t origin; 58 TEEC_UUID uuid = CLIENTAPI_UUID_1; 59 TEEC_Operation operation = { 0 }; 60 operation.started = 1; 61 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 62 63 char str[64] = { 0 }; 64 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 65 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 66 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 67 uuid.clockSeqAndNode[7]); 68 GetContext()->ta_path = (uint8_t *)str; 69 70 ret = TEEC_OpenSession(GetContext(), NULL, &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 71 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 72 ASSERT_EQ(origin, TEEC_ORIGIN_API); 73 } 74 75 /** 76 * @testcase.name : Opensession_WithoutDestination 77 * @testcase.desc : call TEEC_OpenSession Without Destination, 78 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 79 */ 80 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithoutDestination, Function | MediumTest | Level0) 81 { 82 TEEC_Result ret; 83 uint32_t origin; 84 TEEC_Operation operation = { 0 }; 85 operation.started = 1; 86 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 87 88 ret = TEEC_OpenSession(GetContext(), GetSession(), NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 89 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 90 ASSERT_EQ(origin, TEEC_ORIGIN_API); 91 } 92 93 /** 94 * @testcase.name : Opensession_WithoutConnectionMethod 95 * @testcase.desc : call TEEC_OpenSession Without ConnectionMethod, 96 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 97 */ 98 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithoutConnectionMethod, Function | MediumTest | Level0) 99 { 100 TEEC_Result ret; 101 uint32_t origin; 102 TEEC_UUID testId = CLIENTAPI_UUID_1; 103 TEEC_Operation operation = { 0 }; 104 operation.started = 1; 105 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 106 107 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, -1, NULL, &operation, &origin); 108 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 109 ASSERT_EQ(origin, TEEC_ORIGIN_API); 110 } 111 112 /** 113 * @testcase.name : Opensession_WithNotSupportConnectionMethod 114 * @testcase.desc : call TEEC_OpenSession With Not Support ConnectionMethod, 115 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 116 */ 117 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithNotSupportConnectionMethod, Function | MediumTest | Level0) 118 { 119 TEEC_Result ret; 120 uint32_t origin; 121 TEEC_UUID testId = CLIENTAPI_UUID_1; 122 TEEC_Operation operation = { 0 }; 123 operation.started = 1; 124 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 125 char testData[TEST_STR_LEN] = "Hello"; 126 127 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_PUBLIC, NULL, &operation, &origin); 128 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 129 ASSERT_EQ(origin, TEEC_ORIGIN_API); 130 131 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_USER, NULL, &operation, &origin); 132 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 133 ASSERT_EQ(origin, TEEC_ORIGIN_API); 134 135 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_GROUP, NULL, &operation, &origin); 136 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 137 ASSERT_EQ(origin, TEEC_ORIGIN_API); 138 139 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_GROUP, reinterpret_cast<void *>(testData), 140 &operation, &origin); 141 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 142 ASSERT_EQ(origin, TEEC_ORIGIN_API); 143 144 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_APPLICATION, NULL, &operation, &origin); 145 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 146 ASSERT_EQ(origin, TEEC_ORIGIN_API); 147 148 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_USER_APPLICATION, NULL, &operation, &origin); 149 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 150 ASSERT_EQ(origin, TEEC_ORIGIN_API); 151 152 ret = 153 TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_GROUP_APPLICATION, NULL, &operation, &origin); 154 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 155 ASSERT_EQ(origin, TEEC_ORIGIN_API); 156 157 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_GROUP_APPLICATION, 158 reinterpret_cast<void *>(testData), &operation, &origin); 159 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 160 ASSERT_EQ(origin, TEEC_ORIGIN_API); 161 } 162 163 /** 164 * @testcase.name : Opensession_WithoutOperation 165 * @testcase.desc : call TEEC_OpenSession Without Operation, 166 * @testcase.expect : return TEEC_SUCCESS 167 */ 168 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithoutOperation, Function | MediumTest | Level0) 169 { 170 TEEC_Result ret; 171 uint32_t origin; 172 TEEC_UUID uuid = CLIENTAPI_UUID_1; 173 174 char str[64] = { 0 }; 175 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 176 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 177 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 178 uuid.clockSeqAndNode[7]); 179 GetContext()->ta_path = (uint8_t *)str; 180 181 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, NULL, &origin); 182 ASSERT_EQ(ret, TEEC_SUCCESS); 183 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 184 } 185 186 /** 187 * @testcase.name : Opensession_WithoutOrigin 188 * @testcase.desc : call TEEC_OpenSession Without Origin, 189 * @testcase.expect : return TEEC_SUCCESS 190 */ 191 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithoutOrigin, Function | MediumTest | Level0) 192 { 193 TEEC_Result ret; 194 TEEC_UUID uuid = CLIENTAPI_UUID_1; 195 TEEC_Operation operation = { 0 }; 196 operation.started = 1; 197 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 198 199 char str[64] = { 0 }; 200 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 201 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 202 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 203 uuid.clockSeqAndNode[7]); 204 GetContext()->ta_path = (uint8_t *)str; 205 206 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, NULL); 207 ASSERT_EQ(ret, TEEC_SUCCESS); 208 } 209 210 /** 211 * @testcase.name : Opensession_ContextIsNotInit 212 * @testcase.desc : call TEEC_OpenSession With Context is Not Init, 213 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 214 */ 215 TEE_TEST(TeeBasicTestFram, Opensession_ContextIsNotInit, Function | MediumTest | Level0) 216 { 217 TEEC_Result ret; 218 uint32_t origin; 219 const char *name = "testname"; 220 TEEC_Context context = { 0 }; 221 TEEC_Session session = { 0 }; 222 ret = TEEC_InitializeContext(name, &context); 223 EXPECT_EQ(ret, TEEC_SUCCESS); 224 TEEC_FinalizeContext(&context); 225 TEEC_UUID testId = CLIENTAPI_UUID_1; 226 TEEC_Operation operation = { 0 }; 227 operation.started = 1; 228 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 229 230 ret = TEEC_OpenSession(&context, &session, &testId, TEEC_LOGIN_IDENTIFY, NULL, NULL, &origin); 231 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 232 ASSERT_EQ(origin, TEEC_ORIGIN_API); 233 } 234 235 /** 236 * @testcase.name : Opensession_ParamTypesIsInvalid 237 * @testcase.desc : call TEEC_OpenSession With ParamTypes is invalid 238 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 239 */ 240 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_ParamTypesIsInvalid, Function | MediumTest | Level0) 241 { 242 TEEC_Result ret; 243 uint32_t origin; 244 TEEC_UUID testId = CLIENTAPI_UUID_1; 245 TEEC_Operation operation = { 0 }; 246 operation.started = 1; 247 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE); 248 operation.params[0].value.a = 0; 249 operation.params[0].value.b = 0; 250 operation.params[1].value.a = 0xFFFFFFFF; 251 operation.params[1].value.b = 1; 252 253 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 254 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 255 ASSERT_EQ(origin, TEEC_ORIGIN_API); 256 } 257 258 /** 259 * @testcase.name : Opensession_WithOperationIsNone 260 * @testcase.desc : call TEEC_OpenSession With Operation is none 261 * @testcase.expect : return TEEC_SUCCESS 262 */ 263 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithOperationIsNone, Function | MediumTest | Level0) 264 { 265 TEEC_Result ret; 266 uint32_t origin; 267 TEEC_UUID uuid = CLIENTAPI_UUID_1; 268 TEEC_Operation operation = { 0 }; 269 operation.started = 1; 270 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 271 272 char str[64] = { 0 }; 273 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 274 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 275 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 276 uuid.clockSeqAndNode[7]); 277 GetContext()->ta_path = (uint8_t *)str; 278 279 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 280 ASSERT_EQ(ret, TEEC_SUCCESS); 281 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 282 } 283 284 /** 285 * @testcase.name : Opensession_WithOperationIsValue 286 * @testcase.desc : call TEEC_OpenSession With Operation paramtype is value 287 * @testcase.expect : return TEEC_SUCCESS 288 */ 289 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithOperationIsValue, Function | MediumTest | Level0) 290 { 291 TEEC_Result ret; 292 uint32_t origin; 293 TEEC_UUID uuid = CLIENTAPI_UUID_1; 294 TEEC_Operation operation = { 0 }; 295 operation.started = 1; 296 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_OUTPUT, TEEC_VALUE_INOUT, TEEC_VALUE_INOUT); 297 operation.params[0].value.a = 0x111; 298 operation.params[0].value.b = 0x222; 299 operation.params[1].value.a = 0x333; 300 operation.params[1].value.b = 0x444; 301 operation.params[2].value.a = 0x555; 302 operation.params[2].value.b = 0x666; 303 operation.params[3].value.a = 0x777; 304 operation.params[3].value.b = 0x888; 305 306 char str[64] = { 0 }; 307 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 308 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 309 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 310 uuid.clockSeqAndNode[7]); 311 GetContext()->ta_path = (uint8_t *)str; 312 313 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 314 ASSERT_EQ(ret, TEEC_SUCCESS); 315 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 316 ASSERT_EQ(operation.params[0].value.a, 0x111); 317 ASSERT_EQ(operation.params[0].value.b, 0x222); 318 ASSERT_EQ(operation.params[1].value.a, 0x333); 319 ASSERT_EQ(operation.params[1].value.b, 0x444); 320 ASSERT_EQ(operation.params[2].value.a, 0x555); 321 ASSERT_EQ(operation.params[2].value.b, 0x666); 322 ASSERT_EQ(operation.params[3].value.a, 0x777); 323 ASSERT_EQ(operation.params[3].value.b, 0x888); 324 } 325 326 /** 327 * @testcase.name : Opensession_WithOperationIsTempMem 328 * @testcase.desc : call TEEC_OpenSession With Operation paramtype is tempmem 329 * @testcase.expect : return TEEC_SUCCESS 330 */ 331 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithOperationIsTempMem, Function | MediumTest | Level0) 332 { 333 TEEC_Result ret; 334 uint32_t origin; 335 TEEC_UUID uuid = CLIENTAPI_UUID_1; 336 TEEC_Operation operation = { 0 }; 337 char testData0[TEST_STR_LEN] = "Hello"; 338 char testData1[TEST_STR_LEN] = "abcdefgh"; 339 char testData2[TEST_STR_LEN] = "qwertyuiop"; 340 char testData3[TEST_STR_LEN] = "this is test string"; 341 342 uint32_t len0 = strlen(testData0) + 1; 343 uint32_t len1 = strlen(testData1) + 1; 344 uint32_t len2 = strlen(testData2) + 1; 345 uint32_t len3 = strlen(testData3) + 1; 346 operation.started = 1; 347 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_MEMREF_TEMP_OUTPUT, TEEC_MEMREF_TEMP_INOUT, 348 TEEC_MEMREF_TEMP_INOUT); 349 operation.params[0].tmpref.buffer = testData0; 350 operation.params[0].tmpref.size = len0; 351 operation.params[1].tmpref.buffer = testData1; 352 operation.params[1].tmpref.size = len1; 353 operation.params[2].tmpref.buffer = testData2; 354 operation.params[2].tmpref.size = len2; 355 operation.params[3].tmpref.buffer = testData3; 356 operation.params[3].tmpref.size = len3; 357 358 char str[64] = { 0 }; 359 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 360 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 361 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 362 uuid.clockSeqAndNode[7]); 363 GetContext()->ta_path = (uint8_t *)str; 364 365 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 366 ASSERT_EQ(ret, TEEC_SUCCESS); 367 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 368 ASSERT_STREQ(reinterpret_cast<char *>(operation.params[0].tmpref.buffer), testData0); 369 ASSERT_EQ(operation.params[0].tmpref.size, len0); 370 ASSERT_STREQ(reinterpret_cast<char *>(operation.params[1].tmpref.buffer), testData1); 371 ASSERT_EQ(operation.params[1].tmpref.size, len1); 372 ASSERT_STREQ(reinterpret_cast<char *>(operation.params[2].tmpref.buffer), testData2); 373 ASSERT_EQ(operation.params[2].tmpref.size, len2); 374 ASSERT_STREQ(reinterpret_cast<char *>(operation.params[3].tmpref.buffer), testData3); 375 ASSERT_EQ(operation.params[3].tmpref.size, len3); 376 } 377 378 /** 379 * @testcase.name : Opensession_WithOperationIsPartialMem 380 * @testcase.desc : call TEEC_OpenSession With Operation paramtype is PartialMem 381 * @testcase.expect : return TEEC_SUCCESS 382 */ 383 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithOperationIsPartialMem, Function | MediumTest | Level0) 384 { 385 TEEC_Result ret; 386 int rc; 387 uint32_t origin; 388 TEEC_UUID uuid = CLIENTAPI_UUID_1; 389 TEEC_Operation operation = { 0 }; 390 char testData0[TEST_STR_LEN] = "Hello"; 391 392 TEEC_SharedMemory sharedMem = { 0 }; 393 // test malloc mem 394 sharedMem.size = TEST_STR_LEN; 395 sharedMem.flags = TEEC_MEM_INOUT; 396 397 ret = TEEC_AllocateSharedMemory(GetContext(), &sharedMem); 398 ASSERT_EQ(ret, TEEC_SUCCESS); 399 rc = memcpy_s(sharedMem.buffer, TEST_STR_LEN, testData0, TEST_STR_LEN); 400 ASSERT_EQ(rc, 0); 401 402 operation.started = 1; 403 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_MEMREF_PARTIAL_OUTPUT, 404 TEEC_MEMREF_PARTIAL_INOUT, TEEC_MEMREF_PARTIAL_INOUT); 405 operation.params[0].memref.parent = &sharedMem; 406 operation.params[0].memref.offset = 0; 407 operation.params[0].memref.size = sharedMem.size; 408 operation.params[1].memref.parent = &sharedMem; 409 operation.params[1].memref.offset = 0; 410 operation.params[1].memref.size = sharedMem.size; 411 operation.params[2].memref.parent = &sharedMem; 412 operation.params[2].memref.offset = 0; 413 operation.params[2].memref.size = sharedMem.size; 414 operation.params[3].memref.parent = &sharedMem; 415 operation.params[3].memref.offset = 0; 416 operation.params[3].memref.size = sharedMem.size; 417 418 char str[64] = { 0 }; 419 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 420 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 421 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 422 uuid.clockSeqAndNode[7]); 423 GetContext()->ta_path = (uint8_t *)str; 424 425 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 426 ASSERT_EQ(ret, TEEC_SUCCESS); 427 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 428 ASSERT_STREQ(reinterpret_cast<char *>(sharedMem.buffer), testData0); 429 ASSERT_EQ(operation.params[0].memref.size, sharedMem.size); 430 ASSERT_EQ(operation.params[1].memref.size, sharedMem.size); 431 ASSERT_EQ(operation.params[2].memref.size, sharedMem.size); 432 ASSERT_EQ(operation.params[3].memref.size, sharedMem.size); 433 } 434 435 /** 436 * @testcase.name : Opensession_WithNotExistUUID 437 * @testcase.desc : call TEEC_OpenSession With uuid is not exist 438 * @testcase.expect : return TEEC_ERROR_GENERIC 439 */ 440 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithNotExistUUID, Function | MediumTest | Level0) 441 { 442 TEEC_Result ret; 443 uint32_t origin; 444 TEEC_UUID uuid = UUID_TA_NOT_EXIST; 445 TEEC_Operation operation = { 0 }; 446 operation.started = 1; 447 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 448 449 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 450 ASSERT_EQ(ret, TEEC_ERROR_GENERIC); 451 ASSERT_EQ(origin, TEEC_ORIGIN_COMMS); 452 } 453 454 /** 455 * @testcase.name : Opensession_ReturnErrorFromTA 456 * @testcase.desc : call TEEC_OpenSession With TA return error 457 * @testcase.expect : return TEEC_ERROR_GENERIC 458 */ 459 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_ReturnErrorFromTA, Function | MediumTest | Level0) 460 { 461 TEEC_Result ret; 462 uint32_t origin; 463 TEEC_UUID uuid = CLIENTAPI_UUID_1; 464 TEEC_Operation operation = { 0 }; 465 operation.started = 1; 466 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); 467 operation.params[0].value.b = 0xFFFFFFFE; // this number intend for trigger ta return error when opensession 468 469 char str[64] = { 0 }; 470 sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid.timeLow, uuid.timeMid, 471 uuid.timeHiAndVersion, uuid.clockSeqAndNode[0], uuid.clockSeqAndNode[1], uuid.clockSeqAndNode[2], 472 uuid.clockSeqAndNode[3], uuid.clockSeqAndNode[4], uuid.clockSeqAndNode[5], uuid.clockSeqAndNode[6], 473 uuid.clockSeqAndNode[7]); 474 GetContext()->ta_path = (uint8_t *)str; 475 476 ret = TEEC_OpenSession(GetContext(), GetSession(), &uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 477 ASSERT_EQ(ret, TEEC_ERROR_GENERIC); 478 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 479 } 480 481 /** 482 * @testcase.name : Opensession_WithParamTypesIsInvalid 483 * @testcase.desc : call TEEC_OpenSession With paramtype is invalid 484 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 485 */ 486 TEE_TEST(TeeBasicTestFramWithInitContext, Opensession_WithParamTypesIsInvalid, Function | MediumTest | Level0) 487 { 488 TEEC_Result ret; 489 uint32_t origin; 490 TEEC_UUID testId = CLIENTAPI_UUID_1; 491 TEEC_Operation operation = { 0 }; 492 operation.started = 1; 493 operation.paramTypes = TEEC_PARAM_TYPES(0x1F, TEEC_NONE, TEEC_NONE, TEEC_NONE); // 0X1F is invalid 494 495 ret = TEEC_OpenSession(GetContext(), GetSession(), &testId, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); 496 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 497 ASSERT_EQ(origin, TEEC_ORIGIN_API); 498 } 499 500 /** 501 * @testcase.name : RequestCancellationTest 502 * @testcase.desc : call TEEC_RequestCancellation after TEEC_InvokeCommand 503 * @testcase.expect : no error occur,in log can see not support this api 504 */ 505 TEE_TEST(TeeBasicTestFram, RequestCancellationTest, Function | MediumTest | Level0) 506 { 507 TEEC_Result ret; 508 TEEC_UUID testId = CLIENTAPI_UUID_1; 509 ClientSessionMgr sess; 510 ret = sess.Start(&testId); 511 EXPECT_EQ(ret, TEEC_SUCCESS); 512 513 TEEC_Operation operation = { 0 }; 514 operation.started = 1; 515 operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); 516 517 ret = TEEC_InvokeCommand(&sess.session, 0, &operation, NULL); 518 TEEC_RequestCancellation(&operation); 519 520 sess.Destroy(); 521 ASSERT_EQ(ret, TEEC_SUCCESS); 522 }