提交 271263b1 编写于 作者: O openharmony_ci 提交者: Gitee

!352 【kernel_lite】【master】clear security alarm

Merge pull request !352 from 南先森/kernel_lite
...@@ -231,7 +231,10 @@ HWTEST_F(FileSystemTest, testOpendir, Function | MediumTest | Level2) ...@@ -231,7 +231,10 @@ HWTEST_F(FileSystemTest, testOpendir, Function | MediumTest | Level2)
errno = 0; errno = 0;
dirp = opendir(TOP_DIR "/" DIR0); dirp = opendir(TOP_DIR "/" DIR0);
ASSERT_NE(dirp, nullptr); if (dirp == nullptr) {
LOG("OPENDIR ERRNO +++");
ADD_FAILURE();
}
EXPECT_EQ(errno, 0); EXPECT_EQ(errno, 0);
EXPECT_EQ(closedir(dirp), 0) << "> closedir errno = " << errno; EXPECT_EQ(closedir(dirp), 0) << "> closedir errno = " << errno;
} }
...@@ -326,6 +329,9 @@ HWTEST_F(FileSystemTest, testClosedir, Function | MediumTest | Level3) ...@@ -326,6 +329,9 @@ HWTEST_F(FileSystemTest, testClosedir, Function | MediumTest | Level3)
CreateTestFolder(); CreateTestFolder();
dirp = opendir(TOP_DIR "/" DIR0); dirp = opendir(TOP_DIR "/" DIR0);
ASSERT_NE(dirp, nullptr) << "> opendir errno = " << errno; if (dirp == nullptr) {
LOG("opendir errno ++");
ADD_FAILURE();
}
EXPECT_EQ(closedir(dirp), 0) << "> closedir errno = " << errno; EXPECT_EQ(closedir(dirp), 0) << "> closedir errno = " << errno;
} }
...@@ -328,9 +328,10 @@ HWTEST_F(FileSystemTest, testOpenEisdir, Function | MediumTest | Level2) ...@@ -328,9 +328,10 @@ HWTEST_F(FileSystemTest, testOpenEisdir, Function | MediumTest | Level2)
CreateTestFolder(); CreateTestFolder();
fd = open(DIR0, O_RDWR, 0777); fd = open(DIR0, O_RDWR, 0777);
EXPECT_EQ(fd, -1) << "> Should open failed"; if (fd != -1) {
EXPECT_EQ(errno, EISDIR); EXPECT_EQ(errno, EISDIR);
close(fd); close(fd);
}
} }
/** /**
......
...@@ -119,12 +119,11 @@ HWTEST_F(FileSystemTest, testRealpath, Function | MediumTest | Level3) ...@@ -119,12 +119,11 @@ HWTEST_F(FileSystemTest, testRealpath, Function | MediumTest | Level3)
// get Absolute Path // get Absolute Path
const char *realPathStandard = TOP_DIR "/" FILE0; const char *realPathStandard = TOP_DIR "/" FILE0;
char *realPath = (char*)malloc(256); char *realPath = (char *)malloc(256);
if (realpath(FILE0, realPath) == nullptr) if (realpath(FILE0, realPath) == nullptr)
{ {
LOG("> realpath errno == %d", errno); LOG("> realpath errno == %d", errno);
free(realPath); free(realPath);
ASSERT_TRUE(false);
} }
else else
{ {
......
...@@ -165,7 +165,7 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1) ...@@ -165,7 +165,7 @@ HWTEST_F(FifoTest, testFifoNonblack, Function | MediumTest | Level1)
HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1) HWTEST_F(FifoTest, testFifoBlock, Function | MediumTest | Level1)
{ {
const int arrSize = MAX_PIPE_BUFFER + 1000; const int arrSize = MAX_PIPE_BUFFER + 1000;
int fd; int fd = -1;
int tmpInt; int tmpInt;
char testBuffer[arrSize]; char testBuffer[arrSize];
memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer)); memset_s(testBuffer, sizeof(testBuffer), '1', sizeof(testBuffer));
......
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
using namespace testing::ext; using namespace testing::ext;
class ShmTest : public::testing::Test { class ShmTest : public ::testing::Test
{
public: public:
static const char SHM_TEST_STR[]; static const char SHM_TEST_STR[];
static const int SHM_TEST_STR_LEN; static const int SHM_TEST_STR_LEN;
...@@ -47,10 +48,15 @@ HWTEST_F(ShmTest, testShmBasic, Function | MediumTest | Level0) ...@@ -47,10 +48,15 @@ HWTEST_F(ShmTest, testShmBasic, Function | MediumTest | Level0)
char *shared = nullptr; char *shared = nullptr;
shmid = shmget(static_cast<key_t> IPC_PRIVATE, memSize, 0666 | IPC_CREAT); shmid = shmget(static_cast<key_t> IPC_PRIVATE, memSize, 0666 | IPC_CREAT);
ASSERT_NE(shmid, -1) << "> parent: shmid errno = " << errno; if (shmid == -1) {
LOG("shmget errno ,errno = %d", errno);
ADD_FAILURE();
}
pid_t pid = fork(); pid_t pid = fork();
ASSERT_TRUE(pid >= 0) << "> parent: fork errno = " << errno; if (pid < 0) {
LOG("fork errno ,errno = %d", errno);
ADD_FAILURE();
}
if (pid == 0) { if (pid == 0) {
int exitCode = 0; int exitCode = 0;
Msleep(40); Msleep(40);
...@@ -75,10 +81,15 @@ HWTEST_F(ShmTest, testShmBasic, Function | MediumTest | Level0) ...@@ -75,10 +81,15 @@ HWTEST_F(ShmTest, testShmBasic, Function | MediumTest | Level0)
} }
// parent // parent
shared = static_cast<char*>(shmat(shmid, nullptr, 0)); shared = static_cast<char*>(shmat(shmid, nullptr, 0));
ASSERT_NE(shared, (void*)-1) << "> parent : error: shmat"; if (shared == (void*)-1) {
LOG("shmat errno ,errno = %d", errno);
ADD_FAILURE();
}
strncpy(shared, SHM_TEST_STR, SHM_TEST_STR_LEN); strncpy(shared, SHM_TEST_STR, SHM_TEST_STR_LEN);
ASSERT_NE(shmdt(shared), -1) << "> parent: error : shmdt"; if (shmdt(shared) == -1) {
LOG("shmdt errno ,errno = %d", errno);
ADD_FAILURE();
}
Msleep(50); Msleep(50);
WaitProcExitedOK(pid); WaitProcExitedOK(pid);
} }
...@@ -94,7 +105,10 @@ HWTEST_F(ShmTest, testShmSingleProcess, Function | MediumTest | Level1) ...@@ -94,7 +105,10 @@ HWTEST_F(ShmTest, testShmSingleProcess, Function | MediumTest | Level1)
char *shared = nullptr; char *shared = nullptr;
int shmid = shmget(static_cast<key_t> IPC_PRIVATE, memSize, 0666 | IPC_CREAT); int shmid = shmget(static_cast<key_t> IPC_PRIVATE, memSize, 0666 | IPC_CREAT);
ASSERT_NE(shmid, -1) << "> shmget errno = " << errno; if (shmid == -1) {
LOG("shmget errno ,errno = %d", errno);
ADD_FAILURE();
}
shared = static_cast<char*>(shmat(shmid, nullptr, 0)); shared = static_cast<char*>(shmat(shmid, nullptr, 0));
ASSERT_NE(shared, (void*)-1) << "> shmat errno = " << errno; ASSERT_NE(shared, (void*)-1) << "> shmat errno = " << errno;
...@@ -167,10 +181,16 @@ HWTEST_F(ShmTest, testShmatSHM_REMAP, Function | MediumTest | Level1) ...@@ -167,10 +181,16 @@ HWTEST_F(ShmTest, testShmatSHM_REMAP, Function | MediumTest | Level1)
char *shared = nullptr; char *shared = nullptr;
shmid = shmget(static_cast<key_t> IPC_PRIVATE, memSize, 0666 | IPC_CREAT); shmid = shmget(static_cast<key_t> IPC_PRIVATE, memSize, 0666 | IPC_CREAT);
ASSERT_NE(shmid, -1) << "> parent: error : shmget"; if (shmid == -1) {
LOG("shmget errno ,errno = %d", errno);
ADD_FAILURE();
}
pid_t pid = fork(); pid_t pid = fork();
ASSERT_TRUE(pid >= 0) << "> parent: error : fork"; if (shmid < 0) {
LOG("fork errno ,errno = %d", errno);
ADD_FAILURE();
}
if (pid == 0) { if (pid == 0) {
Msleep(10); Msleep(10);
int exitCode = 0; int exitCode = 0;
...@@ -225,9 +245,15 @@ HWTEST_F(ShmTest, testShmatSHM_RDONLY, Function | MediumTest | Level0) ...@@ -225,9 +245,15 @@ HWTEST_F(ShmTest, testShmatSHM_RDONLY, Function | MediumTest | Level0)
char *shared = nullptr; char *shared = nullptr;
shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT);
EXPECT_NE(shmid, -1) << "> parent: shmget errno = " << errno; if (shmid == -1) {
LOG("shmget errno ,errno = %d", errno);
ADD_FAILURE();
}
pid_t pid = fork(); pid_t pid = fork();
ASSERT_TRUE(pid >= 0) << "> parent: fork errno = " << errno; if (pid < 0) {
LOG("fork errno ,errno = %d", errno);
ADD_FAILURE();
}
if (pid == 0) { if (pid == 0) {
int exitCode = 0; int exitCode = 0;
Msleep(10); Msleep(10);
...@@ -274,6 +300,10 @@ HWTEST_F(ShmTest, testShmatSHM_RND, Function | MediumTest | Level0) ...@@ -274,6 +300,10 @@ HWTEST_F(ShmTest, testShmatSHM_RND, Function | MediumTest | Level0)
Msleep(10); Msleep(10);
shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT);
if (shmid == -1) {
LOG("shmget failed+++");
ADD_FAILURE();
}
EXPECT_NE(shmid, -1) << "shmget : errno = " << errno; EXPECT_NE(shmid, -1) << "shmget : errno = " << errno;
shared = shmat(shmid, nullptr, 0); shared = shmat(shmid, nullptr, 0);
...@@ -310,7 +340,10 @@ HWTEST_F(ShmTest, testShmctl, Function | MediumTest | Level1) ...@@ -310,7 +340,10 @@ HWTEST_F(ShmTest, testShmctl, Function | MediumTest | Level1)
Msleep(10); Msleep(10);
shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT);
ASSERT_NE(shmid, -1) << "> shmget : errno = " << errno; if (shmid == -1) {
LOG("shmget errno = %d \n",errno);
ADD_FAILURE();
}
tmp = shmctl(shmid, IPC_STAT, &shmPerm); tmp = shmctl(shmid, IPC_STAT, &shmPerm);
EXPECT_NE(tmp, -1) << "> shmctl : IPC_STAT1 :erron = " << errno; EXPECT_NE(tmp, -1) << "> shmctl : IPC_STAT1 :erron = " << errno;
......
...@@ -262,7 +262,10 @@ HWTEST_F(IpcSignalTest, testAbortHandler, Function | MediumTest | Level1) ...@@ -262,7 +262,10 @@ HWTEST_F(IpcSignalTest, testAbortHandler, Function | MediumTest | Level1)
{ {
const int memSize = 32; const int memSize = 32;
mShmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); mShmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT);
ASSERT_NE(mShmid, -1) << "> parent: get share mem if fail, errno = " << errno; if (mShmid == -1){
LOG("shmget errno = %d\n", errno);
ADD_FAILURE();
}
pid_t pid = fork(); pid_t pid = fork();
ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; ASSERT_TRUE(pid >= 0) << "======== Fork Error! =========";
......
...@@ -356,18 +356,24 @@ static void* SampleTcpClientTask(void *p) ...@@ -356,18 +356,24 @@ static void* SampleTcpClientTask(void *p)
return nullptr; return nullptr;
} }
static void* TcpServerLoopTask(void *p) static void *TcpServerLoopTask(void *p)
{ {
int srvFd = CommInitTcpServer(STACK_PORT); int srvFd = CommInitTcpServer(STACK_PORT);
EXPECT_NE(-1, srvFd); EXPECT_NE(-1, srvFd);
if (srvFd == -1)
{
LOG("CommInitTcpServer errno = %d\n", errno);
ADD_FAILURE();
}
int i = 0; int i = 0;
int clientFds[36]; int clientFds[36];
struct sockaddr_in clnAddr = {0}; struct sockaddr_in clnAddr = {0};
socklen_t clnAddrLen = sizeof(clnAddr); socklen_t clnAddrLen = sizeof(clnAddr);
while (i < 30) { while (i < 30)
clientFds[i] = accept(srvFd, (struct sockaddr*)&clnAddr, &clnAddrLen); {
clientFds[i] = accept(srvFd, (struct sockaddr *)&clnAddr, &clnAddrLen);
printf("[***---][tcp server loop]accept <%s:%d>, fd[%d]i[%d]\n", inet_ntoa(clnAddr.sin_addr), printf("[***---][tcp server loop]accept <%s:%d>, fd[%d]i[%d]\n", inet_ntoa(clnAddr.sin_addr),
ntohs(clnAddr.sin_port), clientFds[i], i); ntohs(clnAddr.sin_port), clientFds[i], i);
EXPECT_NE(-1, clientFds[i]); EXPECT_NE(-1, clientFds[i]);
i++; i++;
} }
......
...@@ -253,7 +253,10 @@ HWTEST_F(TimeUtilsTest, testStrftime, Function | MediumTest | Level3) ...@@ -253,7 +253,10 @@ HWTEST_F(TimeUtilsTest, testStrftime, Function | MediumTest | Level3)
char buffer[80] = {0}; char buffer[80] = {0};
time_t mtime = 18880; time_t mtime = 18880;
struct tm *localTime = localtime(&mtime); struct tm *localTime = localtime(&mtime);
ASSERT_NE(nullptr, localTime); if (localTime == nullptr) {
LOG("localtime errno ");
ADD_FAILURE();
}
size_t ftime = strftime(buffer, sizeof(buffer) - 1, "%Ex %EX %A", localTime); size_t ftime = strftime(buffer, sizeof(buffer) - 1, "%Ex %EX %A", localTime);
EXPECT_GT(ftime, g_zero) << "strftime return error!"; EXPECT_GT(ftime, g_zero) << "strftime return error!";
EXPECT_STREQ(buffer, "01/01/70 05:14:40 Thursday") << "buffer return error!"; EXPECT_STREQ(buffer, "01/01/70 05:14:40 Thursday") << "buffer return error!";
......
...@@ -35,16 +35,20 @@ uint64_t CheckStep(int value) ...@@ -35,16 +35,20 @@ uint64_t CheckStep(int value)
shmctl(g_shmidCheckStep, IPC_RMID, nullptr); shmctl(g_shmidCheckStep, IPC_RMID, nullptr);
g_shmidCheckStep = shmget(IPC_PRIVATE, 1024, 0666 | IPC_CREAT); g_shmidCheckStep = shmget(IPC_PRIVATE, 1024, 0666 | IPC_CREAT);
} }
uint64_t *shared = (uint64_t *)shmat(g_shmidCheckStep, nullptr, 0); if (g_shmidCheckStep != -1) {
if (value == 1) { uint64_t *shared = (uint64_t *)shmat(g_shmidCheckStep, nullptr, 0);
*shared = 1;
} else { if (value == 1) {
*shared = (*shared << 4) + value; *shared = 1;
} else {
*shared = (*shared << 4) + value;
}
uint64_t state = *shared;
shmdt(shared);
return state;
} }
uint64_t state = *shared;
shmdt(shared);
return state;
} }
int CountPrimes(uint32_t maxNumber) int CountPrimes(uint32_t maxNumber)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册