1 /*
2 * Copyright (c) 2005, Bull S.A.. All rights reserved.
3 * Created by: Sebastien Decugis
4
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
17 * This sample test aims to check the following assertion:
18 *
19 * If Real-Time Signals extension is supported, and several signals in the
20 * range SIGRTMIN-SIGRTMAX are selected, the lower numbered is returned first.
21
22 * The steps are:
23 * -> mask SIGRTMIN-SIGRTMAX
24 * -> raise the signals in the range SIGRTMIN-SIGRTMAX
25 * -> sigwait a signal and check we get always teh lowest-ordered.
26
27 * The test fails if we select an unexpected signal.
28
29 */
30
31 /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
32 #define _POSIX_C_SOURCE 200112L
33
34 /******************************************************************************/
35 /*************************** standard includes ********************************/
36 /******************************************************************************/
37 #include <pthread.h>
38 #include <stdarg.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <unistd.h>
43
44 #include <signal.h>
45 #include <errno.h>
46
47 /******************************************************************************/
48 /*************************** Test framework *******************************/
49 /******************************************************************************/
50 #include "../testfrmw/testfrmw.h"
51 #include "../testfrmw/testfrmw.c"
52 /* This header is responsible for defining the following macros:
53 * UNRESOLVED(ret, descr);
54 * where descr is a description of the error and ret is an int
55 * (error code for example)
56 * FAILED(descr);
57 * where descr is a short text saying why the test has failed.
58 * PASSED();
59 * No parameter.
60 *
61 * Both three macros shall terminate the calling process.
62 * The testcase shall not terminate in any other maneer.
63 *
64 * The other file defines the functions
65 * void output_init()
66 * void output(char * string, ...)
67 *
68 * Those may be used to output information.
69 */
70
71 /******************************************************************************/
72 /**************************** Configuration ***********************************/
73 /******************************************************************************/
74 #ifndef VERBOSE
75 #define VERBOSE 1
76 #endif
77
78 /******************************************************************************/
79 /*************************** Test case ***********************************/
80 /******************************************************************************/
81
82 /* The main test function. */
main(void)83 int main(void)
84 {
85 int ret, i, sig;
86 long rts;
87 sigset_t set;
88
89 /* Initialize output */
90 output_init();
91
92 /* Test the RTS extension */
93 rts = sysconf(_SC_REALTIME_SIGNALS);
94
95 if (rts < 0L) {
96 UNTESTED("This test needs the RTS extension");
97 }
98
99 /* Set the signal mask */
100 ret = sigemptyset(&set);
101
102 if (ret != 0) {
103 UNRESOLVED(ret, "Failed to empty signal set");
104 }
105
106 /* Add all SIGRT signals */
107 for (i = SIGRTMIN; i <= SIGRTMAX; i++) {
108
109 ret = sigaddset(&set, i);
110
111 if (ret != 0) {
112 UNRESOLVED(ret, "failed to add signal to signal set");
113 }
114 }
115
116 /* Block all RT signals */
117 ret = pthread_sigmask(SIG_BLOCK, &set, NULL);
118
119 if (ret != 0) {
120 UNRESOLVED(ret, "Failed to block RT signals");
121 }
122
123 /* raise the signals in no particular order */
124 for (i = SIGRTMIN + 1; i <= SIGRTMAX; i += 3) {
125 ret = raise(i);
126
127 if (ret != 0) {
128 UNRESOLVED(ret, "Failed to raise the signal");
129 }
130 }
131
132 for (i = SIGRTMIN; i <= SIGRTMAX; i += 3) {
133 ret = raise(i);
134
135 if (ret != 0) {
136 UNRESOLVED(ret, "Failed to raise the signal");
137 }
138 }
139
140 for (i = SIGRTMIN + 2; i <= SIGRTMAX; i += 3) {
141 ret = raise(i);
142
143 if (ret != 0) {
144 UNRESOLVED(ret, "Failed to raise the signal");
145 }
146 }
147
148 /* All RT signals are pending */
149
150 /* Check the signals are delivered in order */
151 for (i = SIGRTMIN; i <= SIGRTMAX; i++) {
152 ret = sigwait(&set, &sig);
153
154 if (ret != 0) {
155 UNRESOLVED(ret, "Failed to sigwait for RT signal");
156 }
157
158 if (sig != i) {
159 output("SIGRTMIN: %d, SIGRTMAX: %d, i: %d, sig:%d\n",
160 SIGRTMIN, SIGRTMAX, i, sig);
161 FAILED("Got wrong signal");
162 }
163 }
164
165 /* Test passed */
166 #if VERBOSE > 0
167 output("Test passed\n");
168
169 #endif
170 PASSED;
171 }
172