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_NULL(g_cmsisSemSema);
92 };
93
94 /**
95 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0400
96 * @tc.name : semaphore operation for creat when Semaphhore count = 0 and 0
97 * @tc.desc : [C- SOFTWARE -0200]
98 */
99 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew004, Function | MediumTest | Level1)
100 {
101 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT0, NULL);
102 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
103 osSemaphoreDelete(g_cmsisSemSema);
104 osDelay(DELAY_TICKS_5);
105 };
106
107 /**
108 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0500
109 * @tc.name : semaphore operation for creat when Semaphhore count = 1 and 1
110 * @tc.desc : [C- SOFTWARE -0200]
111 */
112 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew005, Function | MediumTest | Level1)
113 {
114 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
115 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
116 osSemaphoreDelete(g_cmsisSemSema);
117 osDelay(DELAY_TICKS_5);
118 };
119
120 /**
121 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0600
122 * @tc.name : semaphore operation for creat when Semaphhore count = 10 and 10
123 * @tc.desc : [C- SOFTWARE -0200]
124 */
125 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew006, Function | MediumTest | Level1)
126 {
127 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT10, NULL);
128 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
129 osSemaphoreDelete(g_cmsisSemSema);
130 osDelay(DELAY_TICKS_5);
131 };
132
133 /**
134 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0700
135 * @tc.name : semaphore operation for creat when Semaphhore count = 0xFE and 0
136 * @tc.desc : [C- SOFTWARE -0200]
137 */
138 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew007, Function | MediumTest | Level1)
139 {
140 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_INT0, NULL);
141 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
142 osSemaphoreDelete(g_cmsisSemSema);
143 osDelay(DELAY_TICKS_5);
144 };
145
146 /**
147 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0800
148 * @tc.name : semaphore operation for creat when Semaphhore count = 0 and 0xFE
149 * @tc.desc : [C- SOFTWARE -0200]
150 */
151 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew008, Function | MediumTest | Level1)
152 {
153 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_HEX_MAX, NULL);
154 TEST_ASSERT_NULL(g_cmsisSemSema);
155 };
156
157 /**
158 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0900
159 * @tc.name : semaphore operation for delete
160 * @tc.desc : [C- SOFTWARE -0200]
161 */
162 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete001, Function | MediumTest | Level1)
163 {
164 osStatus_t uwRet;
165 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL);
166 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
167
168 uwRet = osSemaphoreDelete(g_cmsisSemSema);
169 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
170 };
171
172 /**
173 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1000
174 * @tc.name : semaphore delete operation twice
175 * @tc.desc : [C- SOFTWARE -0200]
176 */
177 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete002, Function | MediumTest | Level1)
178 {
179 osStatus_t uwRet;
180 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL);
181 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
182
183 uwRet = osSemaphoreDelete(g_cmsisSemSema);
184 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
185
186 uwRet = osSemaphoreDelete(g_cmsisSemSema);
187 TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
188 };
189
190 /**
191 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1100
192 * @tc.name : semaphore delete operation with semaphore_id = NULL
193 * @tc.desc : [C- SOFTWARE -0200]
194 */
195 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete003, Function | MediumTest | Level1)
196 {
197 osStatus_t uwRet;
198 uwRet = osSemaphoreDelete(NULL);
199 TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
200
201 };
202
203 /**
204 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1200
205 * @tc.name : semaphore operation for acquire when Semaphhore count = 1 and 1
206 * @tc.desc : [C- SOFTWARE -0200]
207 */
208 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire001, Function | MediumTest | Level1)
209 {
210 osStatus_t uwRet;
211 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
212 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
213 uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
214 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
215
216 uwRet = osSemaphoreDelete(g_cmsisSemSema);
217 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
218 };
219
220 /**
221 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1300
222 * @tc.name : semaphore operation for acquire when Semaphhore count = 1 and 0
223 * @tc.desc : [C- SOFTWARE -0200]
224 */
225 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire002, Function | MediumTest | Level1)
226 {
227 osStatus_t uwRet;
228 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
229 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
230 uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
231 TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
232
233 uwRet = osSemaphoreDelete(g_cmsisSemSema);
234 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
235 };
236
237 /**
238 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1400
239 * @tc.name : semaphore operation for acquire when Semaphhore count = 0 and 1
240 * @tc.desc : [C- SOFTWARE -0200]
241 */
242 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire003, Function | MediumTest | Level1)
243 {
244 osStatus_t uwRet;
245 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL);
246 TEST_ASSERT_NULL(g_cmsisSemSema);
247 };
248
249 /**
250 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1500
251 * @tc.name : semaphore acquire operation with semaphore_id = NULL
252 * @tc.desc : [C- SOFTWARE -0200]
253 */
254 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire004, Function | MediumTest | Level1)
255 {
256 osStatus_t uwRet;
257 uwRet = osSemaphoreAcquire(NULL, 0);
258 TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
259
260 };
261
262 /**
263 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1600
264 * @tc.name : semaphore operation for release
265 * @tc.desc : [C- SOFTWARE -0200]
266 */
267 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease001, Function | MediumTest | Level1)
268 {
269 osStatus_t uwRet;
270 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
271 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
272
273 uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
274 TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
275
276 uwRet = osSemaphoreRelease(g_cmsisSemSema);
277 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
278
279 uwRet = osSemaphoreDelete(g_cmsisSemSema);
280 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
281 };
282
283 /**
284 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1700
285 * @tc.name : semaphore release operation twice
286 * @tc.desc : [C- SOFTWARE -0200]
287 */
288 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease002, Function | MediumTest | Level1)
289 {
290 osStatus_t uwRet;
291 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
292 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
293
294 uwRet = osSemaphoreRelease(g_cmsisSemSema);
295 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
296 uwRet = osSemaphoreRelease(g_cmsisSemSema);
297 TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
298
299 uwRet = osSemaphoreDelete(g_cmsisSemSema);
300 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
301 };
302
303 /**
304 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1800
305 * @tc.name : semaphore operation for release after semaphore acquire
306 * @tc.desc : [C- SOFTWARE -0200]
307 */
308 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease003, Function | MediumTest | Level1)
309 {
310 osStatus_t uwRet;
311 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
312 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
313
314 uwRet = osSemaphoreRelease(g_cmsisSemSema);
315 TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
316
317 uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0);
318 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
319
320 uwRet = osSemaphoreRelease(g_cmsisSemSema);
321 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
322 uwRet = osSemaphoreRelease(g_cmsisSemSema);
323 TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);
324
325 uwRet = osSemaphoreDelete(g_cmsisSemSema);
326 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
327 };
328
329 /**
330 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1900
331 * @tc.name : semaphore release operation with semaphore_id = NULL
332 * @tc.desc : [C- SOFTWARE -0200]
333 */
334 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease004, Function | MediumTest | Level1)
335 {
336 osStatus_t uwRet;
337 uwRet = osSemaphoreRelease(NULL);
338 TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
339
340 };
341
342 /**
343 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2000
344 * @tc.name : semaphore operation for get count when Semaphhore count = 1 or 0xFE
345 * @tc.desc : [C- SOFTWARE -0200]
346 */
347 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount001, Function | MediumTest | Level1)
348 {
349 osStatus_t uwRet;
350 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL);
351 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
352 uwRet = osSemaphoreGetCount(g_cmsisSemSema);
353 TEST_ASSERT_EQUAL_INT(1, uwRet);
354 uwRet = osSemaphoreDelete(g_cmsisSemSema);
355 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
356
357 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL);
358 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
359 uwRet = osSemaphoreGetCount(g_cmsisSemSema);
360 TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX, uwRet);
361 uwRet = osSemaphoreDelete(g_cmsisSemSema);
362 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
363 };
364
365 /**
366 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2100
367 * @tc.name : semaphore operation for get count when Semaphhore count = 1 or 0
368 * @tc.desc : [C- SOFTWARE -0200]
369 */
370 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount002, Function | MediumTest | Level1)
371 {
372 osStatus_t uwRet;
373 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL);
374 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
375 uwRet = osSemaphoreGetCount(g_cmsisSemSema);
376 TEST_ASSERT_EQUAL_INT(0, uwRet);
377 uwRet = osSemaphoreDelete(g_cmsisSemSema);
378 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
379
380 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL);
381 TEST_ASSERT_NULL(g_cmsisSemSema);
382 };
383
384 /**
385 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2200
386 * @tc.name : semaphore operation for get count
387 * @tc.desc : [C- SOFTWARE -0200]
388 */
389 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount003, Function | MediumTest | Level1)
390 {
391 osStatus_t uwRet;
392 g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL);
393 TEST_ASSERT_NOT_NULL(g_cmsisSemSema);
394 uwRet = osSemaphoreAcquire(g_cmsisSemSema, osWaitForever);
395 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
396
397 uwRet = osSemaphoreGetCount(g_cmsisSemSema);
398 TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX - 1, uwRet);
399 uwRet = osSemaphoreDelete(g_cmsisSemSema);
400 TEST_ASSERT_EQUAL_INT(osOK, uwRet);
401 };
402
403 /**
404 * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2300
405 * @tc.name : semaphore get count operation with semaphore_id = NULL
406 * @tc.desc : [C- SOFTWARE -0200]
407 */
408 LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount004, Function | MediumTest | Level1)
409 {
410 osStatus_t uwRet;
411 uwRet = osSemaphoreGetCount(NULL);
412 TEST_ASSERT_EQUAL_INT(0, uwRet);
413
414 };
415
416 RUN_TEST_SUITE(CmsisSemFuncTestSuite);
417