• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      : Closesession_WithCreatedSession
32  * @testcase.desc      : call TEEC_CloseSession With created session
33  * @testcase.expect    : session_id is 0
34  */
35 TEE_TEST(TeeBasicTestFram, Closesession_WithCreatedSession, Function | MediumTest | Level0)
36 {
37     TEEC_Result ret;
38     ClientSessionMgr sess;
39     TEEC_UUID testId = CLIENTAPI_UUID_1;
40     ret = sess.Start(&testId);
41     EXPECT_EQ(ret, TEEC_SUCCESS);
42 
43     TEEC_CloseSession(&sess.session);
44     ASSERT_EQ(sess.session.session_id, 0);
45     ASSERT_STREQ(reinterpret_cast<char *>(sess.session.context), NULL);
46 }
47 
48 /**
49  * @testcase.name      : Closesession_WithoutSession
50  * @testcase.desc      : call TEEC_CloseSession WithoutSession
51  * @testcase.expect    : no error occur
52  */
53 TEE_TEST(TeeBasicTestFram, Closesession_WithoutSession, Function | MediumTest | Level0)
54 {
55     TEEC_Result ret;
56     ClientSessionMgr sess;
57     TEEC_UUID testId = CLIENTAPI_UUID_1;
58     ret = sess.Start(&testId);
59     EXPECT_EQ(ret, TEEC_SUCCESS);
60 
61     TEEC_CloseSession(NULL);
62     ASSERT_NE(sess.session.session_id, 0);
63     ASSERT_NE(sess.session.ops_cnt, 0);
64     ASSERT_STRNE(reinterpret_cast<char *>(sess.session.context), NULL);
65 }
66 
67 /**
68  * @testcase.name      : Closesession_WithNotOpenedSession
69  * @testcase.desc      : call TEEC_CloseSession with Not Opened Session
70  * @testcase.expect    : no error occur
71  */
72 TEE_TEST(TeeBasicTestFram, Closesession_WithNotOpenedSession, Function | MediumTest | Level0)
73 {
74     TEEC_Result ret;
75     TEEC_UUID testId = CLIENTAPI_UUID_1;
76     ClientSessionMgr sess;
77     ret = sess.Start(&testId);
78     EXPECT_EQ(ret, TEEC_SUCCESS);
79     sess.Destroy();
80     ret = TEEC_InitializeContext(NULL, &sess.context);
81     EXPECT_EQ(ret, TEEC_SUCCESS);
82 
83     TEEC_CloseSession(&sess.session);
84     ASSERT_EQ(sess.session.session_id, 0);
85     ASSERT_EQ(sess.session.ops_cnt, 0);
86     ASSERT_STREQ(reinterpret_cast<char *>(sess.session.context), NULL);
87 }
88