1#!/bin/sh 2 3# Copyright (C) 2012-2023 Free Software Foundation, Inc. 4 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 19print_ver_ dd 20 21echo 0123456789abcdefghijklm > in || framework_failure_ 22 23# count bytes 24for operands in "count=14B" "count=14 iflag=count_bytes"; do 25 dd $operands conv=swab < in > out 2> /dev/null || fail=1 26 case $(cat out) in 27 1032547698badc) ;; 28 *) fail=1 ;; 29 esac 30done 31 32for operands in "iseek=10B" "skip=10 iflag=skip_bytes"; do 33 # skip bytes 34 dd $operands < in > out 2> /dev/null || fail=1 35 case $(cat out) in 36 abcdefghijklm) ;; 37 *) fail=1 ;; 38 esac 39 40 # skip records and bytes from pipe 41 echo 0123456789abcdefghijklm | 42 dd $operands bs=2 > out 2> /dev/null || fail=1 43 case $(cat out) in 44 abcdefghijklm) ;; 45 *) fail=1 ;; 46 esac 47done 48 49truncate -s8 expected2 50printf '\0\0\0\0\0\0\0\0abcdefghijklm\n' > expected 51 52for operands in "oseek=8B" "seek=8 oflag=seek_bytes"; do 53 # seek bytes 54 echo abcdefghijklm | 55 dd $operands bs=5 > out 2> /dev/null || fail=1 56 compare expected out || fail=1 57 58 # Just truncation, no I/O 59 dd $operands bs=5 of=out2 count=0 2> /dev/null || fail=1 60 compare expected2 out2 || fail=1 61done 62 63# Check recursive integer parsing 64for oseek in '1x2x4 oflag=seek_bytes' '1Bx2x4' '1Bx8' '2Bx4B' '2x4B'; do 65 # seek bytes 66 echo abcdefghijklm | 67 dd oseek=$oseek bs=5 > out 2> /dev/null || fail=1 68 compare expected out || fail=1 69done 70 71# Negative checks for integer parsing 72for count in B B1 Bx1 KBB BB KBb KBx x1 1x 1xx1; do 73 returns_ 1 dd count=$count </dev/null >/dev/null || fail=1 74done 75Exit $fail 76