• 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 "iCunit.h"
33 #include "iCunit.inc"
34 #include "iCunit_config.h"
35 #include "osTest.h"
36 #if TEST_RESOURCELEAK_CHECK == 1
37 #include "los_swtmr_pri.h"
38 #include "los_sem_pri.h"
39 #include "los_queue_pri.h"
40 #include "los_task_pri.h"
41 #include "los_mux_pri.h"
42 #endif
43 #include <stdio.h>
44 
45 #ifdef __cplusplus
46 #if __cplusplus
47 extern "C" {
48 #endif /* __cpluscplus */
49 #endif /* __cpluscplus */
50 
51 #define ARRAY_SIZE 2
52 
53 #ifdef LOSCFG_KERNEL_SMP
54 LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_testSuitSpin);
55 #endif
56 
57 extern UINT32 g_failResult;
58 extern UINT32 g_passResult;
59 
60 extern int atoi(const char *str);
61 extern int strncmp(const char *s1, const char *s2, size_t n);
62 
63 char *g_strLayer[] = {"LOS", "POSIX", "LIB", "VFS", "EXTEND",
64                       "PARTITION", "CPP", "SHELL", "LINUX", "USB",
65 #if defined(LOSCFG_3RDPARTY_TEST)
66                       "TEST_3RDPARTY",
67 #endif
68                       "DRIVER", "ALL"
69                      };
70 
71 char *g_strModule[] = {"TASK", "MEM", "SEM", "MUX", "EVENT", "QUE", "SWTMR", "HWI", "MP", "ATO", "CPUP", "SCATTER", "RUNSTOP", "TIMER", "MMU",
72                        "ROBIN", "LIBC", "WAIT", "VFAT", "JFFS", "RAMFS", "NFS", "PROC", "FS", "UART",
73                        "PTHREAD", "COMP", "HWI_HALFBOTTOM", "WORKQ", "WAKELOCK", "TIMES",
74                        "LIBM", "SUPPORT", "STL", "MAIL", "MSG", "CP", "SIGNAL", "SCHED", "MTDCHAR", "TIME", "WRITE", "READ", "DYNLOAD", "REGISTER",
75                        "UNAME", "ERR", "CMD", "TICKLESS", "TRACE", "UNALIGNACCESS", "EXC", "REQULATOR", "DEVFREQ", "CPUFREQ", "TEST_MISC",
76 #if defined(LOSCFG_3RDPARTY_TEST)
77                        "THTTPD", "BIDIREFC", "CJSON", "CURL", "FFMPEG", "FREETYPE", "INIPARSER", "JSONCPP", "LIBICONV", "LIBJPEG", "LIBPNG", "OPENEXIF", "OPENSSL",
78                        "OPUS", "SQLITE", "TINYXML", "XML2", "ZBAR", "HARFBUZZ",
79 #endif
80                        "TEST_DRIVERBASE", "ALL"
81                       };
82 UINT32 g_modelNum = sizeof(g_strModule) / sizeof(g_strModule[0]);
83 
84 #if TEST_MODULE_CHECK == 1
85 
86 UINT32 g_failModelResult[sizeof(g_strModule) / sizeof(g_strModule[0])] = {0};
87 UINT32 g_passModelResult[sizeof(g_strModule) / sizeof(g_strModule[0])] = {0};
88 UINT32 g_executModelNum[sizeof(g_strModule) / sizeof(g_strModule[0])] = {0};
89 ICUNIT_CASE_S g_errorCase[50] = {0};
90 
91 #endif
92 
93 char *g_strLevel[] = {"LEVEL0", "LEVEL1", "LEVEL2", "LEVEL3", "LEVEL4", "ALL"};
94 char *g_strType[] = {"FUNCTION", "PRESSURE", "PERFORMANCE", "ALL"};
95 char *g_strSequence[] = {"SEQUENCE", "RANDOM"};
96 
97 
ICunitRand(void)98 u_long ICunitRand(void)
99 {
100     static u_long randseed;
101     u_long t;
102     long x, hi, lo;
103     UINT32 high = 0;
104     UINT32 low = 0;
105 
106     extern VOID LOS_GetCpuCycle(UINT32 * puwCntHi, UINT32 * puwCntLo);
107     LOS_GetCpuCycle(&high, &low);
108     randseed = ((u_long)(high << 30) + low); // 30, generate a seed.
109 
110     /*
111      * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
112      * From "Random number generators: good ones are hard to find",
113      * Park and Miller, Communications of the ACM, vol. 31, no. 10,
114      * October 1988, p. 1195.
115      */
116     x = randseed;
117     hi = x / 127773;            // 127773, generate a seed.
118     lo = x % 127773;            // 127773, generate a seed.
119     t = 16807 * lo - 2836 * hi; // 16807, 2836, generate a seed.
120     if (t <= 0)
121         t += 0x7fffffff;
122     randseed = t;
123     return (u_long)(t);
124 }
125 
ICunitSaveErr(iiUINT32 line,iiUINT32 retCode)126 void ICunitSaveErr(iiUINT32 line, iiUINT32 retCode)
127 {
128 #ifdef LOSCFG_KERNEL_SMP
129     UINT32 intSave;
130     TESTSUIT_LOCK(intSave);
131 #endif
132     g_iCunitErrCode = ((g_iCunitErrCode == 0) && (g_iCunitErrLineNo == 0)) ? (iiUINT32)retCode : g_iCunitErrCode;
133     g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? line : g_iCunitErrLineNo;
134 #ifdef LOSCFG_KERNEL_SMP
135     TESTSUIT_UNLOCK(intSave);
136 #endif
137 }
138 
139 #undef LOSCFG_TEST_LEVEL
140 #define LOSCFG_TEST_LEVEL 0
ICunitAddCase(const iCHAR * caseName,CASE_FUNCTION caseFunc,iUINT16 testcaseLayer,iUINT16 testcaseModule,iUINT16 testcaseLevel,iUINT16 testcaseType)141 iUINT32 ICunitAddCase(const iCHAR *caseName, CASE_FUNCTION caseFunc, iUINT16 testcaseLayer, iUINT16 testcaseModule,
142     iUINT16 testcaseLevel, iUINT16 testcaseType)
143 {
144     iUINT16 idx;
145 
146     if (g_iCunitInitSuccess) {
147         return (iUINT32)ICUNIT_UNINIT;
148     }
149 
150     /* Don't run Firstly with Python */
151     if (g_iCunitCaseRun == 0) {
152         return (iUINT32)ICUNIT_SUCCESS;
153     }
154 
155 #if defined(LITEOS_TESTSUIT_SHELL) || defined(LOSCFG_TEST_MUTIL)
156     idx = g_iCunitCaseCnt;
157 #else
158     idx = 0;
159 #endif
160     if (idx == ICUNIT_CASE_SIZE) {
161         g_iCunitErrLogAddCase++;
162         return (iUINT32)ICUNIT_CASE_FULL;
163     }
164 
165     g_iCunitCaseArray[idx].pcCaseID = caseName;
166     g_iCunitCaseArray[idx].pstCaseFunc = caseFunc;
167     g_iCunitCaseArray[idx].testcase_layer = testcaseLayer;
168     g_iCunitCaseArray[idx].testcase_module = testcaseModule;
169     g_iCunitCaseArray[idx].testcase_level = testcaseLevel;
170     g_iCunitCaseArray[idx].testcase_type = testcaseType;
171 
172 #if defined(LITEOS_TESTSUIT_SHELL) || defined(LOSCFG_TEST_MUTIL)
173     g_iCunitCaseCnt++;
174 #else
175     ICunitRunSingle(&g_iCunitCaseArray[idx]);
176 #endif
177 
178 #if defined(LOSCFG_TEST_MUTIL)
179     ICunitRunSingle(&g_iCunitCaseArray[idx]);
180 #endif
181 
182     return (iUINT32)ICUNIT_SUCCESS;
183 }
184 UINT32 g_cunitInitFlag = 0;
ICunitInit(void)185 iUINT32 ICunitInit(void)
186 {
187 #ifdef LOSCFG_KERNEL_SMP
188     if (LOS_AtomicCmpXchg32bits(&g_cunitInitFlag, 1, 0)) {
189         PRINTK("other core already done iCunitInit\n");
190         return (iUINT32)ICUNIT_SUCCESS;
191     }
192 #endif
193     g_iCunitInitSuccess = 0x0000;
194     g_iCunitCaseCnt = 0x0000;
195     g_iCunitCaseFailedCnt = 0;
196     g_iCunitErrLogAddCase = 0;
197     memset(g_iCunitCaseArray, 0, sizeof(g_iCunitCaseArray));
198     g_iCunitCaseRun = 1;
199 
200     return (iUINT32)ICUNIT_SUCCESS;
201 }
202 
ICunitRunSingle(ICUNIT_CASE_S * psubCase)203 iUINT32 ICunitRunSingle(ICUNIT_CASE_S *psubCase)
204 {
205     if ((g_isSpinorInit == FALSE) && (psubCase->testcase_module == TEST_JFFS))
206         dprintf("****** Jffs is not support ! ******  \n");
207     else
208         ICunitRunF(psubCase);
209 
210     return (iUINT32)ICUNIT_SUCCESS;
211 }
212 
ICunitRunF(ICUNIT_CASE_S * psubCase)213 iUINT32 ICunitRunF(ICUNIT_CASE_S *psubCase)
214 {
215     iUINT32 caseRet;
216     UINT32 curTestTaskID;
217     g_iCunitErrLineNo = 0;
218     g_iCunitErrCode = 0;
219 
220 #if TEST_RESOURCELEAK_CHECK == 1
221     extern UINT32 LOS_MemTotalUsedGet(VOID * pPool);
222     extern HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM];
223     extern SWTMR_CTRL_S *g_swtmrCBArray;
224     static SWTMR_CTRL_S *swtmr;
225     iUINT32 i;
226     static UINT32 gAuwMemuse[ARRAY_SIZE];
227     static UINT32 gUwTskNum[ARRAY_SIZE];
228     static UINT32 gUwSwtNum[ARRAY_SIZE];
229     static UINT32 gUwHwiNum[ARRAY_SIZE];
230     static UINT32 gUwQueueNum[ARRAY_SIZE];
231     LosQueueCB *queueCB = NULL;
232     static UINT32 gUwSemNum[ARRAY_SIZE];
233     static LosSemCB *semNode;
234     UINT32 muxCnt[ARRAY_SIZE];
235 
236     memset(gUwSwtNum, 0, sizeof(gUwSwtNum));
237     memset(gUwHwiNum, 0, sizeof(gUwHwiNum));
238     memset(gUwTskNum, 0, sizeof(gUwTskNum));
239     memset(gAuwMemuse, 0, sizeof(gAuwMemuse));
240     memset(gUwQueueNum, 0, sizeof(gUwQueueNum));
241     memset(gUwSemNum, 0, sizeof(gUwSemNum));
242 
243     curTestTaskID = LOS_CurTaskIDGet();
244 
245     // task
246     for (i = 0; i <= LOSCFG_BASE_CORE_TSK_LIMIT; i++) {
247         if (g_taskCBArray[i].taskStatus == OS_TASK_STATUS_UNUSED)
248             gUwTskNum[0]++;
249     }
250 
251     // swtmr
252     swtmr = g_swtmrCBArray;
253     for (i = 0; i < LOSCFG_BASE_CORE_SWTMR_LIMIT; i++, swtmr++) {
254         if (swtmr->ucState == OS_SWTMR_STATUS_UNUSED)
255             gUwSwtNum[0]++;
256     }
257 
258     // hwi
259     for (i = 0; i < OS_HWI_MAX_NUM; i++) {
260         if ((g_hwiForm[i].pfnHook == (HWI_PROC_FUNC)NULL) && (g_hwiForm[i].uwParam == 0))
261             gUwHwiNum[0]++;
262     }
263 
264     // sem
265     for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) {
266         semNode = GET_SEM(i);
267         if (semNode->semStat == OS_SEM_UNUSED) {
268             gUwSemNum[0]++;
269         }
270     }
271 
272     // queue
273     queueCB = g_allQueue;
274     for (i = 0; i < LOSCFG_BASE_IPC_QUEUE_LIMIT; i++, queueCB++) {
275         if (queueCB->queueState == OS_QUEUE_UNUSED) {
276             gUwQueueNum[0]++;
277         }
278     }
279 
280     gAuwMemuse[0] = LOS_MemTotalUsedGet(OS_SYS_MEM_ADDR);
281 
282     if (g_performanceStart <= 0) {
283         dprintf("# Enter:%s \n", psubCase->pcCaseID);
284     }
285     caseRet = psubCase->pstCaseFunc();
286 
287     if (g_performanceStart <= 0) {
288         if ((strcmp(psubCase->pcCaseID, "LLT_PLAT_004") == 0) ||
289             (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_MUTIPTHREAD_001") == 0) ||
290             (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_PRESSURE_013") == 0) ||
291             (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_PRESSURE_052") == 0) ||
292             (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_026") == 0) ||
293             (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_004") == 0) ||
294             (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_009") == 0) ||
295             (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_013") == 0) ||
296             (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_017") == 0) ||
297             (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_018") == 0) ||
298             (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_039") == 0) ||
299             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_PRESSURE_001") == 0) ||
300             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_151") == 0) ||
301             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_040") == 0) ||
302             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_MULTIPTHREAD_000") == 0) ||
303             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_MULTIPTHREAD_033") == 0) ||
304             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_MULTIPTHREAD_034") == 0) ||
305             (strcmp(psubCase->pcCaseID, "IT_FS_FATVP_363") == 0) ||
306             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_012") == 0) ||
307             (strcmp(psubCase->pcCaseID, "IT_PARTITION_DISK_001") == 0) ||
308             (strcmp(psubCase->pcCaseID, "IT_FS_NFS_PRESSURE_013") == 0) ||
309             (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_019") == 0) ||
310             (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_017") == 0) ||
311             (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_013") == 0) ||
312             (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_009") == 0) ||
313             (strcmp(psubCase->pcCaseID, "LLT_VFS_FAT_002") == 0) ||
314             (strcmp(psubCase->pcCaseID, "IT_FS_FAT_363") == 0) || (strcmp(psubCase->pcCaseID, "LLT_FS_VFS_004") == 0) ||
315             (strcmp(psubCase->pcCaseID, "LLT_FS_RAMFS_003") == 0) ||
316             (strcmp(psubCase->pcCaseID, "LLT_FS_RAMFS_001") == 0)) {
317             dprintf("  [Case]-%s-%s-%s-%s-%s,unrunning!!!\n", psubCase->pcCaseID, g_strLayer[psubCase->testcase_layer],
318                 g_strModule[psubCase->testcase_module], g_strLevel[psubCase->testcase_level],
319                 g_strType[psubCase->testcase_type]);
320             goto ENDING;
321         }
322 
323         gAuwMemuse[1] = LOS_MemTotalUsedGet(OS_SYS_MEM_ADDR);
324 
325         // task
326         for (i = 0; i <= LOSCFG_BASE_CORE_TSK_LIMIT; i++) {
327             if (g_taskCBArray[i].taskStatus == OS_TASK_STATUS_UNUSED)
328                 gUwTskNum[1]++;
329         }
330 
331         // swtmr
332         swtmr = g_swtmrCBArray;
333         for (i = 0; i < LOSCFG_BASE_CORE_SWTMR_LIMIT; i++, swtmr++) {
334             if (swtmr->ucState == OS_SWTMR_STATUS_UNUSED)
335                 gUwSwtNum[1]++;
336         }
337 
338         // hwi
339         for (i = 0; i < OS_HWI_MAX_NUM; i++) {
340             if ((g_hwiForm[i].pfnHook == (HWI_PROC_FUNC)NULL) && (g_hwiForm[i].uwParam == 0))
341                 gUwHwiNum[1]++;
342         }
343 
344         // sem
345         for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) {
346             semNode = GET_SEM(i);
347             if (semNode->semStat == OS_SEM_UNUSED) {
348                 gUwSemNum[1]++;
349             }
350         }
351 
352         // queue
353         queueCB = g_allQueue;
354         for (i = 0; i < LOSCFG_BASE_IPC_QUEUE_LIMIT; i++, queueCB++) {
355             if (queueCB->queueState == OS_QUEUE_UNUSED) {
356                 gUwQueueNum[1]++;
357             }
358         }
359 
360         if (gUwSemNum[1] != gUwSemNum[0]) {
361             dprintf("\n[Case Resource Leak Failed]------------------Sem used:%d  Semleak:%d\n", gUwSemNum[1],
362                 (gUwSemNum[1] - gUwSemNum[0]));
363         }
364 
365         if (gUwQueueNum[1] != gUwQueueNum[0]) {
366             dprintf("\n[Case Resource Leak Failed]------------------Queue used:%d  Queueleak:%d\n", gUwQueueNum[1],
367                 (gUwQueueNum[1] - gUwQueueNum[0]));
368         }
369 
370         if (gUwTskNum[1] != gUwTskNum[0]) {
371             dprintf("\n[Case Resource Leak Failed]------------------Task used:%d  Taskleak:%d\n", gUwTskNum[1],
372                 (gUwTskNum[1] - gUwTskNum[0]));
373         }
374 
375         if (gUwSwtNum[1] != gUwSwtNum[0]) {
376             dprintf("\n[Case Resource Leak Failed]------------------Swtmr used:%d  Swtmrleak:%d\n", gUwSwtNum[1],
377                 (gUwSwtNum[1] - gUwSwtNum[0]));
378         }
379 
380         if (gUwHwiNum[1] != gUwHwiNum[0]) {
381             dprintf("\n[Case Resource Leak Failed]------------------Hwi used:%d  Hwileak:%d\n", gUwHwiNum[1],
382                 (gUwHwiNum[1] - gUwHwiNum[0]));
383         }
384 
385         if (gAuwMemuse[1] != gAuwMemuse[0]) {
386             dprintf("\n[Case Resource Leak Failed]------------------Mem used:%d  Memleak:%d\n", gAuwMemuse[1],
387                 (gAuwMemuse[1] - gAuwMemuse[0]));
388         }
389     }
390 
391 #else
392     if (g_performanceStart <= 0) {
393         curTestTaskID = LOS_CurTaskIDGet();
394         dprintf("# T:%d Enter:%s \n", curTestTaskID, psubCase->pcCaseID);
395     }
396     caseRet = psubCase->pstCaseFunc();
397 #endif
398 
399     psubCase->errLine = g_iCunitErrLineNo;
400     psubCase->retCode = (0 == g_iCunitErrLineNo) ? (caseRet) : (g_iCunitErrCode);
401 
402 #if TEST_MODULE_CHECK == 1
403     g_executModelNum[psubCase->testcase_module]++;
404 #endif
405 ENDING:
406     if (psubCase->errLine == 0 && caseRet == 0) {
407         g_passResult++;
408 
409 #if TEST_MODULE_CHECK == 1
410         g_passModelResult[psubCase->testcase_module]++;
411 #endif
412 
413         if (g_performanceStart <= 0) {
414             dprintf(" T:%d [Passed]-%s-%s-%s-%s-%s\n", curTestTaskID, psubCase->pcCaseID,
415                 g_strLayer[psubCase->testcase_layer], g_strModule[psubCase->testcase_module],
416                 g_strLevel[psubCase->testcase_level], g_strType[psubCase->testcase_type]);
417         }
418     } else {
419 #if TEST_MODULE_CHECK == 1
420         if (g_failResult < 50) { // 50
421             g_errorCase[g_failResult] = *psubCase;
422         }
423         g_failModelResult[psubCase->testcase_module]++;
424 #endif
425 
426         g_iCunitCaseFailedCnt++;
427         g_failResult++;
428         dprintf(" T:%d [Failed]-%s-%s-%s-%s-%s-[Errline: %d RetCode:0x%04X%04X]\n", curTestTaskID, psubCase->pcCaseID,
429             g_strLayer[psubCase->testcase_layer], g_strModule[psubCase->testcase_module],
430             g_strLevel[psubCase->testcase_level], g_strType[psubCase->testcase_type], psubCase->errLine,
431             (iUINT16)((psubCase->retCode) >> 16), (iUINT16)(psubCase->retCode)); // 16
432 
433 #ifdef LOSCFG_SHELL
434         dprintf("\n\n ********************************************************** \n");
435         OsShellCmdSystemInfo(0, NULL);
436         dprintf("\n ********************************************************** \n");
437         const CHAR *taskAll = "-a";
438         OsShellCmdDumpTask(1, &taskAll);
439         dprintf(" ********************************************************** \n\n\n");
440 #endif
441     }
442 
443     return (iUINT32)ICUNIT_SUCCESS;
444 }
445 
ICunitRunTestArray(const char * tcSequence,const char * tcNum,const char * tcLayer,const char * tcModule,const char * tcLevel,const char * tcType)446 INT32 ICunitRunTestArray(const char *tcSequence, const char *tcNum, const char *tcLayer, const char *tcModule,
447     const char *tcLevel, const char *tcType)
448 {
449     iUINT32 testcaseNum;
450     iUINT32 testcaseLayer = 0xFFFF;
451     iUINT32 testcaseModule = 0xFFFF;
452     iUINT32 testcaseLevel = 0xFFFF;
453     iUINT32 testcaseType = 0xFFFF;
454     iUINT32 ilayer;
455     iUINT32 imodule;
456     iUINT32 ilevel;
457     iUINT32 itype;
458 
459     testcaseNum = atoi(tcNum);
460     if (testcaseNum > 0xFFFF) {
461         dprintf("[testcase_Num]-%u is too large \n", testcaseNum);
462 
463         testcaseNum = 0xFFFF;
464     }
465 
466     for (ilayer = 0; ilayer <= TEST_LAYER_ALL; ilayer++) {
467         if (strcmp(g_strLayer[ilayer], tcLayer) == 0) {
468             testcaseLayer = ilayer;
469             dprintf("[testcase_Layer]-%s \n", g_strLayer[ilayer]);
470 
471             break;
472         }
473     }
474 
475     if (testcaseLayer == 0xFFFF) {
476         dprintf("[testcase_Layer]-%s is invalid \n", tcLayer);
477 
478         return (iUINT32)ICUNIT_SUCCESS;
479     }
480 
481     for (imodule = 0; imodule <= TEST_MODULE_ALL; imodule++) {
482         if (strcmp(g_strModule[imodule], tcModule) == 0) {
483             testcaseModule = imodule;
484             dprintf("[testcase_Module]-%s \n", g_strModule[imodule]);
485 
486             break;
487         }
488     }
489 
490     if (testcaseModule == 0xFFFF) {
491         dprintf("[testcase_Module]-%s is invalid \n", tcModule);
492 
493         return (iUINT32)ICUNIT_SUCCESS;
494     }
495 
496     for (ilevel = 0; ilevel <= TEST_LEVEL_ALL; ilevel++) {
497         if (strcmp(g_strLevel[ilevel], tcLevel) == 0) {
498             testcaseLevel = ilevel;
499             dprintf("[testcase_Level]-%s \n", g_strLevel[ilevel]);
500 
501             break;
502         }
503     }
504 
505     if (testcaseLevel == 0xFFFF) {
506         dprintf("[testcase_Level]-%s is invalid \n", tcLevel);
507 
508         return (iUINT32)ICUNIT_SUCCESS;
509     }
510 
511     for (itype = 0; itype <= TEST_TYPE_ALL; itype++) {
512         if (strcmp(g_strType[itype], tcType) == 0) {
513             testcaseType = itype;
514             dprintf("[testcase_Type]-%s \n", g_strType[itype]);
515 
516             break;
517         }
518     }
519 
520     if (testcaseType == 0xFFFF) {
521         dprintf("[testcase_Type]-%s is invalid \n", tcType);
522 
523         return (iUINT32)ICUNIT_SUCCESS;
524     }
525 
526     if (0 == strncmp(tcSequence, "SEQUENCE", 8)) { // 8, "SEQUENCE" length
527         dprintf("[testcase_Sequence]-%s \n", tcSequence);
528 
529         ICunitRunTestArraySequence(testcaseNum, testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
530     } else if (0 == strncmp(tcSequence, "RANDOM", 6)) { // 6, "RANDOM" length
531         dprintf("[testcase_Random]-%s \n", tcSequence);
532 
533         ICunitRunTestArrayRandom(testcaseNum, testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
534     } else {
535         dprintf("[testcase_Sequence]-%s is invalid \n", tcSequence);
536     }
537 
538     g_failResult = 0;
539     g_passResult = 0;
540 
541     return (iUINT32)ICUNIT_SUCCESS;
542 }
543 
ICunitRunTestArraySequence(iUINT32 testcaseNum,iUINT32 testcaseLayer,iUINT32 testcaseModule,iUINT32 testcaseLevel,iUINT32 testcaseType)544 iUINT32 ICunitRunTestArraySequence(iUINT32 testcaseNum, iUINT32 testcaseLayer, iUINT32 testcaseModule,
545     iUINT32 testcaseLevel, iUINT32 testcaseType)
546 {
547     iUINT32 num;
548     iUINT32 idx;
549     iUINT32 idx1;
550     iUINT32 failedCount;
551     iUINT32 successCount;
552 
553     idx1 = g_iCunitCaseCnt;
554 
555     for (num = 0; num < testcaseNum; num++) {
556         failedCount = g_failResult;
557         successCount = g_passResult;
558 
559         for (idx = 0; idx < idx1; idx++) {
560             ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[idx]), testcaseLayer, testcaseModule, testcaseLevel,
561                 testcaseType);
562         }
563     }
564 
565     return (iUINT32)ICUNIT_SUCCESS;
566 }
567 
568 
ICunitRunTestArrayRandom(iUINT32 testcaseNum,iUINT32 testcaseLayer,iUINT32 testcaseModule,iUINT32 testcaseLevel,iUINT32 testcaseType)569 iUINT32 ICunitRunTestArrayRandom(iUINT32 testcaseNum, iUINT32 testcaseLayer, iUINT32 testcaseModule,
570     iUINT32 testcaseLevel, iUINT32 testcaseType)
571 {
572     iUINT32 num;
573     iUINT32 idx;
574     iUINT32 idx1;
575     iUINT32 randIdx;
576     ICUNIT_CASE_S subCaseArrayTemp;
577     iUINT32 failedCount;
578     iUINT32 successCount;
579 
580     memset(&subCaseArrayTemp, 0, sizeof(ICUNIT_CASE_S));
581 
582     idx1 = g_iCunitCaseCnt;
583 
584     for (num = 0; num < testcaseNum; num++) {
585         failedCount = g_failResult;
586         successCount = g_passResult;
587 
588         for (idx = idx1 - 1; idx > 1; idx--) {
589             memset(&subCaseArrayTemp, 0, sizeof(ICUNIT_CASE_S));
590 
591             randIdx = ICunitRand() % idx;
592             subCaseArrayTemp = g_iCunitCaseArray[randIdx];
593             g_iCunitCaseArray[randIdx] = g_iCunitCaseArray[idx];
594             g_iCunitCaseArray[idx] = subCaseArrayTemp;
595             ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[idx]), testcaseLayer, testcaseModule, testcaseLevel,
596                 testcaseType);
597         }
598 
599         ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[1]), testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
600         ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[0]), testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
601     }
602 
603     return (iUINT32)ICUNIT_SUCCESS;
604 }
605 
606 extern iUINT32 ICunitRunTestcaseOne(ICUNIT_CASE_S *testCase);
607 
ICunitRunTestOne(const char * tcId)608 iUINT32 ICunitRunTestOne(const char *tcId)
609 {
610     iUINT32 idx;
611     iUINT32 idx1;
612     ICUNIT_CASE_S subCaseArrayTemp;
613 
614     memset(&subCaseArrayTemp, 0, sizeof(ICUNIT_CASE_S));
615 
616     idx1 = g_iCunitCaseCnt;
617 
618     for (idx = 0; idx < idx1; idx++) {
619         memset(&subCaseArrayTemp, 0, sizeof(ICUNIT_CASE_S));
620         subCaseArrayTemp = g_iCunitCaseArray[idx];
621 
622         if (strcmp(subCaseArrayTemp.pcCaseID, tcId) == 0) {
623             ICunitRunTestcaseOne(&g_iCunitCaseArray[idx]);
624         }
625     }
626 
627     return (iUINT32)ICUNIT_SUCCESS;
628 }
629 
ICunitRunTestcaseSatisfied(ICUNIT_CASE_S * testCase,iUINT32 testcaseLayer,iUINT32 testcaseModule,iUINT32 testcaseLevel,iUINT32 testcaseType)630 iUINT32 ICunitRunTestcaseSatisfied(ICUNIT_CASE_S *testCase, iUINT32 testcaseLayer, iUINT32 testcaseModule,
631     iUINT32 testcaseLevel, iUINT32 testcaseType)
632 {
633     /* reserve interface to extend */
634     if (((testCase->testcase_layer == testcaseLayer) || (testcaseLayer == TEST_LAYER_ALL)) &&
635         ((testCase->testcase_module == testcaseModule) || (testcaseModule == TEST_MODULE_ALL)) &&
636         ((testCase->testcase_level == testcaseLevel) || (testcaseLevel == TEST_LEVEL_ALL)) &&
637         ((testCase->testcase_type == testcaseType) || (testcaseType == TEST_TYPE_ALL))) {
638         ICunitRunSingle(testCase);
639     }
640 
641     return (iUINT32)ICUNIT_SUCCESS;
642 }
643 
ICunitRunTestcaseOne(ICUNIT_CASE_S * testCase)644 iUINT32 ICunitRunTestcaseOne(ICUNIT_CASE_S *testCase)
645 {
646     ICunitRunSingle(testCase);
647     return (iUINT32)ICUNIT_SUCCESS;
648 }
649 
650 
651 #ifndef TST_DRVPRINT
PtSaveReport(iCHAR * iCunitReportName,iCHAR * name,iUINT32 value)652 iUINT32 PtSaveReport(iCHAR *iCunitReportName, iCHAR *name, iUINT32 value)
653 {
654     return ICUNIT_SUCCESS;
655 }
656 #endif
657 
658 #ifdef __cplusplus
659 #if __cplusplus
660 }
661 #endif /* __cpluscplus */
662 #endif /* __cpluscplus */
663