• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "securec.h"
34 #ifdef LOSCFG_KERNEL_CPPSUPPORT
35 #include "los_cppsupport.h"
36 #endif
37 #if defined(TEST3518E) || defined(TEST3516A) || defined(TEST3516EV200)
38 #include "eth_drv.h"
39 #endif
40 #if !defined(LOSCFG_AARCH64) && !defined(TESTISP)
41 #include "console.h"
42 #else
43 #include "los_config.h"
44 #endif
45 #include "los_sem_pri.h"
46 #include "los_mux_pri.h"
47 #include "los_queue_pri.h"
48 #include "los_swtmr_pri.h"
49 
50 #ifdef __cplusplus
51 #if __cplusplus
52 extern "C" {
53 #endif /* __cpluscplus */
54 #endif /* __cpluscplus */
55 UINT32 g_shellTestQueueID;
56 
57 UINT32 g_testTskHandle;
58 UINT32 volatile g_testCount;
59 UINT32 g_flowcheck = 0;
60 UINT32 g_failResult = 0;
61 UINT32 g_passResult = 0;
62 
63 #ifdef TESTPBXA9
snprintf(char * str,unsigned int len,const char * fmt,...)64 int snprintf(char *str, unsigned int len, const char *fmt, ...) {}
65 #endif
66 
67 #ifdef TEST1980
68 UINT32 g_testhwiFlag;
69 UINT32 g_testCpuMask;
70 #endif
71 
72 SPIN_LOCK_S g_testSpin;
73 UINT32 g_testCount1;
74 UINT32 g_testCount2;
75 UINT32 g_testCount3;
76 UINT32 g_testTaskID01;
77 UINT32 g_testTaskID02;
78 UINT32 g_testTaskID03;
79 UINT32 g_testTaskID04;
80 UINT32 g_hwiNum1;
81 UINT32 g_hwiNum2;
82 UINT32 g_semID;
83 UINT32 g_semID2;
84 LosMux g_mutexkernelTest;
85 UINT32 g_cpupTestCount;
86 UINT32 g_waitTestCount;
87 UINT32 g_testPeriod;
88 
89 UINT16 g_swTmrID;
90 UINT32 g_testQueueID01;
91 UINT32 g_testQueueID02;
92 UINT32 g_testQueueID03;
93 UINT32 g_leavingTaskNum;
94 UINT32 g_getTickConsume = 0;
95 EVENT_CB_S g_eventCB;
96 EVENT_CB_S g_event;
97 UINT32 g_testCircleCount = 0;
98 INT32 g_performanceStart = -1;
99 
100 #define MOUNT_PATH NFS_MOUNT_DIR
101 UINT32 g_fatFilesystem;
102 UINT8 g_mIndex;
103 UINT32 g_semID3[LOSCFG_BASE_IPC_SEM_CONFIG + 1];
104 LOS_MEM_POOL_STATUS g_sysMemStatus = { 0 };
105 
106 #if TEST_MODULE_CHECK == 1
107 
108 extern UINT32 g_failModelResult[];
109 extern UINT32 g_passModelResult[];
110 extern UINT32 g_executModelNum[];
111 extern ICUNIT_CASE_S g_errorCase[];
112 #endif
113 extern char *g_strLayer[];
114 extern char *g_strLevel[];
115 extern char *g_strType[];
116 
117 extern char *g_strModule[];
118 extern UINT32 g_modelNum;
119 
120 #ifdef LOSCFG_TEST_FS_FAT
121 #define TEST_FAT32 0x02
122 #define TEST_EXFAT 0x04
123 #endif
124 
125 BOOL g_isSpinorInit = FALSE;
126 BOOL g_isSdInit = FALSE;
127 BOOL g_isUartDevInit = FALSE;
128 BOOL g_isTcpipInit = FALSE;
129 BOOL g_isInitSerial = FALSE;
130 UINT32 g_vfsCyclesCount = 0;
131 INT32 g_serialInitFlag = -1;
132 BOOL g_isAddArray = TRUE;
133 BOOL g_isUsbInit = FALSE;
134 BOOL g_isIpcGmacInit = FALSE;
135 
136 BOOL g_isDriversRandomInit = FALSE;
137 
138 BOOL g_isHisiEthSetPhyModeInit = FALSE;
139 
140 BOOL g_isVfsInit = FALSE;
141 
TRandom(VOID)142 u_long TRandom(VOID)
143 {
144     u_long t;
145     long x, hi, lo;
146     UINT64 cpuCycle;
147     UINT32 high, low;
148     extern VOID LOS_GetCpuCycle(UINT32 * puwCntHi, UINT32 * puwCntLo);
149     LOS_GetCpuCycle(&high, &low);
150     cpuCycle = (((UINT64)high << 30) + low); // 30, generate a seed.
151     x = cpuCycle;
152     hi = x / 127773; // 127773, generate a seed.
153     lo = x % 127773; // 127773, generate a seed.
154     t = 16807 * lo - 2836 * hi; // 16807, 2836, generate a seed.
155     if (t <= 0)
156         t += 0x7fffffff;
157     return (u_long)(t);
158 }
159 
LosMuxCreate(LosMux * mutex)160 UINT32 LosMuxCreate(LosMux *mutex)
161 {
162     return LOS_MuxInit(mutex, NULL);
163 }
164 
TaskCountGetTest(VOID)165 UINT32 TaskCountGetTest(VOID)
166 {
167     UINT32 loop;
168     UINT32 taskCnt = 0;
169     UINT32 intSave;
170     LosTaskCB *taskCB = (LosTaskCB *)NULL;
171 
172     intSave = LOS_IntLock();
173     for (loop = 0; loop < g_taskMaxNum; loop++) {
174         taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
175         if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
176             continue;
177         }
178         taskCnt++;
179     }
180     (VOID)LOS_IntRestore(intSave);
181     return taskCnt;
182 }
183 
SemCountGetTest(VOID)184 UINT32 SemCountGetTest(VOID)
185 {
186     UINT32 loop;
187     UINT32 semCnt = 0;
188     UINT32 intSave;
189     LosSemCB *semNode = (LosSemCB *)NULL;
190 
191     intSave = LOS_IntLock();
192     for (loop = 0; loop < LOSCFG_BASE_IPC_SEM_CONFIG; loop++) {
193         semNode = GET_SEM(loop);
194         if (semNode->semStat == OS_SEM_USED) {
195             semCnt++;
196         }
197     }
198     (VOID)LOS_IntRestore(intSave);
199     return semCnt;
200 }
201 
QueueCountGetTest(VOID)202 UINT32 QueueCountGetTest(VOID)
203 {
204     UINT32 loop;
205     UINT32 queueCnt = 0;
206     UINT32 intSave;
207     LosQueueCB *queueCB = (LosQueueCB *)NULL;
208 
209     intSave = LOS_IntLock();
210     queueCB = g_allQueue;
211     for (loop = 0; loop < LOSCFG_BASE_IPC_QUEUE_CONFIG; loop++, queueCB++) {
212         if (queueCB->queueState == OS_QUEUE_INUSED) {
213             queueCnt++;
214         }
215     }
216     (VOID)LOS_IntRestore(intSave);
217     return queueCnt;
218 }
219 
SwtmrCountGetTest(VOID)220 UINT32 SwtmrCountGetTest(VOID)
221 {
222     UINT32 loop;
223     UINT32 swTmrCnt = 0;
224     UINT32 intSave;
225     SWTMR_CTRL_S *swTmrCB = (SWTMR_CTRL_S *)NULL;
226 
227     intSave = LOS_IntLock();
228     swTmrCB = g_swtmrCBArray;
229     for (loop = 0; loop < LOSCFG_BASE_CORE_SWTMR_CONFIG; loop++, swTmrCB++) {
230         if (swTmrCB->ucState != OS_SWTMR_STATUS_UNUSED) {
231             swTmrCnt++;
232         }
233     }
234     (VOID)LOS_IntRestore(intSave);
235     return swTmrCnt;
236 }
237 #ifdef TEST1980
TestHwiTrigger(unsigned int irq)238 VOID TestHwiTrigger(unsigned int irq)
239 {
240     int i;
241     HalIrqSendIpi(g_testCpuMask, irq);
242     for (i = 0; i < 0xff; i++) {
243     }
244 }
245 #else
TestHwiTrigger(unsigned int irq)246 void TestHwiTrigger(unsigned int irq)
247 {
248     extern void Dsb(void);
249     extern void HalIrqPending(unsigned int vector);
250     extern VOID HalIrqUnmask(unsigned int vector);
251 
252     HalIrqUnmask(irq);
253     HalIrqPending(irq);
254     Dsb();
255     Dsb();
256     Dsb();
257 }
258 #endif
259 
TestExtraTaskDelay(UINT32 tick)260 VOID TestExtraTaskDelay(UINT32 tick)
261 {
262 #ifdef LOSCFG_KERNEL_SMP
263     // trigger task schedule may occor on another core
264     // needs adding delay and checking status later
265     LOS_TaskDelay(tick);
266 #else
267     // do nothing
268 #endif
269 }
270 
TestTickCountGet(VOID)271 UINT64 TestTickCountGet(VOID)
272 {
273     /* not use LOS_TickCountGet for now,
274        cause every timer is not match with others.
275        use cpu0 timer instead. */
276     return LOS_TickCountGet();
277 }
278 
TestTickCountByCurrCpuid(VOID)279 UINT64 TestTickCountByCurrCpuid(VOID)
280 {
281     return LOS_TickCountGet();
282 }
283 
284 /*
285  * different from calling LOS_TaskDelay,
286  * this func will not yield this task to another one.
287  */
TestBusyTaskDelay(UINT32 tick)288 VOID TestBusyTaskDelay(UINT32 tick)
289 {
290     UINT64 runtime;
291 
292     runtime = TestTickCountByCurrCpuid() + tick;
293     while (1) {
294         if (runtime <= TestTickCountByCurrCpuid()) {
295             break;
296         }
297         WFI;
298     }
299 }
300 
TestAssertBusyTaskDelay(UINT32 timeout,UINT32 flag)301 VOID TestAssertBusyTaskDelay(UINT32 timeout, UINT32 flag)
302 {
303     UINT64 runtime;
304 
305     runtime = TestTickCountGet() + timeout;
306     while (1) {
307         if ((runtime <= TestTickCountGet()) || (g_testCount == flag)) {
308             break;
309         }
310         WFI;
311     }
312 }
313 
TestTestHwiDelete(unsigned int irq,VOID * devId)314 VOID TestTestHwiDelete(unsigned int irq, VOID *devId)
315 {
316     HwiIrqParam stuwIrqPara;
317 
318     if (OS_INT_ACTIVE)
319         return;
320 
321     stuwIrqPara.swIrq = irq;
322     stuwIrqPara.pDevId = devId;
323 
324     (VOID)LOS_HwiDelete(irq, &stuwIrqPara);
325     return;
326 }
327 
TestDumpCpuid(VOID)328 VOID TestDumpCpuid(VOID)
329 {
330 #ifdef LOSCFG_KERNEL_SMP
331     PRINT_DEBUG("%d,cpuid = %d\n", LOS_CurTaskIDGet(), ArchCurrCpuid());
332 #endif
333     return;
334 }
335 
336 #if defined(LOSCFG_COMPAT_POSIX)
PosixPthreadInit(pthread_attr_t * attr,int pri)337 UINT32 PosixPthreadInit(pthread_attr_t *attr, int pri)
338 {
339     UINT32 ret;
340     struct sched_param sp;
341 
342     ret = pthread_attr_init(attr);
343     ICUNIT_GOTO_EQUAL(ret, 0, ret, NOK);
344 
345     attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
346 
347     sp.sched_priority = pri;
348     ret = pthread_attr_setschedparam(attr, &sp);
349     ICUNIT_GOTO_EQUAL(ret, 0, ret, NOK);
350 
351     ret = pthread_attr_setschedpolicy(attr, SCHED_RR);
352     ICUNIT_GOTO_EQUAL(ret, 0, ret, NOK);
353 
354     return LOS_OK;
355 NOK:
356     return LOS_NOK;
357 }
358 
PosixPthreadDestroy(pthread_attr_t * attr,pthread_t thread)359 UINT32 PosixPthreadDestroy(pthread_attr_t *attr, pthread_t thread)
360 {
361     UINT32 ret;
362 
363     ret = pthread_join(thread, NULL);
364     ICUNIT_GOTO_EQUAL(ret, 0, ret, NOK);
365 
366     ret = pthread_attr_destroy(attr);
367     ICUNIT_GOTO_EQUAL(ret, 0, ret, NOK);
368 
369     return LOS_OK;
370 NOK:
371     return LOS_NOK;
372 }
373 #endif
374 
375 
TestKernelBaseCore(VOID)376 VOID TestKernelBaseCore(VOID)
377 {
378 #if defined(LOSCFG_TEST_KERNEL_BASE_CORE)
379     ItSuiteLosTask();
380     ItSuiteLosSwtmr();
381     ItSuiteSmpHwi();
382     ItSuiteHwiNesting();
383 #endif
384 }
385 
TestKernelBaseIpc(VOID)386 VOID TestKernelBaseIpc(VOID)
387 {
388 #if defined(LOSCFG_TEST_KERNEL_BASE_IPC)
389     ItSuiteLosEvent();
390     ItSuiteLosMux();
391     ItSuiteLosSem();
392     ItSuiteLosQueue();
393 #endif
394 }
395 
TestKernelBase(VOID)396 VOID TestKernelBase(VOID)
397 {
398 
399 #if defined(LOSCFG_TEST_KERNEL_BASE)
400     TestKernelBaseCore();
401     TestKernelBaseIpc();
402 #endif
403 }
404 
TestPosixMutex(VOID)405 VOID TestPosixMutex(VOID)
406 {
407 #if defined(LOSCFG_TEST_POSIX_MUTEX)
408     ItSuitePosixMutex();
409 #endif
410 }
411 
TestPosixPthread(VOID)412 VOID TestPosixPthread(VOID)
413 {
414 #if defined(LOSCFG_TEST_POSIX_PTHREAD)
415     ItSuitePosixPthread();
416 #endif
417 }
418 
TestPosix(VOID)419 VOID TestPosix(VOID)
420 {
421 #if defined(LOSCFG_TEST_POSIX)
422     TestPosixMutex();
423     TestPosixPthread();
424 #endif
425 }
426 
TestKernelExtendCpup(VOID)427 VOID TestKernelExtendCpup(VOID)
428 {
429 #if defined(LOSCFG_TEST_KERNEL_EXTEND_CPUP)
430     ItSuiteExtendCpup();
431 #endif
432 }
433 
TestKernelExtend(VOID)434 VOID TestKernelExtend(VOID)
435 {
436 #if defined(LOSCFG_TEST_KERNEL_EXTEND)
437     TestKernelExtendCpup();
438 #endif
439 }
440 
TestReset(VOID)441 VOID TestReset(VOID)
442 {
443 #if defined(TEST3559A) || defined(TEST3559A_M7) || defined(TEST3516EV200) || defined(LOSCFG_LLTREPORT) || \
444     defined(LITEOS_3RDPARTY_THTTPD_TEST) || defined(TESTISP)
445 #else
446 #ifdef LOSCFG_SHELL
447     extern VOID cmd_reset(VOID);
448     cmd_reset();
449 #endif
450 #endif
451 }
452 
TestTaskEntry(UINT32 param1,UINT32 param2,UINT32 param3,UINT32 param4)453 VOID TestTaskEntry(UINT32 param1, UINT32 param2, UINT32 param3, UINT32 param4)
454 {
455     UINT32 i;
456 
457     INT32 ret = LOS_SetProcessScheduler(LOS_GetCurrProcessID(), LOS_SCHED_RR, 20); // 20, set a reasonable priority.
458     if (ret != LOS_OK) {
459         dprintf("%s set test process schedule failed! %d\n", ret);
460     }
461 
462     ret = LOS_SetTaskScheduler(LOS_CurTaskIDGet(), LOS_SCHED_RR, TASK_PRIO_TEST);
463     if (ret != LOS_OK) {
464         dprintf("%s set test task schedule failed! %d\n", ret);
465     }
466 
467     g_testCircleCount = 0;
468     dprintf("\t\n --- Test start--- \n");
469 
470 #if (TEST_LESSER_MEM == 1)
471     UINT32 memusedfirst = 0x600000; // 6M for fs or 3M for kernel
472     LOS_MEM_POOL_STATUS status = { 0 };
473     LOS_MemInfoGet(OS_SYS_MEM_ADDR, &status);
474     LOS_MemAlloc(OS_SYS_MEM_ADDR, status.uwTotalFreeSize - memusedfirst);
475 #endif
476 
477 #if defined(LOSCFG_TEST)
478     for (i = 0; i < 1; i++) {
479         g_testCircleCount++;
480         ICunitInit();
481 
482         TestKernelExtend();
483         TestKernelBase();
484         TestPosix();
485 
486 #if (TEST_MODULE_CHECK == 1) && defined(LOSCFG_TEST)
487         for (int i = 0; i < g_modelNum - 1; i++) {
488             if (g_executModelNum[i] != 0) {
489                 dprintf("\nExecuted Model: %s, Executed Model_Num: %d ,failed_count: %d , sucess_count :%d",
490                     g_strModule[i], g_executModelNum[i], g_failModelResult[i], g_passModelResult[i]);
491             }
492             for (int j = 0; j < g_failResult && j < 50; j++) { // 50
493                 if (i == g_errorCase[j].testcase_module) {
494                     LOS_Msleep(200); // 200, delay.
495                     dprintf(" \n [Failed]-%s-%s-%s-%s-%s-[Errline: %d RetCode:0x%04X%04X]", g_errorCase[j].pcCaseID,
496                         g_strLayer[g_errorCase[j].testcase_layer], g_strModule[g_errorCase[j].testcase_module],
497                         g_strLevel[g_errorCase[j].testcase_level], g_strType[g_errorCase[j].testcase_type],
498                         g_errorCase[j].errLine, (iUINT16)((g_errorCase[j].retCode) >> 16), // 16
499                         (iUINT16)(g_errorCase[j].retCode));
500                 }
501             }
502         }
503         dprintf("\nNot Executed Model: ");
504         for (int i = 0; i < g_modelNum - 1; i++) {
505             if (g_executModelNum[i] == 0) {
506                 LOS_Msleep(40); // 40, delay.
507                 dprintf("%s    ", g_strModule[i]);
508             }
509         }
510 #endif
511         dprintf("\n\ntest_count: %d,failed count: %d, success count: %d\n", g_testCircleCount, g_failResult,
512             g_passResult);
513     }
514     LOS_Msleep(200); // 200, delay.
515 #endif
516     dprintf("\t\n --- Test End--- \n");
517 }
518 
TestSystemInit(void)519 void TestSystemInit(void)
520 {
521     INT32 pid;
522     LosProcessCB *testProcess = NULL;
523 
524     InitRebootHook();
525 
526     pid = LOS_Fork(0, "IT_TST_INI", (TSK_ENTRY_FUNC)TestTaskEntry, 0x30000);
527     if (pid < 0) {
528         return;
529     }
530 
531     testProcess = OS_PCB_FROM_PID(pid);
532     g_testTskHandle = testProcess->threadGroupID;
533 #ifdef LOSCFG_KERNEL_SMP
534     ((LosTaskCB *)OS_TCB_FROM_TID(g_testTskHandle))->cpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
535 #endif
536 }
537 
538 #ifdef __cplusplus
539 #if __cplusplus
540 }
541 #endif /* __cpluscplus */
542 #endif /* __cpluscplus */
543