1 /* $NetBSD: t_sigaction.c,v 1.2 2012/11/07 16:51:16 pgoyette Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __COPYRIGHT("@(#) Copyright (c) 2010\
31 The NetBSD Foundation, inc. All rights reserved.");
32 __RCSID("$NetBSD: t_sigaction.c,v 1.2 2012/11/07 16:51:16 pgoyette Exp $");
43 #include <atf-c/config.h>
45 #include "../../../h_macros.h"
47 static bool handler_called
= false;
52 handler_called
= true;
56 sa_resethand_child(const int flags
)
61 sa
.sa_handler
= &handler
;
62 sigemptyset(&sa
.sa_mask
);
64 sigaction(SIGUSR1
, &sa
, NULL
);
65 kill(getpid(), SIGUSR1
);
66 exit(handler_called
? EXIT_SUCCESS
: EXIT_FAILURE
);
70 wait_and_check_child(const pid_t pid
, const char *fail_message
)
74 (void)waitpid(pid
, &status
, 0);
76 if (WIFEXITED(status
))
77 ATF_CHECK_EQ(EXIT_SUCCESS
, WEXITSTATUS(status
));
79 atf_tc_fail("%s; raw exit status was %d", fail_message
, status
);
88 ATF_TC(sigaction_basic
);
89 ATF_TC_HEAD(sigaction_basic
, tc
)
92 atf_tc_set_md_var(tc
, "descr", "Checks for correct I&D cache"
93 "synchronization after copying out the trampoline code.");
96 ATF_TC_BODY(sigaction_basic
, tc
)
98 static struct sigaction sa
;
100 sa
.sa_handler
= catch;
102 sigaction(SIGUSR1
, &sa
, 0);
103 kill(getpid(), SIGUSR1
);
107 ATF_TC(sigaction_noflags
);
108 ATF_TC_HEAD(sigaction_noflags
, tc
)
110 atf_tc_set_md_var(tc
, "descr", "Checks programming a signal with "
111 "sigaction(2) but without any flags");
114 ATF_TC_BODY(sigaction_noflags
, tc
)
116 const pid_t pid
= fork();
118 atf_tc_fail_errno("fork(2) failed");
120 sa_resethand_child(0);
122 wait_and_check_child(pid
, "Child process did not exit cleanly;"
123 " it failed to process the signal");
126 ATF_TC(sigaction_resethand
);
127 ATF_TC_HEAD(sigaction_resethand
, tc
)
129 atf_tc_set_md_var(tc
, "descr", "Checks that SA_RESETHAND works");
132 ATF_TC_BODY(sigaction_resethand
, tc
)
134 const pid_t pid
= fork();
136 atf_tc_fail_errno("fork(2) failed");
138 sa_resethand_child(SA_RESETHAND
);
140 wait_and_check_child(pid
, "Child process did not exit cleanly;"
141 " it either failed to process the signal or SA_RESETHAND"
149 ATF_TP_ADD_TC(tp
, sigaction_basic
);
150 ATF_TP_ADD_TC(tp
, sigaction_noflags
);
151 ATF_TP_ADD_TC(tp
, sigaction_resethand
);
153 return atf_no_error();