未验证 提交 ccdfa724 编写于 作者: O openharmony_ci 提交者: Gitee

!1016 修复执行测试用例执行时间过长等问题

Merge pull request !1016 from 夏不白/fix_unittest
......@@ -34,9 +34,11 @@ static int TestCase(void)
{
int ret;
int status = 0;
int *test = NULL; // for trggering an exception
pid_t pid = fork();
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, INVALID_PROCESS_ID, pid);
if (pid == 0) {
*test = 0x1; // Deliberately trigger an exceptioin
exit(0);
}
......@@ -52,6 +54,7 @@ static int TestCase(void)
pid = fork();
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, INVALID_PROCESS_ID, pid);
if (pid == 0) {
*test = 0x1; // Deliberately trigger an exceptioin
exit(0);
}
......
......@@ -36,13 +36,16 @@
static int TestThread(void)
{
int ret;
int *test = nullptr; // For triggering an exceptioin
pid_t pid = fork();
ICUNIT_ASSERT_WITHIN_EQUAL(pid, 0, INVALID_PROCESS_ID, pid);
if (pid == 0) {
*test = 0x1; // Deliberately trigger an exceptioin
while (1) {
}
}
*test = 0x1; // Deliberately trigger an exceptioin
ret = waitpid(pid, NULL, 0);
ICUNIT_ASSERT_EQUAL(ret, pid, ret);
......
......@@ -37,6 +37,12 @@ static int Testcase(VOID)
int shmid[SHMID_MAX + 1] = {-1};
int ret;
int i;
struct shm_info shmInfo;
int leftShmIds;
ret = shmctl(0, SHM_INFO, reinterpret_cast<struct shmid_ds *>(&shmInfo));
ICUNIT_ASSERT_EQUAL(ret, SHMID_MAX, ret);
leftShmIds = SHMID_MAX - shmInfo.used_ids;
shmid[0] = shmget((key_t)0x1234, PAGE_SIZE, 0777 | IPC_CREAT);
ICUNIT_ASSERT_NOT_EQUAL(shmid[0], -1, shmid[0]);
......@@ -50,20 +56,20 @@ static int Testcase(VOID)
ret = shmctl(shmid[0], IPC_RMID, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
for (i = 0; i < SHMID_MAX; i++) {
for (i = 0; i < leftShmIds; i++) {
shmid[i] = shmget(IPC_PRIVATE, PAGE_SIZE, 0777 | IPC_CREAT);
ICUNIT_ASSERT_NOT_EQUAL(shmid[i], -1, shmid[i]);
}
shmid[SHMID_MAX] = shmget(IPC_PRIVATE, PAGE_SIZE, 0777 | IPC_CREAT);
ICUNIT_ASSERT_EQUAL(shmid[SHMID_MAX], -1, shmid[SHMID_MAX]);
shmid[leftShmIds] = shmget(IPC_PRIVATE, PAGE_SIZE, 0777 | IPC_CREAT);
ICUNIT_ASSERT_EQUAL(shmid[leftShmIds], -1, shmid[leftShmIds]);
for (i = 0; i < SHMID_MAX; i++) {
for (i = 0; i < leftShmIds; i++) {
ret = shmctl(shmid[i], IPC_RMID, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
}
for (i = 0; i < SHMID_MAX; i++) {
for (i = 0; i < leftShmIds; i++) {
ret = shmctl(shmid[i], IPC_RMID, NULL);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册