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 (void)memset_s(g_iCunitCaseArray, sizeof(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
211 return (iUINT32)ICUNIT_SUCCESS;
212 }
213
ICunitRunF(ICUNIT_CASE_S * psubCase)214 iUINT32 ICunitRunF(ICUNIT_CASE_S *psubCase)
215 {
216 iUINT32 caseRet;
217 UINT32 curTestTaskID;
218 g_iCunitErrLineNo = 0;
219 g_iCunitErrCode = 0;
220
221 #if TEST_RESOURCELEAK_CHECK == 1
222 extern UINT32 LOS_MemTotalUsedGet(VOID * pPool);
223 extern HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM];
224 extern SWTMR_CTRL_S *g_swtmrCBArray;
225 static SWTMR_CTRL_S *swtmr;
226 iUINT32 i;
227 static UINT32 gAuwMemuse[ARRAY_SIZE];
228 static UINT32 gUwTskNum[ARRAY_SIZE];
229 static UINT32 gUwSwtNum[ARRAY_SIZE];
230 static UINT32 gUwHwiNum[ARRAY_SIZE];
231 static UINT32 gUwQueueNum[ARRAY_SIZE];
232 LosQueueCB *queueCB = NULL;
233 static UINT32 gUwSemNum[ARRAY_SIZE];
234 static LosSemCB *semNode;
235 UINT32 muxCnt[ARRAY_SIZE];
236
237 (void)memset_s(gUwSwtNum, sizeof(gUwSwtNum), 0, sizeof(gUwSwtNum));
238 (void)memset_s(gUwHwiNum, sizeof(gUwHwiNum), 0, sizeof(gUwHwiNum));
239 (void)memset_s(gUwTskNum, sizeof(gUwTskNum), 0, sizeof(gUwTskNum));
240 (void)memset_s(gAuwMemuse, sizeof(gAuwMemuse), 0, sizeof(gAuwMemuse));
241 (void)memset_s(gUwQueueNum, sizeof(gUwQueueNum), 0, sizeof(gUwQueueNum));
242 (void)memset_s(gUwSemNum, sizeof(gUwSemNum), 0, sizeof(gUwSemNum));
243
244 curTestTaskID = LOS_CurTaskIDGet();
245
246 // task
247 for (i = 0; i <= LOSCFG_BASE_CORE_TSK_LIMIT; i++) {
248 if (g_taskCBArray[i].taskStatus == OS_TASK_STATUS_UNUSED)
249 gUwTskNum[0]++;
250 }
251
252 // swtmr
253 swtmr = g_swtmrCBArray;
254 for (i = 0; i < LOSCFG_BASE_CORE_SWTMR_LIMIT; i++, swtmr++) {
255 if (swtmr->ucState == OS_SWTMR_STATUS_UNUSED)
256 gUwSwtNum[0]++;
257 }
258
259 // hwi
260 for (i = 0; i < OS_HWI_MAX_NUM; i++) {
261 if ((g_hwiForm[i].pfnHook == (HWI_PROC_FUNC)NULL) && (g_hwiForm[i].uwParam == 0))
262 gUwHwiNum[0]++;
263 }
264
265 // sem
266 for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) {
267 semNode = GET_SEM(i);
268 if (semNode->semStat == OS_SEM_UNUSED) {
269 gUwSemNum[0]++;
270 }
271 }
272
273 // queue
274 queueCB = g_allQueue;
275 for (i = 0; i < LOSCFG_BASE_IPC_QUEUE_LIMIT; i++, queueCB++) {
276 if (queueCB->queueState == OS_QUEUE_UNUSED) {
277 gUwQueueNum[0]++;
278 }
279 }
280
281 gAuwMemuse[0] = LOS_MemTotalUsedGet(OS_SYS_MEM_ADDR);
282
283 if (g_performanceStart <= 0) {
284 dprintf("# Enter:%s \n", psubCase->pcCaseID);
285 }
286 caseRet = psubCase->pstCaseFunc();
287
288 if (g_performanceStart <= 0) {
289 if ((strcmp(psubCase->pcCaseID, "LLT_PLAT_004") == 0) ||
290 (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_MUTIPTHREAD_001") == 0) ||
291 (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_PRESSURE_013") == 0) ||
292 (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_PRESSURE_052") == 0) ||
293 (strcmp(psubCase->pcCaseID, "IT_FS_JFFS_026") == 0) ||
294 (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_004") == 0) ||
295 (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_009") == 0) ||
296 (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_013") == 0) ||
297 (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_017") == 0) ||
298 (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_018") == 0) ||
299 (strcmp(psubCase->pcCaseID, "IT_PARTITION_JFFS_039") == 0) ||
300 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_PRESSURE_001") == 0) ||
301 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_151") == 0) ||
302 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_040") == 0) ||
303 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_MULTIPTHREAD_000") == 0) ||
304 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_MULTIPTHREAD_033") == 0) ||
305 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_MULTIPTHREAD_034") == 0) ||
306 (strcmp(psubCase->pcCaseID, "IT_FS_FATVP_363") == 0) ||
307 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_VIRPART_012") == 0) ||
308 (strcmp(psubCase->pcCaseID, "IT_PARTITION_DISK_001") == 0) ||
309 (strcmp(psubCase->pcCaseID, "IT_FS_NFS_PRESSURE_013") == 0) ||
310 (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_019") == 0) ||
311 (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_017") == 0) ||
312 (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_013") == 0) ||
313 (strcmp(psubCase->pcCaseID, "IT_PARTITION_Yaffs_009") == 0) ||
314 (strcmp(psubCase->pcCaseID, "LLT_VFS_FAT_002") == 0) ||
315 (strcmp(psubCase->pcCaseID, "IT_FS_FAT_363") == 0) || (strcmp(psubCase->pcCaseID, "LLT_FS_VFS_004") == 0) ||
316 (strcmp(psubCase->pcCaseID, "LLT_FS_RAMFS_003") == 0) ||
317 (strcmp(psubCase->pcCaseID, "LLT_FS_RAMFS_001") == 0)) {
318 dprintf(" [Case]-%s-%s-%s-%s-%s,unrunning!!!\n", psubCase->pcCaseID, g_strLayer[psubCase->testcase_layer],
319 g_strModule[psubCase->testcase_module], g_strLevel[psubCase->testcase_level],
320 g_strType[psubCase->testcase_type]);
321 goto ENDING;
322 }
323
324 gAuwMemuse[1] = LOS_MemTotalUsedGet(OS_SYS_MEM_ADDR);
325
326 // task
327 for (i = 0; i <= LOSCFG_BASE_CORE_TSK_LIMIT; i++) {
328 if (g_taskCBArray[i].taskStatus == OS_TASK_STATUS_UNUSED)
329 gUwTskNum[1]++;
330 }
331
332 // swtmr
333 swtmr = g_swtmrCBArray;
334 for (i = 0; i < LOSCFG_BASE_CORE_SWTMR_LIMIT; i++, swtmr++) {
335 if (swtmr->ucState == OS_SWTMR_STATUS_UNUSED)
336 gUwSwtNum[1]++;
337 }
338
339 // hwi
340 for (i = 0; i < OS_HWI_MAX_NUM; i++) {
341 if ((g_hwiForm[i].pfnHook == (HWI_PROC_FUNC)NULL) && (g_hwiForm[i].uwParam == 0))
342 gUwHwiNum[1]++;
343 }
344
345 // sem
346 for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) {
347 semNode = GET_SEM(i);
348 if (semNode->semStat == OS_SEM_UNUSED) {
349 gUwSemNum[1]++;
350 }
351 }
352
353 // queue
354 queueCB = g_allQueue;
355 for (i = 0; i < LOSCFG_BASE_IPC_QUEUE_LIMIT; i++, queueCB++) {
356 if (queueCB->queueState == OS_QUEUE_UNUSED) {
357 gUwQueueNum[1]++;
358 }
359 }
360
361 if (gUwSemNum[1] != gUwSemNum[0]) {
362 dprintf("\n[Case Resource Leak Failed]------------------Sem used:%d Semleak:%d\n", gUwSemNum[1],
363 (gUwSemNum[1] - gUwSemNum[0]));
364 }
365
366 if (gUwQueueNum[1] != gUwQueueNum[0]) {
367 dprintf("\n[Case Resource Leak Failed]------------------Queue used:%d Queueleak:%d\n", gUwQueueNum[1],
368 (gUwQueueNum[1] - gUwQueueNum[0]));
369 }
370
371 if (gUwTskNum[1] != gUwTskNum[0]) {
372 dprintf("\n[Case Resource Leak Failed]------------------Task used:%d Taskleak:%d\n", gUwTskNum[1],
373 (gUwTskNum[1] - gUwTskNum[0]));
374 }
375
376 if (gUwSwtNum[1] != gUwSwtNum[0]) {
377 dprintf("\n[Case Resource Leak Failed]------------------Swtmr used:%d Swtmrleak:%d\n", gUwSwtNum[1],
378 (gUwSwtNum[1] - gUwSwtNum[0]));
379 }
380
381 if (gUwHwiNum[1] != gUwHwiNum[0]) {
382 dprintf("\n[Case Resource Leak Failed]------------------Hwi used:%d Hwileak:%d\n", gUwHwiNum[1],
383 (gUwHwiNum[1] - gUwHwiNum[0]));
384 }
385
386 if (gAuwMemuse[1] != gAuwMemuse[0]) {
387 dprintf("\n[Case Resource Leak Failed]------------------Mem used:%d Memleak:%d\n", gAuwMemuse[1],
388 (gAuwMemuse[1] - gAuwMemuse[0]));
389 }
390 }
391
392 #else
393 if (g_performanceStart <= 0) {
394 curTestTaskID = LOS_CurTaskIDGet();
395 dprintf("# T:%d Enter:%s \n", curTestTaskID, psubCase->pcCaseID);
396 }
397 caseRet = psubCase->pstCaseFunc();
398 #endif
399
400 psubCase->errLine = g_iCunitErrLineNo;
401 psubCase->retCode = (0 == g_iCunitErrLineNo) ? (caseRet) : (g_iCunitErrCode);
402
403 #if TEST_MODULE_CHECK == 1
404 g_executModelNum[psubCase->testcase_module]++;
405 #endif
406 ENDING:
407 if (psubCase->errLine == 0 && caseRet == 0) {
408 g_passResult++;
409
410 #if TEST_MODULE_CHECK == 1
411 g_passModelResult[psubCase->testcase_module]++;
412 #endif
413
414 if (g_performanceStart <= 0) {
415 dprintf(" T:%d [Passed]-%s-%s-%s-%s-%s\n", curTestTaskID, psubCase->pcCaseID,
416 g_strLayer[psubCase->testcase_layer], g_strModule[psubCase->testcase_module],
417 g_strLevel[psubCase->testcase_level], g_strType[psubCase->testcase_type]);
418 }
419 } else {
420 #if TEST_MODULE_CHECK == 1
421 if (g_failResult < 50) { // 50
422 g_errorCase[g_failResult] = *psubCase;
423 }
424 g_failModelResult[psubCase->testcase_module]++;
425 #endif
426
427 g_iCunitCaseFailedCnt++;
428 g_failResult++;
429 dprintf(" T:%d [Failed]-%s-%s-%s-%s-%s-[Errline: %d RetCode:0x%04X%04X]\n", curTestTaskID, psubCase->pcCaseID,
430 g_strLayer[psubCase->testcase_layer], g_strModule[psubCase->testcase_module],
431 g_strLevel[psubCase->testcase_level], g_strType[psubCase->testcase_type], psubCase->errLine,
432 (iUINT16)((psubCase->retCode) >> 16), (iUINT16)(psubCase->retCode)); // 16
433
434 #ifdef LOSCFG_SHELL
435 dprintf("\n\n ********************************************************** \n");
436 OsShellCmdSystemInfo(0, NULL);
437 dprintf("\n ********************************************************** \n");
438 const CHAR *taskAll = "-a";
439 OsShellCmdDumpTask(1, &taskAll);
440 dprintf(" ********************************************************** \n\n\n");
441 #endif
442 }
443
444 return (iUINT32)ICUNIT_SUCCESS;
445 }
446
ICunitRunTestArray(const char * tcSequence,const char * tcNum,const char * tcLayer,const char * tcModule,const char * tcLevel,const char * tcType)447 INT32 ICunitRunTestArray(const char *tcSequence, const char *tcNum, const char *tcLayer, const char *tcModule,
448 const char *tcLevel, const char *tcType)
449 {
450 iUINT32 testcaseNum;
451 iUINT32 testcaseLayer = 0xFFFF;
452 iUINT32 testcaseModule = 0xFFFF;
453 iUINT32 testcaseLevel = 0xFFFF;
454 iUINT32 testcaseType = 0xFFFF;
455 iUINT32 ilayer;
456 iUINT32 imodule;
457 iUINT32 ilevel;
458 iUINT32 itype;
459
460 testcaseNum = atoi(tcNum);
461 if (testcaseNum > 0xFFFF) {
462 dprintf("[testcase_Num]-%u is too large \n", testcaseNum);
463
464 testcaseNum = 0xFFFF;
465 }
466
467 for (ilayer = 0; ilayer <= TEST_LAYER_ALL; ilayer++) {
468 if (strcmp(g_strLayer[ilayer], tcLayer) == 0) {
469 testcaseLayer = ilayer;
470 dprintf("[testcase_Layer]-%s \n", g_strLayer[ilayer]);
471
472 break;
473 }
474 }
475
476 if (testcaseLayer == 0xFFFF) {
477 dprintf("[testcase_Layer]-%s is invalid \n", tcLayer);
478
479 return (iUINT32)ICUNIT_SUCCESS;
480 }
481
482 for (imodule = 0; imodule <= TEST_MODULE_ALL; imodule++) {
483 if (strcmp(g_strModule[imodule], tcModule) == 0) {
484 testcaseModule = imodule;
485 dprintf("[testcase_Module]-%s \n", g_strModule[imodule]);
486
487 break;
488 }
489 }
490
491 if (testcaseModule == 0xFFFF) {
492 dprintf("[testcase_Module]-%s is invalid \n", tcModule);
493
494 return (iUINT32)ICUNIT_SUCCESS;
495 }
496
497 for (ilevel = 0; ilevel <= TEST_LEVEL_ALL; ilevel++) {
498 if (strcmp(g_strLevel[ilevel], tcLevel) == 0) {
499 testcaseLevel = ilevel;
500 dprintf("[testcase_Level]-%s \n", g_strLevel[ilevel]);
501
502 break;
503 }
504 }
505
506 if (testcaseLevel == 0xFFFF) {
507 dprintf("[testcase_Level]-%s is invalid \n", tcLevel);
508
509 return (iUINT32)ICUNIT_SUCCESS;
510 }
511
512 for (itype = 0; itype <= TEST_TYPE_ALL; itype++) {
513 if (strcmp(g_strType[itype], tcType) == 0) {
514 testcaseType = itype;
515 dprintf("[testcase_Type]-%s \n", g_strType[itype]);
516
517 break;
518 }
519 }
520
521 if (testcaseType == 0xFFFF) {
522 dprintf("[testcase_Type]-%s is invalid \n", tcType);
523
524 return (iUINT32)ICUNIT_SUCCESS;
525 }
526
527 if (0 == strncmp(tcSequence, "SEQUENCE", 8)) { // 8, "SEQUENCE" length
528 dprintf("[testcase_Sequence]-%s \n", tcSequence);
529
530 ICunitRunTestArraySequence(testcaseNum, testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
531 } else if (0 == strncmp(tcSequence, "RANDOM", 6)) { // 6, "RANDOM" length
532 dprintf("[testcase_Random]-%s \n", tcSequence);
533
534 ICunitRunTestArrayRandom(testcaseNum, testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
535 } else {
536 dprintf("[testcase_Sequence]-%s is invalid \n", tcSequence);
537 }
538
539 g_failResult = 0;
540 g_passResult = 0;
541
542 return (iUINT32)ICUNIT_SUCCESS;
543 }
544
ICunitRunTestArraySequence(iUINT32 testcaseNum,iUINT32 testcaseLayer,iUINT32 testcaseModule,iUINT32 testcaseLevel,iUINT32 testcaseType)545 iUINT32 ICunitRunTestArraySequence(iUINT32 testcaseNum, iUINT32 testcaseLayer, iUINT32 testcaseModule,
546 iUINT32 testcaseLevel, iUINT32 testcaseType)
547 {
548 iUINT32 num;
549 iUINT32 idx;
550 iUINT32 idx1;
551 iUINT32 failedCount;
552 iUINT32 successCount;
553
554 idx1 = g_iCunitCaseCnt;
555
556 for (num = 0; num < testcaseNum; num++) {
557 failedCount = g_failResult;
558 successCount = g_passResult;
559
560 for (idx = 0; idx < idx1; idx++) {
561 ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[idx]), testcaseLayer, testcaseModule, testcaseLevel,
562 testcaseType);
563 }
564 }
565
566 return (iUINT32)ICUNIT_SUCCESS;
567 }
568
569
ICunitRunTestArrayRandom(iUINT32 testcaseNum,iUINT32 testcaseLayer,iUINT32 testcaseModule,iUINT32 testcaseLevel,iUINT32 testcaseType)570 iUINT32 ICunitRunTestArrayRandom(iUINT32 testcaseNum, iUINT32 testcaseLayer, iUINT32 testcaseModule,
571 iUINT32 testcaseLevel, iUINT32 testcaseType)
572 {
573 iUINT32 num;
574 iUINT32 idx;
575 iUINT32 idx1;
576 iUINT32 randIdx;
577 ICUNIT_CASE_S subCaseArrayTemp;
578 iUINT32 failedCount;
579 iUINT32 successCount;
580
581 (void)memset_s(&subCaseArrayTemp, sizeof(ICUNIT_CASE_S), 0, sizeof(ICUNIT_CASE_S));
582
583 idx1 = g_iCunitCaseCnt;
584
585 for (num = 0; num < testcaseNum; num++) {
586 failedCount = g_failResult;
587 successCount = g_passResult;
588
589 for (idx = idx1 - 1; idx > 1; idx--) {
590 (void)memset_s(&subCaseArrayTemp, sizeof(ICUNIT_CASE_S), 0, sizeof(ICUNIT_CASE_S));
591
592 randIdx = ICunitRand() % idx;
593 subCaseArrayTemp = g_iCunitCaseArray[randIdx];
594 g_iCunitCaseArray[randIdx] = g_iCunitCaseArray[idx];
595 g_iCunitCaseArray[idx] = subCaseArrayTemp;
596 ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[idx]), testcaseLayer, testcaseModule, testcaseLevel,
597 testcaseType);
598 }
599
600 ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[1]), testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
601 ICunitRunTestcaseSatisfied(&(g_iCunitCaseArray[0]), testcaseLayer, testcaseModule, testcaseLevel, testcaseType);
602 }
603
604 return (iUINT32)ICUNIT_SUCCESS;
605 }
606
607 extern iUINT32 ICunitRunTestcaseOne(ICUNIT_CASE_S *testCase);
608
ICunitRunTestOne(const char * tcId)609 iUINT32 ICunitRunTestOne(const char *tcId)
610 {
611 iUINT32 idx;
612 iUINT32 idx1;
613 ICUNIT_CASE_S subCaseArrayTemp;
614
615 (void)memset_s(&subCaseArrayTemp, sizeof(ICUNIT_CASE_S), 0, sizeof(ICUNIT_CASE_S));
616
617 idx1 = g_iCunitCaseCnt;
618
619 for (idx = 0; idx < idx1; idx++) {
620 (void)memset_s(&subCaseArrayTemp, sizeof(ICUNIT_CASE_S), 0, sizeof(ICUNIT_CASE_S));
621 subCaseArrayTemp = g_iCunitCaseArray[idx];
622
623 if (strcmp(subCaseArrayTemp.pcCaseID, tcId) == 0) {
624 ICunitRunTestcaseOne(&g_iCunitCaseArray[idx]);
625 }
626 }
627
628 return (iUINT32)ICUNIT_SUCCESS;
629 }
630
ICunitRunTestcaseSatisfied(ICUNIT_CASE_S * testCase,iUINT32 testcaseLayer,iUINT32 testcaseModule,iUINT32 testcaseLevel,iUINT32 testcaseType)631 iUINT32 ICunitRunTestcaseSatisfied(ICUNIT_CASE_S *testCase, iUINT32 testcaseLayer, iUINT32 testcaseModule,
632 iUINT32 testcaseLevel, iUINT32 testcaseType)
633 {
634 /* reserve interface to extend */
635 if (((testCase->testcase_layer == testcaseLayer) || (testcaseLayer == TEST_LAYER_ALL)) &&
636 ((testCase->testcase_module == testcaseModule) || (testcaseModule == TEST_MODULE_ALL)) &&
637 ((testCase->testcase_level == testcaseLevel) || (testcaseLevel == TEST_LEVEL_ALL)) &&
638 ((testCase->testcase_type == testcaseType) || (testcaseType == TEST_TYPE_ALL))) {
639 ICunitRunSingle(testCase);
640 }
641
642 return (iUINT32)ICUNIT_SUCCESS;
643 }
644
ICunitRunTestcaseOne(ICUNIT_CASE_S * testCase)645 iUINT32 ICunitRunTestcaseOne(ICUNIT_CASE_S *testCase)
646 {
647 ICunitRunSingle(testCase);
648 return (iUINT32)ICUNIT_SUCCESS;
649 }
650
651
652 #ifndef TST_DRVPRINT
PtSaveReport(iCHAR * iCunitReportName,iCHAR * name,iUINT32 value)653 iUINT32 PtSaveReport(iCHAR *iCunitReportName, iCHAR *name, iUINT32 value)
654 {
655 return ICUNIT_SUCCESS;
656 }
657 #endif
658
659 #ifdef __cplusplus
660 #if __cplusplus
661 }
662 #endif /* __cpluscplus */
663 #endif /* __cpluscplus */
664