diff --git a/kernel_lite/io_posix/src/IoTestOther.cpp b/kernel_lite/io_posix/src/IoTestOther.cpp old mode 100755 new mode 100644 index deb3048dbcf7ec1899116ad601896ff7fca4f938..c702d485b4d82baddc5330b7c8687a01d661df13 --- a/kernel_lite/io_posix/src/IoTestOther.cpp +++ b/kernel_lite/io_posix/src/IoTestOther.cpp @@ -213,7 +213,9 @@ HWTEST_F(IoTest, testPread, Function | MediumTest | Level1) HWTEST_F(IoTest, testStrptime, Function | MediumTest | Level1) { struct tm tm; - memset_s(&tm, sizeof(struct tm), 0, sizeof(struct tm)); + int memRet = -1; + memRet = memset_s(&tm, sizeof(struct tm), 0, sizeof(struct tm)); + EXPECT_EQ(0, memRet); char *ret = strptime("2020-10-29 21:24:00abc", "%Y-%m-%d %H:%M:%S", &tm); EXPECT_STREQ(ret, "abc"); EXPECT_EQ(tm.tm_year, 120); diff --git a/kernel_lite/io_posix/src/IoTestWchar.cpp b/kernel_lite/io_posix/src/IoTestWchar.cpp old mode 100755 new mode 100644 index 82ced31b5cc5942ded5627e84b09b630bc9f3fc8..9f656b1e986aae07029b2a284e7d830909f0fdce --- a/kernel_lite/io_posix/src/IoTestWchar.cpp +++ b/kernel_lite/io_posix/src/IoTestWchar.cpp @@ -334,10 +334,12 @@ HWTEST_F(IoTest, testMbsinit, Function | MediumTest | Level1) { mbstate_t *ps = nullptr; int ret = mbsinit(ps); + int memRet = -1; EXPECT_NE(ret, 0); mbstate_t psF; - memset_s(&psF, sizeof(psF), 0, sizeof(psF)); + memRet = memset_s(&psF, sizeof(psF), 0, sizeof(psF)); + EXPECT_EQ(0, memRet); ret = mbsinit(&psF); EXPECT_NE(ret, 0); } diff --git a/kernel_lite/ipc_posix/message_queue/IpcMqExceptionTest.cpp b/kernel_lite/ipc_posix/message_queue/IpcMqExceptionTest.cpp old mode 100755 new mode 100644 index e9a22cf94c54492e424d40a4c29a5f6b14d1f105..86bdf1c84cfaf45dc015c0cad5a2c22203f76588 --- a/kernel_lite/ipc_posix/message_queue/IpcMqExceptionTest.cpp +++ b/kernel_lite/ipc_posix/message_queue/IpcMqExceptionTest.cpp @@ -811,8 +811,10 @@ HWTEST_F(IpcMqTest, testMqGetAttrEBADFEINVAL, Function | MediumTest | Level2) mqd_t queue; struct mq_attr mqstat = { 0 }; char qName[MQ_NAME_LEN]; + int memRet = -1; - memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + memRet = memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + EXPECT_EQ(0, memRet); sprintf(qName, "testMqSendEINVAL_%d", GetRandom(10000)); queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, NULL); @@ -839,13 +841,16 @@ HWTEST_F(IpcMqTest, testMqSetAttrEBADFEINVAL, Function | MediumTest | Level2) char qName[MQ_NAME_LEN]; mqd_t queue; struct mq_attr gMqstat = { 0 }, sMqstat = { 0 }; + int memRet = -1; sprintf(qName, "testMqSetAttrEBADFEINVAL_%d", GetRandom(10000)); queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); ASSERT_TRUE(queue != (mqd_t)-1) << "ERROR: mq_open() == (mqd_t)-1"; - memset_s(&gMqstat, sizeof(gMqstat), 0, sizeof(gMqstat)); - memset_s(&sMqstat, sizeof(sMqstat), 0, sizeof(sMqstat)); + memRet = memset_s(&gMqstat, sizeof(gMqstat), 0, sizeof(gMqstat)); + EXPECT_EQ(0, memRet); + memRet = memset_s(&sMqstat, sizeof(sMqstat), 0, sizeof(sMqstat)); + EXPECT_EQ(0, memRet); EXPECT_TRUE(mq_getattr(queue, &gMqstat) == 0) << "ERROR: mq_getattr() != 0"; sMqstat.mq_flags |= O_NONBLOCK; diff --git a/kernel_lite/ipc_posix/message_queue/IpcMqTest.cpp b/kernel_lite/ipc_posix/message_queue/IpcMqTest.cpp old mode 100755 new mode 100644 index 0ab49db146e950ac704cb1f2c566fd36c664e8d7..9faeb127460e9283cb5088be497e8620c0e12238 --- a/kernel_lite/ipc_posix/message_queue/IpcMqTest.cpp +++ b/kernel_lite/ipc_posix/message_queue/IpcMqTest.cpp @@ -108,6 +108,7 @@ HWTEST_F(IpcMqTest, testMqTimedOneLevelCom, Function | MediumTest | Level1) HWTEST_F(IpcMqTest, testMqAllOneLevelCom, Function | MediumTest | Level2) { mqd_t queue; + int memRet = -1; unsigned int prio; struct timespec tts { 0 }, rts = { 0 }; struct mq_attr getAttr = { 0 }; @@ -116,8 +117,10 @@ HWTEST_F(IpcMqTest, testMqAllOneLevelCom, Function | MediumTest | Level2) sprintf_s(qName, sizeof(qName), "testMqAllOneLevelCom_%d", GetRandom(10000)); - memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr)); - memset_s(&setAttr, sizeof(setAttr), 0, sizeof(setAttr)); + memRet = memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr)); + EXPECT_EQ(0, memRet); + memRet = memset_s(&setAttr, sizeof(setAttr), 0, sizeof(setAttr)); + EXPECT_EQ(0, memRet); setAttr.mq_msgsize = MQ_MSG_SIZE; setAttr.mq_maxmsg = MQ_MAX_MSG; queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); @@ -664,17 +667,20 @@ HWTEST_F(IpcMqTest, testMqSetGetAttr, Function | MediumTest | Level1) struct mq_attr getAttr = { 0 }; struct mq_attr setAttr = { 0 }; char qName[MQ_NAME_LEN]; + int memRet = -1; sprintf_s(qName, sizeof(qName), "testMqFunction_%d", GetRandom(10000)); - memset_s(&setAttr, sizeof(setAttr), 0, sizeof(setAttr)); + memRet = memset_s(&setAttr, sizeof(setAttr), 0, sizeof(setAttr)); + EXPECT_EQ(0, memRet); setAttr.mq_msgsize = MQ_MSG_SIZE; setAttr.mq_maxmsg = MQ_MAX_MSG; setAttr.mq_flags = O_NONBLOCK; queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); ASSERT_TRUE(queue != (mqd_t)-1) << "ERROR: mq_open() == (mqd_t)-1"; - memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr)); + memRet = memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr)); + EXPECT_EQ(0, memRet); EXPECT_TRUE(mq_getattr(queue, &getAttr) == 0) << "ERROR: mq_getattr() != 0"; EXPECT_TRUE((getAttr.mq_flags & O_NONBLOCK) == O_NONBLOCK); diff --git a/kernel_lite/ipc_posix/pipe_fifo/FifoTest.cpp b/kernel_lite/ipc_posix/pipe_fifo/FifoTest.cpp old mode 100755 new mode 100644 index 0d639d62601c72dea430c3d89eba67bd5923373c..91789433a868452d4eb2563fb9e11e81b3c12ad3 --- a/kernel_lite/ipc_posix/pipe_fifo/FifoTest.cpp +++ b/kernel_lite/ipc_posix/pipe_fifo/FifoTest.cpp @@ -107,8 +107,10 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1) const int arrSize = MAX_PIPE_BUFFER + 10; int fd = -1; int tmpInt; + int memRet = -1; char testBuffer[arrSize]; - memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); + memRet = memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); + EXPECT_EQ(0, memRet); int ret = mkfifo(FIFO_PATH, 0666); EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno; @@ -117,7 +119,8 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1) ASSERT_TRUE(pid >= 0) << "> parent : fork : error"; if (pid == 0) { char readBuffer[arrSize]; - memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + memRet = memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + EXPECT_EQ(0, memRet); fd = open(FIFO_PATH, O_RDONLY, S_IRUSR|S_IWUSR); if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { LOG("> fcntl errno = %d", errno); @@ -141,7 +144,8 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1) } // parent char writeBuffer[arrSize]; - memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + memRet = memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + EXPECT_EQ(0, memRet); fd = open(FIFO_PATH, O_WRONLY, S_IRUSR|S_IWUSR); EXPECT_NE(fd, -1) << "> open faild errno = " << errno; EXPECT_NE(fcntl(fd, F_SETFL, O_NONBLOCK), -1) << "> fcntl errno = " << errno; @@ -168,7 +172,9 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1) int fd = -1; int tmpInt; char testBuffer[arrSize]; - memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); + int memRet = -1; + memRet = memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); + EXPECT_EQ(0, memRet); int ret = mkfifo(FIFO_PATH, 0666); EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno; @@ -177,7 +183,8 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1) ASSERT_TRUE(pid >= 0) << "> parent : fork : error"; if (pid == 0) { char readBuffer[arrSize]; - memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + memRet = memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + EXPECT_EQ(0, memRet); fd = open(FIFO_PATH, O_RDONLY); Msleep(60); @@ -197,7 +204,8 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1) } // parent char writeBuffer[arrSize]; - memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + memRet = memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + EXPECT_EQ(0, memRet); fd = open(FIFO_PATH, O_WRONLY, S_IRUSR|S_IWUSR); EXPECT_NE(fd, -1) << "> open faild errno = " << errno; diff --git a/kernel_lite/ipc_posix/pipe_fifo/PipeTest.cpp b/kernel_lite/ipc_posix/pipe_fifo/PipeTest.cpp old mode 100755 new mode 100644 index ee5d7659136bbf94ff79cd159bc9ecc89434d4f1..9ed7687bddcd685aa79d61e64405bfc256736640 --- a/kernel_lite/ipc_posix/pipe_fifo/PipeTest.cpp +++ b/kernel_lite/ipc_posix/pipe_fifo/PipeTest.cpp @@ -121,8 +121,10 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3) const int arrSize = MAX_PIPE_BUFFER + 1000; int fd[2]; int tmpInt; + int memRet = -1; char testBuffer[arrSize]; - memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); + memRet = memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); + EXPECT_EQ(0, memRet); printf("abcd \n"); tmpInt = pipe(fd); ASSERT_EQ(tmpInt, 0) << "> parent: Create Pipe Error! "; @@ -132,7 +134,8 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3) ASSERT_TRUE(pid >= 0) << "> parent: error : fork"; if (pid == 0) { char readBuffer[arrSize]; - memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + memRet = memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + EXPECT_EQ(0, memRet); close(fd[1]); Msleep(60); @@ -155,7 +158,8 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3) // parent char writeBuffer[arrSize]; - memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + memRet = memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + EXPECT_EQ(0, memRet); close(fd[0]); Msleep(30); @@ -181,8 +185,9 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2) int fd[2]; int ret; char testBuffer[arrSize]; - memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); - + int memRet = -1; + memRet = memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); + EXPECT_EQ(0, memRet); ret = pipe(fd); ASSERT_EQ(ret, 0) << "> parent: Create Pipe Error! "; @@ -190,7 +195,8 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2) ASSERT_TRUE(pid >= 0) << "> parent: error : fork"; if (pid == 0) { char readBuffer[arrSize]; - memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + memRet = memset_s(readBuffer, sizeof(readBuffer), 0, sizeof(readBuffer)); + EXPECT_EQ(0, memRet); close(fd[1]); Msleep(60); @@ -210,7 +216,8 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2) // parent char writeBuffer[arrSize]; - memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + memRet = memset_s(writeBuffer, sizeof(writeBuffer), '1', sizeof(writeBuffer)); + EXPECT_EQ(0, memRet); close(fd[0]); Msleep(30); diff --git a/kernel_lite/ipc_posix/signal/SignalTest.cpp b/kernel_lite/ipc_posix/signal/SignalTest.cpp old mode 100755 new mode 100644 index 7df77bf21eae2bb97d396b99acfd0873b1866bb0..11532af5f8888f2f6873efce3ff8ea36e64ec483 --- a/kernel_lite/ipc_posix/signal/SignalTest.cpp +++ b/kernel_lite/ipc_posix/signal/SignalTest.cpp @@ -108,7 +108,7 @@ INSTANTIATE_TEST_CASE_P(AllSignalTest, IpcSignalTest, testing::Range(1, MAX_SIGN /** * @tc.number SUB_KERNEL_IPC_SIG_ALL_0300 - * @tc.name test SIGKILL can't blocked. SIGSTOP can't be blocked too, but not suppported by liteos + * @tc.name test SIGKILL can't blocked. SIGSTOP can't be blocked too, but not supported by liteos * @tc.desc [C- SOFTWARE -0200] */ HWTEST_F(IpcSignalTest, testBlockSIGKILL, Function | MediumTest | Level2) @@ -496,9 +496,9 @@ HWTEST_F(IpcSignalTest, testSigtimedwaitBlock, Function | MediumTest | Level1) /** * @tc.number SUB_KERNEL_IPC_SIGTIMEDWAIT_0200 - * @tc.name sigtimedwait error test: timeout or interupted. - * by now, liteos sigtimedwait cannot interupted - * so the interupte-check-code will run only when 'POSIX_TEST' is set + * @tc.name sigtimedwait error test: timeout or interrupted. + * by now, liteos sigtimedwait cannot interrupted + * so the interrupted-check-code will run only when 'POSIX_TEST' is set * @tc.desc [C- SOFTWARE -0200] */ HWTEST_F(IpcSignalTest, testSigtimedwaitTimeout, Function | MediumTest | Level2) @@ -1085,7 +1085,7 @@ HWTEST_F(IpcSignalTest, testSigsuspendTerminate, Function | MediumTest | Level1) Msleep(20); AssertProcAlive(pid); - kill(pid, SIGTRAP); // this should interupt sigsuspend + kill(pid, SIGTRAP); // this should interrupt sigsuspend Msleep(100); WaitProcKilled(pid, SIGHUP); } @@ -1190,7 +1190,7 @@ HWTEST_F(IpcSignalTest, testSigsuspendAndMask, Function | MediumTest | Level1) Msleep(20); AssertProcAlive(pid); - kill(pid, SIGINT); // this should interupt sigsuspend + kill(pid, SIGINT); // this should interrupt sigsuspend Msleep(100); AssertProcExitedOK(pid); } diff --git a/kernel_lite/ipc_posix/signal/SignalTestUtils.cpp b/kernel_lite/ipc_posix/signal/SignalTestUtils.cpp old mode 100755 new mode 100644 index 71cebcd2f7c678ae6c950d267df5c213ac7796f3..7021918dcdbb8288ae10206e30916ce753f09a7d --- a/kernel_lite/ipc_posix/signal/SignalTestUtils.cpp +++ b/kernel_lite/ipc_posix/signal/SignalTestUtils.cpp @@ -30,10 +30,10 @@ int IpcSignalTest::mShmid = 0; siginfo_t IpcSignalTest::mSiginfo; -// special signal hander for function 'abort' +// special signal handler for function 'abort' void IpcSignalTest::SigAbortHandler(int signum) { - LOG("hander: recv a signal: %d", signum); + LOG("handler: recv a signal: %d", signum); int *shared = static_cast(shmat(mShmid, nullptr, 0)); if (shared == reinterpret_cast(-1)) { LOG("SigAbortHandler: shmat fail, errno = %d", errno); @@ -49,15 +49,15 @@ void IpcSignalTest::SigAbortHandler(int signum) // special signal handler for function 'sigaction' void IpcSignalTest::SigactionHandler(int signum, siginfo_t* si, void* ucontext) { - LOG("hander recv a signal: %s(%d)", ALL_SIGNALS[signum].signame, signum); + LOG("handler recv a signal: %s(%d)", ALL_SIGNALS[signum].signame, signum); mReceivedSignal = signum; // siginfo_t para is not supported yet } -// general signal hander. note: not thread-safe +// general signal handler. note: not thread-safe void IpcSignalTest::SignalHandler(int signum) { - LOG("hander recv a signal: %s(%d)", ALL_SIGNALS[signum].signame, signum); + LOG("handler recv a signal: %s(%d)", ALL_SIGNALS[signum].signame, signum); mReceivedSignal = signum; } @@ -101,7 +101,7 @@ void IpcSignalTest::DefaultActionTest(const int signum, const bool expectStop, c ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; if (pid > 0) { // parent Msleep(20); - LOGD("befor kill"); + LOGD("before kill"); kill(pid, signum); if (!expectStop) { Msleep(20); diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c index 483d512d9bdc861a277c82e969dc5a0eb2378f7d..562537083df5af2e8114d35a01470c1f48a01ae2 100644 --- a/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c @@ -136,24 +136,24 @@ static void CmsisThreadCreat004Func001(void const *argument) static void KeepRunByTick(UINT32 tick) { UINT32 tickA = osKernelGetTickCount(); - UINT32 runned = 0; + UINT32 ran = 0; UINT32 loop = 0; UINT32 tickB = 0; - while (runned < tick) { + while (ran < tick) { loop++; tickB = osKernelGetTickCount(); if (tickB >= tickA) { - runned = tickB - tickA; + ran = tickB - tickA; } else { - runned = tickB + (MAX_UINT32 - tickA); + ran = tickB + (MAX_UINT32 - tickA); } if (loop % ALIVE_INFO_DIS == 0) { - printf("runned:%u, tickB:%u, tickA:%u, loop:%u\t\n", - runned, tickB, tickA, loop); + printf("ran:%u, tickB:%u, tickA:%u, loop:%u\t\n", + ran, tickB, tickA, loop); } } - printf("return runned:%u, tickB:%u, tickA:%u\t\n", - runned, tickB, tickA); + printf("return ran:%u, tickB:%u, tickA:%u\t\n", + ran, tickB, tickA); return; } @@ -532,7 +532,7 @@ LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew004, Function | MediumTest /** * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0200 - * @tc.name : thread operation for cycle schdule + * @tc.name : thread operation for cycle schedule * @tc.desc : [C- SOFTWARE -0200] */ LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew005, Function | MediumTest | Level1) diff --git a/kernel_lite/mem_posix/src/MemApiTest.cpp b/kernel_lite/mem_posix/src/MemApiTest.cpp old mode 100755 new mode 100644 index b1c0a09e6b82d0af0fd7484f39a549cf32a0117a..4dfd49b63985a209ca37a369566cea523fc317ad --- a/kernel_lite/mem_posix/src/MemApiTest.cpp +++ b/kernel_lite/mem_posix/src/MemApiTest.cpp @@ -122,6 +122,7 @@ HWTEST_F(MemApiTest, testReallocMem, Function | MediumTest | Level3) char *data = nullptr; int i, failure; char testChar = 0x36; + void *memp = nullptr; failure = 0; for (i = 1; i < 5; i++) { @@ -131,7 +132,13 @@ HWTEST_F(MemApiTest, testReallocMem, Function | MediumTest | Level3) memset(mem, testChar, mlen); rlen = GetRandom(0x200000); + memp = mem; mem = realloc(mem, rlen); + if (mem == nullptr) { + free(memp); + } else { + memp = nullptr; + } ASSERT_TRUE(mem != nullptr) << "mem == NULL, i = " << i; len = mlen <= rlen ? mlen : rlen; diff --git a/kernel_lite/net_posix/src/ActsNetTest.cpp b/kernel_lite/net_posix/src/ActsNetTest.cpp old mode 100755 new mode 100644 index e15de20e3b1834e3b6231697526004fe3f3d34c2..d528ed41ab18a0ca99595901aed1b5cfe6fe218d --- a/kernel_lite/net_posix/src/ActsNetTest.cpp +++ b/kernel_lite/net_posix/src/ActsNetTest.cpp @@ -108,6 +108,7 @@ static int CommInitTcpServer(int port) static void* CommTcpClientTask(void *param) { int* ret = (int *)malloc(sizeof(int)); + int memRet = -1; if (ret == nullptr) { printf("[---][comm client]malloc fail\n"); return nullptr; @@ -138,7 +139,8 @@ static void* CommTcpClientTask(void *param) }; for (int i = 0; i < 4; i++) { sleep(sleepSecond); - memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + memRet = memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + EXPECT_EQ(0, memRet); rst = sprintf_s(dataBuf, sizeof(dataBuf), sendMsgList[i], clnFd); if (rst < 0) { printf("[@@@][comm client]sprintf_s error!\n"); @@ -149,7 +151,8 @@ static void* CommTcpClientTask(void *param) *ret = -1; printf("[@@@][comm client][%d]send fail\n", clnFd); } - memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + memRet = memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + EXPECT_EQ(0, memRet); rst = recv(clnFd, dataBuf, sizeof(dataBuf), 0); if (rst > 0) { printf("[@@@][comm client][%d]recv msg[%s]\n", clnFd, dataBuf); @@ -173,6 +176,7 @@ static void* CommTcpClientTask(void *param) static void* SampleTcpServerTask(void *p) { + int memRet = -1; int srvFd = CommInitTcpServer(STACK_PORT); EXPECT_NE(-1, srvFd); @@ -200,14 +204,16 @@ static void* SampleTcpServerTask(void *p) static char buf[BUF_SIZE + 1] = {0}; unsigned int srvMsgLen = strlen(g_srvMsg); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = strcpy_s(buf, BUF_SIZE, g_srvMsg); EXPECT_EQ(0, ret); ret = send(clnFd, buf, srvMsgLen, 0); printf("[tcp server]send, ret=%d\n", ret); EXPECT_EQ(srvMsgLen, (unsigned int)ret); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet =memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = recv(clnFd, buf, sizeof(buf), 0); printf("[tcp server]recv, ret=%d, msg[%s]\n", ret, buf); EXPECT_EQ(strlen(g_cliMsg), (unsigned int)ret); @@ -219,7 +225,8 @@ static void* SampleTcpServerTask(void *p) clnAddr.sin_family = AF_INET; clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_port = htons(PEER_PORT); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = strcpy_s(buf, BUF_SIZE, g_srvMsg); EXPECT_EQ(0, ret); msg.msg_name = &clnAddr; @@ -236,8 +243,10 @@ static void* SampleTcpServerTask(void *p) WAIT(); static char bufrec[BUF_SIZE + 1] = {0}; - memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); - memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + memRet = memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); + EXPECT_EQ(0, memRet); + memRet = memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + EXPECT_EQ(0, memRet); msg.msg_name = &clnAddr; msg.msg_namelen = sizeof(clnAddr); msg.msg_iov = iov; @@ -265,6 +274,7 @@ static void* SampleTcpServerTask(void *p) static void* SampleTcpClientTask(void *p) { + int memRet = -1; int clnFd = socket(AF_INET, SOCK_STREAM, 0); printf("[tcp client]create socket\n"); EXPECT_NE(-1, clnFd); @@ -294,14 +304,16 @@ static void* SampleTcpClientTask(void *p) static char buf[BUF_SIZE + 1] = {0}; unsigned int cliMsgLen = strlen(g_cliMsg); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = strcpy_s(buf, BUF_SIZE, g_cliMsg); EXPECT_EQ(0, ret); ret = send(clnFd, buf, cliMsgLen, 0); printf("[tcp client]send, ret=%d\n", ret); EXPECT_EQ(cliMsgLen, (unsigned int)ret); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = recv(clnFd, buf, sizeof(buf), 0); printf("[tcp client]recv, ret=%d, msg[%s]\n", ret, buf); EXPECT_EQ(strlen(g_srvMsg), (unsigned int)ret); @@ -314,7 +326,8 @@ static void* SampleTcpClientTask(void *p) clnAddr.sin_family = AF_INET; clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_port = htons(PEER_PORT); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = strcpy_s(buf, BUF_SIZE, g_cliMsg); EXPECT_EQ(0, ret); msg.msg_name = &clnAddr; @@ -331,8 +344,10 @@ static void* SampleTcpClientTask(void *p) WAIT(); static char bufrec[BUF_SIZE + 1] = {0}; - memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); - memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + memRet = memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); + EXPECT_EQ(0, memRet); + memRet = memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + EXPECT_EQ(0, memRet); msg.msg_name = &clnAddr; msg.msg_namelen = sizeof(clnAddr); msg.msg_iov = iov; @@ -438,6 +453,7 @@ static void* TcpClientOnlyConnectTask(void *p) static int TcpServerForFork() { + int memRet = -1; int timeout = 10; char dataBuf[50] = {0}; int srvFd = CommInitTcpServer(STACK_PORT + 1); @@ -454,7 +470,8 @@ static int TcpServerForFork() goto FINALLY; } while (timeout > 0) { - memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + memRet = memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + EXPECT_EQ(0, memRet); ret = recv(cliFd, dataBuf, sizeof(dataBuf), 0); if (ret > 0) { printf("[---][server process]recv msg[%s]\n", dataBuf); @@ -465,7 +482,8 @@ static int TcpServerForFork() } else { printf("[---][server process]recv no data\n"); } - memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + memRet = memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + EXPECT_EQ(0, memRet); sprintf_s(dataBuf, sizeof(dataBuf), "server timeout:%d", timeout); ret = send(cliFd, dataBuf, strlen(dataBuf), 0); if (ret > 0) { @@ -485,6 +503,7 @@ FINALLY: static int SelectServerForFork(unsigned int timeoutSec) { + int memRet = -1; int srvFd = CommInitTcpServer(STACK_PORT + 1); if (srvFd == -1) { return -1; @@ -543,7 +562,8 @@ static int SelectServerForFork(unsigned int timeoutSec) continue; } if (FD_ISSET(fds[i], &readSet)) { - memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + memRet = memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + EXPECT_EQ(0, memRet); int len = recv(fds[i], dataBuf, sizeof(dataBuf), 0); if (len > 0) { printf("[***][select process][%d]recv msg[%s]\n", fds[i], dataBuf); @@ -585,6 +605,7 @@ static int PollServerForFork(int timeoutSec) int fdCount = 1; char dataBuf[50] = {0}; struct pollfd fds[TEST_FD_COUNT]; + int memRet = -1; fds[0].events = POLLIN | POLLPRI; fds[0].fd = srvFd; for (int i = 1; i < TEST_FD_COUNT; i++) { @@ -628,7 +649,8 @@ static int PollServerForFork(int timeoutSec) continue; } if (fds[i].revents & POLLIN) { - memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + memRet = memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); + EXPECT_EQ(0, memRet); int len = recv(fds[i].fd, dataBuf, sizeof(dataBuf), 0); if (len > 0) { printf("[***][poll process][%d]recv msg[%s]\n", fds[i].fd, dataBuf); @@ -735,6 +757,7 @@ HWTEST_F(ActsNetTest, testUdpSample, Function | MediumTest | Level2) { int len = 2; char buf[BUF_SIZE + 1]; + int memRet = -1; struct msghdr msg = {nullptr}; struct iovec iov[2] = {nullptr}; struct sockaddr_in srvAddr = {0}; @@ -752,20 +775,23 @@ HWTEST_F(ActsNetTest, testUdpSample, Function | MediumTest | Level2) clnAddr.sin_family = AF_INET; clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_port = htons(PEER_PORT); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = strcpy_s(buf, BUF_SIZE, g_udpMsg); EXPECT_EQ(0, ret); ret = sendto(sfd, buf, strlen(g_udpMsg), 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr)); EXPECT_NE(-1, ret); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = recvfrom(sfd, buf, sizeof(buf), 0, (struct sockaddr*)&clnAddr, &clnAddrLen); EXPECT_EQ(strlen(g_udpMsg), (unsigned int)ret); clnAddr.sin_family = AF_INET; clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_port = htons(PEER_PORT); - memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memRet = memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + EXPECT_EQ(0, memRet); ret = strcpy_s(buf, BUF_SIZE, g_udpMsg); EXPECT_EQ(0, ret); msg.msg_name = &clnAddr; @@ -1059,12 +1085,14 @@ HWTEST_F(ActsNetTest, testPollMultiClients, Function | MediumTest | Level2) */ HWTEST_F(ActsNetTest, testIoctlIfconf, Function | MediumTest | Level2) { + int memRet = -1; int udpFd = socket(AF_INET, SOCK_DGRAM, 0); ASSERT_NE(-1, udpFd); struct ifreq ifr[5]; struct ifconf ifc = {0}; - memset_s(&ifc, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + memRet = memset_s(&ifc, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + EXPECT_EQ(0, memRet); ifc.ifc_len = 5 * sizeof(struct ifreq); ifc.ifc_buf = (char *)ifr; int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc); @@ -1138,10 +1166,12 @@ HWTEST_F(ActsNetTest, testIoctlIfnetAddrOthers, Function | MediumTest | Level2) { int udpFd = socket(AF_INET, SOCK_DGRAM, 0); ASSERT_NE(-1, udpFd); + int memRet = -1; struct ifreq ifr[5]; struct ifconf ifc = {0}; - memset_s(&ifc, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + memRet = memset_s(&ifc, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + EXPECT_EQ(0, memRet); ifc.ifc_len = 5 * sizeof(struct ifreq); ifc.ifc_buf = (char *)ifr; int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc); @@ -1156,7 +1186,8 @@ HWTEST_F(ActsNetTest, testIoctlIfnetAddrOthers, Function | MediumTest | Level2) addr1 = (struct sockaddr_in *)&ifr[i].ifr_addr; if (strcmp("lo", ifr[i].ifr_name) != 0) { // get inet addr - memset_s(&ifrTmp, sizeof(struct ifreq), 0, sizeof(struct ifreq)); + memRet = memset_s(&ifrTmp, sizeof(struct ifreq), 0, sizeof(struct ifreq)); + EXPECT_EQ(0, memRet); ret = strcpy_s(ifrTmp.ifr_name, sizeof(ifrTmp.ifr_name), ifr[i].ifr_name); ret = ioctl(udpFd, SIOCGIFADDR, &ifrTmp); ASSERT_EQ(0, ret) << "ioctl fail[SIOCGIFADDR], errinfo[" << strerror(errno) << "]"; @@ -1192,10 +1223,12 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2) { int udpFd = socket(AF_INET, SOCK_DGRAM, 0); ASSERT_NE(-1, udpFd); + int memRet = -1; struct ifreq ifr[5]; struct ifconf ifc = {0}; - memset_s(&ifc, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + memRet = memset_s(&ifc, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + EXPECT_EQ(0, memRet); ifc.ifc_len = 5 * sizeof(struct ifreq); ifc.ifc_buf = (char *)ifr; int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc); @@ -1212,7 +1245,8 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2) addr = (struct sockaddr_in *)&ifr[i].ifr_addr; if (strcmp("lo", ifr[i].ifr_name) != 0) { // get ifhwaddr - memset_s(&ifrTmp, sizeof(struct ifreq), 0, sizeof(struct ifreq)); + memRet = memset_s(&ifrTmp, sizeof(struct ifreq), 0, sizeof(struct ifreq)); + EXPECT_EQ(0, memRet); ret = strcpy_s(ifrTmp.ifr_name, sizeof(ifrTmp.ifr_name), ifr[i].ifr_name); EXPECT_EQ(0, ret) << "strcpy_s error"; ret = ioctl(udpFd, SIOCGIFHWADDR, &ifrTmp); @@ -1236,6 +1270,7 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2) HWTEST_F(ActsNetTest, testSocketOpt, Function | MediumTest | Level2) { socklen_t len; + int memRet = -1; struct timeval timeout = {0}; int fd = socket(AF_INET, SOCK_STREAM, 0); EXPECT_NE(-1, fd); @@ -1255,7 +1290,8 @@ HWTEST_F(ActsNetTest, testSocketOpt, Function | MediumTest | Level2) ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len); EXPECT_EQ(0, ret); - memset_s(&timeout, len, 0, len); + memRet = memset_s(&timeout, len, 0, len); + EXPECT_EQ(0, memRet); ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); EXPECT_EQ(0, ret); EXPECT_EQ(1000, timeout.tv_sec); diff --git a/kernel_lite/time_posix/src/AlarmTest.cpp b/kernel_lite/time_posix/src/AlarmTest.cpp index 5501d95bfa85ad2e17ce6181f05b3a0dd0856ebb..e6f6b1d7b551cff6f06be43c1d0450c9d5bf33fe 100755 --- a/kernel_lite/time_posix/src/AlarmTest.cpp +++ b/kernel_lite/time_posix/src/AlarmTest.cpp @@ -29,10 +29,10 @@ using namespace testing::ext; // static membor must init before use. int AlarmTest::mReceivedSignal = 0; -// general signal hander +// general signal handler void AlarmTest::SignalHandler(int signum) { - LOG("hander recv a signal: %d", signum); + LOG("handler recv a signal: %d", signum); mReceivedSignal = signum; } diff --git a/kernel_lite/utils/utils.cpp b/kernel_lite/utils/utils.cpp old mode 100755 new mode 100644 index 756a14d67b60d82747c5947257ce453098746a94..be602c7adbf9a5ab25bcb0a6115cef3b0fa3c858 --- a/kernel_lite/utils/utils.cpp +++ b/kernel_lite/utils/utils.cpp @@ -103,7 +103,7 @@ int CheckProcStatus(pid_t pid, int *code, int flag) return 4; } -// start a elf, only check if execve success or not +// start an elf, only check if execve success or not static int StartElf(const char *fname, char * const argv[], char * const envp[]) { int pid = fork(); @@ -285,4 +285,4 @@ int FixCurProcessToOneCpu(int cpuIndex, cpu_set_t *pOldMask) return -1; } return 0; -} \ No newline at end of file +} diff --git a/kernel_lite/utils/utils.h b/kernel_lite/utils/utils.h old mode 100755 new mode 100644 index 215ceab05cef5f7fa90fa9d4199cbe9f6210ec98..31604e2c529af3132ed4050c2a05581ca212802b --- a/kernel_lite/utils/utils.h +++ b/kernel_lite/utils/utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020 - 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -124,7 +124,7 @@ const int EXECVE_RETURN_ERROR = 190; // execve return -1 const int EXECVE_RETURN_OK = 191; // execve return not -1: execve should never return on success /** - * desc: start a elf, check if execve success, and return child process exit code within timeout_sec + * desc: start an elf, check if execve success, and return child process exit code within timeout_sec * input: fname, argv, envp -- parameters for execve * timeout_sec -- timeout of the child executing, default: 5 seconds. * timeout_sec<=0 means no timeout, wait forever until child exit. @@ -176,4 +176,4 @@ int FixCurProcessToOneCpu(int cpuIndex, cpu_set_t* pOldMask); * output: return cpu count */ int GetCpuCount(void); -#endif \ No newline at end of file +#endif