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 #ifndef _UNI_ICUNIT_H 33 #define _UNI_ICUNIT_H 34 35 #include <string.h> 36 #include <stdio.h> 37 #include "los_typedef.h" 38 #include "los_spinlock.h" 39 40 #ifdef TST_DRVPRINT 41 #include "VOS_typdef.h" 42 #include "uartdriver.h" 43 #endif 44 45 #ifdef __cplusplus 46 #if __cplusplus 47 extern "C" { 48 #endif /* __cpluscplus */ 49 #endif /* __cpluscplus */ 50 51 typedef unsigned short iUINT16; 52 typedef unsigned int iUINT32; 53 typedef signed short iINT16; 54 typedef signed long iINT32; 55 typedef char iCHAR; 56 typedef void iVOID; 57 58 typedef unsigned long iiUINT32; 59 60 61 #ifndef FALSE 62 #define FALSE 0 63 #endif 64 #ifndef TRUE 65 #define TRUE 1 66 #endif 67 68 #define FUNCTION_TEST (1 << 0) 69 70 #define PRESSURE_TEST (1 << 1) 71 72 #define PERFORMANCE_TEST (1 << 2) 73 74 #define TEST_MODE (FUNCTION_TEST) 75 76 #define TEST_LESSER_MEM 0 77 78 79 typedef iUINT32 (*CASE_FUNCTION)(void); 80 81 typedef struct { 82 const iCHAR *pcCaseID; 83 CASE_FUNCTION pstCaseFunc; 84 iUINT16 testcase_layer; 85 iUINT16 testcase_module; 86 iUINT16 testcase_level; 87 iUINT16 testcase_type; 88 iiUINT32 retCode; 89 iUINT16 errLine; 90 } ICUNIT_CASE_S; 91 92 typedef struct { 93 iUINT16 uwCaseCnt; 94 iCHAR *pcSuitID; 95 iCHAR *pucFilename; 96 ICUNIT_CASE_S *pstCaseList; 97 iUINT16 passCnt; 98 iUINT16 failCnt; 99 } ICUNIT_SUIT_S; 100 101 typedef enum { 102 TEST_TASK = 0, 103 TEST_MEM, 104 TEST_VM, 105 TEST_SEM, 106 TEST_MUX, 107 TEST_RWLOCK, 108 TEST_EVENT, 109 TEST_QUE, 110 TEST_SWTMR, 111 TEST_HWI, 112 TEST_MP, 113 TEST_ATO, 114 TEST_CPUP, 115 TEST_SCATTER, 116 TEST_RUNSTOP, 117 TEST_TIMER, 118 TEST_MMU, 119 TEST_ROBIN, 120 TEST_LIBC, 121 TEST_WAIT, 122 TEST_VFAT, 123 TEST_JFFS, 124 TEST_RAMFS, 125 TEST_NFS, 126 TEST_PROC, 127 TEST_FS, 128 TEST_UART, 129 TEST_PTHREAD, 130 TEST_COMP, 131 TEST_HWI_HALFBOTTOM, 132 TEST_WORKQ, 133 TEST_WAKELOCK, 134 TEST_TIMES, 135 TEST_LIBM, 136 TEST_SUPPORT, 137 TEST_STL, 138 TEST_MAIL, 139 TEST_MSG, 140 TEST_CP, 141 TEST_SIGNAL, 142 TEST_SCHED, 143 TEST_MTDCHAR, 144 TEST_TIME, 145 TEST_WRITE, 146 TEST_READ, 147 TEST_DYNLOAD, 148 TEST_REGISTER, 149 TEST_UNAME, 150 TEST_ERR, 151 TEST_CMD, 152 TEST_TICKLESS, 153 TEST_TRACE, 154 TEST_UNALIGNACCESS, 155 TEST_EXC, 156 TEST_REQULATOR, 157 TEST_DEVFREQ, 158 TEST_CPUFREQ, 159 TEST_MISC, 160 #if defined(LOSCFG_3RDPARTY_TEST) 161 TEST_THTTPD, 162 TEST_BIDIREFC, 163 TEST_CJSON, 164 TEST_CURL, 165 TEST_FFMPEG, 166 TEST_FREETYPE, 167 TEST_INIPARSER, 168 TEST_JSONCPP, 169 TEST_LIBICONV, 170 TEST_LIBJPEG, 171 TEST_LIBPNG, 172 TEST_OPENEXIF, 173 TEST_OPENSSL, 174 TEST_OPUS, 175 TEST_SQLITE, 176 TEST_TINYXML, 177 TEST_XML2, 178 TEST_ZBAR, 179 TEST_HARFBUZZ, 180 #endif 181 TEST_DRIVERBASE, 182 TEST_UDP, 183 TEST_TCP, 184 TEST_MODULE_ALL, 185 } LiteOS_test_module; 186 187 typedef enum { 188 TEST_LOS = 0, 189 TEST_POSIX, 190 TEST_LIB, 191 TEST_VFS, 192 TEST_EXTEND, 193 TEST_PARTITION, 194 TEST_CPP, 195 TEST_SHELL, 196 TEST_LINUX, 197 TEST_USB, 198 #if defined(LOSCFG_3RDPARTY_TEST) 199 TEST_3RDPARTY, 200 #endif 201 TEST_DRIVERFRAME, 202 TEST_NET_LWIP, 203 TEST_LAYER_ALL, 204 } LiteOS_test_layer; 205 206 typedef enum { 207 TEST_LEVEL0 = 0, 208 TEST_LEVEL1, 209 TEST_LEVEL2, 210 TEST_LEVEL3, 211 TEST_LEVEL4, 212 TEST_LEVEL_ALL, 213 } LiteOS_test_level; 214 215 typedef enum { 216 TEST_FUNCTION = 0, 217 TEST_PRESSURE, 218 TEST_PERFORMANCE, 219 TEST_TYPE_ALL, 220 } LiteOS_test_type; 221 222 typedef enum { 223 TEST_SEQUENCE = 0, 224 TEST_RANDOM 225 } LiteOS_test_sequence; 226 227 extern iUINT16 g_iCunitErrLineNo; 228 extern iiUINT32 g_iCunitErrCode; 229 extern void ICunitSaveErr(iiUINT32 line, iiUINT32 retCode); 230 231 #define ICUNIT_UNINIT 0x0EF00000 232 #define ICUNIT_OPENFILE_FAILED 0x0EF00001 233 #define ICUNIT_ALLOC_FAIL 0x0EF00002 234 #define ICUNIT_SUIT_FULL 0x0EF00002 235 #define ICUNIT_CASE_FULL 0x0EF00003 236 #define ICUNIT_SUIT_ALL 0x0EF0FFFF 237 238 #define ICUNIT_SUCCESS 0x00000000 239 240 #define ICUNIT_TRACK_EQUAL(param, g_value, retcode) \ 241 do { \ 242 if ((param) != (g_value)) { \ 243 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 244 } \ 245 } while (0) 246 247 248 #define ICUNIT_TRACK_NOT_EQUAL(param, g_value, retcode) \ 249 do { \ 250 if ((param) == (g_value)) { \ 251 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 252 } \ 253 } while (0) 254 255 #define ICUNIT_ASSERT_NOT_EQUAL_NULL(param, g_value, retcode) \ 256 do { \ 257 if ((param) == (g_value)) { \ 258 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 259 return NULL; \ 260 } \ 261 } while (0) 262 263 #define ICUNIT_ASSERT_EQUAL_NULL(param, g_value, retcode) \ 264 do { \ 265 if ((param) != (g_value)) { \ 266 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 267 return NULL; \ 268 } \ 269 } while (0) 270 271 #define ICUNIT_ASSERT_EQUAL_VOID(param, g_value, retcode) \ 272 do { \ 273 if ((param) != (g_value)) { \ 274 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 275 return; \ 276 } \ 277 } while (0) 278 279 #define ICUNIT_ASSERT_NOT_EQUAL_VOID(param, g_value, retcode) \ 280 do { \ 281 if ((param) == (g_value)) { \ 282 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 283 return; \ 284 } \ 285 } while (0) 286 287 #define ICUNIT_ASSERT_EQUAL(param, g_value, retcode) \ 288 do { \ 289 if ((param) != (g_value)) { \ 290 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 291 return 1; \ 292 } \ 293 } while (0) 294 295 #define ICUNIT_ASSERT_NOT_EQUAL(param, g_value, retcode) \ 296 do { \ 297 if ((param) == (g_value)) { \ 298 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 299 return 1; \ 300 } \ 301 } while (0) 302 303 #define ICUNIT_ASSERT_WITHIN_EQUAL(param, value1, value2, retcode) \ 304 do { \ 305 if ((param) < (value1) || (param) > (value2)) { \ 306 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 307 return 1; \ 308 } \ 309 } while (0) 310 311 #define ICUNIT_ASSERT_WITHIN_EQUAL_VOID(param, value1, value2, retcode) \ 312 do { \ 313 if ((param) < (value1) || (param) > (value2)) { \ 314 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 315 return; \ 316 } \ 317 } while (0) 318 319 #define ICUNIT_ASSERT_WITHIN_EQUAL_NULL(param, value1, value2, retcode) \ 320 do { \ 321 if ((param) < (value1) || (param) > (value2)) { \ 322 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 323 return; \ 324 } \ 325 } while (0) 326 327 #define ICUNIT_ASSERT_SIZE_STRING_EQUAL(str1, str2, strsize, retcode) \ 328 do { \ 329 if (strncmp((str1), (str2), (strsize)) != 0) { \ 330 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 331 return 1; \ 332 } \ 333 } while (0) 334 335 #define ICUNIT_ASSERT_EQUAL_TIME(param, g_value, retcode, label) \ 336 do { \ 337 if ((param) < (g_value - 1) || (param) > (g_value + 1)) { \ 338 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 339 goto label; \ 340 } \ 341 } while (0) 342 343 #define ICUNIT_ASSERT_STRING_EQUAL(str1, str2, retcode) \ 344 do { \ 345 if (strcmp(str1, str2) != 0) { \ 346 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 347 return 1; \ 348 } \ 349 } while (0) 350 351 #define ICUNIT_ASSERT_STRING_EQUAL_VOID(str1, str2, retcode) \ 352 do { \ 353 if (strcmp(str1, str2) != 0) { \ 354 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 355 return; \ 356 } \ 357 } while (0) 358 359 #define ICUNIT_ASSERT_STRING_NOT_EQUAL(str1, str2, retcode) \ 360 do { \ 361 if (strcmp(str1, str2) == 0) { \ 362 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 363 return 1; \ 364 } \ 365 } while (0) 366 367 #define ICUNIT_GOTO_EQUAL(param, g_value, retcode, label) \ 368 do { \ 369 if ((param) != (g_value)) { \ 370 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 371 goto label; \ 372 } \ 373 } while (0) 374 375 #define ICUNIT_GOTO_EQUAL_IN(param, value1, value2, retcode, label) \ 376 do { \ 377 if (((param) != (value1)) && ((param) != (value2))) { \ 378 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 379 goto label; \ 380 } \ 381 } while (0) 382 383 #define ICUNIT_GOTO_NOT_EQUAL(param, g_value, retcode, label) \ 384 do { \ 385 if ((param) == (g_value)) { \ 386 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 387 goto label; \ 388 } \ 389 } while (0) 390 391 #define ICUNIT_GOTO_WITHIN_EQUAL(param, value1, value2, retcode, label) \ 392 do { \ 393 if ((param) < (value1) || (param) > (value2)) { \ 394 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 395 goto label; \ 396 } \ 397 } while (0) 398 399 #define ICUNIT_GOTO_STRING_EQUAL(str1, str2, retcode, label) \ 400 do { \ 401 if (strcmp(str1, str2) != 0) { \ 402 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 403 goto label; \ 404 } \ 405 } while (0) 406 407 #define ICUNIT_GOTO_STRING_NOT_EQUAL(str1, str2, retcode, label) \ 408 do { \ 409 if (strcmp(str1, str2) == 0) { \ 410 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 411 goto label; \ 412 } \ 413 } while (0) 414 415 #ifdef LOSCFG_KERNEL_SMP 416 extern SPIN_LOCK_S g_testSuitSpin; 417 #define TESTSUIT_LOCK(state) LOS_SpinLockSave(&g_testSuitSpin, &(state)) 418 #define TESTSUIT_UNLOCK(state) LOS_SpinUnlockRestore(&g_testSuitSpin, state) 419 #endif 420 421 extern iUINT32 iCunitAddSuit_F(iCHAR *suitName, iCHAR *pfileName); 422 #define iCunitAddSuit(suitName) iCunitAddSuit_F(suitName, __FILE__) 423 extern iUINT32 ICunitAddCase(const iCHAR *caseName, CASE_FUNCTION caseFunc, iUINT16 testcaseLayer, 424 iUINT16 testcaseModule, iUINT16 testcaseLevel, iUINT16 testcaseType); 425 426 extern iUINT32 ICunitRunTestOne(const char *tcId); 427 extern INT32 ICunitRunTestArray(const char *tcSequence, const char *tcNum, const char *tcLayer, const char *tcModule, 428 const char *tcLevel, const char *tcType); 429 extern iUINT32 ICunitRunTestArraySequence(iUINT32 testcaseNum, iUINT32 testcaseLayer, iUINT32 testcaseModule, 430 iUINT32 testcaseLevel, iUINT32 testcaseType); 431 extern iUINT32 ICunitRunTestArrayRandom(iUINT32 testcaseNum, iUINT32 testcaseLayer, iUINT32 testcaseModule, 432 iUINT32 testcaseLevel, iUINT32 testcaseType); 433 extern iUINT32 ICunitRunTestcaseSatisfied(ICUNIT_CASE_S *testCase, iUINT32 testcaseLayer, iUINT32 testcaseModule, 434 iUINT32 testcaseLevel, iUINT32 testcaseType); 435 436 extern iUINT32 ICunitInit(void); 437 extern iUINT32 ICunitRunSingle(ICUNIT_CASE_S *psubCase); 438 extern iUINT32 ICunitRunF(ICUNIT_CASE_S *psubCase); 439 440 extern iUINT32 iCunitPrintReport(void); 441 442 443 #define TEST_ADD_CASE(name, casefunc, testcase_layer, testcase_module, testcase_level, testcase_type) \ 444 do { \ 445 iUINT32 uwRet = 1; \ 446 uwRet = ICunitAddCase(name, (CASE_FUNCTION)casefunc, testcase_layer, testcase_module, testcase_level, \ 447 testcase_type); \ 448 ICUNIT_ASSERT_EQUAL_VOID(uwRet, ICUNIT_SUCCESS, uwRet); \ 449 } while (0) 450 451 #define TEST_RUN_SUITE() \ 452 do { \ 453 UINT32 uiRet; \ 454 uiRet = iCunitRun(); \ 455 ICUNIT_ASSERT_NOT_EQUAL_VOID(uiRet, ICUNIT_UNINIT, ICUNIT_UNINIT); \ 456 } while (0) 457 458 #ifdef __cplusplus 459 #if __cplusplus 460 } 461 #endif /* __cpluscplus */ 462 #endif /* __cpluscplus */ 463 464 #endif /* _UNI_ICUNIT_H */