subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Jiri Palecek<jpalecek@web.de>, 2009 |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 22 | */ |
| 23 | #include "test.h" |
| 24 | #include "usctest.h" |
| 25 | #include <errno.h> |
| 26 | #include <signal.h> |
| 27 | #include "../utils/include_j_h.h" |
| 28 | #include "../utils/common_j_h.c" |
| 29 | #include <limits.h> |
| 30 | #include "linux_syscall_numbers.h" |
| 31 | |
Garrett Cooper | 6061109 | 2011-02-23 00:04:58 -0800 | [diff] [blame] | 32 | #define SUCCEED_OR_DIE(syscall, message, ...) \ |
| 33 | (errno = 0, \ |
| 34 | ({int ret=syscall(__VA_ARGS__); \ |
| 35 | if (ret==-1) \ |
| 36 | tst_brkm(TBROK|TERRNO, cleanup, message);\ |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 37 | ret;})) |
| 38 | |
| 39 | /* Report success iff TEST_RETURN and TEST_ERRNO are equal to |
| 40 | exp_return and exp_errno, resp., and cond is true. If cond is not |
| 41 | true, report condition_errmsg |
| 42 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 43 | static void report_success_cond(const char *func, const char *file, int line, |
| 44 | long exp_return, int exp_errno, int condition, |
| 45 | char *condition_errmsg) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 46 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 47 | if (exp_return == TEST_RETURN |
| 48 | && (exp_return != -1 || exp_errno == TEST_ERRNO)) |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 49 | if (condition) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 50 | tst_resm(TPASS, "Test passed"); |
| 51 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 52 | tst_resm(TFAIL, "%s (%s: %d): %s", func, file, line, |
| 53 | condition_errmsg); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 54 | else if (TEST_RETURN != -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 55 | tst_resm(TFAIL, |
| 56 | "%s (%s: %d): Unexpected return value; expected %ld, got %ld", |
| 57 | func, file, line, exp_return, TEST_RETURN); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 58 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 59 | tst_resm(TFAIL | TTERRNO, "%s (%s: %d): Unexpected failure", |
| 60 | func, file, line); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | #define REPORT_SUCCESS_COND(exp_return, exp_errno, condition, condition_errmsg) \ |
| 64 | report_success_cond(__FUNCTION__, __FILE__, __LINE__, exp_return, exp_errno, condition, condition_errmsg); |
| 65 | |
| 66 | /* Report success iff TEST_RETURN and TEST_ERRNO are equal to |
| 67 | exp_return and exp_errno, resp. |
| 68 | */ |
| 69 | #define REPORT_SUCCESS(exp_return, exp_errno) \ |
| 70 | REPORT_SUCCESS_COND(exp_return, exp_errno, 1, ""); |
| 71 | |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 72 | static void cleanup(void); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 73 | |
| 74 | static void empty_handler(int sig) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | static void setup(void) |
| 79 | { |
| 80 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 81 | signal(SIGUSR1, empty_handler); |
| 82 | signal(SIGALRM, empty_handler); |
| 83 | signal(SIGUSR2, SIG_IGN); |
| 84 | |
| 85 | TEST_PAUSE; |
| 86 | } |
| 87 | |
| 88 | static void cleanup(void) |
| 89 | { |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 90 | |
Garrett Cooper | 6061109 | 2011-02-23 00:04:58 -0800 | [diff] [blame] | 91 | TEST_CLEANUP; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 94 | typedef int (*swi_func) (const sigset_t * set, siginfo_t * info, |
| 95 | struct timespec * timeout); |
| 96 | typedef void (*test_func) (swi_func, int); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 97 | |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 98 | #ifdef TEST_SIGWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | static int my_sigwait(const sigset_t * set, siginfo_t * info, |
| 100 | struct timespec *timeout) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 101 | { |
| 102 | int ret; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | int err = sigwait(set, &ret); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 104 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 105 | if (err == 0) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 106 | return ret; |
| 107 | errno = err; |
| 108 | return -1; |
| 109 | } |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 110 | #endif |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 111 | |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 112 | #ifdef TEST_SIGWAITINFO |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 113 | static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info, |
| 114 | struct timespec *timeout) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 115 | { |
Garrett Cooper | 6061109 | 2011-02-23 00:04:58 -0800 | [diff] [blame] | 116 | |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 117 | return sigwaitinfo(set, info); |
| 118 | } |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 119 | #endif |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 120 | |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 121 | #ifdef TEST_SIGTIMEDWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 122 | static int my_sigtimedwait(const sigset_t * set, siginfo_t * info, |
| 123 | struct timespec *timeout) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 124 | { |
Garrett Cooper | 6061109 | 2011-02-23 00:04:58 -0800 | [diff] [blame] | 125 | |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 126 | return sigtimedwait(set, info, timeout); |
| 127 | } |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 128 | #endif |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 129 | |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 130 | #ifdef TEST_RT_SIGTIMEDWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 131 | static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info, |
| 132 | struct timespec *timeout) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 133 | { |
Garrett Cooper | 6061109 | 2011-02-23 00:04:58 -0800 | [diff] [blame] | 134 | |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 135 | /* The last argument is (number_of_signals)/(bits_per_byte), which are 64 and 8, resp. */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 136 | return ltp_syscall(__NR_rt_sigtimedwait, set, info, timeout, 8); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 137 | } |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 138 | #endif |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 139 | |
| 140 | void test_empty_set(swi_func sigwaitinfo, int signo) |
| 141 | { |
| 142 | sigset_t sigs; |
| 143 | siginfo_t si; |
| 144 | pid_t child; |
| 145 | |
| 146 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 147 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 148 | child = create_sig_proc(100000, signo, UINT_MAX); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 149 | |
| 150 | TEST(sigwaitinfo(&sigs, &si, NULL)); |
| 151 | REPORT_SUCCESS(-1, EINTR); |
| 152 | |
| 153 | kill(child, SIGTERM); |
| 154 | } |
| 155 | |
| 156 | void test_timeout(swi_func sigwaitinfo, int signo) |
| 157 | { |
| 158 | sigset_t sigs; |
| 159 | siginfo_t si; |
| 160 | pid_t child; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 161 | struct timespec ts = {.tv_sec = 1 }; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 162 | |
| 163 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 164 | |
| 165 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 166 | child = create_sig_proc(100000, signo, UINT_MAX); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 167 | |
| 168 | TEST(sigwaitinfo(&sigs, &si, &ts)); |
| 169 | REPORT_SUCCESS(-1, EAGAIN); |
| 170 | |
| 171 | kill(child, SIGTERM); |
| 172 | } |
| 173 | |
| 174 | /* Note: sigwait-ing for a signal that is not blocked is unspecified |
| 175 | * by POSIX; but works for non-ignored signals under Linux |
| 176 | */ |
| 177 | void test_unmasked_matching(swi_func sigwaitinfo, int signo) |
| 178 | { |
| 179 | sigset_t sigs; |
| 180 | siginfo_t si; |
| 181 | pid_t child; |
| 182 | |
| 183 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 184 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); |
| 185 | |
| 186 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 187 | child = create_sig_proc(100000, signo, UINT_MAX); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 188 | |
| 189 | TEST(sigwaitinfo(&sigs, &si, NULL)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 190 | REPORT_SUCCESS_COND(signo, 0, si.si_pid == child |
| 191 | && si.si_code == SI_USER |
| 192 | && si.si_signo == signo, "Struct siginfo mismatch"); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 193 | |
| 194 | kill(child, SIGTERM); |
| 195 | } |
| 196 | |
| 197 | void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo) |
| 198 | { |
| 199 | sigset_t sigs; |
| 200 | pid_t child; |
| 201 | |
| 202 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 203 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); |
| 204 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 205 | child = create_sig_proc(100000, signo, UINT_MAX); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 206 | |
| 207 | TEST(sigwaitinfo(&sigs, NULL, NULL)); |
| 208 | REPORT_SUCCESS(signo, 0); |
| 209 | |
| 210 | kill(child, SIGTERM); |
| 211 | } |
| 212 | |
| 213 | void test_masked_matching(swi_func sigwaitinfo, int signo) |
| 214 | { |
| 215 | sigset_t sigs, oldmask; |
| 216 | siginfo_t si; |
| 217 | pid_t child; |
| 218 | |
| 219 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 220 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); |
| 221 | /* let's not get interrupted by our dying child */ |
| 222 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD); |
| 223 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 224 | SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs, |
| 225 | &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 226 | |
| 227 | /* don't wait on a SIGCHLD */ |
| 228 | SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD); |
| 229 | |
| 230 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 231 | child = create_sig_proc(0, signo, 1); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 232 | |
| 233 | TEST(sigwaitinfo(&sigs, &si, NULL)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 234 | REPORT_SUCCESS_COND(signo, 0, si.si_pid == child |
| 235 | && si.si_code == SI_USER |
| 236 | && si.si_signo == signo, "Struct siginfo mismatch"); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 237 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 238 | SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed", |
| 239 | SIG_SETMASK, &oldmask, &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 240 | |
| 241 | Tst_count--; |
| 242 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 243 | if (sigismember(&oldmask, signo)) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 244 | tst_resm(TPASS, "sigwaitinfo restored the original mask"); |
| 245 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 246 | tst_resm(TFAIL, |
| 247 | "sigwaitinfo failed to restore the original mask"); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void test_masked_matching_rt(swi_func sigwaitinfo, int signo) |
| 251 | { |
| 252 | sigset_t sigs, oldmask; |
| 253 | siginfo_t si; |
| 254 | pid_t child[2]; |
| 255 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 256 | signo = SIGRTMIN + 1; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 257 | |
| 258 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 259 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 260 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo + 1); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 261 | /* let's not get interrupted by our dying child */ |
| 262 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD); |
| 263 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 264 | SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs, |
| 265 | &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 266 | |
| 267 | /* don't wait on a SIGCHLD */ |
| 268 | SUCCEED_OR_DIE(sigdelset, "sigdelset failed", &sigs, SIGCHLD); |
| 269 | |
| 270 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 271 | child[0] = create_sig_proc(0, signo, 1); |
| 272 | child[1] = create_sig_proc(0, signo + 1, 1); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 273 | |
| 274 | TEST(sigwaitinfo(&sigs, &si, NULL)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 275 | REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0] |
| 276 | && si.si_code == SI_USER |
| 277 | && si.si_signo == signo, "Struct siginfo mismatch"); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 278 | |
| 279 | /* eat the other signal */ |
| 280 | Tst_count--; |
| 281 | TEST(sigwaitinfo(&sigs, &si, NULL)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 282 | REPORT_SUCCESS_COND(signo + 1, 0, si.si_pid == child[1] |
| 283 | && si.si_code == SI_USER |
| 284 | && si.si_signo == signo + 1, |
| 285 | "Struct siginfo mismatch"); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 286 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 287 | SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed", |
| 288 | SIG_SETMASK, &oldmask, &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 289 | |
| 290 | Tst_count--; |
| 291 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 292 | if (sigismember(&oldmask, signo)) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 293 | tst_resm(TPASS, "sigwaitinfo restored the original mask"); |
| 294 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 295 | tst_resm(TFAIL, |
| 296 | "sigwaitinfo failed to restore the original mask"); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo) |
| 300 | { |
| 301 | sigset_t sigs, oldmask; |
| 302 | pid_t child; |
| 303 | |
| 304 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 305 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); |
| 306 | /* let's not get interrupted by our dying child */ |
| 307 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD); |
| 308 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 309 | SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs, |
| 310 | &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 311 | |
| 312 | /* don't wait on a SIGCHLD */ |
| 313 | SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD); |
| 314 | |
| 315 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 316 | child = create_sig_proc(0, signo, 1); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 317 | |
| 318 | TEST(sigwaitinfo(&sigs, NULL, NULL)); |
| 319 | REPORT_SUCCESS(signo, 0); |
| 320 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 321 | SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed", |
| 322 | SIG_SETMASK, &oldmask, &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 323 | |
| 324 | Tst_count--; |
| 325 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 326 | if (sigismember(&oldmask, signo)) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 327 | tst_resm(TPASS, "sigwaitinfo restored the original mask"); |
| 328 | else |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 329 | tst_resm(TFAIL, |
| 330 | "sigwaitinfo failed to restore the original mask"); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 331 | |
| 332 | } |
| 333 | |
| 334 | void test_bad_address(swi_func sigwaitinfo, int signo) |
| 335 | { |
| 336 | sigset_t sigs, oldmask; |
| 337 | pid_t child; |
| 338 | |
| 339 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 340 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo); |
| 341 | /* let's not get interrupted by our dying child */ |
| 342 | SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD); |
| 343 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 344 | SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs, |
| 345 | &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 346 | |
| 347 | /* don't wait on a SIGCHLD */ |
| 348 | SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD); |
| 349 | |
| 350 | /* Run a child that will wake us up */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 351 | child = create_sig_proc(0, signo, 1); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 352 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 353 | TEST(sigwaitinfo(&sigs, (void *)1, NULL)); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 354 | REPORT_SUCCESS(-1, EFAULT); |
| 355 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 356 | SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &oldmask, |
| 357 | &oldmask); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 358 | |
| 359 | kill(child, SIGTERM); |
| 360 | } |
| 361 | |
| 362 | void test_bad_address2(swi_func sigwaitinfo, int signo) |
| 363 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 364 | TEST(sigwaitinfo((void *)1, NULL, NULL)); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 365 | REPORT_SUCCESS(-1, EFAULT); |
| 366 | } |
| 367 | |
| 368 | void test_bad_address3(swi_func sigwaitinfo, int signo) |
| 369 | { |
| 370 | sigset_t sigs; |
| 371 | SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs); |
| 372 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 373 | TEST(sigwaitinfo(&sigs, NULL, (void *)1)); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 374 | REPORT_SUCCESS(-1, EFAULT); |
| 375 | } |
| 376 | |
| 377 | struct test_desc { |
| 378 | test_func tf; |
| 379 | swi_func swi; |
| 380 | int signo; |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 381 | } tests[] = { |
| 382 | #ifdef TEST_RT_SIGTIMEDWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 383 | { |
| 384 | test_empty_set, my_rt_sigtimedwait, SIGUSR1}, { |
| 385 | test_unmasked_matching, my_rt_sigtimedwait, SIGUSR1}, { |
| 386 | test_masked_matching, my_rt_sigtimedwait, SIGUSR1}, { |
| 387 | test_unmasked_matching_noinfo, my_rt_sigtimedwait, SIGUSR1}, { |
| 388 | test_masked_matching_noinfo, my_rt_sigtimedwait, SIGUSR1}, { |
| 389 | test_bad_address, my_rt_sigtimedwait, SIGUSR1}, { |
| 390 | test_bad_address2, my_rt_sigtimedwait, SIGUSR1}, { |
| 391 | test_bad_address3, my_rt_sigtimedwait, SIGUSR1}, { |
| 392 | test_timeout, my_rt_sigtimedwait, 0}, |
| 393 | /* Special cases */ |
| 394 | /* 1: sigwaitinfo does respond to ignored signal */ |
| 395 | { |
| 396 | test_masked_matching, my_rt_sigtimedwait, SIGUSR2}, |
| 397 | /* 2: An ignored signal doesn't cause sigwaitinfo to return EINTR */ |
| 398 | { |
| 399 | test_timeout, my_rt_sigtimedwait, SIGUSR2}, |
| 400 | /* 3: The handler is not called when the signal is waited for by sigwaitinfo */ |
| 401 | { |
| 402 | test_masked_matching, my_rt_sigtimedwait, SIGTERM}, |
| 403 | /* 4: Simultaneous realtime signals are delivered in the order of increasing signal number */ |
| 404 | { |
| 405 | test_masked_matching_rt, my_rt_sigtimedwait, -1}, |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 406 | #endif |
| 407 | #if defined TEST_SIGWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 408 | { |
| 409 | test_unmasked_matching_noinfo, my_sigwait, SIGUSR1}, { |
| 410 | test_masked_matching_noinfo, my_sigwait, SIGUSR1}, |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 411 | #endif |
| 412 | #if defined TEST_SIGWAITINFO |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 413 | { |
| 414 | test_empty_set, my_sigwaitinfo, SIGUSR1}, { |
| 415 | test_unmasked_matching, my_sigwaitinfo, SIGUSR1}, { |
| 416 | test_masked_matching, my_sigwaitinfo, SIGUSR1}, { |
| 417 | test_unmasked_matching_noinfo, my_sigwaitinfo, SIGUSR1}, { |
| 418 | test_masked_matching_noinfo, my_sigwaitinfo, SIGUSR1}, { |
| 419 | test_bad_address, my_sigwaitinfo, SIGUSR1}, { |
| 420 | test_bad_address2, my_sigwaitinfo, SIGUSR1}, |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 421 | #endif |
| 422 | #if defined TEST_SIGTIMEDWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 423 | { |
| 424 | test_empty_set, my_sigtimedwait, SIGUSR1}, { |
| 425 | test_unmasked_matching, my_sigtimedwait, SIGUSR1}, { |
| 426 | test_masked_matching, my_sigtimedwait, SIGUSR1}, { |
| 427 | test_unmasked_matching_noinfo, my_sigtimedwait, SIGUSR1}, { |
| 428 | test_masked_matching_noinfo, my_sigtimedwait, SIGUSR1}, { |
| 429 | test_bad_address, my_sigtimedwait, SIGUSR1}, { |
| 430 | test_bad_address2, my_sigtimedwait, SIGUSR1}, { |
| 431 | test_bad_address3, my_sigtimedwait, SIGUSR1}, { |
| 432 | test_timeout, my_sigtimedwait, 0}, |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 433 | #endif |
| 434 | }; |
| 435 | |
| 436 | #if defined TEST_SIGWAITINFO |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 437 | const char *TCID = "sigwaitinfo01"; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 438 | #elif defined TEST_RT_SIGTIMEDWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 439 | const char *TCID = "rt_sigtimedwait01"; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 440 | #elif defined TEST_SIGTIMEDWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 441 | const char *TCID = "sigtimedwait01"; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 442 | #elif defined TEST_SIGWAIT |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 443 | const char *TCID = "sigwait01"; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 444 | #endif |
| 445 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 446 | int TST_TOTAL = sizeof(tests) / sizeof(*tests); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 447 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 448 | int main(int argc, char **argv) |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 449 | { |
| 450 | unsigned i; |
| 451 | int lc; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 452 | char *msg; |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 453 | |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 454 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 455 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 456 | |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 457 | setup(); |
| 458 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 459 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 460 | Tst_count = 0; |
| 461 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 462 | for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { |
| 463 | alarm(10); /* arrange a 10 second timeout */ |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 464 | tst_resm(TINFO, "%p, %d", tests[i].swi, tests[i].signo); |
subrata_modak | ded2c1e | 2009-12-07 11:44:52 +0000 | [diff] [blame] | 465 | tests[i].tf(tests[i].swi, tests[i].signo); |
| 466 | } |
| 467 | alarm(0); |
| 468 | } |
| 469 | |
| 470 | cleanup(); |
Garrett Cooper | ab5336e | 2010-12-19 08:41:59 -0800 | [diff] [blame] | 471 | tst_exit(); |
Garrett Cooper | 6061109 | 2011-02-23 00:04:58 -0800 | [diff] [blame] | 472 | } |