1 /* $NetBSD: t_raise.c,v 1.6 2016/11/03 22:08:31 kamil Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_raise.c,v 1.6 2016/11/03 22:08:31 kamil Exp $");
43 static void handler_err(int);
44 static void handler_ret(int);
45 static void handler_stress(int);
47 static int sig[] = { SIGALRM, SIGIO, SIGUSR1, SIGUSR2 };
49 static int sig[] = { SIGALRM, SIGIO, SIGUSR1, SIGUSR2, SIGPWR };
53 handler_stress(int signo)
59 handler_err(int signo)
63 for (i = 0; i < __arraycount(sig); i++) {
65 if (sig[i] == signo) {
73 handler_ret(int signo)
82 ATF_TC_HEAD(raise_err, tc)
84 atf_tc_set_md_var(tc, "descr", "Test raise(3) for invalid parameters");
87 ATF_TC_BODY(raise_err, tc)
93 ATF_REQUIRE(raise(10240 + i) == -1);
100 ATF_TC_HEAD(raise_ret, tc)
102 atf_tc_set_md_var(tc, "descr", "Test return order of raise(3)");
105 ATF_TC_BODY(raise_ret, tc)
112 sa.sa_handler = handler_ret;
115 * Verify that raise(3) does not return
116 * before the signal handler returns.
118 ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0);
119 ATF_REQUIRE(sigaction(SIGUSR1, &sa, 0) == 0);
120 ATF_REQUIRE(raise(SIGUSR1) == 0);
123 atf_tc_fail("raise(3) returned before signal handler");
127 ATF_TC_HEAD(raise_sig, tc)
129 atf_tc_set_md_var(tc, "descr", "A basic test of raise(3)");
132 ATF_TC_BODY(raise_sig, tc)
134 struct timespec tv, tr;
138 for (i = 0; i < __arraycount(sig); i++) {
140 (void)memset(&sa, 0, sizeof(struct sigaction));
148 sa.sa_handler = handler_err;
150 ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0);
151 ATF_REQUIRE(sigaction(sig[i], &sa, 0) == 0);
153 ATF_REQUIRE(raise(sig[i]) == 0);
154 ATF_REQUIRE(nanosleep(&tv, &tr) == 0);
157 atf_tc_fail("raise(3) did not raise a signal");
161 ATF_TC(raise_stress);
162 ATF_TC_HEAD(raise_stress, tc)
164 atf_tc_set_md_var(tc, "descr", "A basic stress test with raise(3)");
167 ATF_TC_BODY(raise_stress, tc)
169 static const int maxiter = 1000 * 10;
174 sa.sa_handler = handler_stress;
176 ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0);
177 ATF_REQUIRE(sigaction(SIGUSR1, &sa, 0) == 0);
179 for (count = i = 0; i < maxiter; i++)
180 (void)raise(SIGUSR1);
182 if (count != maxiter)
183 atf_tc_fail("not all signals were caught");
188 ATF_TP_ADD_TC(tp, raise_err);
189 ATF_TP_ADD_TC(tp, raise_ret);
190 ATF_TP_ADD_TC(tp, raise_sig);
191 ATF_TP_ADD_TC(tp, raise_stress);
193 return atf_no_error();