111be35a1SLionel Sambuc# 211be35a1SLionel Sambuc# Automated Testing Framework (atf) 311be35a1SLionel Sambuc# 411be35a1SLionel Sambuc# Copyright (c) 2007 The NetBSD Foundation, Inc. 511be35a1SLionel Sambuc# All rights reserved. 611be35a1SLionel Sambuc# 711be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 811be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 911be35a1SLionel Sambuc# are met: 1011be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 1111be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 1211be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 1311be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 1411be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 1511be35a1SLionel Sambuc# 1611be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 1711be35a1SLionel Sambuc# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 1811be35a1SLionel Sambuc# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1911be35a1SLionel Sambuc# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2011be35a1SLionel Sambuc# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 2111be35a1SLionel Sambuc# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2211be35a1SLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 2311be35a1SLionel Sambuc# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2411be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2511be35a1SLionel Sambuc# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2611be35a1SLionel Sambuc# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2711be35a1SLionel Sambuc# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811be35a1SLionel Sambuc# 2911be35a1SLionel Sambuc 3011be35a1SLionel Sambuc# ------------------------------------------------------------------------- 3111be35a1SLionel Sambuc# Helper tests for "t_atf_check". 3211be35a1SLionel Sambuc# ------------------------------------------------------------------------- 3311be35a1SLionel Sambuc 3411be35a1SLionel Sambucatf_test_case atf_check_info_ok 3511be35a1SLionel Sambucatf_check_info_ok_head() 3611be35a1SLionel Sambuc{ 3711be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 3811be35a1SLionel Sambuc} 3911be35a1SLionel Sambucatf_check_info_ok_body() 4011be35a1SLionel Sambuc{ 4111be35a1SLionel Sambuc atf_check -s eq:0 -o empty -e empty true 4211be35a1SLionel Sambuc} 4311be35a1SLionel Sambuc 4411be35a1SLionel Sambucatf_test_case atf_check_info_fail 4511be35a1SLionel Sambucatf_check_info_fail_head() 4611be35a1SLionel Sambuc{ 4711be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 4811be35a1SLionel Sambuc} 4911be35a1SLionel Sambucatf_check_info_fail_body() 5011be35a1SLionel Sambuc{ 5111be35a1SLionel Sambuc # In Solaris, /usr/bin/false returns 255 rather than 1. Use the 5211be35a1SLionel Sambuc # built-in version for the check. 5311be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e empty sh -c "false" 5411be35a1SLionel Sambuc} 5511be35a1SLionel Sambuc 5611be35a1SLionel Sambucatf_test_case atf_check_expout_mismatch 5711be35a1SLionel Sambucatf_check_expout_mismatch_head() 5811be35a1SLionel Sambuc{ 5911be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 6011be35a1SLionel Sambuc} 6111be35a1SLionel Sambucatf_check_expout_mismatch_body() 6211be35a1SLionel Sambuc{ 6311be35a1SLionel Sambuc cat >expout <<SECONDEOF 6411be35a1SLionel Sambucfoo 6511be35a1SLionel SambucSECONDEOF 6611be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty echo bar 6711be35a1SLionel Sambuc} 6811be35a1SLionel Sambuc 6911be35a1SLionel Sambucatf_test_case atf_check_experr_mismatch 7011be35a1SLionel Sambucatf_check_experr_mismatch_head() 7111be35a1SLionel Sambuc{ 7211be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 7311be35a1SLionel Sambuc} 7411be35a1SLionel Sambucatf_check_experr_mismatch_body() 7511be35a1SLionel Sambuc{ 7611be35a1SLionel Sambuc cat >experr <<SECONDEOF 7711be35a1SLionel Sambucfoo 7811be35a1SLionel SambucSECONDEOF 7911be35a1SLionel Sambuc atf_check -s eq:0 -o empty -e file:experr -x 'echo bar 1>&2' 8011be35a1SLionel Sambuc} 8111be35a1SLionel Sambuc 8211be35a1SLionel Sambucatf_test_case atf_check_null_stdout 8311be35a1SLionel Sambucatf_check_null_stdout_head() 8411be35a1SLionel Sambuc{ 8511be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 8611be35a1SLionel Sambuc} 8711be35a1SLionel Sambucatf_check_null_stdout_body() 8811be35a1SLionel Sambuc{ 8911be35a1SLionel Sambuc atf_check -s eq:0 -o empty -e empty echo "These are the contents" 9011be35a1SLionel Sambuc} 9111be35a1SLionel Sambuc 9211be35a1SLionel Sambucatf_test_case atf_check_null_stderr 9311be35a1SLionel Sambucatf_check_null_stderr_head() 9411be35a1SLionel Sambuc{ 9511be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 9611be35a1SLionel Sambuc} 9711be35a1SLionel Sambucatf_check_null_stderr_body() 9811be35a1SLionel Sambuc{ 9911be35a1SLionel Sambuc atf_check -s eq:0 -o empty -e empty -x 'echo "These are the contents" 1>&2' 10011be35a1SLionel Sambuc} 10111be35a1SLionel Sambuc 10211be35a1SLionel Sambucatf_test_case atf_check_equal_ok 10311be35a1SLionel Sambucatf_check_equal_ok_head() 10411be35a1SLionel Sambuc{ 10511be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 10611be35a1SLionel Sambuc} 10711be35a1SLionel Sambucatf_check_equal_ok_body() 10811be35a1SLionel Sambuc{ 10911be35a1SLionel Sambuc atf_check_equal a a 11011be35a1SLionel Sambuc} 11111be35a1SLionel Sambuc 11211be35a1SLionel Sambucatf_test_case atf_check_equal_fail 11311be35a1SLionel Sambucatf_check_equal_fail_head() 11411be35a1SLionel Sambuc{ 11511be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 11611be35a1SLionel Sambuc} 11711be35a1SLionel Sambucatf_check_equal_fail_body() 11811be35a1SLionel Sambuc{ 11911be35a1SLionel Sambuc atf_check_equal a b 12011be35a1SLionel Sambuc} 12111be35a1SLionel Sambuc 12211be35a1SLionel Sambucatf_test_case atf_check_equal_eval_ok 12311be35a1SLionel Sambucatf_check_equal_eval_ok_head() 12411be35a1SLionel Sambuc{ 12511be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 12611be35a1SLionel Sambuc} 12711be35a1SLionel Sambucatf_check_equal_eval_ok_body() 12811be35a1SLionel Sambuc{ 12911be35a1SLionel Sambuc x=a 13011be35a1SLionel Sambuc y=a 13111be35a1SLionel Sambuc atf_check_equal '${x}' '${y}' 13211be35a1SLionel Sambuc} 13311be35a1SLionel Sambuc 13411be35a1SLionel Sambucatf_test_case atf_check_equal_eval_fail 13511be35a1SLionel Sambucatf_check_equal_eval_fail_head() 13611be35a1SLionel Sambuc{ 13711be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 13811be35a1SLionel Sambuc} 13911be35a1SLionel Sambucatf_check_equal_eval_fail_body() 14011be35a1SLionel Sambuc{ 14111be35a1SLionel Sambuc x=a 14211be35a1SLionel Sambuc y=b 14311be35a1SLionel Sambuc atf_check_equal '${x}' '${y}' 14411be35a1SLionel Sambuc} 14511be35a1SLionel Sambuc 146*0a6a1f1dSLionel Sambucatf_test_case atf_check_timeout 147*0a6a1f1dSLionel Sambucatf_check_timeout_head() 148*0a6a1f1dSLionel Sambuc{ 149*0a6a1f1dSLionel Sambuc atf_set "descr" "Helper test case for the t_atf_check test program" 150*0a6a1f1dSLionel Sambuc atf_set "timeout" 1 151*0a6a1f1dSLionel Sambuc} 152*0a6a1f1dSLionel Sambucatf_check_timeout_body() 153*0a6a1f1dSLionel Sambuc{ 154*0a6a1f1dSLionel Sambuc atf_check true 155*0a6a1f1dSLionel Sambuc atf_check sleep 42 156*0a6a1f1dSLionel Sambuc} 157*0a6a1f1dSLionel Sambuc 15811be35a1SLionel Sambuc# ------------------------------------------------------------------------- 15911be35a1SLionel Sambuc# Helper tests for "t_config". 16011be35a1SLionel Sambuc# ------------------------------------------------------------------------- 16111be35a1SLionel Sambuc 16211be35a1SLionel Sambucatf_test_case config_get 16311be35a1SLionel Sambucconfig_get_head() 16411be35a1SLionel Sambuc{ 16511be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_config test program" 16611be35a1SLionel Sambuc} 16711be35a1SLionel Sambucconfig_get_body() 16811be35a1SLionel Sambuc{ 16911be35a1SLionel Sambuc if atf_config_has ${TEST_VARIABLE}; then 17011be35a1SLionel Sambuc echo "${TEST_VARIABLE} = $(atf_config_get ${TEST_VARIABLE})" 17111be35a1SLionel Sambuc fi 17211be35a1SLionel Sambuc} 17311be35a1SLionel Sambuc 17411be35a1SLionel Sambucatf_test_case config_has 17511be35a1SLionel Sambucconfig_has_head() 17611be35a1SLionel Sambuc{ 17711be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_config test program" 17811be35a1SLionel Sambuc} 17911be35a1SLionel Sambucconfig_has_body() 18011be35a1SLionel Sambuc{ 18111be35a1SLionel Sambuc if atf_config_has ${TEST_VARIABLE}; then 18211be35a1SLionel Sambuc echo "${TEST_VARIABLE} found" 18311be35a1SLionel Sambuc else 18411be35a1SLionel Sambuc echo "${TEST_VARIABLE} not found" 18511be35a1SLionel Sambuc fi 18611be35a1SLionel Sambuc} 18711be35a1SLionel Sambuc 18811be35a1SLionel Sambuc# ------------------------------------------------------------------------- 18911be35a1SLionel Sambuc# Helper tests for "t_normalize". 19011be35a1SLionel Sambuc# ------------------------------------------------------------------------- 19111be35a1SLionel Sambuc 19211be35a1SLionel Sambucatf_test_case normalize 19311be35a1SLionel Sambucnormalize_head() 19411be35a1SLionel Sambuc{ 19511be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_normalize test program" 19611be35a1SLionel Sambuc atf_set "a.b" "test value 1" 19711be35a1SLionel Sambuc atf_set "c-d" "test value 2" 19811be35a1SLionel Sambuc} 19911be35a1SLionel Sambucnormalize_body() 20011be35a1SLionel Sambuc{ 20111be35a1SLionel Sambuc echo "a.b: $(atf_get a.b)" 20211be35a1SLionel Sambuc echo "c-d: $(atf_get c-d)" 20311be35a1SLionel Sambuc} 20411be35a1SLionel Sambuc 20511be35a1SLionel Sambuc# ------------------------------------------------------------------------- 20611be35a1SLionel Sambuc# Helper tests for "t_tc". 20711be35a1SLionel Sambuc# ------------------------------------------------------------------------- 20811be35a1SLionel Sambuc 20911be35a1SLionel Sambucatf_test_case tc_pass_true 21011be35a1SLionel Sambuctc_pass_true_head() 21111be35a1SLionel Sambuc{ 21211be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_tc test program" 21311be35a1SLionel Sambuc} 21411be35a1SLionel Sambuctc_pass_true_body() 21511be35a1SLionel Sambuc{ 21611be35a1SLionel Sambuc true 21711be35a1SLionel Sambuc} 21811be35a1SLionel Sambuc 21911be35a1SLionel Sambucatf_test_case tc_pass_false 22011be35a1SLionel Sambuctc_pass_false_head() 22111be35a1SLionel Sambuc{ 22211be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_tc test program" 22311be35a1SLionel Sambuc} 22411be35a1SLionel Sambuctc_pass_false_body() 22511be35a1SLionel Sambuc{ 22611be35a1SLionel Sambuc false 22711be35a1SLionel Sambuc} 22811be35a1SLionel Sambuc 22911be35a1SLionel Sambucatf_test_case tc_pass_return_error 23011be35a1SLionel Sambuctc_pass_return_error_head() 23111be35a1SLionel Sambuc{ 23211be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_tc test program" 23311be35a1SLionel Sambuc} 23411be35a1SLionel Sambuctc_pass_return_error_body() 23511be35a1SLionel Sambuc{ 23611be35a1SLionel Sambuc return 1 23711be35a1SLionel Sambuc} 23811be35a1SLionel Sambuc 23911be35a1SLionel Sambucatf_test_case tc_fail 24011be35a1SLionel Sambuctc_fail_head() 24111be35a1SLionel Sambuc{ 24211be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_tc test program" 24311be35a1SLionel Sambuc} 24411be35a1SLionel Sambuctc_fail_body() 24511be35a1SLionel Sambuc{ 24611be35a1SLionel Sambuc echo "An error" 1>&2 24711be35a1SLionel Sambuc exit 1 24811be35a1SLionel Sambuc} 24911be35a1SLionel Sambuc 25011be35a1SLionel Sambucatf_test_case tc_missing_body 25111be35a1SLionel Sambuctc_missing_body_head() 25211be35a1SLionel Sambuc{ 25311be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_tc test program" 25411be35a1SLionel Sambuc} 25511be35a1SLionel Sambuc 25611be35a1SLionel Sambuc# ------------------------------------------------------------------------- 25711be35a1SLionel Sambuc# Helper tests for "t_tp". 25811be35a1SLionel Sambuc# ------------------------------------------------------------------------- 25911be35a1SLionel Sambuc 26011be35a1SLionel Sambucatf_test_case tp_srcdir 26111be35a1SLionel Sambuctp_srcdir_head() 26211be35a1SLionel Sambuc{ 26311be35a1SLionel Sambuc atf_set "descr" "Helper test case for the t_tp test program" 26411be35a1SLionel Sambuc} 26511be35a1SLionel Sambuctp_srcdir_body() 26611be35a1SLionel Sambuc{ 26711be35a1SLionel Sambuc echo "Calling helper" 26811be35a1SLionel Sambuc helper_subr || atf_fail "Could not call helper subroutine" 26911be35a1SLionel Sambuc} 27011be35a1SLionel Sambuc 27111be35a1SLionel Sambuc# ------------------------------------------------------------------------- 27211be35a1SLionel Sambuc# Main. 27311be35a1SLionel Sambuc# ------------------------------------------------------------------------- 27411be35a1SLionel Sambuc 27511be35a1SLionel Sambucatf_init_test_cases() 27611be35a1SLionel Sambuc{ 27711be35a1SLionel Sambuc # Add helper tests for t_atf_check. 27811be35a1SLionel Sambuc atf_add_test_case atf_check_info_ok 27911be35a1SLionel Sambuc atf_add_test_case atf_check_info_fail 28011be35a1SLionel Sambuc atf_add_test_case atf_check_expout_mismatch 28111be35a1SLionel Sambuc atf_add_test_case atf_check_experr_mismatch 28211be35a1SLionel Sambuc atf_add_test_case atf_check_null_stdout 28311be35a1SLionel Sambuc atf_add_test_case atf_check_null_stderr 28411be35a1SLionel Sambuc atf_add_test_case atf_check_equal_ok 28511be35a1SLionel Sambuc atf_add_test_case atf_check_equal_fail 28611be35a1SLionel Sambuc atf_add_test_case atf_check_equal_eval_ok 28711be35a1SLionel Sambuc atf_add_test_case atf_check_equal_eval_fail 288*0a6a1f1dSLionel Sambuc atf_add_test_case atf_check_timeout 28911be35a1SLionel Sambuc 29011be35a1SLionel Sambuc # Add helper tests for t_config. 29111be35a1SLionel Sambuc atf_add_test_case config_get 29211be35a1SLionel Sambuc atf_add_test_case config_has 29311be35a1SLionel Sambuc 29411be35a1SLionel Sambuc # Add helper tests for t_normalize. 29511be35a1SLionel Sambuc atf_add_test_case normalize 29611be35a1SLionel Sambuc 29711be35a1SLionel Sambuc # Add helper tests for t_tc. 29811be35a1SLionel Sambuc atf_add_test_case tc_pass_true 29911be35a1SLionel Sambuc atf_add_test_case tc_pass_false 30011be35a1SLionel Sambuc atf_add_test_case tc_pass_return_error 30111be35a1SLionel Sambuc atf_add_test_case tc_fail 30211be35a1SLionel Sambuc atf_add_test_case tc_missing_body 30311be35a1SLionel Sambuc 30411be35a1SLionel Sambuc # Add helper tests for t_tp. 30511be35a1SLionel Sambuc [ -f $(atf_get_srcdir)/subrs ] && . $(atf_get_srcdir)/subrs 30611be35a1SLionel Sambuc atf_add_test_case tp_srcdir 30711be35a1SLionel Sambuc} 30811be35a1SLionel Sambuc 30911be35a1SLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 310