xref: /freebsd/usr.bin/hexdump/tests/hexdump_test.sh (revision b5ddde39acbf9f991ae5be15507dbfb6a4472b15)
1*b5ddde39SKyle Evans#
2*b5ddde39SKyle Evans# Copyright (c) 2017 Kyle Evans <kevans@FreeBSD.org>
3*b5ddde39SKyle Evans# All rights reserved.
4*b5ddde39SKyle Evans#
5*b5ddde39SKyle Evans# Redistribution and use in source and binary forms, with or without
6*b5ddde39SKyle Evans# modification, are permitted provided that the following conditions
7*b5ddde39SKyle Evans# are met:
8*b5ddde39SKyle Evans# 1. Redistributions of source code must retain the above copyright
9*b5ddde39SKyle Evans#    notice, this list of conditions and the following disclaimer.
10*b5ddde39SKyle Evans# 2. Redistributions in binary form must reproduce the above copyright
11*b5ddde39SKyle Evans#    notice, this list of conditions and the following disclaimer in the
12*b5ddde39SKyle Evans#    documentation and/or other materials provided with the distribution.
13*b5ddde39SKyle Evans#
14*b5ddde39SKyle Evans# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*b5ddde39SKyle Evans# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*b5ddde39SKyle Evans# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*b5ddde39SKyle Evans# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*b5ddde39SKyle Evans# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*b5ddde39SKyle Evans# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*b5ddde39SKyle Evans# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*b5ddde39SKyle Evans# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*b5ddde39SKyle Evans# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*b5ddde39SKyle Evans# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*b5ddde39SKyle Evans# SUCH DAMAGE.
25*b5ddde39SKyle Evans#
26*b5ddde39SKyle Evans# $FreeBSD$
27*b5ddde39SKyle Evans
28*b5ddde39SKyle Evansatf_test_case b_flag
29*b5ddde39SKyle Evansb_flag_head()
30*b5ddde39SKyle Evans{
31*b5ddde39SKyle Evans	atf_set "descr" "Verify -b output"
32*b5ddde39SKyle Evans}
33*b5ddde39SKyle Evansb_flag_body()
34*b5ddde39SKyle Evans{
35*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_a.out" \
36*b5ddde39SKyle Evans	    hexdump -b "$(atf_get_srcdir)/d_hexdump_a.in"
37*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_b.out" \
38*b5ddde39SKyle Evans	    hexdump -b "$(atf_get_srcdir)/d_hexdump_b.in"
39*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_c.out" \
40*b5ddde39SKyle Evans	    hexdump -b "$(atf_get_srcdir)/d_hexdump_c.in"
41*b5ddde39SKyle Evans}
42*b5ddde39SKyle Evans
43*b5ddde39SKyle Evansatf_test_case c_flag
44*b5ddde39SKyle Evansc_flag_head()
45*b5ddde39SKyle Evans{
46*b5ddde39SKyle Evans	atf_set "descr" "Verify -c output"
47*b5ddde39SKyle Evans}
48*b5ddde39SKyle Evansc_flag_body()
49*b5ddde39SKyle Evans{
50*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_a.out" \
51*b5ddde39SKyle Evans	    hexdump -c "$(atf_get_srcdir)/d_hexdump_a.in"
52*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_b.out" \
53*b5ddde39SKyle Evans	    hexdump -c "$(atf_get_srcdir)/d_hexdump_b.in"
54*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_c.out" \
55*b5ddde39SKyle Evans	    hexdump -c "$(atf_get_srcdir)/d_hexdump_c.in"
56*b5ddde39SKyle Evans}
57*b5ddde39SKyle Evans
58*b5ddde39SKyle Evansatf_test_case C_flag
59*b5ddde39SKyle EvansC_flag_head()
60*b5ddde39SKyle Evans{
61*b5ddde39SKyle Evans	atf_set "descr" "Verify -C output"
62*b5ddde39SKyle Evans}
63*b5ddde39SKyle EvansC_flag_body()
64*b5ddde39SKyle Evans{
65*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \
66*b5ddde39SKyle Evans	    hexdump -C "$(atf_get_srcdir)/d_hexdump_a.in"
67*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \
68*b5ddde39SKyle Evans	    hexdump -C "$(atf_get_srcdir)/d_hexdump_b.in"
69*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
70*b5ddde39SKyle Evans	    hexdump -C "$(atf_get_srcdir)/d_hexdump_c.in"
71*b5ddde39SKyle Evans}
72*b5ddde39SKyle Evans
73*b5ddde39SKyle Evansatf_test_case hd_name
74*b5ddde39SKyle Evanshd_name_head()
75*b5ddde39SKyle Evans{
76*b5ddde39SKyle Evans	atf_set "descr" "Verify hd output matching -C output"
77*b5ddde39SKyle Evans}
78*b5ddde39SKyle Evanshd_name_body()
79*b5ddde39SKyle Evans{
80*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \
81*b5ddde39SKyle Evans	    hd "$(atf_get_srcdir)/d_hexdump_a.in"
82*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \
83*b5ddde39SKyle Evans	    hd "$(atf_get_srcdir)/d_hexdump_b.in"
84*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
85*b5ddde39SKyle Evans	    hd "$(atf_get_srcdir)/d_hexdump_c.in"
86*b5ddde39SKyle Evans}
87*b5ddde39SKyle Evans
88*b5ddde39SKyle Evansatf_test_case d_flag
89*b5ddde39SKyle Evansd_flag_head()
90*b5ddde39SKyle Evans{
91*b5ddde39SKyle Evans	atf_set "descr" "Verify -d output"
92*b5ddde39SKyle Evans}
93*b5ddde39SKyle Evansd_flag_body()
94*b5ddde39SKyle Evans{
95*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_a.out" \
96*b5ddde39SKyle Evans	    hexdump -d "$(atf_get_srcdir)/d_hexdump_a.in"
97*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_b.out" \
98*b5ddde39SKyle Evans	    hexdump -d "$(atf_get_srcdir)/d_hexdump_b.in"
99*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_c.out" \
100*b5ddde39SKyle Evans	    hexdump -d "$(atf_get_srcdir)/d_hexdump_c.in"
101*b5ddde39SKyle Evans}
102*b5ddde39SKyle Evans
103*b5ddde39SKyle Evansatf_test_case n_flag
104*b5ddde39SKyle Evansn_flag_head()
105*b5ddde39SKyle Evans{
106*b5ddde39SKyle Evans	atf_set "descr" "Check -n functionality"
107*b5ddde39SKyle Evans}
108*b5ddde39SKyle Evansn_flag_body()
109*b5ddde39SKyle Evans{
110*b5ddde39SKyle Evans	atf_check -o empty hexdump -bn 0 "$(atf_get_srcdir)/d_hexdump_a.in"
111*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_nflag_a.out" \
112*b5ddde39SKyle Evans	    hexdump -bn 1 "$(atf_get_srcdir)/d_hexdump_a.in"
113*b5ddde39SKyle Evans}
114*b5ddde39SKyle Evans
115*b5ddde39SKyle Evansatf_test_case o_flag
116*b5ddde39SKyle Evanso_flag_head()
117*b5ddde39SKyle Evans{
118*b5ddde39SKyle Evans	atf_set "descr" "Verify -o output"
119*b5ddde39SKyle Evans}
120*b5ddde39SKyle Evanso_flag_body()
121*b5ddde39SKyle Evans{
122*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_a.out" \
123*b5ddde39SKyle Evans	    hexdump -o "$(atf_get_srcdir)/d_hexdump_a.in"
124*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_b.out" \
125*b5ddde39SKyle Evans	    hexdump -o "$(atf_get_srcdir)/d_hexdump_b.in"
126*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_c.out" \
127*b5ddde39SKyle Evans	    hexdump -o "$(atf_get_srcdir)/d_hexdump_c.in"
128*b5ddde39SKyle Evans}
129*b5ddde39SKyle Evans
130*b5ddde39SKyle Evansatf_test_case s_flag
131*b5ddde39SKyle Evanss_flag_head()
132*b5ddde39SKyle Evans{
133*b5ddde39SKyle Evans	atf_set "descr" "Verify -s output"
134*b5ddde39SKyle Evans}
135*b5ddde39SKyle Evanss_flag_body()
136*b5ddde39SKyle Evans{
137*b5ddde39SKyle Evans	atf_expect_fail "-s option is currently broken due to capsicum (PR 219173)"
138*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_sflag_a.out" \
139*b5ddde39SKyle Evans	    hexdump -bs 4 "$(atf_get_srcdir)/d_hexdump_a.in"
140*b5ddde39SKyle Evans
141*b5ddde39SKyle Evans	atf_check -o not-empty hexdump -n 100 -s 1024 /dev/random
142*b5ddde39SKyle Evans}
143*b5ddde39SKyle Evans
144*b5ddde39SKyle Evansatf_test_case v_flag
145*b5ddde39SKyle Evansv_flag_head()
146*b5ddde39SKyle Evans{
147*b5ddde39SKyle Evans	atf_set "descr" "Verify -v functionality"
148*b5ddde39SKyle Evans}
149*b5ddde39SKyle Evansv_flag_body()
150*b5ddde39SKyle Evans{
151*b5ddde39SKyle Evans	atf_expect_fail "-s option is currently broken due to capsicum (PR 219173)"
152*b5ddde39SKyle Evans	for i in $(seq 0 7); do
153*b5ddde39SKyle Evans		atf_check -o match:"^\*$" \
154*b5ddde39SKyle Evans		    hexdump -s ${i} "$(atf_get_srcdir)/d_hexdump_c.in"
155*b5ddde39SKyle Evans		atf_check -o not-match:"^\*$" \
156*b5ddde39SKyle Evans		    hexdump -vs ${i} "$(atf_get_srcdir)/d_hexdump_c.in"
157*b5ddde39SKyle Evans	done
158*b5ddde39SKyle Evans
159*b5ddde39SKyle Evans	atf_check -o not-match:"^\*$" \
160*b5ddde39SKyle Evans	    hexdump -s 8 "$(atf_get_srcdir)/d_hexdump_c.in"
161*b5ddde39SKyle Evans	atf_check -o not-match:"^\*$" \
162*b5ddde39SKyle Evans	    hexdump -vs 8 "$(atf_get_srcdir)/d_hexdump_c.in"
163*b5ddde39SKyle Evans}
164*b5ddde39SKyle Evans
165*b5ddde39SKyle Evansatf_test_case x_flag
166*b5ddde39SKyle Evansx_flag_head()
167*b5ddde39SKyle Evans{
168*b5ddde39SKyle Evans	atf_set "descr" "Verify -x output"
169*b5ddde39SKyle Evans}
170*b5ddde39SKyle Evansx_flag_body()
171*b5ddde39SKyle Evans{
172*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_a.out" \
173*b5ddde39SKyle Evans	    hexdump -x "$(atf_get_srcdir)/d_hexdump_a.in"
174*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_b.out" \
175*b5ddde39SKyle Evans	    hexdump -x "$(atf_get_srcdir)/d_hexdump_b.in"
176*b5ddde39SKyle Evans	atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_c.out" \
177*b5ddde39SKyle Evans	    hexdump -x "$(atf_get_srcdir)/d_hexdump_c.in"
178*b5ddde39SKyle Evans}
179*b5ddde39SKyle Evans
180*b5ddde39SKyle Evansatf_init_test_cases()
181*b5ddde39SKyle Evans{
182*b5ddde39SKyle Evans	atf_add_test_case b_flag
183*b5ddde39SKyle Evans	atf_add_test_case c_flag
184*b5ddde39SKyle Evans	atf_add_test_case C_flag
185*b5ddde39SKyle Evans	atf_add_test_case hd_name
186*b5ddde39SKyle Evans	atf_add_test_case d_flag
187*b5ddde39SKyle Evans	atf_add_test_case n_flag
188*b5ddde39SKyle Evans	atf_add_test_case o_flag
189*b5ddde39SKyle Evans	atf_add_test_case s_flag
190*b5ddde39SKyle Evans	atf_add_test_case v_flag
191*b5ddde39SKyle Evans	atf_add_test_case x_flag
192*b5ddde39SKyle Evans}
193