# $NetBSD: t_dd.sh,v 1.3 2022/05/24 21:42:37 rillig Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
test_dd_length() {
result=$1
cmd=$2
set -- x `eval $cmd | wc -c`
res=$2
if [ x"$res" != x"$result" ]; then
atf_fail "Expected $result bytes of output, got $res: $cmd"
fi
}
atf_test_case length
length_head() {
# XXX The PR should be stored in a tag.
atf_set "descr" "Test for result messages accidentally pumped into" \
"the output file if the standard IO descriptors are" \
"closed. The last of the three following tests is" \
"the one expected to fail. (NetBSD PR bin/8521)"
}
length_body() {
test_dd_length 512 \
"dd if=/dev/zero of=/dev/fd/5 count=1 5>&1 >/dev/null 2>/dev/null"
test_dd_length 512 \
"dd if=/dev/zero of=/dev/fd/5 count=1 5>&1 >&- 2>/dev/null"
test_dd_length 512 \
"dd if=/dev/zero of=/dev/fd/5 count=1 5>&1 >&- 2>&-"
}
test_dd_io() {
res="`echo -n "$2" | eval $1`"
if [ x"$res" != x"$3" ]; then
atf_fail "Expected \"$3\", got \"$res\": $1"
fi
}