1240116Smarcel# 2240116Smarcel# Automated Testing Framework (atf) 3240116Smarcel# 4240116Smarcel# Copyright (c) 2007 The NetBSD Foundation, Inc. 5240116Smarcel# All rights reserved. 6240116Smarcel# 7240116Smarcel# Redistribution and use in source and binary forms, with or without 8240116Smarcel# modification, are permitted provided that the following conditions 9240116Smarcel# are met: 10240116Smarcel# 1. Redistributions of source code must retain the above copyright 11240116Smarcel# notice, this list of conditions and the following disclaimer. 12240116Smarcel# 2. Redistributions in binary form must reproduce the above copyright 13240116Smarcel# notice, this list of conditions and the following disclaimer in the 14240116Smarcel# documentation and/or other materials provided with the distribution. 15240116Smarcel# 16240116Smarcel# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17240116Smarcel# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18240116Smarcel# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19240116Smarcel# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20240116Smarcel# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21240116Smarcel# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22240116Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23240116Smarcel# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24240116Smarcel# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25240116Smarcel# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26240116Smarcel# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27240116Smarcel# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28240116Smarcel# 29240116Smarcel 30240116Smarcel# ------------------------------------------------------------------------- 31240116Smarcel# Helper tests for "t_atf_check". 32240116Smarcel# ------------------------------------------------------------------------- 33240116Smarcel 34240116Smarcelatf_test_case atf_check_info_ok 35240116Smarcelatf_check_info_ok_head() 36240116Smarcel{ 37240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 38240116Smarcel} 39240116Smarcelatf_check_info_ok_body() 40240116Smarcel{ 41240116Smarcel atf_check -s eq:0 -o empty -e empty true 42240116Smarcel} 43240116Smarcel 44240116Smarcelatf_test_case atf_check_info_fail 45240116Smarcelatf_check_info_fail_head() 46240116Smarcel{ 47240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 48240116Smarcel} 49240116Smarcelatf_check_info_fail_body() 50240116Smarcel{ 51240116Smarcel # In Solaris, /usr/bin/false returns 255 rather than 1. Use the 52240116Smarcel # built-in version for the check. 53240116Smarcel atf_check -s eq:1 -o empty -e empty sh -c "false" 54240116Smarcel} 55240116Smarcel 56240116Smarcelatf_test_case atf_check_expout_mismatch 57240116Smarcelatf_check_expout_mismatch_head() 58240116Smarcel{ 59240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 60240116Smarcel} 61240116Smarcelatf_check_expout_mismatch_body() 62240116Smarcel{ 63240116Smarcel cat >expout <<SECONDEOF 64240116Smarcelfoo 65240116SmarcelSECONDEOF 66240116Smarcel atf_check -s eq:0 -o file:expout -e empty echo bar 67240116Smarcel} 68240116Smarcel 69240116Smarcelatf_test_case atf_check_experr_mismatch 70240116Smarcelatf_check_experr_mismatch_head() 71240116Smarcel{ 72240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 73240116Smarcel} 74240116Smarcelatf_check_experr_mismatch_body() 75240116Smarcel{ 76240116Smarcel cat >experr <<SECONDEOF 77240116Smarcelfoo 78240116SmarcelSECONDEOF 79240116Smarcel atf_check -s eq:0 -o empty -e file:experr -x 'echo bar 1>&2' 80240116Smarcel} 81240116Smarcel 82240116Smarcelatf_test_case atf_check_null_stdout 83240116Smarcelatf_check_null_stdout_head() 84240116Smarcel{ 85240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 86240116Smarcel} 87240116Smarcelatf_check_null_stdout_body() 88240116Smarcel{ 89240116Smarcel atf_check -s eq:0 -o empty -e empty echo "These are the contents" 90240116Smarcel} 91240116Smarcel 92240116Smarcelatf_test_case atf_check_null_stderr 93240116Smarcelatf_check_null_stderr_head() 94240116Smarcel{ 95240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 96240116Smarcel} 97240116Smarcelatf_check_null_stderr_body() 98240116Smarcel{ 99240116Smarcel atf_check -s eq:0 -o empty -e empty -x 'echo "These are the contents" 1>&2' 100240116Smarcel} 101240116Smarcel 102240116Smarcelatf_test_case atf_check_equal_ok 103240116Smarcelatf_check_equal_ok_head() 104240116Smarcel{ 105240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 106240116Smarcel} 107240116Smarcelatf_check_equal_ok_body() 108240116Smarcel{ 109240116Smarcel atf_check_equal a a 110240116Smarcel} 111240116Smarcel 112240116Smarcelatf_test_case atf_check_equal_fail 113240116Smarcelatf_check_equal_fail_head() 114240116Smarcel{ 115240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 116240116Smarcel} 117240116Smarcelatf_check_equal_fail_body() 118240116Smarcel{ 119240116Smarcel atf_check_equal a b 120240116Smarcel} 121240116Smarcel 122240116Smarcelatf_test_case atf_check_equal_eval_ok 123240116Smarcelatf_check_equal_eval_ok_head() 124240116Smarcel{ 125240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 126240116Smarcel} 127240116Smarcelatf_check_equal_eval_ok_body() 128240116Smarcel{ 129240116Smarcel x=a 130240116Smarcel y=a 131240116Smarcel atf_check_equal '${x}' '${y}' 132240116Smarcel} 133240116Smarcel 134240116Smarcelatf_test_case atf_check_equal_eval_fail 135240116Smarcelatf_check_equal_eval_fail_head() 136240116Smarcel{ 137240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 138240116Smarcel} 139240116Smarcelatf_check_equal_eval_fail_body() 140240116Smarcel{ 141240116Smarcel x=a 142240116Smarcel y=b 143240116Smarcel atf_check_equal '${x}' '${y}' 144240116Smarcel} 145240116Smarcel 146260029Sjmmvatf_test_case atf_check_timeout 147260029Sjmmvatf_check_timeout_head() 148260029Sjmmv{ 149260029Sjmmv atf_set "descr" "Helper test case for the t_atf_check test program" 150260029Sjmmv atf_set "timeout" 1 151260029Sjmmv} 152260029Sjmmvatf_check_timeout_body() 153260029Sjmmv{ 154260029Sjmmv atf_check true 155260029Sjmmv atf_check sleep 42 156260029Sjmmv} 157260029Sjmmv 158240116Smarcel# ------------------------------------------------------------------------- 159240116Smarcel# Helper tests for "t_config". 160240116Smarcel# ------------------------------------------------------------------------- 161240116Smarcel 162240116Smarcelatf_test_case config_get 163240116Smarcelconfig_get_head() 164240116Smarcel{ 165240116Smarcel atf_set "descr" "Helper test case for the t_config test program" 166240116Smarcel} 167240116Smarcelconfig_get_body() 168240116Smarcel{ 169240116Smarcel if atf_config_has ${TEST_VARIABLE}; then 170240116Smarcel echo "${TEST_VARIABLE} = $(atf_config_get ${TEST_VARIABLE})" 171240116Smarcel fi 172240116Smarcel} 173240116Smarcel 174240116Smarcelatf_test_case config_has 175240116Smarcelconfig_has_head() 176240116Smarcel{ 177240116Smarcel atf_set "descr" "Helper test case for the t_config test program" 178240116Smarcel} 179240116Smarcelconfig_has_body() 180240116Smarcel{ 181240116Smarcel if atf_config_has ${TEST_VARIABLE}; then 182240116Smarcel echo "${TEST_VARIABLE} found" 183240116Smarcel else 184240116Smarcel echo "${TEST_VARIABLE} not found" 185240116Smarcel fi 186240116Smarcel} 187240116Smarcel 188240116Smarcel# ------------------------------------------------------------------------- 189240116Smarcel# Helper tests for "t_normalize". 190240116Smarcel# ------------------------------------------------------------------------- 191240116Smarcel 192240116Smarcelatf_test_case normalize 193240116Smarcelnormalize_head() 194240116Smarcel{ 195240116Smarcel atf_set "descr" "Helper test case for the t_normalize test program" 196240116Smarcel atf_set "a.b" "test value 1" 197240116Smarcel atf_set "c-d" "test value 2" 198240116Smarcel} 199240116Smarcelnormalize_body() 200240116Smarcel{ 201240116Smarcel echo "a.b: $(atf_get a.b)" 202240116Smarcel echo "c-d: $(atf_get c-d)" 203240116Smarcel} 204240116Smarcel 205240116Smarcel# ------------------------------------------------------------------------- 206240116Smarcel# Helper tests for "t_tc". 207240116Smarcel# ------------------------------------------------------------------------- 208240116Smarcel 209240116Smarcelatf_test_case tc_pass_true 210240116Smarceltc_pass_true_head() 211240116Smarcel{ 212240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 213240116Smarcel} 214240116Smarceltc_pass_true_body() 215240116Smarcel{ 216240116Smarcel true 217240116Smarcel} 218240116Smarcel 219240116Smarcelatf_test_case tc_pass_false 220240116Smarceltc_pass_false_head() 221240116Smarcel{ 222240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 223240116Smarcel} 224240116Smarceltc_pass_false_body() 225240116Smarcel{ 226240116Smarcel false 227240116Smarcel} 228240116Smarcel 229240116Smarcelatf_test_case tc_pass_return_error 230240116Smarceltc_pass_return_error_head() 231240116Smarcel{ 232240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 233240116Smarcel} 234240116Smarceltc_pass_return_error_body() 235240116Smarcel{ 236240116Smarcel return 1 237240116Smarcel} 238240116Smarcel 239240116Smarcelatf_test_case tc_fail 240240116Smarceltc_fail_head() 241240116Smarcel{ 242240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 243240116Smarcel} 244240116Smarceltc_fail_body() 245240116Smarcel{ 246240116Smarcel echo "An error" 1>&2 247240116Smarcel exit 1 248240116Smarcel} 249240116Smarcel 250240116Smarcelatf_test_case tc_missing_body 251240116Smarceltc_missing_body_head() 252240116Smarcel{ 253240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 254240116Smarcel} 255240116Smarcel 256240116Smarcel# ------------------------------------------------------------------------- 257240116Smarcel# Helper tests for "t_tp". 258240116Smarcel# ------------------------------------------------------------------------- 259240116Smarcel 260240116Smarcelatf_test_case tp_srcdir 261240116Smarceltp_srcdir_head() 262240116Smarcel{ 263240116Smarcel atf_set "descr" "Helper test case for the t_tp test program" 264240116Smarcel} 265240116Smarceltp_srcdir_body() 266240116Smarcel{ 267240116Smarcel echo "Calling helper" 268240116Smarcel helper_subr || atf_fail "Could not call helper subroutine" 269240116Smarcel} 270240116Smarcel 271240116Smarcel# ------------------------------------------------------------------------- 272240116Smarcel# Main. 273240116Smarcel# ------------------------------------------------------------------------- 274240116Smarcel 275240116Smarcelatf_init_test_cases() 276240116Smarcel{ 277240116Smarcel # Add helper tests for t_atf_check. 278240116Smarcel atf_add_test_case atf_check_info_ok 279240116Smarcel atf_add_test_case atf_check_info_fail 280240116Smarcel atf_add_test_case atf_check_expout_mismatch 281240116Smarcel atf_add_test_case atf_check_experr_mismatch 282240116Smarcel atf_add_test_case atf_check_null_stdout 283240116Smarcel atf_add_test_case atf_check_null_stderr 284240116Smarcel atf_add_test_case atf_check_equal_ok 285240116Smarcel atf_add_test_case atf_check_equal_fail 286240116Smarcel atf_add_test_case atf_check_equal_eval_ok 287240116Smarcel atf_add_test_case atf_check_equal_eval_fail 288260029Sjmmv atf_add_test_case atf_check_timeout 289240116Smarcel 290240116Smarcel # Add helper tests for t_config. 291240116Smarcel atf_add_test_case config_get 292240116Smarcel atf_add_test_case config_has 293240116Smarcel 294240116Smarcel # Add helper tests for t_normalize. 295240116Smarcel atf_add_test_case normalize 296240116Smarcel 297240116Smarcel # Add helper tests for t_tc. 298240116Smarcel atf_add_test_case tc_pass_true 299240116Smarcel atf_add_test_case tc_pass_false 300240116Smarcel atf_add_test_case tc_pass_return_error 301240116Smarcel atf_add_test_case tc_fail 302240116Smarcel atf_add_test_case tc_missing_body 303240116Smarcel 304240116Smarcel # Add helper tests for t_tp. 305240116Smarcel [ -f $(atf_get_srcdir)/subrs ] && . $(atf_get_srcdir)/subrs 306240116Smarcel atf_add_test_case tp_srcdir 307240116Smarcel} 308240116Smarcel 309240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 310