xref: /netbsd-src/tests/kernel/t_trapsignal.sh (revision c38e7cc395b1472a774ff828e46123de44c628e9)
1# $NetBSD: t_trapsignal.sh,v 1.1 2017/12/07 19:46:40 christos 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 trap_simple
33trap_simple()
34{
35	atf_set "descr" "Test unhandled traps exit with the right exit code"
36}
37trap_simple_body()
38{
39	atf_check -s signal:11 -o "inline:" -e "inline:" \
40		${HELPER} recurse
41}
42
43atf_test_case trap_handle
44trap_handle()
45{
46	atf_set "descr" "Test handled traps call the signal handler"
47}
48trap_handle_body()
49{
50	atf_check -s exit:0 -o "inline:" -e "inline:got 11\n" \
51		${HELPER} handle
52}
53
54atf_test_case trap_mask
55trap_mask()
56{
57	atf_set "descr" "Test that masking the trapped signal get reset"
58}
59trap_mask_body()
60{
61	atf_check -s signal:11 -o "inline:" -e "inline:" \
62		${HELPER} mask
63}
64
65atf_test_case trap_handle_mask
66trap_handle_mask()
67{
68	atf_set "descr" "Test handled and masked traps get reset"
69}
70trap_handle_mask_body()
71{
72	atf_check -s signal:11 -o "inline:" -e "inline:" \
73		${HELPER} mask handle
74}
75
76atf_test_case trap_handle_recurse
77trap_handle_recurse()
78{
79	atf_set "descr" "Test that receiving the trap in the handler resets"
80}
81
82trap_handle_recurse_body()
83{
84	atf_check -s signal:11 -o "inline:" -e "inline:got 11\n" \
85		${HELPER} handle recurse
86}
87
88atf_init_test_cases()
89{
90	atf_add_test_case trap_simple
91	atf_add_test_case trap_handle
92	atf_add_test_case trap_mask
93	atf_add_test_case trap_handle_recurse
94}
95