提交 6ba17fc8 编写于 作者: W wangchen

fix: kora工具检视问题修复

【背景】kora工具检视问题修复

【修改方案】
1,对部分代码问题进行整改

【影响】
对现有的产品编译不会有影响。
Signed-off-by: Nwangchen <wangchen64@huawei.com>
Change-Id: Iafc58b7c71e5d139e11a0ae9d98ca5a57fc6549f
上级 f61ecd76
......@@ -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();
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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)
{
......
......@@ -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);
}
......
......@@ -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);
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
......
......@@ -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)
......
......@@ -1337,9 +1337,9 @@ out:
LWIP_STATIC void lwip_arp_usage(const char *cmd)
{
PRINTK("Usage:"\
PRINTK("Usage:"
"\n%s"
"\n%s [-i IF] -s IPADDR HWADDR"\
"\n%s [-i IF] -s IPADDR HWADDR"
"\n%s [-i IF] -d IPADDR\n",
cmd, cmd, cmd);
}
......
......@@ -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))
......
......@@ -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)
......
......@@ -117,7 +117,6 @@ EXIT:
LOS_TaskDelete(g_testTaskID01);
return LOS_OK;
return LOS_OK;
}
VOID ItLosEvent022(VOID) // IT_Layer_ModuleORFeature_No
......
......@@ -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
......
......@@ -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:
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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
......
......@@ -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.
......
......@@ -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)
......
......@@ -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));
......
......@@ -46,19 +46,25 @@ static int testcase(void)
writebuf = (char*)malloc(pageSize);
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);
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;
......
......@@ -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
......
......@@ -76,8 +76,10 @@ static int Testcase(void)
(void)memset_s(buf, pageSize, 0xf, pageSize);
count = write(shmfd, buf, pageSize);
if (count != pageSize) {
free(buf);
ICUNIT_ASSERT_EQUAL(count, pageSize, count);
}
free(buf);
/* Simple MAP_ANONYMOUS */
......
......@@ -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
......@@ -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);
......
......@@ -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);
......
......@@ -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";
......
......@@ -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);
......
......@@ -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);
......
......@@ -43,7 +43,6 @@ static VOID *pthread_f02(void *argument)
ret = pthread_getschedparam(pthread_self(), &policy, &param);
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, &param);
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);
......
......@@ -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:
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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));
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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 */
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册