Mercurial > hg > octave-kai > gnulib-hg
annotate tests/test-sigprocmask.c @ 17476:6057744acd2c default tip master
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Fri, 16 Aug 2013 06:32:22 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
15362 | 1 /* Test of sigprocmask. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
17247
diff
changeset
|
2 Copyright (C) 2011-2013 Free Software Foundation, Inc. |
15362 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program 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 | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <signal.h> | |
22 | |
23 #include "signature.h" | |
24 SIGNATURE_CHECK (sigprocmask, int, (int, const sigset_t *, sigset_t *)); | |
25 | |
26 #include <errno.h> | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <unistd.h> | |
30 | |
31 #include "macros.h" | |
32 | |
33 #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) | |
34 | |
35 static volatile int sigint_occurred; | |
36 | |
37 static void | |
38 sigint_handler (int sig) | |
39 { | |
40 sigint_occurred++; | |
41 } | |
42 | |
43 int | |
44 main (int argc, char *argv[]) | |
45 { | |
46 sigset_t set; | |
17247
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
47 pid_t pid = getpid (); |
15362 | 48 char command[80]; |
49 | |
17247
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
50 if (sizeof (int) < sizeof pid && 0x7fffffff < pid) |
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
51 { |
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
52 fputs ("Skipping test: pid too large\n", stderr); |
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
53 return 77; |
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
54 } |
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
55 |
15362 | 56 signal (SIGINT, sigint_handler); |
57 | |
58 sigemptyset (&set); | |
59 sigaddset (&set, SIGINT); | |
60 | |
61 /* Check error handling. */ | |
62 ASSERT (sigprocmask (1729, &set, NULL) == -1); | |
63 ASSERT (errno == EINVAL); | |
64 | |
65 /* Block SIGINT. */ | |
66 ASSERT (sigprocmask (SIG_BLOCK, &set, NULL) == 0); | |
67 | |
68 /* Request a SIGINT signal from outside. */ | |
17247
fe6ac936b969
sigprocmask-tests: skip test if pid is unexpectedly large
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
69 sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, (int) pid); |
15385
1ba9b52b2fba
sigprocmask tests: A better way to avoid a compiler warning.
Bruno Haible <bruno@clisp.org>
parents:
15381
diff
changeset
|
70 ASSERT (system (command) == 0); |
15362 | 71 |
72 /* Wait. */ | |
73 sleep (2); | |
74 | |
75 /* The signal should not have arrived yet, because it is blocked. */ | |
76 ASSERT (sigint_occurred == 0); | |
77 | |
78 /* Unblock SIGINT. */ | |
79 ASSERT (sigprocmask (SIG_UNBLOCK, &set, NULL) == 0); | |
80 | |
81 /* The signal should have arrived now, because POSIX says | |
82 "If there are any pending unblocked signals after the call to | |
83 sigprocmask(), at least one of those signals shall be delivered | |
84 before the call to sigprocmask() returns." */ | |
85 ASSERT (sigint_occurred == 1); | |
86 | |
87 return 0; | |
88 } | |
89 | |
90 #else | |
91 | |
92 /* On native Windows, getpid() values and the arguments that are passed to | |
93 the (Cygwin?) 'kill' program are not necessarily related. */ | |
94 | |
95 int | |
96 main () | |
97 { | |
98 fputs ("Skipping test: native Windows platform\n", stderr); | |
99 return 77; | |
100 } | |
101 | |
102 #endif |