3-1.c revision 1b8a2eaac9978e1f9a829e5e38dc39c892c77c75
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.
14 *  If prior to the call to sigwait() there are multiple pending instances of
15 *  a single signal number (and it is implementation-defined that the signal
16 *  number DOES NOT support queued signals), then there should be no remaining
17 *  pending signals for that signal number.
18 *  Steps are:
19 *  1)  Block a signal that doesn't support queueing from delivery.
20 *  2)  Raise that signal 4 times.
21 *  3)  Call sigwait()
22 *  4)  Verify it cleared the signal from the pending signals and there
23 *      are no signals left in the pending list.
24 *
25 */
26
27
28int main()
29{
30	sigset_t newmask, pendingset;
31	int sig;
32
33	/* Empty set of blocked signals */
34	if ( (sigemptyset(&newmask) == -1) ||
35		(sigemptyset(&pendingset) == -1) )
36	{
37		printf("Error in sigemptyset()\n");
38		return PTS_UNRESOLVED;
39	}
40
41	/* Add SIGALRM to the set of blocked signals */
42	if (sigaddset(&newmask, SIGALRM) == -1)
43	{
44		perror("Error in sigaddset()\n");
45		return PTS_UNRESOLVED;
46	}
47
48	/* Block SIGALRM */
49	if (sigprocmask(SIG_SETMASK, &newmask, NULL) == -1)
50	{
51		printf("Error in sigprocmask()\n");
52		return PTS_UNRESOLVED;
53	}
54
55	/* Send SIGALRM signal 4 times to this process.  Since it is blocked,
56	 * it should be pending. */
57	if (raise(SIGALRM) != 0) {
58		printf("Could not raise SIGALRM\n");
59		return PTS_UNRESOLVED;
60	}
61	if (raise(SIGALRM) != 0) {
62		printf("Could not raise SIGALRM\n");
63		return PTS_UNRESOLVED;
64	}
65	if (raise(SIGALRM) != 0) {
66		printf("Could not raise SIGALRM\n");
67		return PTS_UNRESOLVED;
68	}
69	if (raise(SIGALRM) != 0) {
70		printf("Could not raise SIGALRM\n");
71		return PTS_UNRESOLVED;
72	}
73
74	/* Obtain a set of pending signals */
75	if (sigpending(&pendingset) == -1) {
76		printf("Error calling sigpending()\n");
77		return PTS_UNRESOLVED;
78	}
79
80	/* Make sure SIGALRM is pending */
81	if (sigismember(&pendingset, SIGALRM) == 0) {
82		printf("Error: signal SIGALRM not pending\n");
83		return PTS_UNRESOLVED;
84	}
85
86	/* Call sigwait */
87	if (sigwait(&newmask, &sig) != 0)
88	{
89		printf("Error in sigwait\n");
90		return PTS_UNRESOLVED;
91	}
92
93	/* Make sure SIGALRM is not in the pending list anymore */
94	if (sigpending(&pendingset) == -1) {
95		printf("Error calling sigpending()\n");
96		return PTS_UNRESOLVED;
97	}
98
99	if (sigismember(&pendingset, SIGALRM) == 1)
100	{
101		printf("Test FAILED\n");
102		return PTS_FAIL;
103	}
104
105	printf("Test PASSED\n");
106	return PTS_PASS;
107
108}
109