1 /* Copyright (C) 2006-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
20 #include <support/check.h>
21 #include <support/support.h>
22 #include <support/xsignal.h>
23 #include <support/xunistd.h>
24 #include <support/xtime.h>
27 static volatile int handler_called
;
37 test_pselect_basic (void)
40 sa
.sa_handler
= handler
;
42 sigemptyset (&sa
.sa_mask
);
44 xsigaction (SIGUSR1
, &sa
, NULL
);
46 sa
.sa_handler
= SIG_IGN
;
47 xsigaction (SIGCHLD
, &sa
, NULL
);
50 sigemptyset (&ss_usr1
);
51 sigaddset (&ss_usr1
, SIGUSR1
);
52 TEST_COMPARE (sigprocmask (SIG_BLOCK
, &ss_usr1
, NULL
), 0);
62 TEST_COMPARE (sigprocmask (SIG_SETMASK
, NULL
, &ss
), 0);
63 sigdelset (&ss
, SIGUSR1
);
65 struct timespec to
= { .tv_sec
= 0, .tv_nsec
= 500000000 };
67 pid_t parent
= getpid ();
74 FD_SET (fds
[0][0], &rfds
);
79 if (getppid () != parent
)
80 FAIL_EXIT1 ("getppid()=%d != parent=%d", getppid(), parent
);
83 e
= pselect (fds
[0][0] + 1, &rfds
, NULL
, NULL
, &to
, &ss
);
88 TEST_COMPARE (errno
, EINTR
);
90 TEMP_FAILURE_RETRY (write (fds
[1][1], "foo", 3));
98 FD_SET (fds
[1][0], &rfds
);
100 TEST_COMPARE (kill (p
, SIGUSR1
), 0);
102 int e
= pselect (fds
[1][0] + 1, &rfds
, NULL
, NULL
, NULL
, &ss
);
104 TEST_VERIFY (FD_ISSET (fds
[1][0], &rfds
));
108 test_pselect_large_timeout (void)
110 support_create_timer (0, 100000000, false, NULL
);
117 FD_SET (fds
[0], &rfds
);
120 TEST_COMPARE (sigprocmask (SIG_SETMASK
, NULL
, &ss
), 0);
121 sigdelset (&ss
, SIGALRM
);
123 struct timespec ts
= { TYPE_MAXIMUM (time_t), 0 };
125 TEST_COMPARE (pselect (fds
[0] + 1, &rfds
, NULL
, NULL
, &ts
, &ss
), -1);
126 TEST_VERIFY (errno
== EINTR
|| errno
== EOVERFLOW
);
132 test_pselect_basic ();
134 test_pselect_large_timeout ();
139 #include <support/test-driver.c>