• 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 osSemaphoreId_t  g_cmsisSemSema;
24 #define SEMAPHHORE_COUNT_HEX_MAX    0xFE
25 #define SEMAPHHORE_COUNT_INT0    0
26 #define SEMAPHHORE_COUNT_INT1    1
27 #define SEMAPHHORE_COUNT_INT10    10
28 
29 
30 /**
31  * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
32  * @param        : subsystem name is utils
33  * @param        : module name is utilsFile
34  * @param        : test suit name is CmsisTaskFuncTestSuite
35  */
36 LITE_TEST_SUIT(Cmsis, CmsisSem, CmsisSemFuncTestSuite);
37 
38 /**
39  * @tc.setup     : setup for all testcases
40  * @return       : setup result, TRUE is success, FALSE is fail
41  */
CmsisSemFuncTestSuiteSetUp(void)42 static BOOL CmsisSemFuncTestSuiteSetUp(void)
43 {
44     return TRUE;
45 }
46 
47 /**
48  * @tc.teardown  : teardown for all testcases
49  * @return       : teardown result, TRUE is success, FALSE is fail
50  */
CmsisSemFuncTestSuiteTearDown(void)51 static BOOL CmsisSemFuncTestSuiteTearDown(void)
52 {
53     printf("+-------------------------------------------+\n");
54     return TRUE;
55 }
56 
57 /**
58  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0100
59  * @tc.name      : semaphore operation for creat when Semaphhore count = 1 and 0
60  * @tc.desc      : [C- SOFTWARE -0200]
61  */
62 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew001, Function | MediumTest | Level1)
63 {
64     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
65     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
66     (void)osSemaphoreDelete(g_cmsisSemSema);
67     osDelay(DELAY_TICKS_5);
68 };
69 
70 /**
71  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0200
72  * @tc.name      : semaphore operation for creat when Semaphhore count = 10 and 1
73  * @tc.desc      : [C- SOFTWARE -0200]
74  */
75 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew002, Function | MediumTest | Level1)
76 {
77     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT1, NULL);
78     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
79     (void)osSemaphoreDelete(g_cmsisSemSema);
80     osDelay(DELAY_TICKS_5);
81 };
82 
83 /**
84  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0300
85  * @tc.name      : semaphore operation for creat when Semaphhore count = 0 and 10
86  * @tc.desc      : [C- SOFTWARE -0200]
87  */
88 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew003, Function | MediumTest | Level1)
89 {
90     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT10, NULL);
91     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
92     (void)osSemaphoreDelete(g_cmsisSemSema);
93     osDelay(DELAY_TICKS_5);
94 };
95 
96 /**
97  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0400
98  * @tc.name      : semaphore operation for creat when Semaphhore count = 0 and 0
99  * @tc.desc      : [C- SOFTWARE -0200]
100  */
101 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew004, Function | MediumTest | Level1)
102 {
103     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT0, NULL);
104     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
105     osSemaphoreDelete(g_cmsisSemSema);
106     osDelay(DELAY_TICKS_5);
107 };
108 
109 /**
110  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0500
111  * @tc.name      : semaphore operation for creat when Semaphhore count = 1 and 1
112  * @tc.desc      : [C- SOFTWARE -0200]
113  */
114 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew005, Function | MediumTest | Level1)
115 {
116     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
117     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
118     osSemaphoreDelete(g_cmsisSemSema);
119     osDelay(DELAY_TICKS_5);
120 };
121 
122 /**
123  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0600
124  * @tc.name      : semaphore operation for creat when Semaphhore count = 10 and 10
125  * @tc.desc      : [C- SOFTWARE -0200]
126  */
127 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew006, Function | MediumTest | Level1)
128 {
129     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT10, NULL);
130     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
131     osSemaphoreDelete(g_cmsisSemSema);
132     osDelay(DELAY_TICKS_5);
133 };
134 
135 /**
136  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0700
137  * @tc.name      : semaphore operation for creat when Semaphhore count = 0xFE and 0
138  * @tc.desc      : [C- SOFTWARE -0200]
139  */
140 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew007, Function | MediumTest | Level1)
141 {
142     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_INT0, NULL);
143     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
144     osSemaphoreDelete(g_cmsisSemSema);
145     osDelay(DELAY_TICKS_5);
146 };
147 
148 /**
149  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0800
150  * @tc.name      : semaphore operation for creat when Semaphhore count = 0 and 0xFE
151  * @tc.desc      : [C- SOFTWARE -0200]
152  */
153 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew008, Function | MediumTest | Level1)
154 {
155     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_HEX_MAX, NULL);
156     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
157     osSemaphoreDelete(g_cmsisSemSema);
158     osDelay(DELAY_TICKS_5);
159 };
160 
161 /**
162  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_0900
163  * @tc.name      : semaphore operation for delete
164  * @tc.desc      : [C- SOFTWARE -0200]
165  */
166 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete001, Function | MediumTest | Level1)
167 {
168     osStatus_t uwRet;
169     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL);
170     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
171 
172     uwRet = osSemaphoreDelete(g_cmsisSemSema);
173     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
174 };
175 
176 /**
177  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1000
178  * @tc.name      : semaphore delete operation twice
179  * @tc.desc      : [C- SOFTWARE -0200]
180  */
181 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete002, Function | MediumTest | Level1)
182 {
183     osStatus_t uwRet;
184     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL);
185     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
186 
187     uwRet = osSemaphoreDelete(g_cmsisSemSema);
188     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
189 
190     uwRet = osSemaphoreDelete(g_cmsisSemSema);
191     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
192 };
193 
194 /**
195  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1100
196  * @tc.name      : semaphore delete operation with semaphore_id = NULL
197  * @tc.desc      : [C- SOFTWARE -0200]
198  */
199 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete003, Function | MediumTest | Level1)
200 {
201     osStatus_t uwRet;
202     uwRet = osSemaphoreDelete(NULL);
203     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
204 
205 };
206 
207 /**
208  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1200
209  * @tc.name      : semaphore operation for acquire when Semaphhore count = 1 and 1
210  * @tc.desc      : [C- SOFTWARE -0200]
211  */
212 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire001, Function | MediumTest | Level1)
213 {
214     osStatus_t uwRet;
215     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
216     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
217     uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
218     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
219 
220     uwRet = osSemaphoreDelete(g_cmsisSemSema);
221     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
222 };
223 
224 /**
225  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1300
226  * @tc.name      : semaphore operation for acquire when Semaphhore count = 1 and 0
227  * @tc.desc      : [C- SOFTWARE -0200]
228  */
229 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire002, Function | MediumTest | Level1)
230 {
231     osStatus_t uwRet;
232     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
233     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
234     uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
235     TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
236 
237     uwRet = osSemaphoreDelete(g_cmsisSemSema);
238     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
239 };
240 
241 /**
242  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1400
243  * @tc.name      : semaphore operation for acquire when Semaphhore count = 0 and 1
244  * @tc.desc      : [C- SOFTWARE -0200]
245  */
246 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire003, Function | MediumTest | Level1)
247 {
248     osStatus_t uwRet;
249     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL);
250     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
251     uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
252     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
253 
254     uwRet = osSemaphoreDelete(g_cmsisSemSema);
255     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
256 };
257 
258 /**
259  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1500
260  * @tc.name      : semaphore acquire operation with semaphore_id = NULL
261  * @tc.desc      : [C- SOFTWARE -0200]
262  */
263 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire004, Function | MediumTest | Level1)
264 {
265     osStatus_t uwRet;
266     uwRet = osSemaphoreAcquire(NULL, 0);
267     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
268 
269 };
270 
271 /**
272  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1600
273  * @tc.name      : semaphore operation for release
274  * @tc.desc      : [C- SOFTWARE -0200]
275  */
276 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease001, Function | MediumTest | Level1)
277 {
278     osStatus_t uwRet;
279     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
280     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
281 
282     uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
283     TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
284 
285     uwRet = osSemaphoreRelease(g_cmsisSemSema);
286     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
287 
288     uwRet = osSemaphoreDelete(g_cmsisSemSema);
289     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
290 };
291 
292 /**
293  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1700
294  * @tc.name      : semaphore release operation twice
295  * @tc.desc      : [C- SOFTWARE -0200]
296  */
297 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease002, Function | MediumTest | Level1)
298 {
299     osStatus_t uwRet;
300     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
301     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
302 
303     uwRet = osSemaphoreRelease(g_cmsisSemSema);
304     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
305     uwRet = osSemaphoreRelease(g_cmsisSemSema);
306     TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
307 
308     uwRet = osSemaphoreDelete(g_cmsisSemSema);
309     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
310 };
311 
312 /**
313  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1800
314  * @tc.name      : semaphore operation for release after semaphore acquire
315  * @tc.desc      : [C- SOFTWARE -0200]
316  */
317 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease003, Function | MediumTest | Level1)
318 {
319     osStatus_t uwRet;
320     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
321     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
322 
323     uwRet = osSemaphoreRelease(g_cmsisSemSema);
324     TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
325 
326     uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
327     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
328 
329     uwRet = osSemaphoreRelease(g_cmsisSemSema);
330     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
331     uwRet = osSemaphoreRelease(g_cmsisSemSema);
332     TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
333 
334     uwRet = osSemaphoreDelete(g_cmsisSemSema);
335     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
336 };
337 
338 /**
339  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_1900
340  * @tc.name      : semaphore release operation with semaphore_id = NULL
341  * @tc.desc      : [C- SOFTWARE -0200]
342  */
343 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease004, Function | MediumTest | Level1)
344 {
345     osStatus_t uwRet;
346     uwRet = osSemaphoreRelease(NULL);
347     TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
348 
349 };
350 
351 /**
352  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_2000
353  * @tc.name      : semaphore operation for get count when Semaphhore count = 1 or 0xFE
354  * @tc.desc      : [C- SOFTWARE -0200]
355  */
356 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount001, Function | MediumTest | Level1)
357 {
358     osStatus_t uwRet;
359     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
360     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
361     uwRet = osSemaphoreGetCount(g_cmsisSemSema);
362     TEST_ASSERT_EQUAL_INT(1, uwRet);
363     uwRet = osSemaphoreDelete(g_cmsisSemSema);
364     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
365 
366     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL);
367     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
368     uwRet = osSemaphoreGetCount(g_cmsisSemSema);
369     TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX, uwRet);
370     uwRet = osSemaphoreDelete(g_cmsisSemSema);
371     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
372 };
373 
374 /**
375  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_2100
376  * @tc.name      : semaphore operation for get count when Semaphhore count = 1 or 0
377  * @tc.desc      : [C- SOFTWARE -0200]
378  */
379 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount002, Function | MediumTest | Level1)
380 {
381     osStatus_t uwRet;
382     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
383     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
384     uwRet = osSemaphoreGetCount(g_cmsisSemSema);
385     TEST_ASSERT_EQUAL_INT(0, uwRet);
386     uwRet = osSemaphoreDelete(g_cmsisSemSema);
387     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
388 
389     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL);
390     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
391     uwRet = osSemaphoreGetCount(g_cmsisSemSema);
392     TEST_ASSERT_EQUAL_INT(1, uwRet);
393     uwRet = osSemaphoreDelete(g_cmsisSemSema);
394     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
395 };
396 
397 /**
398  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_2200
399  * @tc.name      : semaphore operation for get count
400  * @tc.desc      : [C- SOFTWARE -0200]
401  */
402 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount003, Function | MediumTest | Level1)
403 {
404     osStatus_t uwRet;
405     g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL);
406     TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
407     uwRet = osSemaphoreAcquire(g_cmsisSemSema, osWaitForever);
408     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
409 
410     uwRet = osSemaphoreGetCount(g_cmsisSemSema);
411     TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX - 1, uwRet);
412     uwRet = osSemaphoreDelete(g_cmsisSemSema);
413     TEST_ASSERT_EQUAL_INT(osOK, uwRet);
414 };
415 
416 /**
417  * @tc.number    : SUB_KERNEL_CMSIS_SEM_OPERATION_2300
418  * @tc.name      : semaphore get count operation with semaphore_id = NULL
419  * @tc.desc      : [C- SOFTWARE -0200]
420  */
421 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount004, Function | MediumTest | Level1)
422 {
423     osStatus_t uwRet;
424     uwRet = osSemaphoreGetCount(NULL);
425     TEST_ASSERT_EQUAL_INT(0, uwRet);
426 
427 };
428 
429 RUN_TEST_SUITE(CmsisSemFuncTestSuite);
430