1/*
2 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7
8 This program tests the assertion that the lowest pending signal will be
9 selected for delivery if there are any multiple pending signals in the
10 range SIGRTMIN to SIGRTMAX.
11
12 Steps:
13 - Register for myhandler to be called when any signal between SIGRTMIN
14   and SIGRTMAX is generated, and make
15   sure SA_SIGINFO is set.
16 - Also, make sure that all of these signals are added to the handler's
17   signal mask.
18 - Initially block all of these signals from the process.
19 - Raise all of these signals using sigqueue.
20 - Unblock all of these queued signals simultaneously using sigprocmask.
21 - Verify that the signals are delivered in order from smallest to
22   biggest.
23 */
24
25#define _XOPEN_SOURCE 600
26#define _XOPEN_REALTIME 1
27
28#include <signal.h>
29#include <stdio.h>
30#include <unistd.h>
31#include <stdlib.h>
32#include <errno.h>
33#include "posixtest.h"
34
35int last_signal = 0;
36int test_failed = 0;
37
38void myhandler(int signo, siginfo_t * info, void *context)
39{
40	printf("%d, ", signo);
41	if (last_signal >= signo) {
42		test_failed = 1;
43	}
44}
45
46int main(void)
47{
48	int pid, rtsig;
49	union sigval value;
50	struct sigaction act;
51	sigset_t mask;
52
53	act.sa_flags = SA_SIGINFO;
54	act.sa_sigaction = myhandler;
55	sigemptyset(&act.sa_mask);
56
57	sigemptyset(&mask);
58
59	for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
60		sigaddset(&act.sa_mask, rtsig);
61		sighold(rtsig);
62		sigaddset(&mask, rtsig);
63	}
64
65	pid = getpid();
66	value.sival_int = 5;	/* 5 is just an arbitrary value */
67
68	for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
69		sigaction(rtsig, &act, 0);
70		if (sigqueue(pid, rtsig, value) != 0) {
71			printf
72			    ("Test UNRESOLVED: call to sigqueue did not return success\n");
73			return PTS_UNRESOLVED;
74		}
75	}
76
77	sigprocmask(SIG_UNBLOCK, &mask, NULL);
78	printf("\n");
79
80	if (test_failed == 1) {
81		printf
82		    ("Test FAILED: A pending signal was delivered even though a smaller one is still pending.\n");
83		return PTS_FAIL;
84	}
85
86	return PTS_PASS;
87}
88