t_trapsignal.sh revision 1.4
1# $NetBSD: t_trapsignal.sh,v 1.4 2018/05/27 17:04:45 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 32 33# SIGSEGV 34 35atf_test_case segv_simple 36segv_simple() 37{ 38 atf_set "descr" "Test unhandled SIGSEGV with the right exit code" 39} 40segv_simple_body() 41{ 42 atf_check -s signal:11 -o "inline:" -e "inline:" \ 43 ${HELPER} segv recurse 44} 45 46atf_test_case segv_handle 47segv_handle() 48{ 49 atf_set "descr" "Test handled SIGSEGV traps call the signal handler" 50} 51segv_handle_body() 52{ 53 atf_check -s exit:0 -o "inline:" -e "inline:got 11\n" \ 54 ${HELPER} segv handle 55} 56 57atf_test_case segv_mask 58segv_mask() 59{ 60 atf_set "descr" "Test that masking SIGSEGV get reset" 61} 62segv_mask_body() 63{ 64 atf_check -s signal:11 -o "inline:" -e "inline:" \ 65 ${HELPER} segv mask 66} 67 68atf_test_case segv_handle_mask 69segv_handle_mask() 70{ 71 atf_set "descr" "Test handled and masked SIGSEGV traps get reset" 72} 73segv_handle_mask_body() 74{ 75 atf_check -s signal:11 -o "inline:" -e "inline:" \ 76 ${HELPER} segv mask handle 77} 78 79atf_test_case segv_handle_recurse 80segv_handle_recurse() 81{ 82 atf_set "descr" "Test that receiving SIGSEGV in the handler resets" 83} 84 85segv_handle_recurse_body() 86{ 87 atf_check -s signal:11 -o "inline:" -e "inline:got 11\n" \ 88 ${HELPER} segv handle recurse 89} 90 91atf_test_case segv_ignore 92segv_ignore() 93{ 94 atf_set "descr" "Test ignored SIGSEGV trap with right exit code" 95} 96 97segv_ignore_body() 98{ 99 atf_check -s signal:11 -o "inline:" -e "inline:" \ 100 ${HELPER} segv ignore 101} 102 103# SIGTRAP 104 105atf_test_case trap_simple 106trap_simple() 107{ 108 atf_set "descr" "Test unhandled SIGTRAP with the right exit code" 109} 110trap_simple_body() 111{ 112 atf_check -s signal:5 -o "inline:" -e "inline:" \ 113 ${HELPER} trap recurse 114} 115 116atf_test_case trap_handle 117trap_handle() 118{ 119 atf_set "descr" "Test handled SIGTRAP traps call the signal handler" 120} 121trap_handle_body() 122{ 123 atf_check -s exit:0 -o "inline:" -e "inline:got 5\n" \ 124 ${HELPER} trap handle 125} 126 127atf_test_case trap_mask 128trap_mask() 129{ 130 atf_set "descr" "Test that masking the trapped SIGTRAP signal get reset" 131} 132trap_mask_body() 133{ 134 atf_check -s signal:5 -o "inline:" -e "inline:" \ 135 ${HELPER} trap mask 136} 137 138atf_test_case trap_handle_mask 139trap_handle_mask() 140{ 141 atf_set "descr" "Test handled and masked SIGTRAP traps get reset" 142} 143trap_handle_mask_body() 144{ 145 atf_check -s signal:5 -o "inline:" -e "inline:" \ 146 ${HELPER} trap mask handle 147} 148 149atf_test_case trap_handle_recurse 150trap_handle_recurse() 151{ 152 atf_set "descr" "Test that receiving SIGTRAP in the handler resets" 153} 154 155trap_handle_recurse_body() 156{ 157 atf_check -s signal:5 -o "inline:" -e "inline:got 5\n" \ 158 ${HELPER} trap handle recurse 159} 160 161atf_test_case trap_ignore 162trap_ignore() 163{ 164 atf_set "descr" "Test ignored trap with right exit code" 165} 166 167trap_ignore_body() 168{ 169 atf_check -s signal:5 -o "inline:" -e "inline:" \ 170 ${HELPER} trap ignore 171} 172 173# SIGFPE 174 175atf_test_case fpe_simple 176fpe_simple() 177{ 178 atf_set "descr" "Test unhandled SIGFPE with the right exit code" 179} 180fpe_simple_body() 181{ 182 atf_check -s signal:8 -o "inline:" -e "inline:" \ 183 ${HELPER} fpe recurse 184} 185 186atf_test_case fpe_handle 187fpe_handle() 188{ 189 atf_set "descr" "Test handled SIGFPE traps call the signal handler" 190} 191fpe_handle_body() 192{ 193 atf_check -s exit:0 -o "inline:" -e "inline:got 8\n" \ 194 ${HELPER} fpe handle 195} 196 197atf_test_case fpe_mask 198fpe_mask() 199{ 200 atf_set "descr" "Test that masking the trapped SIGFPE signal get reset" 201} 202fpe_mask_body() 203{ 204 atf_check -s signal:8 -o "inline:" -e "inline:" \ 205 ${HELPER} fpe mask 206} 207 208atf_test_case fpe_handle_mask 209fpe_handle_mask() 210{ 211 atf_set "descr" "Test handled and masked SIGFPE traps get reset" 212} 213fpe_handle_mask_body() 214{ 215 atf_check -s signal:8 -o "inline:" -e "inline:" \ 216 ${HELPER} fpe mask handle 217} 218 219atf_test_case fpe_handle_recurse 220fpe_handle_recurse() 221{ 222 atf_set "descr" "Test that receiving SIGFPE in the handler resets" 223} 224 225fpe_handle_recurse_body() 226{ 227 atf_check -s signal:8 -o "inline:" -e "inline:got 8\n" \ 228 ${HELPER} fpe handle recurse 229} 230 231atf_test_case fpe_ignore 232fpe_ignore() 233{ 234 atf_set "descr" "Test ignored trap with right exit code" 235} 236 237fpe_ignore_body() 238{ 239 atf_check -s signal:8 -o "inline:" -e "inline:" \ 240 ${HELPER} fpe ignore 241} 242 243# SIGBUS 244 245atf_test_case bus_simple 246bus_simple() 247{ 248 atf_set "descr" "Test unhandled SIGBUS with the right exit code" 249} 250bus_simple_body() 251{ 252 atf_check -s signal:10 -o "inline:" -e "inline:" \ 253 ${HELPER} bus recurse 254} 255 256atf_test_case bus_handle 257bus_handle() 258{ 259 atf_set "descr" "Test handled SIGBUS traps call the signal handler" 260} 261bus_handle_body() 262{ 263 atf_check -s exit:0 -o "inline:" -e "inline:got 10\n" \ 264 ${HELPER} bus handle 265} 266 267atf_test_case bus_mask 268bus_mask() 269{ 270 atf_set "descr" "Test that masking the trapped SIGBUS signal get reset" 271} 272bus_mask_body() 273{ 274 atf_check -s signal:10 -o "inline:" -e "inline:" \ 275 ${HELPER} bus mask 276} 277 278atf_test_case bus_handle_mask 279bus_handle_mask() 280{ 281 atf_set "descr" "Test handled and masked SIGBUS traps get reset" 282} 283bus_handle_mask_body() 284{ 285 atf_check -s signal:10 -o "inline:" -e "inline:" \ 286 ${HELPER} bus mask handle 287} 288 289atf_test_case bus_handle_recurse 290bus_handle_recurse() 291{ 292 atf_set "descr" "Test that receiving SIGBUS in the handler resets" 293} 294 295bus_handle_recurse_body() 296{ 297 atf_check -s signal:10 -o "inline:" -e "inline:got 10\n" \ 298 ${HELPER} bus handle recurse 299} 300 301atf_test_case bus_ignore 302bus_ignore() 303{ 304 atf_set "descr" "Test ignored trap with right exit code" 305} 306 307bus_ignore_body() 308{ 309 atf_check -s signal:10 -o "inline:" -e "inline:" \ 310 ${HELPER} bus ignore 311} 312 313atf_init_test_cases() 314{ 315 atf_add_test_case segv_simple 316 atf_add_test_case segv_handle 317 atf_add_test_case segv_mask 318 atf_add_test_case segv_handle_recurse 319 atf_add_test_case segv_ignore 320 321 atf_add_test_case trap_simple 322 atf_add_test_case trap_handle 323 atf_add_test_case trap_mask 324 atf_add_test_case trap_handle_recurse 325 atf_add_test_case trap_ignore 326 327# atf_add_test_case ill_simple 328# atf_add_test_case ill_handle 329# atf_add_test_case ill_mask 330# atf_add_test_case ill_handle_recurse 331# atf_add_test_case ill_ignore 332 333 atf_add_test_case fpe_simple 334 atf_add_test_case fpe_handle 335 atf_add_test_case fpe_mask 336 atf_add_test_case fpe_handle_recurse 337 atf_add_test_case fpe_ignore 338 339 atf_add_test_case bus_simple 340 atf_add_test_case bus_handle 341 atf_add_test_case bus_mask 342 atf_add_test_case bus_handle_recurse 343 atf_add_test_case bus_ignore 344} 345