1b5ddde39SKyle Evans# 2f0fb94abSKyle Evans# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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# $FreeBSD$ 28b5ddde39SKyle Evans 29*8a9f144cSKyle EvansENDIAN=el 30*8a9f144cSKyle Evansret=$(echo I | tr -d "[:space:]" | od -to2 | head -n1 | awk '{print $2}' | cut -c6) 31*8a9f144cSKyle Evansif [ "$ret" = "0" ]; then 32*8a9f144cSKyle Evans ENDIAN=eb 33*8a9f144cSKyle Evansfi 34*8a9f144cSKyle Evans 35b5ddde39SKyle Evansatf_test_case b_flag 36b5ddde39SKyle Evansb_flag_head() 37b5ddde39SKyle Evans{ 38b5ddde39SKyle Evans atf_set "descr" "Verify -b output" 39b5ddde39SKyle Evans} 40b5ddde39SKyle Evansb_flag_body() 41b5ddde39SKyle Evans{ 42b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_a.out" \ 43b5ddde39SKyle Evans hexdump -b "$(atf_get_srcdir)/d_hexdump_a.in" 44b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_b.out" \ 45b5ddde39SKyle Evans hexdump -b "$(atf_get_srcdir)/d_hexdump_b.in" 46b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_bflag_c.out" \ 47b5ddde39SKyle Evans hexdump -b "$(atf_get_srcdir)/d_hexdump_c.in" 48b5ddde39SKyle Evans} 49b5ddde39SKyle Evans 50b5ddde39SKyle Evansatf_test_case c_flag 51b5ddde39SKyle Evansc_flag_head() 52b5ddde39SKyle Evans{ 53b5ddde39SKyle Evans atf_set "descr" "Verify -c output" 54b5ddde39SKyle Evans} 55b5ddde39SKyle Evansc_flag_body() 56b5ddde39SKyle Evans{ 57b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_a.out" \ 58b5ddde39SKyle Evans hexdump -c "$(atf_get_srcdir)/d_hexdump_a.in" 59b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_b.out" \ 60b5ddde39SKyle Evans hexdump -c "$(atf_get_srcdir)/d_hexdump_b.in" 61b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_cflag_c.out" \ 62b5ddde39SKyle Evans hexdump -c "$(atf_get_srcdir)/d_hexdump_c.in" 63b5ddde39SKyle Evans} 64b5ddde39SKyle Evans 65b5ddde39SKyle Evansatf_test_case C_flag 66b5ddde39SKyle EvansC_flag_head() 67b5ddde39SKyle Evans{ 68b5ddde39SKyle Evans atf_set "descr" "Verify -C output" 69b5ddde39SKyle Evans} 70b5ddde39SKyle EvansC_flag_body() 71b5ddde39SKyle Evans{ 72b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \ 73b5ddde39SKyle Evans hexdump -C "$(atf_get_srcdir)/d_hexdump_a.in" 74b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \ 75b5ddde39SKyle Evans hexdump -C "$(atf_get_srcdir)/d_hexdump_b.in" 76b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \ 77b5ddde39SKyle Evans hexdump -C "$(atf_get_srcdir)/d_hexdump_c.in" 78b5ddde39SKyle Evans} 79b5ddde39SKyle Evans 80b5ddde39SKyle Evansatf_test_case hd_name 81b5ddde39SKyle Evanshd_name_head() 82b5ddde39SKyle Evans{ 83b5ddde39SKyle Evans atf_set "descr" "Verify hd output matching -C output" 84b5ddde39SKyle Evans} 85b5ddde39SKyle Evanshd_name_body() 86b5ddde39SKyle Evans{ 87b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_a.out" \ 88b5ddde39SKyle Evans hd "$(atf_get_srcdir)/d_hexdump_a.in" 89b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_b.out" \ 90b5ddde39SKyle Evans hd "$(atf_get_srcdir)/d_hexdump_b.in" 91b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_UCflag_c.out" \ 92b5ddde39SKyle Evans hd "$(atf_get_srcdir)/d_hexdump_c.in" 93b5ddde39SKyle Evans} 94b5ddde39SKyle Evans 95b5ddde39SKyle Evansatf_test_case d_flag 96b5ddde39SKyle Evansd_flag_head() 97b5ddde39SKyle Evans{ 98b5ddde39SKyle Evans atf_set "descr" "Verify -d output" 99b5ddde39SKyle Evans} 100b5ddde39SKyle Evansd_flag_body() 101b5ddde39SKyle Evans{ 102*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_a_$ENDIAN.out" \ 103b5ddde39SKyle Evans hexdump -d "$(atf_get_srcdir)/d_hexdump_a.in" 104*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_b_$ENDIAN.out" \ 105b5ddde39SKyle Evans hexdump -d "$(atf_get_srcdir)/d_hexdump_b.in" 106*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_dflag_c_$ENDIAN.out" \ 107b5ddde39SKyle Evans hexdump -d "$(atf_get_srcdir)/d_hexdump_c.in" 108b5ddde39SKyle Evans} 109b5ddde39SKyle Evans 110b5ddde39SKyle Evansatf_test_case n_flag 111b5ddde39SKyle Evansn_flag_head() 112b5ddde39SKyle Evans{ 113b5ddde39SKyle Evans atf_set "descr" "Check -n functionality" 114b5ddde39SKyle Evans} 115b5ddde39SKyle Evansn_flag_body() 116b5ddde39SKyle Evans{ 117b5ddde39SKyle Evans atf_check -o empty hexdump -bn 0 "$(atf_get_srcdir)/d_hexdump_a.in" 118b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_nflag_a.out" \ 119b5ddde39SKyle Evans hexdump -bn 1 "$(atf_get_srcdir)/d_hexdump_a.in" 120b5ddde39SKyle Evans} 121b5ddde39SKyle Evans 122b5ddde39SKyle Evansatf_test_case o_flag 123b5ddde39SKyle Evanso_flag_head() 124b5ddde39SKyle Evans{ 125b5ddde39SKyle Evans atf_set "descr" "Verify -o output" 126b5ddde39SKyle Evans} 127b5ddde39SKyle Evanso_flag_body() 128b5ddde39SKyle Evans{ 129*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_a_$ENDIAN.out" \ 130b5ddde39SKyle Evans hexdump -o "$(atf_get_srcdir)/d_hexdump_a.in" 131*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_b_$ENDIAN.out" \ 132b5ddde39SKyle Evans hexdump -o "$(atf_get_srcdir)/d_hexdump_b.in" 133*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_oflag_c_$ENDIAN.out" \ 134b5ddde39SKyle Evans hexdump -o "$(atf_get_srcdir)/d_hexdump_c.in" 135b5ddde39SKyle Evans} 136b5ddde39SKyle Evans 137b5ddde39SKyle Evansatf_test_case s_flag 138b5ddde39SKyle Evanss_flag_head() 139b5ddde39SKyle Evans{ 140b5ddde39SKyle Evans atf_set "descr" "Verify -s output" 141b5ddde39SKyle Evans} 142b5ddde39SKyle Evanss_flag_body() 143b5ddde39SKyle Evans{ 144b5ddde39SKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_sflag_a.out" \ 145b5ddde39SKyle Evans hexdump -bs 4 "$(atf_get_srcdir)/d_hexdump_a.in" 146b5ddde39SKyle Evans 147b5ddde39SKyle Evans atf_check -o not-empty hexdump -n 100 -s 1024 /dev/random 148b5ddde39SKyle Evans} 149b5ddde39SKyle Evans 150b5ddde39SKyle Evansatf_test_case v_flag 151b5ddde39SKyle Evansv_flag_head() 152b5ddde39SKyle Evans{ 153b5ddde39SKyle Evans atf_set "descr" "Verify -v functionality" 154b5ddde39SKyle Evans} 155b5ddde39SKyle Evansv_flag_body() 156b5ddde39SKyle Evans{ 157b5ddde39SKyle Evans for i in $(seq 0 7); do 158b5ddde39SKyle Evans atf_check -o match:"^\*$" \ 159b5ddde39SKyle Evans hexdump -s ${i} "$(atf_get_srcdir)/d_hexdump_c.in" 160b5ddde39SKyle Evans atf_check -o not-match:"^\*$" \ 161b5ddde39SKyle Evans hexdump -vs ${i} "$(atf_get_srcdir)/d_hexdump_c.in" 162b5ddde39SKyle Evans done 163b5ddde39SKyle Evans 164b5ddde39SKyle Evans atf_check -o not-match:"^\*$" \ 165b5ddde39SKyle Evans hexdump -s 8 "$(atf_get_srcdir)/d_hexdump_c.in" 166b5ddde39SKyle Evans atf_check -o not-match:"^\*$" \ 167b5ddde39SKyle Evans hexdump -vs 8 "$(atf_get_srcdir)/d_hexdump_c.in" 168b5ddde39SKyle Evans} 169b5ddde39SKyle Evans 170b5ddde39SKyle Evansatf_test_case x_flag 171b5ddde39SKyle Evansx_flag_head() 172b5ddde39SKyle Evans{ 173b5ddde39SKyle Evans atf_set "descr" "Verify -x output" 174b5ddde39SKyle Evans} 175b5ddde39SKyle Evansx_flag_body() 176b5ddde39SKyle Evans{ 177*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_a_$ENDIAN.out" \ 178b5ddde39SKyle Evans hexdump -x "$(atf_get_srcdir)/d_hexdump_a.in" 179*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_b_$ENDIAN.out" \ 180b5ddde39SKyle Evans hexdump -x "$(atf_get_srcdir)/d_hexdump_b.in" 181*8a9f144cSKyle Evans atf_check -o file:"$(atf_get_srcdir)/d_hexdump_xflag_c_$ENDIAN.out" \ 182b5ddde39SKyle Evans hexdump -x "$(atf_get_srcdir)/d_hexdump_c.in" 183b5ddde39SKyle Evans} 184b5ddde39SKyle Evans 1858fb93ac9SConrad Meyeratf_test_case no_conv_err 1868fb93ac9SConrad Meyerno_conv_err() 1878fb93ac9SConrad Meyer{ 1888fb93ac9SConrad Meyer atf_set "descr" "Verify missing conversion char error handling" 1898fb93ac9SConrad Meyer} 1908fb93ac9SConrad Meyerno_conv_err_body() 1918fb93ac9SConrad Meyer{ 1928fb93ac9SConrad Meyer atf_check -s exit:1 -e ignore \ 1938fb93ac9SConrad Meyer hexdump -e '"%"' 1948fb93ac9SConrad Meyer atf_check -s exit:1 -e ignore \ 1958fb93ac9SConrad Meyer hexdump -e '4/2 "%"' 1968fb93ac9SConrad Meyer} 1978fb93ac9SConrad Meyer 198b5ddde39SKyle Evansatf_init_test_cases() 199b5ddde39SKyle Evans{ 200b5ddde39SKyle Evans atf_add_test_case b_flag 201b5ddde39SKyle Evans atf_add_test_case c_flag 202b5ddde39SKyle Evans atf_add_test_case C_flag 203b5ddde39SKyle Evans atf_add_test_case hd_name 204b5ddde39SKyle Evans atf_add_test_case d_flag 205b5ddde39SKyle Evans atf_add_test_case n_flag 206b5ddde39SKyle Evans atf_add_test_case o_flag 207b5ddde39SKyle Evans atf_add_test_case s_flag 208b5ddde39SKyle Evans atf_add_test_case v_flag 209b5ddde39SKyle Evans atf_add_test_case x_flag 2108fb93ac9SConrad Meyer atf_add_test_case no_conv_err 211b5ddde39SKyle Evans} 212