a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# Copyright (c) 2007 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# All rights reserved.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Redistribution and use in source and binary forms, with or without
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# modification, are permitted provided that the following conditions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# are met:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# 1. Redistributions of source code must retain the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# notice, this list of conditions and the following disclaimer.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# 2. Redistributions in binary form must reproduce the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# notice, this list of conditions and the following disclaimer in the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# documentation and/or other materials provided with the distribution.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# GLOBAL VARIABLES
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Values for the expect property.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntExpect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntExpect_Reason=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# A boolean variable that indicates whether we are parsing a test case's
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# head or not.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntParsing_Head=false
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# The program name.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntProg_Name=${0##*/}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# The file to which the test case will print its result.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntResults_File=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# The test program's source directory: i.e. where its auxiliary data files
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# and helper utilities can be found. Can be overriden through the '-s' flag.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntSource_Dir="$(dirname ${0})"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Indicates the test case we are currently processing.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTest_Case=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# List of meta-data variables for the current test case.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTest_Case_Vars=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# The list of all test cases provided by the test program.
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTest_Cases=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# PUBLIC INTERFACE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_add_test_case tc-name
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Adds the given test case to the list of test cases that form the test
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# program. The name provided here must be accompanied by two functions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# named after it: <tc-name>_head and <tc-name>_body, and optionally by
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# a <tc-name>_cleanup function.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_add_test_case()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Test_Cases="${Test_Cases} ${1}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_check cmd expcode expout experr
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Executes atf-check with given arguments and automatically calls
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_fail in case of failure.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_check()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ${Atf_Check} "${@}" || \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "atf-check failed; see the output of the test for details"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# atf_check_equal expected_expression actual_expression
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# Checks that expected_expression's value matches actual_expression's
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# and, if not, raises an error. Ideally expected_expression and
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# actual_expression should be provided quoted (not expanded) so that
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# the error message is helpful; otherwise it will only show the values,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews# not the expressions themselves.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_check_equal()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval _val1=\"${1}\"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval _val2=\"${2}\"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt test "${_val1}" = "${_val2}" || \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "${1} != ${2} (${_val1} != ${_val2})"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_config_get varname [defvalue]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Prints the value of a configuration variable. If it is not
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# defined, prints the given default value.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_config_get()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _varname="__tc_config_var_$(_atf_normalize ${1})"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ ${#} -eq 1 ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval _value=\"\${${_varname}-__unset__}\"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt [ "${_value}" = __unset__ ] && \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 1 "Could not find configuration variable \`${1}'"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo ${_value}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt elif [ ${#} -eq 2 ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval echo \${${_varname}-${2}}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt else
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 1 "Incorrect number of parameters for atf_config_get"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_config_has varname
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Returns a boolean indicating if the given configuration variable is
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# defined or not.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_config_has()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _varname="__tc_config_var_$(_atf_normalize ${1})"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval _value=\"\${${_varname}-__unset__}\"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt [ "${_value}" != __unset__ ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_expect_death reason
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the expectations to 'death'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_expect_death()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_validate_expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=death
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "expected_death: ${*}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_expect_timeout reason
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the expectations to 'timeout'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_expect_timeout()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_validate_expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=timeout
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "expected_timeout: ${*}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_expect_exit exitcode reason
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the expectations to 'exit'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_expect_exit()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _exitcode="${1}"; shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_validate_expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=exit
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt if [ "${_exitcode}" = "-1" ]; then
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "expected_exit: ${*}"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt else
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "expected_exit(${_exitcode}): ${*}"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_expect_fail reason
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the expectations to 'fail'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_expect_fail()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_validate_expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=fail
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect_Reason="${*}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_expect_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the expectations to 'pass'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_expect_pass()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_validate_expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect_Reason=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_expect_signal signo reason
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the expectations to 'signal'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_expect_signal()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _signo="${1}"; shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_validate_expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=signal
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt if [ "${_signo}" = "-1" ]; then
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "expected_signal: ${*}"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt else
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "expected_signal(${_signo}): ${*}"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_expected_failure msg1 [.. msgN]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Makes the test case report an expected failure with the given error
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# message. Multiple words can be provided, which are concatenated with
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# a single blank space.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_expected_failure()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "expected_failure: ${Expect_Reason}: ${*}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit 0
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_fail msg1 [.. msgN]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Makes the test case fail with the given error message. Multiple
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# words can be provided, in which case they are joined by a single
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# blank space.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_fail()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case "${Expect}" in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fail)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_expected_failure "${@}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt pass)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "failed: ${*}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit 1
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 128 "Unreachable"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_get varname
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Prints the value of a test case-specific variable. Given that one
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# should not get the value of non-existent variables, it is fine to
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# always use this function as 'val=$(atf_get var)'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_get()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval echo \${__tc_var_${Test_Case}_$(_atf_normalize ${1})}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_get_srcdir
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Prints the value of the test case's source directory.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_get_srcdir()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt echo ${Source_Dir}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Makes the test case pass. Shouldn't be used in general, as a test
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# case that does not explicitly fail is assumed to pass.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_pass()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case "${Expect}" in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fail)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "Test case was expecting a failure but got a pass instead"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt pass)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile passed
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit 0
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 128 "Unreachable"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_require_prog prog
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Checks that the given program name (either provided as an absolute
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# path or as a plain file name) can be found. If it is not available,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# automatically skips the test case with an appropriate message.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Relative paths are not allowed because the test case cannot predict
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# where it will be executed from.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_require_prog()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _prog=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case ${1} in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /*)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _prog="${1}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt [ -x ${_prog} ] || \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_skip "The required program ${1} could not be found"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt */*)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "atf_require_prog does not accept relative path names \`${1}'"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _prog=$(_atf_find_in_path "${1}")
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt [ -n "${_prog}" ] || \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_skip "The required program ${1} could not be found" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "in the PATH"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_set varname val1 [.. valN]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the test case's variable 'varname' to the specified values
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# which are concatenated using a single blank space. This function
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# is supposed to be called form the test case's head only.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_set()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ${Parsing_Head} || \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 128 "atf_set called from the test case's body"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Test_Case_Vars="${Test_Case_Vars} ${1}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _var=$(_atf_normalize ${1}); shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval __tc_var_${Test_Case}_${_var}=\"\${*}\"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_skip msg1 [.. msgN]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Skips the test case because of the reason provided. Multiple words
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# can be given, in which case they are joined by a single blank space.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_skip()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile "skipped: ${*}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit 0
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# atf_test_case tc-name cleanup
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Defines a new test case named tc-name. The name provided here must be
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# accompanied by two functions named after it: <tc-name>_head and
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# <tc-name>_body. If cleanup is set to 'cleanup', then this also expects
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# a <tc-name>_cleanup function to be defined.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_test_case()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval "${1}_head() { :; }"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt eval "${1}_body() { atf_fail 'Test case not implemented'; }"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ "${2}" = cleanup ]; then
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt eval __has_cleanup_${1}=true
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval "${1}_cleanup() { :; }"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt else
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval "${1}_cleanup() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 1 'Test case ${1} declared without a cleanup routine'; }"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# PRIVATE INTERFACE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_config_set varname val1 [.. valN]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the test case's private variable 'varname' to the specified
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# values which are concatenated using a single blank space.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_config_set()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _var=$(_atf_normalize ${1}); shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt eval __tc_config_var_${_var}=\"\${*}\"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Config_Vars="${Config_Vars} __tc_config_var_${_var}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_config_set_str varname=val
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Sets the test case's private variable 'varname' to the specified
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# value. The parameter is of the form 'varname=val'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_config_set_from_str()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _oldifs=${IFS}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt IFS='='
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt set -- ${*}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _var=${1}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _val="${@}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt IFS=${_oldifs}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_config_set "${_var}" "${_val}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# _atf_create_resfile contents
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Creates the results file.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_create_resfile()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ -n "${Results_File}" ]; then
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt echo "${*}" >"${Results_File}" || \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 128 "Cannot create results file '${Results_File}'"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt else
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt echo "${*}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_error error_code [msg1 [.. msgN]]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Prints the given error message (which can be composed of multiple
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# arguments, in which case are joined by a single space) and exits
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# with the specified error code.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This must not be used by test programs themselves (hence making
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# the function private) to indicate a test case's failure. They
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# have to use the atf_fail function.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_error()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _error_code="${1}"; shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "${Prog_Name}: ERROR:" "$@" 1>&2
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit ${_error_code}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt#
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# _atf_warning msg1 [.. msgN]
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt#
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# Prints the given warning message (which can be composed of multiple
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# arguments, in which case are joined by a single space).
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt#
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt_atf_warning()
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt echo "${Prog_Name}: WARNING:" "$@" 1>&2
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt}
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_find_in_path program
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Looks for a program in the path and prints the full path to it or
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# nothing if it could not be found. It also returns true in case of
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# success.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_find_in_path()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _prog="${1}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _oldifs=${IFS}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt IFS=:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for _dir in ${PATH}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ -x ${_dir}/${_prog} ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt IFS=${_oldifs}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo ${_dir}/${_prog}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return 0
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt IFS=${_oldifs}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return 1
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_has_tc name
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Returns true if the given test case exists.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_has_tc()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for _tc in ${Test_Cases}; do
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt [ "${_tc}" != "${1}" ] || return 0
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return 1
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_list_tcs
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Describes all test cases and prints the list to the standard output.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_list_tcs()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo 'Content-Type: application/X-atf-tp; version="1"'
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt set -- ${Test_Cases}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt while [ ${#} -gt 0 ]; do
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_parse_head ${1}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "ident: $(atf_get ident)"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for _var in ${Test_Case_Vars}; do
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt [ "${_var}" != "ident" ] && echo "${_var}: $(atf_get ${_var})"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt [ ${#} -gt 1 ] && echo
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_normalize str
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Normalizes a string so that it is a valid shell variable name.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_normalize()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo ${1} | tr .- __
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_parse_head tcname
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Evaluates a test case's head to gather its variables and prepares the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# test program to run it.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_parse_head()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Parsing_Head=true
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Test_Case="${1}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Test_Case_Vars=
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if _atf_has_cleanup "${1}"; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_set has.cleanup "true"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ${1}_head
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_set ident "${1}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Parsing_Head=false
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_run_tc tc
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Runs the specified test case. Prints its exit status to the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# standard output and returns a boolean indicating if the test was
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# successful or not.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_run_tc()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case ${1} in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *:*)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _tcname=${1%%:*}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _tcpart=${1#*:}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ "${_tcpart}" != body -a "${_tcpart}" != cleanup ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_syntax_error "Unknown test case part \`${_tcpart}'"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _tcname=${1}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _tcpart=body
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_has_tc "${_tcname}" || _atf_syntax_error "Unknown test case \`${1}'"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt if [ "${__RUNNING_INSIDE_ATF_RUN}" != "internal-yes-value" ]; then
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews _atf_warning "Running test cases outside of kyua(1) is unsupported"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_warning "No isolation nor timeout control is being applied;" \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt "you may get unexpected failures; see atf-test-case(4)"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_parse_head ${_tcname}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt case ${_tcpart} in
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt body)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt if ${_tcname}_body; then
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_validate_expect
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_create_resfile passed
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt else
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt Expect=pass
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_fail "Test case body returned a non-ok exit code, but" \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt "this is not allowed"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt fi
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ;;
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt cleanup)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt if _atf_has_cleanup "${_tcname}"; then
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ${_tcname}_cleanup || _atf_error 128 "The test case cleanup" \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt "returned a non-ok exit code, but this is not allowed"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt fi
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ;;
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt *)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _atf_error 128 "Unknown test case part"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ;;
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_syntax_error msg1 [.. msgN]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Formats and prints a syntax error message and terminates the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# program prematurely.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_syntax_error()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "${Prog_Name}: ERROR: ${@}" 1>&2
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "${Prog_Name}: See atf-test-program(1) for usage details." 1>&2
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit 1
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_has_cleanup tc-name
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Returns a boolean indicating if the given test case has a cleanup
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# routine or not.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_has_cleanup()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt _found=true
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt eval "[ x\"\${__has_cleanup_${1}}\" = xtrue ] || _found=false"
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt [ "${_found}" = true ]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_validate_expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Ensures that the current test case state is correct regarding the expect
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# status.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_validate_expect()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case "${Expect}" in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt death)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "Test case was expected to terminate abruptly but it" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "continued execution"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "Test case was expected to exit cleanly but it continued" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "execution"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fail)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "Test case was expecting a failure but none were raised"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt pass)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt signal)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "Test case was expected to receive a termination signal" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "but it continued execution"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt timeout)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Expect=pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fail "Test case was expected to hang but it continued execution"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 128 "Unreachable"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# _atf_warning [msg1 [.. msgN]]
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Prints the given warning message (which can be composed of multiple
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# arguments, in which case are joined by a single space).
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# This must not be used by test programs themselves (hence making
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# the function private).
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt_atf_warning()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt echo "${Prog_Name}: WARNING:" "$@" 1>&2
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# main [options] test_case
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Test program's entry point.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntmain()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Process command-line options first.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _numargs=${#}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _lflag=false
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt while getopts :lr:s:v: arg; do
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case ${arg} in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt l)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _lflag=true
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt r)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Results_File=${OPTARG}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Source_Dir=${OPTARG}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_config_set_from_str "${OPTARG}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt \?)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_syntax_error "Unknown option -${OPTARG}."
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # NOTREACHED
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt shift `expr ${OPTIND} - 1`
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case ${Source_Dir} in
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /*)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt Source_Dir=$(pwd)/${Source_Dir}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ;;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt [ -f ${Source_Dir}/${Prog_Name} ] || \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_error 1 "Cannot find the test program in the source" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "directory \`${Source_Dir}'"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Call the test program's hook to register all available test cases.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_init_test_cases
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # Run or list test cases.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if `${_lflag}`; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ ${#} -gt 0 ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_syntax_error "Cannot provide test case names with -l"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_list_tcs
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt else
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if [ ${#} -eq 0 ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_syntax_error "Must provide a test case name"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt elif [ ${#} -gt 1 ]; then
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_syntax_error "Cannot provide more than one test case name"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt else
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt _atf_run_tc "${1}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fi
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4