• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *   http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */
16 #include "ohos_types.h"
17 #include <securec.h>
18 #include "hctest.h"
19 #include "los_config.h"
20 #include "cmsis_os2.h"
21 #include "kernel_test.h"
22 
23 #define LOS_WAIT_FOREVER 0xFFFFFFFF
24 
25 UINT16 g_cmsisTestMutexCount;
26 osMutexId_t g_cmsisMutexId;
27 osMutexAttr_t g_cmsisMutexAttr;
28 
29 /**
30  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
31  * @param        : subsystem name is utils
32  * @param        : module name is utilsFile
33  * @param        : test suit name is CmsisMutexFuncTestSuite
34  */
35 LITE_TEST_SUIT(Cmsis, Cmsismutex, CmsisMutexFuncTestSuite);
36 
37 /**
38  * @tc.setup     : setup for all testcases
39  * @return       : setup result, TRUE is success, FALSE is fail
40  */
CmsisMutexFuncTestSuiteSetUp(void)41 static BOOL CmsisMutexFuncTestSuiteSetUp(void)
42 {
43     return TRUE;
44 }
45 
46 /**
47  * @tc.teardown  : teardown for all testcases
48  * @return       : teardown result, TRUE is success, FALSE is fail
49  */
CmsisMutexFuncTestSuiteTearDown(void)50 static BOOL CmsisMutexFuncTestSuiteTearDown(void)
51 {
52     printf("+-------------------------------------------+\n");
53     return TRUE;
54 }
55 
CmsisMutexGetOwnerFunc001(void const * argument)56 static void CmsisMutexGetOwnerFunc001(void const *argument)
57 {
58     (void)argument;
59     osStatus_t uwRet;
60     osThreadId_t id1;
61     osThreadId_t id2;
62     osThreadAttr_t attr;
63     g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
64     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
65 
66     uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
67     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
68 
69     id1 = osMutexGetOwner(g_cmsisMutexId);
70     id2 = osThreadGetId();
71     TEST_ASSERT_EQUAL_STRING(id1, id2);
72 
73     attr.name = osThreadGetName(id1);
74     TEST_ASSERT_EQUAL_STRING("testMutexGetOwner001", attr.name);
75 
76     uwRet = osMutexRelease(g_cmsisMutexId);
77     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
78 
79     uwRet = osMutexDelete(g_cmsisMutexId);
80     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
81     osThreadExit();
82 }
83 
84 /**
85  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0100
86  * @tc.name      : mutex operation for creat with NULL parameter
87  * @tc.desc      : [C- SOFTWARE -0200]
88  */
89 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew001, Function | MediumTest | Level1)
90 {
91     g_cmsisMutexId = osMutexNew(NULL);
92     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
93     (void)osMutexDelete(g_cmsisMutexId);
94     osDelay(DELAY_TICKS_5);
95 };
96 
97 /**
98  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0200
99  * @tc.name      : mutex operation for creat
100  * @tc.desc      : [C- SOFTWARE -0200]
101  */
102 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew002, Function | MediumTest | Level1)
103 {
104     g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
105     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
106     (void)osMutexDelete(g_cmsisMutexId);
107     osDelay(DELAY_TICKS_5);
108 };
109 
110 /**
111  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0300
112  * @tc.name      : mutex operation for delete after creat mutex with NULL parameter
113  * @tc.desc      : [C- SOFTWARE -0200]
114  */
115 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete001, Function | MediumTest | Level1)
116 {
117     osStatus_t uwRet;
118     g_cmsisMutexId = osMutexNew(NULL);
119     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
120     uwRet = osMutexDelete(g_cmsisMutexId);
121     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
122 
123     uwRet = osMutexDelete(g_cmsisMutexId);
124     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
125 };
126 
127 /**
128  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0400
129  * @tc.name      : mutex operation for delete
130  * @tc.desc      : [C- SOFTWARE -0200]
131  */
132 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete002, Function | MediumTest | Level1)
133 {
134     osStatus_t uwRet;
135     g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
136     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
137     uwRet = osMutexDelete(g_cmsisMutexId);
138     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
139 
140     uwRet = osMutexDelete(g_cmsisMutexId);
141     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
142 };
143 
144 /**
145  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0500
146  * @tc.name      : mutex operation for delete after mutex acquire and release
147  * @tc.desc      : [C- SOFTWARE -0200]
148  */
149 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete003, Function | MediumTest | Level1)
150 {
151     osStatus_t uwRet;
152     g_cmsisMutexId = osMutexNew(NULL);
153     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
154 
155     osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
156     uwRet = osMutexDelete(g_cmsisMutexId);
157     TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
158 
159     osMutexRelease(g_cmsisMutexId);
160     uwRet = osMutexDelete(g_cmsisMutexId);
161     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
162 };
163 
164 /**
165  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0600
166  * @tc.name      : mutex delete operation with mutex_id = NULL
167  * @tc.desc      : [C- SOFTWARE -0200]
168  */
169 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete004, Function | MediumTest | Level1)
170 {
171     osStatus_t uwRet;
172     uwRet = osMutexDelete(NULL);
173     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
174 };
175 
176 /**
177  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0700
178  * @tc.name      : mutex acquire operation with mutex_id = NULL
179  * @tc.desc      : [C- SOFTWARE -0200]
180  */
181 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire001, Function | MediumTest | Level1)
182 {
183     osStatus_t uwRet;
184     uwRet = osMutexAcquire(NULL, LOS_WAIT_FOREVER);
185     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
186 };
187 
188 /**
189  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0800
190  * @tc.name      : mutex operation for acquire
191  * @tc.desc      : [C- SOFTWARE -0200]
192  */
193 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire002, Function | MediumTest | Level1)
194 {
195     osStatus_t uwRet;
196     g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
197     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
198 
199     uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
200     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
201 
202     (void)osMutexRelease(g_cmsisMutexId);
203     uwRet = osMutexDelete(g_cmsisMutexId);
204     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
205 };
206 
207 /**
208  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0900
209  * @tc.name      : mutex operation for release
210  * @tc.desc      : [C- SOFTWARE -0200]
211  */
212 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease001, Function | MediumTest | Level1)
213 {
214     osStatus_t uwRet;
215     g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
216     TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
217 
218     uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
219     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
220 
221     uwRet = osMutexDelete(g_cmsisMutexId);
222     TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
223 
224     uwRet = osMutexRelease(g_cmsisMutexId);
225     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
226 
227     uwRet = osMutexDelete(g_cmsisMutexId);
228     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
229 };
230 
231 /**
232  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_1000
233  * @tc.name      : mutex release operation with mutex_id = NULL
234  * @tc.desc      : [C- SOFTWARE -0200]
235  */
236 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease002, Function | MediumTest | Level1)
237 {
238     osStatus_t uwRet;
239     uwRet = osMutexRelease(NULL);
240     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
241 };
242 
243 /**
244  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_1100
245  * @tc.name      : mutex operation for get owner
246  * @tc.desc      : [C- SOFTWARE -0200]
247  */
248 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner001, Function | MediumTest | Level1)
249 {
250     osThreadId_t id;
251     osThreadAttr_t attr;
252     attr.name = "testMutexGetOwner001";
253     attr.attr_bits = 0U;
254     attr.cb_mem = NULL;
255     attr.cb_size = 0U;
256     attr.stack_mem = NULL;
257     attr.stack_size = TEST_TASK_STACK_SIZE;
258     attr.priority = osPriorityAboveNormal;
259     id = osThreadNew((osThreadFunc_t)CmsisMutexGetOwnerFunc001, NULL, &attr);
260     TEST_ASSERT_NOT_NULL(id);
261 };
262 
263 /**
264  * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_1200
265  * @tc.name      : mutex get owner operation with mutex_id = NULL
266  * @tc.desc      : [C- SOFTWARE -0200]
267  */
268 LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner002, Function | MediumTest | Level1)
269 {
270     osThreadId_t id;
271     id = osMutexGetOwner(NULL);
272     TEST_ASSERT_NULL(id);
273 };
274 
275 RUN_TEST_SUITE(CmsisMutexFuncTestSuite);
276