提交 a55f68f9 编写于 作者: T teamol 提交者: 悟空又丢了

fix: fix ppoll

1.modifications:
modified:   syscall/fs_syscall.c
2.modify 2 testcases:
IO/full/IO_test_ppoll_001.cpp
IO/full/IO_test_ppoll_002.cpp
3.influence:
none
Signed-off-by: 悟空又丢了's avatarpef <cyd1997@126.com>
Change-Id: I85fc091098a6dfef1a4694a3bbc489640ee6dda2
上级 30875019
...@@ -2521,31 +2521,35 @@ int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, cons ...@@ -2521,31 +2521,35 @@ int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, cons
sigset_t_l origMask; sigset_t_l origMask;
sigset_t_l setl; sigset_t_l setl;
if (sigMask == NULL) {
ret = -EINVAL;
return ret;
}
CHECK_ASPACE(tmo_p, sizeof(struct timespec)); CHECK_ASPACE(tmo_p, sizeof(struct timespec));
CHECK_ASPACE(sigMask, sizeof(sigset_t)); CHECK_ASPACE(sigMask, sizeof(sigset_t));
CPY_FROM_USER(tmo_p); DUP_FROM_USER(tmo_p, sizeof(struct timespec));
CPY_FROM_USER(sigMask); DUP_FROM_USER(sigMask, sizeof(sigset_t), FREE_DUP(tmo_p));
timeout = (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS); if (tmo_p != NULL) {
timeout = tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS;
if (timeout & 0x80000000) { if (timeout & 0x80000000) {
ret = -EINVAL; ret = -EINVAL;
printf("ret[1] = %d\n", ret);
return ret; return ret;
} }
setl.sig[0] = *sigMask; } else {
OsSigprocMask(SIG_SETMASK, &setl, &origMask); timeout = -1;
}
if (sigMask != NULL) {
memcpy(&setl.sig[0], sigMask, sizeof(sigset_t));
}
OsSigprocMask(SIG_SETMASK, sigMask?(&setl):NULL, &origMask);
ret = SysPoll(fds, nfds, timeout); ret = SysPoll(fds, nfds, timeout);
if (ret < 0) { if (ret < 0) {
ret = -get_errno(); ret = -get_errno();
} }
OsSigprocMask(SIG_SETMASK, &origMask, NULL); OsSigprocMask(SIG_SETMASK, &origMask, NULL);
PointerFree(tmo_pbak); FREE_DUP(tmo_p);
PointerFree(sigMaskbak); FREE_DUP(sigMask);
return (ret == -1) ? -get_errno() : ret; return (ret == -1) ? -get_errno() : ret;
} }
......
...@@ -85,6 +85,7 @@ sources_full = [ ...@@ -85,6 +85,7 @@ sources_full = [
"full/IO_test_strncasecmp_l_002.cpp", "full/IO_test_strncasecmp_l_002.cpp",
"full/IO_test_ppoll_001.cpp", "full/IO_test_ppoll_001.cpp",
"full/IO_test_ppoll_002.cpp", "full/IO_test_ppoll_002.cpp",
"full/IO_test_ppoll_003.cpp",
"full/IO_test_pselect_001.cpp", "full/IO_test_pselect_001.cpp",
"full/IO_test_pselect_002.cpp", "full/IO_test_pselect_002.cpp",
] ]
......
...@@ -127,13 +127,12 @@ extern VOID IO_TEST_DCNGETTEXT_002(VOID); ...@@ -127,13 +127,12 @@ extern VOID IO_TEST_DCNGETTEXT_002(VOID);
extern VOID IO_TEST_DCGETTEXT_001(VOID); extern VOID IO_TEST_DCGETTEXT_001(VOID);
extern VOID IO_TEST_DCGETTEXT_002(VOID); extern VOID IO_TEST_DCGETTEXT_002(VOID);
extern VOID IO_TEST_GETTEXT_001(VOID); extern VOID IO_TEST_GETTEXT_001(VOID);
extern VOID IO_TEST_PPOLL_001(void);
extern VOID IO_TEST_PPOLL_002(void);
extern VOID IO_TEST_PSELECT_001(void); extern VOID IO_TEST_PSELECT_001(void);
extern VOID IO_TEST_PSELECT_002(void); extern VOID IO_TEST_PSELECT_002(void);
extern VOID IO_TEST_STRFMON_L_001(VOID); extern VOID IO_TEST_STRFMON_L_001(VOID);
extern VOID IO_TEST_STRFMON_L_002(VOID); extern VOID IO_TEST_STRFMON_L_002(VOID);
extern VOID IO_TEST_PPOLL_001(VOID); extern VOID IO_TEST_PPOLL_001(VOID);
extern VOID IO_TEST_PPOLL_002(VOID); extern VOID IO_TEST_PPOLL_002(VOID);
extern VOID IO_TEST_PPOLL_003(VOID);
#endif #endif
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h" #include "It_test_IO.h"
#include <poll.h>
#include "signal.h"
#include "pthread.h" #include "pthread.h"
#define LISTEN_FD_NUM 10 #define BUF_SIZE 128
#define POLL_EVENTS 1 #define DELAY_TIME 200
int pipeFdPpoll[LISTEN_FD_NUM][2]; STATIC INT32 pipeFdPpoll[2];
static pthread_t g_tid = -1; STATIC INT32 g_step = 1;
extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask); STATIC CHAR strBuf[] = "hello world.";
STATIC struct pollfd pfd;
static void *pthread_01(void) STATIC VOID *pthread_01(VOID *arg)
{ {
static int count = 0; INT32 retVal;
int total_num = 0; CHAR buf[BUF_SIZE];
int times = 3; const struct timespec timeout = {1000, 0};
int i, ret;
struct pollfd fds[LISTEN_FD_NUM] = { 0 };
char buffer[20];
struct timespec t = { 3,0 };
sigset_t sigset;
/* TEST_PRINT("[INFO]%s:%d,%s,Create thread %d\n", __FILE__, __LINE__, __func__, count); */
count++;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM); /* 把SIGALRM 信号添加到sigset 信号集中 */
sigaddset(&sigset, SIGUSR1);
for (i = 0; i < LISTEN_FD_NUM; i++) {
fds[i].fd = pipeFdPpoll[i][0];
fds[i].events = POLL_EVENTS;
}
while (times--) {
ret = ppoll(fds, LISTEN_FD_NUM, &t, &sigset);
total_num += ((ret > 0) ? ret : 0);
if (ret <= 0) { /* 执行ppoll监视文件描述符*/
continue; while(g_step < 3) {
usleep(DELAY_TIME);
} }
g_step++;
retVal = ppoll(&pfd, 1, NULL, NULL);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
for (i = 0; i < LISTEN_FD_NUM; i++) { while(g_step < 5) {
if (fds[i].revents & POLL_EVENTS) { usleep(DELAY_TIME);
ret = read(fds[i].fd, buffer, 12);
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT);
ret = strcmp(buffer, "hello world");
TEST_PRINT("[EVENT]%s:%d,%s,buffer=%s\n", __FILE__, __LINE__, __func__, buffer);
}
} }
g_step++;
if (total_num == LISTEN_FD_NUM) { /* 判断revents*/
break; if (pfd.revents & POLLIN) {
} memset(buf, 0, sizeof(buf));
retVal = read(pfd.fd, buf, BUF_SIZE);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
retVal = strcmp(strBuf, buf);
ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
} }
/* ICUNIT_GOTO_EQUAL(total_num, 10, -1, EXIT); */ while(g_step < 6) {
/* TEST_PRINT("[INFO]%s:%d,%s,total_num=%d\n", __FILE__, __LINE__, __func__, total_num); */ usleep(DELAY_TIME);
EXIT: }
return nullptr; pthread_exit(NULL);
} }
static UINT32 testcase1(VOID) STATIC UINT32 testcase(VOID)
{ {
int i; INT32 retVal;
int ret; pthread_t tid;
int count = 0;
/* 建立管道*/
for (i = 0; i < LISTEN_FD_NUM; i++) { while(g_step < 1) {
ret = pipe(pipeFdPpoll[i]); usleep(DELAY_TIME);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][0]);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][1]);
} }
retVal = pipe(pipeFdPpoll);
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
errno = 0; /* 设置pfd*/
ret = pthread_create(&g_tid, nullptr, (void *(*)(void *))pthread_01, nullptr); pfd.fd = pipeFdPpoll[0];
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno)); pfd.events = POLLIN;
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
errno = 0; /* 开辟线程执行 ppoll*/
for (i = 0; i < LISTEN_FD_NUM; i++) { while(g_step < 2) {
if ((pipeFdPpoll[i][1] != 9) && (pipeFdPpoll[i][1] != 10) && (pipeFdPpoll[i][1] != 11)) { usleep(DELAY_TIME);
ret = write(pipeFdPpoll[i][1], "hello world!", 12); /* 12, "hello world" length and '\0' */
}
ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
} }
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
g_step++;
#if 1 /* write looply */ /* 向管道写入数据*/
while(1) { while(g_step < 4) {
if (count++ > 3) { usleep(DELAY_TIME);
break;
} }
sleep(1); sleep(1);
for (i = 0; i < LISTEN_FD_NUM; i++) {
errno = 0;
ret = pthread_create(&g_tid, nullptr, (void *(*)(void *))pthread_01, nullptr);
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
if ((pipeFdPpoll[i][1] == 13) || (pipeFdPpoll[i][1] == 14) || (pipeFdPpoll[i][1] == 15)) {
errno = 0;
ret = write(pipeFdPpoll[i][1], "World HELLO!", 12); /* 12, "hello world" length and '\0' */
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno));
TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][1]=%d,count=%d\n", __FILE__, __LINE__, __func__, ret,i, pipeFdPpoll[i][1], count);
}
/* ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); */
}
}
#endif
pthread_join(g_tid, nullptr);
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(pipeFdPpoll[i][0]);
close(pipeFdPpoll[i][1]);
}
return LOS_OK; retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
EXIT: pthread_join(tid, NULL);
for (i = 0; i < LISTEN_FD_NUM; i++) {
close(pipeFdPpoll[i][0]);
close(pipeFdPpoll[i][1]);
}
return LOS_NOK;
}
static UINT32 testcase(VOID)
{
testcase1();
return LOS_OK; return LOS_OK;
} }
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "It_test_IO.h" #include "It_test_IO.h"
#include "time.h"
#include "signal.h" #include "signal.h"
#include <poll.h> #include "pthread.h"
#include <fcntl.h>
#include <unistd.h>
#include <strings.h>
#define BUF_LEN 20
#define MAX_SCAN_FDSET 10 /* define poll's listened FD set's size */
#define POLL_WAIT_TIMEOUT 10*1000 /* ms */
extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask); #define BUF_SIZE 128
void work_ppoll(int fd) #define DELAY_TIME 200
{
int ret = 0;
int i = 0;
char recv_buf[BUF_LEN];
sigset_t sigset;
struct timespec t;
struct pollfd scan_fdset[MAX_SCAN_FDSET];
int scan_fdset_num = 10;
int count = 5;
bzero(recv_buf, BUF_LEN); static int pipeFdPpoll[2];
sigemptyset(&sigset); static int g_step = 1;
sigaddset(&sigset, SIGALRM); /* add SIGALRM to sigset */ static char strBuf[] = "hello world.";
sigaddset(&sigset, SIGUSR1); /* add SIGUSR1 to sigset */ static struct pollfd pfd;
bzero(&t, sizeof(struct timespec));
t.tv_sec = 10;
t.tv_nsec = 0;
bzero(scan_fdset, sizeof(struct pollfd) * MAX_SCAN_FDSET);
scan_fdset[0].fd = fd;
/* attention:in the book《UNIX网络编程第一卷》P162 metions:POLLERR,POLLHUP,POLLNVAL\ static void *pthread_01(void *arg)
those error signals can not be set in events. */ {
/* they will return in revents,while the proper condition happens. */ int retVal;
scan_fdset[0].events = POLLOUT; /* set the signal needed to be listened:POLLOUT/POLLIN */ char buf[BUF_SIZE];
const struct timespec timeout = {10000, 0};
/* set other elements in the array as invalid. */ /* 执行ppoll监视文件描述符 */
for (i = 1; i < MAX_SCAN_FDSET; i++) { while(g_step < 4) {
/* scan_fdset[i].fd = -1; */ usleep(DELAY_TIME);
scan_fdset[i].fd = fd;
scan_fdset[i].events = POLLOUT; /* set the signal needed to be listened. */
} }
/* scan_fdset_num = 1; */ /* 表示当前的scan_fdset[] 数组中只使用前面1 个元素存放需要监听的扫描符 */ g_step++;
retVal = ppoll(&pfd, 1, &timeout, NULL);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
while (count--) { /* 判断revents */
ret = ppoll(scan_fdset, scan_fdset_num, &t, &sigset); if (pfd.revents & POLLIN) {
memset(buf, 0, sizeof(buf));
for (i = 0; i < MAX_SCAN_FDSET; i++) { retVal = read(pfd.fd, buf, BUF_SIZE);
if (scan_fdset[i].revents & POLLOUT) { ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
TEST_PRINT("[INFO]%s:%d,%s,fd have signal!\n", __FILE__, __LINE__, __func__); retVal = strcmp(strBuf, buf);
ret = read(fd, recv_buf, BUF_LEN); ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
if (-1 == ret) {
TEST_PRINT("[INFO]%s:%d,%s,read error!\n", __FILE__, __LINE__, __func__);
continue;
}
TEST_PRINT("[INFO]%s:%d,%s,recv_buf=%s\n", __FILE__, __LINE__, __func__, recv_buf);
}
TEST_PRINT("[INFO]%s:%d,%s,scan_fdset[i].revents=%d\n", __FILE__, __LINE__, __func__, scan_fdset[i].revents);
} }
while(g_step < 5) {
usleep(DELAY_TIME);
} }
pthread_exit(NULL);
} }
static UINT32 testcase(VOID) static UINT32 testcase(VOID)
{ {
int fd; int retVal;
char *filename = FILEPATH_775; pthread_t tid;
/* 建立管道 */
while(g_step < 1) {
usleep(DELAY_TIME);
}
retVal = pipe(pipeFdPpoll);
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
/* 设置pfd */
pfd.fd = pipeFdPpoll[0];
pfd.events = POLLIN;
/* 向管道写入数据 */
while(g_step < 2) {
usleep(DELAY_TIME);
}
sleep(1);
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
g_step++;
/* 开辟线程执行 ppoll */
while(g_step < 3) {
usleep(DELAY_TIME);
}
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
g_step++;
fd = open(filename, O_RDWR); pthread_join(tid, NULL);
TEST_PRINT("[INFO]%s:%d,%s,fd=%d\n", __FILE__, __LINE__, __func__, fd);
work_ppoll(fd);
return LOS_OK; return LOS_OK;
} }
......
#include "It_test_IO.h"
#include "pthread.h"
#include "signal.h"
#define BUF_SIZE 128
#define DELAY_TIME 200
STATIC INT32 pipeFdPpoll[2];
STATIC INT32 g_step = 1;
STATIC CHAR strBuf[] = "hello world.";
STATIC struct pollfd pfd;
sigset_t sigMask;
STATIC UINT32 count = 0;
STATIC VOID signalHandle(INT32 sigNum)
{
//printf("Capture %d\n", sigNum);
g_step++;
return;
}
STATIC VOID *pthread_01(VOID *arg)
{
INT32 retVal;
CHAR buf[BUF_SIZE];
signal(SIGUSR1, signalHandle);
while (1) {
/*执行ppoll监视文件描述符*/
while (g_step < 2) {
usleep(DELAY_TIME);
}
g_step++;
retVal = ppoll(&pfd, 1, NULL, &sigMask);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
/*判断revents*/
if (pfd.revents & POLLIN) {
memset(buf, 0, sizeof(buf));
retVal = read(pfd.fd, buf, BUF_SIZE);
ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal);
retVal = strcmp(strBuf, buf);
ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal);
count++;
} else {
ICUNIT_ASSERT_NOT_EQUAL_NULL(pfd.revents & POLLIN, 0, pfd.revents & POLLIN);
}
g_step++;
if (g_step >= 7) {
ICUNIT_ASSERT_EQUAL_NULL(count, 2, count);
pthread_exit(NULL);
}
}
return LOS_OK;
}
STATIC UINT32 testcase(VOID)
{
INT32 retVal;
pthread_t tid;
/*建立管道*/
while (g_step < 1) {
usleep(DELAY_TIME);
}
retVal = pipe(pipeFdPpoll);
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
/*设置pfd sigmask*/
pfd.fd = pipeFdPpoll[0];
pfd.events = POLLIN;
pfd.revents = 0x0;
sigemptyset(&sigMask);
sigaddset(&sigMask, SIGUSR1);
/*开辟线程执行 ppoll*/
retVal = pthread_create(&tid, NULL, pthread_01, NULL);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
g_step++;
/*向管道写入数据*/
while (g_step < 3) {
usleep(DELAY_TIME);
}
sleep(1); /*保证先挂起再写入数据*/
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
/*向线程发送信号*/
while (g_step < 5) {
usleep(DELAY_TIME);
}
sleep(1); /*保证先挂起再发送信号*/
retVal = pthread_kill(tid, SIGUSR1);
ICUNIT_ASSERT_EQUAL(retVal, 0, retVal);
/*继续向管道写入数据*/
ICUNIT_ASSERT_EQUAL(g_step, 5, g_step); /*判断挂起解除之前信号没有被处理*/
retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf));
ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal);
while (g_step < 7) {
usleep(DELAY_TIME);
}
ICUNIT_ASSERT_EQUAL(count, 2, count);
/*等待退出*/
pthread_join(tid, NULL);
return LOS_OK;
}
VOID IO_TEST_PPOLL_003(VOID)
{
TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
}
\ No newline at end of file
...@@ -137,6 +137,17 @@ HWTEST_F(IoTest, IO_TEST_PPOLL_002, TestSize.Level0) ...@@ -137,6 +137,17 @@ HWTEST_F(IoTest, IO_TEST_PPOLL_002, TestSize.Level0)
IO_TEST_PPOLL_002(); IO_TEST_PPOLL_002();
} }
/* *
* @tc.name: IO_TEST_PPOLL_003
* @tc.desc: function for IoTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(IoTest, IO_TEST_PPOLL_003, TestSize.Level0)
{
IO_TEST_PPOLL_003();
}
/* * /* *
* @tc.name: IT_STDLIB_POLL_002 * @tc.name: IT_STDLIB_POLL_002
* @tc.desc: function for IoTest * @tc.desc: function for IoTest
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册