xref: /freebsd/contrib/netbsd-tests/lib/libc/ssp/t_ssp.sh (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1# $NetBSD: t_ssp.sh,v 1.7 2014/04/06 19:28:59 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
28h_pass()
29{
30	echo "Executing command [ $2$1 ]"
31	eval $2 atf_check -s exit:0 -o ignore -e ignore $1
32}
33
34h_fail()
35{
36	echo "Executing command [ $2$1 ]"
37	# Begin FreeBSD
38	if true; then
39		eval $2 atf_check -s signal -o ignore -e ignore $1
40	else
41	# End FreeBSD
42	eval $2 atf_check -s signal:6 -o ignore -e ignore $1
43	# Begin FreeBSD
44	fi
45	# End FreeBSD
46}
47
48atf_test_case sprintf
49sprintf_head()
50{
51	atf_set "descr" "Checks sprintf(3)"
52}
53sprintf_body()
54{
55	prog="$(atf_get_srcdir)/h_sprintf"
56
57	h_pass "$prog ok"
58	# Begin FreeBSD
59	if true; then
60		h_fail "$prog 0123456789ab"
61	else
62	# End FreeBSD
63	h_fail "$prog 0123456789"
64	# Begin FreeBSD
65	fi
66	# End FreeBSD
67}
68
69atf_test_case vsprintf
70vsprintf_head()
71{
72	atf_set "descr" "Checks vsprintf(3)"
73}
74vsprintf_body()
75{
76	prog="$(atf_get_srcdir)/h_vsprintf"
77
78	h_pass "$prog ok"
79	# Begin FreeBSD
80	if true; then
81		h_fail "$prog 0123456789ab"
82	else
83	# End FreeBSD
84	h_fail "$prog 0123456789"
85	# Begin FreeBSD
86	fi
87	# End FreeBSD
88}
89
90atf_test_case snprintf
91snprintf_head()
92{
93	atf_set "descr" "Checks snprintf(3)"
94}
95snprintf_body()
96{
97	prog="$(atf_get_srcdir)/h_snprintf"
98
99	h_pass "$prog 10"
100	# Begin FreeBSD
101	if true; then
102		h_fail "$prog 13"
103	else
104	# End FreeBSD
105	h_fail "$prog 11"
106	# Begin FreeBSD
107	fi
108	# End FreeBSD
109}
110
111atf_test_case vsnprintf
112vsnprintf_head()
113{
114	atf_set "descr" "Checks vsnprintf(3)"
115}
116vsnprintf_body()
117{
118	prog="$(atf_get_srcdir)/h_vsnprintf"
119
120	h_pass "$prog 10"
121	# Begin FreeBSD
122	if true; then
123		h_fail "$prog 13"
124	else
125	# End FreeBSD
126	h_fail "$prog 11"
127	# Begin FreeBSD
128	fi
129	# End FreeBSD
130}
131
132atf_test_case gets
133gets_head()
134{
135	atf_set "descr" "Checks gets(3)"
136}
137gets_body()
138{
139	prog="$(atf_get_srcdir)/h_gets"
140
141	h_pass "$prog" "echo ok |"
142	# Begin FreeBSD
143	if true; then
144		h_fail "$prog" "echo 0123456789ab |"
145	else
146	# End FreeBSD
147	h_fail "$prog" "echo 0123456789 |"
148	# Begin FreeBSD
149	fi
150	# End FreeBSD
151}
152
153atf_test_case fgets
154fgets_head()
155{
156	atf_set "descr" "Checks fgets(3)"
157}
158fgets_body()
159{
160	prog="$(atf_get_srcdir)/h_fgets"
161
162	h_pass "$prog 10" "echo ok |"
163	# Begin FreeBSD
164	if true; then
165		h_fail "$prog 13" "echo 0123456789abc |"
166	else
167	# End FreeBSD
168	h_fail "$prog 11" "echo busted |"
169	# Begin FreeBSD
170	fi
171	# End FreeBSD
172}
173
174atf_test_case memcpy
175memcpy_head()
176{
177	atf_set "descr" "Checks memcpy(3)"
178}
179memcpy_body()
180{
181	prog="$(atf_get_srcdir)/h_memcpy"
182
183	h_pass "$prog 10"
184	# Begin FreeBSD
185	if true; then
186		h_fail "$prog 13"
187	else
188	# End FreeBSD
189	h_fail "$prog 11"
190	# Begin FreeBSD
191	fi
192	# End FreeBSD
193}
194
195atf_test_case memmove
196memmove_head()
197{
198	atf_set "descr" "Checks memmove(3)"
199}
200memmove_body()
201{
202	prog="$(atf_get_srcdir)/h_memmove"
203
204	h_pass "$prog 10"
205	# Begin FreeBSD
206	if true; then
207		h_fail "$prog 13"
208	else
209	# End FreeBSD
210	h_fail "$prog 11"
211	# Begin FreeBSD
212	fi
213	# End FreeBSD
214}
215
216atf_test_case memset
217memset_head()
218{
219	atf_set "descr" "Checks memset(3)"
220}
221memset_body()
222{
223	prog="$(atf_get_srcdir)/h_memset"
224
225	h_pass "$prog 10"
226	# Begin FreeBSD
227	if true; then
228		h_fail "$prog 13"
229	else
230	# End FreeBSD
231	h_fail "$prog 11"
232	# Begin FreeBSD
233	fi
234	# End FreeBSD
235}
236
237atf_test_case strcpy
238strcpy_head()
239{
240	atf_set "descr" "Checks strcpy(3)"
241}
242strcpy_body()
243{
244	prog="$(atf_get_srcdir)/h_strcpy"
245
246	h_pass "$prog 0123456"
247	# Begin FreeBSD
248	if true; then
249		h_fail "$prog 0123456789ab"
250	else
251	# End FreeBSD
252	h_fail "$prog 0123456789"
253	# Begin FreeBSD
254	fi
255	# End FreeBSD
256}
257
258atf_test_case stpcpy
259stpcpy_head()
260{
261	atf_set "descr" "Checks stpcpy(3)"
262}
263stpcpy_body()
264{
265	prog="$(atf_get_srcdir)/h_stpcpy"
266
267	h_pass "$prog 0123456"
268	# Begin FreeBSD
269	if true; then
270		h_fail "$prog 0123456789ab"
271	else
272	# End FreeBSD
273	h_fail "$prog 0123456789"
274	# Begin FreeBSD
275	fi
276	# End FreeBSD
277}
278
279atf_test_case strcat
280strcat_head()
281{
282	atf_set "descr" "Checks strcat(3)"
283}
284strcat_body()
285{
286	prog="$(atf_get_srcdir)/h_strcat"
287
288	h_pass "$prog 0123456"
289	h_fail "$prog 0123456789ABCDEF"
290}
291
292atf_test_case strncpy
293strncpy_head()
294{
295	atf_set "descr" "Checks strncpy(3)"
296}
297strncpy_body()
298{
299	prog="$(atf_get_srcdir)/h_strncpy"
300
301	h_pass "$prog 10"
302	# Begin FreeBSD
303	if true; then
304		h_fail "$prog 13"
305	else
306	# End FreeBSD
307	h_fail "$prog 11"
308	# Begin FreeBSD
309	fi
310	# End FreeBSD
311}
312
313atf_test_case stpncpy
314stpncpy_head()
315{
316	atf_set "descr" "Checks stpncpy(3)"
317}
318stpncpy_body()
319{
320	prog="$(atf_get_srcdir)/h_stpncpy"
321
322	h_pass "$prog 10"
323	# Begin FreeBSD
324	if true; then
325		h_fail "$prog 13"
326	else
327	# End FreeBSD
328	h_fail "$prog 11"
329	# Begin FreeBSD
330	fi
331	# End FreeBSD
332}
333
334atf_test_case strncat
335strncat_head()
336{
337	atf_set "descr" "Checks strncat(3)"
338}
339strncat_body()
340{
341	prog="$(atf_get_srcdir)/h_strncat"
342
343	# Begin FreeBSD
344	h_pass "$prog 8"
345	if true; then
346		h_fail "$prog 11"
347	else
348	# End FreeBSD
349	h_fail "$prog 9"
350	# Begin FreeBSD
351	fi
352	# End FreeBSD
353}
354
355atf_test_case raw
356raw_head()
357{
358	atf_set "descr" "Checks raw array overflow"
359}
360raw_body()
361{
362	prog="$(atf_get_srcdir)/h_raw"
363	# Begin FreeBSD
364	[ -x $prog ] || atf_skip "$prog is missing; skipping testcase"
365	# End FreeBSD
366
367	h_pass "$prog 9"
368	# Begin FreeBSD
369	if true; then
370		h_fail "$prog 12"
371	else
372	# End FreeBSD
373	h_fail "$prog 10"
374	# Begin FreeBSD
375	fi
376	# End FreeBSD
377}
378
379atf_test_case read
380read_head()
381{
382	atf_set "descr" "Checks read(2)"
383}
384read_body()
385{
386	prog="$(atf_get_srcdir)/h_read"
387
388	h_pass "$prog 1024" "echo foo |"
389	# Begin FreeBSD
390	if true; then
391		h_fail "$prog 1027" "echo bar |"
392	else
393	# End FreeBSD
394	h_fail "$prog 1025" "echo bar |"
395	# Begin FreeBSD
396	fi
397	# End FreeBSD
398}
399
400atf_test_case readlink
401readlink_head()
402{
403	atf_set "descr" "Checks readlink(2)"
404}
405readlink_body()
406{
407	prog="$(atf_get_srcdir)/h_readlink"
408
409	# Begin FreeBSD
410	if true; then
411		h_pass "$prog 512"
412		h_fail "$prog 523"
413	else
414	# End FreeBSD
415	h_pass "$prog 1024"
416	h_fail "$prog 1025"
417	# Begin FreeBSD
418	fi
419	# End FreeBSD
420}
421
422atf_test_case getcwd
423getcwd_head()
424{
425	atf_set "descr" "Checks getcwd(3)"
426}
427getcwd_body()
428{
429	prog="$(atf_get_srcdir)/h_getcwd"
430
431	h_pass "$prog 1024"
432	# Begin FreeBSD
433	if false; then
434	# End FreeBSD
435	h_fail "$prog 1025"
436	# Begin FreeBSD
437	fi
438	# End FreeBSD
439}
440
441atf_init_test_cases()
442{
443	atf_add_test_case sprintf
444	atf_add_test_case vsprintf
445	atf_add_test_case snprintf
446	atf_add_test_case vsnprintf
447	atf_add_test_case gets
448	atf_add_test_case fgets
449	atf_add_test_case memcpy
450	atf_add_test_case memmove
451	atf_add_test_case memset
452	atf_add_test_case stpcpy
453	atf_add_test_case stpncpy
454	atf_add_test_case strcat
455	atf_add_test_case strcpy
456	atf_add_test_case strncat
457	atf_add_test_case strncpy
458	atf_add_test_case raw
459	atf_add_test_case read
460	atf_add_test_case readlink
461	atf_add_test_case getcwd
462}
463