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 <vector> 16 #include <iostream> 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 : Finalizecontext_WithCreatedContext 32 * @testcase.desc : call TEEC_FinalizeContext With created context 33 * @testcase.expect : fd has released 34 */ 35 TEE_TEST(TeeBasicTestFram, Finalizecontext_WithCreatedContext, Function | MediumTest | Level0) 36 { 37 TEEC_Result ret; 38 ClientSessionMgr sess; 39 ret = TEEC_InitializeContext(NULL, &sess.context); 40 EXPECT_EQ(ret, TEEC_SUCCESS); 41 42 TEEC_FinalizeContext(&sess.context); 43 ASSERT_EQ(sess.context.fd, -1); 44 } 45 46 /** 47 * @testcase.name : Finalizecontext_WithNotCreatedContext 48 * @testcase.desc : call TEEC_FinalizeContext With not created context 49 * @testcase.expect : fd is -1 50 */ 51 TEE_TEST(TeeBasicTestFram, Finalizecontext_WithNotCreatedContext, Function | MediumTest | Level0) 52 { 53 ClientSessionMgr sess; 54 sess.context = { 0 }; 55 TEEC_FinalizeContext(&sess.context); 56 ASSERT_EQ(sess.context.fd, -1); 57 } 58 59 /** 60 * @testcase.name : Finalizecontext_WithoutContext 61 * @testcase.desc : call TEEC_FinalizeContext Without context 62 * @testcase.expect : fd is -1 63 */ 64 TEE_TEST(TeeBasicTestFram, Finalizecontext_WithoutContext, Function | MediumTest | Level0) 65 { 66 TEEC_Result ret; 67 ClientSessionMgr sess; 68 ret = TEEC_InitializeContext(NULL, &sess.context); 69 EXPECT_EQ(ret, TEEC_SUCCESS); 70 71 TEEC_FinalizeContext(NULL); 72 ASSERT_NE(sess.context.fd, -1); 73 }