t_ssp.sh revision 1.8 1 # $NetBSD: t_ssp.sh,v 1.8 2023/11/10 23:03:25 christos Exp $
2 #
3 # Copyright (c) 2008 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 h_pass()
29 {
30 echo "Executing command [ $2$1 ]"
31 eval $2 atf_check -s exit:0 -o ignore -e ignore $1
32 }
33
34 h_fail()
35 {
36 echo "Executing command [ $2$1 ]"
37 eval $2 atf_check -s signal:6 -o ignore -e ignore $1
38 }
39
40 atf_test_case sprintf
41 sprintf_head()
42 {
43 atf_set "descr" "Checks sprintf(3)"
44 }
45 sprintf_body()
46 {
47 prog="$(atf_get_srcdir)/h_sprintf"
48
49 h_pass "$prog ok"
50 h_fail "$prog 0123456789"
51 }
52
53 atf_test_case vsprintf
54 vsprintf_head()
55 {
56 atf_set "descr" "Checks vsprintf(3)"
57 }
58 vsprintf_body()
59 {
60 prog="$(atf_get_srcdir)/h_vsprintf"
61
62 h_pass "$prog ok"
63 h_fail "$prog 0123456789"
64 }
65
66 atf_test_case snprintf
67 snprintf_head()
68 {
69 atf_set "descr" "Checks snprintf(3)"
70 }
71 snprintf_body()
72 {
73 prog="$(atf_get_srcdir)/h_snprintf"
74
75 h_pass "$prog 10"
76 h_fail "$prog 11"
77 }
78
79 atf_test_case vsnprintf
80 vsnprintf_head()
81 {
82 atf_set "descr" "Checks vsnprintf(3)"
83 }
84 vsnprintf_body()
85 {
86 prog="$(atf_get_srcdir)/h_vsnprintf"
87
88 h_pass "$prog 10"
89 h_fail "$prog 11"
90 }
91
92 atf_test_case gets
93 gets_head()
94 {
95 atf_set "descr" "Checks gets(3)"
96 }
97 gets_body()
98 {
99 prog="$(atf_get_srcdir)/h_gets"
100
101 h_pass "$prog" "echo ok |"
102 h_fail "$prog" "echo 0123456789 |"
103 }
104
105 atf_test_case fgets
106 fgets_head()
107 {
108 atf_set "descr" "Checks fgets(3)"
109 }
110 fgets_body()
111 {
112 prog="$(atf_get_srcdir)/h_fgets"
113
114 h_pass "$prog 10" "echo ok |"
115 h_fail "$prog 11" "echo busted |"
116 }
117
118 atf_test_case memcpy
119 memcpy_head()
120 {
121 atf_set "descr" "Checks memcpy(3)"
122 }
123 memcpy_body()
124 {
125 prog="$(atf_get_srcdir)/h_memcpy"
126
127 h_pass "$prog 10"
128 h_fail "$prog 11"
129 }
130
131 atf_test_case memmove
132 memmove_head()
133 {
134 atf_set "descr" "Checks memmove(3)"
135 }
136 memmove_body()
137 {
138 prog="$(atf_get_srcdir)/h_memmove"
139
140 h_pass "$prog 10"
141 h_fail "$prog 11"
142 }
143
144 atf_test_case memset
145 memset_head()
146 {
147 atf_set "descr" "Checks memset(3)"
148 }
149 memset_body()
150 {
151 prog="$(atf_get_srcdir)/h_memset"
152
153 h_pass "$prog 10"
154 h_fail "$prog 11"
155 }
156
157 atf_test_case strcpy
158 strcpy_head()
159 {
160 atf_set "descr" "Checks strcpy(3)"
161 }
162 strcpy_body()
163 {
164 prog="$(atf_get_srcdir)/h_strcpy"
165
166 h_pass "$prog 0123456"
167 h_fail "$prog 0123456789"
168 }
169
170 atf_test_case stpcpy
171 stpcpy_head()
172 {
173 atf_set "descr" "Checks stpcpy(3)"
174 }
175 stpcpy_body()
176 {
177 prog="$(atf_get_srcdir)/h_stpcpy"
178
179 h_pass "$prog 0123456"
180 h_fail "$prog 0123456789"
181 }
182
183 atf_test_case strcat
184 strcat_head()
185 {
186 atf_set "descr" "Checks strcat(3)"
187 }
188 strcat_body()
189 {
190 prog="$(atf_get_srcdir)/h_strcat"
191
192 h_pass "$prog 0123456"
193 h_fail "$prog 0123456789ABCDEF"
194 }
195
196 atf_test_case strncpy
197 strncpy_head()
198 {
199 atf_set "descr" "Checks strncpy(3)"
200 }
201 strncpy_body()
202 {
203 prog="$(atf_get_srcdir)/h_strncpy"
204
205 h_pass "$prog 10"
206 h_fail "$prog 11"
207 }
208
209 atf_test_case stpncpy
210 stpncpy_head()
211 {
212 atf_set "descr" "Checks stpncpy(3)"
213 }
214 stpncpy_body()
215 {
216 prog="$(atf_get_srcdir)/h_stpncpy"
217
218 h_pass "$prog 10"
219 h_fail "$prog 11"
220 }
221
222 atf_test_case strncat
223 strncat_head()
224 {
225 atf_set "descr" "Checks strncat(3)"
226 }
227 strncat_body()
228 {
229 prog="$(atf_get_srcdir)/h_strncat"
230
231 h_pass "$prog 8"
232 h_fail "$prog 9"
233 }
234
235 atf_test_case raw
236 raw_head()
237 {
238 atf_set "descr" "Checks raw array overflow"
239 }
240 raw_body()
241 {
242 prog="$(atf_get_srcdir)/h_raw"
243
244 h_pass "$prog 9"
245 h_fail "$prog 10"
246 }
247
248 atf_test_case read
249 read_head()
250 {
251 atf_set "descr" "Checks read(2)"
252 }
253 read_body()
254 {
255 prog="$(atf_get_srcdir)/h_read"
256
257 h_pass "$prog 1024" "echo foo |"
258 h_fail "$prog 1025" "echo bar |"
259 }
260
261 atf_test_case readlink
262 readlink_head()
263 {
264 atf_set "descr" "Checks readlink(2)"
265 }
266 readlink_body()
267 {
268 prog="$(atf_get_srcdir)/h_readlink"
269
270 h_pass "$prog 1024"
271 h_fail "$prog 1025"
272 }
273
274 atf_test_case getcwd
275 getcwd_head()
276 {
277 atf_set "descr" "Checks getcwd(3)"
278 }
279 getcwd_body()
280 {
281 prog="$(atf_get_srcdir)/h_getcwd"
282
283 h_pass "$prog 1024"
284 h_fail "$prog 1025"
285 }
286
287 atf_test_case getcwd2
288 getcwd2_head()
289 {
290 atf_set "descr" "Checks getcwd(3) override"
291 }
292 getcwd2_body()
293 {
294 prog="$(atf_get_srcdir)/h_getcwd2"
295
296 atf_check -s exit:1 -o ignore \
297 -e 'match:.*getcwd failed: Function not implemented$' $prog
298 }
299
300 atf_init_test_cases()
301 {
302 atf_add_test_case sprintf
303 atf_add_test_case vsprintf
304 atf_add_test_case snprintf
305 atf_add_test_case vsnprintf
306 atf_add_test_case gets
307 atf_add_test_case fgets
308 atf_add_test_case memcpy
309 atf_add_test_case memmove
310 atf_add_test_case memset
311 atf_add_test_case stpcpy
312 atf_add_test_case stpncpy
313 atf_add_test_case strcat
314 atf_add_test_case strcpy
315 atf_add_test_case strncat
316 atf_add_test_case strncpy
317 atf_add_test_case raw
318 atf_add_test_case read
319 atf_add_test_case readlink
320 atf_add_test_case getcwd
321 atf_add_test_case getcwd2
322 }
323