t_hello.sh revision 1.3.4.2 1 # $NetBSD: t_hello.sh,v 1.3.4.2 2025/08/02 05:58:03 perseant Exp $
2 #
3 # Copyright (c) 2025 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 checksupport()
29 {
30 local prog
31
32 prog=$1
33 test -f "$(atf_get_srcdir)/${prog}" || atf_skip "not supported"
34 }
35
36 checkrun()
37 {
38 local prog
39
40 prog=$1
41 atf_check -o inline:"${prog}: Hello, world! 42\n" \
42 "$(atf_get_srcdir)/${prog}"
43 }
44
45 cleanup()
46 {
47 local prog
48
49 prog=$1
50 test -f "${prog}.core" || return 0
51 readelf -rs "$(atf_get_srcdir)/${prog}"
52 gdb -batch -ex bt -ex 'info registers' -ex disas \
53 "$(atf_get_srcdir)/${prog}" "${prog}.core"
54 }
55
56 atf_test_case dynamic cleanup
57 dynamic_head()
58 {
59 atf_set "descr" "Test a dynamic executable"
60 }
61 dynamic_body()
62 {
63 checksupport h_hello_dyn
64 checkrun h_hello_dyn
65 }
66 dynamic_cleanup()
67 {
68 cleanup h_hello_dyn
69 }
70
71 atf_test_case dynamicpie cleanup
72 dynamicpie_head()
73 {
74 atf_set "descr" "Test a dynamic position-independent executable"
75 }
76 dynamicpie_body()
77 {
78 checksupport h_hello_dynpie
79 checkrun h_hello_dynpie
80 }
81 dynamicpie_cleanup()
82 {
83 cleanup h_hello_dynpie
84 }
85
86 atf_test_case relr cleanup
87 relr_head()
88 {
89 atf_set "descr" "Test a static PIE executable with RELR relocations"
90 }
91 relr_body()
92 {
93 checksupport h_hello_relr
94 case `uname -p` in
95 i386|x86_64)
96 ;;
97 *) atf_expect_fail "PR lib/59359: static pies are broken"
98 ;;
99 esac
100 checkrun h_hello_relr
101 }
102 relr_cleanup()
103 {
104 cleanup h_hello_relr
105 }
106
107 atf_test_case static cleanup
108 static_head()
109 {
110 atf_set "descr" "Test a static executable"
111 }
112 static_body()
113 {
114 checksupport h_hello_sta
115 checkrun h_hello_sta
116 }
117 static_cleanup()
118 {
119 cleanup h_hello_sta
120 }
121
122 atf_test_case staticpie cleanup
123 staticpie_head()
124 {
125 atf_set "descr" "Test a static position-independent executable"
126 }
127 staticpie_body()
128 {
129 checksupport h_hello_stapie
130 case `uname -p` in
131 i386|x86_64)
132 ;;
133 *) atf_expect_fail "PR lib/59359: static pies are broken"
134 ;;
135 esac
136 checkrun h_hello_stapie
137 }
138 staticpie_cleanup()
139 {
140 cleanup h_hello_stapie
141 }
142
143 atf_init_test_cases()
144 {
145 atf_add_test_case dynamic
146 atf_add_test_case dynamicpie
147 atf_add_test_case relr
148 atf_add_test_case static
149 atf_add_test_case staticpie
150 }
151