• 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 <tee_client_api.h>
21 #include <tee_client_type.h>
22 #include <empty_test.h>
23 #include <public_test.h>
24 
25 using namespace std;
26 using namespace testing::ext;
27 
28 /**
29  * @testcase.name      : InitContext_NameIsNotNULL
30  * @testcase.desc      : call TEEC_InitializeContext normal test
31  * @testcase.expect    : return TEEC_SUCCESS
32  */
33 TEE_TEST(TeeBasicTestFram, InitContext_NameIsNotNULL, Function | MediumTest | Level0)
34 {
35     TEEC_Result ret;
36     TEEC_Context context = { 0 };
37     const char *name = "testname";
38     ret = TEEC_InitializeContext(name, &context);
39     EXPECT_EQ(ret, TEEC_SUCCESS);
40     TEEC_FinalizeContext(&context);
41 }
42 
43 /**
44  * @testcase.name      : InitContext_ContextIsNULL
45  * @testcase.desc      : call TEEC_InitializeContext with context is null
46  * @testcase.expect    : return TEEC_ERROR_BAD_PARAMETERS
47  */
48 TEE_TEST(TeeBasicTestFram, InitContext_ContextIsNULL, Function | MediumTest | Level0)
49 {
50     TEEC_Result ret;
51     ret = TEEC_InitializeContext(NULL, NULL);
52     ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS);
53 }
54 
55 /**
56  * @testcase.name      : InitContext_AfterFinalizeContext
57  * @testcase.desc      : call TEEC_InitializeContext after Finalize Context
58  * @testcase.expect    : return TEEC_SUCCESS
59  */
60 TEE_TEST(TeeBasicTestFramWithInitContext, InitContext_AfterFinalizeContext, Function | MediumTest | Level0)
61 {
62     TEEC_Result ret;
63     TEEC_FinalizeContext(GetContext());
64 
65     ret = TEEC_InitializeContext(NULL, GetContext());
66     ASSERT_EQ(ret, TEEC_SUCCESS);
67 }
68 
69 /**
70  * @testcase.name      : InitContext_Use17Context
71  * @testcase.desc      : one CA call TEEC_InitializeContext use 17 different Context,
72  *                       this testcase shoud fail at init 17th context,only support 16 contexts in one CA
73  * @testcase.expect    : return TEEC_FAIL
74  */
75 TEE_TEST(TeeBasicTestFram, InitContext_Use17Context, Function | MediumTest | Level0)
76 {
77     TEEC_Result ret;
78     TEEC_Context context[17] = { { 0 } };
79     uint32_t i;
80     for (i = 0; i < 16; i++) {
81         ret = TEEC_InitializeContext(NULL, &context[i]);
82         EXPECT_EQ(ret, TEEC_SUCCESS);
83     }
84     // init 17th context should fail
85     ret = TEEC_InitializeContext(NULL, &context[16]);
86     EXPECT_EQ(ret, TEEC_FAIL);
87 
88     for (i = 0; i < 17; i++)
89         TEEC_FinalizeContext(&context[i]);
90 }
91