Importing NetBSD "Kyua" test framework
To do so, a few dependencies have been imported: * external/bsd/lutok * external/mit/lua * external/public-domain/sqlite * external/public-domain/xz The Kyua framework is the new generation of ATF (Automated Test Framework), it is composed of: * external/bsd/atf * external/bsd/kyua-atf-compat * external/bsd/kyua-cli * external/bsd/kyua-tester * tests Kyua/ATF being written in C++, it depends on libstdc++ which is provided by GCC. As this is not part of the sources, Kyua is only compiled when the native GCC utils are installed. To install Kyua do the following: * In a cross-build enviromnent, add the following to the build.sh commandline: -V MKBINUTILS=yes -V MKGCCCMDS=yes WARNING: At this point the import is still experimental, and not supported on native builds (a.k.a make build). Change-Id: I26aee23c5bbd2d64adcb7c1beb98fe0d479d7ada
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# $NetBSD: Makefile,v 1.3 2012/03/30 15:49:24 njoly Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin
|
||||
|
||||
# LSC FIXME df test is ignored
|
||||
TESTS_SUBDIRS= cat cp dd expr pax ps sh sleep tar
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,12 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/27 08:16:33 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/cat
|
||||
TESTS_SH= t_cat
|
||||
|
||||
FILESDIR= ${TESTSDIR}
|
||||
FILES+= d_align.in
|
||||
FILES+= d_align.out
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,3 @@
|
||||
a b c
|
||||
1 2 3
|
||||
x y z
|
||||
@@ -0,0 +1,3 @@
|
||||
1 a b c$
|
||||
2 1 2 3$
|
||||
3 x y z$
|
||||
@@ -0,0 +1,59 @@
|
||||
# $NetBSD: t_cat.sh,v 1.2 2012/03/27 17:57:02 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2012 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This code is derived from software contributed to The NetBSD Foundation
|
||||
# by Jukka Ruohonen.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
atf_test_case align
|
||||
align_head() {
|
||||
atf_set "descr" "Test that cat(1) aligns the output " \
|
||||
"right with options '-be' (PR bin/4841)"
|
||||
}
|
||||
|
||||
align_body() {
|
||||
|
||||
atf_check -s ignore -o file:$(atf_get_srcdir)/d_align.out \
|
||||
-x "cat -be $(atf_get_srcdir)/d_align.in"
|
||||
}
|
||||
|
||||
atf_test_case nonexistent
|
||||
nonexistent_head() {
|
||||
atf_set "descr" "Test that cat(1) doesn't return zero exit " \
|
||||
"status for a nonexistent file (PR bin/3538)"
|
||||
}
|
||||
|
||||
nonexistent_body() {
|
||||
|
||||
atf_check -s not-exit:0 -o empty -e not-empty \
|
||||
-x "cat /some/name/that/does/not/exist"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case align
|
||||
atf_add_test_case nonexistent
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/17 16:33:10 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/cp
|
||||
TESTS_SH= t_cp
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,294 @@
|
||||
# $NetBSD: t_cp.sh,v 1.1 2012/03/17 16:33:10 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2007, 2008 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.
|
||||
#
|
||||
|
||||
FILES="file file2 file3 link dir dir2 dirlink target"
|
||||
|
||||
cleanup() {
|
||||
rm -fr ${FILES}
|
||||
}
|
||||
|
||||
cp_compare() {
|
||||
echo "Ensuring that $2 and $3 are identical"
|
||||
cmp -s $2 $3 || atf_fail "$2 and $3 are different"
|
||||
}
|
||||
|
||||
reset() {
|
||||
cleanup
|
||||
echo "I'm a file" > file
|
||||
echo "I'm a file, 2" > file2
|
||||
echo "I'm a file, 3" > file3
|
||||
ln -s file link
|
||||
mkdir dir
|
||||
ln -s dir dirlink
|
||||
}
|
||||
|
||||
atf_test_case file_to_file
|
||||
file_to_file_head() {
|
||||
atf_set "descr" "Checks the copy of a file to a file"
|
||||
}
|
||||
file_to_file_body() {
|
||||
reset
|
||||
|
||||
file_to_file_simple
|
||||
file_to_file_preserve
|
||||
file_to_file_noflags
|
||||
}
|
||||
|
||||
file_to_file_simple() {
|
||||
rm -f file2
|
||||
umask 022
|
||||
chmod 777 file
|
||||
atf_check -s eq:0 -o empty -e empty cp file file2
|
||||
cp_compare file_to_file_simple file file2
|
||||
if [ `stat -f "%Lp" file2` != "755" ]; then
|
||||
atf_fail "new file not created with umask"
|
||||
fi
|
||||
|
||||
chmod 644 file
|
||||
chmod 777 file2
|
||||
cp_compare file_to_file_simple file file2
|
||||
if [ `stat -f "%Lp" file2` != "777" ]; then
|
||||
atf_fail "existing files permissions not retained"
|
||||
fi
|
||||
}
|
||||
|
||||
file_to_file_preserve() {
|
||||
rm file3
|
||||
chmod 644 file
|
||||
chflags nodump file
|
||||
atf_check -s eq:0 -o empty -e empty cp -p file file3
|
||||
finfo=`stat -f "%p%u%g%m%z%f" file`
|
||||
f3info=`stat -f "%p%u%g%m%z%f" file3`
|
||||
if [ $finfo != $f3info ]; then
|
||||
atf_fail "attributes not preserved"
|
||||
fi
|
||||
}
|
||||
|
||||
file_to_file_noflags() {
|
||||
rm file3
|
||||
chmod 644 file
|
||||
chflags nodump file
|
||||
atf_check -s eq:0 -o empty -e empty cp -p -N file file3
|
||||
finfo=`stat -f "%f" file`
|
||||
f3info=`stat -f "%f" file3`
|
||||
if [ $finfo = $f3info ]; then
|
||||
atf_fail "-p -N preserved file flags"
|
||||
fi
|
||||
}
|
||||
|
||||
atf_test_case file_to_link
|
||||
file_to_link_head() {
|
||||
atf_set "descr" "Checks the copy of a file to a symbolic link"
|
||||
}
|
||||
file_to_link_body() {
|
||||
reset
|
||||
atf_check -s eq:0 -o empty -e empty cp file2 link
|
||||
cp_compare file_to_link file file2
|
||||
}
|
||||
|
||||
atf_test_case link_to_file
|
||||
link_to_file_head() {
|
||||
atf_set "descr" "Checks the copy of a symbolic link to a file"
|
||||
}
|
||||
link_to_file_body() {
|
||||
reset
|
||||
# file and link are identical (not copied).
|
||||
atf_check -s eq:1 -o empty -e ignore cp link file
|
||||
atf_check -s eq:0 -o empty -e empty cp link file2
|
||||
cp_compare link_to_file file file2
|
||||
}
|
||||
|
||||
atf_test_case file_over_link
|
||||
file_over_link_head() {
|
||||
atf_set "descr" "Checks the copy of a file to a symbolic link" \
|
||||
"without following it"
|
||||
}
|
||||
file_over_link_body() {
|
||||
reset
|
||||
atf_check -s eq:0 -o empty -e empty cp -P file link
|
||||
cp_compare file_over_link file link
|
||||
}
|
||||
|
||||
atf_test_case link_over_file
|
||||
link_over_file_head() {
|
||||
atf_set "descr" "Checks the copy of a symbolic link to a file" \
|
||||
"without following the former"
|
||||
}
|
||||
link_over_file_body() {
|
||||
reset
|
||||
atf_check -s eq:0 -o empty -e empty cp -P link file
|
||||
if [ `readlink link` != `readlink file` ]; then
|
||||
atf_fail "readlink link != readlink file"
|
||||
fi
|
||||
}
|
||||
|
||||
atf_test_case files_to_dir
|
||||
files_to_dir_head() {
|
||||
atf_set "descr" "Checks the copy of multiple files into a directory"
|
||||
}
|
||||
files_to_dir_body() {
|
||||
reset
|
||||
# can't copy multiple files to a file
|
||||
atf_check -s eq:1 -o empty -e ignore cp file file2 file3
|
||||
atf_check -s eq:0 -o empty -e empty cp file file2 link dir
|
||||
cp_compare files_to_dir file "dir/file"
|
||||
}
|
||||
|
||||
atf_test_case dir_to_file
|
||||
dir_to_file_head() {
|
||||
atf_set "descr" "Checks the copy of a directory onto a file, which" \
|
||||
"should not work"
|
||||
}
|
||||
dir_to_file_body() {
|
||||
reset
|
||||
# can't copy a dir onto a file
|
||||
atf_check -s eq:1 -o empty -e ignore cp dir file
|
||||
atf_check -s eq:1 -o empty -e ignore cp -R dir file
|
||||
}
|
||||
|
||||
atf_test_case file_to_linkdir
|
||||
file_to_linkdir_head() {
|
||||
atf_set "descr" "Checks the copy of a file to a symbolic link that" \
|
||||
"points to a directory"
|
||||
}
|
||||
file_to_linkdir_body() {
|
||||
reset
|
||||
atf_check -s eq:0 -o empty -e empty cp file dirlink
|
||||
cp_compare file_to_linkdir file "dir/file"
|
||||
|
||||
# overwrite the link
|
||||
atf_check -s eq:0 -o empty -e empty cp -P file dirlink
|
||||
atf_check -s eq:1 -o empty -e empty readlink dirlink
|
||||
cp_compare file_to_linkdir file dirlink
|
||||
}
|
||||
|
||||
atf_test_case linkdir_to_file
|
||||
linkdir_to_file_head() {
|
||||
atf_set "descr" "Checks the copy of a symbolic link that points to" \
|
||||
"a directory onto a file"
|
||||
}
|
||||
linkdir_to_file_body() {
|
||||
reset
|
||||
# cannot copy a dir onto a file
|
||||
atf_check -s eq:1 -o empty -e ignore cp dirlink file
|
||||
|
||||
# overwrite the link
|
||||
atf_check -s eq:0 -o empty -e empty cp -P dirlink file
|
||||
if [ `readlink file` != `readlink dirlink` ]; then
|
||||
atf_fail "readlink link != readlink file"
|
||||
fi
|
||||
}
|
||||
|
||||
dir_to_dne_no_R() {
|
||||
atf_check -s eq:1 -o empty -e ignore cp dir dir2
|
||||
}
|
||||
|
||||
dir_to_dne() {
|
||||
atf_check -s eq:0 -o empty -e empty cp -R dir dir2
|
||||
cp_compare dir_to_dne "dir/file" "dir2/file"
|
||||
readlink dir2/link >/dev/null
|
||||
if [ $? -gt 0 ]; then
|
||||
atf_fail "-R didn't copy a link as a link"
|
||||
fi
|
||||
}
|
||||
|
||||
dir_to_dir_H() {
|
||||
dir_to_dir_setup
|
||||
atf_check -s eq:0 -o empty -e empty cp -R dir dir2
|
||||
|
||||
chmod 777 dir
|
||||
|
||||
# copy a dir into a dir, only command-line links are followed
|
||||
atf_check -s eq:0 -o empty -e empty cp -R -H dirlink dir2
|
||||
cp_compare dir_to_dir_H "dir/file" "dir2/dirlink/file"
|
||||
readlink dir2/dirlink/link >/dev/null
|
||||
if [ $? -gt 0 ]; then
|
||||
atf_fail "didn't copy a link as a link"
|
||||
fi
|
||||
|
||||
# Created directories have the same mode as the corresponding
|
||||
# source directory, unmodified by the process's umask.
|
||||
if [ `stat -f "%Lp" dir2/dirlink` != "777" ]; then
|
||||
atf_fail "-R modified dir perms with umask"
|
||||
fi
|
||||
}
|
||||
|
||||
dir_to_dir_L() {
|
||||
dir_to_dir_setup
|
||||
atf_check -s eq:0 -o empty -e empty cp -R dir dir2
|
||||
atf_check -s eq:0 -o empty -e empty cp -R -H dirlink dir2
|
||||
|
||||
# copy a dir into a dir, following all links
|
||||
atf_check -s eq:0 -o empty -e empty cp -R -H -L dirlink dir2/dirlink
|
||||
cp_compare dir_to_dir_L "dir/file" "dir2/dirlink/dirlink/file"
|
||||
# fail if -R -L copied a link as a link
|
||||
atf_check -s eq:1 -o ignore -e empty readlink dir2/dirlink/dirlink/link
|
||||
}
|
||||
|
||||
dir_to_dir_subdir_exists() {
|
||||
# recursively copy a dir into another dir, with some subdirs already
|
||||
# existing
|
||||
cleanup
|
||||
|
||||
mkdir -p dir/1 dir/2 dir/3 target/2
|
||||
echo "file" > dir/2/file
|
||||
atf_check -s eq:0 -o empty -e empty cp -R dir/* target
|
||||
cp_compare dir_to_dir_subdir_exists "dir/2/file" "target/2/file"
|
||||
}
|
||||
|
||||
dir_to_dir_setup() {
|
||||
reset
|
||||
umask 077
|
||||
cp -P file file2 file3 link dir
|
||||
}
|
||||
|
||||
atf_test_case dir_to_dir
|
||||
dir_to_dir_head() {
|
||||
atf_set "descr" "Checks the copy of a directory onto another directory"
|
||||
}
|
||||
dir_to_dir_body() {
|
||||
dir_to_dir_setup
|
||||
dir_to_dne_no_R
|
||||
dir_to_dne
|
||||
dir_to_dir_H
|
||||
dir_to_dir_L
|
||||
dir_to_dir_subdir_exists
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case file_to_file
|
||||
atf_add_test_case file_to_link
|
||||
atf_add_test_case link_to_file
|
||||
atf_add_test_case file_over_link
|
||||
atf_add_test_case link_over_file
|
||||
atf_add_test_case files_to_dir
|
||||
atf_add_test_case file_to_linkdir
|
||||
atf_add_test_case linkdir_to_file
|
||||
atf_add_test_case dir_to_file
|
||||
atf_add_test_case dir_to_dir
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/dd
|
||||
TESTS_SH= t_dd
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,130 @@
|
||||
# $NetBSD: t_dd.sh,v 1.1 2012/03/17 16:33:11 jruoho 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
|
||||
}
|
||||
|
||||
allbits1="\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
|
||||
|
||||
ebcdicbits1="\000\001\002\003\067\055\056\057\026\005\045\013\014\015\016\017\020\021\022\023\074\075\062\046\030\031\077\047\034\035\036\037\100\132\177\173\133\154\120\175\115\135\134\116\153\140\113\141\360\361\362\363\364\365\366\367\370\371\172\136\114\176\156\157\174\301\302\303\304\305\306\307\310\311\321\322\323\324\325\326\327\330\331\342\343\344\345\346\347\350\351\255\340\275\232\155\171\201\202\203\204\205\206\207\210\211\221\222\223\224\225\226\227\230\231\242\243\244\245\246\247\250\251\300\117\320\137\007\040\041\042\043\044\025\006\027\050\051\052\053\054\011\012\033\060\061\032\063\064\065\066\010\070\071\072\073\004\024\076\341\101\102\103\104\105\106\107\110\111\121\122\123\124\125\126\127\130\131\142\143\144\145\146\147\150\151\160\161\162\163\164\165\166\167\170\200\212\213\214\215\216\217\220\152\233\234\235\236\237\240\252\253\254\112\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\241\276\277\312\313\314\315\316\317\332\333\334\335\336\337\352\353\354\355\356\357\372\373\374\375\376\377"
|
||||
|
||||
allvisbits=`echo -n "$allbits1" | unvis | vis`
|
||||
ebcdicvisbits=`echo -n "$ebcdicbits1" | unvis | vis`
|
||||
|
||||
atf_test_case io
|
||||
io_head() {
|
||||
atf_set "descr" "This checks the combination of bs= with" \
|
||||
"conv=ebcdic. Prior to revision 1.24 of dd's" \
|
||||
"args.c, the conv option would be ignored."
|
||||
}
|
||||
io_body() {
|
||||
test_dd_io "unvis | dd 2>/dev/null | vis" \
|
||||
"$allvisbits" "$allvisbits"
|
||||
test_dd_io "unvis | dd ibs=1 2>/dev/null | vis" \
|
||||
"$allvisbits" "$allvisbits"
|
||||
test_dd_io "unvis | dd obs=1 2>/dev/null | vis" \
|
||||
"$allvisbits" "$allvisbits"
|
||||
test_dd_io "unvis | dd bs=1 2>/dev/null | vis" \
|
||||
"$allvisbits" "$allvisbits"
|
||||
|
||||
test_dd_io "unvis | dd conv=ebcdic 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
test_dd_io "unvis | dd conv=ebcdic ibs=512 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
test_dd_io "unvis | dd conv=ebcdic obs=512 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
test_dd_io "unvis | dd conv=ebcdic bs=512 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
|
||||
test_dd_io "unvis | dd conv=ebcdic 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
test_dd_io "unvis | dd conv=ebcdic ibs=1 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
test_dd_io "unvis | dd conv=ebcdic obs=1 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
test_dd_io "unvis | dd conv=ebcdic bs=1 2>/dev/null | vis" \
|
||||
"$allvisbits" "$ebcdicvisbits"
|
||||
}
|
||||
|
||||
atf_test_case seek
|
||||
seek_head() {
|
||||
atf_set "descr" "Tests output file seeking"
|
||||
}
|
||||
|
||||
seek_body() {
|
||||
echo TEST1234 > testfile
|
||||
atf_check -s exit:0 -e ignore \
|
||||
dd if=/dev/zero of=testfile seek=1 bs=8k count=1
|
||||
atf_check -s exit:0 -e ignore -o match:'^TEST1234$' dd if=testfile
|
||||
eval $(stat -s testfile)
|
||||
atf_check_equal $st_size $((2*8192))
|
||||
|
||||
echo -n TEST1234 > tf2
|
||||
atf_check -s exit:0 -e ignore -x \
|
||||
'dd bs=4 if=/dev/zero count=1 | tr \\0 \\n | dd of=tf2 bs=4 seek=1'
|
||||
atf_check -s exit:0 -e ignore -o match:'^TEST$' dd if=tf2
|
||||
eval $(stat -s tf2)
|
||||
atf_check_equal $st_size 8
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case length
|
||||
atf_add_test_case io
|
||||
atf_add_test_case seek
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/df
|
||||
|
||||
TESTS_SH= t_df
|
||||
|
||||
BINDIR= ${TESTSDIR}
|
||||
PROG= h_df
|
||||
.PATH: ${NETBSDSRCDIR}/bin/df
|
||||
SRCS= df.c getmntinfo.c
|
||||
|
||||
LDADD+= -lutil
|
||||
DPADD+= ${LIBUTIL}
|
||||
|
||||
# Pass -DINTREE to make to test using humanize_number.c in source tree
|
||||
# directly instead of the one in libc.
|
||||
.if defined(INTREE)
|
||||
.PATH: ${NETBSDSRCDIR}/lib/libc/gen
|
||||
CPPFLAGS+= -I${NETBSDSRCDIR}/lib/libc/include
|
||||
SRCS+= humanize_number.c
|
||||
.endif
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,218 @@
|
||||
/* $NetBSD: getmntinfo.c,v 1.1 2012/03/17 16:33:11 jruoho 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.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define KB * 1024
|
||||
#define MB * 1024 KB
|
||||
#define GB * 1024 MB
|
||||
|
||||
static struct statvfs *getnewstatvfs(void);
|
||||
static void other_variants(const struct statvfs *, const int *, int,
|
||||
const int *, int);
|
||||
static void setup_filer(void);
|
||||
static void setup_ld0g(void);
|
||||
static void setup_strpct(void);
|
||||
|
||||
static struct statvfs *allstatvfs;
|
||||
static int sftotal, sfused;
|
||||
|
||||
struct statvfs *
|
||||
getnewstatvfs(void)
|
||||
{
|
||||
|
||||
if (sftotal == sfused) {
|
||||
sftotal = sftotal ? sftotal * 2 : 1;
|
||||
allstatvfs = realloc(allstatvfs,
|
||||
sftotal * sizeof(struct statvfs));
|
||||
if (allstatvfs == NULL)
|
||||
err(EXIT_FAILURE, "realloc");
|
||||
}
|
||||
|
||||
return (&allstatvfs[sfused++]);
|
||||
}
|
||||
|
||||
void
|
||||
other_variants(const struct statvfs *tmpl, const int *minfree, int minfreecnt,
|
||||
const int *consumed, int consumedcnt)
|
||||
{
|
||||
int64_t total, used;
|
||||
struct statvfs *sf;
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < minfreecnt; i++)
|
||||
for (j = 0; j < consumedcnt; j++) {
|
||||
sf = getnewstatvfs();
|
||||
*sf = *tmpl;
|
||||
total = (int64_t)(u_long)sf->f_blocks * sf->f_bsize;
|
||||
used = total * consumed[j] / 100;
|
||||
sf->f_bfree = (total - used) / sf->f_bsize;
|
||||
sf->f_bavail = (total * (100 - minfree[i]) / 100 -
|
||||
used) / (int)sf->f_bsize;
|
||||
sf->f_bresvd = sf->f_bfree - sf->f_bavail;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Parameter taken from:
|
||||
* http://mail-index.NetBSD.org/tech-userlevel/2004/03/24/0001.html
|
||||
*/
|
||||
void
|
||||
setup_filer(void)
|
||||
{
|
||||
static const struct statvfs tmpl = {
|
||||
#define BSIZE 512
|
||||
#define TOTAL 1147ULL GB
|
||||
#define USED 132ULL MB
|
||||
.f_bsize = BSIZE,
|
||||
.f_frsize = BSIZE,
|
||||
.f_blocks = TOTAL / BSIZE,
|
||||
.f_bfree = (TOTAL - USED) / BSIZE,
|
||||
.f_bavail = (TOTAL - USED) / BSIZE,
|
||||
.f_bresvd = 0,
|
||||
.f_mntfromname = "filer:/",
|
||||
.f_mntonname = "/filer",
|
||||
#undef USED
|
||||
#undef TOTAL
|
||||
#undef BSIZE
|
||||
};
|
||||
static const int minfree[] = { 0, 5, 10, 15, };
|
||||
static const int consumed[] = { 0, 20, 60, 95, 100 };
|
||||
|
||||
*getnewstatvfs() = tmpl;
|
||||
other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
|
||||
consumed, sizeof(consumed) / sizeof(consumed[0]));
|
||||
}
|
||||
|
||||
/*
|
||||
* Parameter taken from:
|
||||
* http://mail-index.NetBSD.org/current-users/2004/03/01/0038.html
|
||||
*/
|
||||
void
|
||||
setup_ld0g(void)
|
||||
{
|
||||
static const struct statvfs tmpl = {
|
||||
#define BSIZE 4096 /* Guess */
|
||||
#define TOTAL 1308726116ULL KB
|
||||
#define USED 17901268ULL KB
|
||||
#define AVAIL 1225388540ULL KB
|
||||
.f_bsize = BSIZE,
|
||||
.f_frsize = BSIZE,
|
||||
.f_blocks = TOTAL / BSIZE,
|
||||
.f_bfree = (TOTAL - USED) / BSIZE,
|
||||
.f_bavail = AVAIL / BSIZE,
|
||||
.f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE,
|
||||
.f_mntfromname = "/dev/ld0g",
|
||||
.f_mntonname = "/anon-root",
|
||||
#undef AVAIL
|
||||
#undef USED
|
||||
#undef TOTAL
|
||||
#undef BSIZE
|
||||
};
|
||||
static const int minfree[] = { 0, 5, 10, 15, };
|
||||
static const int consumed[] = { 0, 20, 60, 95, 100 };
|
||||
|
||||
*getnewstatvfs() = tmpl;
|
||||
other_variants(&tmpl, minfree, sizeof(minfree) / sizeof(minfree[0]),
|
||||
consumed, sizeof(consumed) / sizeof(consumed[0]));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test of strpct() with huge number.
|
||||
*/
|
||||
void
|
||||
setup_strpct(void)
|
||||
{
|
||||
static const struct statvfs tmpl = {
|
||||
#define BSIZE 4096 /* Guess */
|
||||
#define TOTAL 0x4ffffffffULL KB
|
||||
#define USED (TOTAL / 2)
|
||||
#define AVAIL (TOTAL / 2)
|
||||
.f_bsize = BSIZE,
|
||||
.f_frsize = BSIZE,
|
||||
.f_blocks = TOTAL / BSIZE,
|
||||
.f_bfree = (TOTAL - USED) / BSIZE,
|
||||
.f_bavail = AVAIL / BSIZE,
|
||||
.f_bresvd = (TOTAL - USED) / BSIZE - AVAIL / BSIZE,
|
||||
.f_mntfromname = "/dev/strpct",
|
||||
.f_mntonname = "/strpct",
|
||||
#undef AVAIL
|
||||
#undef USED
|
||||
#undef TOTAL
|
||||
#undef BSIZE
|
||||
};
|
||||
|
||||
*getnewstatvfs() = tmpl;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parameter taken from:
|
||||
* http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=23600
|
||||
*/
|
||||
static void
|
||||
setup_pr23600(void)
|
||||
{
|
||||
static const struct statvfs tmpl = {
|
||||
#define BSIZE 512
|
||||
#define TOTAL 20971376ULL
|
||||
#define USED 5719864ULL
|
||||
#define AVAIL 15251512ULL
|
||||
.f_bsize = BSIZE,
|
||||
.f_frsize = BSIZE,
|
||||
.f_blocks = TOTAL,
|
||||
.f_bfree = TOTAL - USED,
|
||||
.f_bavail = AVAIL,
|
||||
.f_bresvd = TOTAL - USED - AVAIL,
|
||||
.f_mntfromname = "/dev/wd0e",
|
||||
.f_mntonname = "/mount/windows/C",
|
||||
#undef AVAIL
|
||||
#undef USED
|
||||
#undef TOTAL
|
||||
#undef BSIZE
|
||||
};
|
||||
|
||||
*getnewstatvfs() = tmpl;
|
||||
}
|
||||
|
||||
int
|
||||
getmntinfo(struct statvfs **mntbuf, int flags)
|
||||
{
|
||||
|
||||
setup_filer();
|
||||
setup_ld0g();
|
||||
setup_strpct();
|
||||
setup_pr23600();
|
||||
|
||||
*mntbuf = allstatvfs;
|
||||
return (sfused);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
# $NetBSD: t_df.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2007, 2008 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.
|
||||
#
|
||||
|
||||
atf_test_case normal
|
||||
normal_head() {
|
||||
atf_set "descr" "Checks that the output of df without flags is" \
|
||||
"correct according to some already-known, sane" \
|
||||
"output"
|
||||
}
|
||||
normal_body() {
|
||||
cat >expout <<EOF
|
||||
Filesystem 1K-blocks Used Avail %Cap Mounted on
|
||||
filer:/ 1202716672 135168 1202581504 0% /filer
|
||||
filer:/ 1202716672 0 1202716672 0% /filer
|
||||
filer:/ 1202716672 240543334 962173337 20% /filer
|
||||
filer:/ 1202716672 721630003 481086668 60% /filer
|
||||
filer:/ 1202716672 1142580838 60135833 95% /filer
|
||||
filer:/ 1202716672 1202716672 0 100% /filer
|
||||
filer:/ 1202716672 0 1142580838 0% /filer
|
||||
filer:/ 1202716672 240543334 902037504 21% /filer
|
||||
filer:/ 1202716672 721630003 420950835 63% /filer
|
||||
filer:/ 1202716672 1142580838 0 100% /filer
|
||||
filer:/ 1202716672 1202716672 -60135833 105% /filer
|
||||
filer:/ 1202716672 0 1082445004 0% /filer
|
||||
filer:/ 1202716672 240543334 841901670 22% /filer
|
||||
filer:/ 1202716672 721630003 360815001 66% /filer
|
||||
filer:/ 1202716672 1142580838 -60135833 105% /filer
|
||||
filer:/ 1202716672 1202716672 -120271667 111% /filer
|
||||
filer:/ 1202716672 0 1022309171 0% /filer
|
||||
filer:/ 1202716672 240543334 781765836 23% /filer
|
||||
filer:/ 1202716672 721630003 300679168 70% /filer
|
||||
filer:/ 1202716672 1142580838 -120271667 111% /filer
|
||||
filer:/ 1202716672 1202716672 -180407500 117% /filer
|
||||
/dev/ld0g 1308726116 17901268 1225388540 1% /anon-root
|
||||
/dev/ld0g 1308726116 0 1308726116 0% /anon-root
|
||||
/dev/ld0g 1308726116 261745224 1046980892 20% /anon-root
|
||||
/dev/ld0g 1308726116 785235672 523490444 60% /anon-root
|
||||
/dev/ld0g 1308726116 1243289812 65436304 95% /anon-root
|
||||
/dev/ld0g 1308726116 1308726116 0 100% /anon-root
|
||||
/dev/ld0g 1308726116 0 1243289808 0% /anon-root
|
||||
/dev/ld0g 1308726116 261745224 981544584 21% /anon-root
|
||||
/dev/ld0g 1308726116 785235672 458054140 63% /anon-root
|
||||
/dev/ld0g 1308726116 1243289812 0 100% /anon-root
|
||||
/dev/ld0g 1308726116 1308726116 -65436304 105% /anon-root
|
||||
/dev/ld0g 1308726116 0 1177853504 0% /anon-root
|
||||
/dev/ld0g 1308726116 261745224 916108280 22% /anon-root
|
||||
/dev/ld0g 1308726116 785235672 392617832 66% /anon-root
|
||||
/dev/ld0g 1308726116 1243289812 -65436304 105% /anon-root
|
||||
/dev/ld0g 1308726116 1308726116 -130872608 111% /anon-root
|
||||
/dev/ld0g 1308726116 0 1112417196 0% /anon-root
|
||||
/dev/ld0g 1308726116 261745224 850671972 23% /anon-root
|
||||
/dev/ld0g 1308726116 785235672 327181528 70% /anon-root
|
||||
/dev/ld0g 1308726116 1243289812 -130872608 111% /anon-root
|
||||
/dev/ld0g 1308726116 1308726116 -196308916 117% /anon-root
|
||||
/dev/strpct 21474836476 10737418240 10737418236 50% /strpct
|
||||
/dev/wd0e 10485688 2859932 7625756 27% /mount/windows/C
|
||||
EOF
|
||||
atf_check -s eq:0 -o file:expout -e empty \
|
||||
-x "BLOCKSIZE=1k $(atf_get_srcdir)/h_df -n"
|
||||
}
|
||||
|
||||
atf_test_case hflag
|
||||
hflag_head() {
|
||||
atf_set "descr" "Checks that the output of df is correct according" \
|
||||
"to some already-known, sane output when using the" \
|
||||
"human readable format"
|
||||
}
|
||||
hflag_body() {
|
||||
cat >expout <<EOF
|
||||
Filesystem Size Used Avail %Cap Mounted on
|
||||
filer:/ 1.1T 132M 1.1T 0% /filer
|
||||
filer:/ 1.1T 0B 1.1T 0% /filer
|
||||
filer:/ 1.1T 229G 918G 20% /filer
|
||||
filer:/ 1.1T 688G 459G 60% /filer
|
||||
filer:/ 1.1T 1.1T 57G 95% /filer
|
||||
filer:/ 1.1T 1.1T 0B 100% /filer
|
||||
filer:/ 1.1T 0B 1.1T 0% /filer
|
||||
filer:/ 1.1T 229G 860G 21% /filer
|
||||
filer:/ 1.1T 688G 401G 63% /filer
|
||||
filer:/ 1.1T 1.1T 0B 100% /filer
|
||||
filer:/ 1.1T 1.1T -57G 105% /filer
|
||||
filer:/ 1.1T 0B 1.0T 0% /filer
|
||||
filer:/ 1.1T 229G 803G 22% /filer
|
||||
filer:/ 1.1T 688G 344G 66% /filer
|
||||
filer:/ 1.1T 1.1T -57G 105% /filer
|
||||
filer:/ 1.1T 1.1T -115G 111% /filer
|
||||
filer:/ 1.1T 0B 975G 0% /filer
|
||||
filer:/ 1.1T 229G 746G 23% /filer
|
||||
filer:/ 1.1T 688G 287G 70% /filer
|
||||
filer:/ 1.1T 1.1T -115G 111% /filer
|
||||
filer:/ 1.1T 1.1T -172G 117% /filer
|
||||
/dev/ld0g 1.2T 17G 1.1T 1% /anon-root
|
||||
/dev/ld0g 1.2T 0B 1.2T 0% /anon-root
|
||||
/dev/ld0g 1.2T 250G 998G 20% /anon-root
|
||||
/dev/ld0g 1.2T 749G 499G 60% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T 62G 95% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T 0B 100% /anon-root
|
||||
/dev/ld0g 1.2T 0B 1.2T 0% /anon-root
|
||||
/dev/ld0g 1.2T 250G 936G 21% /anon-root
|
||||
/dev/ld0g 1.2T 749G 437G 63% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T 0B 100% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T -62G 105% /anon-root
|
||||
/dev/ld0g 1.2T 0B 1.1T 0% /anon-root
|
||||
/dev/ld0g 1.2T 250G 874G 22% /anon-root
|
||||
/dev/ld0g 1.2T 749G 374G 66% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T -62G 105% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T -125G 111% /anon-root
|
||||
/dev/ld0g 1.2T 0B 1.0T 0% /anon-root
|
||||
/dev/ld0g 1.2T 250G 811G 23% /anon-root
|
||||
/dev/ld0g 1.2T 749G 312G 70% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T -125G 111% /anon-root
|
||||
/dev/ld0g 1.2T 1.2T -187G 117% /anon-root
|
||||
/dev/strpct 20T 10T 10T 50% /strpct
|
||||
/dev/wd0e 10G 2.7G 7.3G 27% /mount/windows/C
|
||||
EOF
|
||||
atf_check -s eq:0 -o file:expout -e empty \
|
||||
-x "BLOCKSIZE=1k $(atf_get_srcdir)/h_df -hn"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case normal
|
||||
atf_add_test_case hflag
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/expr
|
||||
TESTS_SH= t_expr
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,228 @@
|
||||
# $NetBSD: t_expr.sh,v 1.3 2012/03/27 07:23:06 jruoho 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.
|
||||
#
|
||||
|
||||
# The first arg will get eval'd so escape any meta characters
|
||||
# The 2nd arg is an expected string/response from expr for that op.
|
||||
test_expr() {
|
||||
echo "Expression '${1}', expecting '${2}'"
|
||||
res=`eval expr $1 2>&1`
|
||||
if [ "$res" != "$2" ]; then
|
||||
atf_fail "Expected $2, got $res from expression: " \
|
||||
"`eval echo $1`"
|
||||
fi
|
||||
}
|
||||
|
||||
atf_test_case lang
|
||||
lang_ops_head() {
|
||||
atf_set "descr" "Test that expr(1) works with non-C LANG (PR bin/2486)"
|
||||
}
|
||||
lang_body() {
|
||||
|
||||
export LANG=nonexistent
|
||||
atf_check -s exit:0 -o inline:"21\n" -e empty -x "expr 10 + 11"
|
||||
|
||||
export LANG=ru_RU.KOI8-R
|
||||
atf_check -s exit:0 -o inline:"21\n" -e empty -x "expr 10 + 11"
|
||||
}
|
||||
|
||||
atf_test_case overflow
|
||||
overflow_head() {
|
||||
atf_set "descr" "Test overflow cases"
|
||||
}
|
||||
overflow_body() {
|
||||
test_expr '4611686018427387904 + 4611686018427387903' \
|
||||
'9223372036854775807'
|
||||
test_expr '4611686018427387904 + 4611686018427387904' \
|
||||
"expr: integer overflow or underflow occurred for operation '4611686018427387904 + 4611686018427387904'"
|
||||
test_expr '4611686018427387904 - -4611686018427387904' \
|
||||
"expr: integer overflow or underflow occurred for operation '4611686018427387904 - -4611686018427387904'"
|
||||
test_expr '-4611686018427387904 - 4611686018427387903' \
|
||||
'-9223372036854775807'
|
||||
test_expr '-4611686018427387904 - 4611686018427387905' \
|
||||
"expr: integer overflow or underflow occurred for operation '-4611686018427387904 - 4611686018427387905'"
|
||||
test_expr '-4611686018427387904 \* 1' '-4611686018427387904'
|
||||
test_expr '-4611686018427387904 \* -1' '4611686018427387904'
|
||||
test_expr '-4611686018427387904 \* 2' '-9223372036854775808'
|
||||
test_expr '-4611686018427387904 \* 3' \
|
||||
"expr: integer overflow or underflow occurred for operation '-4611686018427387904 * 3'"
|
||||
test_expr '-4611686018427387904 \* -2' \
|
||||
"expr: integer overflow or underflow occurred for operation '-4611686018427387904 * -2'"
|
||||
test_expr '4611686018427387904 \* 1' '4611686018427387904'
|
||||
test_expr '4611686018427387904 \* 2' \
|
||||
"expr: integer overflow or underflow occurred for operation '4611686018427387904 * 2'"
|
||||
test_expr '4611686018427387904 \* 3' \
|
||||
"expr: integer overflow or underflow occurred for operation '4611686018427387904 * 3'"
|
||||
}
|
||||
|
||||
atf_test_case gtkmm
|
||||
gtkmm_head() {
|
||||
atf_set "descr" "Test from gtk-- configure that cause problems on old expr"
|
||||
}
|
||||
gtkmm_body() {
|
||||
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
|
||||
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '0'
|
||||
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 3 \& 5 \>= 5' '0'
|
||||
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 2 \& 4 = 4 \& 5 \>= 5' '0'
|
||||
test_expr '3 \> 2 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '1'
|
||||
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 3 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
|
||||
}
|
||||
|
||||
atf_test_case colon_vs_math
|
||||
colon_vs_math_head() {
|
||||
atf_set "descr" "Basic precendence test with the : operator vs. math"
|
||||
}
|
||||
colon_vs_math_body() {
|
||||
test_expr '2 : 4 / 2' '0'
|
||||
test_expr '4 : 4 % 3' '1'
|
||||
}
|
||||
|
||||
atf_test_case arithmetic_ops
|
||||
arithmetic_ops_head() {
|
||||
atf_set "descr" "Dangling arithemtic operator"
|
||||
}
|
||||
arithmetic_ops_body() {
|
||||
test_expr '.java_wrapper : /' '0'
|
||||
test_expr '4 : \*' '0'
|
||||
test_expr '4 : +' '0'
|
||||
test_expr '4 : -' '0'
|
||||
test_expr '4 : /' '0'
|
||||
test_expr '4 : %' '0'
|
||||
}
|
||||
|
||||
atf_test_case basic_math
|
||||
basic_math_head() {
|
||||
atf_set "descr" "Basic math test"
|
||||
}
|
||||
basic_math_body() {
|
||||
test_expr '2 + 4 \* 5' '22'
|
||||
}
|
||||
|
||||
atf_test_case basic_functional
|
||||
basic_functional_head() {
|
||||
atf_set "descr" "Basic functional tests"
|
||||
}
|
||||
basic_functional_body() {
|
||||
test_expr '2' '2'
|
||||
test_expr '-4' '-4'
|
||||
test_expr 'hello' 'hello'
|
||||
}
|
||||
|
||||
atf_test_case compare_ops_precedence
|
||||
compare_ops_precedence_head() {
|
||||
atf_set "descr" "Compare operator precendence test"
|
||||
}
|
||||
compare_ops_precedence_body() {
|
||||
test_expr '2 \> 1 \* 17' '0'
|
||||
}
|
||||
|
||||
atf_test_case compare_ops
|
||||
compare_ops_head() {
|
||||
atf_set "descr" "Compare operator tests"
|
||||
}
|
||||
compare_ops_body() {
|
||||
test_expr '2 \!= 5' '1'
|
||||
test_expr '2 \!= 2' '0'
|
||||
test_expr '2 \<= 3' '1'
|
||||
test_expr '2 \<= 2' '1'
|
||||
test_expr '2 \<= 1' '0'
|
||||
test_expr '2 \< 3' '1'
|
||||
test_expr '2 \< 2' '0'
|
||||
test_expr '2 = 2' '1'
|
||||
test_expr '2 = 4' '0'
|
||||
test_expr '2 \>= 1' '1'
|
||||
test_expr '2 \>= 2' '1'
|
||||
test_expr '2 \>= 3' '0'
|
||||
test_expr '2 \> 1' '1'
|
||||
test_expr '2 \> 2' '0'
|
||||
}
|
||||
|
||||
atf_test_case multiply
|
||||
multiply_head() {
|
||||
atf_set "descr" "Test the multiply operator (PR bin/12838)"
|
||||
}
|
||||
multiply_body() {
|
||||
test_expr '1 \* -1' '-1'
|
||||
test_expr '2 \> 1 \* 17' '0'
|
||||
}
|
||||
|
||||
atf_test_case negative
|
||||
negative_head() {
|
||||
atf_set "descr" "Test the additive inverse"
|
||||
}
|
||||
negative_body() {
|
||||
test_expr '-1 + 5' '4'
|
||||
test_expr '- 1 + 5' 'expr: syntax error'
|
||||
|
||||
test_expr '5 + -1' '4'
|
||||
test_expr '5 + - 1' 'expr: syntax error'
|
||||
|
||||
test_expr '1 - -5' '6'
|
||||
}
|
||||
|
||||
atf_test_case math_precedence
|
||||
math_precedence_head() {
|
||||
atf_set "descr" "More complex math test for precedence"
|
||||
}
|
||||
math_precedence_body() {
|
||||
test_expr '-3 + -1 \* 4 + 3 / -6' '-7'
|
||||
}
|
||||
|
||||
atf_test_case precedence
|
||||
precedence_head() {
|
||||
atf_set "descr" "Test precedence"
|
||||
}
|
||||
precedence_body() {
|
||||
# This is messy but the shell escapes cause that
|
||||
test_expr 'X1/2/3 : X\\\(.\*[^/]\\\)//\*[^/][^/]\*/\*$ \| . : \\\(.\\\)' '1/2'
|
||||
}
|
||||
|
||||
atf_test_case regex
|
||||
regex_head() {
|
||||
atf_set "descr" "Test proper () returning \1 from a regex"
|
||||
}
|
||||
regex_body() {
|
||||
# This is messy but the shell escapes cause that
|
||||
test_expr '1/2 : .\*/\\\(.\*\\\)' '2'
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case lang
|
||||
atf_add_test_case overflow
|
||||
atf_add_test_case gtkmm
|
||||
atf_add_test_case colon_vs_math
|
||||
atf_add_test_case arithmetic_ops
|
||||
atf_add_test_case basic_math
|
||||
atf_add_test_case basic_functional
|
||||
atf_add_test_case compare_ops_precedence
|
||||
atf_add_test_case compare_ops
|
||||
atf_add_test_case multiply
|
||||
atf_add_test_case negative
|
||||
atf_add_test_case math_precedence
|
||||
atf_add_test_case precedence
|
||||
atf_add_test_case regex
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/pax
|
||||
TESTS_SH= t_pax
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,54 @@
|
||||
# $NetBSD: t_pax.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2007, 2008 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.
|
||||
#
|
||||
|
||||
atf_test_case append
|
||||
append_head() {
|
||||
atf_set "descr" "Ensure that appending a file to an archive" \
|
||||
"produces the same results as if the file" \
|
||||
"had been there during the archive's creation"
|
||||
}
|
||||
append_body() {
|
||||
touch foo bar
|
||||
|
||||
# store both foo and bar into file1.tar
|
||||
atf_check -s eq:0 -o empty -e empty \
|
||||
pax -w -b 512 -x ustar -f file1.tar foo bar
|
||||
|
||||
# store foo into file2.tar, then append bar to file2.tar
|
||||
atf_check -s eq:0 -o empty -e empty \
|
||||
pax -w -b 512 -x ustar -f file2.tar foo
|
||||
atf_check -s eq:0 -o empty -e empty \
|
||||
pax -w -b 512 -x ustar -f file2.tar -a bar
|
||||
|
||||
# ensure that file1.tar and file2.tar are equal
|
||||
atf_check -s eq:0 -o empty -e empty cmp file1.tar file2.tar
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case append
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/ps
|
||||
|
||||
TESTS_SH= t_ps
|
||||
|
||||
FILESDIR= ${TESTSDIR}
|
||||
FILES= keywords
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,122 @@
|
||||
# $NetBSD: keywords,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
#
|
||||
# Table of keywords for use with ps "-o" option.
|
||||
#
|
||||
# The first column (keyword) is the name of a keyword.
|
||||
#
|
||||
# The second column (header) is the default column header associated
|
||||
# with the keyword, except if the keyword is an alias, in which case the
|
||||
# second column is the name of another keyword.
|
||||
#
|
||||
# The third column (flag) may be blank, "LJUST", or "ALIAS". "ALIAS"
|
||||
# means that the keyword is an alias. "LJUST" means that the keyword
|
||||
# should be displayed in a left-justified column. The default is that
|
||||
# the keyword should be displayed in a right-justified column.
|
||||
#
|
||||
# keyword header flag
|
||||
#
|
||||
ktracep KTRACEP
|
||||
nwchan WCHAN
|
||||
p_ru P_RU
|
||||
paddr PADDR
|
||||
rlink RLINK
|
||||
%cpu %CPU
|
||||
%mem %MEM
|
||||
acflag ACFLG
|
||||
acflg acflag ALIAS
|
||||
args command ALIAS
|
||||
blocked sigmask ALIAS
|
||||
caught sigcatch ALIAS
|
||||
comm COMMAND LJUST
|
||||
command COMMAND LJUST
|
||||
cpu CPU
|
||||
cputime time ALIAS
|
||||
ctime CTIME
|
||||
egid EGID
|
||||
egroup EGROUP LJUST
|
||||
etime ELAPSED
|
||||
euid EUID
|
||||
euser EUSER LJUST
|
||||
f F
|
||||
flags f ALIAS
|
||||
gid GID
|
||||
group GROUP LJUST
|
||||
groupnames GROUPNAMES LJUST
|
||||
groups GROUPS LJUST
|
||||
holdcnt HOLDCNT
|
||||
ignored sigignore ALIAS
|
||||
inblk INBLK
|
||||
inblock inblk ALIAS
|
||||
jobc JOBC
|
||||
ktrace KTRACE
|
||||
laddr LADDR
|
||||
lid LID
|
||||
lim LIM
|
||||
login LOGIN LJUST
|
||||
logname login ALIAS
|
||||
lstart STARTED LJUST
|
||||
lstate STAT LJUST
|
||||
majflt MAJFLT
|
||||
minflt MINFLT
|
||||
msgrcv MSGRCV
|
||||
msgsnd MSGSND
|
||||
ni nice ALIAS
|
||||
nice NI
|
||||
nivcsw NIVCSW
|
||||
nlwp NLWP
|
||||
nsignals nsigs ALIAS
|
||||
nsigs NSIGS
|
||||
nswap NSWAP
|
||||
nvcsw NVCSW
|
||||
oublk OUBLK
|
||||
oublock oublk ALIAS
|
||||
pagein PAGEIN
|
||||
pcpu %cpu ALIAS
|
||||
pending sig ALIAS
|
||||
pgid PGID
|
||||
pid PID
|
||||
pmem %mem ALIAS
|
||||
ppid PPID
|
||||
pri PRI
|
||||
re RE
|
||||
rgid RGID
|
||||
rgroup RGROUP LJUST
|
||||
rlwp RLWP
|
||||
rss RSS
|
||||
rssize rsz ALIAS
|
||||
rsz RSZ
|
||||
ruid RUID
|
||||
ruser RUSER LJUST
|
||||
sess SESS
|
||||
sid SID
|
||||
sig PENDING
|
||||
sigcatch CAUGHT
|
||||
sigignore IGNORED
|
||||
sigmask BLOCKED
|
||||
sl SL
|
||||
start STARTED
|
||||
stat state ALIAS
|
||||
state STAT LJUST
|
||||
stime STIME
|
||||
svgid SVGID
|
||||
svgroup SVGROUP LJUST
|
||||
svuid SVUID
|
||||
svuser SVUSER LJUST
|
||||
tdev TDEV
|
||||
time TIME
|
||||
tpgid TPGID
|
||||
tsess TSESS
|
||||
tsiz TSIZ
|
||||
tt TTY LJUST
|
||||
tty TTY LJUST
|
||||
uaddr UADDR
|
||||
ucomm UCOMM LJUST
|
||||
uid UID
|
||||
upr UPR
|
||||
user USER LJUST
|
||||
usrpri upr ALIAS
|
||||
utime UTIME
|
||||
vsize vsz ALIAS
|
||||
vsz VSZ
|
||||
wchan WCHAN LJUST
|
||||
xstat XSTAT
|
||||
@@ -0,0 +1,404 @@
|
||||
# $NetBSD: t_ps.sh,v 1.1 2012/03/17 16:33:11 jruoho 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.
|
||||
#
|
||||
|
||||
# the implementation of "ps" to test
|
||||
: ${TEST_PS:="ps"}
|
||||
# tab and newline characters
|
||||
tab="$(printf '\t')"
|
||||
# nl="$(printf '\n')" doesn't work
|
||||
nl='
|
||||
'
|
||||
|
||||
#
|
||||
# Parse the "keywords" file into a load of shell variables
|
||||
#
|
||||
setup_keywords()
|
||||
{
|
||||
# Set variables representing the header text
|
||||
# for all normal keywords (except aliases), and
|
||||
# for regular expressions to match the text in left- or
|
||||
# right-justified columns.
|
||||
# For example, head_text_p_cpu="%CPU" head_regexp_p_cpu=" *%CPU".
|
||||
while read keyword heading flag
|
||||
do
|
||||
case "$keyword" in
|
||||
''|\#*) continue
|
||||
;;
|
||||
esac
|
||||
[ x"$flag" = x"ALIAS" ] && continue
|
||||
kvar="${keyword}"
|
||||
case "${keyword}" in
|
||||
%*) kvar="p_${keyword#%}"
|
||||
;;
|
||||
esac
|
||||
eval head_text_${kvar}=\'"${heading}"\'
|
||||
case "${flag}" in
|
||||
'') # right justified
|
||||
eval head_regexp_${kvar}=\'" *${heading}"\'
|
||||
;;
|
||||
LJUST) # left justified
|
||||
eval head_regexp_${kvar}=\'"${heading} *"\'
|
||||
;;
|
||||
*) atf_fail "unknown flag in keywords"
|
||||
;;
|
||||
esac
|
||||
done <"$(atf_get_srcdir)/keywords"
|
||||
|
||||
# Now do the aliases.
|
||||
while read keyword heading flag
|
||||
do
|
||||
case "$keyword" in
|
||||
''|\#*) continue
|
||||
;;
|
||||
esac
|
||||
[ x"$flag" != x"ALIAS" ] && continue
|
||||
kvar="${keyword}"
|
||||
avar="${heading}"
|
||||
case "${keyword}" in
|
||||
%*) kvar="p_${keyword#%}"
|
||||
;;
|
||||
esac
|
||||
case "${heading}" in
|
||||
%*) avar="p_${heading#%}"
|
||||
;;
|
||||
esac
|
||||
eval head_text_${kvar}=\"\$head_text_${avar}\"
|
||||
eval head_regexp_${kvar}=\"\$head_regexp_${avar}\"
|
||||
done <"$(atf_get_srcdir)/keywords"
|
||||
|
||||
# default sets of keywords
|
||||
default_keywords='pid tty stat time command'
|
||||
j_keywords='user pid ppid pgid sess jobc state tt time command'
|
||||
l_keywords='uid pid ppid cpu pri nice vsz rss wchan state tt time command'
|
||||
s_keywords='uid pid ppid cpu lid nlwp pri nice vsz rss wchan lstate tt time command'
|
||||
u_keywords='user pid %cpu %mem vsz rss tt state start time command'
|
||||
v_keywords='pid state time sl re pagein vsz rss lim tsiz %cpu %mem command'
|
||||
}
|
||||
|
||||
# Convert a list of keywords like "pid comm" to a regexp
|
||||
# like " *PID COMMAND *"
|
||||
heading_keywords_to_regexp()
|
||||
{
|
||||
local keywords="$1"
|
||||
local regexp
|
||||
regexp="$(echo "$keywords" | \
|
||||
sed -E -e 's/\%/p_/g' -e 's/(^| )/\1\$head_regexp_/g')"
|
||||
eval regexp=\""${regexp}"\"
|
||||
regexp="^${regexp}\$"
|
||||
echo "$regexp"
|
||||
}
|
||||
|
||||
#
|
||||
# Check that a string matches a regexp; use the specified id
|
||||
# in error or success messages.
|
||||
#
|
||||
check_regexp() {
|
||||
local id="$1" string="$2" regexp="$3"
|
||||
if ! expr "$string" : "$regexp" >/dev/null
|
||||
then
|
||||
atf_fail "${id}: expected [${regexp}], got [${string}]"
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Run "ps $args -p $$"; check that only one line is printed,
|
||||
# without a preceding header line.
|
||||
#
|
||||
check_no_heading_line()
|
||||
{
|
||||
local args="$1"
|
||||
local output="$(eval "${TEST_PS} $args -p $$")"
|
||||
case "$output" in
|
||||
*"$nl"*)
|
||||
local firstline="${output%%${nl}*}"
|
||||
atf_fail "check_no_heading_line [$args] got [$firstline]"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
#
|
||||
# Run "ps $args"; check that the heading matches the expected regexp.
|
||||
#
|
||||
check_heading_regexp()
|
||||
{
|
||||
args="$1"
|
||||
regexp="$2"
|
||||
actual="$( eval "${TEST_PS} $args" | sed -e 1q )"
|
||||
check_regexp "heading [$args]" "${actual}" "${regexp}"
|
||||
}
|
||||
|
||||
#
|
||||
# Run "ps $args"; check that the heading matches a regexp constructed
|
||||
# from the specified keywords.
|
||||
#
|
||||
check_heading_keywords()
|
||||
{
|
||||
args="$1"
|
||||
keywords="$2"
|
||||
check_heading_regexp "$args" "$(heading_keywords_to_regexp "$keywords")"
|
||||
}
|
||||
|
||||
#
|
||||
# Try several variations on "ps $flag", "ps -$flag", etc.,
|
||||
# and check that the heading always has the correct keywords.
|
||||
#
|
||||
check_heading_variations()
|
||||
{
|
||||
flag="$1"
|
||||
keywords="$2"
|
||||
for args in "$flag" "-$flag" "-$flag$flag -$flag"; do
|
||||
check_heading_keywords "$args" "$keywords"
|
||||
done
|
||||
}
|
||||
|
||||
atf_test_case default_columns
|
||||
default_columns_head()
|
||||
{
|
||||
atf_set "descr" "Checks that the default set of columns is correct" \
|
||||
"and also check that the columns printed by the -j," \
|
||||
"-l, -s, -u and -v flags alone are correct"
|
||||
}
|
||||
default_columns_body()
|
||||
{
|
||||
setup_keywords
|
||||
check_heading_keywords '' "$default_keywords"
|
||||
check_heading_variations 'j' "$j_keywords"
|
||||
check_heading_variations 'l' "$l_keywords"
|
||||
check_heading_variations 's' "$s_keywords"
|
||||
check_heading_variations 'u' "$u_keywords"
|
||||
check_heading_variations 'v' "$v_keywords"
|
||||
}
|
||||
|
||||
atf_test_case minus_O
|
||||
minus_O_head()
|
||||
{
|
||||
atf_set "descr" "Checks that 'ps -O foo' inserts columns just after" \
|
||||
"the pid column"
|
||||
}
|
||||
minus_O_body()
|
||||
{
|
||||
setup_keywords
|
||||
check_heading_keywords '-O %cpu,%mem' \
|
||||
"$(echo "${default_keywords}" | sed -e 's/pid/pid %cpu %mem/')"
|
||||
check_heading_keywords '-O %cpu -O %mem' \
|
||||
"$(echo "${default_keywords}" | sed -e 's/pid/pid %cpu %mem/')"
|
||||
check_heading_keywords '-O%cpu -O%mem' \
|
||||
"$(echo "${default_keywords}" | sed -e 's/pid/pid %cpu %mem/')"
|
||||
}
|
||||
|
||||
atf_test_case minus_o
|
||||
minus_o_head()
|
||||
{
|
||||
atf_set "descr" "Checks simple cases of 'ps -o foo' to control which" \
|
||||
"columns are printed; this does not test header" \
|
||||
"overriding via 'ps -o foo=BAR'"
|
||||
}
|
||||
minus_o_body()
|
||||
{
|
||||
setup_keywords
|
||||
# Keywords for "-o name" override the default display
|
||||
check_heading_keywords '-o pid,%cpu,%mem' \
|
||||
"pid %cpu %mem"
|
||||
check_heading_keywords '-o pid -o %cpu,%mem' \
|
||||
"pid %cpu %mem"
|
||||
check_heading_keywords '-opid -o %cpu,%mem' \
|
||||
"pid %cpu %mem"
|
||||
# Space works like comma
|
||||
check_heading_keywords '-opid -o "%cpu %mem"' \
|
||||
"pid %cpu %mem"
|
||||
# Check missing pid
|
||||
check_heading_keywords '-o comm' \
|
||||
"comm"
|
||||
# Check pid present but not first
|
||||
check_heading_keywords '-o comm,pid' \
|
||||
"comm pid"
|
||||
}
|
||||
|
||||
atf_test_case override_heading_simple
|
||||
override_heading_simple_head()
|
||||
{
|
||||
atf_set "descr" "Tests simple uses of header overriding via" \
|
||||
"'ps -o foo=BAR'. This does not test columns " \
|
||||
"with null headings, or headings with embedded" \
|
||||
"space, ',' or '='."
|
||||
}
|
||||
override_heading_simple_body()
|
||||
{
|
||||
setup_keywords
|
||||
check_heading_regexp '-o pid=PPP -o comm' \
|
||||
'^ *PPP '"${head_text_comm}"'$' # no trailing space
|
||||
check_heading_regexp '-o pid=PPP -o comm=CCC' \
|
||||
'^ *PPP CCC$'
|
||||
check_heading_regexp '-o pid,comm=CCC' \
|
||||
'^'"${head_regexp_pid}"' CCC$'
|
||||
check_heading_regexp '-o pid -o comm=CCC' \
|
||||
'^'"${head_regexp_pid}"' CCC$'
|
||||
# Check missing pid
|
||||
check_heading_regexp '-o comm=CCC' \
|
||||
'^CCC$'
|
||||
# Check pid present but not first
|
||||
check_heading_regexp '-o comm=CCC -o pid=PPP' \
|
||||
'^CCC *PPP$'
|
||||
check_heading_regexp '-o comm,pid=PPP' \
|
||||
'^'"${head_regexp_comm}"' *PPP$'
|
||||
}
|
||||
|
||||
atf_test_case override_heading_embedded_specials
|
||||
override_heading_embedded_specials_head()
|
||||
{
|
||||
atf_set "descr" "Tests header overriding with embedded space," \
|
||||
"',' or '='. Everything after the first '='" \
|
||||
"is part of the heading."
|
||||
}
|
||||
override_heading_embedded_specials_body()
|
||||
{
|
||||
setup_keywords
|
||||
# Check embedded "," or "=" in override header.
|
||||
check_heading_regexp '-o comm,pid==' \
|
||||
'^'"${head_regexp_comm}"' *=$'
|
||||
check_heading_regexp '-o comm,pid=,' \
|
||||
'^'"${head_regexp_comm}"' *,$'
|
||||
check_heading_regexp '-o pid=PPP,comm' \
|
||||
'^ *PPP,comm$' # not like '-o pid=PPP -o comm'
|
||||
check_heading_regexp '-o pid=PPP,comm=CCC' \
|
||||
'^ *PPP,comm=CCC$' # not like '-o pid=PPP -o comm=CCC'
|
||||
check_heading_regexp '-o comm,pid=PPP,QQQ' \
|
||||
'^'"${head_regexp_comm}"' *PPP,QQQ$'
|
||||
check_heading_regexp '-o comm,pid=ppid,tty=state' \
|
||||
'^'"${head_regexp_comm}"' *ppid,tty=state$'
|
||||
# Check embedded space or tab in override header.
|
||||
check_heading_regexp '-o comm,pid="PPP QQQ"' \
|
||||
'^'"${head_regexp_comm}"' *PPP QQQ$'
|
||||
check_heading_regexp '-o comm,pid="PPP${tab}QQQ"' \
|
||||
'^'"${head_regexp_comm}"' *PPP'"${tab}"'QQQ$'
|
||||
}
|
||||
|
||||
atf_test_case override_heading_some_null
|
||||
override_heading_some_null_head()
|
||||
{
|
||||
atf_set "descr" "Tests simple uses of null column headings" \
|
||||
"overriding via 'ps -o foo=BAR -o baz='. This" \
|
||||
"does not test the case where all columns have" \
|
||||
"null headings."
|
||||
}
|
||||
override_heading_some_null_body()
|
||||
{
|
||||
setup_keywords
|
||||
check_heading_regexp '-o pid=PPP -o comm=' \
|
||||
'^ *PPP *$'
|
||||
check_heading_regexp '-o pid= -o comm=CCC' \
|
||||
'^ * CCC$'
|
||||
check_heading_regexp '-o pid -o comm=' \
|
||||
'^'"${head_regexp_pid}"' *$'
|
||||
# Check missing pid
|
||||
check_heading_regexp '-o ppid= -o comm=CCC' \
|
||||
'^ * CCC$'
|
||||
check_heading_regexp '-o ppid=PPP -o comm=' \
|
||||
'^ *PPP *$'
|
||||
# Check pid present but not first
|
||||
check_heading_regexp '-o comm= -o pid=PPP' \
|
||||
'^ * PPP$'
|
||||
check_heading_regexp '-o comm,pid=' \
|
||||
'^'"${head_regexp_comm}"' *$'
|
||||
# A field with a null custom heading retains a minimum width
|
||||
# derived from the default heading. This does not apply
|
||||
# to a field with a very short (non-null) custom heading.
|
||||
#
|
||||
# We choose "holdcnt" as a column whose width is likely to be
|
||||
# determined entirely by the header width, because the values
|
||||
# are likely to be very small.
|
||||
check_heading_regexp '-o holdcnt -o holdcnt -o holdcnt' \
|
||||
'^HOLDCNT HOLDCNT HOLDCNT$'
|
||||
check_heading_regexp '-o holdcnt -o holdcnt= -o holdcnt' \
|
||||
'^HOLDCNT HOLDCNT$'
|
||||
check_heading_regexp '-o holdcnt -o holdcnt=HH -o holdcnt' \
|
||||
'^HOLDCNT HH HOLDCNT$'
|
||||
}
|
||||
|
||||
atf_test_case override_heading_all_null
|
||||
override_heading_all_null_head()
|
||||
{
|
||||
atf_set "descr" "Tests the use of 'ps -o foo= -o bar=' (with a" \
|
||||
"null heading for every column). The heading" \
|
||||
"should not be printed at all in this case."
|
||||
}
|
||||
override_heading_all_null_body()
|
||||
{
|
||||
setup_keywords
|
||||
# A heading with a space is not a null heading,
|
||||
# so should not be suppressed
|
||||
check_heading_regexp '-o comm=" "' \
|
||||
'^ *$'
|
||||
# Null headings should be suppressed
|
||||
check_no_heading_line '-o pid= -o comm='
|
||||
check_no_heading_line '-o pid= -o comm='
|
||||
# Check missing pid
|
||||
check_no_heading_line '-o ppid='
|
||||
check_no_heading_line '-o comm='
|
||||
check_no_heading_line '-o command='
|
||||
check_no_heading_line '-o ppid= -o comm='
|
||||
check_no_heading_line '-o comm= -o ppid='
|
||||
# Check pid present but not first
|
||||
check_no_heading_line '-o comm= -o pid='
|
||||
check_no_heading_line '-o ppid= -o pid= -o command='
|
||||
}
|
||||
|
||||
atf_test_case duplicate_column
|
||||
duplicate_column_head()
|
||||
{
|
||||
atf_set "descr" "Tests the use of -o options to display the" \
|
||||
"same column more than once"
|
||||
}
|
||||
duplicate_column_body()
|
||||
{
|
||||
setup_keywords
|
||||
# two custom headers
|
||||
check_heading_regexp '-o pid=PPP -o pid=QQQ' \
|
||||
'^ *PPP *QQQ$'
|
||||
# one custom header, before and after default header
|
||||
check_heading_regexp '-o pid=PPP -o pid' \
|
||||
'^ *PPP '"${head_regexp_pid}"'$'
|
||||
check_heading_regexp '-o pid -o pid=QQQ' \
|
||||
'^'"${head_regexp_pid}"' *QQQ$'
|
||||
# custom headers both before and after default header
|
||||
check_heading_regexp '-o pid=PPP -o pid -o pid=QQQ' \
|
||||
'^ *PPP '"${head_regexp_pid}"' *QQQ$'
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case default_columns
|
||||
atf_add_test_case minus_O
|
||||
atf_add_test_case minus_o
|
||||
atf_add_test_case override_heading_simple
|
||||
atf_add_test_case override_heading_embedded_specials
|
||||
atf_add_test_case override_heading_some_null
|
||||
atf_add_test_case override_heading_all_null
|
||||
atf_add_test_case duplicate_column
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
# $NetBSD: Makefile,v 1.2 2012/06/11 18:32:59 njoly Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/sh
|
||||
|
||||
TESTS_SH= t_compexit
|
||||
TESTS_SH+= t_exit
|
||||
TESTS_SH+= t_expand
|
||||
TESTS_SH+= t_evaltested
|
||||
TESTS_SH+= t_fsplit
|
||||
TESTS_SH+= t_here
|
||||
TESTS_SH+= t_set_e
|
||||
TESTS_SH+= t_ulimit
|
||||
TESTS_SH+= t_varquote
|
||||
TESTS_SH+= t_wait
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,63 @@
|
||||
# $NetBSD: t_compexit.sh,v 1.1 2012/03/17 16:33:11 jruoho 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.
|
||||
#
|
||||
|
||||
# The standard
|
||||
# http://www.opengroup.org/onlinepubs/007904975/utilities/set.html
|
||||
# says:
|
||||
#
|
||||
# -e
|
||||
#
|
||||
# When this option is on, if a simple command fails for any of the
|
||||
# reasons listed in Consequences of Shell Errors or returns an exit
|
||||
# status value >0, and is not part of the compound list following a
|
||||
# while, until, or if keyword, and is not a part of an AND or OR list,
|
||||
# and is not a pipeline preceded by the ! reserved word, then the shell
|
||||
# shall immediately exit.
|
||||
|
||||
crud() {
|
||||
set -e
|
||||
for x in a
|
||||
do
|
||||
BAR="foo"
|
||||
false && echo true
|
||||
echo mumble
|
||||
done
|
||||
}
|
||||
|
||||
atf_test_case set_e
|
||||
set_e_head() {
|
||||
atf_set "descr" "Tests that 'set -e' turns on error detection" \
|
||||
"and that it behaves as defined by the standard"
|
||||
}
|
||||
set_e_body() {
|
||||
foo=`crud`
|
||||
atf_check_equal 'x$foo' 'xmumble'
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case set_e
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
# $NetBSD: t_evaltested.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2011 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.
|
||||
#
|
||||
|
||||
atf_test_case evaltested
|
||||
|
||||
evaltested_head() {
|
||||
atf_set "descr" "Tests that eval in a tested context does not exit"
|
||||
}
|
||||
|
||||
evaltested_body() {
|
||||
set -e
|
||||
cat > helper.sh << EOF
|
||||
set -e
|
||||
if eval false
|
||||
then
|
||||
echo "'eval false' returned true"
|
||||
exit 1
|
||||
fi
|
||||
echo "passed"
|
||||
exit 0
|
||||
EOF
|
||||
output="$(/bin/sh helper.sh)"
|
||||
[ $? = 0 ] && return
|
||||
|
||||
if [ -n "$output" ]
|
||||
then
|
||||
atf_fail "$output"
|
||||
else
|
||||
atf_fail "'eval false' exited from a tested context"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case evaltested
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
# $NetBSD: t_exit.sh,v 1.3 2012/04/13 06:12:32 jruoho 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.
|
||||
#
|
||||
|
||||
crud() {
|
||||
test yes = no
|
||||
|
||||
cat <<EOF
|
||||
$?
|
||||
EOF
|
||||
}
|
||||
|
||||
atf_test_case background
|
||||
background_head() {
|
||||
atf_set "descr" "Tests that sh(1) sets '$?' properly when running " \
|
||||
"a command in the background (PR bin/46327)"
|
||||
}
|
||||
background_body() {
|
||||
atf_check -s exit:0 -o ignore -e ignore -x "true; true & echo $?"
|
||||
atf_check -s exit:0 -o ignore -e ignore -x "false; true & echo $?"
|
||||
}
|
||||
|
||||
atf_test_case function
|
||||
function_head() {
|
||||
atf_set "descr" "Tests that \$? is correctly updated inside" \
|
||||
"a function"
|
||||
}
|
||||
function_body() {
|
||||
foo=`crud`
|
||||
atf_check_equal 'x$foo' 'x1'
|
||||
}
|
||||
|
||||
atf_test_case readout
|
||||
readout_head() {
|
||||
atf_set "descr" "Tests that \$? is correctly updated in a" \
|
||||
"compound expression"
|
||||
}
|
||||
readout_body() {
|
||||
atf_check_equal '$( true && ! true | false; echo $? )' '0'
|
||||
}
|
||||
|
||||
atf_test_case trap_subshell
|
||||
trap_subshell_head() {
|
||||
atf_set "descr" "Tests that the trap statement in a subshell" \
|
||||
"works when the subshell exits"
|
||||
}
|
||||
trap_subshell_body() {
|
||||
atf_check -s eq:0 -o inline:'exiting\n' -x \
|
||||
'( trap "echo exiting" EXIT; /usr/bin/true )'
|
||||
}
|
||||
|
||||
atf_test_case trap_zero__implicit_exit
|
||||
trap_zero__implicit_exit_body() {
|
||||
# PR bin/6764: sh works but ksh does not"
|
||||
echo '( trap "echo exiting" 0 )' >helper.sh
|
||||
atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
|
||||
atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
|
||||
}
|
||||
|
||||
atf_test_case trap_zero__explicit_exit
|
||||
trap_zero__explicit_exit_body() {
|
||||
echo '( trap "echo exiting" 0; exit )' >helper.sh
|
||||
atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
|
||||
atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
|
||||
}
|
||||
|
||||
atf_test_case trap_zero__explicit_return
|
||||
trap_zero__explicit_return_body() {
|
||||
echo '( trap "echo exiting" 0; return )' >helper.sh
|
||||
atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
|
||||
atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case background
|
||||
atf_add_test_case function
|
||||
atf_add_test_case readout
|
||||
atf_add_test_case trap_subshell
|
||||
atf_add_test_case trap_zero__implicit_exit
|
||||
atf_add_test_case trap_zero__explicit_exit
|
||||
atf_add_test_case trap_zero__explicit_return
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
# $NetBSD: t_expand.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2007, 2009 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.
|
||||
#
|
||||
|
||||
#
|
||||
# This file tests the functions in expand.c.
|
||||
#
|
||||
|
||||
delim_argv() {
|
||||
str=
|
||||
while [ $# -gt 0 ]; do
|
||||
if [ -z "${str}" ]; then
|
||||
str=">$1<"
|
||||
else
|
||||
str="${str} >$1<"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
echo ${str}
|
||||
}
|
||||
|
||||
atf_test_case dollar_at
|
||||
dollar_at_head() {
|
||||
atf_set "descr" "Somewhere between 2.0.2 and 3.0 the expansion" \
|
||||
"of the \$@ variable had been broken. Check for" \
|
||||
"this behavior."
|
||||
}
|
||||
dollar_at_body() {
|
||||
# This one should work everywhere.
|
||||
got=`echo "" "" | sed 's,$,EOL,'`
|
||||
atf_check_equal ' EOL' '$got'
|
||||
|
||||
# This code triggered the bug.
|
||||
set -- "" ""
|
||||
got=`echo "$@" | sed 's,$,EOL,'`
|
||||
atf_check_equal ' EOL' '$got'
|
||||
|
||||
set -- -
|
||||
shift
|
||||
n_arg() { echo $#; }
|
||||
n_args=`n_arg "$@"`
|
||||
atf_check_equal '0' '$n_args'
|
||||
}
|
||||
|
||||
atf_test_case dollar_at_with_text
|
||||
dollar_at_with_text_head() {
|
||||
atf_set "descr" "Test \$@ expansion when it is surrounded by text" \
|
||||
"within the quotes. PR bin/33956."
|
||||
}
|
||||
dollar_at_with_text_body() {
|
||||
set --
|
||||
atf_check_equal '' "$(delim_argv "$@")"
|
||||
atf_check_equal '>foobar<' "$(delim_argv "foo$@bar")"
|
||||
atf_check_equal '>foo bar<' "$(delim_argv "foo $@ bar")"
|
||||
|
||||
set -- a b c
|
||||
atf_check_equal '>a< >b< >c<' "$(delim_argv "$@")"
|
||||
atf_check_equal '>fooa< >b< >cbar<' "$(delim_argv "foo$@bar")"
|
||||
atf_check_equal '>foo a< >b< >c bar<' "$(delim_argv "foo $@ bar")"
|
||||
}
|
||||
|
||||
atf_test_case strip
|
||||
strip_head() {
|
||||
atf_set "descr" "Checks that the %% operator works and strips" \
|
||||
"the contents of a variable from the given point" \
|
||||
"to the end"
|
||||
}
|
||||
strip_body() {
|
||||
line='#define bindir "/usr/bin" /* comment */'
|
||||
stripped='#define bindir "/usr/bin" '
|
||||
atf_expect_fail "PR bin/43469"
|
||||
atf_check_equal '$stripped' '${line%%/\**}'
|
||||
}
|
||||
|
||||
atf_test_case varpattern_backslashes
|
||||
varpattern_backslashes_head() {
|
||||
atf_set "descr" "Tests that protecting wildcards with backslashes" \
|
||||
"works in variable patterns."
|
||||
}
|
||||
varpattern_backslashes_body() {
|
||||
line='/foo/bar/*/baz'
|
||||
stripped='/foo/bar/'
|
||||
atf_check_equal $stripped ${line%%\**}
|
||||
}
|
||||
|
||||
atf_test_case arithmetic
|
||||
arithmetic_head() {
|
||||
atf_set "descr" "POSIX requires shell arithmetic to use signed" \
|
||||
"long or a wider type. We use intmax_t, so at" \
|
||||
"least 64 bits should be available. Make sure" \
|
||||
"this is true."
|
||||
}
|
||||
arithmetic_body() {
|
||||
atf_check_equal '3' '$((1 + 2))'
|
||||
atf_check_equal '2147483647' '$((0x7fffffff))'
|
||||
atf_check_equal '9223372036854775807' '$(((1 << 63) - 1))'
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case dollar_at
|
||||
atf_add_test_case dollar_at_with_text
|
||||
atf_add_test_case strip
|
||||
atf_add_test_case varpattern_backslashes
|
||||
atf_add_test_case arithmetic
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
# $NetBSD: t_fsplit.sh,v 1.1 2012/03/17 16:33:11 jruoho 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.
|
||||
#
|
||||
|
||||
# The standard
|
||||
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
|
||||
# explains (section 2.6) that Field splitting should be performed on the
|
||||
# result of variable expansions.
|
||||
# In particular this means that in ${x-word}, 'word' must be expanded as if
|
||||
# the "${x-" and "}" were absent from the input line.
|
||||
#
|
||||
# So: sh -c 'set ${x-a b c}; echo $#' should give 3.
|
||||
#
|
||||
|
||||
nl='
|
||||
'
|
||||
|
||||
check()
|
||||
{
|
||||
result="$(eval $1)"
|
||||
# Remove newlines
|
||||
oifs="$IFS"
|
||||
IFS="$nl"
|
||||
result="$(echo $result)"
|
||||
IFS="$oifs"
|
||||
if [ "$2" != "$result" ]
|
||||
then
|
||||
atf_fail "expected [$2], found [$result]"
|
||||
fi
|
||||
}
|
||||
|
||||
atf_test_case for
|
||||
for_head() {
|
||||
atf_set "descr" "Checks field splitting in for loops"
|
||||
}
|
||||
for_body() {
|
||||
unset x
|
||||
|
||||
# Since I managed to break this, leave the test in
|
||||
check 'for f in $x; do echo x${f}y; done' ''
|
||||
}
|
||||
|
||||
atf_test_case default_val
|
||||
default_val_head() {
|
||||
atf_set "descr" "Checks field splitting in variable default values"
|
||||
}
|
||||
default_val_body() {
|
||||
unset x
|
||||
|
||||
# Check that IFS is applied to text from ${x-...} unless it is inside
|
||||
# any set of "..."
|
||||
check 'set ${x-a b c}; echo $#' 3
|
||||
check 'for i in ${x-a b c}; do echo "z${i}z"; done' 'zaz zbz zcz'
|
||||
check 'for i in ${x-"a b" c}; do echo "z${i}z"; done' 'za bz zcz'
|
||||
check 'for i in ${x-"a ${x-b c}" d}; do echo "z${i}z"; done' 'za b cz zdz'
|
||||
check 'for i in ${x-"a ${x-"b c"}" d}; do echo "z${i}z"; done' 'za b cz zdz'
|
||||
check 'for i in ${x-a ${x-"b c"} d}; do echo "z${i}z"; done' 'zaz zb cz zdz'
|
||||
check 'for i in ${x-a ${x-b c} d}; do echo "z${i}z"; done' 'zaz zbz zcz zdz'
|
||||
}
|
||||
|
||||
atf_test_case ifs_alpha
|
||||
ifs_alpha_head() {
|
||||
atf_set "descr" "Checks that field splitting works with alphabetic" \
|
||||
"characters"
|
||||
}
|
||||
ifs_alpha_body() {
|
||||
unset x
|
||||
|
||||
# repeat with an alphabetic in IFS
|
||||
check 'IFS=q; set ${x-aqbqc}; echo $#' 3
|
||||
check 'IFS=q; for i in ${x-aqbqc}; do echo "z${i}z"; done' 'zaz zbz zcz'
|
||||
check 'IFS=q; for i in ${x-"aqb"qc}; do echo "z${i}z"; done' 'zaqbz zcz'
|
||||
check 'IFS=q; for i in ${x-"aq${x-bqc}"qd}; do echo "z${i}z"; done' 'zaqbqcz zdz'
|
||||
check 'IFS=q; for i in ${x-"aq${x-"bqc"}"qd}; do echo "z${i}z"; done' 'zaqbqcz zdz'
|
||||
check 'IFS=q; for i in ${x-aq${x-"bqc"}qd}; do echo "z${i}z"; done' 'zaz zbqcz zdz'
|
||||
}
|
||||
|
||||
atf_test_case quote
|
||||
quote_head() {
|
||||
atf_set "descr" "Checks that field splitting works with multi-word" \
|
||||
"fields"
|
||||
}
|
||||
quote_body() {
|
||||
unset x
|
||||
|
||||
# Some quote propagation checks
|
||||
check 'set "${x-a b c}"; echo $#' 1
|
||||
check 'set "${x-"a b" c}"; echo $1' 'a b c'
|
||||
check 'for i in "${x-a b c}"; do echo "z${i}z"; done' 'za b cz'
|
||||
}
|
||||
|
||||
atf_test_case dollar_at
|
||||
dollar_at_head() {
|
||||
atf_set "descr" "Checks that field splitting works when expanding" \
|
||||
"\$@"
|
||||
}
|
||||
dollar_at_body() {
|
||||
unset x
|
||||
|
||||
# Check we get "$@" right
|
||||
check 'set ""; for i; do echo "z${i}z"; done' 'zz'
|
||||
check 'set ""; for i in "$@"; do echo "z${i}z"; done' 'zz'
|
||||
check 'set "" ""; for i; do echo "z${i}z"; done' 'zz zz'
|
||||
check 'set "" ""; for i in "$@"; do echo "z${i}z"; done' 'zz zz'
|
||||
check 'set "" ""; for i in $@; do echo "z${i}z"; done' ''
|
||||
check 'set "a b" c; for i; do echo "z${i}z"; done' 'za bz zcz'
|
||||
check 'set "a b" c; for i in "$@"; do echo "z${i}z"; done' 'za bz zcz'
|
||||
check 'set "a b" c; for i in $@; do echo "z${i}z"; done' 'zaz zbz zcz'
|
||||
check 'set " a b " c; for i in "$@"; do echo "z${i}z"; done' 'z a b z zcz'
|
||||
check 'set --; for i in x"$@"x; do echo "z${i}z"; done' 'zxxz'
|
||||
check 'set a; for i in x"$@"x; do echo "z${i}z"; done' 'zxaxz'
|
||||
check 'set a b; for i in x"$@"x; do echo "z${i}z"; done' 'zxaz zbxz'
|
||||
}
|
||||
|
||||
atf_test_case ifs
|
||||
ifs_head() {
|
||||
atf_set "descr" "Checks that IFS correctly configures field" \
|
||||
"splitting behavior"
|
||||
}
|
||||
ifs_body() {
|
||||
unset x
|
||||
|
||||
# Some IFS tests
|
||||
check 't="-- "; IFS=" "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '0'
|
||||
check 't=" x"; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1'
|
||||
check 't=" x "; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1'
|
||||
check 't=axb; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a:b'
|
||||
check 't="a x b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a : b'
|
||||
check 't="a xx b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a :: b'
|
||||
check 't="a xx b"; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a::b'
|
||||
# A recent 'clarification' means that a single trailing IFS non-whitespace
|
||||
# doesn't generate an empty parameter
|
||||
check 't="xax"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a'
|
||||
check 't="xax "; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a'
|
||||
# Verify that IFS isn't being applied where it shouldn't be.
|
||||
check 'IFS="x"; set axb; IFS=":"; r="$*"; IFS=; echo $# $r' '1 axb'
|
||||
}
|
||||
|
||||
atf_test_case var_length
|
||||
var_length_head() {
|
||||
atf_set "descr" "Checks that field splitting works when expanding" \
|
||||
"a variable's length"
|
||||
}
|
||||
var_length_body() {
|
||||
unset x
|
||||
|
||||
# Check that we apply IFS to ${#var}
|
||||
long=12345678123456781234567812345678
|
||||
long=$long$long$long$long
|
||||
check 'echo ${#long}; IFS=2; echo ${#long}; set 1 ${#long};echo $#' '128 1 8 3'
|
||||
check 'IFS=2; set ${x-${#long}}; IFS=" "; echo $* $#' '1 8 2'
|
||||
check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#' '128 1'
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case for
|
||||
atf_add_test_case default_val
|
||||
atf_add_test_case ifs_alpha
|
||||
atf_add_test_case quote
|
||||
atf_add_test_case dollar_at
|
||||
atf_add_test_case ifs
|
||||
atf_add_test_case var_length
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
# $NetBSD: t_here.sh,v 1.1 2012/03/17 16:33:11 jruoho 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.
|
||||
#
|
||||
|
||||
nl='
|
||||
'
|
||||
|
||||
check()
|
||||
{
|
||||
SVIFS="$IFS"
|
||||
result="$(eval $1)"
|
||||
# Remove newlines
|
||||
oifs="$IFS"
|
||||
IFS="$nl"
|
||||
result="$(echo $result)"
|
||||
IFS="$oifs"
|
||||
if [ "$2" != "$result" ]
|
||||
then
|
||||
atf_fail "expected [$2], found [$result]"
|
||||
fi
|
||||
IFS="$SVIFS"
|
||||
}
|
||||
|
||||
atf_test_case all
|
||||
all_head() {
|
||||
atf_set "descr" "Basic tests for here documents"
|
||||
}
|
||||
all_body() {
|
||||
y=x
|
||||
|
||||
IFS=
|
||||
check 'x=`cat <<EOF'$nl'text'${nl}EOF$nl'`; echo $x' 'text'
|
||||
check 'x=`cat <<\EOF'$nl'text'${nl}EOF$nl'`; echo $x' 'text'
|
||||
|
||||
check 'x=`cat <<EOF'$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'text'
|
||||
check 'x=`cat <<\EOF'$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'te${y}t'
|
||||
check 'x=`cat <<"EOF"'$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'te${y}t'
|
||||
check 'x=`cat <<'"'EOF'"$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'te${y}t'
|
||||
|
||||
check 'x=`cat <<EOF'$nl'te'"'"'xt'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
|
||||
check 'x=`cat <<\EOF'$nl'te'"'"'xt'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
|
||||
check 'x=`cat <<"EOF"'$nl'te'"'"'xt'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
|
||||
|
||||
check 'x=`cat <<EOF'$nl'te'"'"'${y}t'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
|
||||
check 'x=`cat <<EOF'$nl'te'"''"'${y}t'${nl}EOF$nl'`; echo $x' 'te'"''"'xt'
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case all
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
# $NetBSD: t_set_e.sh,v 1.1 2012/03/17 16:33:11 jruoho 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.
|
||||
#
|
||||
|
||||
# references:
|
||||
# http://www.opengroup.org/onlinepubs/009695399/utilities/set.html
|
||||
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
|
||||
|
||||
# the implementation of "sh" to test
|
||||
: ${TEST_SH:="sh"}
|
||||
|
||||
failwith()
|
||||
{
|
||||
case "$SH_FAILS" in
|
||||
"") SH_FAILS=`echo "$1"`;;
|
||||
*) SH_FAILS="$SH_FAILS"`echo; echo "$1"`;;
|
||||
esac
|
||||
}
|
||||
|
||||
check1()
|
||||
{
|
||||
#echo "$TEST_SH -c $1"
|
||||
result=`$TEST_SH -c "$1" 2>/dev/null | tr '\n' ' ' | sed 's/ *$//'`
|
||||
if [ "$result" != "$2" ]; then
|
||||
MSG=`printf "%-56s %-8s %s" "$3" "$result" "$2"`
|
||||
failwith "$MSG"
|
||||
failcount=`expr $failcount + 1`
|
||||
fi
|
||||
count=`expr $count + 1`
|
||||
}
|
||||
|
||||
# direct check: try the given expression.
|
||||
dcheck()
|
||||
{
|
||||
check1 "$1" "$2" "$1"
|
||||
}
|
||||
|
||||
# eval check: indirect through eval.
|
||||
# as of this writing, this changes the behavior pretty drastically and
|
||||
# is thus important to test. (PR bin/29861)
|
||||
echeck()
|
||||
{
|
||||
check1 'eval '"'($1)'" "$2" "eval '($1)'"
|
||||
}
|
||||
|
||||
atf_test_case all
|
||||
all_head() {
|
||||
atf_set "descr" "Tests that 'set -e' works correctly"
|
||||
}
|
||||
all_body() {
|
||||
count=0
|
||||
failcount=0
|
||||
|
||||
# make sure exiting from a subshell behaves as expected
|
||||
dcheck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1'
|
||||
echeck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1'
|
||||
|
||||
# first, check basic functioning.
|
||||
# The ERR shouldn't print; the result of the () should be 1.
|
||||
# Henceforth we'll assume that we don't need to check $?.
|
||||
dcheck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
|
||||
echeck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
|
||||
|
||||
# these cases should be equivalent to the preceding.
|
||||
dcheck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
|
||||
dcheck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK'
|
||||
dcheck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK'
|
||||
echeck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK'
|
||||
dcheck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK'
|
||||
echeck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK'
|
||||
|
||||
# but! with set -e, the false should cause an *immediate* exit.
|
||||
# The return form should not, as such, but there's no way to
|
||||
# distinguish it.
|
||||
dcheck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK'
|
||||
echeck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK'
|
||||
|
||||
# set is not scoped, so these should not exit at all.
|
||||
dcheck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK'
|
||||
echeck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK'
|
||||
|
||||
# according to the standard, only failing *simple* commands
|
||||
# cause an exit under -e. () is not a simple command.
|
||||
# Correct (per POSIX):
|
||||
#dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK'
|
||||
#echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK'
|
||||
# Wrong current behavior:
|
||||
dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK'
|
||||
echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK'
|
||||
|
||||
# make sure an inner nested shell does exit though.
|
||||
dcheck '(set -e; (false; echo ERR)); echo OK' 'OK'
|
||||
|
||||
# The left hand side of an || or && is explicitly tested and
|
||||
# thus should not cause an exit. Furthermore, because a || or
|
||||
# && expression is not a simple command, there should be no
|
||||
# exit even if the overall result is false.
|
||||
dcheck '(set -e; false || true; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; false || true; echo OK); echo OK' 'OK OK'
|
||||
dcheck '(set -e; false && true; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; false && true; echo OK); echo OK' 'OK OK'
|
||||
|
||||
# However, the right hand side is not tested, so a failure
|
||||
# there *should* cause an exit, regardless of whether it
|
||||
# appears inside a non-simple command.
|
||||
#
|
||||
# Note that in at least one place the standard does not
|
||||
# distinguish between the left and right hand sides of
|
||||
# logical operators. It is possible that for strict
|
||||
# compliance these need to not exit; however, if so that
|
||||
# should probably be limited to when some strict-posix setting
|
||||
# is in effect and tested accordingly.
|
||||
#
|
||||
dcheck '(set -e; false || false; echo ERR); echo OK' 'OK'
|
||||
dcheck '(set -e; true && false; echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; false || false; echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; true && false; echo ERR); echo OK' 'OK'
|
||||
|
||||
# correct:
|
||||
#dcheck '(set -e; false && false; echo ERR); echo OK' 'OK'
|
||||
#echeck '(set -e; false && false; echo ERR); echo OK' 'OK'
|
||||
|
||||
# wrong current behavior:
|
||||
dcheck '(set -e; false && false; echo ERR); echo OK' 'ERR OK'
|
||||
echeck '(set -e; false && false; echo ERR); echo OK' 'ERR OK'
|
||||
|
||||
# A failure that is not reached because of short-circuit
|
||||
# evaluation should not cause an exit, however.
|
||||
dcheck '(set -e; true || false; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; true || false; echo OK); echo OK' 'OK OK'
|
||||
|
||||
# For completeness, test the other two combinations.
|
||||
dcheck '(set -e; true || true; echo OK); echo OK' 'OK OK'
|
||||
dcheck '(set -e; true && true; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; true || true; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; true && true; echo OK); echo OK' 'OK OK'
|
||||
|
||||
# likewise, none of these should exit.
|
||||
dcheck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK'
|
||||
dcheck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK'
|
||||
# problematic :-)
|
||||
#dcheck '(set -e; until false; do :; done; echo OK); echo OK' 'OK OK'
|
||||
dcheck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \
|
||||
'OK OK'
|
||||
echeck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \
|
||||
'OK OK'
|
||||
|
||||
# the bang operator tests its argument and thus the argument
|
||||
# should not cause an exit. it is also not a simple command (I
|
||||
# believe) so it also shouldn't exit even if it yields a false
|
||||
# result.
|
||||
dcheck '(set -e; ! false; echo OK); echo OK' 'OK OK'
|
||||
dcheck '(set -e; ! true; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; ! false; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; ! true; echo OK); echo OK' 'OK OK'
|
||||
|
||||
# combined case with () and &&; the inner expression is false
|
||||
# but does not itself exit, and the () should not cause an
|
||||
# exit even when failing.
|
||||
# correct:
|
||||
#dcheck '(set -e; (false && true); echo OK); echo OK' 'OK OK'
|
||||
#echeck '(set -e; (false && true); echo OK); echo OK' 'OK OK'
|
||||
# wrong current behavior:
|
||||
dcheck '(set -e; (false && true); echo OK); echo OK' 'OK'
|
||||
echeck '(set -e; (false && true); echo OK); echo OK' 'OK'
|
||||
|
||||
# pipelines. only the right-hand end is significant.
|
||||
dcheck '(set -e; false | true; echo OK); echo OK' 'OK OK'
|
||||
echeck '(set -e; false | true; echo OK); echo OK' 'OK OK'
|
||||
dcheck '(set -e; true | false; echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; true | false; echo ERR); echo OK' 'OK'
|
||||
|
||||
dcheck '(set -e; while true | false; do :; done; echo OK); echo OK' \
|
||||
'OK OK'
|
||||
dcheck '(set -e; if true | false; then :; fi; echo OK); echo OK' \
|
||||
'OK OK'
|
||||
|
||||
|
||||
# According to dsl@ in PR bin/32282, () is not defined as a
|
||||
# subshell, only as a grouping operator [and a scope, I guess]
|
||||
# so the nested false ought to cause the whole shell to exit,
|
||||
# not just the subshell. dholland@ would like to see C&V,
|
||||
# because that seems like a bad idea. (Among other things, it
|
||||
# would break all the above test logic, which relies on being
|
||||
# able to isolate set -e behavior inside ().) However, I'm
|
||||
# going to put these tests here to make sure the issue gets
|
||||
# dealt with sometime.
|
||||
#
|
||||
# XXX: the second set has been disabled in the name of making
|
||||
# all tests "pass".
|
||||
|
||||
# 1. error if the whole shell exits (current behavior)
|
||||
dcheck 'echo OK; (set -e; false); echo OK' 'OK OK'
|
||||
echeck 'echo OK; (set -e; false); echo OK' 'OK OK'
|
||||
# 2. error if the whole shell does not exit (dsl's suggested behavior)
|
||||
#dcheck 'echo OK; (set -e; false); echo ERR' 'OK'
|
||||
#echeck 'echo OK; (set -e; false); echo ERR' 'OK'
|
||||
|
||||
# The current behavior of the shell is that it exits out as
|
||||
# far as -e is set and then stops. This is probably a
|
||||
# consequence of it handling () wrong, but it's a somewhat
|
||||
# curious compromise position between 1. and 2. above.
|
||||
dcheck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK'
|
||||
|
||||
# backquote expansion (PR bin/17514)
|
||||
|
||||
# correct
|
||||
#dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
|
||||
#dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
|
||||
#dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
|
||||
#dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
|
||||
# wrong current behavior
|
||||
dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
|
||||
dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
|
||||
dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
|
||||
dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK'
|
||||
|
||||
dcheck '(set -e; x=`false`; echo ERR); echo OK' 'OK'
|
||||
dcheck '(set -e; x=$(false); echo ERR); echo OK' 'OK'
|
||||
dcheck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK'
|
||||
dcheck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK'
|
||||
|
||||
# correct
|
||||
#echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
|
||||
#echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
|
||||
#echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
|
||||
#echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
|
||||
|
||||
# wrong current behavior
|
||||
echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
|
||||
echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
|
||||
echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
|
||||
echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK'
|
||||
|
||||
echeck '(set -e; x=`false`; echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; x=$(false); echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK'
|
||||
echeck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK'
|
||||
|
||||
# shift (PR bin/37493)
|
||||
# correct
|
||||
#dcheck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
|
||||
#echeck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
|
||||
# wrong current behavior
|
||||
dcheck '(set -e; shift || true; echo OK); echo OK' 'OK'
|
||||
echeck '(set -e; shift || true; echo OK); echo OK' 'OK'
|
||||
|
||||
# Done.
|
||||
|
||||
if [ "x$SH_FAILS" != x ]; then
|
||||
printf '%-56s %-8s %s\n' "Expression" "Result" "Should be"
|
||||
echo "$SH_FAILS"
|
||||
atf_fail "$failcount of $count failed cases"
|
||||
else
|
||||
atf_pass
|
||||
fi
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case all
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
# $NetBSD: t_ulimit.sh,v 1.1 2012/06/11 18:32:59 njoly Exp $
|
||||
#
|
||||
# Copyright (c) 2012 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.
|
||||
#
|
||||
|
||||
# ulimit builtin test.
|
||||
|
||||
atf_test_case limits
|
||||
limits_head() {
|
||||
atf_set "descr" "Checks for limits flags"
|
||||
}
|
||||
limits_body() {
|
||||
atf_check -s eq:0 -o ignore -e empty \
|
||||
/bin/sh -c "ulimit -a"
|
||||
for l in $(ulimit -a | sed 's,^.*(,,;s, .*$,,');
|
||||
do
|
||||
atf_check -s eq:0 -o ignore -e empty \
|
||||
/bin/sh -c "ulimit $l"
|
||||
done
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case limits
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
# $NetBSD: t_varquote.sh,v 1.2 2012/03/25 18:50:19 christos 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.
|
||||
#
|
||||
|
||||
# Variable quoting test.
|
||||
|
||||
check() {
|
||||
if [ "$1" != "$2" ]
|
||||
then
|
||||
atf_fail "expected [$2], found [$1]" 1>&2
|
||||
fi
|
||||
}
|
||||
|
||||
atf_test_case all
|
||||
all_head() {
|
||||
atf_set "descr" "Basic checks for variable quoting"
|
||||
}
|
||||
all_body() {
|
||||
foo='${a:-foo}'
|
||||
check "$foo" '${a:-foo}'
|
||||
|
||||
foo="${a:-foo}"
|
||||
check "$foo" "foo"
|
||||
|
||||
foo=${a:-"'{}'"}
|
||||
check "$foo" "'{}'"
|
||||
|
||||
foo=${a:-${b:-"'{}'"}}
|
||||
check "$foo" "'{}'"
|
||||
|
||||
foo="${a:-"'{}'"}"
|
||||
check "$foo" "'{}'"
|
||||
|
||||
foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
|
||||
# " z*"
|
||||
# ${a:- }
|
||||
# ${b:- }
|
||||
# " y*"
|
||||
# ${c:- }
|
||||
# ${d:- }
|
||||
# "x*"
|
||||
check "$foo" "x}y}z}"
|
||||
}
|
||||
|
||||
atf_test_case nested_quotes_multiword
|
||||
nested_quotes_multiword_head() {
|
||||
atf_set "descr" "Tests that having nested quoting in a multi-word" \
|
||||
"string works (PR bin/43597)"
|
||||
}
|
||||
nested_quotes_multiword_body() {
|
||||
atf_check -s eq:0 -o match:"first-word second-word" -e empty \
|
||||
/bin/sh -c 'echo "${foo:="first-word"} second-word"'
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case all
|
||||
atf_add_test_case nested_quotes_multiword
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
# $NetBSD: t_wait.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2008, 2009, 2010 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.
|
||||
#
|
||||
|
||||
atf_test_case individual
|
||||
individual_head() {
|
||||
atf_set "descr" "Tests that waiting for individual jobs works"
|
||||
}
|
||||
individual_body() {
|
||||
# atf-sh confuses wait for some reason; work it around by creating
|
||||
# a helper script that executes /bin/sh directly.
|
||||
cat >helper.sh <<EOF
|
||||
sleep 3 &
|
||||
sleep 1 &
|
||||
|
||||
wait %1
|
||||
if [ \$? -ne 0 ]; then
|
||||
echo "Waiting of first job failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wait %2
|
||||
if [ \$? -ne 0 ]; then
|
||||
echo "Waiting of second job failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
output=$(/bin/sh helper.sh)
|
||||
[ $? -eq 0 ] || atf_fail "${output}"
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
atf_add_test_case individual
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/30 09:27:10 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/sleep
|
||||
TESTS_SH= t_sleep
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,72 @@
|
||||
# $NetBSD: t_sleep.sh,v 1.1 2012/03/30 09:27:10 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2012 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This code is derived from software contributed to The NetBSD Foundation
|
||||
# by Jukka Ruohonen.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
atf_test_case fraction
|
||||
fraction_head() {
|
||||
atf_set "descr" "Test that sleep(1) handles " \
|
||||
"fractions of a second (PR bin/3914)"
|
||||
}
|
||||
|
||||
fraction_body() {
|
||||
|
||||
atf_check -s exit:0 -o empty -e empty -x "sleep 0.1"
|
||||
atf_check -s exit:0 -o empty -e empty -x "sleep 0.2"
|
||||
atf_check -s exit:0 -o empty -e empty -x "sleep 0.3"
|
||||
}
|
||||
|
||||
atf_test_case hex
|
||||
hex_head() {
|
||||
atf_set "descr" "Test that sleep(1) handles hexadecimal arguments"
|
||||
}
|
||||
|
||||
hex_body() {
|
||||
|
||||
atf_check -s exit:0 -o empty -e empty -x "sleep 0x01"
|
||||
}
|
||||
|
||||
atf_test_case nonnumeric
|
||||
nonnumeric_head() {
|
||||
atf_set "descr" "Test that sleep(1) errors out with " \
|
||||
"non-numeric argument (PR bin/27140)"
|
||||
}
|
||||
|
||||
nonnumeric_body() {
|
||||
|
||||
atf_check -s not-exit:0 -o empty -e not-empty -x "sleep xyz"
|
||||
atf_check -s not-exit:0 -o empty -e not-empty -x "sleep x21"
|
||||
atf_check -s not-exit:0 -o empty -e not-empty -x "sleep /3"
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
|
||||
atf_add_test_case fraction
|
||||
atf_add_test_case hex
|
||||
atf_add_test_case nonnumeric
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# $NetBSD: Makefile,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/bin/tar
|
||||
TESTS_SH= t_tar
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -0,0 +1,51 @@
|
||||
# $NetBSD: t_tar.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
|
||||
#
|
||||
# Copyright (c) 2007, 2008 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.
|
||||
#
|
||||
|
||||
atf_test_case append
|
||||
append_head() {
|
||||
atf_set "descr" "Ensure that appending a file to an archive" \
|
||||
"produces the same results as if the file" \
|
||||
"had been there during the archive's creation"
|
||||
}
|
||||
append_body() {
|
||||
touch foo bar
|
||||
|
||||
# store both foo and bar into file1.tar
|
||||
atf_check -s eq:0 -o empty -e empty tar -cf file1.tar foo bar
|
||||
|
||||
# store foo into file2.tar, then append bar to file2.tar
|
||||
atf_check -s eq:0 -o empty -e empty tar -cf file2.tar foo
|
||||
atf_check -s eq:0 -o empty -e empty tar -rf file2.tar bar
|
||||
|
||||
# ensure that file1.tar and file2.tar are equal
|
||||
atf_check -s eq:0 -o empty -e empty cmp file1.tar file2.tar
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case append
|
||||
}
|
||||
Reference in New Issue
Block a user