t_trapsignal.sh revision 1.2
11.2Skamil# $NetBSD: t_trapsignal.sh,v 1.2 2018/05/21 08:49:03 kamil Exp $
21.1Schristos#
31.1Schristos# Copyright (c) 2017 The NetBSD Foundation, Inc.
41.1Schristos# All rights reserved.
51.1Schristos#
61.1Schristos# This code is derived from software contributed to The NetBSD Foundation
71.1Schristos# by Christos Zoulas.
81.1Schristos#
91.1Schristos# Redistribution and use in source and binary forms, with or without
101.1Schristos# modification, are permitted provided that the following conditions
111.1Schristos# are met:
121.1Schristos# 1. Redistributions of source code must retain the above copyright
131.1Schristos#    notice, this list of conditions and the following disclaimer.
141.1Schristos# 2. Redistributions in binary form must reproduce the above copyright
151.1Schristos#    notice, this list of conditions and the following disclaimer in the
161.1Schristos#    documentation and/or other materials provided with the distribution.
171.1Schristos#
181.1Schristos# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.1Schristos# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Schristos# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Schristos# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Schristos# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Schristos# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Schristos# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Schristos# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Schristos# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Schristos# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Schristos# POSSIBILITY OF SUCH DAMAGE.
291.1Schristos#
301.1Schristos
311.1SchristosHELPER=$(atf_get_srcdir)/h_segv
321.1Schristosatf_test_case trap_simple
331.1Schristostrap_simple()
341.1Schristos{
351.1Schristos	atf_set "descr" "Test unhandled traps exit with the right exit code"
361.1Schristos}
371.1Schristostrap_simple_body()
381.1Schristos{
391.1Schristos	atf_check -s signal:11 -o "inline:" -e "inline:" \
401.1Schristos		${HELPER} recurse
411.1Schristos}
421.1Schristos
431.1Schristosatf_test_case trap_handle
441.1Schristostrap_handle()
451.1Schristos{
461.1Schristos	atf_set "descr" "Test handled traps call the signal handler"
471.1Schristos}
481.1Schristostrap_handle_body()
491.1Schristos{
501.1Schristos	atf_check -s exit:0 -o "inline:" -e "inline:got 11\n" \
511.1Schristos		${HELPER} handle
521.1Schristos}
531.1Schristos
541.1Schristosatf_test_case trap_mask
551.1Schristostrap_mask()
561.1Schristos{
571.1Schristos	atf_set "descr" "Test that masking the trapped signal get reset"
581.1Schristos}
591.1Schristostrap_mask_body()
601.1Schristos{
611.1Schristos	atf_check -s signal:11 -o "inline:" -e "inline:" \
621.1Schristos		${HELPER} mask
631.1Schristos}
641.1Schristos
651.1Schristosatf_test_case trap_handle_mask
661.1Schristostrap_handle_mask()
671.1Schristos{
681.1Schristos	atf_set "descr" "Test handled and masked traps get reset"
691.1Schristos}
701.1Schristostrap_handle_mask_body()
711.1Schristos{
721.1Schristos	atf_check -s signal:11 -o "inline:" -e "inline:" \
731.1Schristos		${HELPER} mask handle
741.1Schristos}
751.1Schristos
761.1Schristosatf_test_case trap_handle_recurse
771.1Schristostrap_handle_recurse()
781.1Schristos{
791.1Schristos	atf_set "descr" "Test that receiving the trap in the handler resets"
801.1Schristos}
811.1Schristos
821.1Schristostrap_handle_recurse_body()
831.1Schristos{
841.1Schristos	atf_check -s signal:11 -o "inline:" -e "inline:got 11\n" \
851.1Schristos		${HELPER} handle recurse
861.1Schristos}
871.1Schristos
881.2Skamilatf_test_case trap_ignore
891.2Skamiltrap_ignore()
901.2Skamil{
911.2Skamil	atf_set "descr" "Test ignored trap with right exit code"
921.2Skamil}
931.2Skamil
941.2Skamiltrap_ignore_body()
951.2Skamil{
961.2Skamil	atf_check -s signal:11 -o "inline:" -e "inline:" \
971.2Skamil		${HELPER} ignore
981.2Skamil}
991.2Skamil
1001.1Schristosatf_init_test_cases()
1011.1Schristos{
1021.1Schristos	atf_add_test_case trap_simple
1031.1Schristos	atf_add_test_case trap_handle
1041.1Schristos	atf_add_test_case trap_mask
1051.1Schristos	atf_add_test_case trap_handle_recurse
1061.2Skamil	atf_add_test_case trap_ignore
1071.1Schristos}
108