]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/hexdump/tests/hexdump_test.sh
MFC r358553: hexdump: tests: take into account byte order
[FreeBSD/FreeBSD.git] / usr.bin / hexdump / tests / hexdump_test.sh
1 #
2 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 #
4 # Copyright (c) 2017 Kyle Evans <kevans@FreeBSD.org>
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 # $FreeBSD$
28
29 ENDIAN=el
30 ret=$(echo I | tr -d "[:space:]" | od -to2 | head -n1 | awk '{print $2}' | cut -c6)
31 if [ "$ret" = "0" ]; then
32         ENDIAN=eb
33 fi
34
35 atf_test_case b_flag
36 b_flag_head()
37 {
38         atf_set "descr" "Verify -b output"
39 }
40 b_flag_body()
41 {
42         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_a.out" \
43             hexdump -b "$(atf_get_srcdir)/d_hexdump_a.in"
44         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_b.out" \
45             hexdump -b "$(atf_get_srcdir)/d_hexdump_b.in"
46         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_c.out" \
47             hexdump -b "$(atf_get_srcdir)/d_hexdump_c.in"
48 }
49
50 atf_test_case c_flag
51 c_flag_head()
52 {
53         atf_set "descr" "Verify -c output"
54 }
55 c_flag_body()
56 {
57         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_a.out" \
58             hexdump -c "$(atf_get_srcdir)/d_hexdump_a.in"
59         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_b.out" \
60             hexdump -c "$(atf_get_srcdir)/d_hexdump_b.in"
61         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_c.out" \
62             hexdump -c "$(atf_get_srcdir)/d_hexdump_c.in"
63 }
64
65 atf_test_case C_flag
66 C_flag_head()
67 {
68         atf_set "descr" "Verify -C output"
69 }
70 C_flag_body()
71 {
72         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \
73             hexdump -C "$(atf_get_srcdir)/d_hexdump_a.in"
74         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \
75             hexdump -C "$(atf_get_srcdir)/d_hexdump_b.in"
76         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
77             hexdump -C "$(atf_get_srcdir)/d_hexdump_c.in"
78 }
79
80 atf_test_case hd_name
81 hd_name_head()
82 {
83         atf_set "descr" "Verify hd output matching -C output"
84 }
85 hd_name_body()
86 {
87         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \
88             hd "$(atf_get_srcdir)/d_hexdump_a.in"
89         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \
90             hd "$(atf_get_srcdir)/d_hexdump_b.in"
91         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \
92             hd "$(atf_get_srcdir)/d_hexdump_c.in"
93 }
94
95 atf_test_case d_flag
96 d_flag_head()
97 {
98         atf_set "descr" "Verify -d output"
99 }
100 d_flag_body()
101 {
102         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_a_$ENDIAN.out" \
103             hexdump -d "$(atf_get_srcdir)/d_hexdump_a.in"
104         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_b_$ENDIAN.out" \
105             hexdump -d "$(atf_get_srcdir)/d_hexdump_b.in"
106         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_c_$ENDIAN.out" \
107             hexdump -d "$(atf_get_srcdir)/d_hexdump_c.in"
108 }
109
110 atf_test_case n_flag
111 n_flag_head()
112 {
113         atf_set "descr" "Check -n functionality"
114 }
115 n_flag_body()
116 {
117         atf_check -o empty hexdump -bn 0 "$(atf_get_srcdir)/d_hexdump_a.in"
118         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_nflag_a.out" \
119             hexdump -bn 1 "$(atf_get_srcdir)/d_hexdump_a.in"
120 }
121
122 atf_test_case o_flag
123 o_flag_head()
124 {
125         atf_set "descr" "Verify -o output"
126 }
127 o_flag_body()
128 {
129         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_a_$ENDIAN.out" \
130             hexdump -o "$(atf_get_srcdir)/d_hexdump_a.in"
131         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_b_$ENDIAN.out" \
132             hexdump -o "$(atf_get_srcdir)/d_hexdump_b.in"
133         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_c_$ENDIAN.out" \
134             hexdump -o "$(atf_get_srcdir)/d_hexdump_c.in"
135 }
136
137 atf_test_case s_flag
138 s_flag_head()
139 {
140         atf_set "descr" "Verify -s output"
141 }
142 s_flag_body()
143 {
144         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_sflag_a.out" \
145             hexdump -bs 4 "$(atf_get_srcdir)/d_hexdump_a.in"
146
147         atf_check -o not-empty hexdump -n 100 -s 1024 /dev/random
148 }
149
150 atf_test_case v_flag
151 v_flag_head()
152 {
153         atf_set "descr" "Verify -v functionality"
154 }
155 v_flag_body()
156 {
157         for i in $(seq 0 7); do
158                 atf_check -o match:"^\*$" \
159                     hexdump -s ${i} "$(atf_get_srcdir)/d_hexdump_c.in"
160                 atf_check -o not-match:"^\*$" \
161                     hexdump -vs ${i} "$(atf_get_srcdir)/d_hexdump_c.in"
162         done
163
164         atf_check -o not-match:"^\*$" \
165             hexdump -s 8 "$(atf_get_srcdir)/d_hexdump_c.in"
166         atf_check -o not-match:"^\*$" \
167             hexdump -vs 8 "$(atf_get_srcdir)/d_hexdump_c.in"
168 }
169
170 atf_test_case x_flag
171 x_flag_head()
172 {
173         atf_set "descr" "Verify -x output"
174 }
175 x_flag_body()
176 {
177         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_a_$ENDIAN.out" \
178             hexdump -x "$(atf_get_srcdir)/d_hexdump_a.in"
179         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_b_$ENDIAN.out" \
180             hexdump -x "$(atf_get_srcdir)/d_hexdump_b.in"
181         atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_c_$ENDIAN.out" \
182             hexdump -x "$(atf_get_srcdir)/d_hexdump_c.in"
183 }
184
185 atf_init_test_cases()
186 {
187         atf_add_test_case b_flag
188         atf_add_test_case c_flag
189         atf_add_test_case C_flag
190         atf_add_test_case hd_name
191         atf_add_test_case d_flag
192         atf_add_test_case n_flag
193         atf_add_test_case o_flag
194         atf_add_test_case s_flag
195         atf_add_test_case v_flag
196         atf_add_test_case x_flag
197 }