#
# Automated Testing Framework (atf)
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
#
# 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.
#
{
Content-Type: application/X-atf-atffile; version="1"
prop: test-suite = atf
EOF
done
}
{
}
{
# TODO: This really, really, really must use real test programs.
cat >${1} <<EOF
#! $(atf-config -t atf_shell)
while [ \${#} -gt 0 ]; do
case \${1} in
-l)
echo 'Content-Type: application/X-atf-tp; version="1"'
echo
EOF
cnt=1
echo "echo 'ident: tc${cnt}'" >>${1}
done
cat >>${1} <<EOF
exit 0
;;
-r*)
resfile=\$(echo \${1} | cut -d r -f 2-)
;;
esac
testcase=\$(echo \${1} | cut -d : -f 1)
shift
done
EOF
cat >>${1}
}
{
cat >${1} <<EOF
#! /usr/bin/env atf-sh
do_mount() {
platform=\$(uname)
case \${platform} in
Linux|NetBSD)
mount -t tmpfs tmpfs \${1} || atf_fail "Mount failed"
;;
FreeBSD)
mdmfs -s 16m md \${1} || atf_fail "Mount failed"
;;
SunOS)
mount -F tmpfs tmpfs \$(pwd)/\${1} || atf_fail "Mount failed"
;;
*)
atf_fail "create_mount_helper called for an unsupported platform."
;;
esac
}
atf_test_case main
main_head() {
atf_set "require.user" "root"
}
main_body() {
EOF
cat >>${1}
cat >>${1} <<EOF
}
atf_init_test_cases()
{
atf_add_test_case main
}
EOF
}
{
"within atf-run"
}
{
}
{
"order"
}
{
echo "First: read system-wide common.conf."
cat >etc/common.conf <<EOF
Content-Type: application/X-atf-config; version="1"
1st = "sw common"
2nd = "sw common"
3rd = "sw common"
4th = "sw common"
EOF
-e ignore -x \
"ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
echo "Second: read system-wide <test-suite>.conf."
Content-Type: application/X-atf-config; version="1"
1st = "sw atf"
EOF
-e ignore -x \
"ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
echo "Third: read user-specific common.conf."
cat >.atf/common.conf <<EOF
Content-Type: application/X-atf-config; version="1"
2nd = "us common"
EOF
-e ignore -x \
"ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
echo "Fourth: read user-specific <test-suite>.conf."
Content-Type: application/X-atf-config; version="1"
3rd = "us atf"
EOF
-e ignore -x \
"ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
}
{
"overrides the values in configuration files"
}
{
echo "Checking that 'testvar' is not defined."
"ATF_CONFDIR=$(pwd)/etc atf-run helper"
echo "Checking that defining 'testvar' trough '-v' works."
"ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='a value' helper"
echo "Checking that defining 'testvar' trough the configuration" \
"file works."
cat >etc/common.conf <<EOF
Content-Type: application/X-atf-config; version="1"
testvar = "value in conf file"
EOF
"ATF_CONFDIR=$(pwd)/etc atf-run helper"
echo "Checking that defining 'testvar' trough -v overrides the" \
"configuration file."
"ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='a value' helper"
}
{
"are recognized and that they take the lowest priority"
}
{
echo "Checking that 'testvar' is not defined."
"ATF_CONFDIR=$(pwd)/etc atf-run helper"
echo "Checking that defining 'testvar' trough the Atffile works."
"ATF_CONFDIR=$(pwd)/etc atf-run helper"
echo "Checking that defining 'testvar' trough the configuration" \
"file overrides the one in the Atffile."
cat >etc/common.conf <<EOF
Content-Type: application/X-atf-config; version="1"
testvar = "value in conf file"
EOF
"ATF_CONFDIR=$(pwd)/etc atf-run helper"
echo "Checking that defining 'testvar' trough -v overrides the" \
"one in the Atffile."
"ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='new value' helper"
}
{
"inherited by other Atffiles."
}
{
echo "Checking that 'testvar' is not inherited."
echo "Checking that defining 'testvar' in the correct Atffile works."
"ATF_CONFDIR=$(pwd)/etc atf-run"
}
{
atf_set "descr" "Tests that all streams are properly captured"
}
{
}
{
atf_set "descr" "Tests for a race condition in stream multiplexing"
}
{
for i in 1 2 3 4 5; do
echo "Attempt ${i}"
done
}
{
"expect features"
}
{
}
{
"do not create the results file"
}
{
create_helper_stdin helper 1 <<EOF
test -f \${resfile} && echo "resfile found"
exit 0
EOF
re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
}
{
"provide a bogus results output as broken programs"
}
{
# We produce two errors from the header to ensure that the parse
# errors are printed on a single line on the output file. Printing
# them on separate lines would be incorrect.
create_helper_stdin helper 1 <<EOF
echo 'line 1' >\${resfile}
echo 'line 2' >>\${resfile}
exit 0
EOF
re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
}
{
"provide a bogus test case list"
}
{
#! $(atf-config -t atf_shell)
while [ \${#} -gt 0 ]; do
if [ \${1} = -l ]; then
echo 'Content-Type: application/X-atf-tp; version="1"'
echo
echo 'foo: bar'
exit 0
else
shift
fi
done
exit 0
EOF
re='^tp-end: [0-9][0-9]*\.[0-9]*, helper,'
re="${re} Invalid format for test case list:.*First property.*ident"
}
{
"test cases as errors"
}
{
create_helper_stdin helper 0 <<EOF
echo 'Content-Type: application/X-atf-tp; version="1"'
echo
exit 1
EOF
re='^tp-end: [0-9][0-9]*\.[0-9]*, helper,'
}
{
"programs correctly"
}
{
create_helper_stdin helper 1 <<EOF
echo "failed: Yes, it failed" >\${resfile}
exit 0
EOF
re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
}
{
"correctly regardless of their actual results"
}
{
create_helper_stdin helper 2 <<EOF
echo "passed" >\${resfile}
case \${testcase} in
tc1) ;;
tc2) echo "Killing myself!" ; kill -9 \$\$ ;;
esac
EOF
re='^tc-end: [0-9][0-9]*\.[0-9]*, tc2,'
}
{
"can be overriden by the user"
}
{
echo "Checking default hooks"
"ATF_CONFDIR=$(pwd)/atf atf-run"
echo "Checking the system-wide info_start hook"
cat >atf/atf-run.hooks <<EOF
info_start_hook()
{
atf_tps_writer_info "test" "sw value"
}
EOF
-e empty -x \
"ATF_CONFDIR=$(pwd)/atf atf-run"
echo "Checking the user-specific info_start hook"
cat >.atf/atf-run.hooks <<EOF
info_start_hook()
{
atf_tps_writer_info "test" "user value"
}
EOF
-e empty -x \
"ATF_CONFDIR=$(pwd)/atf atf-run"
echo "Checking the system-wide info_end hook"
cat >atf/atf-run.hooks <<EOF
info_end_hook()
{
atf_tps_writer_info "test" "sw value"
}
EOF
-e empty -x \
"ATF_CONFDIR=$(pwd)/atf atf-run"
echo "Checking the user-specific info_end hook"
cat >.atf/atf-run.hooks <<EOF
info_end_hook()
{
atf_tps_writer_info "test" "user value"
}
EOF
-e empty -x \
"ATF_CONFDIR=$(pwd)/atf atf-run"
}
{
"to known sane values"
}
{
undef_vars="LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY \
LC_NUMERIC LC_TIME"
def_vars="HOME TZ"
mangleenv="env"
for v in ${undef_vars} ${def_vars}; do
mangleenv="${mangleenv} ${v}=bogus-value"
done
# We must ignore stderr in this call (instead of specifying -e empty)
# because, when atf-run invokes the shell to run the hooks, we may get
# error messages about an invalid locale. This happens, at least, when
# the shell is bash 4.x.
for v in ${undef_vars}; do
done
done
}
{
atf_set "descr" "Tests that atf-run sets HOME to a sane and valid value"
}
{
}
{
atf_set "descr" "Tests that atf-run nullifies the stdin of test cases"
}
{
}
{
atf_set "descr" "Tests that atf-run sets the umask to a known value"
}
{
create_helper umask
"umask 0000 && atf-run helper"
}
{
"case when the test case result is passed"
}
{
atf_fail "Test case cleanup did not run correctly"
fi
}
{
"case when the test case result is failed"
}
{
atf_fail "Test case cleanup did not run correctly"
fi
}
{
"case when the test case result is skipped"
}
{
atf_fail "Test case cleanup did not run correctly"
fi
}
{
"work directory as the body so that they can share data"
}
{
}
{
"a termination signal while running the body"
}
{
: # TODO: Write this.
}
{
"mount points"
atf_set "require.user" "root"
}
{
create_mount_helper helper <<EOF
echo \$(pwd) >\${ROOT}
mkdir foo
mkdir foo/bar
mkdir foo/bar/mnt
do_mount foo/bar/mnt
mkdir foo/baz
do_mount foo/baz
mkdir foo/baz/foo
mkdir foo/baz/foo/bar
do_mount foo/baz/foo/bar
EOF
;;
*)
# XXX Possibly specify in meta-data too.
atf_skip "Test unimplemented in this platform (${platform})"
;;
esac
}
{
"symlinks, which may live in another device and thus" \
"be treated as mount points"
atf_set "require.user" "root"
}
{
create_mount_helper helper <<EOF
echo \$(pwd) >\${ROOT}
atf_check -s eq:0 -o empty -e empty mkdir foo
atf_check -s eq:0 -o empty -e empty mkdir foo/bar
do_mount foo/bar
atf_check -s eq:0 -o empty -e empty touch a
atf_check -s eq:0 -o empty -e empty ln -s "\$(pwd)/a" foo/bar
EOF
;;
*)
# XXX Possibly specify in meta-data too.
atf_skip "Test unimplemented in this platform (${platform})"
;;
esac
}
{
atf_set "descr" "Tests that atf-run validates the require.arch property"
}
{
echo "Checking for the real architecture"
echo "Checking for a fictitious architecture"
export ATF_ARCH=fictitious
echo "Triggering some failures"
}
{
atf_set "descr" "Tests that atf-run validates the require.config property"
}
{
}
{
atf_set "descr" "Tests that atf-run validates the require.files property"
}
{
echo "Checking absolute paths"
echo "Checking that relative paths are not allowed"
}
{
atf_set "descr" "Tests that atf-run validates the require.machine property"
}
{
echo "Checking for the real machine type"
machine=$(atf-config -t atf_machine)
echo "Checking for a fictitious machine type"
export ATF_MACHINE=fictitious
echo "Triggering some failures"
}
{
atf_set "descr" "Tests that atf-run validates the require.progs property"
}
{
echo "Checking absolute paths"
echo "Checking that relative paths are not allowed"
echo "Check plain file names, searching them in the PATH."
}
{
"when it is set to 'root'"
}
{
else
fi
}
{
"when it is set to 'root'"
}
{
else
fi
}
{
"when it is set to 'root'"
}
{
}
{
atf_set "descr" "Tests that atf-run kills a test case that times out"
}
{
if [ -f finished ]; then
atf_fail "Test case was not killed after time out"
fi
}
{
"that forks, exits, but the child process hangs"
}
{
"been forcibly terminated" || true
}
{
}
{
}
{
}
# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4