t_trapsignal.sh revision 1.3
1# $NetBSD: t_trapsignal.sh,v 1.3 2018/05/22 04:32:56 kamil Exp $
2#
3# Copyright (c) 2017 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# This code is derived from software contributed to The NetBSD Foundation
7# by Christos Zoulas.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31HELPER=$(atf_get_srcdir)/h_segv
32atf_test_case segv_simple
33segv_simple()
34{
35	atf_set "descr" "Test unhandled SIGSEGV with the right exit code"
36}
37segv_simple_body()
38{
39	atf_check -s signal:11 -o "inline:" -e "inline:" \
40		${HELPER} segv recurse
41}
42
43atf_test_case segv_handle
44segv_handle()
45{
46	atf_set "descr" "Test handled SIGSEGV traps call the signal handler"
47}
48segv_handle_body()
49{
50	atf_check -s exit:0 -o "inline:" -e "inline:got 11\n" \
51		${HELPER} segv handle
52}
53
54atf_test_case segv_mask
55segv_mask()
56{
57	atf_set "descr" "Test that masking SIGSEGV get reset"
58}
59segv_mask_body()
60{
61	atf_check -s signal:11 -o "inline:" -e "inline:" \
62		${HELPER} segv mask
63}
64
65atf_test_case segv_handle_mask
66segv_handle_mask()
67{
68	atf_set "descr" "Test handled and masked SIGSEGV traps get reset"
69}
70segv_handle_mask_body()
71{
72	atf_check -s signal:11 -o "inline:" -e "inline:" \
73		${HELPER} segv mask handle
74}
75
76atf_test_case segv_handle_recurse
77segv_handle_recurse()
78{
79	atf_set "descr" "Test that receiving SIGSEGV in the handler resets"
80}
81
82segv_handle_recurse_body()
83{
84	atf_check -s signal:11 -o "inline:" -e "inline:got 11\n" \
85		${HELPER} segv handle recurse
86}
87
88atf_test_case segv_ignore
89segv_ignore()
90{
91	atf_set "descr" "Test ignored SIGSEGV trap with right exit code"
92}
93
94segv_ignore_body()
95{
96	atf_check -s signal:11 -o "inline:" -e "inline:" \
97		${HELPER} segv ignore
98}
99
100atf_test_case trap_simple
101trap_simple()
102{
103	atf_set "descr" "Test unhandled SIGTRAP with the right exit code"
104}
105trap_simple_body()
106{
107	atf_check -s signal:5 -o "inline:" -e "inline:" \
108		${HELPER} trap recurse
109}
110
111atf_test_case trap_handle
112trap_handle()
113{
114	atf_set "descr" "Test handled SIGTRAP traps call the signal handler"
115}
116trap_handle_body()
117{
118	atf_check -s exit:0 -o "inline:" -e "inline:got 5\n" \
119		${HELPER} trap handle
120}
121
122atf_test_case trap_mask
123trap_mask()
124{
125	atf_set "descr" "Test that masking the trapped SIGTRAP signal get reset"
126}
127trap_mask_body()
128{
129	atf_check -s signal:5 -o "inline:" -e "inline:" \
130		${HELPER} trap mask
131}
132
133atf_test_case trap_handle_mask
134trap_handle_mask()
135{
136	atf_set "descr" "Test handled and masked SIGTRAP traps get reset"
137}
138trap_handle_mask_body()
139{
140	atf_check -s signal:5 -o "inline:" -e "inline:" \
141		${HELPER} trap mask handle
142}
143
144atf_test_case trap_handle_recurse
145trap_handle_recurse()
146{
147	atf_set "descr" "Test that receiving SIGTRAP in the handler resets"
148}
149
150trap_handle_recurse_body()
151{
152	atf_check -s signal:5 -o "inline:" -e "inline:got 5\n" \
153		${HELPER} trap handle recurse
154}
155
156atf_test_case trap_ignore
157trap_ignore()
158{
159	atf_set "descr" "Test ignored trap with right exit code"
160}
161
162trap_ignore_body()
163{
164	atf_check -s signal:5 -o "inline:" -e "inline:" \
165		${HELPER} trap ignore
166}
167
168atf_init_test_cases()
169{
170	atf_add_test_case segv_simple
171	atf_add_test_case segv_handle
172	atf_add_test_case segv_mask
173	atf_add_test_case segv_handle_recurse
174	atf_add_test_case segv_ignore
175
176	atf_add_test_case trap_simple
177	atf_add_test_case trap_handle
178	atf_add_test_case trap_mask
179	atf_add_test_case trap_handle_recurse
180	atf_add_test_case trap_ignore
181}
182