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 <common_test.h> 14 #include <gtest/gtest.h> 15 #include <securec.h> 16 #include <tee_client_api.h> 17 #include <tee_client_type.h> 18 #include <test_defines.h> 19 #include <test_log.h> 20 #include <test_tcf_cmdid.h> 21 22 using namespace std; 23 using namespace testing::ext; 24 25 /** 26 * @testcase.name : TEE_Panic_With_Normal 27 * @testcase.desc : test TA call TEE_Panic to make ta panic 28 * @testcase.expect : return TEEC_ERROR_TARGET_DEAD 29 */ 30 TEE_TEST(TeeTCF1Test, TEE_Panic_With_Normal, Function | MediumTest | Level0) 31 { 32 TEEC_Result ret; 33 uint32_t origin; 34 TEEC_Result panicCode = TEEC_ERROR_GENERIC; 35 36 ret = Invoke_Panic(GetSession(), CMD_TEE_Panic, panicCode, &origin); 37 #ifndef TEST_STUB 38 ASSERT_EQ(ret, TEEC_ERROR_TARGET_DEAD); 39 ASSERT_EQ(origin, TEEC_ORIGIN_TEE); 40 #else 41 ASSERT_EQ(ret, TEEC_SUCCESS); 42 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 43 #endif 44 } 45 46 /** 47 * @testcase.name : TEE_Panic_With_MultiSession 48 * @testcase.desc : test TA call TEE_Panic to make a multisession ta panic 49 * @testcase.expect : return TEEC_ERROR_TARGET_DEAD,invoke other tasession will return TEEC_ERROR_ITEM_NOT_FOUND 50 */ 51 TEE_TEST(TeeTCF2TA2TATest, TEE_Panic_With_MultiSession, Function | MediumTest | Level0) 52 { 53 TEEC_Result ret; 54 uint32_t ta2taSession[8] = { 0 }; 55 uint32_t origin = 0; 56 int i; 57 TestData value = { 0 }; 58 value.caseId = 0; 59 value.uuid = TCF_API_UUID_1; // this uuid is for ta2 60 value.inBufferLen = BIG_SIZE; 61 value.outBufferLen = BIG_SIZE; 62 63 for (i = 0; i <= 6; i++) { 64 ret = Invoke_OpenTASession(GetSession(), CMD_TEE_OpenTASession, &ta2taSession[i], &value, &origin); 65 ASSERT_EQ(ret, TEEC_SUCCESS); 66 ASSERT_EQ(origin, TEEC_ORIGIN_TRUSTED_APP); 67 ASSERT_EQ(value.origin, TEEC_ORIGIN_TEE); 68 ASSERT_NE(ta2taSession[i], 0); 69 if (i >= 1) 70 ASSERT_NE(ta2taSession[i], ta2taSession[i - 1]); 71 } 72 #ifndef TEST_STUB 73 // make ta2 one session panic 74 TEEC_Result panicCode = TEEC_ERROR_GENERIC; 75 ret = Invoke_Panic(GetSession2(), CMD_TEE_Panic, panicCode, &origin); 76 ASSERT_EQ(ret, TEEC_ERROR_TARGET_DEAD); 77 ASSERT_EQ(origin, TEEC_ORIGIN_TEE); 78 79 for (i = 0; i <= 6; i++) { 80 ret = Invoke_InvokeTACommand(GetSession(), CMD_TEE_InvokeTACommand, ta2taSession[i], &value, &origin); 81 ASSERT_EQ(ret, TEEC_ERROR_ITEM_NOT_FOUND); 82 ASSERT_EQ(origin, TEEC_ORIGIN_TEE); 83 } 84 #endif 85 } 86