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 "string.h" 35#include "osTest.h" 36#include "iCunit_config.h" 37 38#include <stdio.h> 39 40 41extern UINT32 g_failResult; 42extern UINT32 g_passResult; 43void ICunitSaveErr(iiUINT32 line, iiUINT32 retCode) 44{ 45 iCunit_errLineNo = (iCunit_errLineNo == 0) ? line : iCunit_errLineNo; 46 iCunit_errCode = (iCunit_errCode == 0) ? (iiUINT32)retCode : iCunit_errCode; 47} 48 49iUINT32 ICunitAddCase(iCHAR *caseName, CASE_FUNCTION caseFunc, iUINT16 testcaseLayer, iUINT16 testcaseModule, 50 iUINT16 testcaseLevel, iUINT16 testcaseType) 51{ 52 iUINT16 idx; 53 54 if (iCunit_Init_Success) { 55 return (iUINT32)ICUNIT_UNINIT; 56 } 57 58 idx = 0; 59 if (idx == ICUNIT_CASE_SIZE) { 60 iCunit_ErrLog_AddCase++; 61 return (iUINT32)ICUNIT_CASE_FULL; 62 } 63 64 iCunit_CaseArray[idx].pcCaseID = caseName; 65 iCunit_CaseArray[idx].pstCaseFunc = caseFunc; 66 iCunit_CaseArray[idx].testcase_layer = testcaseLayer; 67 iCunit_CaseArray[idx].testcase_module = testcaseModule; 68 iCunit_CaseArray[idx].testcase_level = testcaseLevel; 69 iCunit_CaseArray[idx].testcase_type = testcaseType; 70 71 ICunitRun(); 72 return (iUINT32)ICUNIT_SUCCESS; 73} 74 75iUINT32 ICunitInit() 76{ 77 iCunit_Init_Success = 0x0000; 78 iCunit_Case_Cnt = 0x0000; 79 80 iCunit_Case_FailedCnt = 0; 81 82 iCunit_ErrLog_AddCase = 0; 83 84 (void)memset_s(iCunit_CaseArray, sizeof(iCunit_CaseArray), 0, sizeof(iCunit_CaseArray)); 85 return (iUINT32)ICUNIT_SUCCESS; 86} 87 88char *g_strLayer[] = { 89 "LOS", "CMSIS", "POSIX", "LIB", "VFS", "EXTEND", 90 "PARTITION", "CPP", "SHELL", "LINUX", "USB", "DRIVERFRAME", "CONTEXTHUB" 91}; 92char *g_strModule[] = { 93 "TASK", "MEM", "SEM", "MUX", "EVENT", "QUE", "SWTMR", "HWI", "ATO", "CPUP", "SCATTER", "RUNSTOP", "TIMER", "MMU", "TICKLESS", 94 "ROBIN", "LIBC", "WAIT", "VFAT", "YAFFS", "JFFS", "RAMFS", "NFS", "PROC", "FS", 95 "PTHREAD", "COMP", "HWI_HALFBOTTOM", "WORKQ", "WAKELOCK", "TIMES", 96 "LIBM", "SUPPORT", "STL", "MAIL", "MSG", "CP", "SIGNAL", "SCHED", "MTDCHAR", "TIME", "WRITE", "READ", "DYNLOAD", "REGISTER", "SR", "UNAME", "ERR" 97}; 98char *g_strLevel[] = { 99 "LEVEL0", "LEVEL1", "LEVEL2", "LEVEL3" 100}; 101char *g_strType[] = { 102 "FUNCTION", "PRESSURE", "PERFORMANCE" 103}; 104 105iUINT32 ICunitRunF(void) 106{ 107 iUINT32 idx, idx1; 108 ICUNIT_CASE_S *psubCaseArray; 109 iUINT32 caseRet; 110 111 psubCaseArray = iCunit_CaseArray; 112 idx1 = 1; 113 114 for (idx = 0; idx < idx1; idx++, psubCaseArray++) { 115 iCunit_errLineNo = 0; 116 iCunit_errCode = 0; 117 118 caseRet = psubCaseArray->pstCaseFunc(); 119 psubCaseArray->errLine = iCunit_errLineNo; 120 psubCaseArray->retCode = (0 == iCunit_errLineNo) ? (caseRet) : (iCunit_errCode); 121 122 if (0 == iCunit_errLineNo && 0 == caseRet) { 123 g_passResult++; 124 PRINTF(" [Passed]-%s-%s-%s-%s-%s\n", psubCaseArray->pcCaseID, g_strLayer[psubCaseArray->testcase_layer], 125 g_strModule[psubCaseArray->testcase_module], g_strLevel[psubCaseArray->testcase_level], 126 g_strType[psubCaseArray->testcase_type]); 127 } else { 128 g_failResult++; 129 iCunit_Case_FailedCnt++; 130 PRINTF(" [Failed]-%s-%s-%s-%s-%s-[Errline: %d RetCode:0x%lx]\n", psubCaseArray->pcCaseID, 131 g_strLayer[psubCaseArray->testcase_layer], g_strModule[psubCaseArray->testcase_module], 132 g_strLevel[psubCaseArray->testcase_level], g_strType[psubCaseArray->testcase_type], 133 psubCaseArray->errLine, psubCaseArray->retCode); 134 } 135 } 136 137 return (iUINT32)ICUNIT_SUCCESS; 138} 139 140iUINT32 ICunitRun() 141{ 142 if (iCunit_Init_Success) { 143 return (iUINT32)ICUNIT_UNINIT; 144 } 145 146 ICunitRunF(); 147 148 return (iUINT32)ICUNIT_SUCCESS; 149} 150 151