1b5ddde39SKyle Evans# 24d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 3f0fb94abSKyle Evans# 4b5ddde39SKyle Evans# Copyright (c) 2017 Kyle Evans <kevans@FreeBSD.org> 5b5ddde39SKyle Evans# 6b5ddde39SKyle Evans# Redistribution and use in source and binary forms, with or without 7b5ddde39SKyle Evans# modification, are permitted provided that the following conditions 8b5ddde39SKyle Evans# are met: 9b5ddde39SKyle Evans# 1. Redistributions of source code must retain the above copyright 10b5ddde39SKyle Evans# notice, this list of conditions and the following disclaimer. 11b5ddde39SKyle Evans# 2. Redistributions in binary form must reproduce the above copyright 12b5ddde39SKyle Evans# notice, this list of conditions and the following disclaimer in the 13b5ddde39SKyle Evans# documentation and/or other materials provided with the distribution. 14b5ddde39SKyle Evans# 15b5ddde39SKyle Evans# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16b5ddde39SKyle Evans# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17b5ddde39SKyle Evans# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18b5ddde39SKyle Evans# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19b5ddde39SKyle Evans# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20b5ddde39SKyle Evans# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21b5ddde39SKyle Evans# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22b5ddde39SKyle Evans# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23b5ddde39SKyle Evans# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24b5ddde39SKyle Evans# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25b5ddde39SKyle Evans# SUCH DAMAGE. 26b5ddde39SKyle Evans# 27b5ddde39SKyle Evans 288a9f144cSKyle EvansENDIAN=el 298a9f144cSKyle Evansret=$(echo I | tr -d "[:space:]" | od -to2 | head -n1 | awk '{print $2}' | cut -c6) 308a9f144cSKyle Evansif [ "$ret" = "0" ]; then 318a9f144cSKyle Evans ENDIAN=eb 328a9f144cSKyle Evansfi 338a9f144cSKyle Evans 34b5ddde39SKyle Evansatf_test_case b_flag 35b5ddde39SKyle Evansb_flag_head() 36b5ddde39SKyle Evans{ 37b5ddde39SKyle Evans atf_set "descr" "Verify -b output" 38b5ddde39SKyle Evans} 39b5ddde39SKyle Evansb_flag_body() 40b5ddde39SKyle Evans{ 41b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_a.out" \ 42b5ddde39SKyle Evans hexdump -b "$(atf_get_srcdir)/d_hexdump_a.in" 43b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_b.out" \ 44b5ddde39SKyle Evans hexdump -b "$(atf_get_srcdir)/d_hexdump_b.in" 45b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_c.out" \ 46b5ddde39SKyle Evans hexdump -b "$(atf_get_srcdir)/d_hexdump_c.in" 47b5ddde39SKyle Evans} 48b5ddde39SKyle Evans 49b5ddde39SKyle Evansatf_test_case c_flag 50b5ddde39SKyle Evansc_flag_head() 51b5ddde39SKyle Evans{ 52b5ddde39SKyle Evans atf_set "descr" "Verify -c output" 53b5ddde39SKyle Evans} 54b5ddde39SKyle Evansc_flag_body() 55b5ddde39SKyle Evans{ 56b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_a.out" \ 57b5ddde39SKyle Evans hexdump -c "$(atf_get_srcdir)/d_hexdump_a.in" 58b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_b.out" \ 59b5ddde39SKyle Evans hexdump -c "$(atf_get_srcdir)/d_hexdump_b.in" 60b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_c.out" \ 61b5ddde39SKyle Evans hexdump -c "$(atf_get_srcdir)/d_hexdump_c.in" 62b5ddde39SKyle Evans} 63b5ddde39SKyle Evans 64b5ddde39SKyle Evansatf_test_case C_flag 65b5ddde39SKyle EvansC_flag_head() 66b5ddde39SKyle Evans{ 67b5ddde39SKyle Evans atf_set "descr" "Verify -C output" 68b5ddde39SKyle Evans} 69b5ddde39SKyle EvansC_flag_body() 70b5ddde39SKyle Evans{ 71b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \ 72b5ddde39SKyle Evans hexdump -C "$(atf_get_srcdir)/d_hexdump_a.in" 73b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \ 74b5ddde39SKyle Evans hexdump -C "$(atf_get_srcdir)/d_hexdump_b.in" 75b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \ 76b5ddde39SKyle Evans hexdump -C "$(atf_get_srcdir)/d_hexdump_c.in" 77*d1016568SXin LI atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_bug118723.out" \ 78*d1016568SXin LI hexdump -C "$(atf_get_srcdir)/d_hexdump_bug118723.in" 79*d1016568SXin LI atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCvflag_bug118723.out" \ 80*d1016568SXin LI hexdump -Cv "$(atf_get_srcdir)/d_hexdump_bug118723.in" 81b5ddde39SKyle Evans} 82b5ddde39SKyle Evans 83b5ddde39SKyle Evansatf_test_case hd_name 84b5ddde39SKyle Evanshd_name_head() 85b5ddde39SKyle Evans{ 86b5ddde39SKyle Evans atf_set "descr" "Verify hd output matching -C output" 87b5ddde39SKyle Evans} 88b5ddde39SKyle Evanshd_name_body() 89b5ddde39SKyle Evans{ 90b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \ 91b5ddde39SKyle Evans hd "$(atf_get_srcdir)/d_hexdump_a.in" 92b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \ 93b5ddde39SKyle Evans hd "$(atf_get_srcdir)/d_hexdump_b.in" 94b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \ 95b5ddde39SKyle Evans hd "$(atf_get_srcdir)/d_hexdump_c.in" 96*d1016568SXin LI atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_bug118723.out" \ 97*d1016568SXin LI hd "$(atf_get_srcdir)/d_hexdump_bug118723.in" 98*d1016568SXin LI atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCvflag_bug118723.out" \ 99*d1016568SXin LI hd -v "$(atf_get_srcdir)/d_hexdump_bug118723.in" 100b5ddde39SKyle Evans} 101b5ddde39SKyle Evans 102b5ddde39SKyle Evansatf_test_case d_flag 103b5ddde39SKyle Evansd_flag_head() 104b5ddde39SKyle Evans{ 105b5ddde39SKyle Evans atf_set "descr" "Verify -d output" 106b5ddde39SKyle Evans} 107b5ddde39SKyle Evansd_flag_body() 108b5ddde39SKyle Evans{ 1098a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_a_$ENDIAN.out" \ 110b5ddde39SKyle Evans hexdump -d "$(atf_get_srcdir)/d_hexdump_a.in" 1118a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_b_$ENDIAN.out" \ 112b5ddde39SKyle Evans hexdump -d "$(atf_get_srcdir)/d_hexdump_b.in" 1138a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_c_$ENDIAN.out" \ 114b5ddde39SKyle Evans hexdump -d "$(atf_get_srcdir)/d_hexdump_c.in" 115b5ddde39SKyle Evans} 116b5ddde39SKyle Evans 117b5ddde39SKyle Evansatf_test_case n_flag 118b5ddde39SKyle Evansn_flag_head() 119b5ddde39SKyle Evans{ 120b5ddde39SKyle Evans atf_set "descr" "Check -n functionality" 121b5ddde39SKyle Evans} 122b5ddde39SKyle Evansn_flag_body() 123b5ddde39SKyle Evans{ 124b5ddde39SKyle Evans atf_check -o empty hexdump -bn 0 "$(atf_get_srcdir)/d_hexdump_a.in" 125b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_nflag_a.out" \ 126b5ddde39SKyle Evans hexdump -bn 1 "$(atf_get_srcdir)/d_hexdump_a.in" 127b5ddde39SKyle Evans} 128b5ddde39SKyle Evans 129b5ddde39SKyle Evansatf_test_case o_flag 130b5ddde39SKyle Evanso_flag_head() 131b5ddde39SKyle Evans{ 132b5ddde39SKyle Evans atf_set "descr" "Verify -o output" 133b5ddde39SKyle Evans} 134b5ddde39SKyle Evanso_flag_body() 135b5ddde39SKyle Evans{ 1368a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_a_$ENDIAN.out" \ 137b5ddde39SKyle Evans hexdump -o "$(atf_get_srcdir)/d_hexdump_a.in" 1388a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_b_$ENDIAN.out" \ 139b5ddde39SKyle Evans hexdump -o "$(atf_get_srcdir)/d_hexdump_b.in" 1408a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_c_$ENDIAN.out" \ 141b5ddde39SKyle Evans hexdump -o "$(atf_get_srcdir)/d_hexdump_c.in" 142b5ddde39SKyle Evans} 143b5ddde39SKyle Evans 144b5ddde39SKyle Evansatf_test_case s_flag 145b5ddde39SKyle Evanss_flag_head() 146b5ddde39SKyle Evans{ 147b5ddde39SKyle Evans atf_set "descr" "Verify -s output" 148b5ddde39SKyle Evans} 149b5ddde39SKyle Evanss_flag_body() 150b5ddde39SKyle Evans{ 151b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_sflag_a.out" \ 152b5ddde39SKyle Evans hexdump -bs 4 "$(atf_get_srcdir)/d_hexdump_a.in" 153b5ddde39SKyle Evans 154b5ddde39SKyle Evans atf_check -o not-empty hexdump -n 100 -s 1024 /dev/random 155b5ddde39SKyle Evans} 156b5ddde39SKyle Evans 157b5ddde39SKyle Evansatf_test_case v_flag 158b5ddde39SKyle Evansv_flag_head() 159b5ddde39SKyle Evans{ 160b5ddde39SKyle Evans atf_set "descr" "Verify -v functionality" 161b5ddde39SKyle Evans} 162b5ddde39SKyle Evansv_flag_body() 163b5ddde39SKyle Evans{ 164b5ddde39SKyle Evans for i in $(seq 0 7); do 165b5ddde39SKyle Evans atf_check -o match:"^\*$" \ 166b5ddde39SKyle Evans hexdump -s ${i} "$(atf_get_srcdir)/d_hexdump_c.in" 167b5ddde39SKyle Evans atf_check -o not-match:"^\*$" \ 168b5ddde39SKyle Evans hexdump -vs ${i} "$(atf_get_srcdir)/d_hexdump_c.in" 169b5ddde39SKyle Evans done 170b5ddde39SKyle Evans 171b5ddde39SKyle Evans atf_check -o not-match:"^\*$" \ 172b5ddde39SKyle Evans hexdump -s 8 "$(atf_get_srcdir)/d_hexdump_c.in" 173b5ddde39SKyle Evans atf_check -o not-match:"^\*$" \ 174b5ddde39SKyle Evans hexdump -vs 8 "$(atf_get_srcdir)/d_hexdump_c.in" 175b5ddde39SKyle Evans} 176b5ddde39SKyle Evans 177b5ddde39SKyle Evansatf_test_case x_flag 178b5ddde39SKyle Evansx_flag_head() 179b5ddde39SKyle Evans{ 180b5ddde39SKyle Evans atf_set "descr" "Verify -x output" 181b5ddde39SKyle Evans} 182b5ddde39SKyle Evansx_flag_body() 183b5ddde39SKyle Evans{ 1848a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_a_$ENDIAN.out" \ 185b5ddde39SKyle Evans hexdump -x "$(atf_get_srcdir)/d_hexdump_a.in" 1868a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_b_$ENDIAN.out" \ 187b5ddde39SKyle Evans hexdump -x "$(atf_get_srcdir)/d_hexdump_b.in" 1888a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_c_$ENDIAN.out" \ 189b5ddde39SKyle Evans hexdump -x "$(atf_get_srcdir)/d_hexdump_c.in" 190b5ddde39SKyle Evans} 191b5ddde39SKyle Evans 1928fb93ac9SConrad Meyeratf_test_case no_conv_err 1938fb93ac9SConrad Meyerno_conv_err() 1948fb93ac9SConrad Meyer{ 1958fb93ac9SConrad Meyer atf_set "descr" "Verify missing conversion char error handling" 1968fb93ac9SConrad Meyer} 1978fb93ac9SConrad Meyerno_conv_err_body() 1988fb93ac9SConrad Meyer{ 1998fb93ac9SConrad Meyer atf_check -s exit:1 -e ignore \ 2008fb93ac9SConrad Meyer hexdump -e '"%"' 2018fb93ac9SConrad Meyer atf_check -s exit:1 -e ignore \ 2028fb93ac9SConrad Meyer hexdump -e '4/2 "%"' 2038fb93ac9SConrad Meyer} 2048fb93ac9SConrad Meyer 205b5ddde39SKyle Evansatf_init_test_cases() 206b5ddde39SKyle Evans{ 207b5ddde39SKyle Evans atf_add_test_case b_flag 208b5ddde39SKyle Evans atf_add_test_case c_flag 209b5ddde39SKyle Evans atf_add_test_case C_flag 210b5ddde39SKyle Evans atf_add_test_case hd_name 211b5ddde39SKyle Evans atf_add_test_case d_flag 212b5ddde39SKyle Evans atf_add_test_case n_flag 213b5ddde39SKyle Evans atf_add_test_case o_flag 214b5ddde39SKyle Evans atf_add_test_case s_flag 215b5ddde39SKyle Evans atf_add_test_case v_flag 216b5ddde39SKyle Evans atf_add_test_case x_flag 2178fb93ac9SConrad Meyer atf_add_test_case no_conv_err 218b5ddde39SKyle Evans} 219