1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "osTest.h"
33 #include "los_config.h"
34 #include "los_swtmr.h"
35 #if (LITEOS_CMSIS_TEST == 1)
36 #include "cmsis_os.h"
37 #endif
38 #if (LOS_POSIX_TEST == 1)
39 #include "posix_test.h"
40 #endif
41 #if (LOS_XTS_TEST == 1)
42 #include "xts_test.h"
43 #endif
44
45 UINT32 volatile g_testCount;
46 UINT32 g_testTskHandle;
47 UINT32 g_testTaskID01;
48 UINT32 g_testTaskID02;
49 UINT32 g_testTaskID03;
50 UINT32 g_testTaskID04;
51
52 EVENT_CB_S g_eventCB01;
53 EVENT_CB_S g_eventCB02;
54 EVENT_CB_S g_eventCB03;
55 UINT32 g_mutexTest;
56 EVENT_CB_S g_exampleEvent;
57
58 UINT32 g_hwiNum1;
59 UINT32 g_hwiNum2;
60 UINT32 g_usSemID;
61 UINT32 g_usSemID2;
62 UINT32 g_cpupTestCount;
63 UINT32 g_cmsisRobinCount1;
64 UINT32 g_cmsisCount;
65
66 UINT16 g_usSwTmrID;
67
68 UINT32 g_testQueueID01;
69 UINT32 g_testQueueID02;
70 UINT32 g_testQueueID03;
71
72 UINT16 g_index;
73 UINT32 g_loopCycle = 0xFFFFF;
74
75 UINT32 g_passResult = 0;
76 UINT32 g_failResult = 0;
77 UINT32 g_testTskHandle;
78
79 UINT32 g_leavingTaskNum;
80 UINT32 g_testTaskIdArray[LOSCFG_BASE_CORE_TSK_LIMIT] = {0};
81 UINT32 g_uwGetTickConsume = 0;
82
83 UINT32 g_usSemID3[LOSCFG_BASE_IPC_SEM_CONFIG + 1];
84
85 #define TST_RAMADDRSTART 0x20000000
86 #define TST_RAMADDREND 0x20010000
87
88 extern SWTMR_CTRL_S *g_swtmrCBArray;
SwtmrCountGetTest(VOID)89 UINT32 SwtmrCountGetTest(VOID)
90 {
91 UINT32 loop;
92 UINT32 swTmrCnt = 0;
93 UINT32 intSave;
94 SWTMR_CTRL_S *swTmrCB = (SWTMR_CTRL_S *)NULL;
95
96 intSave = LOS_IntLock();
97 swTmrCB = g_swtmrCBArray;
98 for (loop = 0; loop < LOSCFG_BASE_CORE_SWTMR_LIMIT; loop++, swTmrCB++) {
99 if (swTmrCB->ucState != OS_SWTMR_STATUS_UNUSED) {
100 swTmrCnt++;
101 }
102 }
103 (VOID)LOS_IntRestore(intSave);
104 return swTmrCnt;
105 }
106
107 extern LosQueueCB *g_allQueue;
108
109 #if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
110 extern LosQueueCB *g_staticQueue;
111 #endif
112
QueueUsedCountGet(VOID)113 UINT32 QueueUsedCountGet(VOID)
114 {
115 UINT32 intSave;
116 UINT32 count = 0;
117 UINT32 index;
118
119 intSave = LOS_IntLock();
120 for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
121 LosQueueCB *queueNode = ((LosQueueCB *)g_allQueue) + index;
122 if (queueNode->queueState == OS_QUEUE_INUSED) {
123 count++;
124 }
125 }
126
127 #if (LOSCFG_BASE_IPC_QUEUE_STATIC == 1)
128 for (index = 0; index < LOSCFG_BASE_IPC_STATIC_QUEUE_LIMIT; index++) {
129 LosQueueCB *queueNode = ((LosQueueCB *)g_staticQueue) + index;
130 if (queueNode->queueState == OS_QUEUE_INUSED) {
131 count++;
132 }
133 }
134 #endif
135
136 LOS_IntRestore(intSave);
137
138 return count;
139 }
140
141 extern LosTaskCB *g_taskCBArray;
TaskUsedCountGet(VOID)142 UINT32 TaskUsedCountGet(VOID)
143 {
144 UINT32 intSave;
145 UINT32 count = 0;
146
147 intSave = LOS_IntLock();
148 for (UINT32 index = 0; index < LOSCFG_BASE_CORE_TSK_LIMIT; index++) {
149 LosTaskCB *taskCB = ((LosTaskCB *)g_taskCBArray) + index;
150 if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
151 count++;
152 }
153 }
154 LOS_IntRestore(intSave);
155
156 return (LOSCFG_BASE_CORE_TSK_LIMIT - count);
157 }
158
TestKernel(void)159 void TestKernel(void)
160 {
161 #if (LOS_KERNEL_ATOMIC_TEST == 1)
162 ItSuiteLosAtomic();
163 #endif
164 #if (LOS_KERNEL_CORE_TASK_TEST == 1)
165 ItSuiteLosTask();
166 #endif
167 #if (LOS_KERNEL_IPC_QUEUE_TEST == 1)
168 ItSuiteLosQueue();
169 #endif
170 #if (LOS_KERNEL_IPC_MUX_TEST == 1)
171 ItSuiteLosMux();
172 #endif
173 #if (LOS_KERNEL_IPC_EVENT_TEST == 1)
174 ItSuiteLosEvent();
175 #endif
176 #if (LOS_KERNEL_IPC_SEM_TEST == 1)
177 ItSuiteLosSem();
178 #endif
179 #if (LOS_KERNEL_CORE_SWTMR_TEST == 1)
180 ItSuiteLosSwtmr();
181 #endif
182 #if (LOS_KERNEL_HWI_TEST == 1)
183 ItSuiteLosHwi();
184 #endif
185 #if (LOS_KERNEL_MEM_TEST == 1)
186 ItSuiteLosMem();
187 #endif
188 #if (LOS_KERNEL_DYNLINK_TEST == 1)
189 ItSuiteLosDynlink();
190 #endif
191
192 #if (LOS_KERNEL_LMS_TEST == 1)
193 ItSuiteLosLms();
194 #endif
195
196 #if (LOS_KERNEL_PM_TEST == 1)
197 ItSuiteLosPm();
198 #endif
199
200 #if (LOS_KERNEL_LMK_TEST == 1)
201 ItSuiteLosLmk();
202 #endif
203
204 #if (LOS_KERNEL_SIGNAL_TEST == 1)
205 ItSuiteLosSignal();
206 #endif
207 }
208
209 #if (CMSIS_OS_VER == 2)
TestCmsis2(void)210 void TestCmsis2(void)
211 {
212 #if (LOS_CMSIS2_CORE_TASK_TEST == 1)
213 ItSuite_Cmsis_Los_Task();
214 #endif
215
216 #if (LOS_CMSIS2_IPC_EVENT_TEST == 1)
217 ItSuite_Cmsis_Los_Event();
218 #endif
219 #if (LOS_CMSIS2_CORE_SWTMR_TEST == 1)
220 ItSuite_Cmsis_Los_Swtmr();
221 #endif
222 #if (LOS_CMSIS2_IPC_SEM_TEST == 1)
223 ItSuite_Cmsis_Los_Sem();
224 #endif
225 #if (LOS_CMSIS2_IPC_MUX_TEST == 1)
226 ItSuite_Cmsis_Los_Mux();
227 #endif
228 #if (LOS_CMSIS2_HWI_TEST == 1)
229 ItSuite_Cmsis_Los_Hwi();
230 #endif
231 #if (LOS_CMSIS2_IPC_MSG_TEST == 1)
232 ItSuite_Cmsis_Los_Msg();
233 #endif
234 }
235 #endif
236
TestTaskEntry(VOID)237 VOID TestTaskEntry(VOID)
238 {
239 PRINTF("\t\n --- Test Start --- \n\n");
240 ICunitInit();
241
242 TestKernel();
243
244 #if (LOS_POSIX_TEST == 1)
245 ItSuitePosix();
246 #endif
247
248 #if (LOS_CMSIS_TEST == 1)
249 CmsisFuncTestSuite();
250 #endif
251
252 #if(LOS_XTS_TEST == 1)
253 XtsTestSuite();
254 #endif
255
256 /* The log is used for testing entrance guard, please do not make any changes. */
257 PRINTF("\nfailed count:%d, success count:%d\n", g_failResult, g_passResult);
258 PRINTF("--- Test End ---\n");
259 }
260
los_TestInit(VOID)261 UINT32 los_TestInit(VOID)
262 {
263 UINT32 ret;
264 TSK_INIT_PARAM_S osTaskInitParam = { 0 };
265
266 osTaskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TestTaskEntry;
267 osTaskInitParam.uwStackSize = OS_TSK_TEST_STACK_SIZE;
268 osTaskInitParam.pcName = "IT_TST_INI";
269 osTaskInitParam.usTaskPrio = TASK_PRIO_TEST;
270 osTaskInitParam.uwResved = LOS_TASK_ATTR_JOINABLE;
271
272 ret = LOS_TaskCreate(&g_testTskHandle, &osTaskInitParam);
273 if (LOS_OK != ret) {
274 PRINTF("LosTestInit error\n");
275 }
276 return ret;
277 }
278
LosAppInit(VOID)279 UINT32 LosAppInit(VOID)
280 {
281 UINT32 ret;
282
283 ret = los_TestInit();
284 if (ret != LOS_OK) {
285 return ret;
286 }
287 return LOS_OK;
288 }
289
290 #ifdef __RISC_V__
291 #ifdef LOS_HIMIDEERV100
292 #define HWI_TRIG_BASE 0x20c20
293 #define HWI_CLEAN_TRI 0x20c20
294 #define HIW_SYS_COUNT OS_RISCV_SYS_VECTOR_CNT
295 #elif defined(LOS_HIFONEV320_RV32)
296 #define HWI_TRIG_BASE 0xF8B31000
297 #define HWI_CLEAN_TRI (HWI_TRIG_BASE + 0x04)
298 #define HWI_MASK_IRQ (HWI_TRIG_BASE + 0x0c)
299 #define HIW_SYS_COUNT (26 + 6)
300 #endif
301
TestHwiTrigger(UINT32 hwiNum)302 VOID TestHwiTrigger(UINT32 hwiNum)
303 {
304 HalIrqEnable(hwiNum);
305 }
306
TestHwiDelete(UINT32 hwiNum)307 UINT32 TestHwiDelete(UINT32 hwiNum)
308 {
309 return;
310 }
311
TestHwiClear(UINT32 hwiNum)312 VOID TestHwiClear(UINT32 hwiNum)
313 {
314 return;
315 }
316
317 #define HIGH_SHIFT 32
LosCpuCycleGet(VOID)318 UINT64 LosCpuCycleGet(VOID)
319 {
320 UINT64 timeCycle;
321
322 timeCycle = LOS_SysCycleGet();
323 return timeCycle;
324 }
325 #else
326
327 #define OS_NVIC_SETPEND 0xE000E200
328 #define OS_NVIC_CLRPEND 0xE000E280
329 #define HWI_SHIFT_NUM 5
330 #define HWI_BIT 2
TestHwiTrigger(UINT32 hwiNum)331 VOID TestHwiTrigger(UINT32 hwiNum)
332 {
333 LOS_HwiTrigger(hwiNum);
334 }
335
TestHwiUnTrigger(UINT32 hwiNum)336 VOID TestHwiUnTrigger(UINT32 hwiNum)
337 {
338 LOS_HwiClear(hwiNum);
339 }
340 #define OS_NVIC_CLRENA_BASE 0xE000E180
341 #define NVIC_CLR_IRQ(uwHwiNum) \
342 do { \
343 *(volatile UINT32 *)(OS_NVIC_CLRENA_BASE + (((uwHwiNum) >> HWI_SHIFT_NUM) << HWI_BIT)) = 1 << ((uwHwiNum) & 0x1F); \
344 } while (0)
345
TestHwiDelete(UINT32 hwiNum)346 UINT32 TestHwiDelete(UINT32 hwiNum)
347 {
348 UINT32 ret = LOS_HwiDelete(hwiNum, NULL);
349 if (ret != LOS_OK) {
350 return LOS_NOK;
351 }
352 return LOS_OK;
353 }
TestHwiClear(UINT32 hwiNum)354 VOID TestHwiClear(UINT32 hwiNum) {}
355 #endif
356
357 #if (LOSCFG_BASE_IPC_SEM == 1)
TestSemDelete(UINT32 semHandle)358 UINT32 TestSemDelete(UINT32 semHandle)
359 {
360 return LOS_SemDelete(semHandle);
361 }
362 UINT32 g_usSemID;
363 UINT32 g_usSemID2;
364 UINT32 g_usSemID3[LOSCFG_BASE_IPC_SEM_LIMIT + 1];
365 #endif
366
367