提交 29a86e35 编写于 作者: L limeng151

修改用例

Signed-off-by: Nlimeng151 <limeng151@huawei.com>
Change-Id: I304f166f521aff1399a88295bbb6bb2ff8e34e8a
上级 fdfc1554
...@@ -213,7 +213,9 @@ HWTEST_F(IoTest, testPread, Function | MediumTest | Level1) ...@@ -213,7 +213,9 @@ HWTEST_F(IoTest, testPread, Function | MediumTest | Level1)
HWTEST_F(IoTest, testStrptime, Function | MediumTest | Level1) HWTEST_F(IoTest, testStrptime, Function | MediumTest | Level1)
{ {
struct tm tm; 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); char *ret = strptime("2020-10-29 21:24:00abc", "%Y-%m-%d %H:%M:%S", &tm);
EXPECT_STREQ(ret, "abc"); EXPECT_STREQ(ret, "abc");
EXPECT_EQ(tm.tm_year, 120); EXPECT_EQ(tm.tm_year, 120);
......
...@@ -334,10 +334,12 @@ HWTEST_F(IoTest, testMbsinit, Function | MediumTest | Level1) ...@@ -334,10 +334,12 @@ HWTEST_F(IoTest, testMbsinit, Function | MediumTest | Level1)
{ {
mbstate_t *ps = nullptr; mbstate_t *ps = nullptr;
int ret = mbsinit(ps); int ret = mbsinit(ps);
int memRet = -1;
EXPECT_NE(ret, 0); EXPECT_NE(ret, 0);
mbstate_t psF; 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); ret = mbsinit(&psF);
EXPECT_NE(ret, 0); EXPECT_NE(ret, 0);
} }
......
...@@ -811,8 +811,10 @@ HWTEST_F(IpcMqTest, testMqGetAttrEBADFEINVAL, Function | MediumTest | Level2) ...@@ -811,8 +811,10 @@ HWTEST_F(IpcMqTest, testMqGetAttrEBADFEINVAL, Function | MediumTest | Level2)
mqd_t queue; mqd_t queue;
struct mq_attr mqstat = { 0 }; struct mq_attr mqstat = { 0 };
char qName[MQ_NAME_LEN]; 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)); sprintf(qName, "testMqSendEINVAL_%d", GetRandom(10000));
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, NULL); 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) ...@@ -839,13 +841,16 @@ HWTEST_F(IpcMqTest, testMqSetAttrEBADFEINVAL, Function | MediumTest | Level2)
char qName[MQ_NAME_LEN]; char qName[MQ_NAME_LEN];
mqd_t queue; mqd_t queue;
struct mq_attr gMqstat = { 0 }, sMqstat = { 0 }; struct mq_attr gMqstat = { 0 }, sMqstat = { 0 };
int memRet = -1;
sprintf(qName, "testMqSetAttrEBADFEINVAL_%d", GetRandom(10000)); sprintf(qName, "testMqSetAttrEBADFEINVAL_%d", GetRandom(10000));
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); 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"; ASSERT_TRUE(queue != (mqd_t)-1) << "ERROR: mq_open() == (mqd_t)-1";
memset_s(&gMqstat, sizeof(gMqstat), 0, sizeof(gMqstat)); memRet = memset_s(&gMqstat, sizeof(gMqstat), 0, sizeof(gMqstat));
memset_s(&sMqstat, sizeof(sMqstat), 0, sizeof(sMqstat)); 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"; EXPECT_TRUE(mq_getattr(queue, &gMqstat) == 0) << "ERROR: mq_getattr() != 0";
sMqstat.mq_flags |= O_NONBLOCK; sMqstat.mq_flags |= O_NONBLOCK;
......
...@@ -108,6 +108,7 @@ HWTEST_F(IpcMqTest, testMqTimedOneLevelCom, Function | MediumTest | Level1) ...@@ -108,6 +108,7 @@ HWTEST_F(IpcMqTest, testMqTimedOneLevelCom, Function | MediumTest | Level1)
HWTEST_F(IpcMqTest, testMqAllOneLevelCom, Function | MediumTest | Level2) HWTEST_F(IpcMqTest, testMqAllOneLevelCom, Function | MediumTest | Level2)
{ {
mqd_t queue; mqd_t queue;
int memRet = -1;
unsigned int prio; unsigned int prio;
struct timespec tts { 0 }, rts = { 0 }; struct timespec tts { 0 }, rts = { 0 };
struct mq_attr getAttr = { 0 }; struct mq_attr getAttr = { 0 };
...@@ -116,8 +117,10 @@ HWTEST_F(IpcMqTest, testMqAllOneLevelCom, Function | MediumTest | Level2) ...@@ -116,8 +117,10 @@ HWTEST_F(IpcMqTest, testMqAllOneLevelCom, Function | MediumTest | Level2)
sprintf_s(qName, sizeof(qName), "testMqAllOneLevelCom_%d", GetRandom(10000)); sprintf_s(qName, sizeof(qName), "testMqAllOneLevelCom_%d", GetRandom(10000));
memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr)); memRet = memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr));
memset_s(&setAttr, sizeof(setAttr), 0, sizeof(setAttr)); 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_msgsize = MQ_MSG_SIZE;
setAttr.mq_maxmsg = MQ_MAX_MSG; setAttr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr);
...@@ -664,17 +667,20 @@ HWTEST_F(IpcMqTest, testMqSetGetAttr, Function | MediumTest | Level1) ...@@ -664,17 +667,20 @@ HWTEST_F(IpcMqTest, testMqSetGetAttr, Function | MediumTest | Level1)
struct mq_attr getAttr = { 0 }; struct mq_attr getAttr = { 0 };
struct mq_attr setAttr = { 0 }; struct mq_attr setAttr = { 0 };
char qName[MQ_NAME_LEN]; char qName[MQ_NAME_LEN];
int memRet = -1;
sprintf_s(qName, sizeof(qName), "testMqFunction_%d", GetRandom(10000)); 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_msgsize = MQ_MSG_SIZE;
setAttr.mq_maxmsg = MQ_MAX_MSG; setAttr.mq_maxmsg = MQ_MAX_MSG;
setAttr.mq_flags = O_NONBLOCK; setAttr.mq_flags = O_NONBLOCK;
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); 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"; 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(mq_getattr(queue, &getAttr) == 0) << "ERROR: mq_getattr() != 0";
EXPECT_TRUE((getAttr.mq_flags & O_NONBLOCK) == O_NONBLOCK); EXPECT_TRUE((getAttr.mq_flags & O_NONBLOCK) == O_NONBLOCK);
......
...@@ -107,8 +107,10 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1) ...@@ -107,8 +107,10 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1)
const int arrSize = MAX_PIPE_BUFFER + 10; const int arrSize = MAX_PIPE_BUFFER + 10;
int fd = -1; int fd = -1;
int tmpInt; int tmpInt;
int memRet = -1;
char testBuffer[arrSize]; 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); int ret = mkfifo(FIFO_PATH, 0666);
EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno; EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno;
...@@ -117,7 +119,8 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1) ...@@ -117,7 +119,8 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1)
ASSERT_TRUE(pid >= 0) << "> parent : fork : error"; ASSERT_TRUE(pid >= 0) << "> parent : fork : error";
if (pid == 0) { if (pid == 0) {
char readBuffer[arrSize]; 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); fd = open(FIFO_PATH, O_RDONLY, S_IRUSR|S_IWUSR);
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
LOG("> fcntl errno = %d", errno); LOG("> fcntl errno = %d", errno);
...@@ -141,7 +144,8 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1) ...@@ -141,7 +144,8 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1)
} }
// parent // parent
char writeBuffer[arrSize]; 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); fd = open(FIFO_PATH, O_WRONLY, S_IRUSR|S_IWUSR);
EXPECT_NE(fd, -1) << "> open faild errno = " << errno; EXPECT_NE(fd, -1) << "> open faild errno = " << errno;
EXPECT_NE(fcntl(fd, F_SETFL, O_NONBLOCK), -1) << "> fcntl 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) ...@@ -168,7 +172,9 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1)
int fd = -1; int fd = -1;
int tmpInt; int tmpInt;
char testBuffer[arrSize]; 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); int ret = mkfifo(FIFO_PATH, 0666);
EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno; EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno;
...@@ -177,7 +183,8 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1) ...@@ -177,7 +183,8 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1)
ASSERT_TRUE(pid >= 0) << "> parent : fork : error"; ASSERT_TRUE(pid >= 0) << "> parent : fork : error";
if (pid == 0) { if (pid == 0) {
char readBuffer[arrSize]; 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); fd = open(FIFO_PATH, O_RDONLY);
Msleep(60); Msleep(60);
...@@ -197,7 +204,8 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1) ...@@ -197,7 +204,8 @@ HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1)
} }
// parent // parent
char writeBuffer[arrSize]; 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); fd = open(FIFO_PATH, O_WRONLY, S_IRUSR|S_IWUSR);
EXPECT_NE(fd, -1) << "> open faild errno = " << errno; EXPECT_NE(fd, -1) << "> open faild errno = " << errno;
......
...@@ -121,8 +121,10 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3) ...@@ -121,8 +121,10 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3)
const int arrSize = MAX_PIPE_BUFFER + 1000; const int arrSize = MAX_PIPE_BUFFER + 1000;
int fd[2]; int fd[2];
int tmpInt; int tmpInt;
int memRet = -1;
char testBuffer[arrSize]; 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"); printf("abcd \n");
tmpInt = pipe(fd); tmpInt = pipe(fd);
ASSERT_EQ(tmpInt, 0) << "> parent: Create Pipe Error! "; ASSERT_EQ(tmpInt, 0) << "> parent: Create Pipe Error! ";
...@@ -132,7 +134,8 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3) ...@@ -132,7 +134,8 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3)
ASSERT_TRUE(pid >= 0) << "> parent: error : fork"; ASSERT_TRUE(pid >= 0) << "> parent: error : fork";
if (pid == 0) { if (pid == 0) {
char readBuffer[arrSize]; 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]); close(fd[1]);
Msleep(60); Msleep(60);
...@@ -155,7 +158,8 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3) ...@@ -155,7 +158,8 @@ HWTEST_F(PipeTest, testPipeBuf, Function | MediumTest | Level3)
// parent // parent
char writeBuffer[arrSize]; 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]); close(fd[0]);
Msleep(30); Msleep(30);
...@@ -181,8 +185,9 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2) ...@@ -181,8 +185,9 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2)
int fd[2]; int fd[2];
int ret; int ret;
char testBuffer[arrSize]; 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); ret = pipe(fd);
ASSERT_EQ(ret, 0) << "> parent: Create Pipe Error! "; ASSERT_EQ(ret, 0) << "> parent: Create Pipe Error! ";
...@@ -190,7 +195,8 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2) ...@@ -190,7 +195,8 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2)
ASSERT_TRUE(pid >= 0) << "> parent: error : fork"; ASSERT_TRUE(pid >= 0) << "> parent: error : fork";
if (pid == 0) { if (pid == 0) {
char readBuffer[arrSize]; 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]); close(fd[1]);
Msleep(60); Msleep(60);
...@@ -210,7 +216,8 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2) ...@@ -210,7 +216,8 @@ HWTEST_F(PipeTest, testPipeBlock, Function | MediumTest | Level2)
// parent // parent
char writeBuffer[arrSize]; 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]); close(fd[0]);
Msleep(30); Msleep(30);
......
...@@ -108,7 +108,7 @@ INSTANTIATE_TEST_CASE_P(AllSignalTest, IpcSignalTest, testing::Range(1, MAX_SIGN ...@@ -108,7 +108,7 @@ INSTANTIATE_TEST_CASE_P(AllSignalTest, IpcSignalTest, testing::Range(1, MAX_SIGN
/** /**
* @tc.number SUB_KERNEL_IPC_SIG_ALL_0300 * @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] * @tc.desc [C- SOFTWARE -0200]
*/ */
HWTEST_F(IpcSignalTest, testBlockSIGKILL, Function | MediumTest | Level2) HWTEST_F(IpcSignalTest, testBlockSIGKILL, Function | MediumTest | Level2)
...@@ -496,9 +496,9 @@ HWTEST_F(IpcSignalTest, testSigtimedwaitBlock, Function | MediumTest | Level1) ...@@ -496,9 +496,9 @@ HWTEST_F(IpcSignalTest, testSigtimedwaitBlock, Function | MediumTest | Level1)
/** /**
* @tc.number SUB_KERNEL_IPC_SIGTIMEDWAIT_0200 * @tc.number SUB_KERNEL_IPC_SIGTIMEDWAIT_0200
* @tc.name sigtimedwait error test: timeout or interupted. * @tc.name sigtimedwait error test: timeout or interrupted.
* by now, liteos sigtimedwait cannot interupted * by now, liteos sigtimedwait cannot interrupted
* so the interupte-check-code will run only when 'POSIX_TEST' is set * so the interrupted-check-code will run only when 'POSIX_TEST' is set
* @tc.desc [C- SOFTWARE -0200] * @tc.desc [C- SOFTWARE -0200]
*/ */
HWTEST_F(IpcSignalTest, testSigtimedwaitTimeout, Function | MediumTest | Level2) HWTEST_F(IpcSignalTest, testSigtimedwaitTimeout, Function | MediumTest | Level2)
...@@ -1085,7 +1085,7 @@ HWTEST_F(IpcSignalTest, testSigsuspendTerminate, Function | MediumTest | Level1) ...@@ -1085,7 +1085,7 @@ HWTEST_F(IpcSignalTest, testSigsuspendTerminate, Function | MediumTest | Level1)
Msleep(20); Msleep(20);
AssertProcAlive(pid); AssertProcAlive(pid);
kill(pid, SIGTRAP); // this should interupt sigsuspend kill(pid, SIGTRAP); // this should interrupt sigsuspend
Msleep(100); Msleep(100);
WaitProcKilled(pid, SIGHUP); WaitProcKilled(pid, SIGHUP);
} }
...@@ -1190,7 +1190,7 @@ HWTEST_F(IpcSignalTest, testSigsuspendAndMask, Function | MediumTest | Level1) ...@@ -1190,7 +1190,7 @@ HWTEST_F(IpcSignalTest, testSigsuspendAndMask, Function | MediumTest | Level1)
Msleep(20); Msleep(20);
AssertProcAlive(pid); AssertProcAlive(pid);
kill(pid, SIGINT); // this should interupt sigsuspend kill(pid, SIGINT); // this should interrupt sigsuspend
Msleep(100); Msleep(100);
AssertProcExitedOK(pid); AssertProcExitedOK(pid);
} }
......
...@@ -30,10 +30,10 @@ int IpcSignalTest::mShmid = 0; ...@@ -30,10 +30,10 @@ int IpcSignalTest::mShmid = 0;
siginfo_t IpcSignalTest::mSiginfo; siginfo_t IpcSignalTest::mSiginfo;
// special signal hander for function 'abort' // special signal handler for function 'abort'
void IpcSignalTest::SigAbortHandler(int signum) void IpcSignalTest::SigAbortHandler(int signum)
{ {
LOG("hander: recv a signal: %d", signum); LOG("handler: recv a signal: %d", signum);
int *shared = static_cast<int*>(shmat(mShmid, nullptr, 0)); int *shared = static_cast<int*>(shmat(mShmid, nullptr, 0));
if (shared == reinterpret_cast<int*>(-1)) { if (shared == reinterpret_cast<int*>(-1)) {
LOG("SigAbortHandler: shmat fail, errno = %d", errno); LOG("SigAbortHandler: shmat fail, errno = %d", errno);
...@@ -49,15 +49,15 @@ void IpcSignalTest::SigAbortHandler(int signum) ...@@ -49,15 +49,15 @@ void IpcSignalTest::SigAbortHandler(int signum)
// special signal handler for function 'sigaction' // special signal handler for function 'sigaction'
void IpcSignalTest::SigactionHandler(int signum, siginfo_t* si, void* ucontext) 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; mReceivedSignal = signum;
// siginfo_t para is not supported yet // 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) 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; mReceivedSignal = signum;
} }
...@@ -101,7 +101,7 @@ void IpcSignalTest::DefaultActionTest(const int signum, const bool expectStop, c ...@@ -101,7 +101,7 @@ void IpcSignalTest::DefaultActionTest(const int signum, const bool expectStop, c
ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; ASSERT_TRUE(pid >= 0) << "======== Fork Error! =========";
if (pid > 0) { // parent if (pid > 0) { // parent
Msleep(20); Msleep(20);
LOGD("befor kill"); LOGD("before kill");
kill(pid, signum); kill(pid, signum);
if (!expectStop) { if (!expectStop) {
Msleep(20); Msleep(20);
......
...@@ -136,24 +136,24 @@ static void CmsisThreadCreat004Func001(void const *argument) ...@@ -136,24 +136,24 @@ static void CmsisThreadCreat004Func001(void const *argument)
static void KeepRunByTick(UINT32 tick) static void KeepRunByTick(UINT32 tick)
{ {
UINT32 tickA = osKernelGetTickCount(); UINT32 tickA = osKernelGetTickCount();
UINT32 runned = 0; UINT32 ran = 0;
UINT32 loop = 0; UINT32 loop = 0;
UINT32 tickB = 0; UINT32 tickB = 0;
while (runned < tick) { while (ran < tick) {
loop++; loop++;
tickB = osKernelGetTickCount(); tickB = osKernelGetTickCount();
if (tickB >= tickA) { if (tickB >= tickA) {
runned = tickB - tickA; ran = tickB - tickA;
} else { } else {
runned = tickB + (MAX_UINT32 - tickA); ran = tickB + (MAX_UINT32 - tickA);
} }
if (loop % ALIVE_INFO_DIS == 0) { if (loop % ALIVE_INFO_DIS == 0) {
printf("runned:%u, tickB:%u, tickA:%u, loop:%u\t\n", printf("ran:%u, tickB:%u, tickA:%u, loop:%u\t\n",
runned, tickB, tickA, loop); ran, tickB, tickA, loop);
} }
} }
printf("return runned:%u, tickB:%u, tickA:%u\t\n", printf("return ran:%u, tickB:%u, tickA:%u\t\n",
runned, tickB, tickA); ran, tickB, tickA);
return; return;
} }
...@@ -532,7 +532,7 @@ LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew004, Function | MediumTest ...@@ -532,7 +532,7 @@ LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew004, Function | MediumTest
/** /**
* @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0200 * @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] * @tc.desc : [C- SOFTWARE -0200]
*/ */
LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew005, Function | MediumTest | Level1) LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew005, Function | MediumTest | Level1)
......
...@@ -122,6 +122,7 @@ HWTEST_F(MemApiTest, testReallocMem, Function | MediumTest | Level3) ...@@ -122,6 +122,7 @@ HWTEST_F(MemApiTest, testReallocMem, Function | MediumTest | Level3)
char *data = nullptr; char *data = nullptr;
int i, failure; int i, failure;
char testChar = 0x36; char testChar = 0x36;
void *memp = nullptr;
failure = 0; failure = 0;
for (i = 1; i < 5; i++) { for (i = 1; i < 5; i++) {
...@@ -131,7 +132,13 @@ HWTEST_F(MemApiTest, testReallocMem, Function | MediumTest | Level3) ...@@ -131,7 +132,13 @@ HWTEST_F(MemApiTest, testReallocMem, Function | MediumTest | Level3)
memset(mem, testChar, mlen); memset(mem, testChar, mlen);
rlen = GetRandom(0x200000); rlen = GetRandom(0x200000);
memp = mem;
mem = realloc(mem, rlen); mem = realloc(mem, rlen);
if (mem == nullptr) {
free(memp);
} else {
memp = nullptr;
}
ASSERT_TRUE(mem != nullptr) << "mem == NULL, i = " << i; ASSERT_TRUE(mem != nullptr) << "mem == NULL, i = " << i;
len = mlen <= rlen ? mlen : rlen; len = mlen <= rlen ? mlen : rlen;
......
...@@ -108,6 +108,7 @@ static int CommInitTcpServer(int port) ...@@ -108,6 +108,7 @@ static int CommInitTcpServer(int port)
static void* CommTcpClientTask(void *param) static void* CommTcpClientTask(void *param)
{ {
int* ret = (int *)malloc(sizeof(int)); int* ret = (int *)malloc(sizeof(int));
int memRet = -1;
if (ret == nullptr) { if (ret == nullptr) {
printf("[---][comm client]malloc fail\n"); printf("[---][comm client]malloc fail\n");
return nullptr; return nullptr;
...@@ -138,7 +139,8 @@ static void* CommTcpClientTask(void *param) ...@@ -138,7 +139,8 @@ static void* CommTcpClientTask(void *param)
}; };
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
sleep(sleepSecond); 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); rst = sprintf_s(dataBuf, sizeof(dataBuf), sendMsgList[i], clnFd);
if (rst < 0) { if (rst < 0) {
printf("[@@@][comm client]sprintf_s error!\n"); printf("[@@@][comm client]sprintf_s error!\n");
...@@ -149,7 +151,8 @@ static void* CommTcpClientTask(void *param) ...@@ -149,7 +151,8 @@ static void* CommTcpClientTask(void *param)
*ret = -1; *ret = -1;
printf("[@@@][comm client][%d]send fail\n", clnFd); 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); rst = recv(clnFd, dataBuf, sizeof(dataBuf), 0);
if (rst > 0) { if (rst > 0) {
printf("[@@@][comm client][%d]recv msg[%s]\n", clnFd, dataBuf); printf("[@@@][comm client][%d]recv msg[%s]\n", clnFd, dataBuf);
...@@ -173,6 +176,7 @@ static void* CommTcpClientTask(void *param) ...@@ -173,6 +176,7 @@ static void* CommTcpClientTask(void *param)
static void* SampleTcpServerTask(void *p) static void* SampleTcpServerTask(void *p)
{ {
int memRet = -1;
int srvFd = CommInitTcpServer(STACK_PORT); int srvFd = CommInitTcpServer(STACK_PORT);
EXPECT_NE(-1, srvFd); EXPECT_NE(-1, srvFd);
...@@ -200,14 +204,16 @@ static void* SampleTcpServerTask(void *p) ...@@ -200,14 +204,16 @@ static void* SampleTcpServerTask(void *p)
static char buf[BUF_SIZE + 1] = {0}; static char buf[BUF_SIZE + 1] = {0};
unsigned int srvMsgLen = strlen(g_srvMsg); 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); ret = strcpy_s(buf, BUF_SIZE, g_srvMsg);
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
ret = send(clnFd, buf, srvMsgLen, 0); ret = send(clnFd, buf, srvMsgLen, 0);
printf("[tcp server]send, ret=%d\n", ret); printf("[tcp server]send, ret=%d\n", ret);
EXPECT_EQ(srvMsgLen, (unsigned int)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); ret = recv(clnFd, buf, sizeof(buf), 0);
printf("[tcp server]recv, ret=%d, msg[%s]\n", ret, buf); printf("[tcp server]recv, ret=%d, msg[%s]\n", ret, buf);
EXPECT_EQ(strlen(g_cliMsg), (unsigned int)ret); EXPECT_EQ(strlen(g_cliMsg), (unsigned int)ret);
...@@ -219,7 +225,8 @@ static void* SampleTcpServerTask(void *p) ...@@ -219,7 +225,8 @@ static void* SampleTcpServerTask(void *p)
clnAddr.sin_family = AF_INET; clnAddr.sin_family = AF_INET;
clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_addr.s_addr = inet_addr(g_localHost);
clnAddr.sin_port = htons(PEER_PORT); 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); ret = strcpy_s(buf, BUF_SIZE, g_srvMsg);
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
msg.msg_name = &clnAddr; msg.msg_name = &clnAddr;
...@@ -236,8 +243,10 @@ static void* SampleTcpServerTask(void *p) ...@@ -236,8 +243,10 @@ static void* SampleTcpServerTask(void *p)
WAIT(); WAIT();
static char bufrec[BUF_SIZE + 1] = {0}; static char bufrec[BUF_SIZE + 1] = {0};
memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); memRet = memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE);
memset_s(&msg, sizeof(msg), 0, sizeof(msg)); EXPECT_EQ(0, memRet);
memRet = memset_s(&msg, sizeof(msg), 0, sizeof(msg));
EXPECT_EQ(0, memRet);
msg.msg_name = &clnAddr; msg.msg_name = &clnAddr;
msg.msg_namelen = sizeof(clnAddr); msg.msg_namelen = sizeof(clnAddr);
msg.msg_iov = iov; msg.msg_iov = iov;
...@@ -265,6 +274,7 @@ static void* SampleTcpServerTask(void *p) ...@@ -265,6 +274,7 @@ static void* SampleTcpServerTask(void *p)
static void* SampleTcpClientTask(void *p) static void* SampleTcpClientTask(void *p)
{ {
int memRet = -1;
int clnFd = socket(AF_INET, SOCK_STREAM, 0); int clnFd = socket(AF_INET, SOCK_STREAM, 0);
printf("[tcp client]create socket\n"); printf("[tcp client]create socket\n");
EXPECT_NE(-1, clnFd); EXPECT_NE(-1, clnFd);
...@@ -294,14 +304,16 @@ static void* SampleTcpClientTask(void *p) ...@@ -294,14 +304,16 @@ static void* SampleTcpClientTask(void *p)
static char buf[BUF_SIZE + 1] = {0}; static char buf[BUF_SIZE + 1] = {0};
unsigned int cliMsgLen = strlen(g_cliMsg); 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); ret = strcpy_s(buf, BUF_SIZE, g_cliMsg);
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
ret = send(clnFd, buf, cliMsgLen, 0); ret = send(clnFd, buf, cliMsgLen, 0);
printf("[tcp client]send, ret=%d\n", ret); printf("[tcp client]send, ret=%d\n", ret);
EXPECT_EQ(cliMsgLen, (unsigned int)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); ret = recv(clnFd, buf, sizeof(buf), 0);
printf("[tcp client]recv, ret=%d, msg[%s]\n", ret, buf); printf("[tcp client]recv, ret=%d, msg[%s]\n", ret, buf);
EXPECT_EQ(strlen(g_srvMsg), (unsigned int)ret); EXPECT_EQ(strlen(g_srvMsg), (unsigned int)ret);
...@@ -314,7 +326,8 @@ static void* SampleTcpClientTask(void *p) ...@@ -314,7 +326,8 @@ static void* SampleTcpClientTask(void *p)
clnAddr.sin_family = AF_INET; clnAddr.sin_family = AF_INET;
clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_addr.s_addr = inet_addr(g_localHost);
clnAddr.sin_port = htons(PEER_PORT); 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); ret = strcpy_s(buf, BUF_SIZE, g_cliMsg);
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
msg.msg_name = &clnAddr; msg.msg_name = &clnAddr;
...@@ -331,8 +344,10 @@ static void* SampleTcpClientTask(void *p) ...@@ -331,8 +344,10 @@ static void* SampleTcpClientTask(void *p)
WAIT(); WAIT();
static char bufrec[BUF_SIZE + 1] = {0}; static char bufrec[BUF_SIZE + 1] = {0};
memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); memRet = memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE);
memset_s(&msg, sizeof(msg), 0, sizeof(msg)); EXPECT_EQ(0, memRet);
memRet = memset_s(&msg, sizeof(msg), 0, sizeof(msg));
EXPECT_EQ(0, memRet);
msg.msg_name = &clnAddr; msg.msg_name = &clnAddr;
msg.msg_namelen = sizeof(clnAddr); msg.msg_namelen = sizeof(clnAddr);
msg.msg_iov = iov; msg.msg_iov = iov;
...@@ -438,6 +453,7 @@ static void* TcpClientOnlyConnectTask(void *p) ...@@ -438,6 +453,7 @@ static void* TcpClientOnlyConnectTask(void *p)
static int TcpServerForFork() static int TcpServerForFork()
{ {
int memRet = -1;
int timeout = 10; int timeout = 10;
char dataBuf[50] = {0}; char dataBuf[50] = {0};
int srvFd = CommInitTcpServer(STACK_PORT + 1); int srvFd = CommInitTcpServer(STACK_PORT + 1);
...@@ -454,7 +470,8 @@ static int TcpServerForFork() ...@@ -454,7 +470,8 @@ static int TcpServerForFork()
goto FINALLY; goto FINALLY;
} }
while (timeout > 0) { 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); ret = recv(cliFd, dataBuf, sizeof(dataBuf), 0);
if (ret > 0) { if (ret > 0) {
printf("[---][server process]recv msg[%s]\n", dataBuf); printf("[---][server process]recv msg[%s]\n", dataBuf);
...@@ -465,7 +482,8 @@ static int TcpServerForFork() ...@@ -465,7 +482,8 @@ static int TcpServerForFork()
} else { } else {
printf("[---][server process]recv no data\n"); 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); sprintf_s(dataBuf, sizeof(dataBuf), "server timeout:%d", timeout);
ret = send(cliFd, dataBuf, strlen(dataBuf), 0); ret = send(cliFd, dataBuf, strlen(dataBuf), 0);
if (ret > 0) { if (ret > 0) {
...@@ -485,6 +503,7 @@ FINALLY: ...@@ -485,6 +503,7 @@ FINALLY:
static int SelectServerForFork(unsigned int timeoutSec) static int SelectServerForFork(unsigned int timeoutSec)
{ {
int memRet = -1;
int srvFd = CommInitTcpServer(STACK_PORT + 1); int srvFd = CommInitTcpServer(STACK_PORT + 1);
if (srvFd == -1) { if (srvFd == -1) {
return -1; return -1;
...@@ -543,7 +562,8 @@ static int SelectServerForFork(unsigned int timeoutSec) ...@@ -543,7 +562,8 @@ static int SelectServerForFork(unsigned int timeoutSec)
continue; continue;
} }
if (FD_ISSET(fds[i], &readSet)) { 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); int len = recv(fds[i], dataBuf, sizeof(dataBuf), 0);
if (len > 0) { if (len > 0) {
printf("[***][select process][%d]recv msg[%s]\n", fds[i], dataBuf); printf("[***][select process][%d]recv msg[%s]\n", fds[i], dataBuf);
...@@ -585,6 +605,7 @@ static int PollServerForFork(int timeoutSec) ...@@ -585,6 +605,7 @@ static int PollServerForFork(int timeoutSec)
int fdCount = 1; int fdCount = 1;
char dataBuf[50] = {0}; char dataBuf[50] = {0};
struct pollfd fds[TEST_FD_COUNT]; struct pollfd fds[TEST_FD_COUNT];
int memRet = -1;
fds[0].events = POLLIN | POLLPRI; fds[0].events = POLLIN | POLLPRI;
fds[0].fd = srvFd; fds[0].fd = srvFd;
for (int i = 1; i < TEST_FD_COUNT; i++) { for (int i = 1; i < TEST_FD_COUNT; i++) {
...@@ -628,7 +649,8 @@ static int PollServerForFork(int timeoutSec) ...@@ -628,7 +649,8 @@ static int PollServerForFork(int timeoutSec)
continue; continue;
} }
if (fds[i].revents & POLLIN) { 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); int len = recv(fds[i].fd, dataBuf, sizeof(dataBuf), 0);
if (len > 0) { if (len > 0) {
printf("[***][poll process][%d]recv msg[%s]\n", fds[i].fd, dataBuf); printf("[***][poll process][%d]recv msg[%s]\n", fds[i].fd, dataBuf);
...@@ -735,6 +757,7 @@ HWTEST_F(ActsNetTest, testUdpSample, Function | MediumTest | Level2) ...@@ -735,6 +757,7 @@ HWTEST_F(ActsNetTest, testUdpSample, Function | MediumTest | Level2)
{ {
int len = 2; int len = 2;
char buf[BUF_SIZE + 1]; char buf[BUF_SIZE + 1];
int memRet = -1;
struct msghdr msg = {nullptr}; struct msghdr msg = {nullptr};
struct iovec iov[2] = {nullptr}; struct iovec iov[2] = {nullptr};
struct sockaddr_in srvAddr = {0}; struct sockaddr_in srvAddr = {0};
...@@ -752,20 +775,23 @@ HWTEST_F(ActsNetTest, testUdpSample, Function | MediumTest | Level2) ...@@ -752,20 +775,23 @@ HWTEST_F(ActsNetTest, testUdpSample, Function | MediumTest | Level2)
clnAddr.sin_family = AF_INET; clnAddr.sin_family = AF_INET;
clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_addr.s_addr = inet_addr(g_localHost);
clnAddr.sin_port = htons(PEER_PORT); 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); ret = strcpy_s(buf, BUF_SIZE, g_udpMsg);
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
ret = sendto(sfd, buf, strlen(g_udpMsg), 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr)); ret = sendto(sfd, buf, strlen(g_udpMsg), 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr));
EXPECT_NE(-1, ret); 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); ret = recvfrom(sfd, buf, sizeof(buf), 0, (struct sockaddr*)&clnAddr, &clnAddrLen);
EXPECT_EQ(strlen(g_udpMsg), (unsigned int)ret); EXPECT_EQ(strlen(g_udpMsg), (unsigned int)ret);
clnAddr.sin_family = AF_INET; clnAddr.sin_family = AF_INET;
clnAddr.sin_addr.s_addr = inet_addr(g_localHost); clnAddr.sin_addr.s_addr = inet_addr(g_localHost);
clnAddr.sin_port = htons(PEER_PORT); 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); ret = strcpy_s(buf, BUF_SIZE, g_udpMsg);
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
msg.msg_name = &clnAddr; msg.msg_name = &clnAddr;
...@@ -1059,12 +1085,14 @@ HWTEST_F(ActsNetTest, testPollMultiClients, Function | MediumTest | Level2) ...@@ -1059,12 +1085,14 @@ HWTEST_F(ActsNetTest, testPollMultiClients, Function | MediumTest | Level2)
*/ */
HWTEST_F(ActsNetTest, testIoctlIfconf, Function | MediumTest | Level2) HWTEST_F(ActsNetTest, testIoctlIfconf, Function | MediumTest | Level2)
{ {
int memRet = -1;
int udpFd = socket(AF_INET, SOCK_DGRAM, 0); int udpFd = socket(AF_INET, SOCK_DGRAM, 0);
ASSERT_NE(-1, udpFd); ASSERT_NE(-1, udpFd);
struct ifreq ifr[5]; struct ifreq ifr[5];
struct ifconf ifc = {0}; 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_len = 5 * sizeof(struct ifreq);
ifc.ifc_buf = (char *)ifr; ifc.ifc_buf = (char *)ifr;
int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc); int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc);
...@@ -1138,10 +1166,12 @@ HWTEST_F(ActsNetTest, testIoctlIfnetAddrOthers, Function | MediumTest | Level2) ...@@ -1138,10 +1166,12 @@ HWTEST_F(ActsNetTest, testIoctlIfnetAddrOthers, Function | MediumTest | Level2)
{ {
int udpFd = socket(AF_INET, SOCK_DGRAM, 0); int udpFd = socket(AF_INET, SOCK_DGRAM, 0);
ASSERT_NE(-1, udpFd); ASSERT_NE(-1, udpFd);
int memRet = -1;
struct ifreq ifr[5]; struct ifreq ifr[5];
struct ifconf ifc = {0}; 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_len = 5 * sizeof(struct ifreq);
ifc.ifc_buf = (char *)ifr; ifc.ifc_buf = (char *)ifr;
int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc); int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc);
...@@ -1156,7 +1186,8 @@ HWTEST_F(ActsNetTest, testIoctlIfnetAddrOthers, Function | MediumTest | Level2) ...@@ -1156,7 +1186,8 @@ HWTEST_F(ActsNetTest, testIoctlIfnetAddrOthers, Function | MediumTest | Level2)
addr1 = (struct sockaddr_in *)&ifr[i].ifr_addr; addr1 = (struct sockaddr_in *)&ifr[i].ifr_addr;
if (strcmp("lo", ifr[i].ifr_name) != 0) { if (strcmp("lo", ifr[i].ifr_name) != 0) {
// get inet addr // 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 = strcpy_s(ifrTmp.ifr_name, sizeof(ifrTmp.ifr_name), ifr[i].ifr_name);
ret = ioctl(udpFd, SIOCGIFADDR, &ifrTmp); ret = ioctl(udpFd, SIOCGIFADDR, &ifrTmp);
ASSERT_EQ(0, ret) << "ioctl fail[SIOCGIFADDR], errinfo[" << strerror(errno) << "]"; ASSERT_EQ(0, ret) << "ioctl fail[SIOCGIFADDR], errinfo[" << strerror(errno) << "]";
...@@ -1192,10 +1223,12 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2) ...@@ -1192,10 +1223,12 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2)
{ {
int udpFd = socket(AF_INET, SOCK_DGRAM, 0); int udpFd = socket(AF_INET, SOCK_DGRAM, 0);
ASSERT_NE(-1, udpFd); ASSERT_NE(-1, udpFd);
int memRet = -1;
struct ifreq ifr[5]; struct ifreq ifr[5];
struct ifconf ifc = {0}; 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_len = 5 * sizeof(struct ifreq);
ifc.ifc_buf = (char *)ifr; ifc.ifc_buf = (char *)ifr;
int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc); int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc);
...@@ -1212,7 +1245,8 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2) ...@@ -1212,7 +1245,8 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2)
addr = (struct sockaddr_in *)&ifr[i].ifr_addr; addr = (struct sockaddr_in *)&ifr[i].ifr_addr;
if (strcmp("lo", ifr[i].ifr_name) != 0) { if (strcmp("lo", ifr[i].ifr_name) != 0) {
// get ifhwaddr // 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); ret = strcpy_s(ifrTmp.ifr_name, sizeof(ifrTmp.ifr_name), ifr[i].ifr_name);
EXPECT_EQ(0, ret) << "strcpy_s error"; EXPECT_EQ(0, ret) << "strcpy_s error";
ret = ioctl(udpFd, SIOCGIFHWADDR, &ifrTmp); ret = ioctl(udpFd, SIOCGIFHWADDR, &ifrTmp);
...@@ -1236,6 +1270,7 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2) ...@@ -1236,6 +1270,7 @@ HWTEST_F(ActsNetTest, testIoctlIfhwAddr, Function | MediumTest | Level2)
HWTEST_F(ActsNetTest, testSocketOpt, Function | MediumTest | Level2) HWTEST_F(ActsNetTest, testSocketOpt, Function | MediumTest | Level2)
{ {
socklen_t len; socklen_t len;
int memRet = -1;
struct timeval timeout = {0}; struct timeval timeout = {0};
int fd = socket(AF_INET, SOCK_STREAM, 0); int fd = socket(AF_INET, SOCK_STREAM, 0);
EXPECT_NE(-1, fd); EXPECT_NE(-1, fd);
...@@ -1255,7 +1290,8 @@ HWTEST_F(ActsNetTest, testSocketOpt, Function | MediumTest | Level2) ...@@ -1255,7 +1290,8 @@ HWTEST_F(ActsNetTest, testSocketOpt, Function | MediumTest | Level2)
ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len); ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len);
EXPECT_EQ(0, ret); 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); ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len);
EXPECT_EQ(0, ret); EXPECT_EQ(0, ret);
EXPECT_EQ(1000, timeout.tv_sec); EXPECT_EQ(1000, timeout.tv_sec);
......
...@@ -29,10 +29,10 @@ using namespace testing::ext; ...@@ -29,10 +29,10 @@ using namespace testing::ext;
// static membor must init before use. // static membor must init before use.
int AlarmTest::mReceivedSignal = 0; int AlarmTest::mReceivedSignal = 0;
// general signal hander // general signal handler
void AlarmTest::SignalHandler(int signum) void AlarmTest::SignalHandler(int signum)
{ {
LOG("hander recv a signal: %d", signum); LOG("handler recv a signal: %d", signum);
mReceivedSignal = signum; mReceivedSignal = signum;
} }
......
...@@ -103,7 +103,7 @@ int CheckProcStatus(pid_t pid, int *code, int flag) ...@@ -103,7 +103,7 @@ int CheckProcStatus(pid_t pid, int *code, int flag)
return 4; 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[]) static int StartElf(const char *fname, char * const argv[], char * const envp[])
{ {
int pid = fork(); int pid = fork();
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -124,7 +124,7 @@ const int EXECVE_RETURN_ERROR = 190; // execve return -1 ...@@ -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 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 * input: fname, argv, envp -- parameters for execve
* timeout_sec -- timeout of the child executing, default: 5 seconds. * timeout_sec -- timeout of the child executing, default: 5 seconds.
* timeout_sec<=0 means no timeout, wait forever until child exit. * timeout_sec<=0 means no timeout, wait forever until child exit.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册