Checkpoint initial integration work

- Some of the lib/libc and lib/thr tests fail
- lib/msun/exp_test:exp2_values now passes with clang 3.8.0

The Makefiles in contrib/netbsd-tests were pruned as they have no value

Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
Enji Cooper 2016-08-12 08:50:05 +00:00
commit 640235e2c2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/netbsd-tests-update-12/; revision=304003
217 changed files with 33138 additions and 13332 deletions

View file

@ -6,6 +6,8 @@ NETBSD_ATF_TESTS_SH= cat_test
${PACKAGE}FILES+= d_align.in
${PACKAGE}FILES+= d_align.out
${PACKAGE}FILES+= d_se_output.in
${PACKAGE}FILES+= d_se_output.out
.include <netbsd-tests.test.mk>

View file

@ -1,3 +1,5 @@
a b c
1 2 3
x y z

View file

@ -1,3 +1,5 @@
1 a b c$
$
2 1 2 3$
$
3 x y z$

View file

@ -0,0 +1,3 @@
Of course it runs NetBSD

View file

@ -0,0 +1,3 @@
$
Of course it runs NetBSD$
$

View file

@ -1,4 +1,4 @@
# $NetBSD: t_cat.sh,v 1.2 2012/03/27 17:57:02 jruoho Exp $
# $NetBSD: t_cat.sh,v 1.3 2016/06/16 01:04:58 sevan Exp $
#
# Copyright (c) 2012 The NetBSD Foundation, Inc.
# All rights reserved.
@ -52,8 +52,20 @@ nonexistent_body() {
-x "cat /some/name/that/does/not/exist"
}
atf_test_case se_output
se_output_head() {
atf_set "descr" "Test that cat(1) prints a $ sign " \
"on blank lines with options '-se' (PR bin/51250)"
}
se_output_body() {
atf_check -s ignore -o file:$(atf_get_srcdir)/d_se_output.out \
-x "cat -se $(atf_get_srcdir)/d_se_output.in"
}
atf_init_test_cases()
{
atf_add_test_case align
atf_add_test_case nonexistent
atf_add_test_case se_output
}

View file

@ -1,6 +1,6 @@
#!/bin/sh
#
# $NetBSD: scoped_command,v 1.1 2014/05/31 14:29:06 christos Exp $
# $NetBSD: scoped_command,v 1.2 2016/03/27 14:57:50 christos Exp $
#
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
@ -30,6 +30,27 @@
# POSSIBILITY OF SUCH DAMAGE.
#
: ${TEST_SH:=/bin/sh}
sane_sh()
{
set -- ${TEST_SH}
case "$#" in
(0) set /bin/sh;;
(1|2) ;;
(*) set "$1";; # Just ignore options if we cannot make them work
esac
case "$1" in
/*) TEST_SH="$1${2+ }$2";;
./*) TEST_SH="${PWD}${1#.}${2+ }$2";;
*/*) TEST_SH="${PWD}/$1${2+ }$2";;
*) TEST_SH="$( command -v "$1" )${2+ }$2";;
esac
}
sane_sh
set -e
# USAGE:
@ -52,7 +73,7 @@ cmd="echo 'before ${3}'
${2}
echo 'after ${3}, return value:' ${?}"
echo "#!/bin/sh"
echo "#!${TEST_SH}"
[ 'func' = "${1}" ] && cat <<EOF
func()

View file

@ -1,4 +1,4 @@
# $NetBSD: t_dotcmd.sh,v 1.1 2014/05/31 14:29:06 christos Exp $
# $NetBSD: t_dotcmd.sh,v 1.2 2016/03/27 14:57:50 christos Exp $
#
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
@ -33,6 +33,10 @@
# in C/C++ so, for example, if the dotcmd is in a loop's body, a break in
# the sourced file can be used to break out of that loop.
# Note that the standard does not require this, and allows lexically
# scoped interpretation of break/continue (and permits dynamic scope
# as an optional extension.)
cmds='return break continue'
scopes='case compound file for func subshell until while'

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,783 @@
# $NetBSD: t_cmdsub.sh,v 1.4 2016/04/04 12:40:13 christos Exp $
#
# Copyright (c) 2016 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 "sh" to test
: ${TEST_SH:="/bin/sh"}
#
# This file tests command substitutions ( `...` and $( ... ) )
#
# CAUTION:
# Be careful attempting running these tests outside the ATF environment
# Some of the tests run "rm *" in the current directory to clean up
# An ATF test directory should be empty already, outside ATF, anything
atf_test_case a_basic_cmdsub
a_basic_cmdsub_head() {
atf_set "descr" 'Test operation of simple $( ) substitutions'
}
a_basic_cmdsub_body() {
atf_check -s exit:0 -o match:'Result is true today' -e empty \
${TEST_SH} -c \
'echo Result is $( true && echo true || echo false ) today'
atf_check -s exit:0 -o match:'Result is false today' -e empty \
${TEST_SH} -c \
'echo Result is $( false && echo true || echo false ) today'
atf_check -s exit:0 -o match:'aaabbbccc' -e empty \
${TEST_SH} -c 'echo aaa$( echo bbb )ccc'
atf_check -s exit:0 -o match:'aaabbb cccddd' -e empty \
${TEST_SH} -c 'echo aaa$( echo bbb ccc )ddd'
atf_check -s exit:0 -o inline:'aaabbb cccddd\n' -e empty \
${TEST_SH} -c 'echo aaa$( echo bbb; echo ccc )ddd'
atf_check -s exit:0 -o inline:'aaabbb\ncccddd\n' -e empty \
${TEST_SH} -c 'echo "aaa$( echo bbb; echo ccc )ddd"'
atf_check -s exit:0 -o inline:'some string\n' -e empty \
${TEST_SH} -c 'X=$( echo some string ); echo "$X"'
atf_check -s exit:0 -o inline:'weird; string *\n' -e empty \
${TEST_SH} -c 'X=$( echo "weird; string *" ); echo "$X"'
rm -f * 2>/dev/null || :
for f in file-1 file-2
do
cp /dev/null "$f"
done
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found $( echo * )'
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found "$( echo * )"'
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found $('" echo '*' )"
atf_check -s exit:0 -o match:'Found \*' -e empty \
${TEST_SH} -c 'echo Found "$('" echo '*' "')"'
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found $('" echo \\* )"
atf_check -s exit:0 -o match:'Found \*' -e empty \
${TEST_SH} -c 'echo Found "$('" echo \\* )"\"
}
atf_test_case b_basic_backticks
b_basic_backticks_head() {
atf_set "descr" 'Test operation of old style ` ` substitutions'
}
b_basic_backticks_body() {
atf_check -s exit:0 -o match:'Result is true today' -e empty \
${TEST_SH} -c \
'echo Result is `true && echo true || echo false` today'
atf_check -s exit:0 -o match:'Result is false today' -e empty \
${TEST_SH} -c \
'echo Result is `false && echo true || echo false` today'
atf_check -s exit:0 -o match:'aaabbbccc' -e empty \
${TEST_SH} -c 'echo aaa` echo bbb `ccc'
atf_check -s exit:0 -o match:'aaabbb cccddd' -e empty \
${TEST_SH} -c 'echo aaa` echo bbb ccc `ddd'
atf_check -s exit:0 -o inline:'aaabbb cccddd\n' -e empty \
${TEST_SH} -c 'echo aaa` echo bbb; echo ccc `ddd'
atf_check -s exit:0 -o inline:'aaabbb\ncccddd\n' -e empty \
${TEST_SH} -c 'echo "aaa` echo bbb; echo ccc `ddd"'
atf_check -s exit:0 -o inline:'some string\n' -e empty \
${TEST_SH} -c 'X=` echo some string `; echo "$X"'
atf_check -s exit:0 -o inline:'weird; string *\n' -e empty \
${TEST_SH} -c 'X=` echo "weird; string *" `; echo "$X"'
rm -f * 2>/dev/null || :
for f in file-1 file-2
do
cp /dev/null "$f"
done
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found ` echo * `'
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found "` echo * `"'
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found `'" echo '*' "'`'
atf_check -s exit:0 -o match:'Found \*' -e empty \
${TEST_SH} -c 'echo Found "`'" echo '*' "'`"'
atf_check -s exit:0 -o match:'Found file-1 file-2' -e empty \
${TEST_SH} -c 'echo Found `'" echo \\* "'`'
atf_check -s exit:0 -o match:'Found \*' -e empty \
${TEST_SH} -c 'echo Found "`'" echo \\* "'`"'
}
atf_test_case c_nested_cmdsub
c_nested_cmdsub_head() {
atf_set "descr" "Test that cmd substitutions can be nested"
}
c_nested_cmdsub_body() {
atf_check -s exit:0 -o match:'__foobarbletch__' -e empty \
${TEST_SH} -c 'echo __$( echo foo$(echo bar)bletch )__'
atf_check -s exit:0 -o match:'_abcde_' -e empty \
${TEST_SH} -c 'echo _$(echo a$(echo $(echo b)c$(echo d))e )_'
atf_check -s exit:0 -o match:'123454321' -e empty \
${TEST_SH} -c 'echo 1$(echo 2$(echo 3$(echo 4$(echo 5)4)3)2)1'
}
atf_test_case d_nested_backticks
d_nested_backticks_head() {
atf_set "descr" "Tests that old style backtick cmd subs can be nested"
}
d_nested_backticks_body() {
atf_check -s exit:0 -o match:'__foobarbletch__' -e empty \
${TEST_SH} -c 'echo __` echo foo\`echo bar\`bletch `__'
atf_check -s exit:0 -o match:'_abcde_' -e empty \
${TEST_SH} -c \
'echo _`echo a\`echo \\\`echo b\\\`c\\\`echo d\\\`\`e `_'
atf_check -s exit:0 -o match:'123454321' -e empty \
${TEST_SH} -c \
'echo 1`echo 2\`echo 3\\\`echo 4\\\\\\\`echo 5\\\\\\\`4\\\`3\`2`1'
}
atf_test_case e_perverse_mixing
e_perverse_mixing_head() {
atf_set "descr" \
"Checks various mixed new and old style cmd substitutions"
}
e_perverse_mixing_body() {
atf_check -s exit:0 -o match:'__foobarbletch__' -e empty \
${TEST_SH} -c 'echo __$( echo foo`echo bar`bletch )__'
atf_check -s exit:0 -o match:'__foobarbletch__' -e empty \
${TEST_SH} -c 'echo __` echo foo$(echo bar)bletch `__'
atf_check -s exit:0 -o match:'_abcde_' -e empty \
${TEST_SH} -c 'echo _$(echo a`echo $(echo b)c$(echo d)`e )_'
atf_check -s exit:0 -o match:'_abcde_' -e empty \
${TEST_SH} -c 'echo _`echo a$(echo \`echo b\`c\`echo d\`)e `_'
atf_check -s exit:0 -o match:'12345654321' -e empty \
${TEST_SH} -c \
'echo 1`echo 2$(echo 3\`echo 4\\\`echo 5$(echo 6)5\\\`4\`3)2`1'
}
atf_test_case f_redirect_in_cmdsub
f_redirect_in_cmdsub_head() {
atf_set "descr" "Checks that redirects work in command substitutions"
}
f_redirect_in_cmdsub_body() {
atf_require_prog cat
atf_require_prog rm
rm -f file 2>/dev/null || :
atf_check -s exit:0 -o match:'_aa_' -e empty \
${TEST_SH} -c 'echo _$( echo a$( echo b > file )a)_'
atf_check -s exit:0 -o match:b -e empty ${TEST_SH} -c 'cat file'
atf_check -s exit:0 -o match:'_aba_' -e empty \
${TEST_SH} -c 'echo _$( echo a$( cat < file )a)_'
atf_check -s exit:0 -o match:'_aa_' -e empty \
${TEST_SH} -c 'echo _$( echo a$( echo d >> file )a)_'
atf_check -s exit:0 -o inline:'b\nd\n' -e empty ${TEST_SH} -c 'cat file'
atf_check -s exit:0 -o match:'_aa_' -e match:'not error' \
${TEST_SH} -c 'echo _$( echo a$( echo not error >&2 )a)_'
}
atf_test_case g_redirect_in_backticks
g_redirect_in_backticks_head() {
atf_set "descr" "Checks that redirects work in old style cmd sub"
}
g_redirect_in_backticks_body() {
atf_require_prog cat
atf_require_prog rm
rm -f file 2>/dev/null || :
atf_check -s exit:0 -o match:'_aa_' -e empty \
${TEST_SH} -c 'echo _` echo a\` echo b > file \`a`_'
atf_check -s exit:0 -o match:b -e empty ${TEST_SH} -c 'cat file'
atf_check -s exit:0 -o match:'_aba_' -e empty \
${TEST_SH} -c 'echo _` echo a\` cat < file \`a`_'
atf_check -s exit:0 -o match:'_aa_' -e empty \
${TEST_SH} -c 'echo _` echo a\` echo d >> file \`a`_'
atf_check -s exit:0 -o inline:'b\nd\n' -e empty ${TEST_SH} -c 'cat file'
atf_check -s exit:0 -o match:'_aa_' -e match:'not error' \
${TEST_SH} -c 'echo _` echo a\` echo not error >&2 \`a`_'
}
atf_test_case h_vars_in_cmdsub
h_vars_in_cmdsub_head() {
atf_set "descr" "Check that variables work in command substitutions"
}
h_vars_in_cmdsub_body() {
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo __$( echo ${X} )__'
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo __$( echo "${X}" )__'
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo "__$( echo ${X} )__"'
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo "__$( echo "${X}" )__"'
atf_check -s exit:0 -o inline:'a\n\nb\n\nc\n' -e empty \
${TEST_SH} -c "for X in a '' b '' c"'; do echo $( echo "$X" ); done'
atf_check -s exit:0 -o match:'__acd__' -e empty \
${TEST_SH} -c 'X=; unset Y; echo "__$( echo a${X-b}${Y-c}d)__"'
atf_check -s exit:0 -o match:'__abcd__' -e empty \
${TEST_SH} -c 'X=; unset Y; echo "__$( echo a${X:-b}${Y:-c}d)__"'
atf_check -s exit:0 -o match:'__XYX__' -e empty \
${TEST_SH} -c 'X=X; echo "__${X}$( X=Y; echo ${X} )${X}__"'
atf_check -s exit:0 -o match:'__def__' -e empty \
${TEST_SH} -c 'X=abc; echo "__$(X=def; echo "${X}" )__"'
atf_check -s exit:0 -o inline:'abcdef\nabc\n' -e empty \
${TEST_SH} -c 'X=abc; echo "$X$(X=def; echo ${X} )"; echo $X'
}
atf_test_case i_vars_in_backticks
i_vars_in_backticks_head() {
atf_set "descr" "Checks that variables work in old style cmd sub"
}
i_vars_in_backticks_body() {
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo __` echo ${X} `__'
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo __` echo "${X}" `__'
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo "__` echo ${X} `__"'
atf_check -s exit:0 -o match:'__abc__' -e empty \
${TEST_SH} -c 'X=abc; echo "__` echo \"${X}\" `__"'
atf_check -s exit:0 -o inline:'a\n\nb\n\nc\n' -e empty \
${TEST_SH} -c "for X in a '' b '' c"'; do echo $( echo "$X" ); done'
atf_check -s exit:0 -o match:'__acd__' -e empty \
${TEST_SH} -c 'X=; unset Y; echo "__$( echo a${X-b}${Y-c}d)__"'
atf_check -s exit:0 -o match:'__abcd__' -e empty \
${TEST_SH} -c 'X=; unset Y; echo "__$( echo a${X:-b}${Y:-c}d)__"'
atf_check -s exit:0 -o match:'__XYX__' -e empty \
${TEST_SH} -c 'X=X; echo "__${X}$( X=Y; echo ${X} )${X}__"'
atf_check -s exit:0 -o inline:'abcdef\nabc\n' -e empty \
${TEST_SH} -c 'X=abc; echo "$X`X=def; echo \"${X}\" `";echo $X'
# The following is nonsense, so is not included ...
# atf_check -s exit:0 -o match:'__abc__' -e empty \
# oV cV oV cV
# ${TEST_SH} -c 'X=abc; echo "__`X=def echo "${X}" `__"'
# `start in " ^ " ends, ` not yet
}
atf_test_case j_cmdsub_in_varexpand
j_cmdsub_in_varexpand_head() {
atf_set "descr" "Checks that command sub can be used in var expansion"
}
j_cmdsub_in_varexpand_body() {
atf_check -s exit:0 -o match:'foo' -e empty \
${TEST_SH} -c 'X=set; echo ${X+$(echo foo)}'
atf_check -s exit:0 -o match:'set' -e empty \
${TEST_SH} -c 'X=set; echo ${X-$(echo foo)}'
rm -f bar 2>/dev/null || :
atf_check -s exit:0 -o match:'set' -e empty \
${TEST_SH} -c 'X=set; echo ${X-$(echo foo > bar)}'
test -f bar && atf_fail "bar should not exist, but does"
atf_check -s exit:0 -o inline:'\n' -e empty \
${TEST_SH} -c 'X=set; echo ${X+$(echo foo > bar)}'
test -f bar || atf_fail "bar should exist, but does not"
}
atf_test_case k_backticks_in_varexpand
k_backticks_in_varexpand_head() {
atf_set "descr" "Checks that old style cmd sub works in var expansion"
}
k_backticks_in_varexpand_body() {
atf_check -s exit:0 -o match:'foo' -e empty \
${TEST_SH} -c 'X=set; echo ${X+`echo foo`}'
atf_check -s exit:0 -o match:'set' -e empty \
${TEST_SH} -c 'X=set; echo ${X-`echo foo`}'
rm -f bar 2>/dev/null || :
atf_check -s exit:0 -o match:'set' -e empty \
${TEST_SH} -c 'X=set; echo ${X-`echo foo > bar`}'
test -f bar && atf_fail "bar should not exist, but does"
atf_check -s exit:0 -o inline:'\n' -e empty \
${TEST_SH} -c 'X=set; echo ${X+`echo foo > bar`}'
test -f bar || atf_fail "bar should exist, but does not"
}
atf_test_case l_arithmetic_in_cmdsub
l_arithmetic_in_cmdsub_head() {
atf_set "descr" "Checks that arithmetic works in cmd substitutions"
}
l_arithmetic_in_cmdsub_body() {
atf_check -s exit:0 -o inline:'1 + 1 = 2\n' -e empty \
${TEST_SH} -c 'echo 1 + 1 = $( echo $(( 1 + 1 )) )'
atf_check -s exit:0 -o inline:'X * Y = 6\n' -e empty \
${TEST_SH} -c 'X=2; Y=3; echo X \* Y = $( echo $(( X * Y )) )'
atf_check -s exit:0 -o inline:'Y % X = 1\n' -e empty \
${TEST_SH} -c 'X=2; Y=3; echo Y % X = $( echo $(( $Y % $X )) )'
}
atf_test_case m_arithmetic_in_backticks
m_arithmetic_in_backticks_head() {
atf_set "descr" "Checks that arithmetic works in old style cmd sub"
}
m_arithmetic_in_backticks_body() {
atf_check -s exit:0 -o inline:'2 + 3 = 5\n' -e empty \
${TEST_SH} -c 'echo 2 + 3 = ` echo $(( 2 + 3 )) `'
atf_check -s exit:0 -o inline:'X * Y = 6\n' -e empty \
${TEST_SH} -c 'X=2; Y=3; echo X \* Y = ` echo $(( X * Y )) `'
atf_check -s exit:0 -o inline:'Y % X = 1\n' -e empty \
${TEST_SH} -c 'X=2; Y=3; echo Y % X = ` echo $(( $Y % $X )) `'
}
atf_test_case n_cmdsub_in_arithmetic
n_cmdsub_in_arithmetic_head() {
atf_set "descr" "Tests uses of command substitutions in arithmetic"
}
n_cmdsub_in_arithmetic_body() {
atf_check -s exit:0 -o inline:'7\n' -e empty \
${TEST_SH} -c 'echo $(( $( echo 3 ) $( echo + ) $( echo 4 ) ))'
atf_check -s exit:0 -o inline:'11\n7\n18\n4\n1\n' -e empty \
${TEST_SH} -c \
'for op in + - \* / %
do
echo $(( $( echo 9 ) $( echo "${op}" ) $( echo 2 ) ))
done'
}
atf_test_case o_backticks_in_arithmetic
o_backticks_in_arithmetic_head() {
atf_set "descr" "Tests old style cmd sub used in arithmetic"
}
o_backticks_in_arithmetic_body() {
atf_check -s exit:0 -o inline:'33\n' -e empty \
${TEST_SH} -c 'echo $(( `echo 77` `echo -` `echo 44`))'
atf_check -s exit:0 -o inline:'14\n8\n33\n3\n2\n' -e empty \
${TEST_SH} -c \
'for op in + - \* / %
do
echo $((`echo 11``echo "${op}"``echo 3`))
done'
}
atf_test_case p_cmdsub_in_heredoc
p_cmdsub_in_heredoc_head() {
atf_set "descr" "Checks that cmdsubs work inside a here document"
}
p_cmdsub_in_heredoc_body() {
atf_require_prog cat
atf_check -s exit:0 -o inline:'line 1+1\nline 2\nline 3\n' -e empty \
${TEST_SH} -c \
'cat <<- EOF
$( echo line 1 )$( echo +1 )
$( echo line 2;echo line 3 )
EOF'
}
atf_test_case q_backticks_in_heredoc
q_backticks_in_heredoc_head() {
atf_set "descr" "Checks that old style cmdsubs work in here docs"
}
q_backticks_in_heredoc_body() {
atf_require_prog cat
atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
${TEST_SH} -c \
'cat <<- EOF
`echo Mary ` `echo had a `
` echo little; echo lamb `
EOF'
}
atf_test_case r_heredoc_in_cmdsub
r_heredoc_in_cmdsub_head() {
atf_set "descr" "Checks that here docs work inside cmd subs"
}
r_heredoc_in_cmdsub_body() {
atf_require_prog cat
atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
${TEST_SH} -c 'echo "$( cat <<- \EOF
Mary had a
little
lamb
EOF
)"'
atf_check -s exit:0 -e empty \
-o inline:'Mary had 1\nlittle\nlamb\nMary had 4\nlittle\nlambs\n' \
${TEST_SH} -c 'for N in 1 4; do echo "$( cat <<- EOF
Mary had ${N}
little
lamb$( [ $N -gt 1 ] && echo s )
EOF
)"; done'
atf_check -s exit:0 -o inline:'A Calculation:\n2 * 7 = 14\n' -e empty \
${TEST_SH} -c 'echo "$( cat <<- EOF
A Calculation:
2 * 7 = $(( 2 * 7 ))
EOF
)"'
}
atf_test_case s_heredoc_in_backticks
s_heredoc_in_backticks_head() {
atf_set "descr" "Checks that here docs work inside old style cmd subs"
}
s_heredoc_in_backticks_body() {
atf_require_prog cat
atf_check -s exit:0 -o inline:'Mary had a little lamb\n' -e empty \
${TEST_SH} -c 'echo ` cat <<- \EOF
Mary had a
little
lamb
EOF
`'
atf_check -s exit:0 -o inline:'A Calculation:\n17 / 3 = 5\n' -e empty \
${TEST_SH} -c 'echo "` cat <<- EOF
A Calculation:
17 / 3 = $(( 17 / 3 ))
EOF
`"'
}
atf_test_case t_nested_cmdsubs_in_heredoc
t_nested_cmdsubs_in_heredoc_head() {
atf_set "descr" "Checks nested command substitutions in here docs"
}
t_nested_cmdsubs_in_heredoc_body() {
atf_require_prog cat
atf_require_prog rm
rm -f * 2>/dev/null || :
echo "Hello" > File
atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
${TEST_SH} -c 'cat <<- EOF
$(cat File) U
$( V=$(cat File); echo "${V%lo}p" ) me!
EOF'
rm -f * 2>/dev/null || :
echo V>V ; echo A>A; echo R>R
echo Value>VAR
atf_check -s exit:0 -o inline:'$2.50\n' -e empty \
${TEST_SH} -c 'cat <<- EOF
$(Value='\''$2.50'\'';eval echo $(eval $(cat V)$(cat A)$(cat R)=\'\''\$$(cat $(cat V)$(cat A)$(cat R))\'\''; eval echo \$$(set -- *;echo ${3}${1}${2})))
EOF'
}
atf_test_case u_nested_backticks_in_heredoc
u_nested_backticks_in_heredoc_head() {
atf_set "descr" "Checks nested old style cmd subs in here docs"
}
u_nested_backticks_in_heredoc_body() {
atf_require_prog cat
atf_require_prog rm
rm -f * 2>/dev/null || :
echo "Hello" > File
atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
${TEST_SH} -c 'cat <<- EOF
`cat File` U
`V=\`cat File\`; echo "${V%lo}p" ` me!
EOF'
rm -f * 2>/dev/null || :
echo V>V ; echo A>A; echo R>R
echo Value>VAR
atf_check -s exit:0 -o inline:'$5.20\n' -e empty \
${TEST_SH} -c 'cat <<- EOF
`Value='\''$5.20'\'';eval echo \`eval \\\`cat V\\\`\\\`cat A\\\`\\\`cat R\\\`=\\\'\''\\\$\\\`cat \\\\\\\`cat V\\\\\\\`\\\\\\\`cat A\\\\\\\`\\\\\\\`cat R\\\\\\\`\\\`\\\'\''; eval echo \\\$\\\`set -- *;echo \\\\\${3}\\\\\${1}\\\\\${2}\\\`\``
EOF'
}
atf_test_case v_cmdsub_paren_tests
v_cmdsub__paren_tests_head() {
atf_set "descr" "tests with cmdsubs containing embedded ')'"
}
v_cmdsub_paren_tests_body() {
# Tests from:
# http://www.in-ulm.de/~mascheck/various/cmd-subst/
# (slightly modified.)
atf_check -s exit:0 -o inline:'A.1\n' -e empty ${TEST_SH} -c \
'echo $(
case x in x) echo A.1;; esac
)'
atf_check -s exit:0 -o inline:'A.2\n' -e empty ${TEST_SH} -c \
'echo $(
case x in x) echo A.2;; esac # comment
)'
atf_check -s exit:0 -o inline:'A.3\n' -e empty ${TEST_SH} -c \
'echo $(
case x in (x) echo A.3;; esac
)'
atf_check -s exit:0 -o inline:'A.4\n' -e empty ${TEST_SH} -c \
'echo $(
case x in (x) echo A.4;; esac # comment
)'
atf_check -s exit:0 -o inline:'A.5\n' -e empty ${TEST_SH} -c \
'echo $(
case x in (x) echo A.5
esac
)'
atf_check -s exit:0 -o inline:'B: quoted )\n' -e empty ${TEST_SH} -c \
'echo $(
echo '\''B: quoted )'\''
)'
atf_check -s exit:0 -o inline:'C: comment then closing paren\n' \
-e empty ${TEST_SH} -c \
'echo $(
echo C: comment then closing paren # )
)'
atf_check -s exit:0 -o inline:'D.1: here-doc with )\n' \
-e empty ${TEST_SH} -c \
'echo $(
cat <<-\eof
D.1: here-doc with )
eof
)'
# D.2 is a bogus test.
atf_check -s exit:0 -o inline:'D.3: here-doc with \()\n' \
-e empty ${TEST_SH} -c \
'echo $(
cat <<-\eof
D.3: here-doc with \()
eof
)'
atf_check -s exit:0 -e empty \
-o inline:'E: here-doc terminated with a parenthesis ("academic")\n' \
${TEST_SH} -c \
'echo $(
cat <<-\)
E: here-doc terminated with a parenthesis ("academic")
)
)'
atf_check -s exit:0 -e empty \
-o inline:'F.1: here-doc embed with unbal single, back- or doublequote '\''\n' \
${TEST_SH} -c \
'echo $(
cat <<-"eof"
F.1: here-doc embed with unbal single, back- or doublequote '\''
eof
)'
atf_check -s exit:0 -e empty \
-o inline:'F.2: here-doc embed with unbal single, back- or doublequote "\n' \
${TEST_SH} -c \
'echo $(
cat <<-"eof"
F.2: here-doc embed with unbal single, back- or doublequote "
eof
)'
atf_check -s exit:0 -e empty \
-o inline:'F.3: here-doc embed with unbal single, back- or doublequote `\n' \
${TEST_SH} -c \
'echo $(
cat <<-"eof"
F.3: here-doc embed with unbal single, back- or doublequote `
eof
)'
atf_check -s exit:0 -e empty -o inline:'G: backslash at end of line\n' \
${TEST_SH} -c \
'echo $(
echo G: backslash at end of line # \
)'
atf_check -s exit:0 -e empty \
-o inline:'H: empty command-substitution\n' \
${TEST_SH} -c 'echo H: empty command-substitution $( )'
}
atf_test_case w_heredoc_outside_cmdsub
w_heredoc_outside_cmdsub_head() {
atf_set "descr" "Checks that here docs work inside cmd subs"
}
w_heredoc_outside_cmdsub_body() {
atf_require_prog cat
atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
${TEST_SH} -c 'echo "$( cat <<- \EOF )"
Mary had a
little
lamb
EOF
'
atf_check -s exit:0 -e empty \
-o inline:'Mary had 1\nlittle\nlamb\nMary had 4\nlittle\nlambs\n' \
${TEST_SH} -c 'for N in 1 4; do echo "$( cat <<- EOF )"
Mary had ${N}
little
lamb$( [ $N -gt 1 ] && echo s )
EOF
done'
atf_check -s exit:0 -o inline:'A Calculation:\n2 * 7 = 14\n' -e empty \
${TEST_SH} -c 'echo "$( cat <<- EOF)"
A Calculation:
2 * 7 = $(( 2 * 7 ))
EOF
'
}
atf_test_case x_heredoc_outside_backticks
x_heredoc_outside_backticks_head() {
atf_set "descr" "Checks that here docs work inside old style cmd subs"
}
x_heredoc_outside_backticks_body() {
atf_require_prog cat
atf_check -s exit:0 -o inline:'Mary had a little lamb\n' -e empty \
${TEST_SH} -c 'echo ` cat <<- \EOF `
Mary had a
little
lamb
EOF
'
atf_check -s exit:0 -o inline:'A Calculation:\n17 / 3 = 5\n' -e empty \
${TEST_SH} -c 'echo "` cat <<- EOF `"
A Calculation:
17 / 3 = $(( 17 / 3 ))
EOF
'
}
atf_test_case t_nested_cmdsubs_in_heredoc
t_nested_cmdsubs_in_heredoc_head() {
atf_set "descr" "Checks nested command substitutions in here docs"
}
t_nested_cmdsubs_in_heredoc_body() {
atf_require_prog cat
atf_require_prog rm
rm -f * 2>/dev/null || :
echo "Hello" > File
atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
${TEST_SH} -c 'cat <<- EOF
$(cat File) U
$( V=$(cat File); echo "${V%lo}p" ) me!
EOF'
rm -f * 2>/dev/null || :
echo V>V ; echo A>A; echo R>R
echo Value>VAR
atf_check -s exit:0 -o inline:'$2.50\n' -e empty \
${TEST_SH} -c 'cat <<- EOF
$(Value='\''$2.50'\'';eval echo $(eval $(cat V)$(cat A)$(cat R)=\'\''\$$(cat $(cat V)$(cat A)$(cat R))\'\''; eval echo \$$(set -- *;echo ${3}${1}${2})))
EOF'
}
atf_test_case z_absurd_heredoc_cmdsub_combos
z_absurd_heredoc_cmdsub_combos_head() {
atf_set "descr" "perverse and unusual cmd substitutions & more"
}
z_absurd_heredoc_cmdsub_combos_body() {
echo "Help!" > help
# This version works in NetBSD (& FreeBSD)'s sh (and most others)
atf_check -s exit:0 -o inline:'Help!\nMe 2\n' -e empty ${TEST_SH} -c '
cat <<- EOF
$(
cat <<- STOP
$(
cat `echo help`
)
STOP
)
$(
cat <<- END 4<<-TRASH
Me $(( 1 + 1 ))
END
This is unused noise!
TRASH
)
EOF
'
# atf_expect_fail "PR bin/50993 - heredoc parsing done incorrectly"
atf_check -s exit:0 -o inline:'Help!\nMe 2\n' -e empty ${TEST_SH} -c '
cat <<- EOF
$(
cat << STOP
$(
cat `echo help`
)
STOP
)
$(
cat <<- END 4<<TRASH
Me $(( 1 + 1 ))
END
This is unused noise!
TRASH
)
EOF
'
}
atf_init_test_cases() {
atf_add_test_case a_basic_cmdsub
atf_add_test_case b_basic_backticks
atf_add_test_case c_nested_cmdsub
atf_add_test_case d_nested_backticks
atf_add_test_case e_perverse_mixing
atf_add_test_case f_redirect_in_cmdsub
atf_add_test_case g_redirect_in_backticks
atf_add_test_case h_vars_in_cmdsub
atf_add_test_case i_vars_in_backticks
atf_add_test_case j_cmdsub_in_varexpand
atf_add_test_case k_backticks_in_varexpand
atf_add_test_case l_arithmetic_in_cmdsub
atf_add_test_case m_arithmetic_in_backticks
atf_add_test_case n_cmdsub_in_arithmetic
atf_add_test_case o_backticks_in_arithmetic
atf_add_test_case p_cmdsub_in_heredoc
atf_add_test_case q_backticks_in_heredoc
atf_add_test_case r_heredoc_in_cmdsub
atf_add_test_case s_heredoc_in_backticks
atf_add_test_case t_nested_cmdsubs_in_heredoc
atf_add_test_case u_nested_backticks_in_heredoc
atf_add_test_case v_cmdsub_paren_tests
atf_add_test_case w_heredoc_outside_cmdsub
atf_add_test_case x_heredoc_outside_backticks
atf_add_test_case z_absurd_heredoc_cmdsub_combos
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_evaltested.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
# $NetBSD: t_evaltested.sh,v 1.2 2016/03/27 14:50:01 christos Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
@ -24,6 +24,8 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
atf_test_case evaltested
@ -43,7 +45,7 @@ fi
echo "passed"
exit 0
EOF
output="$(/bin/sh helper.sh)"
output="$($TEST_SH helper.sh)"
[ $? = 0 ] && return
if [ -n "$output" ]

View file

@ -1,4 +1,4 @@
# $NetBSD: t_exit.sh,v 1.3 2012/04/13 06:12:32 jruoho Exp $
# $NetBSD: t_exit.sh,v 1.6 2016/05/07 23:51:30 kre Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
@ -24,74 +24,124 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
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)"
"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_check -o match:0 -e empty ${TEST_SH} -c 'true; true & echo $?'
# atf_expect_fail "PR bin/46327" (now fixed?)
atf_check -o match:0 -e empty ${TEST_SH} -c 'false; true & echo $?'
}
atf_test_case function
function_head() {
atf_set "descr" "Tests that \$? is correctly updated inside" \
"a function"
atf_set "descr" "Tests that \$? is correctly updated inside " \
"a function"
}
function_body() {
foo=`crud`
atf_check_equal 'x$foo' 'x1'
atf_check -s exit:0 -o match:STATUS=1-0 -e empty \
${TEST_SH} -c '
crud() {
test yes = no
cat <<-EOF
STATUS=$?
EOF
}
foo=$(crud)
echo "${foo}-$?"
'
}
atf_test_case readout
readout_head() {
atf_set "descr" "Tests that \$? is correctly updated in a" \
"compound expression"
atf_set "descr" "Tests that \$? is correctly updated in a " \
"compound expression"
}
readout_body() {
atf_check_equal '$( true && ! true | false; echo $? )' '0'
atf_check -s exit:0 -o match:0 -e empty \
${TEST_SH} -c 'true && ! true | false; echo $?'
}
atf_test_case trap_subshell
trap_subshell_head() {
atf_set "descr" "Tests that the trap statement in a subshell" \
"works when the subshell exits"
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_check -s exit:0 -o inline:'exiting\n' -e empty \
${TEST_SH} -c '( trap "echo exiting" EXIT; /usr/bin/true )'
}
atf_test_case trap_zero__implicit_exit
trap_zero__implicit_exit_head() {
atf_set "descr" "Tests that the trap statement in a subshell in a " \
"script works when the subshell simply runs out of commands"
}
trap_zero__implicit_exit_body() {
# PR bin/6764: sh works but ksh does not"
# 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_check -s exit:0 -o match:exiting -e empty ${TEST_SH} helper.sh
# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
}
atf_test_case trap_zero__explicit_exit
trap_zero__explicit_exit_head() {
atf_set "descr" "Tests that the trap statement in a subshell in a " \
"script works when the subshell executes an 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
echo '( trap "echo exiting" 0; exit; echo NO_NO_NO )' >helper.sh
atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
${TEST_SH} helper.sh
# test ksh by setting TEST_SH to /bin/ksh and run the entire set...
# atf_check -s exit: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_test_case simple_exit
simple_exit_head() {
atf_set "descr" "Tests that various values for exit status work"
}
# Note: ATF will not allow tests of exit values > 255, even if they would work
simple_exit_body() {
for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
do
atf_check -s exit:$N -o empty -e empty \
${TEST_SH} -c "exit $N; echo FOO; echo BAR >&2"
done
}
atf_test_case subshell_exit
subshell_exit_head() {
atf_set "descr" "Tests that subshell exit status works and \$? gets it"
}
# Note: ATF will not allow tests of exit values > 255, even if they would work
subshell_exit_body() {
for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
do
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -c "(exit $N); test \$? -eq $N"
done
}
atf_test_case subshell_background
subshell_background_head() {
atf_set "descr" "Tests that sh(1) sets '$?' properly when running " \
"a subshell in the background"
}
subshell_background_body() {
atf_check -o match:0 -e empty \
${TEST_SH} -c 'true; (false || true) & echo $?'
# atf_expect_fail "PR bin/46327" (now fixed?)
atf_check -o match:0 -e empty \
${TEST_SH} -c 'false; (false || true) & echo $?'
}
atf_init_test_cases() {
@ -101,5 +151,7 @@ atf_init_test_cases() {
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
atf_add_test_case simple_exit
atf_add_test_case subshell_exit
atf_add_test_case subshell_background
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_expand.sh,v 1.2 2013/10/06 21:05:50 ast Exp $
# $NetBSD: t_expand.sh,v 1.8 2016/04/29 18:29:17 christos Exp $
#
# Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
# All rights reserved.
@ -24,6 +24,8 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
#
# This file tests the functions in expand.c.
@ -50,19 +52,15 @@ dollar_at_head() {
}
dollar_at_body() {
# This one should work everywhere.
got=`echo "" "" | sed 's,$,EOL,'`
atf_check_equal ' EOL' '$got'
atf_check -s exit:0 -o inline:' EOL\n' -e empty \
${TEST_SH} -c 'echo "" "" | '" sed 's,\$,EOL,'"
# This code triggered the bug.
set -- "" ""
got=`echo "$@" | sed 's,$,EOL,'`
atf_check_equal ' EOL' '$got'
atf_check -s exit:0 -o inline:' EOL\n' -e empty \
${TEST_SH} -c 'set -- "" ""; echo "$@" | '" sed 's,\$,EOL,'"
set -- -
shift
n_arg() { echo $#; }
n_args=`n_arg "$@"`
atf_check_equal '0' '$n_args'
atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
'set -- -; shift; n_arg() { echo $#; }; n_arg "$@"'
}
atf_test_case dollar_at_with_text
@ -71,15 +69,61 @@ dollar_at_with_text_head() {
"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")"
cat <<'EOF' > h-f1
delim_argv() {
str=
while [ $# -gt 0 ]; do
if [ -z "${str}" ]; then
str=">$1<"
else
str="${str} >$1<"
fi
shift
done
echo "${str}"
}
EOF
cat <<'EOF' > h-f2
delim_argv() {
str=
while [ $# -gt 0 ]; do
str="${str}${str:+ }>$1<"
shift
done
echo "${str}"
}
EOF
chmod +x h-f1 h-f2
for f in 1 2
do
atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
". ./h-f${f}; "'set -- ; delim_argv "$@"'
atf_check -s exit:0 -o inline:'>foobar<\n' -e empty \
${TEST_SH} -c \
". ./h-f${f}; "'set -- ; delim_argv "foo$@bar"'
atf_check -s exit:0 -o inline:'>foo bar<\n' -e empty \
${TEST_SH} -c \
". ./h-f${f}; "'set -- ; delim_argv "foo $@ bar"'
atf_check -s exit:0 -o inline:'>a< >b< >c<\n' -e empty \
${TEST_SH} -c \
". ./h-f${f}; "'set -- a b c; delim_argv "$@"'
atf_check -s exit:0 -o inline:'>fooa< >b< >cbar<\n' -e empty \
${TEST_SH} -c \
". ./h-f${f}; "'set -- a b c; delim_argv "foo$@bar"'
atf_check -s exit:0 -o inline:'>foo a< >b< >c bar<\n' -e empty \
${TEST_SH} -c \
". ./h-f${f}; "'set -- a b c; delim_argv "foo $@ bar"'
done
}
atf_test_case strip
@ -91,8 +135,25 @@ strip_head() {
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_expect_fail "PR bin/43469" -- now fixed
for exp in \
'${line%%/\**}' \
'${line%%"/*"*}' \
'${line%%'"'"'/*'"'"'*}' \
'"${line%%/\**}"' \
'"${line%%"/*"*}"' \
'"${line%%'"'"'/*'"'"'*}"' \
'${line%/\**}' \
'${line%"/*"*}' \
'${line%'"'"'/*'"'"'*}' \
'"${line%/\**}"' \
'"${line%"/*"*}"' \
'"${line%'"'"'/*'"'"'*}"'
do
atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
"line='${line}'; echo :${exp}:"
done
}
atf_test_case varpattern_backslashes
@ -103,7 +164,8 @@ varpattern_backslashes_head() {
varpattern_backslashes_body() {
line='/foo/bar/*/baz'
stripped='/foo/bar/'
atf_check_equal $stripped ${line%%\**}
atf_check -o inline:'/foo/bar/\n' -e empty ${TEST_SH} -c \
'line="/foo/bar/*/baz"; echo ${line%%\**}'
}
atf_test_case arithmetic
@ -114,9 +176,13 @@ arithmetic_head() {
"this is true."
}
arithmetic_body() {
atf_check_equal '3' '$((1 + 2))'
atf_check_equal '2147483647' '$((0x7fffffff))'
atf_check_equal '9223372036854775807' '$(((1 << 63) - 1))'
atf_check -o inline:'3' -e empty ${TEST_SH} -c \
'printf %s $((1 + 2))'
atf_check -o inline:'2147483647' -e empty ${TEST_SH} -c \
'printf %s $((0x7fffffff))'
atf_check -o inline:'9223372036854775807' -e empty ${TEST_SH} -c \
'printf %s $(((1 << 63) - 1))'
}
atf_test_case iteration_on_null_parameter
@ -126,10 +192,178 @@ iteration_on_null_parameter_head() {
"PR bin/48202."
}
iteration_on_null_parameter_body() {
s1=`/bin/sh -uc 'N=; set -- ${N}; for X; do echo "[$X]"; done' 2>&1`
s2=`/bin/sh -uc 'N=; set -- ${N:-}; for X; do echo "[$X]"; done' 2>&1`
atf_check_equal '' '$s1'
atf_check_equal '[]' '$s2'
atf_check -o empty -e empty ${TEST_SH} -c \
'N=; set -- ${N}; for X; do echo "[$X]"; done'
}
atf_test_case iteration_on_quoted_null_parameter
iteration_on_quoted_null_parameter_head() {
atf_set "descr" \
'Check iteration of "$@" in for loop when set to null;'
}
iteration_on_quoted_null_parameter_body() {
atf_check -o inline:'[]\n' -e empty ${TEST_SH} -c \
'N=; set -- "${N}"; for X; do echo "[$X]"; done'
}
atf_test_case iteration_on_null_or_null_parameter
iteration_on_null_or_null_parameter_head() {
atf_set "descr" \
'Check expansion of null parameter as default for another null'
}
iteration_on_null_or_null_parameter_body() {
atf_check -o empty -e empty ${TEST_SH} -c \
'N=; E=; set -- ${N:-${E}}; for X; do echo "[$X]"; done'
}
atf_test_case iteration_on_null_or_missing_parameter
iteration_on_null_or_missing_parameter_head() {
atf_set "descr" \
'Check expansion of missing parameter as default for another null'
}
iteration_on_null_or_missing_parameter_body() {
# atf_expect_fail 'PR bin/50834'
atf_check -o empty -e empty ${TEST_SH} -c \
'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
}
nl='
'
reset()
{
TEST_NUM=0
TEST_FAILURES=''
TEST_FAIL_COUNT=0
TEST_ID="$1"
}
check()
{
fail=false
TEMP_FILE=$( mktemp OUT.XXXXXX )
TEST_NUM=$(( $TEST_NUM + 1 ))
MSG=
# our local shell (ATF_SHELL) better do quoting correctly...
# some of the tests expect us to expand $nl internally...
CMD="$1"
result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
STATUS=$?
if [ "${STATUS}" -ne "$3" ]; then
MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
MSG="${MSG} expected exit code $3, got ${STATUS}"
# don't actually fail just because of wrong exit code
# unless we either expected, or received "good"
case "$3/${STATUS}" in
(*/0|0/*) fail=true;;
esac
fi
if [ "$3" -eq 0 ]; then
if [ -s "${TEMP_FILE}" ]; then
MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
MSG="${MSG} Messages produced on stderr unexpected..."
MSG="${MSG}${nl}$( cat "${TEMP_FILE}" )"
fail=true
fi
else
if ! [ -s "${TEMP_FILE}" ]; then
MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
MSG="${MSG} Expected messages on stderr,"
MSG="${MSG} nothing produced"
fail=true
fi
fi
rm -f "${TEMP_FILE}"
# Remove newlines (use local shell for this)
oifs="$IFS"
IFS="$nl"
result="$(echo $result)"
IFS="$oifs"
if [ "$2" != "$result" ]
then
MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
MSG="${MSG} Expected output '$2', received '$result'"
fail=true
fi
if $fail
then
MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
MSG="${MSG} Full command: <<${CMD}>>"
fi
$fail && test -n "$TEST_ID" && {
TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+${nl}}"
TEST_FAILURES="${TEST_FAILURES}${TEST_ID}[$TEST_NUM]:"
TEST_FAILURES="${TEST_FAILURES} Test of '$1' failed.";
TEST_FAILURES="${TEST_FAILURES}${nl}${MSG}"
TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
return 0
}
$fail && atf_fail "Test[$TEST_NUM] of '$1' failed${nl}${MSG}"
return 0
}
results()
{
test -z "${TEST_ID}" && return 0
test -z "${TEST_FAILURES}" && return 0
echo >&2 "=========================================="
echo >&2 "While testing '${TEST_ID}'"
echo >&2 " - - - - - - - - - - - - - - - - -"
echo >&2 "${TEST_FAILURES}"
atf_fail \
"Test ${TEST_ID}: $TEST_FAIL_COUNT subtests (of $TEST_NUM) failed - see stderr"
}
atf_test_case shell_params
shell_params_head() {
atf_set "descr" "Test correct operation of the numeric parameters"
}
shell_params_body() {
atf_require_prog mktemp
reset shell_params
check 'set -- a b c; echo "$#: $1 $2 $3"' '3: a b c' 0
check 'set -- a b c d e f g h i j k l m; echo "$#: ${1}0 ${10} $10"' \
'13: a0 j a0' 0
check 'x="$0"; set -- a b; y="$0";
[ "x${x}y" = "x${y}y" ] && echo OK || echo x="$x" y="$y"' \
'OK' 0
check "${TEST_SH} -c 'echo 0=\$0 1=\$1 2=\$2' a b c" '0=a 1=b 2=c' 0
echo 'echo 0="$0" 1="$1" 2="$2"' > helper.sh
check "${TEST_SH} helper.sh a b c" '0=helper.sh 1=a 2=b' 0
check 'set -- a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh \
iiiiiiiii jjjjjjjjjj kkkkkkkkkkk
echo "${#}: ${#1} ${#2} ${#3} ${#4} ... ${#9} ${#10} ${#11}"' \
'11: 1 2 3 4 ... 9 10 11' 0
check 'set -- a b c; echo "$#: ${1-A} ${2-B} ${3-C} ${4-D} ${5-E}"' \
'3: a b c D E' 0
check 'set -- a "" c "" e
echo "$#: ${1:-A} ${2:-B} ${3:-C} ${4:-D} ${5:-E}"' \
'5: a B c D e' 0
check 'set -- a "" c "" e
echo "$#: ${1:+A} ${2:+B} ${3:+C} ${4:+D} ${5:+E}"' \
'5: A C E' 0
check 'set -- "abab*cbb"
echo "${1} ${1#a} ${1%b} ${1##ab} ${1%%b} ${1#*\*} ${1%\**}"' \
'abab*cbb bab*cbb abab*cb ab*cbb abab*cb cbb abab' 0
check 'set -- "abab?cbb"
echo "${1}:${1#*a}+${1%b*}-${1##*a}_${1%%b*}%${1#[ab]}=${1%?*}/${1%\?*}"' \
'abab?cbb:bab?cbb+abab?cb-b?cbb_a%bab?cbb=abab?cb/abab' 0
check 'set -- a "" c "" e; echo "${2:=b}"' '' 1
results
}
atf_init_test_cases() {
@ -139,4 +373,8 @@ atf_init_test_cases() {
atf_add_test_case varpattern_backslashes
atf_add_test_case arithmetic
atf_add_test_case iteration_on_null_parameter
atf_add_test_case iteration_on_quoted_null_parameter
atf_add_test_case iteration_on_null_or_null_parameter
atf_add_test_case iteration_on_null_or_missing_parameter
atf_add_test_case shell_params
}

View file

@ -1,6 +1,6 @@
# $NetBSD: t_fsplit.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
# $NetBSD: t_fsplit.sh,v 1.4 2016/03/27 14:50:01 christos Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -33,22 +33,51 @@
# the "${x-" and "}" were absent from the input line.
#
# So: sh -c 'set ${x-a b c}; echo $#' should give 3.
# and: sh -c 'set -- ${x-}' echo $#' shold give 0
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
nl='
'
check()
{
result="$(eval $1)"
TEST=$((${TEST} + 1))
case "$#" in
(2) ;;
(*) atf_fail "Internal test error, $# args to check test ${TEST}";;
esac
result=$( ${TEST_SH} -c "unset x; $1" )
STATUS="$?"
# Remove newlines
oifs="$IFS"
IFS="$nl"
result="$(echo $result)"
IFS="$oifs"
# trim the test text in case we use it in a message below
case "$1" in
????????????????*)
set -- "$(expr "$1" : '\(............\).*')..." "$2" ;;
esac
if [ "$2" != "$result" ]
then
atf_fail "expected [$2], found [$result]"
if [ "${STATUS}" = "0" ]
then
atf_fail "Test ${TEST} '$1': expected [$2], found [$result]"
else
atf_fail \
"TEST ${TEST} '$1' failed ($STATUS): expected [$2], found [$result]"
fi
elif [ "${STATUS}" != 0 ]
then
atf_fail "TEST ${TEST} '$1' failed ($STATUS)"
fi
}
@ -59,6 +88,7 @@ for_head() {
for_body() {
unset x
TEST=0
# Since I managed to break this, leave the test in
check 'for f in $x; do echo x${f}y; done' ''
}
@ -68,17 +98,121 @@ default_val_head() {
atf_set "descr" "Checks field splitting in variable default values"
}
default_val_body() {
unset x
TEST=0
# 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'
check 'set -- ${x-a b c}; echo $#' 3
check 'set -- ${x-"a b" c}; echo $#' 2
check 'set -- ${x-a "b c"}; echo $#' 2
check 'set -- ${x-"a b c"}; echo $#' 1
check "set -- \${x-'a b' c}; echo \$#" 2
check "set -- \${x-a 'b c'}; echo \$#" 2
check "set -- \${x-'a b c'}; echo \$#" 1
check 'set -- ${x-a\ b c}; echo $#' 2
check 'set -- ${x-a b\ c}; echo $#' 2
check 'set -- ${x-a\ b\ c}; echo $#' 1
check 'set -- ${x}; echo $#' 0
check 'set -- ${x-}; echo $#' 0
check 'set -- ${x-""}; echo $#' 1
check 'set -- ""${x}; echo $#' 1
check 'set -- ""${x-}; echo $#' 1
check 'set -- ""${x-""}; echo $#' 1
check 'set -- ${x}""; echo $#' 1
check 'set -- ${x-}""; echo $#' 1
check 'set -- ${x-""}""; echo $#' 1
check 'set -- ""${x}""; echo $#' 1
check 'set -- ""${x-}""; echo $#' 1
check 'set -- ""${x-""}""; echo $#' 1
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' \
'zaz zbz zcz zdz'
# I am not sure these two are correct, the rules on quoting word
# in ${var-word} are peculiar, and hard to fathom...
# They are what the NetBSD shell does, and bash, not the freebsd shell
# (as of Mar 1, 2016)
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'
}
atf_test_case replacement_val
replacement_val_head() {
atf_set "descr" "Checks field splitting in variable replacement values"
}
replacement_val_body() {
TEST=0
# Check that IFS is applied to text from ${x+...} unless it is inside
# any set of "...", or whole expansion is quoted, or both...
check 'x=BOGUS; set -- ${x+a b c}; echo $#' 3
check 'x=BOGUS; set -- ${x+"a b" c}; echo $#' 2
check 'x=BOGUS; set -- ${x+a "b c"}; echo $#' 2
check 'x=BOGUS; set -- ${x+"a b c"}; echo $#' 1
check "x=BOGUS; set -- \${x+'a b' c}; echo \$#" 2
check "x=BOGUS; set -- \${x+a 'b c'}; echo \$#" 2
check "x=BOGUS; set -- \${x+'a b c'}; echo \$#" 1
check 'x=BOGUS; set -- ${x+a\ b c}; echo $#' 2
check 'x=BOGUS; set -- ${x+a b\ c}; echo $#' 2
check 'x=BOGUS; set -- ${x+a\ b\ c}; echo $#' 1
check 'x=BOGUS; set -- ${x+}; echo $#' 0
check 'x=BOGUS; set -- ${x+""}; echo $#' 1
check 'x=BOGUS; set -- ""${x+}; echo $#' 1
check 'x=BOGUS; set -- ""${x+""}; echo $#' 1
check 'x=BOGUS; set -- ${x+}""; echo $#' 1
check 'x=BOGUS; set -- ${x+""}""; echo $#' 1
check 'x=BOGUS; set -- ""${x+}""; echo $#' 1
check 'x=BOGUS; set -- ""${x+""}""; echo $#' 1
# verify that the value of $x does not affecty the value of ${x+...}
check 'x=BOGUS; set -- ${x+}; echo X$1' X
check 'x=BOGUS; set -- ${x+""}; echo X$1' X
check 'x=BOGUS; set -- ""${x+}; echo X$1' X
check 'x=BOGUS; set -- ""${x+""}; echo X$1' X
check 'x=BOGUS; set -- ${x+}""; echo X$1' X
check 'x=BOGUS; set -- ${x+""}""; echo X$1' X
check 'x=BOGUS; set -- ""${x+}""; echo X$1' X
check 'x=BOGUS; set -- ""${x+""}""; echo X$1' X
check 'x=BOGUS; set -- ${x+}; echo X${1-:}X' X:X
check 'x=BOGUS; set -- ${x+""}; echo X${1-:}X' XX
check 'x=BOGUS; set -- ""${x+}; echo X${1-:}X' XX
check 'x=BOGUS; set -- ""${x+""}; echo X${1-:}X' XX
check 'x=BOGUS; set -- ${x+}""; echo X${1-:}X' XX
check 'x=BOGUS; set -- ${x+""}""; echo X${1-:}X' XX
check 'x=BOGUS; set -- ""${x+}""; echo X${1-:}X' XX
check 'x=BOGUS; set -- ""${x+""}""; echo X${1-:}X' XX
# and validate that the replacement can be used as expected
check 'x=BOGUS; for i in ${x+a b c}; do echo "z${i}z"; done'\
'zaz zbz zcz'
check 'x=BOGUS; for i in ${x+"a b" c}; do echo "z${i}z"; done'\
'za bz zcz'
check 'x=BOGUS; for i in ${x+"a ${x+b c}" d}; do echo "z${i}z"; done'\
'za b cz zdz'
check 'x=BOGUS; for i in ${x+"a ${x+"b c"}" d}; do echo "z${i}z"; done'\
'za b cz zdz'
check 'x=BOGUS; for i in ${x+a ${x+"b c"} d}; do echo "z${i}z"; done'\
'zaz zb cz zdz'
check 'x=BOGUS; for i in ${x+a ${x+b c} d}; do echo "z${i}z"; done'\
'zaz zbz zcz zdz'
}
atf_test_case ifs_alpha
@ -89,13 +223,19 @@ ifs_alpha_head() {
ifs_alpha_body() {
unset x
TEST=0
# 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'
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
@ -106,6 +246,7 @@ quote_head() {
quote_body() {
unset x
TEST=0
# Some quote propagation checks
check 'set "${x-a b c}"; echo $#' 1
check 'set "${x-"a b" c}"; echo $1' 'a b c'
@ -120,19 +261,44 @@ dollar_at_head() {
dollar_at_body() {
unset x
TEST=0
# 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'
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'
check 'set --; for i; do echo "z${i}z"; done' ''
check 'set --; for i in $@; do echo "z${i}z"; done' ''
check 'set --; for i in "$@"; do echo "z${i}z"; done' ''
# atf_expect_fail "PR bin/50834"
check 'set --; for i in ""$@; do echo "z${i}z"; done' 'zz'
# atf_expect_pass
check 'set --; for i in $@""; do echo "z${i}z"; done' 'zz'
check 'set --; for i in ""$@""; do echo "z${i}z"; done' 'zz'
check 'set --; for i in """$@"; do echo "z${i}z"; done' 'zz'
check 'set --; for i in "$@"""; 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'
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 a b c; for i in "$@$@"; do echo "z${i}z"; done' \
'zaz zbz zcaz zbz zcz'
check 'set a b c; for i in "$@""$@";do echo "z${i}z"; done' \
'zaz zbz zcaz zbz zcz'
}
atf_test_case ifs
@ -143,6 +309,7 @@ ifs_head() {
ifs_body() {
unset x
TEST=0
# 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'
@ -165,19 +332,26 @@ var_length_head() {
"a variable's length"
}
var_length_body() {
unset x
TEST=0
# 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'
export long
# first test that the test method works...
check 'set -u; : ${long}; echo ${#long}' '128'
# Check that we apply IFS to ${#var}
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 replacement_val
atf_add_test_case ifs_alpha
atf_add_test_case quote
atf_add_test_case dollar_at

View file

@ -1,4 +1,4 @@
# $NetBSD: t_here.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
# $NetBSD: t_here.sh,v 1.6 2016/03/31 16:21:52 christos Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
@ -24,50 +24,542 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
nl='
'
reset()
{
TEST_NUM=0
TEST_FAILURES=''
TEST_FAIL_COUNT=0
TEST_ID="$1"
}
check()
{
SVIFS="$IFS"
result="$(eval $1)"
# Remove newlines
fail=false
TEMP_FILE=$( mktemp OUT.XXXXXX )
TEST_NUM=$(( $TEST_NUM + 1 ))
# our local shell (ATF_SHELL) better do quoting correctly...
# some of the tests expect us to expand $nl internally...
CMD="nl='${nl}'; $1"
result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
STATUS=$?
if [ "${STATUS}" -ne "$3" ]; then
echo >&2 "[$TEST_NUM] expected exit code $3, got ${STATUS}"
# don't actually fail just because of wrong exit code
# unless we either expected, or received "good"
case "$3/${STATUS}" in
(*/0|0/*) fail=true;;
esac
fi
if [ "$3" -eq 0 ]; then
if [ -s "${TEMP_FILE}" ]; then
echo >&2 \
"[$TEST_NUM] Messages produced on stderr unexpected..."
cat "${TEMP_FILE}" >&2
fail=true
fi
else
if ! [ -s "${TEMP_FILE}" ]; then
echo >&2 \
"[$TEST_NUM] Expected messages on stderr, nothing produced"
fail=true
fi
fi
rm -f "${TEMP_FILE}"
# Remove newlines (use local shell for this)
oifs="$IFS"
IFS="$nl"
result="$(echo $result)"
IFS="$oifs"
if [ "$2" != "$result" ]
then
atf_fail "expected [$2], found [$result]"
echo >&2 "[$TEST_NUM] Expected output '$2', received '$result'"
fail=true
fi
IFS="$SVIFS"
if $fail
then
echo >&2 "[$TEST_NUM] Full command: <<${CMD}>>"
fi
$fail && test -n "$TEST_ID" && {
TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+
}${TEST_ID}[$TEST_NUM]: test of '$1' failed";
TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
return 0
}
$fail && atf_fail "Test[$TEST_NUM] of '$1' failed"
return 0
}
atf_test_case all
all_head() {
results()
{
test -z "${TEST_ID}" && return 0
test -z "${TEST_FAILURES}" && return 0
echo >&2 "=========================================="
echo >&2 "While testing '${TEST_ID}'"
echo >&2 " - - - - - - - - - - - - - - - - -"
echo >&2 "${TEST_FAILURES}"
atf_fail \
"Test ${TEST_ID}: $TEST_FAIL_COUNT subtests (of $TEST_NUM) failed - see stderr"
}
atf_test_case do_simple
do_simple_head() {
atf_set "descr" "Basic tests for here documents"
}
all_body() {
do_simple_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'
reset 'simple'
IFS=' '
check 'x=`cat <<EOF'$nl'text'${nl}EOF$nl'`; echo $x' 'text' 0
check 'x=`cat <<\EOF'$nl'text'${nl}EOF$nl'`; echo $x' 'text' 0
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 "y=${y};"'x=`cat <<EOF'$nl'te${y}t'${nl}EOF$nl'`; echo $x' \
'text' 0
check "y=${y};"'x=`cat <<\EOF'$nl'te${y}t'${nl}EOF$nl'`; echo $x' \
'te${y}t' 0
check "y=${y};"'x=`cat <<"EOF"'$nl'te${y}t'${nl}EOF$nl'`; echo $x' \
'te${y}t' 0
check "y=${y};"'x=`cat <<'"'EOF'"$nl'te${y}t'${nl}EOF$nl'`; echo $x' \
'te${y}t' 0
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 that quotes in the here doc survive and cause no problems
check "cat <<EOF${nl}te'xt${nl}EOF$nl" "te'xt" 0
check "cat <<\EOF${nl}te'xt${nl}EOF$nl" "te'xt" 0
check "cat <<'EOF'${nl}te'xt${nl}EOF$nl" "te'xt" 0
check "cat <<EOF${nl}te\"xt${nl}EOF$nl" 'te"xt' 0
check "cat <<\EOF${nl}te\"xt${nl}EOF$nl" 'te"xt' 0
check "cat <<'EOF'${nl}te\"xt${nl}EOF$nl" 'te"xt' 0
check "cat <<'EO'F${nl}te\"xt${nl}EOF$nl" 'te"xt' 0
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'
check "y=${y};"'x=`cat <<EOF'$nl'te'"'"'${y}t'${nl}EOF$nl'`; echo $x' \
'te'"'"'xt' 0
check "y=${y};"'x=`cat <<EOF'$nl'te'"''"'${y}t'${nl}EOF$nl'`; echo $x' \
'te'"''"'xt' 0
# note that the blocks of empty space in the following must
# be entirely tab characters, no spaces.
check 'x=`cat <<EOF'"$nl text${nl}EOF$nl"'`; echo "$x"' \
' text' 0
check 'x=`cat <<-EOF'"$nl text${nl}EOF$nl"'`; echo $x' \
'text' 0
check 'x=`cat <<-EOF'"${nl}text${nl} EOF$nl"'`; echo $x' \
'text' 0
check 'x=`cat <<-\EOF'"$nl text${nl} EOF$nl"'`; echo $x' \
'text' 0
check 'x=`cat <<- "EOF"'"$nl text${nl}EOF$nl"'`; echo $x' \
'text' 0
check 'x=`cat <<- '"'EOF'${nl}text${nl} EOF$nl"'`; echo $x' \
'text' 0
results
}
atf_test_case end_markers
end_markers_head() {
atf_set "descr" "Tests for various end markers of here documents"
}
end_markers_body() {
reset 'end_markers'
for end in EOF 1 \! '$$$' "string " a\\\ a\\\ \ '&' '' ' ' ' ' \
--STRING-- . '~~~' ')' '(' '#' '()' '(\)' '(\/)' '--' '\' '{' '}' \
VERYVERYVERYVERYLONGLONGLONGin_fact_absurdly_LONG_LONG_HERE_DOCUMENT_TERMINATING_MARKER_THAT_goes_On_forever_and_ever_and_ever...
do
# check unquoted end markers
case "${end}" in
('' | *[' ()\$&#*~']* ) ;; # skip unquoted endmark test for these
(*) check \
'x=$(cat << '"${end}${nl}text${nl}${end}${nl}"'); printf %s "$x"' 'text' 0
;;
esac
# and quoted end markers
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end}${nl}"'); printf %s "$x"' 'text' 0
# and see what happens if we encounter "almost" an end marker
case "${#end}" in
(0|1) ;; # too short to try truncation tests
(*) check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end%?}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end%?}" 0
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end#?}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end#?}" 0
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end%?}+${nl}${end}${nl}"');printf %s "$x"' \
"text ${end%?}+" 0
;;
esac
# or something that is a little longer
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end}x${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end}x" 0
check \
'x=$(cat <<'"'${end}'${nl}text${nl}!${end}${nl}${end}${nl}"'); printf %s "$x"' \
"text !${end}" 0
# or which does not begin at start of line
check \
'x=$(cat <<'"'${end}'${nl}text${nl} ${end}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end}" 0
check \
'x=$(cat <<'"'${end}'${nl}text${nl} ${end}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end}" 0
# or end at end of line
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end} ${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end} " 0
# or something that is correct much of the way, but then...
case "${#end}" in
(0) ;; # cannot test this one
(1) check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end}${end}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end}${end}" 0
;;
(2-7) pfx="${end%?}"
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end}${pfx}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end}${pfx}" 0
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${pfx}${end}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${pfx}${end}" 0
;;
(*) pfx=${end%??????}; sfx=${end#??????}
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${end}${sfx}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${end}${sfx}" 0
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${pfx}${end}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${pfx}${end}" 0
check \
'x=$(cat <<'"'${end}'${nl}text${nl}${pfx}${sfx}${nl}${end}${nl}"'); printf %s "$x"' \
"text ${pfx}${sfx}" 0
;;
esac
done
# Add striptabs tests (in similar way) here one day...
results
}
atf_test_case incomplete
incomplete_head() {
atf_set "descr" "Basic tests for incomplete here documents"
}
incomplete_body() {
reset incomplete
check 'cat <<EOF' '' 2
check 'cat <<- EOF' '' 2
check 'cat <<\EOF' '' 2
check 'cat <<- \EOF' '' 2
check 'cat <<EOF'"${nl}" '' 2
check 'cat <<- EOF'"${nl}" '' 2
check 'cat <<'"'EOF'${nl}" '' 2
check 'cat <<- "EOF"'"${nl}" '' 2
check 'cat << EOF'"${nl}${nl}" '' 2
check 'cat <<-EOF'"${nl}${nl}" '' 2
check 'cat << '"'EOF'${nl}${nl}" '' 2
check 'cat <<-"EOF"'"${nl}${nl}" '' 2
check 'cat << EOF'"${nl}"'line 1'"${nl}" '' 2
check 'cat <<-EOF'"${nl}"' line 1'"${nl}" '' 2
check 'cat << EOF'"${nl}"'line 1'"${nl}"' line 2'"${nl}" '' 2
check 'cat <<-EOF'"${nl}"' line 1'"${nl}"'line 2'"${nl}" '' 2
check 'cat << EOF'"${nl}line 1${nl}${nl}line3${nl}${nl}5!${nl}" '' 2
results
}
atf_test_case lineends
lineends_head() {
atf_set "descr" "Tests for line endings in here documents"
}
lineends_body() {
reset lineends
# note that "check" removes newlines from stdout before comparing.
# (they become blanks, provided there is something before & after)
check 'cat << \echo'"${nl}"'\'"${nl}echo${nl}echo${nl}" '\' 0
check 'cat << echo'"${nl}"'\'"${nl}echo${nl}echo${nl}" 'echo' 0
check 'cat << echo'"${nl}"'\\'"${nl}echo${nl}echo${nl}" '\' 0
check 'X=3; cat << ec\ho'"${nl}"'$X\'"${nl}echo${nl}echo${nl}" \
'$X\' 0
check 'X=3; cat << echo'"${nl}"'$X'"${nl}echo${nl}echo${nl}" \
'3' 0
check 'X=3; cat << echo'"${nl}"'$X\'"${nl}echo${nl}echo${nl}" \
'' 0
check 'X=3; cat << echo'"${nl}"'${X}\'"${nl}echo${nl}echo${nl}" \
'3echo' 0
check 'X=3; cat << echo'"${nl}"'\$X\'"${nl}echo${nl}echo${nl}" \
'$Xecho' 0
check 'X=3; cat << echo'"${nl}"'\\$X \'"${nl}echo${nl}echo${nl}" \
'\3 echo' 0
check \
'cat << "echo"'"${nl}"'line1\'"${nl}"'line2\'"${nl}echo${nl}echo${nl}" \
'line1\ line2\' 0
check \
'cat << echo'"${nl}"'line1\'"${nl}"'line2\'"${nl}echo${nl}echo${nl}" \
'line1line2echo' 0
results
}
atf_test_case multiple
multiple_head() {
atf_set "descr" "Tests for multiple here documents on one cmd line"
}
multiple_body() {
reset multiple
check \
"(cat ; cat <&3) <<EOF0 3<<EOF3${nl}STDIN${nl}EOF0${nl}-3-${nl}EOF3${nl}" \
'STDIN -3-' 0
check "(read line; echo \"\$line\"; cat <<EOF1; echo \"\$line\") <<EOF2
The File
EOF1
The Line
EOF2
" 'The Line The File The Line' 0
check "(read line; echo \"\$line\"; cat <<EOF; echo \"\$line\") <<EOF
The File
EOF
The Line
EOF
" 'The Line The File The Line' 0
check "V=1; W=2; cat <<-1; cat <<2; cat <<- 3; cat <<'4';"' cat <<\5
$V
$W
3
4
5
1
2
5
4*$W+\$V
3
$W
1
2
3
4
7+$V
$W+6
5
' '1 2 3 4 5 5 4*2+$V $W 1 2 3 7+$V $W+6' 0
results
}
atf_test_case nested
nested_head() {
atf_set "descr" "Tests for nested here documents for one cmd"
}
nested_body() {
reset nested
check \
'cat << EOF1'"${nl}"'$(cat << EOF2'"${nl}LINE${nl}EOF2${nl}"')'"${nl}EOF1${nl}"\
'LINE' 0
# This next one fails ... and correctly, so we will omit it (bad test)
# Reasoning is that the correct data "$(cat << EOF2)\nLINE\nEOF2\n" is
# collected for the outer (EOF1) heredoc, when that is parsed, it looks
# like
# $(cat <<EOF2)
# LINE
# EOF2
# which looks like a good command - except it is being parsed in "heredoc"
# syntax, which means it is enclosed in double quotes, which means that
# the newline after the ')' in the first line is not a newline token, but
# just a character. The EOF2 heredoc cannot start until after the next
# newline token, of which there are none here... LINE and EOF2 are just
# more data in the outer EOF1 heredoc for its "cat" command to read & write.
#
# The previous sub-test works because there the \n comes inside the
# $( ), and in there, the outside quoting rules are suspended, and it
# all starts again - so that \n is a newline token, and the EOF2 heredoc
# is processed.
#
# check \
# 'cat << EOF1'"${nl}"'$(cat << EOF2 )'"${nl}LINE${nl}EOF2${nl}EOF1${nl}" \
# 'LINE' 0
L='cat << EOF1'"${nl}"'LINE1$(cat << EOF2'"${nl}"
L="${L}"'LINE2$(cat << EOF3'"${nl}"
L="${L}"'LINE3$(cat << EOF4'"${nl}"
L="${L}"'LINE4$(cat << EOF5'"${nl}"
L="${L}LINE5${nl}EOF5${nl})4${nl}EOF4${nl})3${nl}"
L="${L}EOF3${nl})2${nl}EOF2${nl})1${nl}EOF1${nl}"
# That mess is ...
#
# cat <<EOF1
# LINE1$(cat << EOF2
# LINE2$(cat << EOF3
# LINE3$(cat << EOF4
# LINE4$(cat << EOF5
# LINE5
# EOF5
# )4
# EOF4
# )3
# EOF3
# )2
# EOF2
# )1
# EOF1
check "${L}" 'LINE1LINE2LINE3LINE4LINE54321' 0
results
}
atf_test_case quoting
quoting_head() {
atf_set "descr" "Tests for use of quotes inside here documents"
}
quoting_body() {
reset quoting
check 'X=!; cat <<- E\0F
<'\''"'\'' \\$X\$X "'\''" \\>
E0F
' '<'\''"'\'' \\$X\$X "'\''" \\>' 0
check 'X=!; cat <<- E0F
<'\''"'\'' \\$X\$X "'\''" \\>
E0F
' '<'\''"'\'' \!$X "'\''" \>' 0
check 'cat <<- END
$( echo "'\''" ) $( echo '\''"'\'' ) $( echo \\ )
END
' "' \" \\" 0
check 'X=12345; Y="string1 line1?-line2"; Z=; unset W; cat <<-EOF
${#X}${Z:-${Y}}${W+junk}${Y%%l*}${Y#*\?}
"$Z"'\''$W'\'' ${Y%" "*} $(( X + 54321 ))
EOF
' '5string1 line1?-line2string1 -line2 ""'\'\'' string1 66666' 0
results
}
atf_test_case side_effects
side_effects_head() {
atf_set "descr" "Tests how side effects in here documents are handled"
}
side_effects_body() {
atf_check -s exit:0 -o inline:'2\n1\n' -e empty ${TEST_SH} -c '
unset X
cat <<-EOF
${X=2}
EOF
echo "${X-1}"
'
}
atf_test_case vicious
vicious_head() {
atf_set "descr" "Tests for obscure and obnoxious uses of here docs"
}
vicious_body() {
reset
cat <<- \END_SCRIPT > script
cat <<ONE && cat \
<<TWO
a
ONE
b
TWO
END_SCRIPT
atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} script
# This next one is causing discussion currently (late Feb 2016)
# amongst stds writers & implementors. Consequently we
# will not check what it produces. The eventual result
# seems unlikely to be what we currently output, which
# is:
# A:echo line 1
# B:echo line 2)" && prefix DASH_CODE <<DASH_CODE
# B:echo line 3
# line 4
# line 5
#
# The likely intended output is ...
#
# A:echo line 3
# B:echo line 1
# line 2
# DASH_CODE:echo line 4)"
# DASH_CODE:echo line 5
#
# The difference is explained by differing opinions on just
# when processing of a here doc should start
cat <<- \END_SCRIPT > script
prefix() { sed -e "s/^/$1:/"; }
DASH_CODE() { :; }
prefix A <<XXX && echo "$(prefix B <<XXX
echo line 1
XXX
echo line 2)" && prefix DASH_CODE <<DASH_CODE
echo line 3
XXX
echo line 4)"
echo line 5
DASH_CODE
END_SCRIPT
# we will just verify that the shell can parse the
# script somehow, and doesn't fall over completely...
atf_check -s exit:0 -o ignore -e empty ${TEST_SH} script
}
atf_init_test_cases() {
atf_add_test_case all
atf_add_test_case do_simple # not worthy of a comment
atf_add_test_case end_markers # the mundane, the weird, the bizarre
atf_add_test_case incomplete # where the end marker isn't...
atf_add_test_case lineends # test weird line endings in heredocs
atf_add_test_case multiple # multiple << operators on one cmd
atf_add_test_case nested # here docs inside here docs
atf_add_test_case quoting # stuff quoted inside
atf_add_test_case side_effects # here docs that modify environment
atf_add_test_case vicious # evil test from the austin-l list...
}

View file

@ -0,0 +1,674 @@
# $NetBSD: t_option.sh,v 1.3 2016/03/08 14:19:28 christos Exp $
#
# Copyright (c) 2016 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 "sh" to test
: ${TEST_SH:="/bin/sh"}
# The standard
# http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
# says:
# ...[lots]
test_option_on_off()
{
atf_require_prog tr
for opt
do
# t is needed, as inside $()` $- appears to lose
# the 'e' option if it happened to already be
# set. Must check if that is what should
# happen, but that is a different issue.
test -z "${opt}" && continue
# if we are playing with more that one option at a
# time, the code below requires that we start with no
# options set, or it will mis-diagnose the situation
CLEAR=''
test "${#opt}" -gt 1 &&
CLEAR='xx="$-" && xx=$(echo "$xx" | tr -d cs) && test -n "$xx" && set +"$xx";'
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
"opt=${opt}"'
x() {
echo "ERROR: Unable to $1 option $2" >&2
exit 1
}
s() {
set -"$1"
t="$-"
x=$(echo "$t" | tr -d "$1")
test "$t" = "$x" && x set "$1"
return 0
}
c() {
set +"$1"
t="$-"
x=$(echo "$t" | tr -d "$1")
test "$t" != "$x" && x clear "$1"
return 0
}
'"${CLEAR}"'
# if we do not do this, -x tracing splatters stderr
# for some shells, -v does as well (is that correct?)
case "${opt}" in
(*[xv]*) exec 2>/dev/null;;
esac
o="$-"
x=$(echo "$o" | tr -d "$opt")
if [ "$o" = "$x" ]; then # option was off
s "${opt}"
c "${opt}"
else
c "${opt}"
s "${opt}"
fi
'
done
}
test_optional_on_off()
{
RET=0
OPTS=
for opt
do
test "${opt}" = n && continue
${TEST_SH} -c "set -${opt}" 2>/dev/null &&
OPTS="${OPTS} ${opt}" || RET=1
done
test -n "${OPTS}" && test_option_on_off ${OPTS}
return "${RET}"
}
atf_test_case set_a
set_a_head() {
atf_set "descr" "Tests that 'set -a' turns on all var export " \
"and that it behaves as defined by the standard"
}
set_a_body() {
atf_require_prog env
atf_require_prog grep
test_option_on_off a
# without -a, new variables should not be exported (so grep "fails")
atf_check -s exit:1 -o empty -e empty ${TEST_SH} -ce \
'unset VAR; set +a; VAR=value; env | grep "^VAR="'
# with -a, they should be
atf_check -s exit:0 -o match:VAR=value -e empty ${TEST_SH} -ce \
'unset VAR; set -a; VAR=value; env | grep "^VAR="'
}
atf_test_case set_C
set_C_head() {
atf_set "descr" "Tests that 'set -C' turns on no clobber mode " \
"and that it behaves as defined by the standard"
}
set_C_body() {
atf_require_prog ls
test_option_on_off C
# Check that the environment to use for the tests is sane ...
# we assume current dir is a new tempory directory & is empty
test -z "$(ls)" || atf_skip "Test execution directory not clean"
test -c "/dev/null" || atf_skip "Problem with /dev/null"
echo Dummy_Content > Junk_File
echo Precious_Content > Important_File
# Check that we can redirect onto file when -C is not set
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
'
D=$(ls -l Junk_File) || exit 1
set +C
echo "Overwrite it now" > Junk_File
A=$(ls -l Junk_File) || exit 1
test "${A}" != "${D}"
'
# Check that we cannot redirect onto file when -C is set
atf_check -s exit:0 -o empty -e not-empty ${TEST_SH} -c \
'
D=$(ls -l Important_File) || exit 1
set -C
echo "Fail to Overwrite it now" > Important_File
A=$(ls -l Important_File) || exit 1
test "${A}" = "${D}"
'
# Check that we can append to file, even when -C is set
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
'
D=$(ls -l Junk_File) || exit 1
set -C
echo "Append to it now" >> Junk_File
A=$(ls -l Junk_File) || exit 1
test "${A}" != "${D}"
'
# Check that we abort on attempt to redirect onto file when -Ce is set
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'
set -Ce
echo "Fail to Overwrite it now" > Important_File
echo "Should not reach this point"
'
# Last check that we can override -C for when we really need to
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
'
D=$(ls -l Junk_File) || exit 1
set -C
echo "Change the poor bugger again" >| Junk_File
A=$(ls -l Junk_File) || exit 1
test "${A}" != "${D}"
'
}
atf_test_case set_e
set_e_head() {
atf_set "descr" "Tests that 'set -e' turns on error detection " \
"and that a simple case behaves as defined by the standard"
}
set_e_body() {
test_option_on_off e
# Check that -e does nothing if no commands fail
atf_check -s exit:0 -o match:I_am_OK -e empty \
${TEST_SH} -c \
'false; printf "%s" I_am; set -e; true; printf "%s\n" _OK'
# and that it (silently, but with exit status) aborts if cmd fails
atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \
${TEST_SH} -c \
'false; printf "%s" I_am; set -e; false; printf "%s\n" _Broken'
# same, except -e this time is on from the beginning
atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \
${TEST_SH} -ec 'printf "%s" I_am; false; printf "%s\n" _Broken'
# More checking of -e in other places, there is lots to deal with.
}
atf_test_case set_f
set_f_head() {
atf_set "descr" "Tests that 'set -f' turns off pathname expansion " \
"and that it behaves as defined by the standard"
}
set_f_body() {
atf_require_prog ls
test_option_on_off f
# Check that the environment to use for the tests is sane ...
# we assume current dir is a new tempory directory & is empty
test -z "$(ls)" || atf_skip "Test execution directory not clean"
# we will assume that atf will clean up this junk directory
# when we are done. But for testing pathname expansion
# we need files
for f in a b c d e f aa ab ac ad ae aaa aab aac aad aba abc bbb ccc
do
echo "$f" > "$f"
done
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -ec \
'X=$(echo b*); Y=$(echo b*); test "${X}" != "a*";
test "${X}" = "${Y}"'
# now test expansion is different when -f is set
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -ec \
'X=$(echo b*); Y=$(set -f; echo b*); test "${X}" != "${Y}"'
}
atf_test_case set_n
set_n_head() {
atf_set "descr" "Tests that 'set -n' supresses command execution " \
"and that it behaves as defined by the standard"
}
set_n_body() {
# pointless to test this, if it turns on, it stays on...
# test_option_on_off n
# so just allow the tests below to verify it can be turned on
# nothing should be executed, hence no output...
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -enc 'echo ABANDON HOPE; echo ALL YE; echo ...'
# this is true even when the "commands" do not exist
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -enc 'ERR; FAIL; ABANDON HOPE'
# but if there is a syntax error, it should be detected (w or w/o -e)
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -enc 'echo JUMP; for frogs swim; echo in puddles'
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -nc 'echo ABANDON HOPE; echo "ALL YE; echo ...'
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -enc 'echo ABANDON HOPE;; echo ALL YE; echo ...'
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -nc 'do YOU ABANDON HOPE; for all eternity?'
# now test enabling -n in the middle of a script
# note that once turned on, it cannot be turned off again.
#
# omit more complex cases, as those can send some shells
# into infinite loops, and believe it or not, that might be OK!
atf_check -s exit:0 -o match:first -o not-match:second -e empty \
${TEST_SH} -c 'echo first; set -n; echo second'
atf_check -s exit:0 -o match:first -o not-match:third -e empty \
${TEST_SH} -c 'echo first; set -n; echo second; set +n; echo third'
atf_check -s exit:0 -o inline:'a\nb\n' -e empty \
${TEST_SH} -c 'for x in a b c d
do
case "$x" in
a);; b);; c) set -n;; d);;
esac
printf "%s\n" "$x"
done'
# This last one is a bit more complex to explain, so I will not try
# First, we need to know what signal number is used for SIGUSR1 on
# the local (testing) system (signal number is $(( $XIT - 128 )) )
# this will take slightly over 1 second elapsed time (the sleep 1)
# The "10" for the first sleep just needs to be something big enough
# that the rest of the commands have time to complete, even on
# very slow testing systems. 10 should be enough. Otherwise irrelevant
# The shell will usually blather to stderr about the sleep 10 being
# killed, but it affects nothing, so just allow it to cry.
(sleep 10 & sleep 1; kill -USR1 $!; wait $!)
XIT="$?"
# The exit value should be an integer > 128 and < 256 (often 158)
# If it is not just skip the test
# If we do run the test, it should take (slightly over) either 1 or 2
# seconds to complete, depending upon the shell being tested.
case "${XIT}" in
( 129 | 1[3-9][0-9] | 2[0-4][0-9] | 25[0-5] )
# The script below should exit with the same code - no output
# Or that is the result that seems best explanable.
# "set -n" in uses like this is not exactly well defined...
# This script comes from a member of the austin group
# (they author changes to the posix shell spec - and more.)
# The author is also an (occasional?) NetBSD user.
atf_check -s exit:${XIT} -o empty -e empty ${TEST_SH} -c '
trap "set -n" USR1
{ sleep 1; kill -USR1 $$; sleep 1; } &
false
wait && echo t || echo f
wait
echo foo
'
;;
esac
}
atf_test_case set_u
set_u_head() {
atf_set "descr" "Tests that 'set -u' turns on unset var detection " \
"and that it behaves as defined by the standard"
}
set_u_body() {
test_option_on_off u
# first make sure it is OK to unset an unset variable
atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset _UNSET_VARIABLE_; echo OK'
# even if -u is set
atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -cue \
'unset _UNSET_VARIABLE_; echo OK'
# and that without -u accessing an unset variable is harmless
atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset X; echo ${X}; echo OK'
# and that the unset variable test expansion works properly
atf_check -s exit:0 -o match:OKOK -e empty ${TEST_SH} -ce \
'unset X; printf "%s" ${X-OK}; echo OK'
# Next test that with -u set, the shell aborts on access to unset var
# do not use -e, want to make sure it is -u that causes abort
atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo ${X}; echo ERR'
# quoting should make no difference...
atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo "${X}"; echo ERR'
# Now a bunch of accesses to unset vars, with -u, in ways that are OK
atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset X; set -u; echo ${X-GOOD}; echo OK'
atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset X; set -u; echo ${X-OK}'
atf_check -s exit:0 -o not-match:ERR -o match:OK -e empty \
${TEST_SH} -ce 'unset X; set -u; echo ${X+ERR}; echo OK'
# and some more ways that are not OK
atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo ${X#foo}; echo ERR'
atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo ${X%%bar}; echo ERR'
# lastly, just while we are checking unset vars, test aborts w/o -u
atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; echo ${X?}; echo ERR'
atf_check -s not-exit:0 -o not-match:ERR -e match:X_NOT_SET \
${TEST_SH} -c 'unset X; echo ${X?X_NOT_SET}; echo ERR'
}
atf_test_case set_v
set_v_head() {
atf_set "descr" "Tests that 'set -v' turns on input read echoing " \
"and that it behaves as defined by the standard"
}
set_v_body() {
test_option_on_off v
# check that -v does nothing if no later input line is read
atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \
-e empty \
${TEST_SH} -ec 'printf "%s" OK; set -v; echo OK; exit 0'
# but that it does when there are multiple lines
cat <<- 'EOF' |
set -v
printf %s OK
echo OK
exit 0
EOF
atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \
-e match:printf -e match:OK -e match:echo \
-e not-match:set ${TEST_SH}
# and that it can be disabled again
cat <<- 'EOF' |
set -v
printf %s OK
set +v
echo OK
exit 0
EOF
atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \
-e match:printf -e match:OK -e not-match:echo \
${TEST_SH}
# and lastly, that shell keywords do get output when "read"
cat <<- 'EOF' |
set -v
for i in 111 222 333
do
printf %s $i
done
exit 0
EOF
atf_check -s exit:0 \
-o match:111222333 -o not-match:printf \
-o not-match:for -o not-match:do -o not-match:done \
-e match:printf -e match:111 -e not-match:111222 \
-e match:for -e match:do -e match:done \
${TEST_SH}
}
atf_test_case set_x
set_x_head() {
atf_set "descr" "Tests that 'set -x' turns on command exec logging " \
"and that it behaves as defined by the standard"
}
set_x_body() {
test_option_on_off x
# check that cmd output appears after -x is enabled
atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \
-e not-match:printf -e match:OK -e match:echo \
${TEST_SH} -ec 'printf "%s" OK; set -x; echo OK; exit 0'
# and that it stops again afer -x is disabled
atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \
-e match:printf -e match:OK -e not-match:echo \
${TEST_SH} -ec 'set -x; printf "%s" OK; set +x; echo OK; exit 0'
# also check that PS4 is output correctly
atf_check -s exit:0 \
-o match:OK -o not-match:echo \
-e match:OK -e match:Run:echo \
${TEST_SH} -ec 'PS4=Run:; set -x; echo OK; exit 0'
return 0
# This one seems controversial... I suspect it is NetBSD's sh
# that is wrong to not output "for" "while" "if" ... etc
# and lastly, that shell keywords do not get output when "executed"
atf_check -s exit:0 \
-o match:111222333 -o not-match:printf \
-o not-match:for \
-e match:printf -e match:111 -e not-match:111222 \
-e not-match:for -e not-match:do -e not-match:done \
${TEST_SH} -ec \
'set -x; for i in 111 222 333; do printf "%s" $i; done; echo; exit 0'
}
opt_test_setup()
{
test -n "$1" || { echo >&2 "Internal error"; exit 1; }
cat > "$1" << 'END_OF_FUNCTIONS'
local_opt_check()
{
local -
}
instr()
{
expr "$2" : "\(.*$1\)" >/dev/null
}
save_opts()
{
local -
set -e
set -u
instr e "$-" && instr u "$-" && return 0
echo ERR
}
fiddle_opts()
{
set -e
set -u
instr e "$-" && instr u "$-" && return 0
echo ERR
}
local_test()
{
set +eu
save_opts
instr '[eu]' "$-" || printf %s "OK"
fiddle_opts
instr e "$-" && instr u "$-" && printf %s "OK"
set +eu
}
END_OF_FUNCTIONS
}
atf_test_case restore_local_opts
restore_local_opts_head() {
atf_set "descr" "Tests that 'local -' saves and restores options. " \
"Note that "local" is a local shell addition"
}
restore_local_opts_body() {
atf_require_prog cat
atf_require_prog expr
FN="test-funcs.$$"
opt_test_setup "${FN}" || atf_skip "Cannot setup test environment"
${TEST_SH} -ec ". './${FN}'; local_opt_check" 2>/dev/null ||
atf_skip "sh extension 'local -' not supported by ${TEST_SH}"
atf_check -s exit:0 -o match:OKOK -o not-match:ERR -e empty \
${TEST_SH} -ec ". './${FN}'; local_test"
}
atf_test_case vi_emacs_VE_toggle
vi_emacs_VE_toggle_head() {
atf_set "descr" "Tests enabling vi disables emacs (and v.v - but why?)"\
" Note that -V and -E are local shell additions"
}
vi_emacs_VE_toggle_body() {
test_optional_on_off V E ||
atf_skip "One or both V & E opts unsupported by ${TEST_SH}"
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '
q() {
eval "case \"$-\" in
(*${2}*) return 1;;
(*${1}*) return 0;;
esac"
return 1
}
x() {
echo >&2 "Option set or toggle failure:" \
" on=$1 off=$2 set=$-"
exit 1
}
set -V; q V E || x V E
set -E; q E V || x E V
set -V; q V E || x V E
set +EV; q "" "[VE]" || x "" VE
exit 0
'
}
atf_test_case xx_bogus
xx_bogus_head() {
atf_set "descr" "Tests that attempting to set a nonsense option fails."
}
xx_bogus_body() {
# Biggest problem here is picking a "nonsense option" that is
# not implemented by any shell, anywhere. Hopefully this will do.
# 'set' is a special builtin, so a conforming shell should exit
# on an arg error, and the ERR should not be printed.
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -c 'set -% ; echo ERR'
}
atf_test_case Option_switching
Option_switching_head() {
atf_set "descr" "options can be enabled and disabled"
}
Option_switching_body() {
# Cannot test -m, setting it causes test shell to fail...
# (test shell gets SIGKILL!) Wonder why ... something related to atf
# That is, it works if just run as "sh -c 'echo $-; set -m; echo $-'"
# Don't bother testing toggling -n, once on, it stays on...
# (and because the test fn refuses to allow us to try)
# Cannot test -o or -c here, or the extension -s
# they can only be used, not switched
# these are the posix options, that all shells should implement
test_option_on_off a b C e f h u v x # m
# and these are extensions that might not exist (non-fatal to test)
# -i and -s (and -c) are posix options, but are not required to
# be accessable via the "set" command, just the command line.
# We allow for -i to work with set, as that makes some sense,
# -c and -s do not.
test_optional_on_off E i I p q V || true
# Also test (some) option combinations ...
# only testing posix options here, because it is easier...
test_option_on_off aeu vx Ca aCefux
}
atf_init_test_cases() {
# tests are run in order sort of names produces, so choose names wisely
# this one tests turning on/off all the mandatory. and extra flags
atf_add_test_case Option_switching
# and this tests the NetBSD "local -" functionality in functions.
atf_add_test_case restore_local_opts
# no tests for -m (no idea how to do that one)
# -I (no easy way to generate the EOF it ignores)
# -i (not sure how to test that one at the minute)
# -p (because we aren't going to run tests setuid)
# -V/-E (too much effort, and a real test would be huge)
# -c (because almost all the other tests test it anyway)
# -q (because, for now, I am lazy)
# -s (coming soon, hopefully)
# -o (really +o: again, hopefully soon)
# -o longname (again, just laziness, don't wait...)
# -h/-b (because NetBSD doesn't implement them)
atf_add_test_case set_a
atf_add_test_case set_C
atf_add_test_case set_e
atf_add_test_case set_f
atf_add_test_case set_n
atf_add_test_case set_u
atf_add_test_case set_v
atf_add_test_case set_x
atf_add_test_case vi_emacs_VE_toggle
atf_add_test_case xx_bogus
}

View file

@ -0,0 +1,903 @@
# $NetBSD: t_redir.sh,v 1.9 2016/05/14 00:33:02 kre Exp $
#
# Copyright (c) 2016 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 "sh" to test
: ${TEST_SH:="/bin/sh"}
# Any failures in this first test means it is not worth bothering looking
# for causes of failures in any other tests, make this one work first.
# Problems with this test usually mean inadequate ATF_SHELL used for testing.
# (though if all pass but the last, it might be a TEST_SH problem.)
atf_test_case basic_test_method_test
basic_test_method_test_head()
{
atf_set "descr" "Tests that test method works as expected"
}
basic_test_method_test_body()
{
cat <<- 'DONE' |
DONE
atf_check -s exit:0 -o empty -e empty ${TEST_SH}
cat <<- 'DONE' |
DONE
atf_check -s exit:0 -o match:0 -e empty ${TEST_SH} -c 'wc -l'
cat <<- 'DONE' |
echo hello
DONE
atf_check -s exit:0 -o match:hello -e empty ${TEST_SH}
cat <<- 'DONE' |
echo hello
DONE
atf_check -s exit:0 -o match:1 -e empty ${TEST_SH} -c 'wc -l'
cat <<- 'DONE' |
echo hello\
world
DONE
atf_check -s exit:0 -o match:helloworld -e empty ${TEST_SH}
cat <<- 'DONE' |
echo hello\
world
DONE
atf_check -s exit:0 -o match:2 -e empty ${TEST_SH} -c 'wc -l'
printf '%s\n%s\n%s\n' Line1 Line2 Line3 > File
atf_check -s exit:0 -o inline:'Line1\nLine2\nLine3\n' -e empty \
${TEST_SH} -c 'cat File'
cat <<- 'DONE' |
set -- X "" '' Y
echo ARGS="${#}"
echo '' -$1- -$2- -$3- -$4-
cat <<EOF
X=$1
EOF
cat <<\EOF
Y=$4
EOF
DONE
atf_check -s exit:0 -o match:ARGS=4 -o match:'-X- -- -- -Y-' \
-o match:X=X -o match:'Y=\$4' -e empty ${TEST_SH}
}
atf_test_case do_input_redirections
do_input_redirections_head()
{
atf_set "descr" "Tests that simple input redirection works"
}
do_input_redirections_body()
{
printf '%s\n%s\n%s\nEND\n' 'First Line' 'Second Line' 'Line 3' >File
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH} -c 'cat < File'
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH} -c 'cat <File'
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH} -c 'cat< File'
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH} -c 'cat < "File"'
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH} -c '< File cat'
ln File wc
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH} -c '< wc cat'
mv wc cat
atf_check -s exit:0 -e empty -o match:4 \
${TEST_SH} -c '< cat wc'
cat <<- 'EOF' |
for l in 1 2 3; do
read line < File
echo "$line"
done
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nFirst Line\nFirst Line\n' \
${TEST_SH}
cat <<- 'EOF' |
for l in 1 2 3; do
read line
echo "$line"
done <File
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\n' \
${TEST_SH}
cat <<- 'EOF' |
for l in 1 2 3; do
read line < File
echo "$line"
done <File
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nFirst Line\nFirst Line\n' \
${TEST_SH}
cat <<- 'EOF' |
line=
while [ "$line" != END ]; do
read line || exit 1
echo "$line"
done <File
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH}
cat <<- 'EOF' |
while :; do
read line || exit 0
echo "$line"
done <File
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
${TEST_SH}
cat <<- 'EOF' |
l=''
while read line < File
do
echo "$line"
l="${l}x"
[ ${#l} -ge 3 ] && break
done
echo DONE
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nFirst Line\nFirst Line\nDONE\n' \
${TEST_SH}
cat <<- 'EOF' |
while read line
do
echo "$line"
done <File
echo DONE
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nEND\nDONE\n' \
${TEST_SH}
cat <<- 'EOF' |
l=''
while read line
do
echo "$line"
l="${l}x"
[ ${#l} -ge 3 ] && break
done <File
echo DONE
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line\nSecond Line\nLine 3\nDONE\n' ${TEST_SH}
cat <<- 'EOF' |
l=''
while read line1 <File
do
read line2
echo "$line1":"$line2"
l="${l}x"
[ ${#l} -ge 2 ] && break
done <File
echo DONE
EOF
atf_check -s exit:0 -e empty \
-o inline:'First Line:First Line\nFirst Line:Second Line\nDONE\n' \
${TEST_SH}
}
atf_test_case do_output_redirections
do_output_redirections_head()
{
atf_set "descr" "Test Output redirections"
}
do_output_redirections_body()
{
nl='
'
T=0
i() { T=$(expr "$T" + 1); }
rm -f Output 2>/dev/null || :
test -f Output && atf_fail "Unable to remove Output file"
#1
i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '> Output'
test -f Output || atf_fail "#$T: Did not make Output file"
#2
rm -f Output 2>/dev/null || :
i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '>> Output'
test -f Output || atf_fail "#$T: Did not make Output file"
#3
rm -f Output 2>/dev/null || :
i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '>| Output'
test -f Output || atf_fail "#$T: Did not make Output file"
#4
rm -f Output 2>/dev/null || :
i
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Hello >Output'
test -s Output || atf_fail "#$T: Did not make non-empty Output file"
test "$(cat Output)" = "Hello" ||
atf_fail "#$T: Incorrect Output: Should be 'Hello' is '$(cat Output)'"
#5
i
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Hello>!Output'
test -s Output || atf_fail "#$T: Did not make non-empty Output file"
test "$(cat Output)" = "Hello" ||
atf_fail "#$T: Incorrect Output: Should be 'Hello' is '$(cat Output)'"
#6
i
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Bye >>Output'
test -s Output || atf_fail "#$T: Removed Output file"
test "$(cat Output)" = "Hello${nl}Bye" || atf_fail \
"#$T: Incorrect Output: Should be 'Hello\\nBye' is '$(cat Output)'"
#7
i; atf_check -s exit:0 -o inline:'line 1\nline 2\n' -e empty \
${TEST_SH} -c \
'echo line 1 > Output; echo line 2 >> Output; cat Output'
test "$(cat Output)" = "line 1${nl}line 2" || atf_fail \
"#$T: Incorrect Output: Should be 'line 1\\nline 2' is '$(cat Output)'"
#8
i; atf_check -s exit:0 -o inline:'line 2\n' -e empty \
${TEST_SH} -c 'echo line 1 > Output; echo line 2'
test "$(cat Output)" = "line 1" || atf_fail \
"#$T: Incorrect Output: Should be 'line 1' is '$(cat Output)'"
#9
i; atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -c '(echo line 1; echo line 2 > Out2) > Out1'
test "$(cat Out1)" = "line 1" || atf_fail \
"#$T: Incorrect Out1: Should be 'line 1' is '$(cat Out1)'"
test "$(cat Out2)" = "line 2" || atf_fail \
"#$T: Incorrect Out2: Should be 'line 2' is '$(cat Out2)'"
#10
i; atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -c '{ echo line 1; echo line 2 > Out2;} > Out1'
test "$(cat Out1)" = "line 1" || atf_fail \
"#$T: Incorrect Out1: Should be 'line 1' is '$(cat Out1)'"
test "$(cat Out2)" = "line 2" || atf_fail \
"#$T: Incorrect Out2: Should be 'line 2' is '$(cat Out2)'"
#11
i; rm -f Out1 Out2 2>/dev/null || :
cat <<- 'EOF' |
for arg in 'line 1' 'line 2' 'line 3'
do
echo "$arg"
echo "$arg" > Out1
done > Out2
EOF
atf_check -s exit:0 -o empty -e empty ${TEST_SH}
test "$(cat Out1)" = "line 3" || atf_fail \
"#$T: Incorrect Out1: Should be 'line 3' is '$(cat Out1)'"
test "$(cat Out2)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
"#$T: Incorrect Out2: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out2)'"
#12
i; rm -f Out1 Out2 2>/dev/null || :
cat <<- 'EOF' |
for arg in 'line 1' 'line 2' 'line 3'
do
echo "$arg"
echo "$arg" >> Out1
done > Out2
EOF
atf_check -s exit:0 -o empty -e empty ${TEST_SH}
test "$(cat Out1)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
"#$T: Incorrect Out1: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out1)'"
test "$(cat Out2)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
"#$T: Incorrect Out2: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out2)'"
}
atf_test_case fd_redirections
fd_redirections_head()
{
atf_set "descr" "Tests redirections to/from specific descriptors"
}
fd_redirections_body()
{
atf_require_prog /bin/echo
cat <<- 'DONE' > helper.sh
f() {
/bin/echo nothing "$1" >& "$1"
}
for n
do
eval "f $n $n"'> file-$n'
done
DONE
cat <<- 'DONE' > reread.sh
f() {
(read -r var; echo "${var}") <&"$1"
}
for n
do
x=$( eval "f $n $n"'< file-$n' )
test "${x}" = "nothing $n" || echo "$n"
done
DONE
validate()
{
for n
do
test -e "file-$n" || atf_fail "file-$n not created"
C=$(cat file-"$n")
test "$C" = "nothing $n" ||
atf_fail "file-$n contains '$C' not 'nothing $n'"
done
}
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} helper.sh 1 2 3 4 5 6 7 8 9
validate 1 2 3 4 5 6 7 8 9
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} reread.sh 3 4 5 6 7 8 9
L=$(ulimit -n)
if [ "$L" -ge 30 ]
then
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} helper.sh 10 15 19 20 25 29
validate 10 15 19 20 25 29
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} reread.sh 10 15 19 20 25 29
fi
if [ "$L" -ge 100 ]
then
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} helper.sh 32 33 49 50 51 63 64 65 77 88 99
validate 32 33 49 50 51 63 64 65 77 88 99
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} reread.sh 32 33 49 50 51 63 64 65 77 88 99
fi
if [ "$L" -ge 500 ]
then
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} helper.sh 100 101 199 200 222 333 444 499
validate 100 101 199 200 222 333 444 499
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} reread.sh 100 101 199 200 222 333 444 499
fi
if [ "$L" -gt 1005 ]
then
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} helper.sh 1000 1001 1002 1003 1004 1005
validate 1000 1001 1002 1003 1004 1005
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} reread.sh 1000 1001 1002 1003 1004 1005
fi
}
atf_test_case local_redirections
local_redirections_head()
{
atf_set "descr" \
"Tests that exec can reassign file descriptors in the shell itself"
}
local_redirections_body()
{
cat <<- 'DONE' > helper.sh
for f
do
eval "exec $f"'> file-$f'
done
for f
do
printf '%s\n' "Hello $f" >&"$f"
done
for f
do
eval "exec $f"'>&-'
done
for f
do
eval "exec $f"'< file-$f'
done
for f
do
exec <& "$f"
read -r var || echo >&2 "No data in file-$f"
read -r x && echo >&2 "Too much data in file-${f}: $x"
test "${var}" = "Hello $f" ||
echo >&2 "file-$f contains '${var}' not 'Hello $f'"
done
DONE
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} helper.sh 3 4 5 6 7 8 9
L=$(ulimit -n)
if [ "$L" -ge 30 ]
then
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} helper.sh 10 11 13 15 16 19 20 28 29
fi
if [ "$L" -ge 100 ]
then
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} helper.sh 30 31 32 63 64 65 77 88 99
fi
if [ "$L" -ge 500 ]
then
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} helper.sh 100 101 111 199 200 201 222 333 499
fi
if [ "$L" -ge 1005 ]
then
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} helper.sh 1000 1001 1002 1003 1004 1005
fi
}
atf_test_case named_fd_redirections
named_fd_redirections_head()
{
atf_set "descr" "Tests redirections to /dev/stdout (etc)"
}
named_fd_redirections_body()
{
if test -c /dev/stdout
then
atf_check -s exit:0 -o inline:'OK\n' -e empty \
${TEST_SH} -c 'echo OK >/dev/stdout'
atf_check -s exit:0 -o inline:'OK\n' -e empty \
${TEST_SH} -c '/bin/echo OK >/dev/stdout'
fi
if test -c /dev/stdin
then
atf_require_prog cat
echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
${TEST_SH} -c 'read var </dev/stdin; echo $var'
echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
${TEST_SH} -c 'cat </dev/stdin'
fi
if test -c /dev/stderr
then
atf_check -s exit:0 -e inline:'OK\n' -o empty \
${TEST_SH} -c 'echo OK 2>/dev/stderr >&2'
atf_check -s exit:0 -e inline:'OK\n' -o empty \
${TEST_SH} -c '/bin/echo OK 2>/dev/stderr >&2'
fi
if test -c /dev/fd/8 && test -c /dev/fd/9
then
atf_check -s exit:0 -o inline:'EIGHT\n' -e empty \
${TEST_SH} -c 'printf "%s\n" EIGHT 8>&1 >/dev/fd/8 |
cat 9<&0 </dev/fd/9'
fi
return 0
}
atf_test_case redir_in_case
redir_in_case_head()
{
atf_set "descr" "Tests that sh(1) allows just redirections " \
"in case statements. (PR bin/48631)"
}
redir_in_case_body()
{
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -c 'case x in (whatever) >foo;; esac'
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -c 'case x in (whatever) >foo 2>&1;; esac'
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -c 'case x in (whatever) >foo 2>&1 </dev/null;; esac'
atf_check -s exit:0 -o empty -e empty \
${TEST_SH} -c 'case x in (whatever) >${somewhere};; esac'
}
atf_test_case incorrect_redirections
incorrect_redirections_head()
{
atf_set "descr" "Tests that sh(1) correctly ignores non-redirections"
}
incorrect_redirections_body() {
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'echo foo>'
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'read foo<'
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'echo foo<>'
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'echo x > '"$nl"
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'read x < '"$nl"
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'echo x <> '"$nl"
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'echo x >< anything'
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'echo x >>< anything'
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'echo x >|< anything'
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'echo x > ; read x < /dev/null || echo bad'
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
'read x < & echo y > /dev/null; wait && echo bad'
rm -f Output 2>/dev/null || :
atf_check -s exit:0 -e empty -o inline:'A Line > Output\n' \
${TEST_SH} -c 'echo A Line \> Output'
test -f Output && atf_file "File 'Output' appeared and should not have"
rm -f Output 2>/dev/null || :
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} -c 'echo A Line \>> Output'
test -f Output || atf_file "File 'Output' not created when it should"
test "$(cat Output)" = 'A Line >' || atf_fail \
"Output file contains '$(cat Output)' instead of '"'A Line >'\'
rm -f Output \> 2>/dev/null || :
atf_check -s exit:0 -e empty -o empty \
${TEST_SH} -c 'echo A Line >\> Output'
test -f Output && atf_file "File 'Output' appeared and should not have"
test -f '>' || atf_file "File '>' not created when it should"
test "$(cat '>')" = 'A Line Output' || atf_fail \
"Output file ('>') contains '$(cat '>')' instead of 'A Line Output'"
}
# Many more tests in t_here, so here we have just rudimentary checks
atf_test_case redir_here_doc
redir_here_doc_head()
{
atf_set "descr" "Tests that sh(1) correctly processes 'here' doc " \
"input redirections"
}
redir_here_doc_body()
{
# nb: the printf is not executed, it is data
cat <<- 'DONE' |
cat <<EOF
printf '%s\n' 'hello\n'
EOF
DONE
atf_check -s exit:0 -o match:printf -o match:'hello\\n' \
-e empty ${TEST_SH}
}
atf_test_case subshell_redirections
subshell_redirections_head()
{
atf_set "descr" "Tests redirection interactions between shell and " \
"its sub-shell(s)"
}
subshell_redirections_body()
{
atf_require_prog cat
LIM=$(ulimit -n)
cat <<- 'DONE' |
exec 6>output-file
( printf "hello\n" >&6 )
exec 8<output-file
( read hello <&8 ; test hello = "$hello" || echo >&2 Hello )
( printf "bye-bye\n" >&6 )
( exec 8<&- )
read bye <&8 || echo >&2 "Closed?"
echo Bye="$bye"
DONE
atf_check -s exit:0 -o match:Bye=bye-bye -e empty \
${TEST_SH}
cat <<- 'DONE' |
for arg in one-4 two-24 three-14
do
fd=${arg#*-}
file=${arg%-*}
eval "exec ${fd}>${file}"
done
for arg in one-5 two-7 three-19
do
fd=${arg#*-}
file=${arg%-*}
eval "exec ${fd}<${file}"
done
(
echo line-1 >&4
echo line-2 >&24
echo line-3 >&14
echo go
) | (
read go
read x <&5
read y <&7
read z <&19
printf "%s\n" "${x}" "${y}" "${z}"
)
DONE
atf_check -s exit:0 -o inline:'line-1\nline-2\nline-3\n' \
-e empty ${TEST_SH}
cat <<- 'DONE' |
for arg in one-4-5 two-6-7 three-8-9 four-11-10 five-3-12
do
ofd=${arg##*-}
file=${arg%-*}
ifd=${file#*-}
file=${file%-*}
eval "exec ${ofd}>${file}"
eval "exec ${ifd}<${file}"
done
( ( ( echo line-1 >& 13 ) 13>&12 ) 12>&5 ) >stdout 2>errout
( ( ( echo line-2 >& 4) 13>&12 ) 4>&7 ) >>stdout 2>>errout
( ( ( echo line-3 >& 6) 8>&1 6>&11 >&12) 11>&9 >&7 ) >>stdout
( ( ( cat <&13 >&12 ) 13<&8 12>&10 ) 10>&1 8<&6 ) 6<&4
( ( ( cat <&4 ) <&4 6<&8 8<&11 )
<&4 4<&6 6<&8 8<&11 ) <&4 4<&6 6<&8 8<&11 11<&3
( ( ( cat <&7 >&1 ) 7<&6 >&10 ) 10>&2 6<&8 ) 2>&1
DONE
atf_check -s exit:0 -o inline:'line-1\nline-2\nline-3\n' \
-e empty ${TEST_SH}
}
atf_test_case ulimit_redirection_interaction
ulimit_redirection_interaction_head()
{
atf_set "descr" "Tests interactions between redirect and ulimit -n "
}
ulimit_redirection_interaction_body()
{
atf_require_prog ls
cat <<- 'DONE' > helper.sh
oLIM=$(ulimit -n)
HRD=$(ulimit -H -n)
test "${oLIM}" -lt "${HRD}" && ulimit -n "${HRD}"
LIM=$(ulimit -n)
FDs=
LFD=-1
while [ ${LIM} -gt 16 ]
do
FD=$(( ${LIM} - 1 ))
if [ "${FD}" -eq "${LFD}" ]; then
echo >&2 "Infinite loop... (busted $(( )) ??)"
exit 1
fi
LFD="${FD}"
eval "exec ${FD}"'> /dev/null'
FDs="${FD}${FDs:+ }${FDs}"
(
FD=$(( ${LIM} + 1 ))
eval "exec ${FD}"'> /dev/null'
echo "Reached unreachable command"
) 2>/dev/null && echo >&2 "Opened beyond limit!"
(eval 'ls 2>&1 3>&1 4>&1 5>&1 '"${FD}"'>&1') >&"${FD}"
LIM=$(( ${LIM} / 2 ))
ulimit -S -n "${LIM}"
done
# Even though ulimit has been reduced, open fds should work
for FD in ${FDs}
do
echo ${FD} in ${FDs} >&"${FD}" || exit 1
done
ulimit -S -n "${oLIM}"
# maybe more later...
DONE
atf_check -s exit:0 -o empty -e empty ${TEST_SH} helper.sh
}
atf_test_case validate_fn_redirects
validate_fn_redirects_head()
{
# These test cases inspired by PR bin/48875 and the sh
# changes that were required to fix it.
atf_set "descr" "Tests various redirections applied to functions " \
"See PR bin/48875"
}
validate_fn_redirects_body()
{
cat <<- 'DONE' > f-def
f() {
printf '%s\n' In-Func
}
DONE
atf_check -s exit:0 -o inline:'In-Func\nsuccess1\n' -e empty \
${TEST_SH} -c ". ./f-def; f ; printf '%s\n' success1"
atf_check -s exit:0 -o inline:'success2\n' -e empty \
${TEST_SH} -c ". ./f-def; f >/dev/null; printf '%s\n' success2"
atf_check -s exit:0 -o inline:'success3\n' -e empty \
${TEST_SH} -c ". ./f-def; f >&- ; printf '%s\n' success3"
atf_check -s exit:0 -o inline:'In-Func\nsuccess4\n' -e empty \
${TEST_SH} -c ". ./f-def; f & wait; printf '%s\n' success4"
atf_check -s exit:0 -o inline:'success5\n' -e empty \
${TEST_SH} -c ". ./f-def; f >&- & wait; printf '%s\n' success5"
atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess6\n' -e empty \
${TEST_SH} -c ". ./f-def; f;f; printf '%s\n' success6"
atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess7\n' -e empty \
${TEST_SH} -c ". ./f-def; { f;f;}; printf '%s\n' success7"
atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess8\n' -e empty \
${TEST_SH} -c ". ./f-def; { f;f;}& wait; printf '%s\n' success8"
atf_check -s exit:0 -o inline:'In-Func\nsuccess9\n' -e empty \
${TEST_SH} -c \
". ./f-def; { f>/dev/null;f;}& wait; printf '%s\n' success9"
atf_check -s exit:0 -o inline:'In-Func\nsuccess10\n' -e empty \
${TEST_SH} -c \
". ./f-def; { f;f>/dev/null;}& wait; printf '%s\n' success10"
# This one tests the issue etcupdate had with the original 48875 fix
atf_check -s exit:0 -o inline:'Func a\nFunc b\nFunc c\n' -e empty \
${TEST_SH} -c '
f() {
echo Func "$1"
}
exec 3<&0 4>&1
( echo x-a; echo y-b; echo z-c ) |
while read A
do
B=${A#?-}
f "$B" <&3 >&4
done >&2'
# And this tests a similar condition with that same fix
cat <<- 'DONE' >Script
f() {
printf '%s' " hello $1"
}
exec 3>&1
echo $( for i in a b c
do printf '%s' @$i; f $i >&3; done >foo
)
printf '%s\n' foo=$(cat foo)
DONE
atf_check -s exit:0 -e empty \
-o inline:' hello a hello b hello c\nfoo=@a@b@c\n' \
${TEST_SH} Script
# Tests with sh reading stdin, which is not quite the same internal
# mechanism.
echo ". ./f-def || echo >&2 FAIL
f
printf '%s\n' stdin1
"| atf_check -s exit:0 -o inline:'In-Func\nstdin1\n' -e empty ${TEST_SH}
echo '
. ./f-def || echo >&2 FAIL
f >&-
printf "%s\n" stdin2
' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH}
cat <<- 'DONE' > fgh.def
f() {
echo -n f >&3
sleep 4
echo -n F >&3
}
g() {
echo -n g >&3
sleep 2
echo -n G >&3
}
h() {
echo -n h >&3
}
DONE
atf_check -s exit:0 -o inline:'fFgGh' -e empty \
${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
exec 3>&1
f; g; h'
atf_check -s exit:0 -o inline:'fghGF' -e empty \
${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
exec 3>&1
f & sleep 1; g & sleep 1; h; wait'
atf_check -s exit:0 -o inline:'fFgGhX Y\n' -e empty \
${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
exec 3>&1
echo X $( f ; g ; h ) Y'
# This one is the real test for PR bin/48875. If the
# cmdsub does not complete before f g (and h) exit,
# then the 'F' & 'G' will precede 'X Y' in the output.
# If the cmdsub finishes while f & g are still running,
# then the X Y will appear before the F and G.
# The trailing "sleep 3" is just so we catch all the
# output (otherwise atf_check will be finished while
# f & g are still sleeping).
atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty \
${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
exec 3>&1
echo X $( f >&- & sleep 1; g >&- & sleep 1 ; h ) Y
sleep 3
exec 4>&1 || echo FD_FAIL
'
# Do the test again to verify it also all works reading stdin
# (which is a slightly different path through the shell)
echo '
. ./fgh.def || echo >&2 FAIL
exec 3>&1
echo X $( f >&- & sleep 1; g >&- & sleep 1 ; h ) Y
sleep 3
exec 4>&1 || echo FD_FAIL
' | atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty ${TEST_SH}
}
atf_init_test_cases() {
atf_add_test_case basic_test_method_test
atf_add_test_case do_input_redirections
atf_add_test_case do_output_redirections
atf_add_test_case fd_redirections
atf_add_test_case local_redirections
atf_add_test_case incorrect_redirections
atf_add_test_case named_fd_redirections
atf_add_test_case redir_here_doc
atf_add_test_case redir_in_case
atf_add_test_case subshell_redirections
atf_add_test_case ulimit_redirection_interaction
atf_add_test_case validate_fn_redirects
}

View file

@ -0,0 +1,178 @@
# $NetBSD: t_redircloexec.sh,v 1.3 2016/05/15 15:44:43 kre Exp $
#
# Copyright (c) 2016 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas.
#
# 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 "sh" to test
: ${TEST_SH:="/bin/sh"}
mkhelper() {
name=$1
fd=$2
shift 2
echo "$@" > ./"${name}1"
echo "echo ${name}2" ">&${fd}" > ./"${name}2"
}
runhelper() {
${TEST_SH} "./${1}1"
}
cleanhelper() {
# not really needed, atf cleans up...
rm -f ./"${1}1" ./"${1}2" out
}
atf_test_case exec_redir_closed
exec_redir_closed_head() {
atf_set "descr" "Tests that redirections created by exec are closed on exec"
}
exec_redir_closed_body() {
mkhelper exec 6 \
"exec 6> out; echo exec1 >&6; ${TEST_SH} exec2; exec 6>&-"
atf_check -s exit:0 -o empty -e not-empty ${TEST_SH} ./exec1
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -e ./exec1
mkhelper exec 9 \
"exec 9> out; echo exec1 >&9; ${TEST_SH} exec2"
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} ./exec1
mkhelper exec 8 \
"exec 8> out; printf OK; echo exec1 >&8;" \
"printf OK; ${TEST_SH} exec2; printf ERR"
atf_check -s not-exit:0 -o match:OKOK -o not-match:ERR -e not-empty \
${TEST_SH} -e ./exec1
mkhelper exec 7 \
"exec 7> out; printf OK; echo exec1 >&7;" \
"printf OK; ${TEST_SH} exec2 || printf ERR"
atf_check -s exit:0 -o match:OKOKERR -e not-empty \
${TEST_SH} ./exec1
cleanhelper exec
}
atf_test_case exec_redir_open
exec_redir_open_head() {
atf_set "descr" "Tests that redirections created by exec can remain open"
}
exec_redir_open_body() {
mkhelper exec 6 \
"exec 6> out 6>&6; echo exec1 >&6; ${TEST_SH} exec2; exec 6>&-"
atf_check -s exit:0 -o empty -e empty ${TEST_SH} ./exec1
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -e ./exec1
mkhelper exec 9 \
"exec 9> out ; echo exec1 >&9; ${TEST_SH} exec2 9>&9"
atf_check -s exit:0 -o empty -e empty ${TEST_SH} ./exec1
mkhelper exec 8 \
"exec 8> out; printf OK; exec 8>&8; echo exec1 >&8;" \
"printf OK; ${TEST_SH} exec2; printf OK"
atf_check -s exit:0 -o match:OKOKOK -e empty \
${TEST_SH} -e ./exec1
mkhelper exec 7 \
"exec 7> out; printf OK; echo exec1 >&7;" \
"printf OK; ${TEST_SH} 7>&7 exec2; printf OK"
atf_check -s exit:0 -o match:OKOKOK -e empty \
${TEST_SH} -e ./exec1
cleanhelper exec
}
atf_test_case loop_redir_open
loop_redir_open_head() {
atf_set "descr" "Tests that redirections in loops don't close on exec"
}
loop_redir_open_body() {
mkhelper for 3 "for x in x; do ${TEST_SH} ./for2; done 3>out"
atf_check -s exit:0 \
-o empty \
-e empty \
${TEST_SH} ./for1
cleanhelper for
}
atf_test_case compound_redir_open
compound_redir_open_head() {
atf_set "descr" "Tests that redirections in compound statements don't close on exec"
}
compound_redir_open_body() {
mkhelper comp 3 "{ ${TEST_SH} ./comp2; } 3>out"
atf_check -s exit:0 \
-o empty \
-e empty \
${TEST_SH} ./comp1
cleanhelper comp
}
atf_test_case simple_redir_open
simple_redir_open_head() {
atf_set "descr" "Tests that redirections in simple commands don't close on exec"
}
simple_redir_open_body() {
mkhelper simp 4 "${TEST_SH} ./simp2 4>out"
atf_check -s exit:0 \
-o empty \
-e empty \
${TEST_SH} ./simp1
cleanhelper simp
}
atf_test_case subshell_redir_open
subshell_redir_open_head() {
atf_set "descr" "Tests that redirections on subshells don't close on exec"
}
subshell_redir_open_body() {
mkhelper comp 5 "( ${TEST_SH} ./comp2; ${TEST_SH} ./comp2 ) 5>out"
atf_check -s exit:0 \
-o empty \
-e empty \
${TEST_SH} ./comp1
cleanhelper comp
}
atf_init_test_cases() {
atf_add_test_case exec_redir_closed
atf_add_test_case exec_redir_open
atf_add_test_case loop_redir_open
atf_add_test_case compound_redir_open
atf_add_test_case simple_redir_open
atf_add_test_case subshell_redir_open
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_set_e.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
# $NetBSD: t_set_e.sh,v 1.4 2016/03/31 16:22:27 christos Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
@ -30,7 +30,7 @@
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
# the implementation of "sh" to test
: ${TEST_SH:="sh"}
: ${TEST_SH:="/bin/sh"}
failwith()
{
@ -63,7 +63,7 @@ dcheck()
# is thus important to test. (PR bin/29861)
echeck()
{
check1 'eval '"'($1)'" "$2" "eval '($1)'"
check1 'eval '"'( $1 )'" "$2" "eval '($1)'"
}
atf_test_case all
@ -81,8 +81,8 @@ all_body() {
# 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'
dcheck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
echeck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
# these cases should be equivalent to the preceding.
dcheck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
@ -205,6 +205,9 @@ all_body() {
# According to dsl@ in PR bin/32282, () is not defined as a
# subshell, only as a grouping operator [and a scope, I guess]
# (This is incorrect. () is definitely a sub-shell)
# 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
@ -215,8 +218,10 @@ all_body() {
#
# XXX: the second set has been disabled in the name of making
# all tests "pass".
#
# As they should be, they are utter nonsense.
# 1. error if the whole shell exits (current behavior)
# 1. error if the whole shell exits (current correct 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)
@ -232,29 +237,32 @@ all_body() {
# backquote expansion (PR bin/17514)
# correct
# (in-)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
# Not-wrong current behavior
# the exit status of ommand substitution is ignored in most cases
# None of these should be causing the shell to exit.
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'
# This is testing one case (the case?) where the exit status is used
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
# correct (really just commented out incorrect nonsense)
#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
# not-wrong current behavior (as above)
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'
@ -267,11 +275,19 @@ all_body() {
# shift (PR bin/37493)
# correct
# Actually, both ways are correct, both are permitted
#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'
# (not-) wrong current behavior
#dcheck '(set -e; shift || true; echo OK); echo OK' 'OK'
#echeck '(set -e; shift || true; echo OK); echo OK' 'OK'
# what is wrong is this test assuming one behaviour or the other
# (and incidentally this has nothing whatever to do with "-e",
# the test should really be moved elsewhere...)
# But for now, leave it here, and correct it:
dcheck '(set -e; shift && echo OK); echo OK' 'OK'
echeck '(set -e; shift && echo OK); echo OK' 'OK'
# Done.

View file

@ -0,0 +1,181 @@
# $NetBSD: t_shift.sh,v 1.2 2016/05/17 09:05:14 kre Exp $
#
# Copyright (c) 2016 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 "sh" to test
: ${TEST_SH:="/bin/sh"}
atf_test_case basic_shift_test
basic_shift_test_head() {
atf_set "descr" "Test correct operation of valid shifts"
}
basic_shift_test_body() {
for a in \
"one-arg::0:one-arg" \
"one-arg:1:0:one-arg" \
"one-arg:0:1 one-arg" \
"a b c::2 b c:a" \
"a b c:1:2 b c:a" \
"a b c:2:1 c:a:b" \
"a b c:3:0:a:b:c" \
"a b c:0:3 a b c" \
"a b c d e f g h i j k l m n o p:1:15 b c d e f g h i j k l m n o p"\
"a b c d e f g h i j k l m n o p:9:7 j k l m n o p:a:b:c:g:h:i" \
"a b c d e f g h i j k l m n o p:13:3 n o p:a:b:c:d:k:l:m" \
"a b c d e f g h i j k l m n o p:16:0:a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p"
do
oIFS="${IFS}"
IFS=:; set -- $a
IFS="${oIFS}"
init="$1"; n="$2"; res="$3"; shift 3
not=
for b
do
not="${not} -o not-match:$b"
done
atf_check -s exit:0 -o "match:${res}" ${not} -e empty \
${TEST_SH} -c "set -- ${init}; shift $n;"' echo "$# $*"'
done
atf_check -s exit:0 -o match:complete -o not-match:ERR -e empty \
${TEST_SH} -c \
'set -- a b c d e;while [ $# -gt 0 ];do shift||echo ERR;done;echo complete'
}
atf_test_case excessive_shift
excessive_shift_head() {
atf_set "descr" "Test acceptable operation of shift too many"
}
# In:
#
# http://pubs.opengroup.org/onlinepubs/9699919799
# /utilities/V3_chap02.html#tag_18_26_01
#
# (that URL should be one line, with the /util... immediately after ...9799)
#
# POSIX says of shift (in the "EXIT STATUS" paragraph):
#
# If the n operand is invalid or is greater than "$#", this may be considered
# a syntax error and a non-interactive shell may exit; if the shell does not
# exit in this case, a non-zero exit status shall be returned.
# Otherwise, zero shall be returned.
#
# NetBSD's sh treats it as an error and exits (if non-interactive, as here),
# other shells do not.
#
# Either behaviour is acceptable - so the test allows for both
# (and checks that if the shell does not exit, "shift" returns status != 0)
excessive_shift_body() {
for a in \
"one-arg:2" \
"one-arg:4" \
"one-arg:13" \
"one two:3" \
"one two:7" \
"one two three four five:6" \
"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:16" \
"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:17" \
"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:30" \
"I II III IV V VI VII VIII IX X XI XII XIII XIV XV:9999"
do
oIFS="${IFS}"
IFS=:; set -- $a
IFS="${oIFS}"
atf_check -s not-exit:0 -o match:OK -o not-match:ERR \
-e ignore ${TEST_SH} -c \
"set -- $1 ;"'echo OK:$#-'"$2;shift $2 && echo ERR"
done
}
atf_test_case function_shift
function_shift_head() {
atf_set "descr" "Test that shift in a function does not affect outside"
}
function_shift_body() {
: # later...
}
atf_test_case non_numeric_shift
non_numeric_shift_head() {
atf_set "descr" "Test that non-numeric args to shift are detected"
}
# from the DESCRIPTION section at the URL mentioned with the excessive_shift
# test:
#
# The value n shall be an unsigned decimal integer ...
#
# That is not hex (octal will be treated as if it were decimal, a leading 0
# will simply be ignored - we test for this by giving an "octal" value that
# would be OK if parsed as octal, but not if parsed (correctly) as decimal)
#
# Obviously total trash like roman numerals or alphabetic strings are out.
#
# Also no signed values (no + or -) and not a string that looks kind of like
# a number, but only if you're generous
#
# But as the EXIT STATUS section quoted above says, with an invalid 'n'
# the shell has the option of exiting, or returning status != 0, so
# again this test allows both.
non_numeric_shift_body() {
# there are 9 args set, 010 is 8 if parsed octal, 10 decimal
for a in a I 0x12 010 5V -1 ' ' '' +1 ' 1'
do
atf_check -s not-exit:0 -o empty -e ignore ${TEST_SH} -c \
"set -- a b c d e f g h i; shift '$a' && echo ERROR"
done
}
atf_test_case too_many_args
too_many_args_head() {
# See PR bin/50896
atf_set "descr" "Test that sh detects invalid extraneous args to shift"
}
# This is a syntax error, a non-interactive shell (us) must exit $? != 0
too_many_args_body() {
# This tests the bug in PR bin/50896 is fixed
for a in "1 1" "1 0" "1 2 3" "1 foo" "1 --" "-- 1"
do
atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
" set -- a b c d; shift ${a} ; echo FAILED "
done
}
atf_init_test_cases() {
atf_add_test_case basic_shift_test
atf_add_test_case excessive_shift
atf_add_test_case function_shift
atf_add_test_case non_numeric_shift
atf_add_test_case too_many_args
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_ulimit.sh,v 1.1 2012/06/11 18:32:59 njoly Exp $
# $NetBSD: t_ulimit.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
#
# Copyright (c) 2012 The NetBSD Foundation, Inc.
# All rights reserved.
@ -24,6 +24,8 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
# ulimit builtin test.
@ -31,13 +33,22 @@ atf_test_case limits
limits_head() {
atf_set "descr" "Checks for limits flags"
}
get_ulimits() {
local limits=$(${TEST_SH} -c 'ulimit -a' |
sed -e 's/.*\(-[A-Za-z0-9]\)[^A-Za-z0-9].*/\1/' | sort -u)
if [ -z "$limits" ]; then
# grr ksh
limits="-a -b -c -d -f -l -m -n -p -r -s -t -v"
fi
echo "$limits"
}
limits_body() {
atf_check -s eq:0 -o ignore -e empty \
/bin/sh -c "ulimit -a"
for l in $(ulimit -a | sed 's,^.*(,,;s, .*$,,');
atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit -a"
for l in $(get_ulimits)
do
atf_check -s eq:0 -o ignore -e empty \
/bin/sh -c "ulimit $l"
atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit $l"
done
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_varquote.sh,v 1.2 2012/03/25 18:50:19 christos Exp $
# $NetBSD: t_varquote.sh,v 1.5 2016/03/27 14:50:01 christos Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
@ -24,6 +24,8 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
# Variable quoting test.
@ -39,30 +41,70 @@ 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"
cat <<-'EOF' > script.sh
T=0
check() {
T=$((${T} + 1))
foo=${a:-"'{}'"}
check "$foo" "'{}'"
if [ "$1" != "$2" ]
then
printf '%s\n' "T${T}: expected [$2], found [$1]"
exit 1
fi
}
foo=${a:-${b:-"'{}'"}}
check "$foo" "'{}'"
#1
foo='${a:-foo}'
check "$foo" '${a:-foo}'
#2
foo="${a:-foo}"
check "$foo" "foo"
#3
foo=${a:-"'{}'"}
check "$foo" "'{}'"
#4
foo=${a:-${b:-"'{}'"}}
check "$foo" "'{}'"
#5
# ${ } The ' are inside ".." so are literal (not quotes).
foo="${a-'}'}"
check "$foo" "''}"
#6
# The rules for quoting in ${var-word} expressions are somewhat
# weird, in the following there is not one quoted string being
# assigned to foo (with internally quoted sub-strings), rather
# it is a mixed quoted/unquoted string, with parts that are
# quoted, separated by 2 unquoted sections...
# qqqqqqqqqq uuuuuuuuuu qq uuuu qqqq
foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
# " z*"
# ${a:- }
# ${b:- }
# " y*"
# ${c:- }
# ${d:- }
# "x*"
check "$foo" "x}y}z}"
#7
# And believe it or not, this is the one that gives
# most problems, with 3 different observed outputs...
# qqqqq qq q is one interpretation
# qqqqq QQQQ q is another (most common)
# (the third is syntax error...)
foo="${a:-"'{}'"}"
check "$foo" "'{}'"
foo="${a:-"'{}'"}"
check "$foo" "'{}'"
EOF
foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
# " z*"
# ${a:- }
# ${b:- }
# " y*"
# ${c:- }
# ${d:- }
# "x*"
check "$foo" "x}y}z}"
OUT=$( ${TEST_SH} script.sh 2>&1 )
if [ $? -ne 0 ]
then
atf_fail "${OUT}"
elif [ -n "${OUT}" ]
then
atf_fail "script.sh unexpectedly said: ${OUT}"
fi
}
atf_test_case nested_quotes_multiword
@ -72,10 +114,21 @@ nested_quotes_multiword_head() {
}
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"'
${TEST_SH} -c 'echo "${foo:="first-word"} second-word"'
}
atf_test_case default_assignment_with_arith
default_assignment_with_arith_head() {
atf_set "descr" "Tests default variable assignment with arithmetic" \
"string works (PR bin/50827)"
}
default_assignment_with_arith_body() {
atf_check -s eq:0 -o empty -e empty ${TEST_SH} -c ': "${x=$((1))}"'
atf_check -s eq:0 -o match:1 -e empty ${TEST_SH} -c 'echo "${x=$((1))}"'
}
atf_init_test_cases() {
atf_add_test_case all
atf_add_test_case nested_quotes_multiword
atf_add_test_case default_assignment_with_arith
}

View file

@ -0,0 +1,251 @@
# $NetBSD: t_varval.sh,v 1.1 2016/03/16 15:49:19 christos Exp $
#
# Copyright (c) 2016 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 "sh" to test
: ${TEST_SH:="/bin/sh"}
# Test all kinds of weird values in various ways to use shell $... expansions
oneline()
{
q="'"
test $# -eq 4 && q=""
v=$( printf '\\%3.3o' $(( $2 & 0xFF )) )
printf "%s" "$1"
if [ $2 != 39 ]; then
printf "%sprefix${v}suffix%s" "$q" "$q"
elif [ $# -ne 4 ]; then
printf %s prefix\"\'\"suffix
else
printf %s prefix\'suffix
fi
printf "%s\n" "$3"
}
mkdata() {
quote= pfx=
while [ $# -gt 0 ]
do
case "$1" in
--) shift; break;;
-q) quote=no; shift; continue;;
esac
pfx="${pfx}${pfx:+ }${1}"
shift
done
sfx=
while [ $# -gt 0 ]
do
sfx="${sfx}${sfx:+ }${1}"
shift
done
i=1 # '\0' is not expected to work, anywhere...
while [ $i -lt 256 ]
do
oneline "${pfx}" "$i" "${sfx}" $quote
i=$(( $i + 1 ))
done
}
atf_test_case aaa
aaa_head() {
atf_set "descr" "Check that this test has a hope of working. " \
"Just give up on these tests if the aaa test fails".
}
aaa_body() {
oneline "echo " 9 '' |
atf_check -s exit:0 -o inline:'prefix\tsuffix\n' -e empty \
${TEST_SH}
oneline "VAR=" 65 '; echo "${#VAR}:${VAR}"' |
atf_check -s exit:0 -o inline:'13:prefixAsuffix\n' -e empty \
${TEST_SH}
oneline "VAR=" 1 '; echo "${#VAR}:${VAR}"' |
atf_check -s exit:0 -o inline:'13:prefixsuffix\n' -e empty \
${TEST_SH}
oneline "VAR=" 10 '; echo "${#VAR}:${VAR}"' |
atf_check -s exit:0 -o inline:'13:prefix\nsuffix\n' -e empty \
${TEST_SH}
rm -f prefix* 2>/dev/null || :
oneline "echo hello >" 45 "" |
atf_check -s exit:0 -o empty -e empty ${TEST_SH}
test -f "prefix-suffix" ||
atf_fail "failed to create prefix-suffix (45)"
test -s "prefix-suffix" ||
atf_fail "no data in prefix-suffix (45)"
test "$(cat prefix-suffix)" = "hello" ||
atf_fail "incorrect data in prefix-suffix (45)"
return 0
}
atf_test_case assignment
assignment_head() {
atf_set "descr" "Check that all chars can be assigned to vars"
}
assignment_body() {
atf_require_prog grep
atf_require_prog rm
rm -f results || :
mkdata "VAR=" -- '; echo ${#VAR}' |
atf_check -s exit:0 -o save:results -e empty ${TEST_SH}
test -z $( grep -v "^13$" results ) ||
atf_fail "Incorrect lengths: $(grep -nv '^13$' results)"
return 0
}
atf_test_case cmdline
cmdline_head() {
atf_set "descr" "Check vars containing all chars can be used"
}
cmdline_body() {
atf_require_prog rm
atf_require_prog wc
rm -f results || :
mkdata "VAR=" -- '; echo "${VAR}"' |
atf_check -s exit:0 -o save:results -e empty ${TEST_SH}
# 256 because one output line contains a \n ...
test $( wc -l < results ) -eq 256 ||
atf_fail "incorrect line count in results"
test $(wc -c < results) -eq $(( 255 * 14 )) ||
atf_fail "incorrect character count in results"
return 0
}
atf_test_case redirect
redirect_head() {
atf_set "descr" "Check vars containing all chars can be used"
}
redirect_body() {
atf_require_prog ls
atf_require_prog wc
atf_require_prog rm
atf_require_prog mkdir
atf_require_prog rmdir
nl='
'
rm -f prefix* suffix || :
mkdir prefix # one of the files will be prefix/suffix
mkdata "VAR=" -- '; echo "${VAR}" > "${VAR}"' |
atf_check -s exit:0 -o empty -e empty ${TEST_SH}
test -f "prefix/suffix" ||
atf_fail "Failed to create file in subdirectory"
test $( wc -l < "prefix/suffix" ) -eq 1 ||
atf_fail "Not exactly one line in prefix/suffix file"
atf_check -s exit:0 -o empty -e empty rm "prefix/suffix"
atf_check -s exit:0 -o empty -e empty rmdir "prefix"
test -f "prefix${nl}suffix" ||
atf_fail "Failed to create file with newline in its name"
test $( wc -l < "prefix${nl}suffix" ) -eq 2 ||
atf_fail "NewLine file did not contain embedded newline"
atf_check -s exit:0 -o empty -e empty rm "prefix${nl}suffix"
# Now there should be 253 files left...
test $( ls | wc -l ) -eq 253 ||
atf_fail \
"Did not create all expected files: wanted: 253, found ($( ls | wc -l ))"
# and each of them should have a name that is 13 chars long (+ \n)
test $( ls | wc -c ) -eq $(( 253 * 14 )) ||
atf_fail "File names do not appear to be as expected"
return 0
}
atf_test_case read
read_head() {
atf_set "descr" "Check vars containing all chars can be used"
}
read_body() {
atf_require_prog ls
atf_require_prog wc
atf_require_prog rm
atf_require_prog mkdir
atf_require_prog rmdir
nl='
'
rm -f prefix* suffix || :
mkdir prefix # one of the files will be prefix/suffix
mkdata -q |
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '
while read -r VAR
do
# skip the mess made by embedded newline
case "${VAR}" in
(prefix | suffix) continue;;
esac
echo "${VAR}" > "${VAR}"
done'
test -f "prefix/suffix" ||
atf_fail "Failed to create file in subdirectory"
test $( wc -l < "prefix/suffix" ) -eq 1 ||
atf_fail "Not exactly one line in prefix/suffix file"
atf_check -s exit:0 -o empty -e empty rm "prefix/suffix"
atf_check -s exit:0 -o empty -e empty rmdir "prefix"
# Now there should be 253 files left...
test $( ls | wc -l ) -eq 253 ||
atf_fail \
"Did not create all expected files: wanted: 253, found ($( ls | wc -l ))"
# and each of them should have a name that is 13 chars long (+ \n)
test $( ls | wc -c ) -eq $(( 253 * 14 )) ||
atf_fail "File names do not appear to be as expected"
return 0
}
atf_init_test_cases() {
atf_add_test_case aaa
atf_add_test_case assignment
atf_add_test_case cmdline
atf_add_test_case redirect
atf_add_test_case read
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_wait.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
# $NetBSD: t_wait.sh,v 1.8 2016/03/31 16:22:54 christos Exp $
#
# Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@ -24,36 +24,172 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}
atf_test_case basic_wait
basic_wait_head() {
atf_set "descr" "Tests simple uses of wait"
}
basic_wait_body() {
atf_require_prog sleep
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
'(echo nothing >/dev/null) & wait'
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
'(exit 3) & wait $!; S=$?; test $S -eq 3 || {
echo "status: $S"; exit 1; }'
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
'sleep 3 & sleep 2 & sleep 1 & wait'
atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
'sleep 3 & (exit 2) & sleep 1 & wait'
}
atf_test_case individual
individual_head() {
atf_set "descr" "Tests that waiting for individual jobs works"
atf_set "descr" "Tests that waiting for individual processes 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 &
atf_require_prog sleep
wait %1
if [ \$? -ne 0 ]; then
echo "Waiting of first job failed"
cat >individualhelper.sh <<\EOF
sleep 3 & P1=$!
sleep 1 & P2=$!
wait ${P1}
S=$?
if [ $S -ne 0 ]; then
echo "Waiting for first process failed: $S"
exit 1
fi
wait %2
if [ \$? -ne 0 ]; then
echo "Waiting of second job failed"
wait ${P2}
S=$?
if [ $? -ne 0 ]; then
echo "Waiting for second process failed"
exit 1
fi
exit 0
EOF
output=$(/bin/sh helper.sh)
output=$(${TEST_SH} individualhelper.sh 2>&1)
[ $? -eq 0 ] || atf_fail "${output}"
}
atf_init_test_cases() {
atf_add_test_case individual
atf_test_case jobs
jobs_head() {
atf_set "descr" "Tests that waiting for individual jobs works"
}
jobs_body() {
# atf-sh confuses wait for some reason; work it around by creating
# a helper script that executes /bin/sh directly.
if ! ${TEST_SH} -c 'sleep 1 & wait %1' 2>/dev/null
then
atf_skip "No job control support in this shell"
fi
cat >individualhelper.sh <<\EOF
sleep 3 &
sleep 1 &
wait %1
if [ $? -ne 0 ]; then
echo "Waiting for first job failed"
exit 1
fi
wait %2
if [ $? -ne 0 ]; then
echo "Waiting for second job failed"
exit 1
fi
exit 0
EOF
output=$(${TEST_SH} individualhelper.sh 2>&1)
[ $? -eq 0 ] || atf_fail "${output}"
cat >individualhelper.sh <<\EOF
{ sleep 3; exit 3; } &
{ sleep 1; exit 7; } &
wait %1
S=$?
if [ $S -ne 3 ]; then
echo "Waiting for first job failed - status: $S != 3 (expected)"
exit 1
fi
wait %2
S=$?
if [ $S -ne 7 ]; then
echo "Waiting for second job failed - status: $S != 7 (expected)"
exit 1
fi
exit 0
EOF
output=$(${TEST_SH} individualhelper.sh 2>&1)
[ $? -eq 0 ] || atf_fail "${output}"
}
atf_test_case kill
kill_head() {
atf_set "descr" "Tests that killing the shell while in wait calls trap"
}
kill_body() {
atf_require_prog sleep
atf_require_prog kill
s=killhelper.sh
z=killhelper.$$
pid=
# waiting for a specific process that is not a child
# should return exit status of 127 according to the spec
# This test is here before the next, to avoid that one
# entering an infinite loop should the shell have a bug here.
atf_check -s exit:127 -o empty -e ignore ${TEST_SH} -c 'wait 1'
cat > "${s}" <<'EOF'
trap "echo SIGHUP" 1
(sleep 5; exit 3) &
sl=$!
wait
S=$?
echo $S
LS=9999
while [ $S -ne 0 ] && [ $S != 127 ]; do
wait $sl; S=$?; echo $S
test $S = $LS && { echo "wait repeats..."; exit 2; }
LS=$S
done
EOF
${TEST_SH} $s > $z &
pid=$!
sleep 1
kill -HUP "${pid}"
wait
output="$(cat $z | tr '\n' ' ')"
if [ "$output" != "SIGHUP 129 3 127 " ]; then
atf_fail "${output} != 'SIGHUP 129 3 127 '"
fi
}
atf_init_test_cases() {
atf_add_test_case basic_wait
atf_add_test_case individual
atf_add_test_case jobs
atf_add_test_case kill
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_opencrypto.sh,v 1.4 2014/01/18 15:15:16 pgoyette Exp $
# $NetBSD: t_opencrypto.sh,v 1.6 2015/12/26 07:10:03 pgoyette Exp $
#
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
@ -80,7 +80,11 @@ arc4_body() {
}
arc4_cleanup() {
common_cleanup
# No cleanup required since test is skipped. Trying to run rump.halt
# at this point fails, causing the ATF environment to erroneously
# report a failed test!
#
# common_cleanup
}
atf_test_case camellia cleanup
@ -98,7 +102,7 @@ camellia_cleanup() {
atf_test_case cbcdes cleanup
cbcdes_head() {
common_head "Test ARC4 crypto"
common_head "Test DES_CBC crypto"
}
cbcdes_body() {

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* $NetBSD: h_dm.c,v 1.1 2010/10/06 11:24:55 haad Exp $ */
/* $NetBSD: h_dm.c,v 1.2 2016/01/23 21:18:27 christos Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@ -83,6 +83,7 @@ dm_test_versions(void) {
dict_out = prop_dictionary_internalize(prefp.pref_plist);
xml = prop_dictionary_externalize(dict_out);
__USE(xml);
rump_sys_close(fd);
@ -122,6 +123,7 @@ dm_test_targets(void) {
dict_out = prop_dictionary_internalize(prefp.pref_plist);
xml = prop_dictionary_externalize(dict_out);
__USE(xml);
rump_sys_close(fd);

View file

@ -0,0 +1,84 @@
# $NetBSD: t_fss.sh,v 1.2 2016/07/29 20:27:37 pgoyette Exp $
#
# Copyright (c) 2006, 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.
#
#
# Verify basic operation of fss(4) file system snapshot device
#
orig_data="Original data"
repl_data="Replacement data"
atf_test_case basic cleanup
basic_body() {
# create of mount-points for the file system and snapshot
mkdir ./m1
mkdir ./m2
# create a small 4MB file, treat it as a disk, init a file-system on it,
# and mount it
dd if=/dev/zero of=./image bs=32k count=64
vndconfig -c vnd0 ./image
newfs /dev/vnd0a
mount /dev/vnd0a ./m1
echo "${orig_data}" > ./m1/text
# configure and mount a snapshot of the file system
fssconfig -c fss0 ./m1 ./backup
mount -o rdonly /dev/fss0 ./m2
# Modify the data on the underlying file system
echo "${repl_data}" > ./m1/text || abort
# Verify that original data is still visible in the snapshot
read test_data < ./m2/text
atf_check_equal "${orig_data}" "${test_data}"
# Unmount our temporary stuff
umount /dev/fss0 || true
fssconfig -u fss0 || true
umount /dev/vnd0a || true
vndconfig -u vnd0 || true
}
basic_cleanup() {
umount /dev/vnd0a || true
fssconfig -u fss0 || true
umount /dev/fss0 || true
vndconfig -u vnd0 || true
}
atf_init_test_cases()
{
atf_add_test_case basic
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_swsensor.sh,v 1.7 2013/04/14 16:07:46 martin Exp $
# $NetBSD: t_swsensor.sh,v 1.9 2015/04/23 23:23:28 pgoyette Exp $
get_sensor_info() {
rump.envstat -x | \
@ -6,7 +6,13 @@ get_sensor_info() {
}
get_sensor_key() {
get_sensor_info | grep -A1 $1 | grep integer | sed -e 's;<[/a-z]*>;;g'
local v
v=$(get_sensor_info | grep -A1 $1 | grep integer | \
sed -e 's;<[/a-z]*>;;g')
if [ -z "$v" ] ; then
v="key_$1_not_found"
fi
echo $v
}
get_powerd_event_count() {
@ -60,7 +66,7 @@ start_rump() {
common_head() {
atf_set descr "$1"
atf_set timeout 60
atf_set timeout 120
atf_set require.progs rump.powerd rump.envstat rump.modload \
rump.halt rump.sysctl rump_server \
sed grep awk \

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_swwdog.c,v 1.5 2011/06/26 12:14:59 christos Exp $ */
/* $NetBSD: t_swwdog.c,v 1.6 2015/04/23 04:49:37 pgoyette Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@ -121,6 +121,7 @@ testbody(int max)
_exit(2);
}
/* fail */
printf("no watchdog registered!\n");
_exit(1);
}

View file

@ -0,0 +1,267 @@
/* $NetBSD: t_hid.c,v 1.8 2016/05/05 17:40:26 jakllsch Exp $ */
/*
* Copyright (c) 2016 Jonathan A. Kollasch
* 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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/cdefs.h>
__RCSID("$NetBSD: t_hid.c,v 1.8 2016/05/05 17:40:26 jakllsch Exp $");
#include <machine/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <atf-c.h>
#include <rump/rump.h>
#define hid_start_parse rumpns_hid_start_parse
#define hid_end_parse rumpns_hid_end_parse
#define hid_get_item rumpns_hid_get_item
#define hid_locate rumpns_hid_locate
#define hid_report_size rumpns_hid_report_size
#define hid_get_data rumpns_hid_get_data
#define hid_get_udata rumpns_hid_get_udata
#define uhidevdebug rumpns_uhidevdebug
#include <usb.h>
#include <usbhid.h>
#include <hid.h>
#include "../../lib/libusbhid/hid_test_data.c"
#define MYd_ATF_CHECK_EQ(d, v) \
ATF_CHECK_EQ_MSG(d, v, "== %d", (d))
#define MYld_ATF_CHECK_EQ(d, v) \
ATF_CHECK_EQ_MSG(d, v, "== %ld", (d))
#define MYu_ATF_CHECK_EQ(d, v) \
ATF_CHECK_EQ_MSG(d, v, "== %u", (d))
#define MYlu_ATF_CHECK_EQ(d, v) \
ATF_CHECK_EQ_MSG(d, v, "== %lu", (d))
#define MYx_ATF_CHECK_EQ(d, v) \
ATF_CHECK_EQ_MSG(d, v, "== 0x%x", (d))
#define MYlx_ATF_CHECK_EQ(d, v) \
ATF_CHECK_EQ_MSG(d, v, "== 0x%lx", (d))
int uhidevdebug;
ATF_TC(khid);
ATF_TC_HEAD(khid, tc)
{
atf_tc_set_md_var(tc, "descr", "check kernel hid.c");
}
static int
locate_item(const void *desc, int size, u_int32_t u, u_int8_t id,
enum hid_kind k, struct hid_item *hip)
{
struct hid_data *d;
struct hid_item h;
h.report_ID = 0;
for (d = hid_start_parse(desc, size, k); hid_get_item(d, &h); ) {
if (h.kind == k && !(h.flags & HIO_CONST) &&
(/*XXX*/uint32_t)h.usage == u && h.report_ID == id) {
if (hip != NULL)
*hip = h;
hid_end_parse(d);
return (1);
}
}
hid_end_parse(d);
return (0);
}
ATF_TC_BODY(khid, tc)
{
int ret;
struct hid_item hi;
uhidevdebug = 0;
rump_init();
rump_schedule();
ret = locate_item(range_test_report_descriptor,
sizeof(range_test_report_descriptor), 0xff000003, 0, hid_input,
&hi);
ATF_REQUIRE(ret > 0);
MYu_ATF_CHECK_EQ(hi.loc.size, 32);
MYu_ATF_CHECK_EQ(hi.loc.count, 1);
MYu_ATF_CHECK_EQ(hi.loc.pos, 0);
MYx_ATF_CHECK_EQ(hi.flags, 0);
MYd_ATF_CHECK_EQ(hi.logical_minimum, -2147483648);
MYd_ATF_CHECK_EQ(hi.logical_maximum, 2147483647);
MYd_ATF_CHECK_EQ(hi.physical_minimum, -2147483648);
MYd_ATF_CHECK_EQ(hi.physical_maximum, 2147483647);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_minimum_report,
&hi.loc), -2147483648);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_negative_one_report,
&hi.loc), -1);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_positive_one_report,
&hi.loc), 1);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_maximum_report,
&hi.loc), 2147483647);
ret = locate_item(range_test_report_descriptor,
sizeof(range_test_report_descriptor), 0xff000002, 0, hid_input,
&hi);
ATF_REQUIRE(ret > 0);
MYu_ATF_CHECK_EQ(hi.loc.size, 16);
MYu_ATF_CHECK_EQ(hi.loc.count, 1);
MYu_ATF_CHECK_EQ(hi.loc.pos, 32);
MYx_ATF_CHECK_EQ(hi.flags, 0);
MYd_ATF_CHECK_EQ(hi.logical_minimum, -32768);
MYd_ATF_CHECK_EQ(hi.logical_maximum, 32767);
MYd_ATF_CHECK_EQ(hi.physical_minimum, -32768);
MYd_ATF_CHECK_EQ(hi.physical_maximum, 32767);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_minimum_report,
&hi.loc), -32768);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_negative_one_report,
&hi.loc), -1);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_positive_one_report,
&hi.loc), 1);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_maximum_report,
&hi.loc), 32767);
ret = locate_item(range_test_report_descriptor,
sizeof(range_test_report_descriptor), 0xff000001, 0, hid_input,
&hi);
ATF_REQUIRE(ret > 0);
MYu_ATF_CHECK_EQ(hi.loc.size, 8);
MYu_ATF_CHECK_EQ(hi.loc.count, 1);
MYu_ATF_CHECK_EQ(hi.loc.pos, 48);
MYx_ATF_CHECK_EQ(hi.flags, 0);
MYd_ATF_CHECK_EQ(hi.logical_minimum, -128);
MYd_ATF_CHECK_EQ(hi.logical_maximum, 127);
MYd_ATF_CHECK_EQ(hi.physical_minimum, -128);
MYd_ATF_CHECK_EQ(hi.physical_maximum, 127);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_minimum_report,
&hi.loc), -128);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_negative_one_report,
&hi.loc), -1);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_positive_one_report,
&hi.loc), 1);
MYld_ATF_CHECK_EQ(hid_get_data(range_test_maximum_report,
&hi.loc), 127);
ret = locate_item(unsigned_range_test_report_descriptor,
sizeof(unsigned_range_test_report_descriptor), 0xff000013, 0,
hid_input, &hi);
ATF_REQUIRE(ret > 0);
MYu_ATF_CHECK_EQ(hi.loc.size, 32);
MYu_ATF_CHECK_EQ(hi.loc.count, 1);
MYu_ATF_CHECK_EQ(hi.loc.pos, 0);
MYx_ATF_CHECK_EQ(hi.flags, 0);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_minimum_report,
&hi.loc), 0x0);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_positive_one_report,
&hi.loc), 0x1);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_negative_one_report,
&hi.loc), 0xfffffffe);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_maximum_report,
&hi.loc), 0xffffffff);
ret = locate_item(unsigned_range_test_report_descriptor,
sizeof(unsigned_range_test_report_descriptor), 0xff000012, 0,
hid_input, &hi);
ATF_REQUIRE(ret > 0);
MYu_ATF_CHECK_EQ(hi.loc.size, 16);
MYu_ATF_CHECK_EQ(hi.loc.count, 1);
MYu_ATF_CHECK_EQ(hi.loc.pos, 32);
MYx_ATF_CHECK_EQ(hi.flags, 0);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_minimum_report,
&hi.loc), 0x0);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_positive_one_report,
&hi.loc), 0x1);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_negative_one_report,
&hi.loc), 0xfffe);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_maximum_report,
&hi.loc), 0xffff);
ret = locate_item(unsigned_range_test_report_descriptor,
sizeof(unsigned_range_test_report_descriptor), 0xff000011, 0,
hid_input, &hi);
ATF_REQUIRE(ret > 0);
MYu_ATF_CHECK_EQ(hi.loc.size, 8);
MYu_ATF_CHECK_EQ(hi.loc.count, 1);
MYu_ATF_CHECK_EQ(hi.loc.pos, 48);
MYx_ATF_CHECK_EQ(hi.flags, 0);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_minimum_report,
&hi.loc), 0x0);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_positive_one_report,
&hi.loc), 0x1);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_negative_one_report,
&hi.loc), 0xfe);
MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_maximum_report,
&hi.loc), 0xff);
rump_unschedule();
}
ATF_TC(khid_parse_just_pop);
ATF_TC_HEAD(khid_parse_just_pop, tc)
{
atf_tc_set_md_var(tc, "descr", "check kernel hid.c for "
"Pop on empty stack bug");
}
ATF_TC_BODY(khid_parse_just_pop, tc)
{
struct hid_data *hdp;
struct hid_item hi;
rump_init();
rump_schedule();
hdp = hid_start_parse(just_pop_report_descriptor,
sizeof just_pop_report_descriptor, hid_none);
while (hid_get_item(hdp, &hi) > 0) {
}
hid_end_parse(hdp);
rump_unschedule();
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, khid);
ATF_TP_ADD_TC(tp, khid_parse_just_pop);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: fstest_lfs.c,v 1.4 2010/07/30 16:15:05 pooka Exp $ */
/* $NetBSD: fstest_lfs.c,v 1.5 2015/08/30 18:27:26 dholland Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -48,8 +48,6 @@
#include "h_fsmacros.h"
#include "mount_lfs.h"
sem_t lfs_clearnerloop;
struct lfstestargs {
struct ufs_args ta_uargs;
pthread_t ta_cleanerthread;

View file

@ -1,4 +1,4 @@
/* $NetBSD: h_fsmacros.h,v 1.38 2013/06/26 19:29:24 reinoud Exp $ */
/* $NetBSD: h_fsmacros.h,v 1.40 2015/08/29 19:19:43 dholland Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -110,10 +110,6 @@ do { \
atf_tc_set_md_var(tc, "descr", type " test for " desc); \
atf_tc_set_md_var(tc, "X-fs.type", #fs); \
atf_tc_set_md_var(tc, "X-fs.mntname", type); \
if (strcmp(#fs, "zfs") == 0) { \
/* This should not be necessary. */ \
atf_tc_set_md_var(tc, "require.user", "root"); \
} \
} \
void *fs##func##tmp; \
\
@ -136,10 +132,6 @@ do { \
atf_tc_set_md_var(tc, "descr",_type_" test for "_desc_);\
atf_tc_set_md_var(tc, "X-fs.type", #_fs_); \
atf_tc_set_md_var(tc, "X-fs.mntname", _type_); \
if (strcmp(#_fs_, "zfs") == 0) { \
/* This should not be necessary. */ \
atf_tc_set_md_var(tc, "require.user", "root"); \
} \
} \
void *_fs_##_func_##tmp; \
\
@ -153,7 +145,7 @@ do { \
atf_tc_fail_errno("unmount r/w failed"); \
if (_fs_##_fstest_mount(tc, _fs_##_func_##tmp, \
FSTEST_MNTNAME, MNT_RDONLY) != 0) \
atf_tc_fail_errno("mount ro failed"); \
atf_tc_fail_errno("mount ro failed"); \
_func_(tc,FSTEST_MNTNAME); \
if (_fs_##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) {\
rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \

File diff suppressed because it is too large Load diff

View file

@ -1,571 +0,0 @@
/* $NetBSD: nfsd.c,v 1.4 2013/10/19 17:45:00 christos Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Rick Macklem at The University of Guelph.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95";
#else
__RCSID("$NetBSD: nfsd.c,v 1.4 2013/10/19 17:45:00 christos Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/uio.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <poll.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
#include <nfs/nfs.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <netdb.h>
#include <rump/rump.h>
#include <rump/rump_syscalls.h>
/* Global defs */
#ifdef DEBUG
#define syslog(e, s, args...) \
do { \
fprintf(stderr,(s), ## args); \
fprintf(stderr, "\n"); \
} while (/*CONSTCOND*/0)
int debug = 1;
#else
int debug = 0;
#endif
int main __P((int, char **));
void nonfs __P((int));
void usage __P((void));
static void *
child(void *arg)
{
struct nfsd_srvargs nsd;
int nfssvc_flag;
nfssvc_flag = NFSSVC_NFSD;
memset(&nsd, 0, sizeof(nsd));
while (rump_sys_nfssvc(nfssvc_flag, &nsd) < 0) {
if (errno != ENEEDAUTH) {
syslog(LOG_ERR, "nfssvc: %m %d", errno);
exit(1);
}
nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL;
}
return NULL;
}
/*
* Nfs server daemon mostly just a user context for nfssvc()
*
* 1 - do file descriptor and signal cleanup
* 2 - create the nfsd thread(s)
* 3 - create server socket(s)
* 4 - register socket with portmap
*
* For connectionless protocols, just pass the socket into the kernel via
* nfssvc().
* For connection based sockets, loop doing accepts. When you get a new
* socket from accept, pass the msgsock into the kernel via nfssvc().
* The arguments are:
* -c - support iso cltp clients
* -r - reregister with portmapper
* -t - support tcp nfs clients
* -u - support udp nfs clients
* followed by "n" which is the number of nfsd threads to create
*/
int nfsd_main(int, char**);
int
nfsd_main(argc, argv)
int argc;
char *argv[];
{
struct nfsd_args nfsdargs;
struct addrinfo *ai_udp, *ai_tcp, *ai_udp6, *ai_tcp6, hints;
struct netconfig *nconf_udp, *nconf_tcp, *nconf_udp6, *nconf_tcp6;
struct netbuf nb_udp, nb_tcp, nb_udp6, nb_tcp6;
struct sockaddr_in inetpeer;
struct pollfd set[4];
socklen_t len;
int ch, connect_type_cnt, i, msgsock;
int nfsdcnt, on = 1, reregister, sock, tcpflag, tcpsock;
int tcp6sock, ip6flag;
int tp4cnt, tp4flag, tpipcnt, udpflag, ecode, s;
int error = 0;
#define DEFNFSDCNT 4
nfsdcnt = DEFNFSDCNT;
reregister = tcpflag = tp4cnt = tp4flag = tpipcnt = 0;
udpflag = ip6flag = 0;
nconf_udp = nconf_tcp = nconf_udp6 = nconf_tcp6 = NULL;
tcpsock = tcp6sock = -1;
#define GETOPT "6n:rtu"
#define USAGE "[-rtu] [-n num_servers]"
while ((ch = getopt(argc, argv, GETOPT)) != -1) {
switch (ch) {
case '6':
ip6flag = 1;
s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (s < 0 && (errno == EPROTONOSUPPORT ||
errno == EPFNOSUPPORT || errno == EAFNOSUPPORT))
ip6flag = 0;
else
close(s);
break;
case 'n':
nfsdcnt = atoi(optarg);
if (nfsdcnt < 1) {
warnx("nfsd count %d; reset to %d", nfsdcnt, DEFNFSDCNT);
nfsdcnt = DEFNFSDCNT;
}
break;
case 'r':
reregister = 1;
break;
case 't':
tcpflag = 1;
break;
case 'u':
udpflag = 1;
break;
default:
case '?':
usage();
};
}
argv += optind;
argc -= optind;
/*
* XXX
* Backward compatibility, trailing number is the count of daemons.
*/
if (argc > 1)
usage();
if (argc == 1) {
nfsdcnt = atoi(argv[0]);
if (nfsdcnt < 1) {
warnx("nfsd count %d; reset to %d", nfsdcnt, DEFNFSDCNT);
nfsdcnt = DEFNFSDCNT;
}
}
/*
* If none of TCP or UDP are specified, default to UDP only.
*/
if (tcpflag == 0 && udpflag == 0)
udpflag = 1;
if (debug == 0) {
fprintf(stderr, "non-debug not supported here\n");
exit(1);
#ifdef not_the_debug_man
daemon(0, 0);
(void)signal(SIGHUP, SIG_IGN);
(void)signal(SIGINT, SIG_IGN);
(void)signal(SIGQUIT, SIG_IGN);
(void)signal(SIGSYS, nonfs);
#endif
}
if (udpflag) {
memset(&hints, 0, sizeof hints);
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp);
if (ecode != 0) {
syslog(LOG_ERR, "getaddrinfo udp: %s",
gai_strerror(ecode));
exit(1);
}
nconf_udp = getnetconfigent("udp");
if (nconf_udp == NULL)
err(1, "getnetconfigent udp failed");
nb_udp.buf = ai_udp->ai_addr;
nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
if (reregister)
if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp))
err(1, "rpcb_set udp failed");
}
if (tcpflag) {
memset(&hints, 0, sizeof hints);
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp);
if (ecode != 0) {
syslog(LOG_ERR, "getaddrinfo tcp: %s",
gai_strerror(ecode));
exit(1);
}
nconf_tcp = getnetconfigent("tcp");
if (nconf_tcp == NULL)
err(1, "getnetconfigent tcp failed");
nb_tcp.buf = ai_tcp->ai_addr;
nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
if (reregister)
if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp, &nb_tcp))
err(1, "rpcb_set tcp failed");
}
if (udpflag && ip6flag) {
memset(&hints, 0, sizeof hints);
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_INET6;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp6);
if (ecode != 0) {
syslog(LOG_ERR, "getaddrinfo udp: %s",
gai_strerror(ecode));
exit(1);
}
nconf_udp6 = getnetconfigent("udp6");
if (nconf_udp6 == NULL)
err(1, "getnetconfigent udp6 failed");
nb_udp6.buf = ai_udp6->ai_addr;
nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
if (reregister)
if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6))
err(1, "rpcb_set udp6 failed");
}
if (tcpflag && ip6flag) {
memset(&hints, 0, sizeof hints);
hints.ai_flags = AI_PASSIVE;
hints.ai_family = PF_INET6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp6);
if (ecode != 0) {
syslog(LOG_ERR, "getaddrinfo tcp: %s",
gai_strerror(ecode));
exit(1);
}
nconf_tcp6 = getnetconfigent("tcp6");
if (nconf_tcp6 == NULL)
err(1, "getnetconfigent tcp6 failed");
nb_tcp6.buf = ai_tcp6->ai_addr;
nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
if (reregister)
if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6))
err(1, "rpcb_set tcp6 failed");
}
openlog("nfsd", LOG_PID, LOG_DAEMON);
for (i = 0; i < nfsdcnt; i++) {
pthread_t t;
pthread_create(&t, NULL, child, NULL);
}
/* If we are serving udp, set up the socket. */
if (udpflag) {
if ((sock = rump_sys_socket(ai_udp->ai_family, ai_udp->ai_socktype,
ai_udp->ai_protocol)) < 0) {
syslog(LOG_ERR, "can't create udp socket");
exit(1);
}
if (bind(sock, ai_udp->ai_addr, ai_udp->ai_addrlen) < 0) {
syslog(LOG_ERR, "can't bind udp addr");
exit(1);
}
if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp) ||
!rpcb_set(RPCPROG_NFS, 3, nconf_udp, &nb_udp)) {
syslog(LOG_ERR, "can't register with udp portmap");
exit(1);
}
nfsdargs.sock = sock;
nfsdargs.name = NULL;
nfsdargs.namelen = 0;
if (rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
syslog(LOG_ERR, "can't add UDP socket");
exit(1);
}
(void)rump_sys_close(sock);
}
if (udpflag &&ip6flag) {
if ((sock = rump_sys_socket(ai_udp6->ai_family, ai_udp6->ai_socktype,
ai_udp6->ai_protocol)) < 0) {
syslog(LOG_ERR, "can't create udp socket");
exit(1);
}
if (rump_sys_setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
&on, sizeof on) < 0) {
syslog(LOG_ERR, "can't set v6-only binding for udp6 "
"socket: %m");
exit(1);
}
if (rump_sys_bind(sock, ai_udp6->ai_addr, ai_udp6->ai_addrlen) < 0) {
syslog(LOG_ERR, "can't bind udp addr");
exit(1);
}
if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6) ||
!rpcb_set(RPCPROG_NFS, 3, nconf_udp6, &nb_udp6)) {
syslog(LOG_ERR, "can't register with udp portmap");
exit(1);
}
nfsdargs.sock = sock;
nfsdargs.name = NULL;
nfsdargs.namelen = 0;
if (rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
syslog(LOG_ERR, "can't add UDP6 socket");
exit(1);
}
(void)rump_sys_close(sock);
}
/* Now set up the master server socket waiting for tcp connections. */
on = 1;
connect_type_cnt = 0;
if (tcpflag) {
if ((tcpsock = rump_sys_socket(ai_tcp->ai_family, ai_tcp->ai_socktype,
ai_tcp->ai_protocol)) < 0) {
syslog(LOG_ERR, "can't create tcp socket");
exit(1);
}
if (setsockopt(tcpsock,
SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
if (bind(tcpsock, ai_tcp->ai_addr, ai_tcp->ai_addrlen) < 0) {
syslog(LOG_ERR, "can't bind tcp addr");
exit(1);
}
if (rump_sys_listen(tcpsock, 5) < 0) {
syslog(LOG_ERR, "listen failed");
exit(1);
}
if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp, &nb_tcp) ||
!rpcb_set(RPCPROG_NFS, 3, nconf_tcp, &nb_tcp)) {
syslog(LOG_ERR, "can't register tcp with rpcbind");
exit(1);
}
set[0].fd = tcpsock;
set[0].events = POLLIN;
connect_type_cnt++;
} else
set[0].fd = -1;
if (tcpflag && ip6flag) {
if ((tcp6sock = socket(ai_tcp6->ai_family, ai_tcp6->ai_socktype,
ai_tcp6->ai_protocol)) < 0) {
syslog(LOG_ERR, "can't create tcp socket");
exit(1);
}
if (setsockopt(tcp6sock,
SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
if (setsockopt(tcp6sock, IPPROTO_IPV6, IPV6_V6ONLY,
&on, sizeof on) < 0) {
syslog(LOG_ERR, "can't set v6-only binding for tcp6 "
"socket: %m");
exit(1);
}
if (bind(tcp6sock, ai_tcp6->ai_addr, ai_tcp6->ai_addrlen) < 0) {
syslog(LOG_ERR, "can't bind tcp6 addr");
exit(1);
}
if (listen(tcp6sock, 5) < 0) {
syslog(LOG_ERR, "listen failed");
exit(1);
}
if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6) ||
!rpcb_set(RPCPROG_NFS, 3, nconf_tcp6, &nb_tcp6)) {
syslog(LOG_ERR, "can't register tcp6 with rpcbind");
exit(1);
}
set[1].fd = tcp6sock;
set[1].events = POLLIN;
connect_type_cnt++;
} else
set[1].fd = -1;
set[2].fd = -1;
set[3].fd = -1;
if (connect_type_cnt == 0) {
pause();
exit(0);
}
/*
* Loop forever accepting connections and passing the sockets
* into the kernel for the mounts.
*/
for (;;) {
if (rump_sys_poll(set, 4, INFTIM) < 1) {
syslog(LOG_ERR, "poll failed: %m");
exit(1);
}
len = sizeof(inetpeer);
if ((msgsock = accept(tcpsock,
(struct sockaddr *)&inetpeer, &len)) < 0) {
syslog(LOG_ERR, "accept failed: %d", error);
exit(1);
}
memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
if (setsockopt(msgsock, SOL_SOCKET,
SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
syslog(LOG_ERR,
"setsockopt SO_KEEPALIVE: %m");
nfsdargs.sock = msgsock;
nfsdargs.name = (caddr_t)&inetpeer;
nfsdargs.namelen = sizeof(inetpeer);
rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
(void)rump_sys_close(msgsock);
#ifdef notyet
if (set[1].revents & POLLIN) {
len = sizeof(inet6peer);
if ((msgsock = rump_sys_accept(tcp6sock,
(struct sockaddr *)&inet6peer, &len, &error)) < 0) {
syslog(LOG_ERR, "accept failed: %m");
exit(1);
}
if (rump_sys_setsockopt(msgsock, SOL_SOCKET,
SO_KEEPALIVE, (char *)&on, sizeof(on), &error) < 0)
syslog(LOG_ERR,
"setsockopt SO_KEEPALIVE: %m");
nfsdargs.sock = msgsock;
nfsdargs.name = (caddr_t)&inet6peer;
nfsdargs.namelen = sizeof(inet6peer);
rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs, &error);
(void)rump_sys_close(msgsock, &error);
}
if (set[2].revents & POLLIN) {
len = sizeof(isopeer);
if ((msgsock = rump_sys_accept(tp4sock,
(struct sockaddr *)&isopeer, &len, &error)) < 0) {
syslog(LOG_ERR, "accept failed: %m");
exit(1);
}
if (rump_sys_setsockopt(msgsock, SOL_SOCKET,
SO_KEEPALIVE, (char *)&on, sizeof(on), &error) < 0)
syslog(LOG_ERR,
"setsockopt SO_KEEPALIVE: %m");
nfsdargs.sock = msgsock;
nfsdargs.name = (caddr_t)&isopeer;
nfsdargs.namelen = len;
rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs, &error);
(void)rump_sys_close(msgsock, &error);
}
if (set[3].revents & POLLIN) {
len = sizeof(inetpeer);
if ((msgsock = rump_sys_accept(tpipsock,
(struct sockaddr *)&inetpeer, &len)) < 0) {
syslog(LOG_ERR, "accept failed: %m");
exit(1);
}
if (setsockopt(msgsock, SOL_SOCKET,
SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
syslog(LOG_ERR, "setsockopt SO_KEEPALIVE: %m");
nfsdargs.sock = msgsock;
nfsdargs.name = (caddr_t)&inetpeer;
nfsdargs.namelen = len;
rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
(void)rump_sys_close(msgsock);
}
#endif /* notyet */
}
}
void
usage()
{
(void)fprintf(stderr, "usage: nfsd %s\n", USAGE);
exit(1);
}
void
nonfs(signo)
int signo;
{
syslog(LOG_ERR, "missing system call: NFS not available.");
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: rumpnfsd.c,v 1.8 2014/05/12 15:31:07 christos Exp $ */
/* $NetBSD: rumpnfsd.c,v 1.9 2015/11/08 02:45:16 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -37,6 +37,7 @@
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <rpc/rpc.h>
void *mountd_main(void *);
void *rpcbind_main(void *);
@ -87,7 +88,7 @@ main(int argc, char *argv[])
}
rump_init();
init_fdsets();
svc_fdset_init(SVC_FDSET_MT);
rv = rump_pub_etfs_register("/etc/exports", "./exports", RUMP_ETFS_REG);
if (rv) {

View file

@ -1,4 +1,4 @@
# $NetBSD: t_rquotad.sh,v 1.4 2014/03/13 12:45:14 gson Exp $
# $NetBSD: t_rquotad.sh,v 1.5 2016/08/10 23:25:39 kre Exp $
#
# Copyright (c) 2011 Manuel Bouyer
# All rights reserved.
@ -114,7 +114,7 @@ get_nfs_quota()
unset RUMPHIJACK
unset LD_PRELOAD
atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet \
atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet -lrumpdev \
-lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\
${RUMP_SERVER}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_vnd.sh,v 1.8 2011/04/21 22:26:46 haad Exp $
# $NetBSD: t_vnd.sh,v 1.9 2016/07/29 05:23:24 pgoyette Exp $
#
# Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
# All rights reserved.
@ -38,7 +38,7 @@ basic_body() {
atf_check -s eq:0 -o ignore -e ignore \
dd if=/dev/zero of=disk.img bs=1m count=10
atf_check -s eq:0 -o empty -e empty vnconfig /dev/vnd3 disk.img
atf_check -s eq:0 -o empty -e empty vndconfig /dev/vnd3 disk.img
atf_check -s eq:0 -o ignore -e ignore newfs /dev/rvnd3a
@ -58,7 +58,7 @@ basic_body() {
done
atf_check -s eq:0 -o empty -e empty umount mnt
atf_check -s eq:0 -o empty -e empty vnconfig -u /dev/vnd3
atf_check -s eq:0 -o empty -e empty vndconfig -u /dev/vnd3
test_unmount
touch done
@ -66,7 +66,7 @@ basic_body() {
basic_cleanup() {
if [ ! -f done ]; then
umount mnt 2>/dev/null 1>&2
vnconfig -u /dev/vnd3 2>/dev/null 1>&2
vndconfig -u /dev/vnd3 2>/dev/null 1>&2
fi
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_io.c,v 1.12 2013/08/04 11:02:02 pooka Exp $ */
/* $NetBSD: t_io.c,v 1.16 2015/04/04 12:34:44 riastradh Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -222,6 +222,22 @@ wrrd_after_unlink(const atf_tc_t *tc, const char *mp)
FSTEST_EXIT();
}
static void
read_fault(const atf_tc_t *tc, const char *mp)
{
char ch = 123;
int fd;
FSTEST_ENTER();
RL(fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777));
ATF_REQUIRE_EQ(rump_sys_write(fd, &ch, 1), 1);
RL(rump_sys_close(fd));
RL(fd = rump_sys_open("file", O_RDONLY | O_SYNC | O_RSYNC));
ATF_REQUIRE_ERRNO(EFAULT, rump_sys_read(fd, NULL, 1) == -1);
RL(rump_sys_close(fd));
FSTEST_EXIT();
}
ATF_TC_FSAPPLY(holywrite, "create a sparse file and fill hole");
ATF_TC_FSAPPLY(extendfile, "check that extending a file works");
ATF_TC_FSAPPLY(extendfile_append, "check that extending a file works "
@ -232,6 +248,7 @@ ATF_TC_FSAPPLY(overwrite_trunc, "write 64k + truncate + rewrite");
ATF_TC_FSAPPLY(shrinkfile, "shrink file");
ATF_TC_FSAPPLY(read_after_unlink, "contents can be read off disk after unlink");
ATF_TC_FSAPPLY(wrrd_after_unlink, "file can be written and read after unlink");
ATF_TC_FSAPPLY(read_fault, "read at bad address must return EFAULT");
ATF_TP_ADD_TCS(tp)
{
@ -245,6 +262,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_FSAPPLY(shrinkfile);
ATF_TP_FSAPPLY(read_after_unlink);
ATF_TP_FSAPPLY(wrrd_after_unlink);
ATF_TP_FSAPPLY(read_fault);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_renamerace.c,v 1.32 2014/07/29 09:15:48 gson Exp $ */
/* $NetBSD: t_renamerace.c,v 1.33 2016/05/04 08:30:22 dholland Exp $ */
/*
* Modified for rump and atf from a program supplied
@ -127,7 +127,7 @@ renamerace(const atf_tc_t *tc, const char *mp)
atf_tc_fail("race did not trigger this time");
if (FSTYPE_MSDOS(tc)) {
atf_tc_expect_fail("PR kern/44661");
atf_tc_expect_fail("PR kern/43626");
/*
* XXX: race does not trigger every time at least
* on amd64/qemu.

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_unpriv.c,v 1.11 2014/08/29 17:39:18 gson Exp $ */
/* $NetBSD: t_unpriv.c,v 1.12 2015/04/09 19:51:13 riastradh Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -55,8 +55,6 @@ owner(const atf_tc_t *tc, const char *mp)
rump_pub_lwproc_rfork(RUMP_RFCFDG);
if (rump_sys_setuid(1) == -1)
atf_tc_fail_errno("setuid");
if (FSTYPE_ZFS(tc))
atf_tc_expect_fail("PR kern/47656: Test known to be broken");
if (rump_sys_chown(".", 1, -1) != -1 || errno != EPERM)
atf_tc_fail_errno("chown");
if (rump_sys_chmod(".", 0000) != -1 || errno != EPERM)

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_vnops.c,v 1.43 2014/09/09 06:51:00 gson Exp $ */
/* $NetBSD: t_vnops.c,v 1.55 2016/01/28 10:10:09 martin Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -31,6 +31,7 @@
#include <assert.h>
#include <atf-c.h>
#include <ctype.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdlib.h>
@ -118,10 +119,10 @@ lookup_complex(const atf_tc_t *tc, const char *mountpath)
FIELD(st_uid);
FIELD(st_gid);
FIELD(st_rdev);
TIME(st_atim);
TIME(st_mtim);
TIME(st_ctim);
TIME(st_birthtim);
TIME(st_atimespec);
TIME(st_mtimespec);
TIME(st_ctimespec);
TIME(st_birthtimespec);
FIELD(st_size);
FIELD(st_blocks);
FIELD(st_flags);
@ -179,8 +180,6 @@ dir_notempty(const atf_tc_t *tc, const char *mountpath)
rump_sys_close(fd);
rv = rump_sys_rmdir(pb);
if (FSTYPE_ZFS(tc))
atf_tc_expect_fail("PR kern/47656: Test known to be broken");
if (rv != -1 || errno != ENOTEMPTY)
atf_tc_fail("non-empty directory removed succesfully");
@ -276,8 +275,6 @@ rename_dir(const atf_tc_t *tc, const char *mp)
md(pb1, mp, "dir3/.");
if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
atf_tc_fail_errno("rename 2");
if (FSTYPE_ZFS(tc))
atf_tc_expect_fail("PR kern/47656: Test known to be broken");
if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
atf_tc_fail_errno("rename 3");
@ -442,6 +439,78 @@ rename_reg_nodir(const atf_tc_t *tc, const char *mp)
rump_sys_chdir("/");
}
/* PR kern/50607 */
static void
create_many(const atf_tc_t *tc, const char *mp)
{
char buf[64];
int nfiles = 2324; /* #Nancy */
int i;
/* takes forever with many files */
if (FSTYPE_MSDOS(tc))
nfiles /= 4;
RL(rump_sys_chdir(mp));
if (FSTYPE_SYSVBFS(tc)) {
/* fs doesn't support many files or subdirectories */
nfiles = 5;
} else {
/* msdosfs doesn't like many entries in the root directory */
RL(rump_sys_mkdir("subdir", 0777));
RL(rump_sys_chdir("subdir"));
}
/* create them */
#define TESTFN "testfile"
for (i = 0; i < nfiles; i++) {
int fd;
sprintf(buf, TESTFN "%d", i);
RL(fd = rump_sys_open(buf, O_RDWR|O_CREAT|O_EXCL, 0666));
RL(rump_sys_close(fd));
}
/* wipe them out */
for (i = 0; i < nfiles; i++) {
sprintf(buf, TESTFN "%d", i);
RL(rump_sys_unlink(buf));
}
#undef TESTFN
rump_sys_chdir("/");
}
/*
* Test creating files with one-character names using all possible
* character values. Failures to create the file are ignored as the
* characters allowed in file names vary by file system, but at least
* we can check that the fs does not crash, and if the file is
* successfully created, unlinking it should also succeed.
*/
static void
create_nonalphanum(const atf_tc_t *tc, const char *mp)
{
char buf[64];
int i;
RL(rump_sys_chdir(mp));
for (i = 0; i < 256; i++) {
int fd;
sprintf(buf, "%c", i);
fd = rump_sys_open(buf, O_RDWR|O_CREAT|O_EXCL, 0666);
if (fd == -1)
continue;
RL(rump_sys_close(fd));
RL(rump_sys_unlink(buf));
}
printf("\n");
rump_sys_chdir("/");
}
static void
create_nametoolong(const atf_tc_t *tc, const char *mp)
{
@ -645,8 +714,6 @@ attrs(const atf_tc_t *tc, const char *mp)
RL(rump_sys_stat(TESTFILE, &sb2));
#define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a)
if (FSTYPE_ZFS(tc))
atf_tc_expect_fail("PR kern/47656: Test known to be broken");
if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
CHECK(st_uid);
CHECK(st_gid);
@ -684,9 +751,6 @@ fcntl_lock(const atf_tc_t *tc, const char *mp)
RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
RL(rump_sys_ftruncate(fd, 8192));
/* PR kern/43321 */
if (FSTYPE_ZFS(tc))
atf_tc_expect_fail("PR kern/47656: Test known to be broken");
RL(rump_sys_fcntl(fd, F_SETLK, &l));
/* Next, we fork and try to lock the same area */
@ -820,9 +884,6 @@ fcntl_getlock_pids(const atf_tc_t *tc, const char *mp)
RL(rump_sys_ftruncate(fd[i], sz));
if (FSTYPE_ZFS(tc))
atf_tc_expect_fail("PR kern/47656: Test known to be "
"broken");
if (i < __arraycount(lock)) {
RL(rump_sys_fcntl(fd[i], F_SETLK, &lock[i]));
expect[i].l_pid = pid[i];
@ -932,9 +993,6 @@ lstat_symlink(const atf_tc_t *tc, const char *mp)
USES_SYMLINKS;
if (FSTYPE_V7FS(tc))
atf_tc_expect_fail("PR kern/48864");
FSTEST_ENTER();
src = "source";
@ -973,6 +1031,11 @@ ATF_TC_FSAPPLY(access_simple, "access(2)");
ATF_TC_FSAPPLY(read_directory, "read(2) on directories");
ATF_TC_FSAPPLY(lstat_symlink, "lstat(2) values for symbolic links");
#undef FSTEST_IMGSIZE
#define FSTEST_IMGSIZE (1024*1024*64)
ATF_TC_FSAPPLY(create_many, "create many directory entries");
ATF_TC_FSAPPLY(create_nonalphanum, "non-alphanumeric filenames");
ATF_TP_ADD_TCS(tp)
{
@ -984,6 +1047,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_FSAPPLY(rename_dir);
ATF_TP_FSAPPLY(rename_dotdot);
ATF_TP_FSAPPLY(rename_reg_nodir);
ATF_TP_FSAPPLY(create_many);
ATF_TP_FSAPPLY(create_nonalphanum);
ATF_TP_FSAPPLY(create_nametoolong);
ATF_TP_FSAPPLY(create_exist);
ATF_TP_FSAPPLY(rename_nametoolong);

View file

@ -1,4 +1,4 @@
# $NetBSD: t_factor.sh,v 1.7 2010/11/19 12:31:36 pgoyette Exp $
# $NetBSD: t_factor.sh,v 1.9 2016/06/27 05:29:32 pgoyette Exp $
#
# Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
# All rights reserved.
@ -27,32 +27,55 @@
expect() {
echo "${2}" >expout
atf_check -s eq:0 -o file:expout -e empty /usr/bin/factor ${1}
ncrypt=$( ldd /usr/games/factor | grep -c -- -lcrypt )
if [ "X$3" != "X" -a $ncrypt -eq 0 ] ; then
atf_skip "crypto needed for huge non-prime factors - PR bin/23663"
fi
atf_check -s eq:0 -o file:expout -e empty /usr/games/factor ${1}
}
atf_test_case overflow
overflow_head() {
atf_test_case overflow1
overflow1_head() {
atf_set "descr" "Tests for overflow conditions"
atf_set "require.progs" "/usr/bin/factor"
}
overflow_body() {
overflow1_body() {
expect '8675309' '8675309: 8675309'
}
atf_test_case overflow2
overflow2_head() {
atf_set "descr" "Tests for overflow conditions"
atf_set "require.progs" "/usr/games/factor"
}
overflow2_body() {
expect '6172538568' '6172538568: 2 2 2 3 7 17 2161253'
}
atf_test_case loop
loop_head() {
atf_test_case loop1
loop1_head() {
atf_set "descr" "Tests some cases that once locked the program" \
"in an infinite loop"
atf_set "require.progs" "/usr/bin/factor"
}
loop_body() {
expect '99999999999991' '99999999999991: 7 13 769231 1428571'
loop1_body() {
expect '2147483647111311' '2147483647111311: 3 3 3 131 607148331103'
}
atf_test_case loop2
loop2_head() {
atf_set "descr" "Tests some cases that once locked the program" \
"in an infinite loop"
atf_set "require.progs" "/usr/games/factor"
}
loop2_body() {
expect '99999999999991' '99999999999991: 7 13 769231 1428571' Need_Crypto
}
atf_init_test_cases()
{
atf_add_test_case overflow
atf_add_test_case loop
atf_add_test_case overflow1
atf_add_test_case overflow2
atf_add_test_case loop1
atf_add_test_case loop2
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: h_macros.h,v 1.9 2013/05/17 15:42:09 christos Exp $ */
/* $NetBSD: h_macros.h,v 1.12 2016/08/04 11:49:07 jakllsch Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -51,7 +51,7 @@ do { \
ATF_REQUIRE_MSG(RZ_rv == 0, "%s: %s", #x, strerror(RZ_rv)); \
} while (/*CONSTCOND*/0)
static __inline __printflike(1, 2) void
__dead static __inline __printflike(1, 2) void
atf_tc_fail_errno(const char *fmt, ...)
{
va_list ap;
@ -75,7 +75,7 @@ tests_makegarbage(void *space, size_t len)
uint16_t randval;
while (len >= sizeof(randval)) {
*sb++ = (random() & 0xffff);
*sb++ = (uint16_t)random();
len -= sizeof(*sb);
}
randval = (uint16_t)random();

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_bitops.c,v 1.16 2012/12/07 02:28:19 christos Exp $ */
/* $NetBSD: t_bitops.c,v 1.19 2015/03/21 05:50:19 isaki Exp $ */
/*-
* Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_bitops.c,v 1.16 2012/12/07 02:28:19 christos Exp $");
__RCSID("$NetBSD: t_bitops.c,v 1.19 2015/03/21 05:50:19 isaki Exp $");
#include <atf-c.h>
@ -67,7 +67,7 @@ static const struct {
ATF_TC(bitmap_basic);
ATF_TC_HEAD(bitmap_basic, tc)
{
atf_tc_set_md_var(tc, "descr", "A basic test of __BITMAP_*");
atf_tc_set_md_var(tc, "descr", "A basic test of __BITMAP_*");
}
ATF_TC_BODY(bitmap_basic, tc)
@ -174,65 +174,191 @@ ATF_TC_BODY(ffsfls, tc)
}
}
ATF_TC(ilog2_basic);
ATF_TC_HEAD(ilog2_basic, tc)
ATF_TC(ilog2_32bit);
ATF_TC_HEAD(ilog2_32bit, tc)
{
atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for correctness");
atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for 32bit variable");
}
ATF_TC_BODY(ilog2_basic, tc)
ATF_TC_BODY(ilog2_32bit, tc)
{
uint64_t i, x;
int i;
uint32_t x;
for (i = x = 0; i < 64; i++) {
x = (uint64_t)1 << i;
ATF_REQUIRE(i == (uint64_t)ilog2(x));
for (i = 0; i < 32; i++) {
x = 1 << i;
ATF_REQUIRE(ilog2(x) == i);
}
}
ATF_TC(ilog2_log2);
ATF_TC_HEAD(ilog2_log2, tc)
ATF_TC(ilog2_64bit);
ATF_TC_HEAD(ilog2_64bit, tc)
{
atf_tc_set_md_var(tc, "descr", "Test log2(3) vs. ilog2(3)");
atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for 64bit variable");
}
ATF_TC_BODY(ilog2_log2, tc)
ATF_TC_BODY(ilog2_64bit, tc)
{
#ifdef __vax__
atf_tc_skip("Test is unavailable on vax because of lack of log2()");
#else
double x, y;
uint64_t i;
int i;
uint64_t x;
for (i = 0; i < 64; i++) {
x = ((uint64_t)1) << i;
ATF_REQUIRE(ilog2(x) == i);
}
}
ATF_TC(ilog2_const);
ATF_TC_HEAD(ilog2_const, tc)
{
atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for constant");
}
ATF_TC_BODY(ilog2_const, tc)
{
/*
* This may fail under QEMU; see PR misc/44767.
* These inlines test __builtin_constant_p() part of ilog2()
* at compile time, so don't change it to loop. PR lib/49745
*/
for (i = 1; i < UINT32_MAX; i += UINT16_MAX) {
ATF_REQUIRE(ilog2(0x0000000000000001ULL) == 0);
ATF_REQUIRE(ilog2(0x0000000000000002ULL) == 1);
ATF_REQUIRE(ilog2(0x0000000000000004ULL) == 2);
ATF_REQUIRE(ilog2(0x0000000000000008ULL) == 3);
ATF_REQUIRE(ilog2(0x0000000000000010ULL) == 4);
ATF_REQUIRE(ilog2(0x0000000000000020ULL) == 5);
ATF_REQUIRE(ilog2(0x0000000000000040ULL) == 6);
ATF_REQUIRE(ilog2(0x0000000000000080ULL) == 7);
ATF_REQUIRE(ilog2(0x0000000000000100ULL) == 8);
ATF_REQUIRE(ilog2(0x0000000000000200ULL) == 9);
ATF_REQUIRE(ilog2(0x0000000000000400ULL) == 10);
ATF_REQUIRE(ilog2(0x0000000000000800ULL) == 11);
ATF_REQUIRE(ilog2(0x0000000000001000ULL) == 12);
ATF_REQUIRE(ilog2(0x0000000000002000ULL) == 13);
ATF_REQUIRE(ilog2(0x0000000000004000ULL) == 14);
ATF_REQUIRE(ilog2(0x0000000000008000ULL) == 15);
ATF_REQUIRE(ilog2(0x0000000000010000ULL) == 16);
ATF_REQUIRE(ilog2(0x0000000000020000ULL) == 17);
ATF_REQUIRE(ilog2(0x0000000000040000ULL) == 18);
ATF_REQUIRE(ilog2(0x0000000000080000ULL) == 19);
ATF_REQUIRE(ilog2(0x0000000000100000ULL) == 20);
ATF_REQUIRE(ilog2(0x0000000000200000ULL) == 21);
ATF_REQUIRE(ilog2(0x0000000000400000ULL) == 22);
ATF_REQUIRE(ilog2(0x0000000000800000ULL) == 23);
ATF_REQUIRE(ilog2(0x0000000001000000ULL) == 24);
ATF_REQUIRE(ilog2(0x0000000002000000ULL) == 25);
ATF_REQUIRE(ilog2(0x0000000004000000ULL) == 26);
ATF_REQUIRE(ilog2(0x0000000008000000ULL) == 27);
ATF_REQUIRE(ilog2(0x0000000010000000ULL) == 28);
ATF_REQUIRE(ilog2(0x0000000020000000ULL) == 29);
ATF_REQUIRE(ilog2(0x0000000040000000ULL) == 30);
ATF_REQUIRE(ilog2(0x0000000080000000ULL) == 31);
ATF_REQUIRE(ilog2(0x0000000100000000ULL) == 32);
ATF_REQUIRE(ilog2(0x0000000200000000ULL) == 33);
ATF_REQUIRE(ilog2(0x0000000400000000ULL) == 34);
ATF_REQUIRE(ilog2(0x0000000800000000ULL) == 35);
ATF_REQUIRE(ilog2(0x0000001000000000ULL) == 36);
ATF_REQUIRE(ilog2(0x0000002000000000ULL) == 37);
ATF_REQUIRE(ilog2(0x0000004000000000ULL) == 38);
ATF_REQUIRE(ilog2(0x0000008000000000ULL) == 39);
ATF_REQUIRE(ilog2(0x0000010000000000ULL) == 40);
ATF_REQUIRE(ilog2(0x0000020000000000ULL) == 41);
ATF_REQUIRE(ilog2(0x0000040000000000ULL) == 42);
ATF_REQUIRE(ilog2(0x0000080000000000ULL) == 43);
ATF_REQUIRE(ilog2(0x0000100000000000ULL) == 44);
ATF_REQUIRE(ilog2(0x0000200000000000ULL) == 45);
ATF_REQUIRE(ilog2(0x0000400000000000ULL) == 46);
ATF_REQUIRE(ilog2(0x0000800000000000ULL) == 47);
ATF_REQUIRE(ilog2(0x0001000000000000ULL) == 48);
ATF_REQUIRE(ilog2(0x0002000000000000ULL) == 49);
ATF_REQUIRE(ilog2(0x0004000000000000ULL) == 50);
ATF_REQUIRE(ilog2(0x0008000000000000ULL) == 51);
ATF_REQUIRE(ilog2(0x0010000000000000ULL) == 52);
ATF_REQUIRE(ilog2(0x0020000000000000ULL) == 53);
ATF_REQUIRE(ilog2(0x0040000000000000ULL) == 54);
ATF_REQUIRE(ilog2(0x0080000000000000ULL) == 55);
ATF_REQUIRE(ilog2(0x0100000000000000ULL) == 56);
ATF_REQUIRE(ilog2(0x0200000000000000ULL) == 57);
ATF_REQUIRE(ilog2(0x0400000000000000ULL) == 58);
ATF_REQUIRE(ilog2(0x0800000000000000ULL) == 59);
ATF_REQUIRE(ilog2(0x1000000000000000ULL) == 60);
ATF_REQUIRE(ilog2(0x2000000000000000ULL) == 61);
ATF_REQUIRE(ilog2(0x4000000000000000ULL) == 62);
ATF_REQUIRE(ilog2(0x8000000000000000ULL) == 63);
x = log2(i);
y = (double)(ilog2(i));
ATF_REQUIRE(ceil(x) >= y);
if (fabs(floor(x) - y) > 1.0e-40) {
atf_tc_expect_fail("PR misc/44767");
atf_tc_fail("log2(%"PRIu64") != "
"ilog2(%"PRIu64")", i, i);
}
}
#endif
ATF_REQUIRE(ilog2(0x0000000000000003ULL) == 1);
ATF_REQUIRE(ilog2(0x0000000000000007ULL) == 2);
ATF_REQUIRE(ilog2(0x000000000000000fULL) == 3);
ATF_REQUIRE(ilog2(0x000000000000001fULL) == 4);
ATF_REQUIRE(ilog2(0x000000000000003fULL) == 5);
ATF_REQUIRE(ilog2(0x000000000000007fULL) == 6);
ATF_REQUIRE(ilog2(0x00000000000000ffULL) == 7);
ATF_REQUIRE(ilog2(0x00000000000001ffULL) == 8);
ATF_REQUIRE(ilog2(0x00000000000003ffULL) == 9);
ATF_REQUIRE(ilog2(0x00000000000007ffULL) == 10);
ATF_REQUIRE(ilog2(0x0000000000000fffULL) == 11);
ATF_REQUIRE(ilog2(0x0000000000001fffULL) == 12);
ATF_REQUIRE(ilog2(0x0000000000003fffULL) == 13);
ATF_REQUIRE(ilog2(0x0000000000007fffULL) == 14);
ATF_REQUIRE(ilog2(0x000000000000ffffULL) == 15);
ATF_REQUIRE(ilog2(0x000000000001ffffULL) == 16);
ATF_REQUIRE(ilog2(0x000000000003ffffULL) == 17);
ATF_REQUIRE(ilog2(0x000000000007ffffULL) == 18);
ATF_REQUIRE(ilog2(0x00000000000fffffULL) == 19);
ATF_REQUIRE(ilog2(0x00000000001fffffULL) == 20);
ATF_REQUIRE(ilog2(0x00000000003fffffULL) == 21);
ATF_REQUIRE(ilog2(0x00000000007fffffULL) == 22);
ATF_REQUIRE(ilog2(0x0000000000ffffffULL) == 23);
ATF_REQUIRE(ilog2(0x0000000001ffffffULL) == 24);
ATF_REQUIRE(ilog2(0x0000000003ffffffULL) == 25);
ATF_REQUIRE(ilog2(0x0000000007ffffffULL) == 26);
ATF_REQUIRE(ilog2(0x000000000fffffffULL) == 27);
ATF_REQUIRE(ilog2(0x000000001fffffffULL) == 28);
ATF_REQUIRE(ilog2(0x000000003fffffffULL) == 29);
ATF_REQUIRE(ilog2(0x000000007fffffffULL) == 30);
ATF_REQUIRE(ilog2(0x00000000ffffffffULL) == 31);
ATF_REQUIRE(ilog2(0x00000001ffffffffULL) == 32);
ATF_REQUIRE(ilog2(0x00000003ffffffffULL) == 33);
ATF_REQUIRE(ilog2(0x00000007ffffffffULL) == 34);
ATF_REQUIRE(ilog2(0x0000000fffffffffULL) == 35);
ATF_REQUIRE(ilog2(0x0000001fffffffffULL) == 36);
ATF_REQUIRE(ilog2(0x0000003fffffffffULL) == 37);
ATF_REQUIRE(ilog2(0x0000007fffffffffULL) == 38);
ATF_REQUIRE(ilog2(0x000000ffffffffffULL) == 39);
ATF_REQUIRE(ilog2(0x000001ffffffffffULL) == 40);
ATF_REQUIRE(ilog2(0x000003ffffffffffULL) == 41);
ATF_REQUIRE(ilog2(0x000007ffffffffffULL) == 42);
ATF_REQUIRE(ilog2(0x00000fffffffffffULL) == 43);
ATF_REQUIRE(ilog2(0x00001fffffffffffULL) == 44);
ATF_REQUIRE(ilog2(0x00003fffffffffffULL) == 45);
ATF_REQUIRE(ilog2(0x00007fffffffffffULL) == 46);
ATF_REQUIRE(ilog2(0x0000ffffffffffffULL) == 47);
ATF_REQUIRE(ilog2(0x0001ffffffffffffULL) == 48);
ATF_REQUIRE(ilog2(0x0003ffffffffffffULL) == 49);
ATF_REQUIRE(ilog2(0x0007ffffffffffffULL) == 50);
ATF_REQUIRE(ilog2(0x000fffffffffffffULL) == 51);
ATF_REQUIRE(ilog2(0x001fffffffffffffULL) == 52);
ATF_REQUIRE(ilog2(0x003fffffffffffffULL) == 53);
ATF_REQUIRE(ilog2(0x007fffffffffffffULL) == 54);
ATF_REQUIRE(ilog2(0x00ffffffffffffffULL) == 55);
ATF_REQUIRE(ilog2(0x01ffffffffffffffULL) == 56);
ATF_REQUIRE(ilog2(0x03ffffffffffffffULL) == 57);
ATF_REQUIRE(ilog2(0x07ffffffffffffffULL) == 58);
ATF_REQUIRE(ilog2(0x0fffffffffffffffULL) == 59);
ATF_REQUIRE(ilog2(0x1fffffffffffffffULL) == 60);
ATF_REQUIRE(ilog2(0x3fffffffffffffffULL) == 61);
ATF_REQUIRE(ilog2(0x7fffffffffffffffULL) == 62);
ATF_REQUIRE(ilog2(0xffffffffffffffffULL) == 63);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, bitmap_basic);
ATF_TP_ADD_TC(tp, bitmap_basic);
ATF_TP_ADD_TC(tp, fast_divide32);
ATF_TP_ADD_TC(tp, ffsfls);
ATF_TP_ADD_TC(tp, ilog2_basic);
ATF_TP_ADD_TC(tp, ilog2_log2);
ATF_TP_ADD_TC(tp, ilog2_32bit);
ATF_TP_ADD_TC(tp, ilog2_64bit);
ATF_TP_ADD_TC(tp, ilog2_const);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_cdefs.c,v 1.3 2013/09/05 09:01:27 gsutre Exp $ */
/* $NetBSD: t_cdefs.c,v 1.4 2016/03/16 07:21:36 mrg Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_cdefs.c,v 1.3 2013/09/05 09:01:27 gsutre Exp $");
__RCSID("$NetBSD: t_cdefs.c,v 1.4 2016/03/16 07:21:36 mrg Exp $");
#include <atf-c.h>
#include <sys/types.h>
@ -180,34 +180,34 @@ ATF_TC_HEAD(stypefit, tc)
ATF_TC_BODY(stypefit, tc)
{
#define CHECK(a, b, c) ATF_REQUIRE(!__type_fit(a, b) == c)
#define CHECK(a, b, c) ATF_REQUIRE(__type_fit(a, b) == c)
CHECK(signed char, -1, 0);
CHECK(signed char, 1, 0);
CHECK(signed char, 0x7f, 0);
CHECK(signed char, 0x80, 1);
CHECK(signed char, 0xff, 1);
CHECK(signed char, 0x1ff, 1);
CHECK(signed char, -1, 1);
CHECK(signed char, 1, 1);
CHECK(signed char, 0x7f, 1);
CHECK(signed char, 0x80, 0);
CHECK(signed char, 0xff, 0);
CHECK(signed char, 0x1ff, 0);
CHECK(signed short, -1, 0);
CHECK(signed short, 1, 0);
CHECK(signed short, 0x7fff, 0);
CHECK(signed short, 0x8000, 1);
CHECK(signed short, 0xffff, 1);
CHECK(signed short, 0x1ffff, 1);
CHECK(signed short, -1, 1);
CHECK(signed short, 1, 1);
CHECK(signed short, 0x7fff, 1);
CHECK(signed short, 0x8000, 0);
CHECK(signed short, 0xffff, 0);
CHECK(signed short, 0x1ffff, 0);
CHECK(signed int, -1, 0);
CHECK(signed int, 1, 0);
CHECK(signed int, 0x7fffffff, 0);
CHECK(signed int, 0x80000000, 1);
CHECK(signed int, 0xffffffff, 1);
CHECK(signed int, 0x1ffffffffLL, 1);
CHECK(signed int, -1, 1);
CHECK(signed int, 1, 1);
CHECK(signed int, 0x7fffffff, 1);
CHECK(signed int, 0x80000000, 0);
CHECK(signed int, 0xffffffff, 0);
CHECK(signed int, 0x1ffffffffLL, 0);
CHECK(signed long long, -1, 0);
CHECK(signed long long, 1, 0);
CHECK(signed long long, 0x7fffffffffffffffLL, 0);
CHECK(signed long long, 0x8000000000000000LL, 1);
CHECK(signed long long, 0xffffffffffffffffLL, 1);
CHECK(signed long long, -1, 1);
CHECK(signed long long, 1, 1);
CHECK(signed long long, 0x7fffffffffffffffLL, 1);
CHECK(signed long long, 0x8000000000000000LL, 0);
CHECK(signed long long, 0xffffffffffffffffLL, 0);
#undef CHECK
}
@ -220,34 +220,34 @@ ATF_TC_HEAD(utypefit, tc)
ATF_TC_BODY(utypefit, tc)
{
#define CHECK(a, b, c) ATF_REQUIRE(!__type_fit(a, b) == c)
#define CHECK(a, b, c) ATF_REQUIRE(__type_fit(a, b) == c)
CHECK(unsigned char, -1, 1);
CHECK(unsigned char, 1, 0);
CHECK(unsigned char, 0x7f, 0);
CHECK(unsigned char, 0x80, 0);
CHECK(unsigned char, 0xff, 0);
CHECK(unsigned char, 0x1ff, 1);
CHECK(unsigned char, -1, 0);
CHECK(unsigned char, 1, 1);
CHECK(unsigned char, 0x7f, 1);
CHECK(unsigned char, 0x80, 1);
CHECK(unsigned char, 0xff, 1);
CHECK(unsigned char, 0x1ff, 0);
CHECK(unsigned short, -1, 1);
CHECK(unsigned short, 1, 0);
CHECK(unsigned short, 0x7fff, 0);
CHECK(unsigned short, 0x8000, 0);
CHECK(unsigned short, 0xffff, 0);
CHECK(unsigned short, 0x1ffff, 1);
CHECK(unsigned short, -1, 0);
CHECK(unsigned short, 1, 1);
CHECK(unsigned short, 0x7fff, 1);
CHECK(unsigned short, 0x8000, 1);
CHECK(unsigned short, 0xffff, 1);
CHECK(unsigned short, 0x1ffff, 0);
CHECK(unsigned int, -1, 1);
CHECK(unsigned int, 1, 0);
CHECK(unsigned int, 0x7fffffff, 0);
CHECK(unsigned int, 0x80000000, 0);
CHECK(unsigned int, 0xffffffff, 0);
CHECK(unsigned int, 0x1ffffffffLL, 1);
CHECK(unsigned int, -1, 0);
CHECK(unsigned int, 1, 1);
CHECK(unsigned int, 0x7fffffff, 1);
CHECK(unsigned int, 0x80000000, 1);
CHECK(unsigned int, 0xffffffff, 1);
CHECK(unsigned int, 0x1ffffffffLL, 0);
CHECK(unsigned long long, -1, 1);
CHECK(unsigned long long, 1, 0);
CHECK(unsigned long long, 0x7fffffffffffffffULL, 0);
CHECK(unsigned long long, 0x8000000000000000ULL, 0);
CHECK(unsigned long long, 0xffffffffffffffffULL, 0);
CHECK(unsigned long long, -1, 0);
CHECK(unsigned long long, 1, 1);
CHECK(unsigned long long, 0x7fffffffffffffffULL, 1);
CHECK(unsigned long long, 0x8000000000000000ULL, 1);
CHECK(unsigned long long, 0xffffffffffffffffULL, 1);
#undef CHECK
}

View file

@ -0,0 +1,125 @@
/* $NetBSD: t_pslist.c,v 1.1 2016/04/09 04:39:47 riastradh Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Taylor R. Campbell.
*
* 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/pslist.h>
#include <atf-c.h>
/*
* XXX This is a limited test to make sure the operations behave as
* described on a sequential machine. It does nothing to test the
* pserialize-safety of any operations.
*/
ATF_TC(misc);
ATF_TC_HEAD(misc, tc)
{
atf_tc_set_md_var(tc, "descr", "pserialize-safe list tests");
}
ATF_TC_BODY(misc, tc)
{
struct pslist_head h = PSLIST_INITIALIZER;
struct element {
unsigned i;
struct pslist_entry entry;
} elements[] = {
{ .i = 0, .entry = PSLIST_ENTRY_INITIALIZER },
{ .i = 1 },
{ .i = 2 },
{ .i = 3 },
{ .i = 4 },
{ .i = 5 },
{ .i = 6 },
{ .i = 7 },
};
struct element *element;
unsigned i;
/* Check PSLIST_INITIALIZER is destroyable. */
PSLIST_DESTROY(&h);
PSLIST_INIT(&h);
/* Check PSLIST_ENTRY_INITIALIZER is destroyable. */
PSLIST_ENTRY_DESTROY(&elements[0], entry);
for (i = 0; i < __arraycount(elements); i++)
PSLIST_ENTRY_INIT(&elements[i], entry);
PSLIST_WRITER_INSERT_HEAD(&h, &elements[4], entry);
PSLIST_WRITER_INSERT_BEFORE(&elements[4], &elements[2], entry);
PSLIST_WRITER_INSERT_BEFORE(&elements[4], &elements[3], entry);
PSLIST_WRITER_INSERT_BEFORE(&elements[2], &elements[1], entry);
PSLIST_WRITER_INSERT_HEAD(&h, &elements[0], entry);
PSLIST_WRITER_INSERT_AFTER(&elements[4], &elements[5], entry);
PSLIST_WRITER_INSERT_AFTER(&elements[5], &elements[7], entry);
PSLIST_WRITER_INSERT_AFTER(&elements[5], &elements[6], entry);
PSLIST_WRITER_REMOVE(&elements[0], entry);
ATF_CHECK(elements[0].entry.ple_next != NULL);
PSLIST_ENTRY_DESTROY(&elements[0], entry);
PSLIST_WRITER_REMOVE(&elements[4], entry);
ATF_CHECK(elements[4].entry.ple_next != NULL);
PSLIST_ENTRY_DESTROY(&elements[4], entry);
PSLIST_ENTRY_INIT(&elements[0], entry);
PSLIST_WRITER_INSERT_HEAD(&h, &elements[0], entry);
PSLIST_ENTRY_INIT(&elements[4], entry);
PSLIST_WRITER_INSERT_AFTER(&elements[3], &elements[4], entry);
i = 0;
PSLIST_WRITER_FOREACH(element, &h, struct element, entry) {
ATF_CHECK_EQ(i, element->i);
i++;
}
i = 0;
PSLIST_READER_FOREACH(element, &h, struct element, entry) {
ATF_CHECK_EQ(i, element->i);
i++;
}
while ((element = PSLIST_WRITER_FIRST(&h, struct element, entry))
!= NULL) {
PSLIST_WRITER_REMOVE(element, entry);
PSLIST_ENTRY_DESTROY(element, entry);
}
PSLIST_DESTROY(&h);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, misc);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_socket.c,v 1.3 2013/10/19 17:45:00 christos Exp $ */
/* $NetBSD: t_socket.c,v 1.4 2015/02/27 08:30:30 martin Exp $ */
#include <sys/types.h>
#include <sys/mount.h>
@ -74,7 +74,7 @@ ATF_TC(cmsg_sendfd);
ATF_TC_HEAD(cmsg_sendfd, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks that fd passing works");
atf_tc_set_md_var(tc, "timeout", "2");
atf_tc_set_md_var(tc, "timeout", "10");
}
ATF_TC_BODY(cmsg_sendfd, tc)

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_paths.c,v 1.14 2014/11/04 00:20:19 justin Exp $ */
/* $NetBSD: t_paths.c,v 1.16 2015/05/07 06:23:23 pgoyette Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_paths.c,v 1.14 2014/11/04 00:20:19 justin Exp $");
__RCSID("$NetBSD: t_paths.c,v 1.16 2015/05/07 06:23:23 pgoyette Exp $");
#include <sys/param.h>
#include <sys/stat.h>
@ -47,6 +47,7 @@ __RCSID("$NetBSD: t_paths.c,v 1.14 2014/11/04 00:20:19 justin Exp $");
#define PATH_DIR __BIT(1) /* A directory */
#define PATH_FILE __BIT(2) /* A file */
#define PATH_ROOT __BIT(3) /* Access for root only */
#define PATH_OPT __BIT(3) /* Optional, ENODEV if not supported */
static const struct {
const char *path;
@ -82,7 +83,7 @@ static const struct {
{ _PATH_MIXER, PATH_DEV },
{ _PATH_MIXER0, PATH_DEV },
{ _PATH_NOLOGIN, PATH_FILE },
{ _PATH_POWER, PATH_DEV | PATH_ROOT },
{ _PATH_POWER, PATH_DEV | PATH_ROOT | PATH_OPT },
{ _PATH_PRINTCAP, PATH_FILE },
{ _PATH_PUD, PATH_DEV | PATH_ROOT },
{ _PATH_PUFFS, PATH_DEV | PATH_ROOT },
@ -92,12 +93,13 @@ static const struct {
{ _PATH_SKEYKEYS, PATH_FILE | PATH_ROOT },
{ _PATH_SOUND, PATH_DEV },
{ _PATH_SOUND0, PATH_DEV },
{ _PATH_SYSMON, PATH_DEV },
{ _PATH_SYSMON, PATH_DEV | PATH_OPT },
{ _PATH_TTY, PATH_DEV },
{ _PATH_UNIX, PATH_FILE | PATH_ROOT },
{ _PATH_URANDOM, PATH_DEV },
{ _PATH_VIDEO, PATH_DEV },
{ _PATH_VIDEO0, PATH_DEV },
{ _PATH_WATCHDOG, PATH_DEV | PATH_OPT },
{ _PATH_DEV, PATH_DIR },
{ _PATH_DEV_PTS, PATH_DIR },
@ -143,13 +145,22 @@ ATF_TC_BODY(paths, tc)
switch (errno) {
case ENODEV:
if ((paths[i].flags & PATH_OPT) == 0) {
atf_tc_fail("Required path %s does "
"not exist", paths[i].path);
}
break;
case EPERM: /* FALLTHROUGH */
case EACCES: /* FALLTHROUGH */
if ((paths[i].flags & PATH_ROOT) == 0) {
atf_tc_fail("UID %u failed to open %s",
(uint32_t)uid, paths[i].path);
atf_tc_fail("UID %u failed to open %s, "
"error %d", (uint32_t)uid,
paths[i].path, errno);
}
case EBUSY: /* FALLTHROUGH */

View file

@ -11,9 +11,9 @@ RDR 10.1.1.253 80 <- -> 203.1.1.1 80 [10.2.2.6 2000]
RDR 10.1.1.254 80 <- -> 203.1.1.1 80 [10.2.2.5 2000]
Hostmap table:
10.2.2.7,203.1.1.1 -> 254.1.1.10,0.0.0.0 (use = 1)
10.2.2.6,203.1.1.1 -> 253.1.1.10,0.0.0.0 (use = 1)
10.2.2.5,203.1.1.1 -> 254.1.1.10,0.0.0.0 (use = 1)
10.2.2.7,203.1.1.1 -> 10.1.1.254,0.0.0.0 (use = 1)
10.2.2.6,203.1.1.1 -> 10.1.1.253,0.0.0.0 (use = 1)
10.2.2.5,203.1.1.1 -> 10.1.1.254,0.0.0.0 (use = 1)
List of active state sessions:
List of configured pools
List of configured hash tables

View file

@ -11,9 +11,9 @@ RDR 10:1:1::253 80 <- -> 203:0:1::1:1 80 [10::2:2:6 2000]
RDR 10:1:1::254 80 <- -> 203:0:1::1:1 80 [10::2:2:5 2000]
Hostmap table:
10::2:2:7,203:0:1:0:0:0:1:1 -> 254:1:1::10,any (use = 1)
10::2:2:6,203:0:1:0:0:0:1:1 -> 253:0:1:0:0:0:1:10,any (use = 1)
10::2:2:5,203:0:1:0:0:0:1:1 -> 254:1:1::10,any (use = 3)
10::2:2:7,203:0:1:0:0:0:1:1 -> 10:1:1::254,any (use = 1)
10::2:2:6,203:0:1:0:0:0:1:1 -> 10:0:1:0:0:0:1:253,any (use = 1)
10::2:2:5,203:0:1:0:0:0:1:1 -> 10:1:1::254,any (use = 3)
List of active state sessions:
List of configured pools
List of configured hash tables

View file

@ -1,4 +1,4 @@
# $NetBSD: t_filter_parse.sh,v 1.11 2014/06/29 09:27:58 darrenr Exp $
# $NetBSD: t_filter_parse.sh,v 1.12 2014/12/06 19:31:25 dholland Exp $
#
# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@ -133,3 +133,4 @@ atf_init_test_cases()
atf_add_test_case i22
atf_add_test_case i23
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_nat_exec.sh,v 1.20 2014/07/15 20:00:23 martin Exp $
# $NetBSD: t_nat_exec.sh,v 1.22 2015/12/26 08:01:58 pgoyette Exp $
#
# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@ -71,9 +71,9 @@ test_case n8 nattest hex hex -T update_ipid=0
test_case n9 nattest hex hex -T update_ipid=0
test_case n10 nattest hex hex -T update_ipid=0
test_case n11 nattest text text
failing_test_case n12 nattest "Known to be broken" hex hex -T update_ipid=0 -v
test_case n12 nattest hex hex -T update_ipid=0
test_case n13 nattest text text
failing_test_case_be n14 nattest "See PR kern/47665" text text
test_case n14 nattest text text
test_case n15 nattest text text -T update_ipid=0
test_case n16 nattest hex hex -D
test_case n17 nattest hex hex -D

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_ioctl.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */
/* $NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
/*-
* Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_ioctl.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $");
__RCSID("$NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $");
#include <sys/event.h>
#include <sys/ioctl.h>
@ -53,7 +53,8 @@ ATF_TC_BODY(kfilter_byfilter, tc)
{
char buf[32];
struct kfilter_mapping km;
int i, kq;
int kq;
uint32_t i;
RL(kq = kqueue());

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_proc1.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */
/* $NetBSD: t_proc1.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
/*-
* Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_proc1.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $");
__RCSID("$NetBSD: t_proc1.c,v 1.2 2015/01/14 22:22:32 christos Exp $");
/*
* this also used to trigger problem fixed in
@ -99,7 +99,8 @@ ATF_TC_BODY(proc1, tc)
{
struct kevent event[1];
pid_t pid;
int kq, want, status;
int kq, status;
u_int want;
RL(kq = kqueue());
@ -112,7 +113,7 @@ ATF_TC_BODY(proc1, tc)
(void)sleep(1); /* give child some time to come up */
event[0].ident = pid;
event[0].ident = (uintptr_t)pid;
event[0].filter = EVFILT_PROC;
event[0].flags = EV_ADD | EV_ENABLE;
event[0].fflags = NOTE_EXIT | NOTE_FORK | NOTE_EXEC; /* | NOTE_TRACK;*/

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_proc2.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */
/* $NetBSD: t_proc2.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_proc2.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $");
__RCSID("$NetBSD: t_proc2.c,v 1.2 2015/01/14 22:22:32 christos Exp $");
#include <sys/event.h>
#include <sys/time.h>
@ -106,7 +106,8 @@ ATF_TC_BODY(proc2, tc)
/* NOTREACHED */
}
EV_SET(&ke, pid, EVFILT_PROC, EV_ADD, NOTE_FORK|NOTE_TRACK, 0, 0);
EV_SET(&ke, (uintptr_t)pid, EVFILT_PROC, EV_ADD, NOTE_FORK|NOTE_TRACK,
0, 0);
RL(kevent(kq, &ke, 1, NULL, 0, &timeout));

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_proc3.c,v 1.1 2012/11/17 21:55:24 joerg Exp $ */
/* $NetBSD: t_proc3.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_proc3.c,v 1.1 2012/11/17 21:55:24 joerg Exp $");
__RCSID("$NetBSD: t_proc3.c,v 1.2 2015/01/14 22:22:32 christos Exp $");
#include <sys/event.h>
#include <sys/time.h>
@ -63,7 +63,7 @@ ATF_TC_BODY(proc3, tc)
RL(kq = kqueue());
EV_SET(&ke, getpid(), EVFILT_PROC, EV_ADD, NOTE_TRACK, 0, 0);
EV_SET(&ke, (uintptr_t)getpid(), EVFILT_PROC, EV_ADD, NOTE_TRACK, 0, 0);
RL(kevent(kq, &ke, 1, NULL, 0, NULL));

View file

@ -0,0 +1,533 @@
#include <sys/event.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <atf-c.h>
/*
* Test cases for events triggered by manipulating a target directory
* content. Using EVFILT_VNODE filter on the target directory descriptor.
*
*/
static const char *dir_target = "foo";
static const char *dir_inside1 = "foo/bar1";
static const char *dir_inside2 = "foo/bar2";
static const char *dir_outside = "bar";
static const char *file_inside1 = "foo/baz1";
static const char *file_inside2 = "foo/baz2";
static const char *file_outside = "qux";
static const struct timespec ts = {0, 0};
static int kq = -1;
static int target = -1;
int init_target(void);
int init_kqueue(void);
int create_file(const char *);
void cleanup(void);
int
init_target(void)
{
if (mkdir(dir_target, S_IRWXU) < 0) {
return -1;
}
target = open(dir_target, O_RDONLY, 0);
return target;
}
int
init_kqueue(void)
{
struct kevent eventlist[1];
kq = kqueue();
if (kq < 0) {
return -1;
}
EV_SET(&eventlist[0], (uintptr_t)target, EVFILT_VNODE,
EV_ADD | EV_ONESHOT, NOTE_DELETE |
NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB |
NOTE_LINK | NOTE_RENAME | NOTE_REVOKE, 0, 0);
return kevent(kq, eventlist, 1, NULL, 0, NULL);
}
int
create_file(const char *file)
{
int fd;
fd = open(file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if (fd < 0) {
return -1;
}
return close(fd);
}
void
cleanup(void)
{
(void)unlink(file_inside1);
(void)unlink(file_inside2);
(void)unlink(file_outside);
(void)rmdir(dir_inside1);
(void)rmdir(dir_inside2);
(void)rmdir(dir_outside);
(void)rmdir(dir_target);
(void)close(kq);
(void)close(target);
}
ATF_TC_WITH_CLEANUP(dir_no_note_link_create_file_in);
ATF_TC_HEAD(dir_no_note_link_create_file_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) does not return NOTE_LINK for the directory "
"'foo' if a file 'foo/baz' is created.");
}
ATF_TC_BODY(dir_no_note_link_create_file_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(create_file(file_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0);
}
ATF_TC_CLEANUP(dir_no_note_link_create_file_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_no_note_link_delete_file_in);
ATF_TC_HEAD(dir_no_note_link_delete_file_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) does not return NOTE_LINK for the directory "
"'foo' if a file 'foo/baz' is deleted.");
}
ATF_TC_BODY(dir_no_note_link_delete_file_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(create_file(file_inside1) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(unlink(file_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0);
}
ATF_TC_CLEANUP(dir_no_note_link_delete_file_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_no_note_link_mv_dir_within);
ATF_TC_HEAD(dir_no_note_link_mv_dir_within, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) does not return NOTE_LINK for the directory "
"'foo' if a directory 'foo/bar' is renamed to 'foo/baz'.");
}
ATF_TC_BODY(dir_no_note_link_mv_dir_within, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(dir_inside1, dir_inside2) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0);
}
ATF_TC_CLEANUP(dir_no_note_link_mv_dir_within, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_no_note_link_mv_file_within);
ATF_TC_HEAD(dir_no_note_link_mv_file_within, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) does not return NOTE_LINK for the directory "
"'foo' if a file 'foo/baz' is renamed to 'foo/qux'.");
}
ATF_TC_BODY(dir_no_note_link_mv_file_within, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(create_file(file_inside1) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(file_inside1, file_inside2) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, 0);
}
ATF_TC_CLEANUP(dir_no_note_link_mv_file_within, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_link_create_dir_in);
ATF_TC_HEAD(dir_note_link_create_dir_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_LINK for the directory "
"'foo' if a directory 'foo/bar' is created.");
}
ATF_TC_BODY(dir_note_link_create_dir_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK);
}
ATF_TC_CLEANUP(dir_note_link_create_dir_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_link_delete_dir_in);
ATF_TC_HEAD(dir_note_link_delete_dir_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_LINK for the directory "
"'foo' if a directory 'foo/bar' is deleted.");
}
ATF_TC_BODY(dir_note_link_delete_dir_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rmdir(dir_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK);
}
ATF_TC_CLEANUP(dir_note_link_delete_dir_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_link_mv_dir_in);
ATF_TC_HEAD(dir_note_link_mv_dir_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_LINK for the directory "
"'foo' if a directory 'bar' is renamed to 'foo/bar'.");
}
ATF_TC_BODY(dir_note_link_mv_dir_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_outside, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(dir_outside, dir_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK);
}
ATF_TC_CLEANUP(dir_note_link_mv_dir_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_link_mv_dir_out);
ATF_TC_HEAD(dir_note_link_mv_dir_out, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_LINK for the directory "
"'foo' if a directory 'foo/bar' is renamed to 'bar'.");
}
ATF_TC_BODY(dir_note_link_mv_dir_out, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(dir_inside1, dir_outside) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_LINK, NOTE_LINK);
}
ATF_TC_CLEANUP(dir_note_link_mv_dir_out, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_create_dir_in);
ATF_TC_HEAD(dir_note_write_create_dir_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a directory 'foo/bar' is created.");
}
ATF_TC_BODY(dir_note_write_create_dir_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_create_dir_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_create_file_in);
ATF_TC_HEAD(dir_note_write_create_file_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a file 'foo/baz' is created.");
}
ATF_TC_BODY(dir_note_write_create_file_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(create_file(file_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_create_file_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_delete_dir_in);
ATF_TC_HEAD(dir_note_write_delete_dir_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a directory 'foo/bar' is deleted.");
}
ATF_TC_BODY(dir_note_write_delete_dir_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rmdir(dir_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_delete_dir_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_delete_file_in);
ATF_TC_HEAD(dir_note_write_delete_file_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a file 'foo/baz' is deleted.");
}
ATF_TC_BODY(dir_note_write_delete_file_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(create_file(file_inside1) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(unlink(file_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_delete_file_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_mv_dir_in);
ATF_TC_HEAD(dir_note_write_mv_dir_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a directory 'bar' is renamed to 'foo/bar'.");
}
ATF_TC_BODY(dir_note_write_mv_dir_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_outside, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(dir_outside, dir_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_mv_dir_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_mv_dir_out);
ATF_TC_HEAD(dir_note_write_mv_dir_out, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a directory 'foo/bar' is renamed to 'bar'.");
}
ATF_TC_BODY(dir_note_write_mv_dir_out, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(dir_inside1, dir_outside) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_mv_dir_out, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_mv_dir_within);
ATF_TC_HEAD(dir_note_write_mv_dir_within, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a directory 'foo/bar' is renamed to 'foo/baz'.");
}
ATF_TC_BODY(dir_note_write_mv_dir_within, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(dir_inside1, dir_inside2) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_mv_dir_within, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_mv_file_in);
ATF_TC_HEAD(dir_note_write_mv_file_in, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a file 'qux' is renamed to 'foo/baz'.");
}
ATF_TC_BODY(dir_note_write_mv_file_in, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(create_file(file_outside) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(file_outside, file_inside1) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_mv_file_in, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_mv_file_out);
ATF_TC_HEAD(dir_note_write_mv_file_out, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a file 'foo/baz' is renamed to 'qux'.");
}
ATF_TC_BODY(dir_note_write_mv_file_out, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(create_file(file_inside1) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(file_inside1, file_outside) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_mv_file_out, tc)
{
cleanup();
}
ATF_TC_WITH_CLEANUP(dir_note_write_mv_file_within);
ATF_TC_HEAD(dir_note_write_mv_file_within, tc)
{
atf_tc_set_md_var(tc, "descr", "This test case ensures "
"that kevent(2) returns NOTE_WRITE for the directory "
"'foo' if a file 'foo/baz' is renamed to 'foo/qux'.");
}
ATF_TC_BODY(dir_note_write_mv_file_within, tc)
{
struct kevent changelist[1];
ATF_REQUIRE(init_target() != -1);
ATF_REQUIRE(create_file(file_inside1) != -1);
ATF_REQUIRE(init_kqueue() != -1);
ATF_REQUIRE(rename(file_inside1, file_inside2) != -1);
ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, &ts) != -1);
ATF_CHECK_EQ(changelist[0].fflags & NOTE_WRITE, NOTE_WRITE);
}
ATF_TC_CLEANUP(dir_note_write_mv_file_within, tc)
{
cleanup();
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, dir_no_note_link_create_file_in);
ATF_TP_ADD_TC(tp, dir_no_note_link_delete_file_in);
ATF_TP_ADD_TC(tp, dir_no_note_link_mv_dir_within);
ATF_TP_ADD_TC(tp, dir_no_note_link_mv_file_within);
ATF_TP_ADD_TC(tp, dir_note_link_create_dir_in);
ATF_TP_ADD_TC(tp, dir_note_link_delete_dir_in);
ATF_TP_ADD_TC(tp, dir_note_link_mv_dir_in);
ATF_TP_ADD_TC(tp, dir_note_link_mv_dir_out);
ATF_TP_ADD_TC(tp, dir_note_write_create_dir_in);
ATF_TP_ADD_TC(tp, dir_note_write_create_file_in);
ATF_TP_ADD_TC(tp, dir_note_write_delete_dir_in);
ATF_TP_ADD_TC(tp, dir_note_write_delete_file_in);
ATF_TP_ADD_TC(tp, dir_note_write_mv_dir_in);
ATF_TP_ADD_TC(tp, dir_note_write_mv_dir_out);
ATF_TP_ADD_TC(tp, dir_note_write_mv_dir_within);
ATF_TP_ADD_TC(tp, dir_note_write_mv_file_in);
ATF_TP_ADD_TC(tp, dir_note_write_mv_file_out);
ATF_TP_ADD_TC(tp, dir_note_write_mv_file_within);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_rnd.c,v 1.5 2012/03/18 09:46:50 jruoho Exp $ */
/* $NetBSD: t_rnd.c,v 1.9 2016/05/22 04:34:44 riastradh Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -27,12 +27,12 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_rnd.c,v 1.5 2012/03/18 09:46:50 jruoho Exp $");
__RCSID("$NetBSD: t_rnd.c,v 1.9 2016/05/22 04:34:44 riastradh Exp $");
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <sys/rnd.h>
#include <sys/rndio.h>
#include <atf-c.h>
@ -86,10 +86,29 @@ ATF_TC_BODY(RNDADDDATA2, tc)
ATF_REQUIRE_ERRNO(EINVAL, rump_sys_ioctl(fd, RNDADDDATA, &rd) == -1);
}
ATF_TC(read_random);
ATF_TC_HEAD(read_random, tc)
{
atf_tc_set_md_var(tc, "descr", "does reading /dev/random return "
"within reasonable time");
atf_tc_set_md_var(tc, "timeout", "10");
}
ATF_TC_BODY(read_random, tc)
{
char buf[128];
int fd;
rump_init();
RL(fd = rump_sys_open("/dev/random", O_RDONLY));
RL(rump_sys_read(fd, buf, sizeof(buf)));
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, RNDADDDATA);
ATF_TP_ADD_TC(tp, RNDADDDATA2);
ATF_TP_ADD_TC(tp, read_random);
return atf_no_error();
}

View file

@ -1,7 +1,7 @@
/* $NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $ */
/* $NetBSD: t_bpfjit.c,v 1.14 2015/02/14 22:40:18 alnsn Exp $ */
/*-
* Copyright (c) 2011-2012, 2014 Alexander Nasonov.
* Copyright (c) 2011-2012, 2014-2015 Alexander Nasonov.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $");
__RCSID("$NetBSD: t_bpfjit.c,v 1.14 2015/02/14 22:40:18 alnsn Exp $");
#include <atf-c.h>
#include <stdint.h>
@ -67,9 +67,75 @@ ATF_TC_BODY(libbpfjit_empty, tc)
{
struct bpf_insn dummy;
ATF_CHECK(!bpf_validate(&dummy, 0));
ATF_CHECK(bpfjit_generate_code(NULL, &dummy, 0) == NULL);
}
ATF_TC(libbpfjit_ret_k);
ATF_TC_HEAD(libbpfjit_ret_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of a trivial bpf program");
}
ATF_TC_BODY(libbpfjit_ret_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_RET+BPF_K, 17)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 17);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_bad_ret_k);
ATF_TC_HEAD(libbpfjit_bad_ret_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that JIT compilation of a program with bad BPF_RET fails");
}
ATF_TC_BODY(libbpfjit_bad_ret_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_RET+BPF_K+0x8000, 13)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
/*
* The point of this test is checking a bad instruction of
* a valid class and with a valid BPF_RVAL data.
*/
const uint16_t rcode = insns[0].code;
ATF_CHECK(BPF_CLASS(rcode) == BPF_RET &&
(BPF_RVAL(rcode) == BPF_K || BPF_RVAL(rcode) == BPF_A));
ATF_CHECK(!bpf_validate(insns, insn_count));
/* Current implementation generates code. */
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 13);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_add_k);
ATF_TC_HEAD(libbpfjit_alu_add_k, tc)
{
@ -399,6 +465,245 @@ ATF_TC_BODY(libbpfjit_alu_div80000000_k, tc)
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod0_k);
ATF_TC_HEAD(libbpfjit_alu_mod0_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0");
}
ATF_TC_BODY(libbpfjit_alu_mod0_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
//ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod1_k);
ATF_TC_HEAD(libbpfjit_alu_mod1_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=1");
}
ATF_TC_BODY(libbpfjit_alu_mod1_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, 7),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 1),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod2_k);
ATF_TC_HEAD(libbpfjit_alu_mod2_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=2");
}
ATF_TC_BODY(libbpfjit_alu_mod2_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, 7),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 2),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 1);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod4_k);
ATF_TC_HEAD(libbpfjit_alu_mod4_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=4");
}
ATF_TC_BODY(libbpfjit_alu_mod4_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 4),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 3);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod10_k);
ATF_TC_HEAD(libbpfjit_alu_mod10_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10");
}
ATF_TC_BODY(libbpfjit_alu_mod10_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 9);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod10000_k);
ATF_TC_HEAD(libbpfjit_alu_mod10000_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10000");
}
ATF_TC_BODY(libbpfjit_alu_mod10000_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10000),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 3849);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod7609801_k);
ATF_TC_HEAD(libbpfjit_alu_mod7609801_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_mod+BPF_K with k=7609801");
}
ATF_TC_BODY(libbpfjit_alu_mod7609801_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294967295)),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, UINT32_C(7609801)),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(3039531));
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod80000000_k);
ATF_TC_HEAD(libbpfjit_alu_mod80000000_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0x80000000");
}
ATF_TC_BODY(libbpfjit_alu_mod80000000_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, UINT32_C(0x80000000)),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(0x7fffffde));
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_and_k);
ATF_TC_HEAD(libbpfjit_alu_and_k, tc)
{
@ -459,6 +764,36 @@ ATF_TC_BODY(libbpfjit_alu_or_k, tc)
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_xor_k);
ATF_TC_HEAD(libbpfjit_alu_xor_k, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_XOR+BPF_K");
}
ATF_TC_BODY(libbpfjit_alu_xor_k, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
BPF_STMT(BPF_ALU+BPF_XOR+BPF_K, 0x0000b1e0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 0xdeadbeef);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_lsh_k);
ATF_TC_HEAD(libbpfjit_alu_lsh_k, tc)
{
@ -962,7 +1297,7 @@ ATF_TC_HEAD(libbpfjit_alu_div80000000_x, tc)
ATF_TC_BODY(libbpfjit_alu_div80000000_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_MAX - 33),
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0x80000000)),
BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
@ -983,6 +1318,253 @@ ATF_TC_BODY(libbpfjit_alu_div80000000_x, tc)
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod0_x);
ATF_TC_HEAD(libbpfjit_alu_mod0_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=0");
}
ATF_TC_BODY(libbpfjit_alu_mod0_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod1_x);
ATF_TC_HEAD(libbpfjit_alu_mod1_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=1");
}
ATF_TC_BODY(libbpfjit_alu_mod1_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, 7),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod2_x);
ATF_TC_HEAD(libbpfjit_alu_mod2_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=2");
}
ATF_TC_BODY(libbpfjit_alu_mod2_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, 7),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 1);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod4_x);
ATF_TC_HEAD(libbpfjit_alu_mod4_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=4");
}
ATF_TC_BODY(libbpfjit_alu_mod4_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 4),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 3);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod10_x);
ATF_TC_HEAD(libbpfjit_alu_mod10_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=10");
}
ATF_TC_BODY(libbpfjit_alu_mod10_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 10),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 9);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod10000_x);
ATF_TC_HEAD(libbpfjit_alu_mod10000_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=10000");
}
ATF_TC_BODY(libbpfjit_alu_mod10000_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 10000),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 3849);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod7609801_x);
ATF_TC_HEAD(libbpfjit_alu_mod7609801_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=7609801");
}
ATF_TC_BODY(libbpfjit_alu_mod7609801_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294967295)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(7609801)),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(3039531));
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_mod80000000_x);
ATF_TC_HEAD(libbpfjit_alu_mod80000000_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=0x80000000");
}
ATF_TC_BODY(libbpfjit_alu_mod80000000_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0x80000000)),
BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == UINT32_C(0x7fffffde));
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_and_x);
ATF_TC_HEAD(libbpfjit_alu_and_x, tc)
{
@ -1045,6 +1627,37 @@ ATF_TC_BODY(libbpfjit_alu_or_x, tc)
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_xor_x);
ATF_TC_HEAD(libbpfjit_alu_xor_x, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test JIT compilation of BPF_ALU+BPF_XOR+BPF_X");
}
ATF_TC_BODY(libbpfjit_alu_xor_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0x0000b1e0),
BPF_STMT(BPF_ALU+BPF_XOR+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
};
bpfjit_func_t code;
uint8_t pkt[1]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 0xdeadbeef);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_alu_lsh_x);
ATF_TC_HEAD(libbpfjit_alu_lsh_x, tc)
{
@ -1305,6 +1918,54 @@ ATF_TC_BODY(libbpfjit_jmp_ja, tc)
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_jmp_ja_invalid);
ATF_TC_HEAD(libbpfjit_jmp_ja_invalid, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test BPF_JMP+BPF_JA to invalid destination");
}
ATF_TC_BODY(libbpfjit_jmp_ja_invalid, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_JMP+BPF_JA, 4),
BPF_STMT(BPF_RET+BPF_K, 0),
BPF_STMT(BPF_RET+BPF_K, 1),
BPF_STMT(BPF_RET+BPF_K, 2),
BPF_STMT(BPF_RET+BPF_K, 3),
};
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(!bpf_validate(insns, insn_count));
ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
}
ATF_TC(libbpfjit_jmp_ja_overflow);
ATF_TC_HEAD(libbpfjit_jmp_ja_overflow, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test BPF_JMP+BPF_JA with negative offset");
}
ATF_TC_BODY(libbpfjit_jmp_ja_overflow, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_JMP+BPF_JA, 1),
BPF_STMT(BPF_RET+BPF_K, 777),
BPF_STMT(BPF_JMP+BPF_JA, UINT32_MAX - 1), // -2
BPF_STMT(BPF_RET+BPF_K, 0)
};
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
/* Jumps with negative offsets work in userspace ... */
ATF_CHECK(bpf_validate(insns, insn_count));
/* .. but not for bpfjit. */
ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
}
ATF_TC(libbpfjit_jmp_jgt_k);
ATF_TC_HEAD(libbpfjit_jmp_jgt_k, tc)
{
@ -1693,26 +2354,26 @@ ATF_TC_BODY(libbpfjit_jmp_jeq_x, tc)
BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 8),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
BPF_STMT(BPF_RET+BPF_K, 0),
BPF_STMT(BPF_RET+BPF_K, 1),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 0),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 9),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
BPF_STMT(BPF_RET+BPF_K, 1),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
BPF_STMT(BPF_RET+BPF_K, 2),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
BPF_STMT(BPF_RET+BPF_K, 3),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 7),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 3),
BPF_STMT(BPF_RET+BPF_K, 3),
BPF_STMT(BPF_RET+BPF_K, 4),
BPF_STMT(BPF_RET+BPF_K, 5),
BPF_STMT(BPF_RET+BPF_K, 6),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 6),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 3, 1),
BPF_STMT(BPF_RET+BPF_K, 6),
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 1, 0, 0),
BPF_STMT(BPF_RET+BPF_K, 7),
BPF_STMT(BPF_RET+BPF_K, 8)
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 0),
BPF_STMT(BPF_RET+BPF_K, 8),
BPF_STMT(BPF_RET+BPF_K, 9)
};
bpfjit_func_t code;
@ -1725,14 +2386,14 @@ ATF_TC_BODY(libbpfjit_jmp_jeq_x, tc)
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 7);
ATF_CHECK(jitcall(code, pkt, 2, 2) == 7);
ATF_CHECK(jitcall(code, pkt, 3, 3) == 1);
ATF_CHECK(jitcall(code, pkt, 4, 4) == 7);
ATF_CHECK(jitcall(code, pkt, 5, 5) == 7);
ATF_CHECK(jitcall(code, pkt, 6, 6) == 8);
ATF_CHECK(jitcall(code, pkt, 7, 7) == 5);
ATF_CHECK(jitcall(code, pkt, 8, 8) == 0);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 8);
ATF_CHECK(jitcall(code, pkt, 2, 2) == 8);
ATF_CHECK(jitcall(code, pkt, 3, 3) == 2);
ATF_CHECK(jitcall(code, pkt, 4, 4) == 8);
ATF_CHECK(jitcall(code, pkt, 5, 5) == 3);
ATF_CHECK(jitcall(code, pkt, 6, 6) == 9);
ATF_CHECK(jitcall(code, pkt, 7, 7) == 6);
ATF_CHECK(jitcall(code, pkt, 8, 8) == 1);
bpfjit_free_code(code);
}
@ -1794,6 +2455,98 @@ ATF_TC_BODY(libbpfjit_jmp_jset_x, tc)
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_jmp_jeq_x_noinit_ax);
ATF_TC_HEAD(libbpfjit_jmp_jeq_x_noinit_ax, tc)
{
atf_tc_set_md_var(tc, "descr", "Test JIT compilation "
"of BPF_JMP+BPF_EQ+BPF_X with uninitialised A and X");
}
ATF_TC_BODY(libbpfjit_jmp_jeq_x_noinit_ax, tc)
{
static struct bpf_insn insns[] = {
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
BPF_STMT(BPF_RET+BPF_K, 10),
BPF_STMT(BPF_RET+BPF_K, 11)
};
bpfjit_func_t code;
uint8_t pkt[8]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 10);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_jmp_jeq_x_noinit_a);
ATF_TC_HEAD(libbpfjit_jmp_jeq_x_noinit_a, tc)
{
atf_tc_set_md_var(tc, "descr", "Test JIT compilation "
"of BPF_JMP+BPF_EQ+BPF_X with uninitialised A");
}
ATF_TC_BODY(libbpfjit_jmp_jeq_x_noinit_a, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LDX+BPF_W+BPF_LEN, 0), /* X > 0 */
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
BPF_STMT(BPF_RET+BPF_K, 10),
BPF_STMT(BPF_RET+BPF_K, 11)
};
bpfjit_func_t code;
uint8_t pkt[8]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 11);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_jmp_jeq_x_noinit_x);
ATF_TC_HEAD(libbpfjit_jmp_jeq_x_noinit_x, tc)
{
atf_tc_set_md_var(tc, "descr", "Test JIT compilation "
"of BPF_JMP+BPF_EQ+BPF_X with uninitialised X");
}
ATF_TC_BODY(libbpfjit_jmp_jeq_x_noinit_x, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_LD+BPF_LEN, 0), /* A > 0 */
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
BPF_STMT(BPF_RET+BPF_K, 10),
BPF_STMT(BPF_RET+BPF_K, 11)
};
bpfjit_func_t code;
uint8_t pkt[8]; /* the program doesn't read any data */
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(bpf_validate(insns, insn_count));
code = bpfjit_generate_code(NULL, insns, insn_count);
ATF_REQUIRE(code != NULL);
ATF_CHECK(jitcall(code, pkt, 1, 1) == 11);
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_jmp_modulo_x);
ATF_TC_HEAD(libbpfjit_jmp_modulo_x, tc)
{
@ -3883,6 +4636,8 @@ ATF_TP_ADD_TCS(tp)
* to ../../net/bpfjit/t_bpfjit.c
*/
ATF_TP_ADD_TC(tp, libbpfjit_empty);
ATF_TP_ADD_TC(tp, libbpfjit_ret_k);
ATF_TP_ADD_TC(tp, libbpfjit_bad_ret_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_add_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_sub_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mul_k);
@ -3894,8 +4649,17 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_alu_div10000_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div7609801_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div80000000_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod0_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod1_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod2_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod4_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10000_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod7609801_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod80000000_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_and_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_or_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_k);
@ -3912,8 +4676,17 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_alu_div10000_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div7609801_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_div80000000_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod0_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod1_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod2_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod4_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod10000_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod7609801_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_mod80000000_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_and_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_or_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_x);
@ -3921,6 +4694,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_alu_modulo_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_neg);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_invalid);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_overflow);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jgt_k);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_k);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_k);
@ -3930,6 +4705,9 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_x);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jset_x);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x_noinit_ax);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x_noinit_a);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x_noinit_x);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_modulo_x);
ATF_TP_ADD_TC(tp, libbpfjit_ld_abs);
ATF_TP_ADD_TC(tp, libbpfjit_ld_abs_k_overflow);

View file

@ -1,8 +1,11 @@
/* $NetBSD: return_one.S,v 1.1 2011/07/18 23:16:09 jym Exp $ */
/* $NetBSD: return_one.S,v 1.2 2016/08/05 15:02:29 scole Exp $ */
#include <machine/asm.h>
.globl return_one, return_one_end;
.globl return_one_end
return_one: return_one_end:
nop
ENTRY(return_one,0)
mov ret0=1
br.ret.sptk.few rp
return_one_end:
END(return_one)

View file

@ -1,10 +1,11 @@
/* $NetBSD: return_one.S,v 1.2 2012/03/16 08:51:47 matt Exp $ */
/* $NetBSD: return_one.S,v 1.3 2015/03/29 00:38:36 matt Exp $ */
#include <machine/asm.h>
.globl return_one, return_one_end
.globl return_one_start, return_one_end
_ENTRY(return_one)
return_one_start:
li %r3, 1
blr
return_one_end:

View file

@ -1,11 +1,11 @@
/* $NetBSD: return_one.S,v 1.1 2014/09/19 17:36:26 matt Exp $ */
/* $NetBSD: return_one.S,v 1.2 2015/03/28 07:07:54 matt Exp $ */
#include <machine/asm.h>
.globl return_one_end
ENTRY_NP(return_one)
li v0, 1
li a0, 1
ret
return_one_end:
END(return_one)

View file

@ -0,0 +1,179 @@
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* 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/cdefs.h>
__RCSID("$NetBSD: h_lfsr.c,v 1.1 2015/11/18 18:35:35 christos Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <err.h>
#include <string.h>
#include <unistd.h>
#include <db.h>
#define MAXKEY 0xffff
#ifdef DEBUG
#define DPRINTF(...) printf(__VA_ARGS__)
#else
#define DPRINTF(...)
#endif
static uint16_t
next(uint16_t *cur)
{
uint16_t lsb = *cur & 1;
*cur >>= 1;
*cur ^= (-lsb) & 0xB400u;
return *cur;
}
int
main(int argc, char *argv[])
{
char buf[65536];
char kb[256];
DBT key, val;
DB *db;
HASHINFO hi;
uint8_t c;
uint16_t len;
uint32_t pagesize = atoi(argv[1]);
memset(&hi, 0, sizeof(hi));
memset(buf, 'a', sizeof(buf));
hi.bsize = pagesize;
hi.nelem = 65536;
hi.ffactor = 128;
key.data = kb;
val.data = buf;
db = dbopen(NULL, O_CREAT|O_TRUNC|O_RDWR, 0, DB_HASH, &hi);
if (db == NULL)
err(EXIT_FAILURE, "dbopen");
len = 0xaec1;
for (size_t i = 0; i < MAXKEY; i++) {
key.size = (len & 0xff) + 1;
c = len >> 8;
memset(kb, c, key.size);
val.size = (next(&len) & 0xff) + 1;
switch ((*db->put)(db, &key, &val, R_NOOVERWRITE)) {
case 0:
DPRINTF("put %zu %zu %#x\n",
key.size, val.size, c);
break;
case -1:
err(EXIT_FAILURE, "put error %zu %zu %#x",
key.size, val.size, c);
case 1:
errx(EXIT_FAILURE, "put overwrite %zu %zu %#x",
key.size, val.size, c);
default:
abort();
}
}
len = 0xaec1;
for (size_t i = 0; i < MAXKEY; i++) {
key.size = (len & 0xff) + 1;
c = len >> 8;
memset(kb, c, key.size);
next(&len);
switch ((*db->get)(db, &key, &val, 0)) {
case 0:
DPRINTF("get %zu %zu %#x\n",
key.size, val.size, c);
break;
case -1:
err(EXIT_FAILURE, "get %zu %zu %#x",
key.size, val.size, c);
case 1:
errx(EXIT_FAILURE, "get not found %zu %zu %#x",
key.size, val.size, c);
default:
abort();
}
if (memcmp(key.data, kb, key.size) != 0)
errx(EXIT_FAILURE, "get badkey %zu %zu %#x",
key.size, val.size, c);
if (val.size != (len & 0xff) + 1U)
errx(EXIT_FAILURE, "get badvallen %zu %zu %#x",
key.size, val.size, c);
if (memcmp(val.data, buf, val.size) != 0)
errx(EXIT_FAILURE, "get badval %zu %zu %#x",
key.size, val.size, c);
}
len = 0xaec1;
for (size_t i = 0; i < MAXKEY; i++) {
key.size = (len & 0xff) + 1;
c = len >> 8;
memset(kb, c, key.size);
next(&len);
switch ((*db->del)(db, &key, 0)) {
case 0:
DPRINTF("del %zu %zu %#x\n",
key.size, val.size, c);
break;
case -1:
err(EXIT_FAILURE, "del %zu %zu %#x", key.size,
val.size, c);
case 1:
errx(EXIT_FAILURE, "del not found %zu %zu %#x",
key.size, val.size, c);
default:
abort();
}
}
len = 0xaec1;
for (size_t i = 0; i < MAXKEY; i++) {
key.size = (len & 0xff) + 1;
c = len >> 8;
memset(kb, c, key.size);
next(&len);
switch ((*db->get)(db, &key, &val, 0)) {
case 0:
errx(EXIT_FAILURE, "get2 found %zu %zu %#x",
key.size, val.size, c);
break;
case -1:
err(EXIT_FAILURE, "get2 %zu %zu %#x",
key.size, val.size, c);
case 1:
DPRINTF("get2 %zu %zu %#x\n",
key.size, val.size, c);
break;
default:
abort();
}
}
return 0;
}

View file

@ -1,4 +1,4 @@
# $NetBSD: t_db.sh,v 1.4 2013/07/29 10:43:15 skrll Exp $
# $NetBSD: t_db.sh,v 1.6 2015/11/18 18:35:35 christos Exp $
#
# Copyright (c) 2008 The NetBSD Foundation, Inc.
# All rights reserved.
@ -25,11 +25,16 @@
# POSSIBILITY OF SUCH DAMAGE.
#
prog()
prog_db()
{
echo $(atf_get_srcdir)/h_db
}
prog_lfsr()
{
echo $(atf_get_srcdir)/h_lfsr
}
dict()
{
if [ -f /usr/share/dict/words ]; then
@ -77,7 +82,7 @@ small_btree_body()
echo k$i
done >in
atf_check -o file:exp "$(prog)" btree in
atf_check -o file:exp "$(prog_db)" btree in
}
atf_test_case small_hash
@ -106,7 +111,7 @@ small_hash_body()
echo k$i
done >in
atf_check -o file:exp "$(prog)" hash in
atf_check -o file:exp "$(prog_db)" hash in
}
atf_test_case small_recno
@ -133,7 +138,7 @@ small_recno_body()
printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
}' >in
atf_check -o file:exp "$(prog)" recno in
atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case medium_btree
@ -164,7 +169,7 @@ medium_btree_body()
echo k$i
done >in
atf_check -o file:exp "$(prog)" btree in
atf_check -o file:exp "$(prog_db)" btree in
}
atf_test_case medium_hash
@ -195,7 +200,7 @@ medium_hash_body()
echo k$i
done >in
atf_check -o file:exp "$(prog)" hash in
atf_check -o file:exp "$(prog_db)" hash in
}
atf_test_case medium_recno
@ -220,7 +225,7 @@ medium_recno_body()
printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
}' >in
atf_check -o file:exp "$(prog)" recno in
atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case big_btree
@ -249,7 +254,7 @@ big_btree_body()
echo k$i
done >in
atf_check "$(prog)" -o out btree in
atf_check "$(prog_db)" -o out btree in
cmp -s exp out || atf_fail "test failed for page size: $psize"
done
}
@ -277,7 +282,7 @@ big_hash_body()
echo k$i
done >in
atf_check "$(prog)" -o out hash in
atf_check "$(prog_db)" -o out hash in
cmp -s exp out || atf_fail "test failed"
}
@ -305,7 +310,7 @@ big_recno_body()
for psize in 512 16384 65536; do
echo "checking page size: $psize"
atf_check "$(prog)" -o out recno in
atf_check "$(prog_db)" -o out recno in
cmp -s exp out || atf_fail "test failed for page size: $psize"
done
}
@ -373,7 +378,7 @@ random_recno_body()
printf("g\nk%d\n", i);
}' >in
atf_check -o file:exp "$(prog)" recno in
atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case reverse_recno
@ -411,7 +416,7 @@ reverse_recno_body()
printf("g\nk%d\n", i);
}' >in
atf_check -o file:exp "$(prog)" recno in
atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case alternate_recno
@ -463,7 +468,7 @@ alternate_recno_body()
printf("g\nk%d\n", i);
}' >in
atf_check "$(prog)" -o out recno in
atf_check "$(prog_db)" -o out recno in
sort -o exp exp
sort -o out out
@ -532,7 +537,7 @@ h_delete()
}' >> exp
fi
atf_check "$(prog)" -o out $type in
atf_check "$(prog_db)" -o out $type in
atf_check -o file:exp cat out
}
@ -576,7 +581,7 @@ h_repeated()
}
}' >in
$(prog) btree in
$(prog_db) btree in
}
atf_test_case repeated_btree
@ -631,7 +636,7 @@ duplicate_btree_body()
printf("o\n");
}' >in
atf_check -o file:exp -x "$(prog) -iflags=1 btree in | sort"
atf_check -o file:exp -x "$(prog_db) -iflags=1 btree in | sort"
}
h_cursor_flags()
@ -660,7 +665,7 @@ h_cursor_flags()
printf("eR_CURSOR SHOULD HAVE FAILED\n");
}' >in
atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
atf_check -o ignore -e ignore -s ne:0 "$(prog_db)" -o out $type in
atf_check -s ne:0 test -s out
cat exp |
@ -674,7 +679,7 @@ h_cursor_flags()
printf("eR_CURSOR SHOULD HAVE FAILED\n");
}' >in
atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
atf_check -o ignore -e ignore -s ne:0 "$(prog_db)" -o out $type in
atf_check -s ne:0 test -s out
}
@ -730,7 +735,7 @@ reverse_order_recno_body()
printf("or\n");
}' >in
atf_check -o file:exp "$(prog)" recno in
atf_check -o file:exp "$(prog_db)" recno in
}
atf_test_case small_page_btree
@ -763,7 +768,7 @@ small_page_btree_body()
echo k$i
done >in
atf_check -o file:exp "$(prog)" -i psize=512 btree in
atf_check -o file:exp "$(prog_db)" -i psize=512 btree in
}
h_byte_orders()
@ -783,14 +788,14 @@ h_byte_orders()
echo k$i
done >in
atf_check -o file:exp "$(prog)" -ilorder=$order -f byte.file $type in
atf_check -o file:exp "$(prog_db)" -ilorder=$order -f byte.file $type in
for i in `sed 50q $(dict)`; do
echo g
echo k$i
done >in
atf_check -o file:exp "$(prog)" -s -ilorder=$order -f byte.file $type in
atf_check -o file:exp "$(prog_db)" -s -ilorder=$order -f byte.file $type in
done
}
@ -823,14 +828,14 @@ h_bsize_ffactor()
ffactor=$2
echo "bucketsize $bsize, fill factor $ffactor"
atf_check -o file:exp "$(prog)" "-ibsize=$bsize,\
atf_check -o file:exp "$(prog_db)" "-ibsize=$bsize,\
ffactor=$ffactor,nelem=25000,cachesize=65536" hash in
}
atf_test_case bsize_ffactor
bsize_ffactor_head()
{
atf_set "timeout" "480"
atf_set "timeout" "1800"
atf_set "descr" "Checks hash database with various" \
"bucketsizes and fill factors"
# Begin FreeBSD
@ -896,9 +901,21 @@ bsize_ffactor_body()
h_bsize_ffactor 8192 341
h_bsize_ffactor 8192 455
h_bsize_ffactor 8192 683
h_bsize_ffactor 16384 341
h_bsize_ffactor 16384 455
h_bsize_ffactor 16384 683
h_bsize_ffactor 32768 341
h_bsize_ffactor 32768 455
h_bsize_ffactor 32768 683
h_bsize_ffactor 65536 341
h_bsize_ffactor 65536 455
h_bsize_ffactor 65536 683
}
# FIXME: what does it test?
# This tests 64K block size addition/removal
atf_test_case four_char_hash
four_char_hash_head()
{
@ -921,15 +938,32 @@ EOF
# Begin FreeBSD
if true; then
atf_check "$(prog)" -i bsize=32768 hash in
atf_check "$(prog_db)" -i bsize=32768 hash in
else
# End FreeBSD
atf_check "$(prog)" -i bsize=65536 hash in
atf_check "$(prog_db)" -i bsize=65536 hash in
# Begin FreeBSD
fi
# End FreeBSD
}
atf_test_case bsize_torture
bsize_torture_head()
{
atf_set "timeout" "36000"
atf_set "descr" "Checks hash database with various bucket sizes"
}
bsize_torture_body()
{
TMPDIR="$(pwd)/db_dir"; export TMPDIR
mkdir ${TMPDIR}
for i in 2048 4096 8192 16384 32768 65536
do
atf_check "$(prog_lfsr)" $i
done
}
atf_init_test_cases()
{
atf_add_test_case small_btree
@ -957,4 +991,5 @@ atf_init_test_cases()
atf_add_test_case byte_orders_hash
atf_add_test_case bsize_ffactor
atf_add_test_case four_char_hash
atf_add_test_case bsize_torture
}

View file

@ -0,0 +1,343 @@
/* $NetBSD: t_db_hash_seq.c,v 1.2 2015/06/22 22:35:51 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* 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/cdefs.h>
__RCSID("$NetBSD: t_db_hash_seq.c,v 1.2 2015/06/22 22:35:51 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
#include <db.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <syslog.h>
#include <netinet/in.h>
#define ATF
struct conf {
struct sockaddr_storage c_ss;
int c_lmask;
int c_port;
int c_proto;
int c_family;
int c_uid;
int c_nfail;
char c_name[128];
int c_rmask;
int c_duration;
};
struct dbinfo {
int count;
time_t last;
char id[64];
};
#ifdef ATF
#include <atf-c.h>
#define DO_ERR(msg, ...) ATF_REQUIRE_MSG(0, msg, __VA_ARGS__)
#define DO_WARNX(msg, ...) ATF_REQUIRE_MSG(0, msg, __VA_ARGS__)
#else
#include <err.h>
#define DO_ERR(fmt, ...) err(EXIT_FAILURE, fmt, __VA_ARGS__)
#define DO_WARNX(fmt, ...) warnx(fmt, __VA_ARGS__)
#endif
#define DO_DEBUG(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
static HASHINFO openinfo = {
4096, /* bsize */
32, /* ffactor */
256, /* nelem */
8 * 1024 * 1024,/* cachesize */
NULL, /* hash() */
0 /* lorder */
};
static int debug = 0;
static int
state_close(DB *db)
{
if (db == NULL)
return -1;
if ((*db->close)(db) == -1)
DO_ERR("%s: can't close db", __func__);
return 0;
}
static DB *
state_open(const char *dbname, int flags, mode_t perm)
{
DB *db;
db = dbopen(dbname, flags, perm, DB_HASH, &openinfo);
if (db == NULL) {
if (errno == ENOENT && (flags & O_CREAT) == 0)
return NULL;
DO_ERR("%s: can't open `%s'", __func__, dbname);
}
return db;
}
static int
state_sizecheck(const DBT *t)
{
if (sizeof(struct conf) == t->size)
return 0;
DO_WARNX("Key size mismatch %zu != %zu", sizeof(struct conf), t->size);
return 0;
}
static int
state_del(DB *db, const struct conf *c)
{
int rv;
DBT k;
if (db == NULL)
return -1;
k.data = __UNCONST(c);
k.size = sizeof(*c);
switch (rv = (*db->del)(db, &k, 1)) {
case 0:
case 1:
if (debug > 1) {
DO_DEBUG("%s: returns %d", __func__, rv);
(*db->sync)(db, 0);
}
return 0;
default:
DO_ERR("%s: failed", __func__);
return -1;
}
}
#if 0
static int
state_get(DB *db, const struct conf *c, struct dbinfo *dbi)
{
int rv;
DBT k, v;
if (db == NULL)
return -1;
k.data = __UNCONST(c);
k.size = sizeof(*c);
switch (rv = (*db->get)(db, &k, &v, 0)) {
case 0:
case 1:
if (rv)
memset(dbi, 0, sizeof(*dbi));
else
memcpy(dbi, v.data, sizeof(*dbi));
if (debug > 1)
DO_DEBUG("%s: returns %d", __func__, rv);
return 0;
default:
DO_ERR("%s: failed", __func__);
return -1;
}
}
#endif
static int
state_put(DB *db, const struct conf *c, const struct dbinfo *dbi)
{
int rv;
DBT k, v;
if (db == NULL)
return -1;
k.data = __UNCONST(c);
k.size = sizeof(*c);
v.data = __UNCONST(dbi);
v.size = sizeof(*dbi);
switch (rv = (*db->put)(db, &k, &v, 0)) {
case 0:
if (debug > 1) {
DO_DEBUG("%s: returns %d", __func__, rv);
(*db->sync)(db, 0);
}
return 0;
case 1:
errno = EEXIST;
/*FALLTHROUGH*/
default:
DO_ERR("%s: failed", __func__);
}
}
static int
state_iterate(DB *db, struct conf *c, struct dbinfo *dbi, unsigned int first)
{
int rv;
DBT k, v;
if (db == NULL)
return -1;
first = first ? R_FIRST : R_NEXT;
switch (rv = (*db->seq)(db, &k, &v, first)) {
case 0:
if (state_sizecheck(&k) == -1)
return -1;
memcpy(c, k.data, sizeof(*c));
memcpy(dbi, v.data, sizeof(*dbi));
if (debug > 1)
DO_DEBUG("%s: returns %d", __func__, rv);
return 1;
case 1:
if (debug > 1)
DO_DEBUG("%s: returns %d", __func__, rv);
return 0;
default:
DO_ERR("%s: failed", __func__);
return -1;
}
}
#define MAXB 100
static int
testdb(int skip)
{
size_t i;
int f;
char flag[MAXB];
DB *db;
struct conf c;
struct dbinfo d;
db = state_open(NULL, O_RDWR|O_CREAT|O_TRUNC, 0600);
if (db == NULL)
DO_ERR("%s: cannot open `%s'", __func__, "foo");
memset(&c, 0, sizeof(c));
memset(&d, 0, sizeof(d));
memset(flag, 0, sizeof(flag));
for (i = 0; i < __arraycount(flag); i++) {
c.c_port = i;
state_put(db, &c, &d);
}
for (f = 1, i = 0; state_iterate(db, &c, &d, f) == 1; f = 0, i++) {
if (debug > 1)
DO_DEBUG("%zu %d\n", i, c.c_port);
if (flag[c.c_port])
DO_WARNX("Already visited %d", c.c_port);
flag[c.c_port] = 1;
if (skip == 0 || c.c_port % skip != 0)
continue;
state_del(db, &c);
}
state_close(db);
for (i = 0; i < __arraycount(flag); i++) {
if (flag[i] == 0)
DO_WARNX("Not visited %zu", i);
}
return 0;
}
#ifndef ATF
int
main(int argc, char *argv[])
{
return testdb(6);
}
#else
ATF_TC(test_hash_del_none);
ATF_TC_HEAD(test_hash_del_none, tc)
{
atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables deleting none");
}
ATF_TC_BODY(test_hash_del_none, tc)
{
testdb(0);
}
ATF_TC(test_hash_del_all);
ATF_TC_HEAD(test_hash_del_all, tc)
{
atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables deleting all");
}
ATF_TC_BODY(test_hash_del_all, tc)
{
testdb(1);
}
ATF_TC(test_hash_del_alt);
ATF_TC_HEAD(test_hash_del_alt, tc)
{
atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables alternating deletets");
}
ATF_TC_BODY(test_hash_del_alt, tc)
{
testdb(2);
}
ATF_TC(test_hash_del_every_7);
ATF_TC_HEAD(test_hash_del_every_7, tc)
{
atf_tc_set_md_var(tc, "descr", "Check sequential scan of hash tables deleting every 7 elements");
}
ATF_TC_BODY(test_hash_del_every_7, tc)
{
testdb(7);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, test_hash_del_none);
ATF_TP_ADD_TC(tp, test_hash_del_all);
ATF_TP_ADD_TC(tp, test_hash_del_alt);
ATF_TP_ADD_TC(tp, test_hash_del_every_7);
return 0;
}
#endif

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_execve.c,v 1.1 2014/04/29 06:29:02 uebayasi Exp $ */
/* $NetBSD: t_execve.c,v 1.2 2015/09/12 15:21:33 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -47,7 +47,8 @@ ATF_TC_BODY(t_execve_null, tc)
err = execve(NULL, NULL, NULL);
ATF_REQUIRE(err == -1);
ATF_REQUIRE(errno == EFAULT);
ATF_REQUIRE_MSG(errno == EFAULT,
"wrong error returned %d instead of %d", errno, EFAULT);
}
ATF_TP_ADD_TCS(tp)

View file

@ -1,4 +1,4 @@
/* $NetBSD: isqemu.h,v 1.3 2013/04/14 12:46:29 martin Exp $ */
/* $NetBSD: isqemu.h,v 1.4 2015/01/03 14:21:05 gson Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@ -34,6 +34,7 @@
#include <sys/param.h>
#include <sys/sysctl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <err.h>

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_spawn.c,v 1.1 2012/02/13 21:03:08 martin Exp $ */
/* $NetBSD: t_spawn.c,v 1.2 2014/10/18 08:33:30 snj Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -137,7 +137,7 @@ ATF_TC(t_spawn_child);
ATF_TC_HEAD(t_spawn_child, tc)
{
atf_tc_set_md_var(tc, "descr",
"posix_spawn a child and get it's return code");
"posix_spawn a child and get its return code");
}
ATF_TC_BODY(t_spawn_child, tc)

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_fnmatch.c,v 1.3 2012/04/08 09:58:59 jruoho Exp $ */
/* $NetBSD: t_fnmatch.c,v 1.6 2014/10/12 22:33:41 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_fnmatch.c,v 1.3 2012/04/08 09:58:59 jruoho Exp $");
__RCSID("$NetBSD: t_fnmatch.c,v 1.6 2014/10/12 22:33:41 christos Exp $");
#include <atf-c.h>
#include <fnmatch.h>
@ -153,6 +153,30 @@ ATF_TC_BODY(fnmatch_period, tc)
ATF_CHECK(fnmatch("x/*y", "x/.y", FNM_PATHNAME | FNM_PERIOD) != 0);
}
ATF_TC(fnmatch_initialbracket);
ATF_TC_HEAD(fnmatch_initialbracket, tc)
{
atf_tc_set_md_var(tc, "descr", "Test fnmatch with initial [");
}
ATF_TC_BODY(fnmatch_initialbracket, tc)
{
ATF_CHECK(fnmatch("[[?*\\\\]", "\\", 0) == 0);
ATF_CHECK(fnmatch("[]?*\\\\]", "]", 0) == 0);
ATF_CHECK(fnmatch("[!]a-]", "b", 0) == 0);
ATF_CHECK(fnmatch("[]-_]", "^", 0) == 0); /* range: ']', '^', '_' */
ATF_CHECK(fnmatch("[!]-_]", "X", 0) == 0);
ATF_CHECK(fnmatch("[a-z]/[a-z]", "a/b", 0) == 0);
ATF_CHECK(fnmatch("[*]/b", "*/b", 0) == 0);
ATF_CHECK(fnmatch("[?]/b", "?/b", 0) == 0);
ATF_CHECK(fnmatch("[[a]/b", "a/b", 0) == 0);
ATF_CHECK(fnmatch("[[a]/b", "[/b", 0) == 0);
ATF_CHECK(fnmatch("[/b", "[/b", 0) == 0);
ATF_CHECK(fnmatch("[*]/b", "a/b", 0) != 0);
ATF_CHECK(fnmatch("[?]/b", "a/b", 0) != 0);
}
ATF_TP_ADD_TCS(tp)
{
@ -162,6 +186,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, fnmatch_noescape);
ATF_TP_ADD_TC(tp, fnmatch_pathname);
ATF_TP_ADD_TC(tp, fnmatch_period);
ATF_TP_ADD_TC(tp, fnmatch_initialbracket);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_fpsetmask.c,v 1.14 2014/11/04 00:20:19 justin Exp $ */
/* $NetBSD: t_fpsetmask.c,v 1.16 2016/03/12 11:55:14 martin Exp $ */
/*-
* Copyright (c) 1995 The NetBSD Foundation, Inc.
@ -58,8 +58,20 @@ ATF_TC_BODY(no_test, tc)
#include <ieeefp.h>
const char *skip_mesg;
const char *skip_arch;
#if __arm__ && !__SOFTFP__
/*
* Some NEON fpus do not implement IEEE exception handling,
* skip these tests if running on them and compiled for
* hard float.
*/
#define FPU_PREREQ() \
if (0 == fpsetmask(fpsetmask(FP_X_INV))) \
atf_tc_skip("FPU does not implement exception handling");
#endif
#ifndef FPU_PREREQ
#define FPU_PREREQ() /* nothing */
#endif
void sigfpe(int, siginfo_t *, void *);
@ -296,6 +308,9 @@ sigfpe(int s, siginfo_t *si, void *c)
\
ATF_TC_BODY(m##_##t, tc) \
{ \
\
FPU_PREREQ(); \
\
if (strcmp(MACHINE, "macppc") == 0) \
atf_tc_expect_fail("PR port-macppc/46319"); \
\
@ -323,11 +338,13 @@ ATF_TC_BODY(fpsetmask_basic, tc)
size_t i;
fp_except_t msk, lst[] = { FP_X_INV, FP_X_DZ, FP_X_OFL, FP_X_UFL };
FPU_PREREQ();
msk = fpgetmask();
for (i = 0; i < __arraycount(lst); i++) {
fpsetmask(msk | lst[i]);
ATF_CHECK((fpgetmask() & lst[i]) != 0);
fpsetmask(msk & lst[i]);
fpsetmask(msk & ~lst[i]);
ATF_CHECK((fpgetmask() & lst[i]) == 0);
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_randomid.c,v 1.3 2011/07/07 09:49:59 jruoho Exp $ */
/* $NetBSD: t_randomid.c,v 1.5 2015/03/07 09:59:15 isaki Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#define PERIOD 30000
uint64_t last[65536];
uint32_t last[65536];
ATF_TC(randomid_basic);
ATF_TC_HEAD(randomid_basic, tc)
@ -50,30 +50,30 @@ ATF_TC_HEAD(randomid_basic, tc)
ATF_TC_BODY(randomid_basic, tc)
{
static randomid_t ctx = NULL;
uint64_t lowest, n, diff;
uint32_t lowest, n, diff;
uint16_t id;
memset(last, 0, sizeof(last));
ctx = randomid_new(16, (long)3600);
lowest = UINT64_MAX;
lowest = UINT32_MAX;
for (n = 0; n < 1000000; n++) {
for (n = 0; n < 100000; n++) {
id = randomid(ctx);
if (last[id] > 0) {
diff = n - last[id];
if (diff <= lowest) {
if (lowest != UINT64_MAX)
printf("id %5d: last call at %9"PRIu64
", current call %9"PRIu64
" (diff %5"PRIu64"), "
"lowest %"PRIu64"\n",
if (lowest != UINT32_MAX)
printf("id %5d: last call at %9"PRIu32
", current call %9"PRIu32
" (diff %5"PRIu32"), "
"lowest %"PRIu32"\n",
id, last[id], n, diff, lowest);
ATF_REQUIRE_MSG(diff >= PERIOD,
"diff (%"PRIu64") less than minimum "
"diff (%"PRIu32") less than minimum "
"period (%d)", diff, PERIOD);
lowest = diff;

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_siginfo.c,v 1.24 2014/11/04 00:20:19 justin Exp $ */
/* $NetBSD: t_siginfo.c,v 1.30 2015/12/22 14:25:58 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -46,8 +46,9 @@
#include <setjmp.h>
#include <float.h>
#ifdef HAVE_FENV
#include <fenv.h>
#ifdef __HAVE_FENV
#include <ieeefp.h> /* only need for ARM Cortex/Neon hack */
#elif defined(_FLOAT_IEEE754)
#include <ieeefp.h>
#endif
@ -316,13 +317,21 @@ ATF_TC_BODY(sigfpe_flt, tc)
atf_tc_skip("Test does not run correctly under QEMU");
#if defined(__powerpc__)
atf_tc_skip("Test not valid on powerpc");
#elif defined(__arm__) && !__SOFTFP__
/*
* Some NEON fpus do not implement IEEE exception handling,
* skip these tests if running on them and compiled for
* hard float.
*/
if (0 == fpsetmask(fpsetmask(FP_X_INV)))
atf_tc_skip("FPU does not implement exception handling");
#endif
if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigfpe_flt_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
#ifdef HAVE_FENV
#ifdef __HAVE_FENV
feenableexcept(FE_ALL_EXCEPT);
#elif defined(_FLOAT_IEEE754)
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
@ -373,7 +382,7 @@ ATF_TC_BODY(sigfpe_int, tc)
sa.sa_sigaction = sigfpe_int_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
#ifdef HAVE_FENV
#ifdef __HAVE_FENV
feenableexcept(FE_ALL_EXCEPT);
#elif defined(_FLOAT_IEEE754)
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
@ -454,15 +463,19 @@ ATF_TC_BODY(sigbus_adraln, tc)
{
struct sigaction sa;
#if defined(__alpha__)
#if defined(__alpha__) || defined(__arm__)
int rv, val;
size_t len = sizeof(val);
rv = sysctlbyname("machdep.unaligned_sigbus", &val, &len, NULL, 0);
ATF_REQUIRE(rv == 0);
if (val == 0)
atf_tc_skip("SIGBUS signal not enabled for unaligned accesses");
atf_tc_skip("No SIGBUS signal for unaligned accesses");
#endif
/* m68k (except sun2) never issue SIGBUS (PR lib/49653) */
if (strcmp(MACHINE_ARCH, "m68k") == 0)
atf_tc_skip("No SIGBUS signal for unaligned accesses");
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigbus_action;
sigemptyset(&sa.sa_mask);

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_sleep.c,v 1.8 2014/07/15 14:56:34 gson Exp $ */
/* $NetBSD: t_sleep.c,v 1.9 2016/08/11 21:34:11 kre Exp $ */
/*-
* Copyright (c) 2006 Frank Kardel
@ -180,7 +180,8 @@ do_kevent(struct timespec *delay, struct timespec *remain)
(void)close(kq);
if (rtc == -1) {
ATF_REQUIRE_MSG(kerrno == EINTR, "kevent: %s", strerror(errno));
ATF_REQUIRE_MSG(kerrno == EINTR, "kevent: %s",
strerror(kerrno));
return 0;
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho Exp $ */
/* $NetBSD: t_time.c,v 1.3 2014/10/31 12:22:38 justin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho Exp $");
__RCSID("$NetBSD: t_time.c,v 1.3 2014/10/31 12:22:38 justin Exp $");
#ifdef __FreeBSD__
#include <sys/time.h>
@ -94,15 +94,16 @@ ATF_TC_HEAD(time_timeofday, tc)
ATF_TC_BODY(time_timeofday, tc)
{
struct timeval tv = { 0, 0 };
time_t t;
time_t t1, t2;
t = time(NULL);
t1 = time(NULL);
ATF_REQUIRE(gettimeofday(&tv, NULL) == 0);
t2 = time(NULL);
(void)fprintf(stderr, "%"PRId64" vs. %"PRId64"\n",
(int64_t)t, (int64_t)tv.tv_sec);
(int64_t)t1, (int64_t)tv.tv_sec);
if (t != tv.tv_sec)
if (t1 > tv.tv_sec || t2 < tv.tv_sec)
atf_tc_fail("time(3) and gettimeofday(2) differ");
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_vis.c,v 1.7 2014/09/08 19:01:03 christos Exp $ */
/* $NetBSD: t_vis.c,v 1.8 2015/05/23 14:02:11 christos Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -32,6 +32,7 @@
#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <err.h>
#include <vis.h>
@ -143,6 +144,35 @@ ATF_TC_BODY(strunvis_hex, tc)
}
}
ATF_TC(strvis_locale);
ATF_TC_HEAD(strvis_locale, tc)
{
atf_tc_set_md_var(tc, "descr", "Test strvis(3) with locale");
}
ATF_TC_BODY(strvis_locale, tc)
{
char s[256], cd[sizeof(s) * 4 + 1], jd[sizeof(cd)], *ol;
int jr, cr;
for (size_t i = 0; i < sizeof(s) - 1; i++)
s[i] = i + 1;
s[sizeof(s) - 1] = '\0';
ol = setlocale(LC_CTYPE, "ja_JP.UTF-8");
ATF_REQUIRE(ol != NULL);
jr = strvisx(jd, s, sizeof(s), VIS_WHITE | VIS_NOLOCALE);
ATF_REQUIRE(jr != -1);
ol = strdup(ol);
ATF_REQUIRE(ol != NULL);
ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
cr = strvisx(cd, s, sizeof(s), VIS_WHITE);
ATF_REQUIRE(jr == cr);
ATF_REQUIRE(memcmp(jd, cd, jr) == 0);
setlocale(LC_CTYPE, ol);
free(ol);
}
ATF_TP_ADD_TCS(tp)
{
@ -150,6 +180,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, strvis_null);
ATF_TP_ADD_TC(tp, strvis_empty);
ATF_TP_ADD_TC(tp, strunvis_hex);
ATF_TP_ADD_TC(tp, strvis_locale);
return atf_no_error();
}

View file

@ -0,0 +1,109 @@
/* $NetBSD: t_inet_addr.c,v 1.1 2015/04/09 16:47:56 ginsbach Exp $ */
/*
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
*
* 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/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2011\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_inet_addr.c,v 1.1 2015/04/09 16:47:56 ginsbach Exp $");
#include <arpa/inet.h>
#include <atf-c.h>
#include <stdio.h>
#include <string.h>
ATF_TC(inet_addr_basic);
ATF_TC_HEAD(inet_addr_basic, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks inet_addr(3)");
}
ATF_TC_BODY(inet_addr_basic, tc)
{
static const char *addrs[] = {
"127.0.0.1", "99.99.99.99", "0.0.0.0", "255.255.255.255" };
struct in_addr ia;
const char *ian;
in_addr_t addr;
size_t i;
for (i = 0; i < __arraycount(addrs); i++) {
(void)fprintf(stderr, "checking %s\n", addrs[i]);;
addr = inet_addr(addrs[i]);
ia.s_addr = addr;
ian = inet_ntoa(ia);
ATF_REQUIRE(ian != NULL);
ATF_CHECK(strcmp(ian, addrs[i]) == 0);
}
}
ATF_TC(inet_addr_err);
ATF_TC_HEAD(inet_addr_err, tc)
{
atf_tc_set_md_var(tc, "descr", "Invalid addresses with inet_addr(3)");
}
ATF_TC_BODY(inet_addr_err, tc)
{
static const char *addrs[] = {
". . . .", "1.2.3.", "0.0.0.256", "255.255.255.256",
"................................................",
"a.b.c.d", "0x0.0x1.0x2.0x3", "-1.-1.-1.-1", "", " "};
struct in_addr ia;
const char *ian;
in_addr_t addr;
size_t i;
for (i = 0; i < __arraycount(addrs); i++) {
(void)fprintf(stderr, "checking %s\n", addrs[i]);;
addr = inet_addr(addrs[i]);
ia.s_addr = addr;
ian = inet_ntoa(ia);
ATF_REQUIRE(ian != NULL);
ATF_CHECK(strcmp(ian, addrs[i]) != 0);
}
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, inet_addr_basic);
ATF_TP_ADD_TC(tp, inet_addr_err);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_inet_network.c,v 1.3 2011/07/15 11:27:23 jruoho Exp $ */
/* $NetBSD: t_inet_network.c,v 1.4 2015/04/09 16:47:56 ginsbach Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -32,79 +32,17 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_inet_network.c,v 1.3 2011/07/15 11:27:23 jruoho Exp $");
__RCSID("$NetBSD: t_inet_network.c,v 1.4 2015/04/09 16:47:56 ginsbach Exp $");
#include <arpa/inet.h>
#include <atf-c.h>
#include <stdio.h>
#include <string.h>
#define H_REQUIRE(input, expected) \
ATF_REQUIRE_EQ_MSG(inet_network(input), (in_addr_t) expected, \
"inet_network(%s) returned: 0x%08X, expected: %s", #input, \
inet_network(input), #expected)
ATF_TC(inet_addr_basic);
ATF_TC_HEAD(inet_addr_basic, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks inet_addr(3)");
}
ATF_TC_BODY(inet_addr_basic, tc)
{
static const char *addrs[] = {
"127.0.0.1", "99.99.99.99", "0.0.0.0", "255.255.255.255" };
struct in_addr ia;
const char *ian;
in_addr_t addr;
size_t i;
for (i = 0; i < __arraycount(addrs); i++) {
(void)fprintf(stderr, "checking %s\n", addrs[i]);;
addr = inet_addr(addrs[i]);
ia.s_addr = addr;
ian = inet_ntoa(ia);
ATF_REQUIRE(ian != NULL);
ATF_CHECK(strcmp(ian, addrs[i]) == 0);
}
}
ATF_TC(inet_addr_err);
ATF_TC_HEAD(inet_addr_err, tc)
{
atf_tc_set_md_var(tc, "descr", "Invalid addresses with inet_addr(3)");
}
ATF_TC_BODY(inet_addr_err, tc)
{
static const char *addrs[] = {
". . . .", "1.2.3.", "0.0.0.256", "255.255.255.256",
"................................................",
"a.b.c.d", "0x0.0x1.0x2.0x3", "-1.-1.-1.-1", "", " "};
struct in_addr ia;
const char *ian;
in_addr_t addr;
size_t i;
for (i = 0; i < __arraycount(addrs); i++) {
(void)fprintf(stderr, "checking %s\n", addrs[i]);;
addr = inet_addr(addrs[i]);
ia.s_addr = addr;
ian = inet_ntoa(ia);
ATF_REQUIRE(ian != NULL);
ATF_CHECK(strcmp(ian, addrs[i]) != 0);
}
}
ATF_TC(inet_network_basic);
ATF_TC_HEAD(inet_network_basic, tc)
{
@ -165,8 +103,6 @@ ATF_TC_BODY(inet_network_err, tc)
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, inet_addr_basic);
ATF_TP_ADD_TC(tp, inet_addr_err);
ATF_TP_ADD_TC(tp, inet_network_basic);
ATF_TP_ADD_TC(tp, inet_network_err);

View file

@ -1,4 +1,4 @@
# $NetBSD: t_servent.sh,v 1.1 2011/01/12 17:32:27 pgoyette Exp $
# $NetBSD: t_servent.sh,v 1.2 2016/03/08 08:34:17 joerg Exp $
#
# Copyright (c) 2008 The NetBSD Foundation, Inc.
# All rights reserved.
@ -29,6 +29,8 @@ atf_test_case servent
servent_head()
{
atf_set "descr" "Checks {get,set,end}servent(3)"
# libc doesn't include aliases
atf_set "require.files" "/var/db/services.cdb"
}
servent_body()
{

View file

@ -1,18 +1,19 @@
/* $NetBSD: t_rpc.c,v 1.3 2013/02/28 15:56:53 christos Exp $ */
/* $NetBSD: t_rpc.c,v 1.9 2015/11/27 13:59:40 christos Exp $ */
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_rpc.c,v 1.3 2013/02/28 15:56:53 christos Exp $");
__RCSID("$NetBSD: t_rpc.c,v 1.9 2015/11/27 13:59:40 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
#include <rpc/rpc.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#ifndef TEST
#include <atf-c.h>
@ -28,6 +29,12 @@ __RCSID("$NetBSD: t_rpc.c,v 1.3 2013/02/28 15:56:53 christos Exp $");
#define SKIPX(ev, msg, ...) errx(ev, msg, __VA_ARGS__)
#endif
#ifdef DEBUG
#define DPRINTF(...) printf(__VA_ARGS__)
#else
#define DPRINTF(...)
#endif
#define RPCBPROC_NULL 0
@ -51,7 +58,7 @@ reply(caddr_t replyp, struct netbuf * raddrp, struct netconfig * nconf)
#define __rpc_control rpc_control
#endif
extern bool __rpc_control(int, void *);
extern bool_t __rpc_control(int, void *);
static void
onehost(const char *host, const char *transp)
@ -86,9 +93,140 @@ onehost(const char *host, const char *transp)
reply(NULL, &addr, NULL);
}
#define PROGNUM 0x81
#define VERSNUM 0x01
#define PLUSONE 1
#define DESTROY 2
static struct timeval tout = {1, 0};
static void
server(struct svc_req *rqstp, SVCXPRT *transp)
{
int num;
DPRINTF("Starting server\n");
switch (rqstp->rq_proc) {
case NULLPROC:
if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
ERRX(EXIT_FAILURE, "svc_sendreply failed %d", 0);
return;
case PLUSONE:
break;
case DESTROY:
if (!svc_sendreply(transp, (xdrproc_t)xdr_void, NULL))
ERRX(EXIT_FAILURE, "svc_sendreply failed %d", 0);
svc_destroy(transp);
exit(0);
default:
svcerr_noproc(transp);
return;
}
if (!svc_getargs(transp, (xdrproc_t)xdr_int, (void *)&num)) {
svcerr_decode(transp);
return;
}
DPRINTF("About to increment\n");
num++;
if (!svc_sendreply(transp, (xdrproc_t)xdr_int, (void *)&num))
ERRX(EXIT_FAILURE, "svc_sendreply failed %d", 1);
DPRINTF("Leaving server procedure.\n");
}
static int
rawtest(const char *arg)
{
CLIENT *clnt;
SVCXPRT *svc;
int num, resp;
enum clnt_stat rv;
if (arg)
num = atoi(arg);
else
num = 0;
svc = svc_raw_create();
if (svc == NULL)
ERRX(EXIT_FAILURE, "Cannot create server %d", num);
if (!svc_reg(svc, PROGNUM, VERSNUM, server, NULL))
ERRX(EXIT_FAILURE, "Cannot register server %d", num);
clnt = clnt_raw_create(PROGNUM, VERSNUM);
if (clnt == NULL)
ERRX(EXIT_FAILURE, "%s",
clnt_spcreateerror("clnt_raw_create"));
rv = clnt_call(clnt, PLUSONE, (xdrproc_t)xdr_int, (void *)&num,
(xdrproc_t)xdr_int, (void *)&resp, tout);
if (rv != RPC_SUCCESS)
ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
DPRINTF("Got %d\n", resp);
clnt_destroy(clnt);
svc_destroy(svc);
if (++num != resp)
ERRX(EXIT_FAILURE, "expected %d got %d", num, resp);
return EXIT_SUCCESS;
}
static int
regtest(const char *hostname, const char *transp, const char *arg, int p)
{
CLIENT *clnt;
int num, resp;
enum clnt_stat rv;
pid_t pid;
if (arg)
num = atoi(arg);
else
num = 0;
#ifdef __NetBSD__
svc_fdset_init(p ? SVC_FDSET_POLL : 0);
#endif
if (!svc_create(server, PROGNUM, VERSNUM, transp))
ERRX(EXIT_FAILURE, "Cannot create server %d", num);
switch ((pid = fork())) {
case 0:
DPRINTF("Calling svc_run\n");
svc_run();
ERRX(EXIT_FAILURE, "svc_run returned %d!", num);
case -1:
ERRX(EXIT_FAILURE, "Fork failed (%s)", strerror(errno));
default:
sleep(1);
break;
}
DPRINTF("Initializing client\n");
clnt = clnt_create(hostname, PROGNUM, VERSNUM, transp);
if (clnt == NULL)
ERRX(EXIT_FAILURE, "%s",
clnt_spcreateerror("clnt_raw_create"));
rv = clnt_call(clnt, PLUSONE, (xdrproc_t)xdr_int, (void *)&num,
(xdrproc_t)xdr_int, (void *)&resp, tout);
if (rv != RPC_SUCCESS)
ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
DPRINTF("Got %d\n", resp);
if (++num != resp)
ERRX(EXIT_FAILURE, "expected %d got %d", num, resp);
rv = clnt_call(clnt, DESTROY, (xdrproc_t)xdr_void, NULL,
(xdrproc_t)xdr_void, NULL, tout);
if (rv != RPC_SUCCESS)
ERRX(EXIT_FAILURE, "clnt_call: %s", clnt_sperrno(rv));
clnt_destroy(clnt);
return EXIT_SUCCESS;
}
#ifdef TEST
static void
allhosts(void)
allhosts(const char *transp)
{
enum clnt_stat clnt_stat;
@ -103,28 +241,49 @@ int
main(int argc, char *argv[])
{
int ch;
int s, p;
const char *transp = "udp";
while ((ch = getopt(argc, argv, "ut")) != -1)
p = s = 0;
while ((ch = getopt(argc, argv, "prstu")) != -1)
switch (ch) {
case 'p':
p = 1;
break;
case 's':
s = 1;
break;
case 't':
transp = "tcp";
break;
case 'u':
transp = "udp";
break;
case 'r':
transp = NULL;
break;
default:
fprintf(stderr, "Usage: %s -[t|u] [<hostname>...]\n",
fprintf(stderr,
"Usage: %s -[r|s|t|u] [<hostname>...]\n",
getprogname());
return EXIT_FAILURE;
}
if (argc == optind)
allhosts();
else
for (; optind < argc; optind++)
onehost(argv[optind], transp);
if (argc == optind) {
if (transp)
allhosts(transp);
else
rawtest(NULL);
} else {
for (; optind < argc; optind++) {
if (transp)
s == 0 ?
onehost(argv[optind], transp) :
regtest(argv[optind], transp, "1", p);
else
rawtest(argv[optind]);
}
}
return EXIT_SUCCESS;
}
@ -156,10 +315,75 @@ ATF_TC_BODY(get_svc_addr_udp, tc)
}
ATF_TC(raw);
ATF_TC_HEAD(raw, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks svc raw");
}
ATF_TC_BODY(raw, tc)
{
rawtest(NULL);
}
ATF_TC(tcp);
ATF_TC_HEAD(tcp, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks svc tcp (select)");
}
ATF_TC_BODY(tcp, tc)
{
regtest("localhost", "tcp", "1", 0);
}
ATF_TC(udp);
ATF_TC_HEAD(udp, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks svc udp (select)");
}
ATF_TC_BODY(udp, tc)
{
regtest("localhost", "udp", "1", 0);
}
ATF_TC(tcp_poll);
ATF_TC_HEAD(tcp_poll, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks svc tcp (poll)");
}
ATF_TC_BODY(tcp_poll, tc)
{
regtest("localhost", "tcp", "1", 1);
}
ATF_TC(udp_poll);
ATF_TC_HEAD(udp_poll, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks svc udp (poll)");
}
ATF_TC_BODY(udp_poll, tc)
{
regtest("localhost", "udp", "1", 1);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, get_svc_addr_udp);
ATF_TP_ADD_TC(tp, get_svc_addr_tcp);
ATF_TP_ADD_TC(tp, raw);
ATF_TP_ADD_TC(tp, tcp);
ATF_TP_ADD_TC(tp, udp);
ATF_TP_ADD_TC(tp, tcp_poll);
ATF_TP_ADD_TC(tp, udp_poll);
return atf_no_error();
}

View file

@ -0,0 +1,96 @@
/*
* Based on the OpenBSD test
* Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_open_memstream.c,v 1.2 2014/10/19 11:17:43 justin Exp $");
#include <atf-c.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
ATF_TC(test_open_memstream);
ATF_TC_HEAD(test_open_memstream, tc)
{
atf_tc_set_md_var(tc, "descr", "Test open_memstream functionality");
}
#define OFFSET 16384
const char start[] = "start";
const char hello[] = "hello";
ATF_TC_BODY(test_open_memstream, tc)
{
FILE *fp;
char *buf = (char *)0xff;
size_t size = 0;
off_t off;
int i;
fp = open_memstream(&buf, &size);
ATF_REQUIRE(fp != NULL);
off = ftello(fp);
ATF_CHECK(off == 0);
ATF_CHECK(fflush(fp) == 0);
ATF_CHECK(size == 0);
ATF_CHECK(buf != (char *)0xff);
ATF_CHECK(fseek(fp, -6, SEEK_SET) == -1);
ATF_CHECK(fseek(fp, OFFSET, SEEK_SET) == 0);
ATF_CHECK(fprintf(fp, hello) != EOF);
ATF_CHECK(fflush(fp) != EOF);
ATF_CHECK(size == OFFSET + sizeof(hello)-1);
ATF_CHECK(fseek(fp, 0, SEEK_SET) == 0);
ATF_CHECK(fprintf(fp, start) != EOF);
ATF_CHECK(fflush(fp) != EOF);
ATF_CHECK(size == sizeof(start)-1);
/* Needed for sparse files */
ATF_CHECK(strncmp(buf, start, sizeof(start)-1) == 0);
for (i = sizeof(start)-1; i < OFFSET; i++)
ATF_CHECK(buf[i] == '\0');
ATF_CHECK(memcmp(buf + OFFSET, hello, sizeof(hello)-1) == 0);
/* verify that simply seeking past the end doesn't increase the size */
ATF_CHECK(fseek(fp, 100, SEEK_END) == 0);
ATF_CHECK(fflush(fp) != EOF);
ATF_CHECK(size == OFFSET + sizeof(hello)-1);
ATF_CHECK(fseek(fp, 8, SEEK_SET) == 0);
ATF_CHECK(ftell(fp) == 8);
/* Try to seek backward */
ATF_CHECK(fseek(fp, -1, SEEK_CUR) == 0);
ATF_CHECK(ftell(fp) == 7);
ATF_CHECK(fseek(fp, 5, SEEK_CUR) == 0);
ATF_CHECK(fclose(fp) != EOF);
ATF_CHECK(size == 12);
free(buf);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, test_open_memstream);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $ */
/* $NetBSD: t_getenv.c,v 1.3 2015/02/27 08:55:35 martin Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $");
__RCSID("$NetBSD: t_getenv.c,v 1.3 2015/02/27 08:55:35 martin Exp $");
#include <atf-c.h>
#include <errno.h>
@ -123,7 +123,7 @@ ATF_TC_HEAD(setenv_basic, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test setenv(3), getenv(3), unsetenv(3)");
atf_tc_set_md_var(tc, "timeout", "300");
atf_tc_set_md_var(tc, "timeout", "600");
}
ATF_TC_BODY(setenv_basic, tc)

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $ */
/* $NetBSD: t_posix_memalign.c,v 1.4 2015/11/07 17:35:31 nros Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -32,11 +32,12 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $");
__RCSID("$NetBSD: t_posix_memalign.c,v 1.4 2015/11/07 17:35:31 nros Exp $");
#include <atf-c.h>
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -49,10 +50,10 @@ ATF_TC_HEAD(posix_memalign_basic, tc)
}
ATF_TC_BODY(posix_memalign_basic, tc)
{
size_t size[] = {
static const size_t size[] = {
1, 2, 3, 4, 10, 100, 16384, 32768, 65536
};
size_t align[] = {
static const size_t align[] = {
512, 1024, 16, 32, 64, 4, 2048, 16, 2
};
@ -63,7 +64,7 @@ ATF_TC_BODY(posix_memalign_basic, tc)
int ret;
p = (void*)0x1;
(void)printf("Checking posix_memalign(&p, %zd, %zd)...\n",
(void)printf("Checking posix_memalign(&p, %zu, %zu)...\n",
align[i], size[i]);
ret = posix_memalign(&p, align[i], size[i]);
@ -80,9 +81,61 @@ ATF_TC_BODY(posix_memalign_basic, tc)
}
}
ATF_TC(aligned_alloc_basic);
ATF_TC_HEAD(aligned_alloc_basic, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks aligned_alloc(3)");
}
ATF_TC_BODY(aligned_alloc_basic, tc)
{
static const size_t size[] = {
1, 2, 3, 4, 10, 100, 16384, 32768, 65536, 10000, 0
};
static const size_t align[] = {
512, 1024, 16, 32, 64, 4, 2048, 16, 2, 2048, 0
};
size_t i;
void *p;
for (i = 0; i < __arraycount(size); i++) {
(void)printf("Checking aligned_alloc(%zu, %zu)...\n",
align[i], size[i]);
p = aligned_alloc(align[i], size[i]);
if (p == NULL) {
if (align[i] == 0 || ((align[i] - 1) & align[i]) != 0 ||
size[i] % align[i] != 0) {
ATF_REQUIRE_EQ_MSG(errno, EINVAL,
"aligned_alloc: %s", strerror(errno));
}
else {
ATF_REQUIRE_EQ_MSG(errno, ENOMEM,
"aligned_alloc: %s", strerror(errno));
}
}
else {
ATF_REQUIRE_EQ_MSG(align[i] == 0, false,
"aligned_alloc: success when alignment was not "
"a power of 2");
ATF_REQUIRE_EQ_MSG((align[i] - 1) & align[i], 0,
"aligned_alloc: success when alignment was not "
"a power of 2");
ATF_REQUIRE_EQ_MSG(size[i] % align[i], 0,
"aligned_alloc: success when size was not an "
"integer multiple of alignment");
ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0,
"p = %p", p);
free(p);
}
}
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, posix_memalign_basic);
ATF_TP_ADD_TC(tp, aligned_alloc_basic);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $ */
/* $NetBSD: t_strtod.c,v 1.34 2015/12/22 14:19:25 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
/* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $");
__RCSID("$NetBSD: t_strtod.c,v 1.34 2015/12/22 14:19:25 christos Exp $");
#include <errno.h>
#include <math.h>
@ -42,9 +42,7 @@ __RCSID("$NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $");
#include <atf-c.h>
#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
#include <fenv.h>
#endif
#if !defined(__vax__)
static const char * const inf_strings[] =
@ -246,7 +244,7 @@ ATF_TC_HEAD(strtod_round, tc)
ATF_TC_BODY(strtod_round, tc)
{
#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
#ifdef __HAVE_FENV
/*
* Test that strtod(3) honors the current rounding mode.
@ -270,7 +268,7 @@ ATF_TC_BODY(strtod_round, tc)
atf_tc_fail("strtod(3) did not honor fesetround(3)");
}
#else
atf_tc_skip("Requires one of i386, amd64 or sparc");
atf_tc_skip("Requires <fenv.h> support");
#endif
}

View file

@ -0,0 +1,304 @@
/* $NetBSD: t_strtoi.c,v 1.1 2015/05/01 14:17:56 christos Exp $ */
/*-
* Copyright (c) 2015 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.
*/
/*
* Created by Kamil Rytarowski, vesed on ID:
* NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_strtoi.c,v 1.1 2015/05/01 14:17:56 christos Exp $");
#include <atf-c.h>
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
struct test {
const char *str;
intmax_t res;
int base;
const char *end;
intmax_t lo;
intmax_t hi;
int rstatus;
};
static void check(struct test *, intmax_t, char *, int);
static void
check(struct test *t, intmax_t rv, char *end, int rstatus)
{
if (rv != t->res)
atf_tc_fail_nonfatal("strtoi(%s, &end, %d, %jd, %jd, &rstatus)"
" failed (rv = %jd)", t->str, t->base, t->lo, t->hi, rv);
if (rstatus != t->rstatus)
atf_tc_fail_nonfatal("strtoi(%s, &end, %d, %jd, %jd, &rstatus)"
" failed (rstatus: %d ('%s'))",
t->str, t->base, t->lo, t->hi, rstatus, strerror(rstatus));
if ((t->end != NULL && strcmp(t->end, end) != 0) ||
(t->end == NULL && *end != '\0'))
atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
"strtoi(%s, &end, %d, %jd, %jd, &rstatus)",
end, t->str, t->base, t->lo, t->hi);
}
ATF_TC(strtoi_base);
ATF_TC_HEAD(strtoi_base, tc)
{
atf_tc_set_md_var(tc, "descr", "Test strtoi(3) with different bases");
}
ATF_TC_BODY(strtoi_base, tc)
{
struct test t[] = {
{ "123456789", 123456789, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "111010110111100110100010101",123456789, 2, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "22121022020212200", 123456789, 3, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "13112330310111", 123456789, 4, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "223101104124", 123456789, 5, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "20130035113", 123456789, 6, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "3026236221", 123456789, 7, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "726746425", 123456789, 8, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "277266780", 123456789, 9, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "123456789", 123456789, 10, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "63762A05", 123456789, 11, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "35418A99", 123456789, 12, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "1C767471", 123456789, 13, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "12579781", 123456789, 14, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "AC89BC9", 123456789, 15, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "75BCD15", 123456789, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "1234567", 342391, 8, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "01234567", 342391, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0123456789", 123456789, 10, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0x75bcd15", 123456789, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
};
intmax_t rv;
char *end;
int e;
size_t i;
for (i = 0; i < __arraycount(t); i++) {
errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
if (errno != 0)
atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
e, strerror(e));
check(&t[i], rv, end, e);
}
}
ATF_TC(strtoi_case);
ATF_TC_HEAD(strtoi_case, tc)
{
atf_tc_set_md_var(tc, "descr", "Case insensitivity with strtoi(3)");
}
ATF_TC_BODY(strtoi_case, tc)
{
struct test t[] = {
{ "abcd", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " dcba", 0xdcba, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "abcd dcba", 0xabcd, 16, " dcba",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "abc0x123", 0xabc0, 16, "x123",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "abcd\0x123", 0xabcd, 16, "\0x123",
INTMAX_MIN, INTMAX_MAX, 0 },
{ "ABCD", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "aBcD", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0xABCD", 0xabcd, 16, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "0xABCDX", 0xabcd, 16, "X",
INTMAX_MIN, INTMAX_MAX, ENOTSUP},
};
intmax_t rv;
char *end;
int e;
size_t i;
for (i = 0; i < __arraycount(t); i++) {
errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
if (errno != 0)
atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
e, strerror(e));
check(&t[i], rv, end, e);
}
}
ATF_TC(strtoi_range);
ATF_TC_HEAD(strtoi_range, tc)
{
atf_tc_set_md_var(tc, "descr", "Test ERANGE from strtoi(3)");
}
ATF_TC_BODY(strtoi_range, tc)
{
struct test t[] = {
#if INTMAX_MAX == 0x7fffffffffffffff
{ "1000000000000000000000", INTMAX_MAX, 8, NULL,
INTMAX_MIN, INTMAX_MAX, ERANGE },
{ "9223372036854775808", INTMAX_MAX, 10, NULL,
INTMAX_MIN, INTMAX_MAX, ERANGE },
{ "8000000000000000", INTMAX_MAX, 16, NULL,
INTMAX_MIN, INTMAX_MAX, ERANGE },
#else
#error extend this test to your platform!
#endif
{ "10", 1, 10, NULL,
-1, 1, ERANGE },
{ "10", 11, 10, NULL,
11, 20, ERANGE },
};
intmax_t rv;
char *end;
int e;
size_t i;
for (i = 0; i < __arraycount(t); i++) {
errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
if (errno != 0)
atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
e, strerror(e));
check(&t[i], rv, end, e);
}
}
ATF_TC(strtoi_signed);
ATF_TC_HEAD(strtoi_signed, tc)
{
atf_tc_set_md_var(tc, "descr", "A basic test of strtoi(3)");
}
ATF_TC_BODY(strtoi_signed, tc)
{
struct test t[] = {
{ "1", 1, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " 2", 2, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " 3", 3, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ " -3", -3, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "--1", 0, 0, "--1",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "+-2", 0, 0, "+-2",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "++3", 0, 0, "++3",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "+9", 9, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "+123", 123, 0, NULL,
INTMAX_MIN, INTMAX_MAX, 0 },
{ "-1 3", -1, 0, " 3",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "-1.3", -1, 0, ".3",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "- 3", 0, 0, "- 3",
INTMAX_MIN, INTMAX_MAX, ECANCELED },
{ "+33.", 33, 0, ".",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
{ "30x0", 30, 0, "x0",
INTMAX_MIN, INTMAX_MAX, ENOTSUP },
};
intmax_t rv;
char *end;
int e;
size_t i;
for (i = 0; i < __arraycount(t); i++) {
errno = 0;
rv = strtoi(t[i].str, &end, t[i].base, t[i].lo, t[i].hi, &e);
if (errno != 0)
atf_tc_fail("strtoi(3) changed errno to %d ('%s')",
e, strerror(e));
check(&t[i], rv, end, e);
}
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, strtoi_base);
ATF_TP_ADD_TC(tp, strtoi_case);
ATF_TP_ADD_TC(tp, strtoi_range);
ATF_TP_ADD_TC(tp, strtoi_signed);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $ */
/* $NetBSD: t_strtol.c,v 1.6 2016/06/01 01:12:02 pgoyette Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $");
__RCSID("$NetBSD: t_strtol.c,v 1.6 2016/06/01 01:12:02 pgoyette Exp $");
#include <atf-c.h>
#include <errno.h>
@ -59,7 +59,8 @@ check(struct test *t, long int li, long long int lli, char *end)
atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
"(rv = %lld)", t->str, t->base, lli);
if (t->end != NULL && strcmp(t->end, end) != 0)
if ((t->end != NULL && strcmp(t->end, end) != 0) ||
(t->end == NULL && *end != '\0'))
atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
"strtol(%s, &end, %d)", end, t->str, t->base);
}
@ -89,8 +90,8 @@ ATF_TC_BODY(strtol_base, tc)
{ "12579781", 123456789, 14, NULL },
{ "AC89BC9", 123456789, 15, NULL },
{ "75BCD15", 123456789, 16, NULL },
{ "123456789", 342391, 8, NULL },
{ "0123456789", 342391, 0, NULL },
{ "1234567", 342391, 8, NULL },
{ "01234567", 342391, 0, NULL },
{ "0123456789", 123456789, 10, NULL },
{ "0x75bcd15", 123456789, 0, NULL },
};
@ -121,7 +122,7 @@ ATF_TC_BODY(strtol_case, tc)
{ "abcd", 0xabcd, 16, NULL },
{ " dcba", 0xdcba, 16, NULL },
{ "abcd dcba", 0xabcd, 16, " dcba" },
{ "abc0x123", 0xabc0, 16, NULL },
{ "abc0x123", 0xabc0, 16, "x123" },
{ "abcd\0x123", 0xabcd, 16, "\0x123" },
{ "ABCD", 0xabcd, 16, NULL },
{ "aBcD", 0xabcd, 16, NULL },

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_memset.c,v 1.3 2013/03/17 02:23:31 christos Exp $ */
/* $NetBSD: t_memset.c,v 1.4 2015/09/11 09:25:52 martin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_memset.c,v 1.3 2013/03/17 02:23:31 christos Exp $");
__RCSID("$NetBSD: t_memset.c,v 1.4 2015/09/11 09:25:52 martin Exp $");
#include <sys/stat.h>
@ -42,6 +42,8 @@ static long page = 0;
static void fill(char *, size_t, char);
static bool check(char *, size_t, char);
int zero; /* always zero, but the compiler does not know */
ATF_TC(memset_array);
ATF_TC_HEAD(memset_array, tc)
{
@ -133,6 +135,50 @@ ATF_TC_BODY(memset_nonzero, tc)
free(buf);
}
ATF_TC(memset_zero_size);
ATF_TC_HEAD(memset_zero_size, tc)
{
atf_tc_set_md_var(tc, "descr", "Test memset(3) with zero size");
}
ATF_TC_BODY(memset_zero_size, tc)
{
char buf[1024];
(void)memset(buf, 'x', sizeof(buf));
if (check(buf, sizeof(buf), 'x') != true)
atf_tc_fail("memset(3) did not fill a static buffer");
(void)memset(buf+sizeof(buf)/2, 0, zero);
if (check(buf, sizeof(buf), 'x') != true)
atf_tc_fail("memset(3) with 0 size did change the buffer");
}
ATF_TC(bzero_zero_size);
ATF_TC_HEAD(bzero_zero_size, tc)
{
atf_tc_set_md_var(tc, "descr", "Test bzero(3) with zero size");
}
ATF_TC_BODY(bzero_zero_size, tc)
{
char buf[1024];
(void)memset(buf, 'x', sizeof(buf));
if (check(buf, sizeof(buf), 'x') != true)
atf_tc_fail("memset(3) did not fill a static buffer");
(void)bzero(buf+sizeof(buf)/2, zero);
if (check(buf, sizeof(buf), 'x') != true)
atf_tc_fail("bzero(3) with 0 size did change the buffer");
}
ATF_TC(memset_struct);
ATF_TC_HEAD(memset_struct, tc)
{
@ -202,6 +248,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, memset_nonzero);
ATF_TP_ADD_TC(tp, memset_struct);
ATF_TP_ADD_TC(tp, memset_return);
ATF_TP_ADD_TC(tp, memset_zero_size);
ATF_TP_ADD_TC(tp, bzero_zero_size);
return atf_no_error();
}

View file

@ -0,0 +1,119 @@
/* $NetBSD: cpp_atomic_ops_linkable.cc,v 1.4 2016/02/27 18:50:39 joerg Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Martin Husemann <martin@NetBSD.org>.
*
* 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 is a simple link-time test to verify all builtin atomic sync
* operations for C++ <atomic> are available.
*/
#include <atomic>
#include <machine/types.h> // for __HAVE_ATOMIC64_OPS
template <class T>
class ATest {
public:
ATest() : m_val(0)
{
m_val.exchange(std::atomic<T>(8));
m_val--;
m_val++;
m_val ^= 0x0f;
m_val &= 0x0f;
m_val |= 2;
T tval(1), other(42);
m_val.compare_exchange_weak(tval, other,
std::memory_order_release, std::memory_order_relaxed);
}
private:
volatile std::atomic<T> m_val;
};
#if defined(__clang__) && defined(__sparc64__)
#define NO_SHORT_ATOMICS
#endif
int main(int argc, char **argv)
{
#ifndef NO_SHORT_ATOMICS
ATest<char>();
ATest<signed char>();
ATest<unsigned char>();
ATest<short>();
ATest<unsigned short>();
#endif
ATest<int>();
ATest<unsigned int>();
ATest<long>();
ATest<unsigned long>();
#ifdef __HAVE_ATOMIC64_OPS
ATest<long long>();
ATest<unsigned long long>();
#endif
#ifndef NO_SHORT_ATOMICS
ATest<char16_t>();
#endif
ATest<char32_t>();
ATest<wchar_t>();
#ifndef NO_SHORT_ATOMICS
ATest<int_least8_t>();
ATest<uint_least8_t>();
ATest<int_least16_t>();
ATest<uint_least16_t>();
#endif
ATest<int_least32_t>();
ATest<uint_least32_t>();
#ifdef __HAVE_ATOMIC64_OPS
ATest<int_least64_t>();
ATest<uint_least64_t>();
#endif
#ifndef NO_SHORT_ATOMICS
ATest<int_fast8_t>();
ATest<uint_fast8_t>();
ATest<int_fast16_t>();
ATest<uint_fast16_t>();
#endif
ATest<int_fast32_t>();
ATest<uint_fast32_t>();
#ifdef __HAVE_ATOMIC64_OPS
ATest<int_fast64_t>();
ATest<uint_fast64_t>();
#endif
ATest<intptr_t>();
ATest<uintptr_t>();
ATest<std::size_t>();
ATest<std::ptrdiff_t>();
#ifdef __HAVE_ATOMIC64_OPS
ATest<intmax_t>();
ATest<uintmax_t>();
#endif /* NO_SHORT_ATOMICS */
}

View file

@ -0,0 +1,78 @@
/* $NetBSD: t_bind.c,v 1.3 2015/04/05 23:28:10 rtr Exp $ */
/*
* Copyright (c) 2015 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 <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <atf-c.h>
ATF_TC(bind_foreign_family);
ATF_TC_HEAD(bind_foreign_family, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks that binding a socket "
"with a different address family fails");
}
ATF_TC_BODY(bind_foreign_family, tc)
{
struct sockaddr_in addr;
/* addr.sin_family = AF_UNSPEC = 0 */
memset(&addr, 0, sizeof(addr));
/*
* it is not necessary to initialize sin_{addr,port} since
* those structure members shall not be accessed if bind
* fails correctly.
*/
int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
ATF_REQUIRE(sock != -1);
/* should fail but currently doesn't */
ATF_REQUIRE(-1 == bind(sock, (struct sockaddr *)&addr, sizeof(addr)));
ATF_REQUIRE(EAFNOSUPPORT == errno);
close(sock);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, bind_foreign_family);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_connect.c,v 1.1 2011/11/05 18:19:02 jruoho Exp $ */
/* $NetBSD: t_connect.c,v 1.2 2015/04/05 23:17:41 rtr Exp $ */
/*
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
@ -102,10 +102,39 @@ ATF_TC_BODY(connect_low_port, tc)
#endif
}
ATF_TC(connect_foreign_family);
ATF_TC_HEAD(connect_foreign_family, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks that connecting a socket "
"with a different address family fails");
}
ATF_TC_BODY(connect_foreign_family, tc)
{
struct sockaddr_in addr;
/* addr.sin_family = AF_UNSPEC = 0 */
memset(&addr, 0, sizeof(addr));
/*
* it is not necessary to initialize sin_{addr,port} since
* those structure members shall not be accessed if connect
* fails correctly.
*/
int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
ATF_REQUIRE(sock != -1);
ATF_REQUIRE(-1 == connect(sock, (struct sockaddr *)&addr, sizeof(addr)));
ATF_REQUIRE(EAFNOSUPPORT == errno);
close(sock);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, connect_low_port);
ATF_TP_ADD_TC(tp, connect_foreign_family);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_getrusage.c,v 1.3 2014/09/03 19:24:12 matt Exp $ */
/* $NetBSD: t_getrusage.c,v 1.4 2016/08/05 15:01:39 scole Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_getrusage.c,v 1.3 2014/09/03 19:24:12 matt Exp $");
__RCSID("$NetBSD: t_getrusage.c,v 1.4 2016/08/05 15:01:39 scole Exp $");
#include <sys/resource.h>
#include <sys/time.h>
@ -64,6 +64,8 @@ work(void)
while (n > 0) {
#ifdef __or1k__
asm volatile("l.nop"); /* Do something. */
#elif defined(__ia64__)
asm volatile("nop 0"); /* Do something. */
#else
asm volatile("nop"); /* Do something. */
#endif

View file

@ -0,0 +1,82 @@
/* $NetBSD: t_getsockname.c,v 1.1 2016/07/30 11:03:54 njoly Exp $ */
/*
* Copyright (c) 2016 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/socket.h>
#include <sys/un.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
ATF_TC(getsockname_unix);
ATF_TC_HEAD(getsockname_unix, tc)
{
atf_tc_set_md_var(tc, "descr", "Checks getsockname with UNIX domain");
}
ATF_TC_BODY(getsockname_unix, tc)
{
const char *path = "sock.unix";
int sd;
socklen_t len;
struct sockaddr_un sun;
sd = socket(AF_UNIX, SOCK_STREAM, 0);
ATF_REQUIRE(sd != -1);
len = sizeof(sun);
memset(&sun, 0, sizeof(sun));
ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1);
ATF_CHECK(sun.sun_family == AF_UNIX);
ATF_CHECK(strcmp(sun.sun_path, "") == 0);
len = sizeof(sun);
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
strcpy(sun.sun_path, path);
ATF_REQUIRE(bind(sd, (struct sockaddr *)&sun, len) != -1);
len = sizeof(sun);
memset(&sun, 0, sizeof(sun));
ATF_REQUIRE(getsockname(sd, (struct sockaddr *)&sun, &len) != -1);
ATF_CHECK(sun.sun_family == AF_UNIX);
ATF_CHECK(strcmp(sun.sun_path, path) == 0);
ATF_REQUIRE(close(sd) != -1);
ATF_REQUIRE(unlink(path) != -1);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, getsockname_unix);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_kevent.c,v 1.6 2012/11/29 09:13:44 martin Exp $ */
/* $NetBSD: t_kevent.c,v 1.7 2015/02/05 13:55:37 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_kevent.c,v 1.6 2012/11/29 09:13:44 martin Exp $");
__RCSID("$NetBSD: t_kevent.c,v 1.7 2015/02/05 13:55:37 isaki Exp $");
#include <sys/types.h>
#include <sys/event.h>
@ -179,8 +179,14 @@ ATF_TC_BODY(kqueue_unsupported_fd, tc)
struct kevent ev;
fd = open(DRVCTLDEV, O_RDONLY);
if (fd == -1 && errno == ENOENT)
atf_tc_skip("no " DRVCTLDEV " available for testing");
if (fd == -1) {
switch (errno) {
case ENOENT:
case ENXIO:
atf_tc_skip("no " DRVCTLDEV " available for testing");
break;
}
}
ATF_REQUIRE(fd != -1);
ATF_REQUIRE((kq = kqueue()) != -1);

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $ */
/* $NetBSD: t_mlock.c,v 1.6 2016/08/09 12:02:44 kre Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_mlock.c,v 1.5 2014/02/26 20:49:26 martin Exp $");
__RCSID("$NetBSD: t_mlock.c,v 1.6 2016/08/09 12:02:44 kre Exp $");
#ifdef __FreeBSD__
#include <sys/types.h>
@ -180,6 +180,7 @@ ATF_TC_BODY(mlock_err, tc)
void *invalid_ptr;
#endif
int null_errno = ENOMEM; /* error expected for NULL */
void *buf;
#ifdef __FreeBSD__
#ifdef VM_MIN_ADDRESS
@ -191,31 +192,51 @@ ATF_TC_BODY(mlock_err, tc)
#else
if (sysctlbyname("vm.minaddress", &vmin, &len, NULL, 0) != 0)
atf_tc_fail("failed to read vm.minaddress");
/*
* Any bad address must return ENOMEM (for lock & unlock)
*/
errno = 0;
ATF_REQUIRE_ERRNO(ENOMEM, mlock(NULL, page) == -1);
if (vmin > 0)
null_errno = EINVAL; /* NULL is not inside user VM */
#endif
errno = 0;
ATF_REQUIRE_ERRNO(null_errno, mlock(NULL, page) == -1);
ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)0, page) == -1);
errno = 0;
ATF_REQUIRE_ERRNO(null_errno, mlock((char *)0, page) == -1);
ATF_REQUIRE_ERRNO(ENOMEM, mlock((char *)-1, page) == -1);
errno = 0;
ATF_REQUIRE_ERRNO(EINVAL, mlock((char *)-1, page) == -1);
ATF_REQUIRE_ERRNO(ENOMEM, munlock(NULL, page) == -1);
errno = 0;
ATF_REQUIRE_ERRNO(null_errno, munlock(NULL, page) == -1);
ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)0, page) == -1);
errno = 0;
ATF_REQUIRE_ERRNO(null_errno, munlock((char *)0, page) == -1);
ATF_REQUIRE_ERRNO(ENOMEM, munlock((char *)-1, page) == -1);
buf = malloc(page);
ATF_REQUIRE(buf != NULL);
/*
* unlocking memory that is not locked is an error...
*/
errno = 0;
ATF_REQUIRE_ERRNO(EINVAL, munlock((char *)-1, page) == -1);
ATF_REQUIRE_ERRNO(ENOMEM, munlock(buf, page) == -1);
/* There is no sbrk on AArch64 and RISC-V */
#if !defined(__aarch64__) && !defined(__riscv__)
/*
* These are permitted to fail (EINVAL) but do not on NetBSD
*/
ATF_REQUIRE(mlock((void *)(((uintptr_t)buf) + page/3), page/5) == 0);
ATF_REQUIRE(munlock((void *)(((uintptr_t)buf) + page/3), page/5) == 0);
(void)free(buf);
/*
* Try to create a pointer to an unmapped page - first after current
* brk will likely do.

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $ */
/* $NetBSD: t_mmap.c,v 1.9 2015/02/28 13:57:08 martin Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -55,7 +55,7 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $");
__RCSID("$NetBSD: t_mmap.c,v 1.9 2015/02/28 13:57:08 martin Exp $");
#include <sys/param.h>
#include <sys/mman.h>
@ -461,6 +461,68 @@ ATF_TC_CLEANUP(mmap_truncate, tc)
(void)unlink(path);
}
ATF_TC_WITH_CLEANUP(mmap_truncate_signal);
ATF_TC_HEAD(mmap_truncate_signal, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test mmap(2) ftruncate(2) causing signal");
}
ATF_TC_BODY(mmap_truncate_signal, tc)
{
char *map;
long i;
int fd, sta;
pid_t pid;
fd = open(path, O_RDWR | O_CREAT, 0700);
if (fd < 0)
return;
ATF_REQUIRE(write(fd, "foo\n", 5) == 5);
map = mmap(NULL, page, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
ATF_REQUIRE(map != MAP_FAILED);
sta = 0;
for (i = 0; i < 5; i++)
sta += map[i];
ATF_REQUIRE(sta == 334);
ATF_REQUIRE(ftruncate(fd, 0) == 0);
pid = fork();
ATF_REQUIRE(pid >= 0);
if (pid == 0) {
ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR);
ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR);
sta = 0;
for (i = 0; i < page; i++)
sta += map[i];
/* child never will get this far, but the compiler will
not know, so better use the values calculated to
prevent the access to be optimized out */
ATF_REQUIRE(i == 0);
ATF_REQUIRE(sta == 0);
return;
}
(void)wait(&sta);
ATF_REQUIRE(WIFEXITED(sta) != 0);
if (WEXITSTATUS(sta) == SIGSEGV)
atf_tc_fail("child process got SIGSEGV instead of SIGBUS");
ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS);
ATF_REQUIRE(munmap(map, page) == 0);
ATF_REQUIRE(close(fd) == 0);
}
ATF_TC_CLEANUP(mmap_truncate_signal, tc)
{
(void)unlink(path);
}
ATF_TC(mmap_va0);
ATF_TC_HEAD(mmap_va0, tc)
{
@ -518,6 +580,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, mmap_prot_2);
ATF_TP_ADD_TC(tp, mmap_prot_3);
ATF_TP_ADD_TC(tp, mmap_truncate);
ATF_TP_ADD_TC(tp, mmap_truncate_signal);
ATF_TP_ADD_TC(tp, mmap_va0);
return atf_no_error();

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_mprotect.c,v 1.3 2011/07/20 22:53:44 jym Exp $ */
/* $NetBSD: t_mprotect.c,v 1.4 2016/05/28 14:34:49 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_mprotect.c,v 1.3 2011/07/20 22:53:44 jym Exp $");
__RCSID("$NetBSD: t_mprotect.c,v 1.4 2016/05/28 14:34:49 christos Exp $");
#include <sys/param.h>
#include <sys/mman.h>
@ -78,10 +78,7 @@ paxinit(void)
rv = sysctlbyname("security.pax.mprotect.enabled",
&pax_enabled, &len, NULL, 0);
if (rv != 0)
return false;
return paxset(1, 1);
return rv == 0;
}
static bool
@ -194,6 +191,12 @@ ATF_TC_BODY(mprotect_exec, tc)
break;
}
if (!paxinit())
return;
if (pax_enabled == 1 && pax_global == 1)
atf_tc_skip("PaX MPROTECT restrictions enabled");
/*
* Map a page read/write and copy a trivial assembly function inside.
* We will then change the mapping rights:
@ -262,7 +265,7 @@ ATF_TC_BODY(mprotect_pax, tc)
size_t i;
int rv;
if (paxinit() != true)
if (!paxinit() || !paxset(1, 1))
return;
/*

View file

@ -0,0 +1,63 @@
/* $NetBSD: t_posix_fallocate.c,v 1.1 2015/01/31 23:06:57 christos Exp $ */
/*-
* Copyright 2015, Google 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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/cdefs.h>
__RCSID("$NetBSD: t_posix_fallocate.c,v 1.1 2015/01/31 23:06:57 christos Exp $");
#include <atf-c.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
ATF_TC_WITHOUT_HEAD(ebadf);
ATF_TC_BODY(ebadf, tc)
{
int rc, saved;
errno = 1111;
rc = posix_fallocate(-1, 0, 4096);
saved = errno;
if (rc == -1 && saved != 1111)
atf_tc_fail("Should return error %s without setting errno.",
strerror(saved));
if (rc != EBADF)
atf_tc_fail("returned %s but expected %s.",
strerror(saved), strerror(EBADF));
if (saved != 1111)
atf_tc_fail("errno should be %d but got changed to %d.",
1111, saved);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, ebadf);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_setrlimit.c,v 1.4 2012/06/12 23:56:19 christos Exp $ */
/* $NetBSD: t_setrlimit.c,v 1.5 2016/07/13 09:53:16 njoly Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_setrlimit.c,v 1.4 2012/06/12 23:56:19 christos Exp $");
__RCSID("$NetBSD: t_setrlimit.c,v 1.5 2016/07/13 09:53:16 njoly Exp $");
#include <sys/resource.h>
#include <sys/mman.h>
@ -512,6 +512,25 @@ ATF_TC_BODY(setrlimit_perm, tc)
}
}
ATF_TC(setrlimit_stack);
ATF_TC_HEAD(setrlimit_stack, tc)
{
atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_STACK");
atf_tc_set_md_var(tc, "require.user", "unprivileged");
}
ATF_TC_BODY(setrlimit_stack, tc)
{
struct rlimit res;
/* Ensure soft limit is not bigger than hard limit */
res.rlim_cur = res.rlim_max = 4192256;
ATF_REQUIRE(setrlimit(RLIMIT_STACK, &res) == 0);
ATF_REQUIRE(getrlimit(RLIMIT_STACK, &res) == 0);
ATF_CHECK(res.rlim_cur <= res.rlim_max);
}
ATF_TP_ADD_TCS(tp)
{
@ -527,6 +546,7 @@ ATF_TP_ADD_TCS(tp)
#ifdef __NetBSD__
ATF_TP_ADD_TC(tp, setrlimit_nthr);
#endif
ATF_TP_ADD_TC(tp, setrlimit_stack);
return atf_no_error();
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: t_sigqueue.c,v 1.4 2011/07/07 16:31:11 jruoho Exp $ */
/* $NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_sigqueue.c,v 1.4 2011/07/07 16:31:11 jruoho Exp $");
__RCSID("$NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $");
#include <atf-c.h>
@ -99,17 +99,121 @@ ATF_TC_HEAD(sigqueue_err, tc)
ATF_TC_BODY(sigqueue_err, tc)
{
union sigval sv;
static union sigval sv;
errno = 0;
ATF_REQUIRE_ERRNO(EINVAL, sigqueue(getpid(), -1, sv) == -1);
}
static int signals[] = {
SIGINT, SIGRTMIN + 1, SIGINT, SIGRTMIN + 0, SIGRTMIN + 2,
SIGQUIT, SIGRTMIN + 1
};
#ifdef __arraycount
#define CNT __arraycount(signals)
#else
#define CNT (sizeof(signals) / sizeof(signals[0]))
#endif
static sig_atomic_t count = 0;
static int delivered[CNT];
static void
myhandler(int signo, siginfo_t *info, void *context)
{
delivered[count++] = signo;
}
static int
asc(const void *a, const void *b)
{
const int *ia = a, *ib = b;
return *ib - *ia;
}
/*
* given a array of signals to be delivered in tosend of size len
* place in ordered the signals to be delivered in delivery order
* and return the number of signals that should be delivered
*/
static size_t
sigorder(int *ordered, const int *tosend, size_t len)
{
memcpy(ordered, tosend, len * sizeof(*tosend));
qsort(ordered, len, sizeof(*ordered), asc);
if (len == 1)
return len;
size_t i, j;
for (i = 0, j = 0; i < len - 1; i++) {
if (ordered[i] >= SIGRTMIN)
continue;
if (j == 0)
j = i + 1;
while (ordered[i] == ordered[j] && j < len)
j++;
if (j == len)
break;
ordered[i + 1] = ordered[j];
}
return i + 1;
}
ATF_TC(sigqueue_rt);
ATF_TC_HEAD(sigqueue_rt, tc)
{
atf_tc_set_md_var(tc, "descr", "Test queuing of real-time signals");
}
ATF_TC_BODY(sigqueue_rt, tc)
{
pid_t pid;
union sigval val;
struct sigaction act;
int ordered[CNT];
struct sigaction oact[CNT];
size_t ndelivered;
ndelivered = sigorder(ordered, signals, CNT);
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = myhandler;
sigemptyset(&act.sa_mask);
for (size_t i = 0; i < ndelivered; i++)
ATF_REQUIRE(sigaction(ordered[i], &act, &oact[i]) != -1);
val.sival_int = 0;
pid = getpid();
sigset_t mask, orig;
sigemptyset(&mask);
for (size_t i = 0; i < CNT; i++)
sigaddset(&mask, signals[i]);
ATF_REQUIRE(sigprocmask(SIG_BLOCK, &mask, &orig) != -1);
for (size_t i = 0; i < CNT; i++)
ATF_REQUIRE(sigqueue(pid, signals[i], val) != -1);
ATF_REQUIRE(sigprocmask(SIG_UNBLOCK, &mask, &orig) != -1);
sleep(1);
ATF_REQUIRE_MSG((size_t)count == ndelivered,
"count %zu != ndelivered %zu", (size_t)count, ndelivered);
for (size_t i = 0; i < ndelivered; i++)
ATF_REQUIRE_MSG(ordered[i] == delivered[i],
"%zu: ordered %d != delivered %d",
i, ordered[i], delivered[i]);
for (size_t i = 0; i < ndelivered; i++)
ATF_REQUIRE(sigaction(signals[i], &oact[i], NULL) != -1);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, sigqueue_basic);
ATF_TP_ADD_TC(tp, sigqueue_err);
ATF_TP_ADD_TC(tp, sigqueue_rt);
return atf_no_error();
}

View file

@ -0,0 +1,265 @@
/* $NetBSD: t_wait.c,v 1.4 2016/04/27 21:14:24 christos Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* 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/cdefs.h>
__RCSID("$NetBSD: t_wait.c,v 1.4 2016/04/27 21:14:24 christos Exp $");
#include <sys/wait.h>
#include <sys/resource.h>
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <pwd.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <atf-c.h>
#ifdef __FreeBSD__
#define wrusage __wrusage
#endif
ATF_TC(wait6_invalid);
ATF_TC_HEAD(wait6_invalid, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that wait6(2) returns EINVAL with 0 options");
}
ATF_TC_BODY(wait6_invalid, tc)
{
siginfo_t si;
struct wrusage wru;
int st;
ATF_REQUIRE(wait6(P_ALL, 0, &st, 0, &wru, &si) == -1
&& errno == EINVAL);
}
ATF_TC(wait6_noproc);
ATF_TC_HEAD(wait6_noproc, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that wait6(2) returns ECHILD with for no processes");
}
ATF_TC_BODY(wait6_noproc, tc)
{
siginfo_t si;
struct wrusage wru;
int st;
ATF_REQUIRE(wait6(P_ALL, 0, &st, WEXITED, &wru, &si) == -1
&& errno == ECHILD);
}
ATF_TC(wait6_exited);
ATF_TC_HEAD(wait6_exited, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that wait6(2) handled exiting process and code");
}
ATF_TC_BODY(wait6_exited, tc)
{
siginfo_t si;
struct wrusage wru;
int st;
pid_t pid;
switch (pid = fork()) {
case -1:
ATF_REQUIRE(pid > 0);
case 0:
exit(0x5a5a5a5a);
/*NOTREACHED*/
default:
ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
ATF_REQUIRE(WIFEXITED(st) && WEXITSTATUS(st) == 0x5a);
ATF_REQUIRE(si.si_status = 0x5a5a5a5a);
ATF_REQUIRE(si.si_pid == pid);
ATF_REQUIRE(si.si_uid == getuid());
ATF_REQUIRE(si.si_code == CLD_EXITED);
#ifdef __NetBSD__
printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
(uintmax_t)si.si_utime);
#endif
break;
}
}
ATF_TC(wait6_terminated);
ATF_TC_HEAD(wait6_terminated, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that wait6(2) handled terminated process and code");
}
ATF_TC_BODY(wait6_terminated, tc)
{
siginfo_t si;
struct wrusage wru;
int st;
pid_t pid;
switch (pid = fork()) {
case 0:
sleep(100);
/*FALLTHROUGH*/
case -1:
ATF_REQUIRE(pid > 0);
default:
ATF_REQUIRE(kill(pid, SIGTERM) == 0);
ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGTERM);
ATF_REQUIRE(si.si_status == SIGTERM);
ATF_REQUIRE(si.si_pid == pid);
ATF_REQUIRE(si.si_uid == getuid());
ATF_REQUIRE(si.si_code == CLD_KILLED);
#ifdef __NetBSD__
printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
(uintmax_t)si.si_utime);
#endif
break;
}
}
ATF_TC(wait6_coredumped);
ATF_TC_HEAD(wait6_coredumped, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that wait6(2) handled coredumped process and code");
}
ATF_TC_BODY(wait6_coredumped, tc)
{
siginfo_t si;
struct wrusage wru;
int st;
pid_t pid;
static const struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
switch (pid = fork()) {
case 0:
ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
*(char *)8 = 0;
/*FALLTHROUGH*/
case -1:
ATF_REQUIRE(pid > 0);
default:
ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGSEGV
&& WCOREDUMP(st));
ATF_REQUIRE(si.si_status == SIGSEGV);
ATF_REQUIRE(si.si_pid == pid);
ATF_REQUIRE(si.si_uid == getuid());
ATF_REQUIRE(si.si_code == CLD_DUMPED);
#ifdef __NetBSD__
printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
(uintmax_t)si.si_utime);
#endif
break;
}
}
ATF_TC(wait6_stop_and_go);
ATF_TC_HEAD(wait6_stop_and_go, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test that wait6(2) handled stopped/continued process and code");
}
ATF_TC_BODY(wait6_stop_and_go, tc)
{
siginfo_t si;
struct wrusage wru;
int st;
pid_t pid;
static const struct rlimit rl = { 0, 0 };
ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
switch (pid = fork()) {
case 0:
sleep(100);
/*FALLTHROUGH*/
case -1:
ATF_REQUIRE(pid > 0);
default:
ATF_REQUIRE(kill(pid, SIGSTOP) == 0);
ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid);
ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP);
ATF_REQUIRE(si.si_status == SIGSTOP);
ATF_REQUIRE(si.si_pid == pid);
ATF_REQUIRE(si.si_uid == getuid());
ATF_REQUIRE(si.si_code == CLD_STOPPED);
#ifdef __NetBSD__
printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
(uintmax_t)si.si_utime);
#endif
ATF_REQUIRE(kill(pid, SIGCONT) == 0);
ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid);
ATF_REQUIRE(WIFCONTINUED(st));
ATF_REQUIRE(si.si_status == SIGCONT);
ATF_REQUIRE(si.si_pid == pid);
ATF_REQUIRE(si.si_uid == getuid());
ATF_REQUIRE(si.si_code == CLD_CONTINUED);
#ifdef __NetBSD__
printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
(uintmax_t)si.si_utime);
#endif
ATF_REQUIRE(kill(pid, SIGQUIT) == 0);
ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT);
ATF_REQUIRE(si.si_status == SIGQUIT);
ATF_REQUIRE(si.si_pid == pid);
ATF_REQUIRE(si.si_uid == getuid());
ATF_REQUIRE(si.si_code == CLD_KILLED);
#ifdef __NetBSD__
printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
(uintmax_t)si.si_utime);
#endif
break;
}
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, wait6_invalid);
ATF_TP_ADD_TC(tp, wait6_noproc);
ATF_TP_ADD_TC(tp, wait6_exited);
ATF_TP_ADD_TC(tp, wait6_terminated);
ATF_TP_ADD_TC(tp, wait6_coredumped);
ATF_TP_ADD_TC(tp, wait6_stop_and_go);
return atf_no_error();
}

Some files were not shown because too many files have changed in this diff Show more