1 #include <signal.h>
2 #include <stdio.h>
3 #include "posixtest.h"
4
5 /*
6
7 * Copyright (c) 2002, Intel Corporation. All rights reserved.
8 * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
9 * This file is licensed under the GPL license. For the full content
10 * of this license, see the COPYING file at the top level of this
11 * source tree.
12
13 * Test that the sigwait() function. If no signal in 'set' is pending at the
14 * time of the call, the thread shall be suspended until one or more becomes
15 * pending.
16 * 1) Block a signal from delivery.
17 * 2) Call sigwait()
18 * 3) Raise the signal.
19 * 4) Verify this process will return when the signal is sent.
20 */
21
main(void)22 int main(void)
23 {
24 sigset_t newmask, pendingset;
25 int sig;
26
27 /* Empty set of blocked signals */
28
29 if ((sigemptyset(&newmask) == -1) || (sigemptyset(&pendingset) == -1)) {
30 printf("Error in sigemptyset()\n");
31 return PTS_UNRESOLVED;
32 }
33
34 /* Add SIGUSR2 to the set of blocked signals */
35 if (sigaddset(&newmask, SIGUSR2) == -1) {
36 perror("Error in sigaddset()\n");
37 return PTS_UNRESOLVED;
38 }
39
40 /* Block SIGUSR2 */
41 if (sigprocmask(SIG_SETMASK, &newmask, NULL) == -1) {
42 printf("Error in sigprocmask()\n");
43 return PTS_UNRESOLVED;
44 }
45
46 /* Send SIGUSR2 signal to this process. Since it is blocked,
47 * it should be pending */
48 if (raise(SIGUSR2) != 0) {
49 printf("Could not raise SIGUSR2\n");
50 return PTS_UNRESOLVED;
51 }
52
53 /* Test that SIGUSR2 is pending */
54 if (sigpending(&pendingset) == -1) {
55 printf("Could not get pending signal set\n");
56 return PTS_UNRESOLVED;
57 }
58
59 if (sigismember(&pendingset, SIGUSR2) != 1) {
60 printf("Signal SIGUSR2 is not pending!\n");
61 return PTS_FAIL;
62 }
63
64 /* Call sigwait and test if it passed/failed */
65 if (sigwait(&newmask, &sig) != 0) {
66 printf("Error in sigwait()\n");
67 return PTS_FAIL;
68 }
69
70 if (sig != SIGUSR2) {
71 printf("sigwait selected another signal\n");
72 return PTS_FAIL;
73 }
74
75 /* Test that SIGUSR2 is not pending anymore */
76 if (sigpending(&pendingset) == -1) {
77 printf("Could not get pending signal set\n");
78 return PTS_UNRESOLVED;
79 }
80
81 if (sigismember(&pendingset, SIGUSR2) != 0) {
82 printf("Signal SIGUSR2 is not pending!\n");
83 return PTS_FAIL;
84 }
85
86 /* If we get here, then the process was suspended until
87 * SIGUSR2 was raised. */
88 printf("Test PASSED\n");
89
90 return PTS_PASS;
91
92 }
93