xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/ppoll/ppoll01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Crackerjack Project., 2007-2008 ,Hitachi, Ltd
4*49cdfc7eSAndroid Build Coastguard Worker  *          Author(s): Takahiro Yasui <[email protected]>,
5*49cdfc7eSAndroid Build Coastguard Worker  *		       Yumiko Sugita <[email protected]>,
6*49cdfc7eSAndroid Build Coastguard Worker  *		       Satoshi Fujiwara <[email protected]>
7*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2016 Linux Test Project
8*49cdfc7eSAndroid Build Coastguard Worker  */
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker #ifndef _GNU_SOURCE
11*49cdfc7eSAndroid Build Coastguard Worker #define _GNU_SOURCE
12*49cdfc7eSAndroid Build Coastguard Worker #endif
13*49cdfc7eSAndroid Build Coastguard Worker 
14*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <poll.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
18*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
19*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
20*49cdfc7eSAndroid Build Coastguard Worker #include "ltp_signal.h"
21*49cdfc7eSAndroid Build Coastguard Worker #include "time64_variants.h"
22*49cdfc7eSAndroid Build Coastguard Worker #include "tst_sig_proc.h"
23*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
24*49cdfc7eSAndroid Build Coastguard Worker #include "tst_timer.h"
25*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker /* Older versions of glibc don't publish this constant's value. */
28*49cdfc7eSAndroid Build Coastguard Worker #ifndef POLLRDHUP
29*49cdfc7eSAndroid Build Coastguard Worker #define POLLRDHUP 0x2000
30*49cdfc7eSAndroid Build Coastguard Worker #endif
31*49cdfc7eSAndroid Build Coastguard Worker 
32*49cdfc7eSAndroid Build Coastguard Worker #define TYPE_NAME(x) .ttype = x, .desc = #x
33*49cdfc7eSAndroid Build Coastguard Worker 
34*49cdfc7eSAndroid Build Coastguard Worker struct test_case {
35*49cdfc7eSAndroid Build Coastguard Worker 	int ttype;		   /* test type (enum) */
36*49cdfc7eSAndroid Build Coastguard Worker 	const char *desc;	   /* test description (name) */
37*49cdfc7eSAndroid Build Coastguard Worker 	int ret;		   /* expected ret code */
38*49cdfc7eSAndroid Build Coastguard Worker 	int err;		   /* expected errno code */
39*49cdfc7eSAndroid Build Coastguard Worker 	short expect_revents;	   /* expected revents value */
40*49cdfc7eSAndroid Build Coastguard Worker 	unsigned int nfds;	   /* nfds ppoll parameter */
41*49cdfc7eSAndroid Build Coastguard Worker 	sigset_t *sigmask;	   /* sigmask ppoll parameter */
42*49cdfc7eSAndroid Build Coastguard Worker 	sigset_t *sigmask_cur;	   /* sigmask set for current process */
43*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts *ts;	   /* ts ppoll parameter */
44*49cdfc7eSAndroid Build Coastguard Worker 	struct pollfd *fds;	   /* fds ppoll parameter */
45*49cdfc7eSAndroid Build Coastguard Worker 	int sigint_count;	   /* if > 0, spawn process to send SIGINT */
46*49cdfc7eSAndroid Build Coastguard Worker 				   /* 'count' times to current process */
47*49cdfc7eSAndroid Build Coastguard Worker 	unsigned int sigint_delay; /* delay between SIGINT signals */
48*49cdfc7eSAndroid Build Coastguard Worker };
49*49cdfc7eSAndroid Build Coastguard Worker 
50*49cdfc7eSAndroid Build Coastguard Worker enum test_type {
51*49cdfc7eSAndroid Build Coastguard Worker 	NORMAL,
52*49cdfc7eSAndroid Build Coastguard Worker 	MASK_SIGNAL,
53*49cdfc7eSAndroid Build Coastguard Worker 	TIMEOUT,
54*49cdfc7eSAndroid Build Coastguard Worker 	FD_ALREADY_CLOSED,
55*49cdfc7eSAndroid Build Coastguard Worker 	SEND_SIGINT,
56*49cdfc7eSAndroid Build Coastguard Worker 	SEND_SIGINT_RACE_TEST,
57*49cdfc7eSAndroid Build Coastguard Worker 	INVALID_NFDS,
58*49cdfc7eSAndroid Build Coastguard Worker 	INVALID_FDS,
59*49cdfc7eSAndroid Build Coastguard Worker };
60*49cdfc7eSAndroid Build Coastguard Worker 
61*49cdfc7eSAndroid Build Coastguard Worker static int fd1 = -1;
62*49cdfc7eSAndroid Build Coastguard Worker static sigset_t sigmask_empty, sigmask_sigint;
63*49cdfc7eSAndroid Build Coastguard Worker static struct pollfd fds_good[1], fds_already_closed[1];
64*49cdfc7eSAndroid Build Coastguard Worker 
65*49cdfc7eSAndroid Build Coastguard Worker static struct tst_ts ts_short, ts_long;
66*49cdfc7eSAndroid Build Coastguard Worker 
67*49cdfc7eSAndroid Build Coastguard Worker /* Test cases
68*49cdfc7eSAndroid Build Coastguard Worker  *
69*49cdfc7eSAndroid Build Coastguard Worker  *   test status of errors on man page
70*49cdfc7eSAndroid Build Coastguard Worker  *
71*49cdfc7eSAndroid Build Coastguard Worker  *   EBADF              can't check because EBADF never happen even though
72*49cdfc7eSAndroid Build Coastguard Worker  *                      fd was invalid. In this case, information of invalid
73*49cdfc7eSAndroid Build Coastguard Worker  *                      fd is set in revents
74*49cdfc7eSAndroid Build Coastguard Worker  *   EFAULT             v ('fds' array in the invalid address space)
75*49cdfc7eSAndroid Build Coastguard Worker  *   EINTR              v (a non blocked signal was caught)
76*49cdfc7eSAndroid Build Coastguard Worker  *   EINVAL             v ('nfds' is over the 'RLIMIT_NOFILE' value)
77*49cdfc7eSAndroid Build Coastguard Worker  *   ENOMEM             can't check because it's difficult to create no-memory
78*49cdfc7eSAndroid Build Coastguard Worker  */
79*49cdfc7eSAndroid Build Coastguard Worker 
80*49cdfc7eSAndroid Build Coastguard Worker static struct test_case tcase[] = {
81*49cdfc7eSAndroid Build Coastguard Worker 	{
82*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(NORMAL),
83*49cdfc7eSAndroid Build Coastguard Worker 		.expect_revents = POLLIN | POLLOUT,
84*49cdfc7eSAndroid Build Coastguard Worker 		.ret = 1,
85*49cdfc7eSAndroid Build Coastguard Worker 		.err = 0,
86*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = 1,
87*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_long,
88*49cdfc7eSAndroid Build Coastguard Worker 		.fds = fds_good,
89*49cdfc7eSAndroid Build Coastguard Worker 	},
90*49cdfc7eSAndroid Build Coastguard Worker 	{
91*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(MASK_SIGNAL),
92*49cdfc7eSAndroid Build Coastguard Worker 		.ret = 0,
93*49cdfc7eSAndroid Build Coastguard Worker 		.err = 0,
94*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = 0,
95*49cdfc7eSAndroid Build Coastguard Worker 		.sigmask = &sigmask_sigint,
96*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_short,
97*49cdfc7eSAndroid Build Coastguard Worker 		.fds = fds_good,
98*49cdfc7eSAndroid Build Coastguard Worker 		.sigint_count = 4,
99*49cdfc7eSAndroid Build Coastguard Worker 		.sigint_delay = 100000,
100*49cdfc7eSAndroid Build Coastguard Worker 	},
101*49cdfc7eSAndroid Build Coastguard Worker 	{
102*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(TIMEOUT),
103*49cdfc7eSAndroid Build Coastguard Worker 		.ret = 0,
104*49cdfc7eSAndroid Build Coastguard Worker 		.err = 0,
105*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = 0,
106*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_short,
107*49cdfc7eSAndroid Build Coastguard Worker 		.fds = fds_good,
108*49cdfc7eSAndroid Build Coastguard Worker 	},
109*49cdfc7eSAndroid Build Coastguard Worker 	{
110*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(FD_ALREADY_CLOSED),
111*49cdfc7eSAndroid Build Coastguard Worker 		.expect_revents = POLLNVAL,
112*49cdfc7eSAndroid Build Coastguard Worker 		.ret = 1,
113*49cdfc7eSAndroid Build Coastguard Worker 		.err = 0,
114*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = 1,
115*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_long,
116*49cdfc7eSAndroid Build Coastguard Worker 		.fds = fds_already_closed,
117*49cdfc7eSAndroid Build Coastguard Worker 	},
118*49cdfc7eSAndroid Build Coastguard Worker 	{
119*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(SEND_SIGINT),
120*49cdfc7eSAndroid Build Coastguard Worker 		.ret = -1,
121*49cdfc7eSAndroid Build Coastguard Worker 		.err = EINTR,
122*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = 0,
123*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_long,
124*49cdfc7eSAndroid Build Coastguard Worker 		.fds = fds_good,
125*49cdfc7eSAndroid Build Coastguard Worker 		.sigint_count = 40,
126*49cdfc7eSAndroid Build Coastguard Worker 		.sigint_delay = 100000,
127*49cdfc7eSAndroid Build Coastguard Worker 	},
128*49cdfc7eSAndroid Build Coastguard Worker 	{
129*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(SEND_SIGINT_RACE_TEST),
130*49cdfc7eSAndroid Build Coastguard Worker 		.ret = -1,
131*49cdfc7eSAndroid Build Coastguard Worker 		.err = EINTR,
132*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = 0,
133*49cdfc7eSAndroid Build Coastguard Worker 		.sigmask = &sigmask_empty,
134*49cdfc7eSAndroid Build Coastguard Worker 		.sigmask_cur = &sigmask_sigint,
135*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_long,
136*49cdfc7eSAndroid Build Coastguard Worker 		.fds = fds_good,
137*49cdfc7eSAndroid Build Coastguard Worker 		.sigint_count = 1,
138*49cdfc7eSAndroid Build Coastguard Worker 		.sigint_delay = 0,
139*49cdfc7eSAndroid Build Coastguard Worker 	},
140*49cdfc7eSAndroid Build Coastguard Worker 	{
141*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(INVALID_NFDS),
142*49cdfc7eSAndroid Build Coastguard Worker 		.ret = -1,
143*49cdfc7eSAndroid Build Coastguard Worker 		.err = EINVAL,
144*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = -1,
145*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_long,
146*49cdfc7eSAndroid Build Coastguard Worker 		.fds = fds_good,
147*49cdfc7eSAndroid Build Coastguard Worker 	},
148*49cdfc7eSAndroid Build Coastguard Worker 	{
149*49cdfc7eSAndroid Build Coastguard Worker 		TYPE_NAME(INVALID_FDS),
150*49cdfc7eSAndroid Build Coastguard Worker 		.ret = -1,
151*49cdfc7eSAndroid Build Coastguard Worker 		.err = EFAULT,
152*49cdfc7eSAndroid Build Coastguard Worker 		.nfds = 1,
153*49cdfc7eSAndroid Build Coastguard Worker 		.ts = &ts_long,
154*49cdfc7eSAndroid Build Coastguard Worker 		.fds = (struct pollfd *) -1,
155*49cdfc7eSAndroid Build Coastguard Worker 	},
156*49cdfc7eSAndroid Build Coastguard Worker };
157*49cdfc7eSAndroid Build Coastguard Worker 
libc_ppoll(struct pollfd * fds,nfds_t nfds,void * tmo_p,const sigset_t * sigmask,size_t sigsetsize LTP_ATTRIBUTE_UNUSED)158*49cdfc7eSAndroid Build Coastguard Worker static inline int libc_ppoll(struct pollfd *fds, nfds_t nfds, void *tmo_p,
159*49cdfc7eSAndroid Build Coastguard Worker 			     const sigset_t *sigmask,
160*49cdfc7eSAndroid Build Coastguard Worker 			     size_t sigsetsize LTP_ATTRIBUTE_UNUSED)
161*49cdfc7eSAndroid Build Coastguard Worker {
162*49cdfc7eSAndroid Build Coastguard Worker 	return ppoll(fds, nfds, tmo_p, sigmask);
163*49cdfc7eSAndroid Build Coastguard Worker }
164*49cdfc7eSAndroid Build Coastguard Worker 
sys_ppoll(struct pollfd * fds,nfds_t nfds,void * tmo_p,const sigset_t * sigmask,size_t sigsetsize)165*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_ppoll(struct pollfd *fds, nfds_t nfds, void *tmo_p,
166*49cdfc7eSAndroid Build Coastguard Worker 			    const sigset_t *sigmask, size_t sigsetsize)
167*49cdfc7eSAndroid Build Coastguard Worker {
168*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_ppoll, fds, nfds, tmo_p, sigmask, sigsetsize);
169*49cdfc7eSAndroid Build Coastguard Worker }
170*49cdfc7eSAndroid Build Coastguard Worker 
sys_ppoll_time64(struct pollfd * fds,nfds_t nfds,void * tmo_p,const sigset_t * sigmask,size_t sigsetsize)171*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_ppoll_time64(struct pollfd *fds, nfds_t nfds, void *tmo_p,
172*49cdfc7eSAndroid Build Coastguard Worker 				   const sigset_t *sigmask, size_t sigsetsize)
173*49cdfc7eSAndroid Build Coastguard Worker {
174*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_ppoll_time64, fds, nfds, tmo_p, sigmask,
175*49cdfc7eSAndroid Build Coastguard Worker 			   sigsetsize);
176*49cdfc7eSAndroid Build Coastguard Worker }
177*49cdfc7eSAndroid Build Coastguard Worker 
178*49cdfc7eSAndroid Build Coastguard Worker static struct time64_variants variants[] = {
179*49cdfc7eSAndroid Build Coastguard Worker 	{ .ppoll = libc_ppoll, .ts_type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
180*49cdfc7eSAndroid Build Coastguard Worker 
181*49cdfc7eSAndroid Build Coastguard Worker #if (__NR_ppoll != __LTP__NR_INVALID_SYSCALL)
182*49cdfc7eSAndroid Build Coastguard Worker 	{ .ppoll = sys_ppoll, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
183*49cdfc7eSAndroid Build Coastguard Worker #endif
184*49cdfc7eSAndroid Build Coastguard Worker 
185*49cdfc7eSAndroid Build Coastguard Worker #if (__NR_ppoll_time64 != __LTP__NR_INVALID_SYSCALL)
186*49cdfc7eSAndroid Build Coastguard Worker 	{ .ppoll = sys_ppoll_time64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
187*49cdfc7eSAndroid Build Coastguard Worker #endif
188*49cdfc7eSAndroid Build Coastguard Worker };
189*49cdfc7eSAndroid Build Coastguard Worker 
sighandler(int sig LTP_ATTRIBUTE_UNUSED)190*49cdfc7eSAndroid Build Coastguard Worker static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
191*49cdfc7eSAndroid Build Coastguard Worker {
192*49cdfc7eSAndroid Build Coastguard Worker }
193*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)194*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
195*49cdfc7eSAndroid Build Coastguard Worker {
196*49cdfc7eSAndroid Build Coastguard Worker 	struct time64_variants *tv = &variants[tst_variant];
197*49cdfc7eSAndroid Build Coastguard Worker 	int fd2;
198*49cdfc7eSAndroid Build Coastguard Worker 
199*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TINFO, "Testing variant: %s", tv->desc);
200*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_SIGNAL(SIGINT, sighandler);
201*49cdfc7eSAndroid Build Coastguard Worker 
202*49cdfc7eSAndroid Build Coastguard Worker 	if (sigemptyset(&sigmask_empty) == -1)
203*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK | TERRNO, "sigemptyset");
204*49cdfc7eSAndroid Build Coastguard Worker 	if (sigemptyset(&sigmask_sigint) == -1)
205*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK | TERRNO, "sigemptyset");
206*49cdfc7eSAndroid Build Coastguard Worker 	if (sigaddset(&sigmask_sigint, SIGINT) == -1)
207*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK | TERRNO, "sigaddset");
208*49cdfc7eSAndroid Build Coastguard Worker 
209*49cdfc7eSAndroid Build Coastguard Worker 	fd1 = SAFE_OPEN("testfile1", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
210*49cdfc7eSAndroid Build Coastguard Worker 	fds_good[0].fd = fd1;
211*49cdfc7eSAndroid Build Coastguard Worker 	fds_good[0].events = POLLIN | POLLPRI | POLLOUT | POLLRDHUP;
212*49cdfc7eSAndroid Build Coastguard Worker 	fds_good[0].revents = 0;
213*49cdfc7eSAndroid Build Coastguard Worker 
214*49cdfc7eSAndroid Build Coastguard Worker 	fd2 = SAFE_OPEN("testfile2", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
215*49cdfc7eSAndroid Build Coastguard Worker 	fds_already_closed[0].fd = fd2;
216*49cdfc7eSAndroid Build Coastguard Worker 	fds_already_closed[0].events = POLLIN | POLLPRI | POLLOUT | POLLRDHUP;
217*49cdfc7eSAndroid Build Coastguard Worker 	fds_already_closed[0].revents = 0;
218*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_CLOSE(fd2);
219*49cdfc7eSAndroid Build Coastguard Worker 
220*49cdfc7eSAndroid Build Coastguard Worker 	ts_short.type = ts_long.type = tv->ts_type;
221*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&ts_short, 0);
222*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&ts_short, 20000000);
223*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&ts_long, 2);
224*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&ts_long, 0);
225*49cdfc7eSAndroid Build Coastguard Worker }
226*49cdfc7eSAndroid Build Coastguard Worker 
cleanup(void)227*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
228*49cdfc7eSAndroid Build Coastguard Worker {
229*49cdfc7eSAndroid Build Coastguard Worker 	if (fd1 != -1)
230*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_CLOSE(fd1);
231*49cdfc7eSAndroid Build Coastguard Worker }
232*49cdfc7eSAndroid Build Coastguard Worker 
do_test(unsigned int i)233*49cdfc7eSAndroid Build Coastguard Worker static void do_test(unsigned int i)
234*49cdfc7eSAndroid Build Coastguard Worker {
235*49cdfc7eSAndroid Build Coastguard Worker 	struct time64_variants *tv = &variants[tst_variant];
236*49cdfc7eSAndroid Build Coastguard Worker 	pid_t pid = 0;
237*49cdfc7eSAndroid Build Coastguard Worker 	int sys_ret, sys_errno = 0, dummy;
238*49cdfc7eSAndroid Build Coastguard Worker 	struct test_case *tc = &tcase[i];
239*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts ts, *tsp = NULL;
240*49cdfc7eSAndroid Build Coastguard Worker 
241*49cdfc7eSAndroid Build Coastguard Worker 	if (tc->ts) {
242*49cdfc7eSAndroid Build Coastguard Worker 		memcpy(&ts, tc->ts, sizeof(ts));
243*49cdfc7eSAndroid Build Coastguard Worker 		tsp = &ts;
244*49cdfc7eSAndroid Build Coastguard Worker 	}
245*49cdfc7eSAndroid Build Coastguard Worker 
246*49cdfc7eSAndroid Build Coastguard Worker 	tst_res(TINFO, "case %s", tc->desc);
247*49cdfc7eSAndroid Build Coastguard Worker 
248*49cdfc7eSAndroid Build Coastguard Worker 	/* setup */
249*49cdfc7eSAndroid Build Coastguard Worker 	if (tc->sigmask_cur) {
250*49cdfc7eSAndroid Build Coastguard Worker 	       if (sigprocmask(SIG_SETMASK, tc->sigmask_cur, NULL) == -1)
251*49cdfc7eSAndroid Build Coastguard Worker 			tst_brk(TBROK, "sigprocmask");
252*49cdfc7eSAndroid Build Coastguard Worker 	}
253*49cdfc7eSAndroid Build Coastguard Worker 	if (tc->sigint_count > 0) {
254*49cdfc7eSAndroid Build Coastguard Worker 		pid = create_sig_proc(SIGINT, tc->sigint_count,
255*49cdfc7eSAndroid Build Coastguard Worker 			tc->sigint_delay);
256*49cdfc7eSAndroid Build Coastguard Worker 	}
257*49cdfc7eSAndroid Build Coastguard Worker 
258*49cdfc7eSAndroid Build Coastguard Worker 	/* test */
259*49cdfc7eSAndroid Build Coastguard Worker 	errno = 0;
260*49cdfc7eSAndroid Build Coastguard Worker 	sys_ret = tv->ppoll(tc->fds, tc->nfds, tst_ts_get(tsp), tc->sigmask,
261*49cdfc7eSAndroid Build Coastguard Worker 			    SIGSETSIZE);
262*49cdfc7eSAndroid Build Coastguard Worker 	sys_errno = errno;
263*49cdfc7eSAndroid Build Coastguard Worker 
264*49cdfc7eSAndroid Build Coastguard Worker 	/* cleanup */
265*49cdfc7eSAndroid Build Coastguard Worker 	if (tc->sigmask_cur) {
266*49cdfc7eSAndroid Build Coastguard Worker 		if (sigprocmask(SIG_SETMASK, &sigmask_empty, NULL) == -1)
267*49cdfc7eSAndroid Build Coastguard Worker 			tst_brk(TBROK, "sigprocmask");
268*49cdfc7eSAndroid Build Coastguard Worker 	}
269*49cdfc7eSAndroid Build Coastguard Worker 	if (pid > 0) {
270*49cdfc7eSAndroid Build Coastguard Worker 		kill(pid, SIGTERM);
271*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_WAIT(&dummy);
272*49cdfc7eSAndroid Build Coastguard Worker 	}
273*49cdfc7eSAndroid Build Coastguard Worker 
274*49cdfc7eSAndroid Build Coastguard Worker 	/* result check */
275*49cdfc7eSAndroid Build Coastguard Worker 	if (tc->expect_revents) {
276*49cdfc7eSAndroid Build Coastguard Worker 		if (tc->fds[0].revents == tc->expect_revents)
277*49cdfc7eSAndroid Build Coastguard Worker 			tst_res(TPASS, "revents=0x%04x", tc->expect_revents);
278*49cdfc7eSAndroid Build Coastguard Worker 		else
279*49cdfc7eSAndroid Build Coastguard Worker 			tst_res(TFAIL, "revents=0x%04x, expected=0x%04x",
280*49cdfc7eSAndroid Build Coastguard Worker 				tc->fds[0].revents, tc->expect_revents);
281*49cdfc7eSAndroid Build Coastguard Worker 	}
282*49cdfc7eSAndroid Build Coastguard Worker 	if (tc->ret >= 0 && tc->ret == sys_ret) {
283*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS, "ret: %d", sys_ret);
284*49cdfc7eSAndroid Build Coastguard Worker 	} else if (tc->ret == -1 && sys_ret == -1 && sys_errno == tc->err) {
285*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS, "ret: %d, errno: %s (%d)", sys_ret,
286*49cdfc7eSAndroid Build Coastguard Worker 			tst_strerrno(sys_errno), sys_errno);
287*49cdfc7eSAndroid Build Coastguard Worker 	} else {
288*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "ret: %d, exp: %d, ret_errno: %s (%d),"
289*49cdfc7eSAndroid Build Coastguard Worker 			" exp_errno: %s (%d)", sys_ret, tc->ret,
290*49cdfc7eSAndroid Build Coastguard Worker 			tst_strerrno(sys_errno), sys_errno,
291*49cdfc7eSAndroid Build Coastguard Worker 			tst_strerrno(tc->err), tc->err);
292*49cdfc7eSAndroid Build Coastguard Worker 	}
293*49cdfc7eSAndroid Build Coastguard Worker }
294*49cdfc7eSAndroid Build Coastguard Worker 
295*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
296*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcase),
297*49cdfc7eSAndroid Build Coastguard Worker 	.test = do_test,
298*49cdfc7eSAndroid Build Coastguard Worker 	.test_variants = ARRAY_SIZE(variants),
299*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
300*49cdfc7eSAndroid Build Coastguard Worker 	.cleanup = cleanup,
301*49cdfc7eSAndroid Build Coastguard Worker 	.forks_child = 1,
302*49cdfc7eSAndroid Build Coastguard Worker 	.needs_tmpdir = 1,
303*49cdfc7eSAndroid Build Coastguard Worker };
304