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# TODO: Bring in the checks in the bootstrap testsuite for atf_check. 3111be35a1SLionel Sambuc 3211be35a1SLionel Sambucatf_test_case info_ok 3311be35a1SLionel Sambucinfo_ok_head() 3411be35a1SLionel Sambuc{ 3511be35a1SLionel Sambuc atf_set "descr" "Verifies that atf_check prints an informative" \ 3611be35a1SLionel Sambuc "message even when the command is successful" 3711be35a1SLionel Sambuc} 3811be35a1SLionel Sambucinfo_ok_body() 3911be35a1SLionel Sambuc{ 4011be35a1SLionel Sambuc h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 4111be35a1SLionel Sambuc 4211be35a1SLionel Sambuc atf_check -s eq:0 -o save:stdout -e save:stderr -x \ 4311be35a1SLionel Sambuc "${h} atf_check_info_ok" 4411be35a1SLionel Sambuc grep 'Executing command.*true' stdout >/dev/null || \ 4511be35a1SLionel Sambuc atf_fail "atf_check does not print an informative message" 4611be35a1SLionel Sambuc 4711be35a1SLionel Sambuc atf_check -s eq:0 -o save:stdout -e save:stderr -x \ 4811be35a1SLionel Sambuc "${h} atf_check_info_fail" 4911be35a1SLionel Sambuc grep 'Executing command.*false' stdout >/dev/null || \ 5011be35a1SLionel Sambuc atf_fail "atf_check does not print an informative message" 5111be35a1SLionel Sambuc} 5211be35a1SLionel Sambuc 5311be35a1SLionel Sambucatf_test_case expout_mismatch 5411be35a1SLionel Sambucexpout_mismatch_head() 5511be35a1SLionel Sambuc{ 5611be35a1SLionel Sambuc atf_set "descr" "Verifies that atf_check prints a diff of the" \ 5711be35a1SLionel Sambuc "stdout and the expected stdout if the two do not" \ 5811be35a1SLionel Sambuc "match" 5911be35a1SLionel Sambuc} 6011be35a1SLionel Sambucexpout_mismatch_body() 6111be35a1SLionel Sambuc{ 6211be35a1SLionel Sambuc h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 6311be35a1SLionel Sambuc 6411be35a1SLionel Sambuc atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 6511be35a1SLionel Sambuc "${h} atf_check_expout_mismatch" 6611be35a1SLionel Sambuc grep 'Executing command.*echo bar' stdout >/dev/null || \ 6711be35a1SLionel Sambuc atf_fail "atf_check does not print an informative message" 6811be35a1SLionel Sambuc grep 'stdout does not match golden output' stderr >/dev/null || \ 6911be35a1SLionel Sambuc atf_fail "atf_check does not print the stdout header" 7011be35a1SLionel Sambuc grep 'stderr' stderr >/dev/null && \ 7111be35a1SLionel Sambuc atf_fail "atf_check prints the stderr header" 7211be35a1SLionel Sambuc grep '^-foo' stderr >/dev/null || \ 7311be35a1SLionel Sambuc atf_fail "atf_check does not print the stdout's diff" 7411be35a1SLionel Sambuc grep '^+bar' stderr >/dev/null || \ 7511be35a1SLionel Sambuc atf_fail "atf_check does not print the stdout's diff" 7611be35a1SLionel Sambuc} 7711be35a1SLionel Sambuc 7811be35a1SLionel Sambucatf_test_case experr_mismatch 7911be35a1SLionel Sambucexperr_mismatch_head() 8011be35a1SLionel Sambuc{ 8111be35a1SLionel Sambuc atf_set "descr" "Verifies that atf_check prints a diff of the" \ 8211be35a1SLionel Sambuc "stderr and the expected stderr if the two do not" \ 8311be35a1SLionel Sambuc "match" 8411be35a1SLionel Sambuc} 8511be35a1SLionel Sambucexperr_mismatch_body() 8611be35a1SLionel Sambuc{ 8711be35a1SLionel Sambuc h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 8811be35a1SLionel Sambuc 8911be35a1SLionel Sambuc atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 9011be35a1SLionel Sambuc "${h} atf_check_experr_mismatch" 9111be35a1SLionel Sambuc grep 'Executing command.*echo bar' stdout >/dev/null || \ 9211be35a1SLionel Sambuc atf_fail "atf_check does not print an informative message" 9311be35a1SLionel Sambuc grep 'stdout' stderr >/dev/null && \ 9411be35a1SLionel Sambuc atf_fail "atf_check prints the stdout header" 9511be35a1SLionel Sambuc grep 'stderr does not match golden output' stderr >/dev/null || \ 9611be35a1SLionel Sambuc atf_fail "atf_check does not print the stderr header" 9711be35a1SLionel Sambuc grep '^-foo' stderr >/dev/null || \ 9811be35a1SLionel Sambuc atf_fail "atf_check does not print the stderr's diff" 9911be35a1SLionel Sambuc grep '^+bar' stderr >/dev/null || \ 10011be35a1SLionel Sambuc atf_fail "atf_check does not print the stderr's diff" 10111be35a1SLionel Sambuc} 10211be35a1SLionel Sambuc 10311be35a1SLionel Sambucatf_test_case null_stdout 10411be35a1SLionel Sambucnull_stdout_head() 10511be35a1SLionel Sambuc{ 10611be35a1SLionel Sambuc atf_set "descr" "Verifies that atf_check prints a the stdout it got" \ 10711be35a1SLionel Sambuc "when it was supposed to be null" 10811be35a1SLionel Sambuc} 10911be35a1SLionel Sambucnull_stdout_body() 11011be35a1SLionel Sambuc{ 11111be35a1SLionel Sambuc h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 11211be35a1SLionel Sambuc 11311be35a1SLionel Sambuc atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 11411be35a1SLionel Sambuc "${h} atf_check_null_stdout" 11511be35a1SLionel Sambuc grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \ 11611be35a1SLionel Sambuc atf_fail "atf_check does not print an informative message" 11711be35a1SLionel Sambuc grep 'stdout not empty' stderr >/dev/null || \ 11811be35a1SLionel Sambuc atf_fail "atf_check does not print the stdout header" 11911be35a1SLionel Sambuc grep 'stderr' stderr >/dev/null && \ 12011be35a1SLionel Sambuc atf_fail "atf_check prints the stderr header" 12111be35a1SLionel Sambuc grep 'These are the contents' stderr >/dev/null || \ 12211be35a1SLionel Sambuc atf_fail "atf_check does not print stdout's contents" 12311be35a1SLionel Sambuc} 12411be35a1SLionel Sambuc 12511be35a1SLionel Sambucatf_test_case null_stderr 12611be35a1SLionel Sambucnull_stderr_head() 12711be35a1SLionel Sambuc{ 12811be35a1SLionel Sambuc atf_set "descr" "Verifies that atf_check prints a the stderr it got" \ 12911be35a1SLionel Sambuc "when it was supposed to be null" 13011be35a1SLionel Sambuc} 13111be35a1SLionel Sambucnull_stderr_body() 13211be35a1SLionel Sambuc{ 13311be35a1SLionel Sambuc h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 13411be35a1SLionel Sambuc 13511be35a1SLionel Sambuc atf_check -s eq:1 -o save:stdout -e save:stderr -x \ 13611be35a1SLionel Sambuc "${h} atf_check_null_stderr" 13711be35a1SLionel Sambuc grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \ 13811be35a1SLionel Sambuc atf_fail "atf_check does not print an informative message" 13911be35a1SLionel Sambuc grep 'stdout' stderr >/dev/null && \ 14011be35a1SLionel Sambuc atf_fail "atf_check prints the stdout header" 14111be35a1SLionel Sambuc grep 'stderr not empty' stderr >/dev/null || \ 14211be35a1SLionel Sambuc atf_fail "atf_check does not print the stderr header" 14311be35a1SLionel Sambuc grep 'These are the contents' stderr >/dev/null || \ 14411be35a1SLionel Sambuc atf_fail "atf_check does not print stderr's contents" 14511be35a1SLionel Sambuc} 14611be35a1SLionel Sambuc 14711be35a1SLionel Sambucatf_test_case equal 14811be35a1SLionel Sambucequal_head() 14911be35a1SLionel Sambuc{ 15011be35a1SLionel Sambuc atf_set "descr" "Verifies that atf_check_equal works" 15111be35a1SLionel Sambuc} 15211be35a1SLionel Sambucequal_body() 15311be35a1SLionel Sambuc{ 15411be35a1SLionel Sambuc h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)" 15511be35a1SLionel Sambuc 15611be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_ok" 15711be35a1SLionel Sambuc 15811be35a1SLionel Sambuc atf_check -s eq:1 -o ignore -e ignore -x \ 15911be35a1SLionel Sambuc "${h} -r resfile atf_check_equal_fail" 16011be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty grep '^failed: a != b (a != b)$' \ 16111be35a1SLionel Sambuc resfile 16211be35a1SLionel Sambuc 16311be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_eval_ok" 16411be35a1SLionel Sambuc 16511be35a1SLionel Sambuc atf_check -s eq:1 -o ignore -e ignore -x \ 16611be35a1SLionel Sambuc "${h} -r resfile atf_check_equal_eval_fail" 16711be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty \ 16811be35a1SLionel Sambuc grep '^failed: \${x} != \${y} (a != b)$' resfile 16911be35a1SLionel Sambuc} 17011be35a1SLionel Sambuc 171*0a6a1f1dSLionel Sambucatf_test_case flush_stdout_on_timeout 172*0a6a1f1dSLionel Sambucflush_stdout_on_timeout_body() 173*0a6a1f1dSLionel Sambuc{ 174*0a6a1f1dSLionel Sambuc "$(atf_get_srcdir)/misc_helpers" -s "$(atf_get_srcdir)" atf_check_timeout \ 175*0a6a1f1dSLionel Sambuc >out 2>err & 176*0a6a1f1dSLionel Sambuc pid="${!}" 177*0a6a1f1dSLionel Sambuc sleep 10 178*0a6a1f1dSLionel Sambuc kill "${pid}" 179*0a6a1f1dSLionel Sambuc 180*0a6a1f1dSLionel Sambuc grep 'Executing command.*true' out \ 181*0a6a1f1dSLionel Sambuc || atf_fail 'First command not in output' 182*0a6a1f1dSLionel Sambuc grep 'Executing command.*sleep 42' out \ 183*0a6a1f1dSLionel Sambuc || atf_fail 'Second command not in output' 184*0a6a1f1dSLionel Sambuc} 185*0a6a1f1dSLionel Sambuc 18611be35a1SLionel Sambucatf_init_test_cases() 18711be35a1SLionel Sambuc{ 18811be35a1SLionel Sambuc atf_add_test_case info_ok 18911be35a1SLionel Sambuc atf_add_test_case expout_mismatch 19011be35a1SLionel Sambuc atf_add_test_case experr_mismatch 19111be35a1SLionel Sambuc atf_add_test_case null_stdout 19211be35a1SLionel Sambuc atf_add_test_case null_stderr 19311be35a1SLionel Sambuc atf_add_test_case equal 194*0a6a1f1dSLionel Sambuc atf_add_test_case flush_stdout_on_timeout 19511be35a1SLionel Sambuc} 19611be35a1SLionel Sambuc 19711be35a1SLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 198