From 6ba17fc862c7ae8d326e6d3501661c74e5609dc6 Mon Sep 17 00:00:00 2001 From: wangchen <253227059@qq.com> Date: Tue, 22 Mar 2022 12:52:03 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20kora=E5=B7=A5=E5=85=B7=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=20=E3=80=90=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E3=80=91kora=E5=B7=A5=E5=85=B7=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 1,对部分代码问题进行整改 【影响】 对现有的产品编译不会有影响。 Signed-off-by: wangchen Change-Id: Iafc58b7c71e5d139e11a0ae9d98ca5a57fc6549f --- apps/lms/src/sample_usr_lms.c | 34 +++++- drivers/char/random/src/random_hw.c | 2 +- fs/patchfs/los_patchfs.c | 11 +- fs/rootfs/los_bootargs.c | 4 +- fs/rootfs/los_rootfs.c | 4 +- fs/vfs/vfs_cmd/vfs_shellcmd.c | 6 +- kernel/base/mem/tlsf/los_memory.c | 4 +- kernel/base/misc/los_stackinfo.c | 6 +- kernel/extended/hilog/los_hilog.c | 6 +- net/lwip-2.1/enhancement/src/api_shell.c | 8 +- testsuites/kernel/include/iCunit.h | 110 ------------------ .../task/full/It_los_task_timeslice_004.c | 2 - .../ipc/event/full/It_los_event_022.c | 1 - .../ipc/event/smp/It_smp_los_event_032.c | 1 - .../ipc/queue/full/It_los_queue_head_015.c | 2 - .../kernel_extend/cpup/It_extend_cpup.c | 2 +- .../posix/pthread/full/It_posix_pthread_023.c | 3 +- .../posix/pthread/full/It_posix_pthread_069.c | 12 +- .../posix/pthread/full/It_posix_pthread_101.c | 3 +- .../basic/dynload/smoke/dynload_test_002.cpp | 10 +- .../basic/mem/shm/full/it_test_mem_100.cpp | 2 + .../basic/mem/shm/full/shm_test_013.cpp | 20 ++-- .../unittest/basic/mem/vm/mem_vm_test.cpp | 31 ----- .../basic/mem/vm/smoke/mmap_test_002.cpp | 6 +- testsuites/unittest/extended/ipc/ipc_test.cpp | 26 ----- .../extended/signal/smoke/mkfifo_test_001.cpp | 6 + .../libc/io/full/It_stdio_fwprintf_001.cpp | 2 + .../libc/io/full/It_stdio_hasmntopt_001.cpp | 4 + .../libc/io/full/It_stdio_putwc_001.cpp | 2 + .../posix/mqueue/full/It_posix_queue_134.cpp | 2 - .../pthread/full/It_posix_pthread_044.cpp | 2 - .../unittest/libc/sys/smoke/sys_test_007.cpp | 2 +- .../unittest/libc/sys/smoke/sys_test_030.cpp | 12 -- .../libc/util/smoke/util_test_003.cpp | 3 + .../libc/util/smoke/util_test_007.cpp | 6 +- .../net/socket/smoke/net_socket_test_003.cpp | 16 +-- .../net/socket/smoke/net_socket_test_007.cpp | 10 +- .../basic/process/full/process_test_066.cpp | 3 + .../basic/process/smoke/process_test_046.cpp | 1 - .../security/vid/smoke/vid_test_001.cpp | 7 ++ 40 files changed, 146 insertions(+), 248 deletions(-) diff --git a/apps/lms/src/sample_usr_lms.c b/apps/lms/src/sample_usr_lms.c index 8ecadc87..c8ef15d6 100644 --- a/apps/lms/src/sample_usr_lms.c +++ b/apps/lms/src/sample_usr_lms.c @@ -53,7 +53,9 @@ static void LmsMallocTest(void) #define TEST_SIZE 16 printf("\n-------- LmsMallocTest Start --------\n"); char *buf = (char *)malloc(TEST_SIZE); - + if (buf == NULL) { + return; + } printf("[LmsMallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n"); BufReadTest(buf, -1, TEST_SIZE); printf("[LmsMallocTest] write overflow error should be triggered, write range[0, TEST_SIZE]\n"); @@ -88,6 +90,9 @@ static void LmsCallocTest(void) #define TEST_SIZE 16 printf("\n-------- LmsCallocTest Start --------\n"); char *buf = (char *)calloc(4, 4); /* 4: test size */ + if (buf == NULL) { + return; + } printf("[LmsCallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n"); BufReadTest(buf, -1, TEST_SIZE); free(buf); @@ -99,6 +104,9 @@ static void LmsVallocTest(void) #define TEST_SIZE 4096 printf("\n-------- LmsVallocTest Start --------\n"); char *buf = (char *)valloc(TEST_SIZE); + if (buf == NULL) { + return; + } printf("[LmsVallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n"); BufReadTest(buf, -1, TEST_SIZE); free(buf); @@ -111,6 +119,9 @@ static void LmsAlignedAllocTest(void) #define TEST_SIZE 128 printf("\n-------- LmsAlignedAllocTest Start --------\n"); char *buf = (char *)aligned_alloc(TEST_ALIGN_SIZE, TEST_SIZE); + if (buf == NULL) { + return; + } printf("[LmsAlignedAllocTest] read overflow & underflow error should be triggered, read range[-1,128]\n"); BufReadTest(buf, -1, 128); free(buf); @@ -122,6 +133,9 @@ static void LmsMemsetTest(void) #define TEST_SIZE 32 printf("\n-------- LmsMemsetTest Start --------\n"); char *buf = (char *)malloc(TEST_SIZE); + if (buf == NULL) { + return; + } printf("[LmsMemsetTest] memset overflow & underflow error should be triggered, memset size:%d\n", TEST_SIZE + 1); memset(buf, 0, TEST_SIZE + 1); free(buf); @@ -133,6 +147,9 @@ static void LmsMemcpyTest(void) #define TEST_SIZE 20 printf("\n-------- LmsMemcpyTest Start --------\n"); char *buf = (char *)malloc(TEST_SIZE); + if (buf == NULL) { + return; + } char localBuf[32] = {0}; /* 32: test size */ printf("[LmsMemcpyTest] memcpy overflow error should be triggered, memcpy size:%d\n", TEST_SIZE + 1); memcpy(buf, localBuf, TEST_SIZE + 1); @@ -145,6 +162,9 @@ static void LmsMemmoveTest(void) #define TEST_SIZE 20 printf("\n-------- LmsMemmoveTest Start --------\n"); char *buf = (char *)malloc(TEST_SIZE); + if (buf == NULL) { + return; + } printf("[LmsMemmoveTest] memmove overflow error should be triggered\n"); memmove(buf + 12, buf, 10); /* 12 and 10: test size */ free(buf); @@ -156,6 +176,9 @@ static void LmsStrcpyTest(void) #define TEST_SIZE 16 printf("\n-------- LmsStrcpyTest Start --------\n"); char *buf = (char *)malloc(TEST_SIZE); + if (buf == NULL) { + return; + } char *testStr = "bbbbbbbbbbbbbbbbb"; printf("[LmsStrcpyTest] strcpy overflow error should be triggered, src string buf size:%d\n", strlen(testStr) + 1); strcpy(buf, testStr); @@ -168,6 +191,9 @@ static void LmsStrcatTest(void) #define TEST_SIZE 16 printf("\n-------- LmsStrcatTest Start --------\n"); char *buf = (char *)malloc(TEST_SIZE); + if (buf == NULL) { + return; + } buf[0] = 'a'; buf[1] = 'b'; buf[2] = 0; @@ -185,6 +211,9 @@ static void LmsFreeTest(void) #define TEST_SIZE 16 printf("\n-------- LmsFreeTest Start --------\n"); char *buf = (char *)malloc(TEST_SIZE); + if (buf == NULL) { + return; + } printf("[LmsFreeTest] free size:%d\n", TEST_SIZE); free(buf); printf("[LmsFreeTest] Use after free error should be triggered, read range[1,1]\n"); @@ -200,6 +229,9 @@ int main(int argc, char * const *argv) (void)argv; printf("\n############### Lms Test start ###############\n"); char *tmp = (char *)malloc(5000); /* 5000: test mem size */ + if (tmp == NULL) { + return; + } LmsMallocTest(); LmsReallocTest(); LmsCallocTest(); diff --git a/drivers/char/random/src/random_hw.c b/drivers/char/random/src/random_hw.c index a290a586..04934a14 100644 --- a/drivers/char/random/src/random_hw.c +++ b/drivers/char/random/src/random_hw.c @@ -41,7 +41,7 @@ void RandomOperationsInit(const RandomOperations *r) if (r != NULL) { (void)memcpy_s(&g_randomOp, sizeof(RandomOperations), r, sizeof(RandomOperations)); } else { - PRINT_ERR("param is invalid\n", __FUNCTION__, __LINE__); + PRINT_ERR("%s %d param is invalid\n", __FUNCTION__, __LINE__); } return; } diff --git a/fs/patchfs/los_patchfs.c b/fs/patchfs/los_patchfs.c index 82b621a4..04346c6a 100644 --- a/fs/patchfs/los_patchfs.c +++ b/fs/patchfs/los_patchfs.c @@ -55,14 +55,15 @@ INT32 OsMountPatchFs(VOID) } partInfo.fsType = strdup(FS_TYPE); if (partInfo.fsType == NULL) { - return LOS_NOK; + ret = LOS_NOK; + goto EXIT; } partInfo.startAddr = PATCHFS_FLASH_ADDR; partInfo.partSize = PATCHFS_FLASH_SIZE; #else ret = GetPartitionInfo(&partInfo); if (ret != LOS_OK) { - return ret; + goto EXIT; } partInfo.startAddr = (partInfo.startAddr >= 0) ? partInfo.startAddr : PATCHFS_FLASH_ADDR; partInfo.partSize = (partInfo.partSize >= 0) ? partInfo.partSize : PATCHFS_FLASH_SIZE; @@ -71,7 +72,7 @@ INT32 OsMountPatchFs(VOID) ret = LOS_NOK; partInfo.devName = strdup(PATCH_FLASH_DEV_NAME); if (partInfo.devName == NULL) { - return LOS_NOK; + goto EXIT; } const CHAR *devName = GetDevNameOfPartition(&partInfo); if (devName != NULL) { @@ -92,9 +93,13 @@ INT32 OsMountPatchFs(VOID) ResetDevNameofPartition(&partInfo); } +EXIT: free(partInfo.devName); + partInfo.devName = NULL; free(partInfo.storageType); + partInfo.storageType = NULL; free(partInfo.fsType); + partInfo.fsType = NULL; return ret; } diff --git a/fs/rootfs/los_bootargs.c b/fs/rootfs/los_bootargs.c index 82d02c22..c6e2a680 100644 --- a/fs/rootfs/los_bootargs.c +++ b/fs/rootfs/los_bootargs.c @@ -214,7 +214,7 @@ UINT64 LOS_SizeStrToNum(CHAR *value) UINT64 num = 0; /* If the string is a hexadecimal value */ - if (sscanf_s(value, "0x%x", &num) > 0) { + if (sscanf_s(value, "0x%llx", &num) > 0) { value += strlen("0x"); if (strspn(value, "0123456789abcdefABCDEF") < strlen(value)) { goto ERROUT; @@ -247,4 +247,4 @@ UINT64 LOS_SizeStrToNum(CHAR *value) ERROUT: PRINT_ERR("Invalid value string \"%s\"!\n", value); return num; -} \ No newline at end of file +} diff --git a/fs/rootfs/los_rootfs.c b/fs/rootfs/los_rootfs.c index 58cbce12..a81c0163 100644 --- a/fs/rootfs/los_rootfs.c +++ b/fs/rootfs/los_rootfs.c @@ -327,7 +327,7 @@ STATIC INT32 CheckValidation(UINT64 rootAddr, UINT64 rootSize, UINT64 userAddr, if ((rootAddr & (alignSize - 1)) || (rootSize & (alignSize - 1)) || (userAddr & (alignSize - 1)) || (userSize & (alignSize - 1))) { - PRINT_ERR("The address or size value should be 0x%x aligned!\n", alignSize); + PRINT_ERR("The address or size value should be 0x%llx aligned!\n", alignSize); return LOS_NOK; } @@ -371,4 +371,4 @@ INT32 OsMountRootfs() } return LOS_OK; -} \ No newline at end of file +} diff --git a/fs/vfs/vfs_cmd/vfs_shellcmd.c b/fs/vfs/vfs_cmd/vfs_shellcmd.c index 77cad26d..67c175d1 100644 --- a/fs/vfs/vfs_cmd/vfs_shellcmd.c +++ b/fs/vfs/vfs_cmd/vfs_shellcmd.c @@ -654,7 +654,7 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename char *dst_filepath = NULL; char *buf = NULL; const char *filename = NULL; - size_t r_size, w_size; + ssize_t r_size, w_size; int src_fd = -1; int dst_fd = -1; struct stat stat_buf; @@ -1391,8 +1391,8 @@ int checkNum(const char *arg) #ifdef LOSCFG_KERNEL_SYSCALL int osShellCmdSu(int argc, const char **argv) { - unsigned int su_uid; - unsigned int su_gid; + int su_uid; + int su_gid; if (argc == 0) { diff --git a/kernel/base/mem/tlsf/los_memory.c b/kernel/base/mem/tlsf/los_memory.c index 92e19659..20221c99 100644 --- a/kernel/base/mem/tlsf/los_memory.c +++ b/kernel/base/mem/tlsf/los_memory.c @@ -1748,7 +1748,7 @@ STATIC VOID OsMemNodeInfo(const struct OsMemNodeHead *tmpNode, usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag); } else { freeNode = (struct OsMemFreeNodeHead *)tmpNode; - PRINTK("\n broken node head: %#x %#x %#x %#x, ", + PRINTK("\n broken node head: %#x %#x %#x %#x, %#x", freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic, freeNode->header.sizeAndFlag); } @@ -1759,7 +1759,7 @@ STATIC VOID OsMemNodeInfo(const struct OsMemNodeHead *tmpNode, usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag); } else { freeNode = (struct OsMemFreeNodeHead *)preNode; - PRINTK("prev node head: %#x %#x %#x %#x, ", + PRINTK("prev node head: %#x %#x %#x %#x, %#x", freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic, freeNode->header.sizeAndFlag); } diff --git a/kernel/base/misc/los_stackinfo.c b/kernel/base/misc/los_stackinfo.c index 5bac7160..f7ab26f3 100644 --- a/kernel/base/misc/los_stackinfo.c +++ b/kernel/base/misc/los_stackinfo.c @@ -117,8 +117,10 @@ VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum) VOID OsStackInit(VOID *stacktop, UINT32 stacksize) { /* initialize the task stack, write magic num to stack top */ - (VOID)memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize); - *((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD; + errno_t ret = memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize); + if (ret == EOK) { + *((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD; + } } #ifdef LOSCFG_SHELL_CMD_DEBUG diff --git a/kernel/extended/hilog/los_hilog.c b/kernel/extended/hilog/los_hilog.c index 35370892..dd7c7c6f 100644 --- a/kernel/extended/hilog/los_hilog.c +++ b/kernel/extended/hilog/los_hilog.c @@ -148,7 +148,7 @@ static int HiLogBufferCopy(unsigned char *dst, unsigned dstLen, const unsigned c static int HiLogReadRingBuffer(unsigned char *buffer, size_t bufLen) { - size_t retval; + int retval; size_t bufLeft = HILOG_BUFFER - g_hiLogDev.headOffset; if (bufLeft > bufLen) { retval = HiLogBufferCopy(buffer, bufLen, HiLogBufferHead(), bufLen); @@ -165,7 +165,7 @@ static int HiLogReadRingBuffer(unsigned char *buffer, size_t bufLen) static ssize_t HiLogRead(struct file *filep, char *buffer, size_t bufLen) { - size_t retval; + int retval; struct HiLogEntry header; (void)filep; @@ -209,7 +209,7 @@ out: g_hiLogDev.count = 0; } (VOID)LOS_MuxRelease(&g_hiLogDev.mtx); - return retval; + return (ssize_t)retval; } static int HiLogWriteRingBuffer(unsigned char *buffer, size_t bufLen) diff --git a/net/lwip-2.1/enhancement/src/api_shell.c b/net/lwip-2.1/enhancement/src/api_shell.c index 8c0c609f..5831bf56 100644 --- a/net/lwip-2.1/enhancement/src/api_shell.c +++ b/net/lwip-2.1/enhancement/src/api_shell.c @@ -1337,10 +1337,10 @@ out: LWIP_STATIC void lwip_arp_usage(const char *cmd) { - PRINTK("Usage:"\ - "\n%s" - "\n%s [-i IF] -s IPADDR HWADDR"\ - "\n%s [-i IF] -d IPADDR\n", + PRINTK("Usage:" + "\n%s" + "\n%s [-i IF] -s IPADDR HWADDR" + "\n%s [-i IF] -d IPADDR\n", cmd, cmd, cmd); } diff --git a/testsuites/kernel/include/iCunit.h b/testsuites/kernel/include/iCunit.h index 6b7e0376..31d355e6 100644 --- a/testsuites/kernel/include/iCunit.h +++ b/testsuites/kernel/include/iCunit.h @@ -237,8 +237,6 @@ extern void ICunitSaveErr(iiUINT32 line, iiUINT32 retCode); #define ICUNIT_SUCCESS 0x00000000 -#if 1 - #define ICUNIT_TRACK_EQUAL(param, g_value, retcode) \ do { \ if ((param) != (g_value)) { \ @@ -414,114 +412,6 @@ extern void ICunitSaveErr(iiUINT32 line, iiUINT32 retCode); } \ } while (0) -#else - -#define ICUNIT_TRACK_EQUAL(param, g_value, retcode) \ - do { \ - if ((param) != (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - } \ - } while (0) - -#define ICUNIT_TRACK_NOT_EQUAL(param, g_value, retcode) \ - do { \ - if ((param) == (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - } \ - } while (0) - -#define ICUNIT_ASSERT_EQUAL_VOID(param, g_value, retcode) \ - do { \ - if ((param) != (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - return; \ - } \ - } while (0) - -#define ICUNIT_ASSERT_NOT_EQUAL_VOID(param, g_value, retcode) \ - do { \ - if ((param) == (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - return; \ - } \ - } while (0) -#define ICUNIT_ASSERT_EQUAL(param, g_value, retcode) \ - do { \ - if ((param) != (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - return 1; \ - } \ - } while (0) - -#define ICUNIT_ASSERT_NOT_EQUAL(param, g_value, retcode) \ - do { \ - if ((param) == (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - return 1; \ - } \ - } while (0) - -#define ICUNIT_ASSERT_STRING_EQUAL(str1, str2, retcode) \ - do { \ - if (strcmp(str1, str2) != 0) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - return 1; \ - } \ - } while (0) - -#define ICUNIT_ASSERT_STRING_NOT_EQUAL(str1, str2, retcode) \ - do { \ - if (strcmp(str1, str2) == 0) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - return 1; \ - } \ - } while (0) - -#define ICUNIT_GOTO_EQUAL(param, g_value, retcode, label) \ - do { \ - if ((param) != (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - goto label; \ - } \ - } while (0) - -#define ICUNIT_GOTO_NOT_EQUAL(param, g_value, retcode, label) \ - do { \ - if ((param) == (g_value)) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - goto label; \ - } \ - } while (0) - -#define ICUNIT_GOTO_STRING_EQUAL(str1, str2, retcode, label) \ - do { \ - if (strcmp(str1, str2) != 0) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - goto label; \ - } \ - } while (0) - -#define ICUNIT_GOTO_STRING_NOT_EQUAL(str1, str2, retcode, label) \ - do { \ - if (strcmp(str1, str2) == 0) { \ - g_iCunitErrLineNo = (g_iCunitErrLineNo == 0) ? __LINE__ : g_iCunitErrLineNo; \ - g_iCunitErrCode = (g_iCunitErrCode == 0) ? (iiUINT32)retcode : g_iCunitErrCode; \ - goto label; \ - } \ - } while (0) -#endif - #ifdef LOSCFG_KERNEL_SMP extern SPIN_LOCK_S g_testSuitSpin; #define TESTSUIT_LOCK(state) LOS_SpinLockSave(&g_testSuitSpin, &(state)) diff --git a/testsuites/kernel/sample/kernel_base/core/task/full/It_los_task_timeslice_004.c b/testsuites/kernel/sample/kernel_base/core/task/full/It_los_task_timeslice_004.c index d59e9882..cbe89f85 100644 --- a/testsuites/kernel/sample/kernel_base/core/task/full/It_los_task_timeslice_004.c +++ b/testsuites/kernel/sample/kernel_base/core/task/full/It_los_task_timeslice_004.c @@ -45,8 +45,6 @@ static void TaskF02(void const * argument) ICUNIT_GOTO_EQUAL(g_timesliceTestCount, 1, ret, EXIT); g_timesliceTestCount++; return; - -EXIT:; } static void SwtmrF01(UINT32 *arg) diff --git a/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_022.c b/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_022.c index 794af7da..686c18cd 100644 --- a/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_022.c +++ b/testsuites/kernel/sample/kernel_base/ipc/event/full/It_los_event_022.c @@ -117,7 +117,6 @@ EXIT: LOS_TaskDelete(g_testTaskID01); return LOS_OK; - return LOS_OK; } VOID ItLosEvent022(VOID) // IT_Layer_ModuleORFeature_No diff --git a/testsuites/kernel/sample/kernel_base/ipc/event/smp/It_smp_los_event_032.c b/testsuites/kernel/sample/kernel_base/ipc/event/smp/It_smp_los_event_032.c index cc6bd21f..9e6c9dfa 100644 --- a/testsuites/kernel/sample/kernel_base/ipc/event/smp/It_smp_los_event_032.c +++ b/testsuites/kernel/sample/kernel_base/ipc/event/smp/It_smp_los_event_032.c @@ -103,7 +103,6 @@ static UINT32 Testcase(void) PRINT_DEBUG("ret1= 0x%x,ret2 = 0x%x,ret3=0x%x\n", g_ret1, g_ret2, g_ret3); if ((g_ret1 == 0x11) && (g_ret2 == LOS_OK) && (g_ret3 == LOS_OK)) { // pend-post-del ///post-pend-del - } else if ((g_ret1 == 0x11) && (g_ret2 == LOS_OK) && (g_ret3 == LOS_OK)) { // del-pend-post//del-post-pend } else if ((g_ret1 == 0x11) && (g_ret2 == LOS_OK) && (g_ret3 == LOS_ERRNO_EVENT_SHOULD_NOT_DESTROY)) { // pend-delete-post } else if ((g_ret1 == 0xff) && (g_ret2 == LOS_OK) && (g_ret3 == LOS_OK)) { // post-del-pend diff --git a/testsuites/kernel/sample/kernel_base/ipc/queue/full/It_los_queue_head_015.c b/testsuites/kernel/sample/kernel_base/ipc/queue/full/It_los_queue_head_015.c index 3fb0e441..0e437bf8 100644 --- a/testsuites/kernel/sample/kernel_base/ipc/queue/full/It_los_queue_head_015.c +++ b/testsuites/kernel/sample/kernel_base/ipc/queue/full/It_los_queue_head_015.c @@ -56,8 +56,6 @@ static UINT32 Testcase(VOID) ret = LOS_QueueRead(queueID[index - 1], &buff2, sizeof(UINTPTR), 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_QueueCreate("Q1", 3, &queueID[index], 0, 8); // 3, Set the queue length; 8, Set the node size of the queue. - ret = LOS_QueueCreate("Q1", 3, &queueID[index], 0, 8); // 3, Set the queue length; 8, Set the node size of the queue. ICUNIT_GOTO_NOT_EQUAL(ret, LOS_OK, ret, EXIT); EXIT: diff --git a/testsuites/kernel/sample/kernel_extend/cpup/It_extend_cpup.c b/testsuites/kernel/sample/kernel_extend/cpup/It_extend_cpup.c index fc348ff5..ec095e56 100644 --- a/testsuites/kernel/sample/kernel_extend/cpup/It_extend_cpup.c +++ b/testsuites/kernel/sample/kernel_extend/cpup/It_extend_cpup.c @@ -46,7 +46,7 @@ UINT32 TestGetSingleHwiCpup(UINT32 hwi, UINT32 mode) { UINT32 size; UINT32 tempHwi; - if (hwi < 0 || hwi > OS_HWI_MAX_NUM) { + if (hwi > OS_HWI_MAX_NUM) { return -1; } diff --git a/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_023.c b/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_023.c index 1f024163..89caf553 100644 --- a/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_023.c +++ b/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_023.c @@ -51,7 +51,6 @@ static VOID *PthreadF01(void *argument) pthread_cleanup_push(PthreadCleanF01, (void *)8); // 8, here set value. return (void *)8; // 8, here set value about the return status. - pthread_cleanup_pop(0) } static UINT32 Testcase(VOID) @@ -85,4 +84,4 @@ VOID ItPosixPthread023(VOID) // IT_Layer_ModuleORFeature_No #if __cplusplus } #endif /* __cpluscplus */ -#endif /* __cpluscplus */ \ No newline at end of file +#endif /* __cpluscplus */ diff --git a/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_069.c b/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_069.c index f2c258ba..457c4600 100644 --- a/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_069.c +++ b/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_069.c @@ -51,13 +51,17 @@ static UINT32 Testcase(VOID) ICUNIT_ASSERT_EQUAL(rc, 0, rc); rc = pthread_cond_init(&cond2, NULL); - ICUNIT_ASSERT_EQUAL(rc, 0, rc); + ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); rc = pthread_cond_destroy(&cond1); - ICUNIT_ASSERT_EQUAL(rc, ENOERR, rc); + ICUNIT_GOTO_EQUAL(rc, ENOERR, rc, EXIT); rc = pthread_cond_destroy(&cond2); - ICUNIT_ASSERT_EQUAL(rc, ENOERR, rc); + ICUNIT_GOTO_EQUAL(rc, ENOERR, rc, EXIT); + return PTHREAD_NO_ERROR; +EXIT: + (void)pthread_cond_destroy(&cond1); + (void)pthread_cond_destroy(&cond2); } VOID ItPosixPthread069(VOID) // IT_Layer_ModuleORFeature_No @@ -69,4 +73,4 @@ VOID ItPosixPthread069(VOID) // IT_Layer_ModuleORFeature_No #if __cplusplus } #endif /* __cpluscplus */ -#endif /* __cpluscplus */ \ No newline at end of file +#endif /* __cpluscplus */ diff --git a/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_101.c b/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_101.c index d41b1318..0d04ba17 100644 --- a/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_101.c +++ b/testsuites/kernel/sample/posix/pthread/full/It_posix_pthread_101.c @@ -48,8 +48,7 @@ static VOID *PthreadF01(void *argument) ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(oldstate, PTHREAD_CANCEL_DEFERRED, oldstate, EXIT); - LOS_TaskDelay(2); // 2, delay for Timing control. - LOS_TaskDelay(2); // 2, delay for Timing control. + LOS_TaskDelay(4); // 4, delay for Timing control. EXIT: return (void *)9; // 9, here set value about the return status. diff --git a/testsuites/unittest/basic/dynload/smoke/dynload_test_002.cpp b/testsuites/unittest/basic/dynload/smoke/dynload_test_002.cpp index 0c2e5f5a..7a175f77 100644 --- a/testsuites/unittest/basic/dynload/smoke/dynload_test_002.cpp +++ b/testsuites/unittest/basic/dynload/smoke/dynload_test_002.cpp @@ -56,8 +56,8 @@ static int Testcase(void) ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle); func = (int (*)(int))dlsym(handle, SYMBOL_TO_FIND); - ICUNIT_ASSERT_NOT_EQUAL(func, NULL, func); - ICUNIT_ASSERT_EQUAL(func, SYMBOL_TO_MATCH, func); + ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT); + ICUNIT_GOTO_EQUAL(func, SYMBOL_TO_MATCH, func, EXIT); ret = dlclose(handle); ICUNIT_ASSERT_EQUAL(ret, 0, ret); @@ -66,12 +66,16 @@ static int Testcase(void) ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle); func = (int (*)(int))dlsym(handle, SYMBOL_TO_FIND); - ICUNIT_ASSERT_NOT_EQUAL(func, NULL, func); + ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT); ret = dlclose(handle); ICUNIT_ASSERT_EQUAL(ret, 0, ret); return 0; + +EXIT: + dlclose(handle); + return 0; } void ItTestDynload002(void) diff --git a/testsuites/unittest/basic/mem/shm/full/it_test_mem_100.cpp b/testsuites/unittest/basic/mem/shm/full/it_test_mem_100.cpp index 05e1a59f..addcc3d6 100644 --- a/testsuites/unittest/basic/mem/shm/full/it_test_mem_100.cpp +++ b/testsuites/unittest/basic/mem/shm/full/it_test_mem_100.cpp @@ -42,6 +42,8 @@ static int TestCase(void) wchar_t *p, *pnew; pnew = (wchar_t*)malloc(sizeof(wchar_t) * (wcslen(res) + wcslen(res1))); + ICUNIT_ASSERT_NOT_EQUAL(pnew, NULL, pnew); + p = wmempcpy(pnew, res, wcslen(res)); wmempcpy(p, res1, wcslen(res1)); flag = wmemcmp(pnew, res2, wcslen(res)); diff --git a/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp b/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp index ab659ce9..ba98058f 100644 --- a/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp +++ b/testsuites/unittest/basic/mem/shm/full/shm_test_013.cpp @@ -44,21 +44,27 @@ static int testcase(void) ICUNIT_ASSERT_NOT_EQUAL(shmfd, -1, shmfd); writebuf = (char*)malloc(pageSize); - ICUNIT_ASSERT_NOT_EQUAL(writebuf, NULL, writebuf); + ICUNIT_ASSERT_NOT_EQUAL(writebuf, NULL, writebuf); readbuf = (char*)malloc(pageSize); - ICUNIT_ASSERT_NOT_EQUAL(readbuf, NULL, readbuf); + ICUNIT_GOTO_NOT_EQUAL(readbuf, NULL, readbuf, EXIT); (void)memset_s(writebuf, pageSize, 0xf, pageSize); count = write(shmfd, writebuf, pageSize); - ICUNIT_ASSERT_EQUAL(count, pageSize, count); + ICUNIT_GOTO_EQUAL(count, pageSize, count, EXIT); ret = lseek(shmfd, 0, SEEK_SET); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); count = read(shmfd, readbuf, pageSize); - ICUNIT_ASSERT_EQUAL(count, pageSize, count); - free(readbuf); - free(writebuf); + ICUNIT_GOTO_EQUAL(count, pageSize, count, EXIT); + +EXIT: + if (readbuf != NULL) { + free(readbuf); + } + if (writebuf != NULL) { + free(writebuf); + } close(shmfd); ret = shm_unlink("test_1"); return 0; diff --git a/testsuites/unittest/basic/mem/vm/mem_vm_test.cpp b/testsuites/unittest/basic/mem/vm/mem_vm_test.cpp index 61e9f8fb..982dbff3 100644 --- a/testsuites/unittest/basic/mem/vm/mem_vm_test.cpp +++ b/testsuites/unittest/basic/mem/vm/mem_vm_test.cpp @@ -51,37 +51,6 @@ HWTEST_F(MemVmTest, ItTestMmap001, TestSize.Level0) { ItTestMmap001(); } -#if 0 // need tmpfs -/* * - * @tc.name: it_test_mmap_002 - * @tc.desc: function for MemVmTest - * @tc.type: FUNC - */ -HWTEST_F(MemVmTest, ItTestMmap002, TestSize.Level0) -{ - ItTestMmap002(); -} - -/* * - * @tc.name: it_test_mmap_003 - * @tc.desc: function for MemVmTest - * @tc.type: FUNC - */ -HWTEST_F(MemVmTest, ItTestMmap003, TestSize.Level0) -{ - ItTestMmap003(); -} - -/* * - * @tc.name: it_test_mmap_004 - * @tc.desc: function for MemVmTest - * @tc.type: FUNC - */ -HWTEST_F(MemVmTest, ItTestMmap004, TestSize.Level0) -{ - ItTestMmap004(); -} -#endif /* * * @tc.name: it_test_mmap_005 diff --git a/testsuites/unittest/basic/mem/vm/smoke/mmap_test_002.cpp b/testsuites/unittest/basic/mem/vm/smoke/mmap_test_002.cpp index ed5c4a4d..8731e27e 100644 --- a/testsuites/unittest/basic/mem/vm/smoke/mmap_test_002.cpp +++ b/testsuites/unittest/basic/mem/vm/smoke/mmap_test_002.cpp @@ -76,8 +76,10 @@ static int Testcase(void) (void)memset_s(buf, pageSize, 0xf, pageSize); count = write(shmfd, buf, pageSize); - ICUNIT_ASSERT_EQUAL(count, pageSize, count); - + if (count != pageSize) { + free(buf); + ICUNIT_ASSERT_EQUAL(count, pageSize, count); + } free(buf); /* Simple MAP_ANONYMOUS */ diff --git a/testsuites/unittest/extended/ipc/ipc_test.cpp b/testsuites/unittest/extended/ipc/ipc_test.cpp index 1b8fa8bb..4fb45462 100644 --- a/testsuites/unittest/extended/ipc/ipc_test.cpp +++ b/testsuites/unittest/extended/ipc/ipc_test.cpp @@ -40,30 +40,4 @@ public: static void SetUpTestCase(void) {} static void TearDownTestCase(void) {} }; - -#if defined(LOSCFG_USER_TEST_FULL) -/* * - * @tc.name: IPC_TEST_MKFIFOAT_001 - * @tc.desc: function for IoTest:mkfifoat-normal test - * @tc.type: FUNC - */ -#if 0 -HWTEST_F(IoTest, IPC_TEST_MKFIFOAT_001, TestSize.Level0) -{ - IPC_TEST_MKFIFOAT_001(); -} -#endif - -/* * - * @tc.name: IPC_TEST_MKFIFOAT_002 - * @tc.desc: function for IoTest:mkfifoat-innormal test - * @tc.type: FUNC - */ -#if 0 -HWTEST_F(IoTest, IPC_TEST_MKFIFOAT_002, TestSize.Level0) -{ - IPC_TEST_MKFIFOAT_002(); -} -#endif -#endif } // namespace OHOS diff --git a/testsuites/unittest/extended/signal/smoke/mkfifo_test_001.cpp b/testsuites/unittest/extended/signal/smoke/mkfifo_test_001.cpp index a0832bb5..fb4c3d83 100644 --- a/testsuites/unittest/extended/signal/smoke/mkfifo_test_001.cpp +++ b/testsuites/unittest/extended/signal/smoke/mkfifo_test_001.cpp @@ -56,11 +56,17 @@ static int TestMkfifo() return -1; } else if (pid == 0) { fd = open("/dev/fifo", O_WRONLY); + if (fd < 0) { + return -1; + } write(fd, sentence, sizeof(sentence) + 1); close(fd); exit(0); } else { fd = open("/dev/fifo", O_RDONLY); + if (fd < 0) { + return -1; + } read(fd, buffer, sizeof(buffer)); printf("Receive data: %s\n", buffer); close(fd); diff --git a/testsuites/unittest/libc/io/full/It_stdio_fwprintf_001.cpp b/testsuites/unittest/libc/io/full/It_stdio_fwprintf_001.cpp index 6cda97ad..1bf57114 100644 --- a/testsuites/unittest/libc/io/full/It_stdio_fwprintf_001.cpp +++ b/testsuites/unittest/libc/io/full/It_stdio_fwprintf_001.cpp @@ -60,6 +60,8 @@ static UINT32 Testcase(VOID) fclose(testFile); testFile = fopen(pathname, "r"); + ICUNIT_GOTO_NOT_EQUAL(testFile, NULL, testFile, EXIT); + p = fgetws(tarStr, 16, testFile); // 16, read size,total write and '\0' nRet = wcscmp(L"hello world 666", tarStr); ICUNIT_GOTO_EQUAL(nRet, 0, nRet, EXIT); diff --git a/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp b/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp index f493a15c..151a7b4b 100644 --- a/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp +++ b/testsuites/unittest/libc/io/full/It_stdio_hasmntopt_001.cpp @@ -55,6 +55,10 @@ static UINT32 testcase(VOID) } mnt_new = (struct mntent *)malloc(sizeof(struct mntent)); + if (mnt_new == NULL) { + (VOID)RecoveryFileEnv(pathList, 1); + return LOS_NOK; + } mnt_new->mnt_fsname = "UUID=c4992556-a86e-45e8-ba5f-190b16a9073x"; mnt_new->mnt_dir = "/usr1"; mnt_new->mnt_type = "ext3"; diff --git a/testsuites/unittest/libc/io/full/It_stdio_putwc_001.cpp b/testsuites/unittest/libc/io/full/It_stdio_putwc_001.cpp index 6c122743..a3667385 100644 --- a/testsuites/unittest/libc/io/full/It_stdio_putwc_001.cpp +++ b/testsuites/unittest/libc/io/full/It_stdio_putwc_001.cpp @@ -55,6 +55,8 @@ static UINT32 Testcase(VOID) fclose(putwcFile); putwcFile = fopen(pathname, "r"); + ICUNIT_GOTO_NOT_EQUAL(putwcFile, NULL, putwcFile, EXIT); + tarWc = getwc(putwcFile); ICUNIT_GOTO_EQUAL(tarWc, L'H', tarWc, EXIT); diff --git a/testsuites/unittest/libc/posix/mqueue/full/It_posix_queue_134.cpp b/testsuites/unittest/libc/posix/mqueue/full/It_posix_queue_134.cpp index bc147b0c..1293dce1 100644 --- a/testsuites/unittest/libc/posix/mqueue/full/It_posix_queue_134.cpp +++ b/testsuites/unittest/libc/posix/mqueue/full/It_posix_queue_134.cpp @@ -44,8 +44,6 @@ static UINT32 Testcase(VOID) ICUNIT_GOTO_EQUAL(ret, MQUEUE_IS_ERROR, ret, EXIT1); - ICUNIT_GOTO_EQUAL(ret, MQUEUE_IS_ERROR, ret, EXIT1); - ret = mq_close(mqueue); ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1); diff --git a/testsuites/unittest/libc/posix/pthread/full/It_posix_pthread_044.cpp b/testsuites/unittest/libc/posix/pthread/full/It_posix_pthread_044.cpp index 9c8c79d9..35e76fe0 100644 --- a/testsuites/unittest/libc/posix/pthread/full/It_posix_pthread_044.cpp +++ b/testsuites/unittest/libc/posix/pthread/full/It_posix_pthread_044.cpp @@ -43,7 +43,6 @@ static VOID *pthread_f02(void *argument) ret = pthread_getschedparam(pthread_self(), &policy, ¶m); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); - ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(policy, SCHED_RR, policy, EXIT); // ICUNIT_GOTO_EQUAL(param.sched_priority, 3, param.sched_priority, EXIT); @@ -63,7 +62,6 @@ static VOID *pthread_f01(void *argument) ret = pthread_getschedparam(pthread_self(), &policy, ¶m); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); - ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ICUNIT_GOTO_EQUAL(policy, SCHED_RR, policy, EXIT); // ICUNIT_GOTO_EQUAL(param.sched_priority, 4, param.sched_priority, EXIT); diff --git a/testsuites/unittest/libc/sys/smoke/sys_test_007.cpp b/testsuites/unittest/libc/sys/smoke/sys_test_007.cpp index 46a2e04d..cc14a156 100644 --- a/testsuites/unittest/libc/sys/smoke/sys_test_007.cpp +++ b/testsuites/unittest/libc/sys/smoke/sys_test_007.cpp @@ -43,7 +43,7 @@ static UINT32 TestCase(VOID) ICUNIT_GOTO_NOT_EQUAL(p, NULL, p, EXIT); x = drand48(); - printf("x= %d\n", x); + printf("x= %lf\n", x); return 0; EXIT: diff --git a/testsuites/unittest/libc/sys/smoke/sys_test_030.cpp b/testsuites/unittest/libc/sys/smoke/sys_test_030.cpp index 59384fa4..8e3bc49e 100644 --- a/testsuites/unittest/libc/sys/smoke/sys_test_030.cpp +++ b/testsuites/unittest/libc/sys/smoke/sys_test_030.cpp @@ -42,18 +42,6 @@ static void sig_alarm(int signum) static UINT32 TestCase(VOID) { -#if 0 - int alarm_time = 1; - int ret; - - signal(SIGALRM, sig_alarm); - alarm(alarm_time); - ret = sigsetjmp(jmp_env, 1); - if (ret) { - ICUNIT_ASSERT_EQUAL(ret, val, ret); - } - sleep(3); -#endif return 0; } diff --git a/testsuites/unittest/libc/util/smoke/util_test_003.cpp b/testsuites/unittest/libc/util/smoke/util_test_003.cpp index 6ebea016..867aa173 100644 --- a/testsuites/unittest/libc/util/smoke/util_test_003.cpp +++ b/testsuites/unittest/libc/util/smoke/util_test_003.cpp @@ -48,6 +48,9 @@ static UINT32 TestCase(VOID) NULL }; CHAR *buf = (char *)malloc(TEST_BUF_SIZE); + if (buf == NULL) { + return -1; + } CHAR *a = TEST_STR; CHAR *value = NULL; CHAR *subopts = NULL; diff --git a/testsuites/unittest/libc/util/smoke/util_test_007.cpp b/testsuites/unittest/libc/util/smoke/util_test_007.cpp index cacdae8d..80dc8212 100644 --- a/testsuites/unittest/libc/util/smoke/util_test_007.cpp +++ b/testsuites/unittest/libc/util/smoke/util_test_007.cpp @@ -87,11 +87,13 @@ static UINT32 TestCase(VOID) ptr = (int *)Xmalloc(sizeof(int)); *ptr = rand() & 0xff; val = tsearch((void *)ptr, &g_root, Compare); - if (val == NULL) + if (val == NULL) { exit(EXIT_FAILURE); - else if ((*(int **)val) != ptr) + } else if ((*(int **)val) != ptr) { free(ptr); + } } + twalk(g_root, Action); tdestroy(g_root, free); diff --git a/testsuites/unittest/net/socket/smoke/net_socket_test_003.cpp b/testsuites/unittest/net/socket/smoke/net_socket_test_003.cpp index 6dbcab64..92500214 100644 --- a/testsuites/unittest/net/socket/smoke/net_socket_test_003.cpp +++ b/testsuites/unittest/net/socket/smoke/net_socket_test_003.cpp @@ -83,7 +83,7 @@ static int SampleTcpServer() ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, sfd); /* send */ - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = strcpy_s(gBuf, BUF_SIZE - 1, SRV_MSG); @@ -94,7 +94,7 @@ static int SampleTcpServer() ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), ret); /* recv */ - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = recv(sfd, gBuf, sizeof(gBuf), 0); @@ -107,7 +107,7 @@ static int SampleTcpServer() clnAddr.sin_family = AF_INET; clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); clnAddr.sin_port = htons(PEER_PORT); - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = strcpy_s(gBuf, BUF_SIZE - 1, SRV_MSG); @@ -128,7 +128,7 @@ static int SampleTcpServer() Wait(); /* recvmsg */ - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = memset_s(&msg, sizeof(msg), 0, sizeof(msg)); @@ -196,7 +196,7 @@ static int SampleTcpClient() inet_addr(STACK_IP), ((struct sockaddr_in*)&addr)->sin_addr.s_addr); /* send */ - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = strcpy_s(gBuf, BUF_SIZE - 1, CLI_MSG); @@ -207,7 +207,7 @@ static int SampleTcpClient() ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), ret); /* recv */ - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = recv(sfd, gBuf, sizeof(gBuf), 0); @@ -220,7 +220,7 @@ static int SampleTcpClient() clnAddr.sin_family = AF_INET; clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); clnAddr.sin_port = htons(PEER_PORT); - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = strcpy_s(gBuf, BUF_SIZE - 1, CLI_MSG); @@ -241,7 +241,7 @@ static int SampleTcpClient() Wait(); /* recvmsg */ - ret = memset_s(gBuf, BUF_SIZE - 1, 0, BUF_SIZE - 1); + ret = memset_s(gBuf, BUF_SIZE + 1, 0, BUF_SIZE + 1); ICUNIT_ASSERT_EQUAL(ret, 0, ret); gBuf[BUF_SIZE - 1] = '\0'; ret = memset_s(&msg, sizeof(msg), 0, sizeof(msg)); diff --git a/testsuites/unittest/net/socket/smoke/net_socket_test_007.cpp b/testsuites/unittest/net/socket/smoke/net_socket_test_007.cpp index f3418093..94bc166b 100644 --- a/testsuites/unittest/net/socket/smoke/net_socket_test_007.cpp +++ b/testsuites/unittest/net/socket/smoke/net_socket_test_007.cpp @@ -139,13 +139,17 @@ static int TcpTest() } else { printf("malloc 20M success\n"); ret = memset_s(buf, bufSiz, 0, bufSiz); - ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); ret = send(lsfd, buf, bufSiz, 0); printf("send ret = %d, errno :%d\n", ret, errno); - ICUNIT_ASSERT_EQUAL(ret, -1, ret); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); } -#endif +EXIT: + if (buf != NULL) { + free(buf); + } +#endif close(lsfd); return 0; } diff --git a/testsuites/unittest/process/basic/process/full/process_test_066.cpp b/testsuites/unittest/process/basic/process/full/process_test_066.cpp index a29be892..f12bd0d3 100644 --- a/testsuites/unittest/process/basic/process/full/process_test_066.cpp +++ b/testsuites/unittest/process/basic/process/full/process_test_066.cpp @@ -149,6 +149,9 @@ static int TestSpawnAttr(short flag) ICUNIT_GOTO_EQUAL(status, 0, status, EXIT); fd = open("/storage/testspawnattr.txt", O_RDWR | O_CREAT, 0644); // 0644, open config + if (fd < 0) { + goto EXIT; + } ret = read(fd, temp, NUMMAX); ICUNIT_GOTO_EQUAL(ret, NUMMAX, ret, EXIT1); diff --git a/testsuites/unittest/process/basic/process/smoke/process_test_046.cpp b/testsuites/unittest/process/basic/process/smoke/process_test_046.cpp index 0232fff3..a6f849a1 100644 --- a/testsuites/unittest/process/basic/process/smoke/process_test_046.cpp +++ b/testsuites/unittest/process/basic/process/smoke/process_test_046.cpp @@ -51,7 +51,6 @@ static int Testcase(void) CPU_SET(1, &cpuset); /* cpu1 unsupported operation */ ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset); ICUNIT_GOTO_EQUAL(ret, -1, ret, ERROR_OUT); - CPU_ZERO(&cpuset); CPU_ZERO(&cpuset); CPU_SET(0, &cpuset); /* cpu0 */ diff --git a/testsuites/unittest/security/vid/smoke/vid_test_001.cpp b/testsuites/unittest/security/vid/smoke/vid_test_001.cpp index d2dc6be0..631dcf28 100644 --- a/testsuites/unittest/security/vid/smoke/vid_test_001.cpp +++ b/testsuites/unittest/security/vid/smoke/vid_test_001.cpp @@ -55,7 +55,14 @@ static void ChildFunc() ent.sigev_signo = SIGUSR1; tid2 = (timer_t *)malloc(sizeof(UINTPTR) * 1024); + if (tid2 == NULL) { + return; + } ret1 = (int *)malloc(sizeof(int) * 1024); + if (ret1 == NULL) { + free(tid2); + return; + } (void)memset_s(tid2, sizeof(char *) * 1024, 0, sizeof(char *) * 1024); (void)memset_s(ret1, sizeof(int) * 1024, 0xff, sizeof(int) * 1024); while (i < 1024) { -- GitLab