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 33 #ifndef _LOS_ICUNIT_H 34 #define _LOS_ICUNIT_H 35 #include "osTest.h" 36 37 #ifdef TST_DRVPRINT 38 #include "VOS_typdef.h" 39 #include "uartdriver.h" 40 #endif 41 42 #ifdef __cplusplus 43 #if __cplusplus 44 extern "C" { 45 #endif /* __cplusplus */ 46 #endif /* __cplusplus */ 47 48 typedef unsigned short iUINT16; 49 typedef unsigned int iUINT32; 50 typedef signed short iINT16; 51 typedef signed long iINT32; 52 typedef char iCHAR; 53 typedef void iVOID; 54 55 typedef unsigned long iiUINT32; 56 57 58 #ifndef FALSE 59 #define FALSE 0 60 #endif 61 #ifndef TRUE 62 #define TRUE 1 63 #endif 64 65 #define FUNCTION_TEST (1 << 0) 66 67 #define PRESSURE_TEST (1 << 1) 68 69 #define PERFORMANCE_TEST (1 << 2) 70 71 #define TEST_MODE (FUNCTION_TEST) 72 73 typedef iUINT32 (*CASE_FUNCTION)(void); 74 75 typedef struct { 76 iCHAR *pcCaseID; 77 CASE_FUNCTION pstCaseFunc; 78 iUINT16 testcase_layer; 79 iUINT16 testcase_module; 80 iUINT16 testcase_level; 81 iUINT16 testcase_type; 82 iiUINT32 retCode; 83 iUINT16 errLine; 84 } ICUNIT_CASE_S; 85 86 typedef struct { 87 iUINT16 uwCaseCnt; 88 iCHAR *pcSuitID; 89 iCHAR *pucFilename; 90 ICUNIT_CASE_S *pstCaseList; 91 iUINT16 passCnt; 92 iUINT16 failCnt; 93 } ICUNIT_SUIT_S; 94 95 typedef enum { 96 TEST_TASK = 0, 97 TEST_MEM, 98 TEST_SEM, 99 TEST_MUX, 100 TEST_EVENT, 101 TEST_QUE, 102 TEST_SWTMR, 103 TEST_HWI, 104 TEST_ATO, 105 TEST_CPUP, 106 TEST_SCATTER, 107 TEST_RUNSTOP, 108 TEST_TIMER, 109 TEST_MMU, 110 TEST_TICKLESS, 111 TEST_ROBIN, 112 TEST_LIBC, 113 TEST_WAIT, 114 TEST_VFAT, 115 TEST_YAFFS, 116 TEST_JFFS, 117 TEST_RAMFS, 118 TEST_NFS, 119 TEST_PROC, 120 TEST_FS, 121 TEST_PTHREAD, 122 TEST_COMP, 123 TEST_HWI_HALFBOTTOM, 124 TEST_WORKQ, 125 TEST_WAKELOCK, 126 TEST_TIMES, 127 TEST_LIBM, 128 TEST_SUPPORT, 129 TEST_STL, 130 TEST_MAIL, 131 TEST_MSG, 132 TEST_CP, 133 TEST_SIGNAL, 134 TEST_SCHED, 135 TEST_MTDCHAR, 136 TEST_TIME, 137 TEST_WRITE, 138 TEST_READ, 139 TEST_DYNLOAD, 140 TEST_REGISTER, 141 TEST_SR, 142 TEST_UNAME, 143 TEST_MISC, 144 TEST_EXC, 145 #if defined(LOSCFG_3RDPARTY_TEST) 146 TEST_THTTPD, 147 TEST_BIDIREFC, 148 TEST_CJSON, 149 TEST_CURL, 150 TEST_FFMPEG, 151 TEST_FREETYPE, 152 TEST_INIPARSER, 153 TEST_JSONCPP, 154 TEST_LIBICONV, 155 TEST_LIBJPEG, 156 TEST_LIBPNG, 157 TEST_OPENEXIF, 158 TEST_OPENSSL, 159 TEST_OPUS, 160 TEST_SQLITE, 161 TEST_TINYXML, 162 #endif 163 TEST_DRIVERBASE, 164 TEST_DYNLINK, 165 TEST_LMS, 166 } LiteOS_test_module; 167 168 typedef enum { 169 TEST_LOS = 0, 170 TEST_CMSIS, 171 TEST_POSIX, 172 TEST_LIB, 173 TEST_VFS, 174 TEST_EXTEND, 175 TEST_PARTITION, 176 TEST_CPP, 177 TEST_SHELL, 178 TEST_LINUX, 179 TEST_USB, 180 #if defined(LOSCFG_3RDPARTY_TEST) 181 TEST_3RDPARTY, 182 #endif 183 TEST_DRIVERFRAME, 184 TEST_CONTEXHUB 185 } LiteOS_test_layer; 186 187 typedef enum { 188 TEST_LEVEL0 = 0, 189 TEST_LEVEL1, 190 TEST_LEVEL2, 191 TEST_LEVEL3 192 } LiteOS_test_level; 193 194 typedef enum { 195 TEST_FUNCTION = 0, 196 TEST_PRESSURE, 197 TEST_PERFORMANCE 198 } LiteOS_test_type; 199 200 201 extern iUINT16 iCunit_errLineNo; 202 extern iiUINT32 iCunit_errCode; 203 extern void ICunitSaveErr(iiUINT32 line, iiUINT32 retCode); 204 205 206 #define ICUNIT_UNINIT 0x0EF00000 207 #define ICUNIT_OPENFILE_FAILED 0x0EF00001 208 #define ICUNIT_ALLOC_FAIL 0x0EF00002 209 #define ICUNIT_SUIT_FULL 0x0EF00002 210 #define ICUNIT_CASE_FULL 0x0EF00003 211 #define ICUNIT_SUIT_ALL 0x0EF0FFFF 212 213 #define ICUNIT_SUCCESS 0x00000000 214 215 #define ICUNIT_TRACK_EQUAL(param, value, retcode) \ 216 do { \ 217 if ((param) != (value)) { \ 218 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 219 } \ 220 } while (0) 221 222 #define ICUNIT_TRACK_NOT_EQUAL(param, value, retcode) \ 223 do { \ 224 if ((param) == (value)) { \ 225 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 226 } \ 227 } while (0) 228 229 #define ICUNIT_ASSERT_EQUAL_VOID(param, value, retcode) \ 230 do { \ 231 if ((param) != (value)) { \ 232 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 233 return; \ 234 } \ 235 } while (0) 236 237 #define ICUNIT_ASSERT_NOT_EQUAL_VOID(param, value, retcode) \ 238 do { \ 239 if ((param) == (value)) { \ 240 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 241 return; \ 242 } \ 243 } while (0) 244 #define ICUNIT_ASSERT_EQUAL(param, value, retcode) \ 245 do { \ 246 if ((param) != (value)) { \ 247 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 248 return 1; \ 249 } \ 250 } while (0) 251 252 #define ICUNIT_ASSERT_NOT_EQUAL(param, value, retcode) \ 253 do { \ 254 if ((param) == (value)) { \ 255 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 256 return 1; \ 257 } \ 258 } while (0) 259 260 #define ICUNIT_ASSERT_WITHIN_EQUAL(param, value1, value2, retcode) \ 261 do { \ 262 if ((param) < (value1) || (param) > (value2)) { \ 263 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 264 return 1; \ 265 } \ 266 } while (0) 267 268 #define ICUNIT_ASSERT_WITHIN_EQUAL_VOID(param, value1, value2, retcode) \ 269 do { \ 270 if ((param) < (value1) || (param) > (value2)) { \ 271 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 272 return; \ 273 } \ 274 } while (0) 275 276 #define ICUNIT_ASSERT_EQUAL_VOID(param, value, retcode) \ 277 do { \ 278 if ((param) != (value)) { \ 279 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 280 return; \ 281 } \ 282 } while (0) 283 284 #define ICUNIT_ASSERT_SIZE_STRING_EQUAL(str1, str2, strsize, retcode) \ 285 do { \ 286 if (strncmp((str1), (str2), (strsize)) != 0) { \ 287 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 288 return 1; \ 289 } \ 290 } while (0) 291 292 #define ICUNIT_ASSERT_STRING_EQUAL(str1, str2, retcode) \ 293 do { \ 294 if (strcmp(str1, str2) != 0) { \ 295 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 296 return 1; \ 297 } \ 298 } while (0) 299 300 #define ICUNIT_ASSERT_STRING_EQUAL_VOID(str1, str2, retcode) \ 301 do { \ 302 if (strcmp((const char *)str1, (const char *)str2) != 0) { \ 303 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 304 return; \ 305 } \ 306 } while (0) 307 308 #define ICUNIT_ASSERT_STRING_NOT_EQUAL(str1, str2, retcode) \ 309 do { \ 310 if (strcmp(str1, str2) == 0) { \ 311 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 312 return 1; \ 313 } \ 314 } while (0) 315 316 #define ICUNIT_GOTO_EQUAL(param, value, retcode, label) \ 317 do { \ 318 if ((param) != (value)) { \ 319 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 320 goto label; \ 321 } \ 322 } while (0) 323 324 #define ICUNIT_GOTO_NOT_EQUAL(param, value, retcode, label) \ 325 do { \ 326 if ((param) == (value)) { \ 327 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 328 goto label; \ 329 } \ 330 } while (0) 331 332 #define ICUNIT_GOTO_STRING_EQUAL(str1, str2, retcode, label) \ 333 do { \ 334 if (strcmp(str1, str2) != 0) { \ 335 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 336 goto label; \ 337 } \ 338 } while (0) 339 340 #define ICUNIT_GOTO_STRING_NOT_EQUAL(str1, str2, retcode, label) \ 341 do { \ 342 if (strcmp(str1, str2) == 0) { \ 343 ICunitSaveErr(__LINE__, (iiUINT32)retcode); \ 344 goto label; \ 345 } \ 346 } while (0) 347 348 extern iUINT32 iCunitAddSuit_F(iCHAR *suitName, iCHAR *pfileName); 349 #define iCunitAddSuit(suitName) iCunitAddSuit_F(suitName, __FILE__) 350 351 extern iUINT32 ICunitAddCase(iCHAR *caseName, CASE_FUNCTION caseFunc, iUINT16 testcaseLayer, iUINT16 testcaseModule, 352 iUINT16 testcaseLevel, iUINT16 testcaseType); 353 354 extern iUINT32 ICunitRun(void); 355 extern iUINT32 ICunitInit(void); 356 extern iUINT32 iCunitPrintReport(void); 357 358 359 #define TEST_ADD_CASE(name, casefunc, testcase_layer, testcase_module, testcase_level, testcase_type) \ 360 do { \ 361 iUINT32 uwRet = 1; \ 362 uwRet = ICunitAddCase(name, (CASE_FUNCTION)casefunc, testcase_layer, testcase_module, testcase_level, \ 363 testcase_type); \ 364 ICUNIT_ASSERT_EQUAL_VOID(uwRet, ICUNIT_SUCCESS, uwRet); \ 365 } while (0) 366 367 #define TEST_RUN_SUITE() \ 368 do { \ 369 UINT32 uiRet; \ 370 uiRet = ICunitRun(); \ 371 ICUNIT_ASSERT_NOT_EQUAL_VOID(uiRet, ICUNIT_UNINIT, ICUNIT_UNINIT); \ 372 } while (0) 373 374 #ifdef __cplusplus 375 #if __cplusplus 376 } 377 #endif /* __cplusplus */ 378 #endif /* __cplusplus */ 379 380 #endif /* _UNI_ICUNIT_H */ 381