1*11be35a1SLionel Sambuc# 2*11be35a1SLionel Sambuc# Automated Testing Framework (atf) 3*11be35a1SLionel Sambuc# 4*11be35a1SLionel Sambuc# Copyright (c) 2007 The NetBSD Foundation, Inc. 5*11be35a1SLionel Sambuc# All rights reserved. 6*11be35a1SLionel Sambuc# 7*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 8*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 9*11be35a1SLionel Sambuc# are met: 10*11be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 11*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 12*11be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 13*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 14*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 15*11be35a1SLionel Sambuc# 16*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17*11be35a1SLionel Sambuc# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18*11be35a1SLionel Sambuc# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19*11be35a1SLionel Sambuc# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20*11be35a1SLionel Sambuc# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21*11be35a1SLionel Sambuc# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*11be35a1SLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23*11be35a1SLionel Sambuc# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*11be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25*11be35a1SLionel Sambuc# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26*11be35a1SLionel Sambuc# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27*11be35a1SLionel Sambuc# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*11be35a1SLionel Sambuc# 29*11be35a1SLionel Sambuc 30*11be35a1SLionel Sambuccheck_result() { 31*11be35a1SLionel Sambuc file="${1}"; shift 32*11be35a1SLionel Sambuc 33*11be35a1SLionel Sambuc atf_check -s eq:0 -o match:"${*}" -e empty cat "${file}" 34*11be35a1SLionel Sambuc rm "${file}" 35*11be35a1SLionel Sambuc} 36*11be35a1SLionel Sambuc 37*11be35a1SLionel Sambucatf_test_case expect_pass 38*11be35a1SLionel Sambucexpect_pass_body() { 39*11be35a1SLionel Sambuc for h in $(get_helpers); do 40*11be35a1SLionel Sambuc atf_check -s eq:0 -e ignore "${h}" -r result expect_pass_and_pass 41*11be35a1SLionel Sambuc check_result result "passed" 42*11be35a1SLionel Sambuc 43*11be35a1SLionel Sambuc atf_check -s eq:1 -e ignore "${h}" -r result \ 44*11be35a1SLionel Sambuc expect_pass_but_fail_requirement 45*11be35a1SLionel Sambuc check_result result "failed: Some reason" 46*11be35a1SLionel Sambuc 47*11be35a1SLionel Sambuc # atf-sh does not support non-fatal failures yet; skip checks for 48*11be35a1SLionel Sambuc # such conditions. 49*11be35a1SLionel Sambuc case "${h}" in *sh_helpers*) continue ;; esac 50*11be35a1SLionel Sambuc 51*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e match:"Some reason" \ 52*11be35a1SLionel Sambuc "${h}" -r result expect_pass_but_fail_check 53*11be35a1SLionel Sambuc check_result result "failed: 1 checks failed" 54*11be35a1SLionel Sambuc done 55*11be35a1SLionel Sambuc} 56*11be35a1SLionel Sambuc 57*11be35a1SLionel Sambucatf_test_case expect_fail 58*11be35a1SLionel Sambucexpect_fail_body() { 59*11be35a1SLionel Sambuc for h in $(get_helpers c_helpers cpp_helpers); do 60*11be35a1SLionel Sambuc atf_check -s eq:0 "${h}" -r result expect_fail_and_fail_requirement 61*11be35a1SLionel Sambuc check_result result "expected_failure: Fail reason: The failure" 62*11be35a1SLionel Sambuc 63*11be35a1SLionel Sambuc atf_check -s eq:1 -e match:"Expected check failure: Fail first: abc" \ 64*11be35a1SLionel Sambuc -e not-match:"And fail again" "${h}" -r result expect_fail_but_pass 65*11be35a1SLionel Sambuc check_result result "failed: .*expecting a failure" 66*11be35a1SLionel Sambuc 67*11be35a1SLionel Sambuc # atf-sh does not support non-fatal failures yet; skip checks for 68*11be35a1SLionel Sambuc # such conditions. 69*11be35a1SLionel Sambuc case "${h}" in *sh_helpers*) continue ;; esac 70*11be35a1SLionel Sambuc 71*11be35a1SLionel Sambuc atf_check -s eq:0 -e match:"Expected check failure: Fail first: abc" \ 72*11be35a1SLionel Sambuc -e match:"Expected check failure: And fail again: def" \ 73*11be35a1SLionel Sambuc "${h}" -r result expect_fail_and_fail_check 74*11be35a1SLionel Sambuc check_result result "expected_failure: And fail again: 2 checks" \ 75*11be35a1SLionel Sambuc "failed as expected" 76*11be35a1SLionel Sambuc done 77*11be35a1SLionel Sambuc 78*11be35a1SLionel Sambuc # atf-sh does not support non-fatal failures yet; skip checks for 79*11be35a1SLionel Sambuc # such conditions. 80*11be35a1SLionel Sambuc for h in $(get_helpers sh_helpers); do 81*11be35a1SLionel Sambuc atf_check -s eq:0 -e ignore "${h}" -r result \ 82*11be35a1SLionel Sambuc expect_fail_and_fail_requirement 83*11be35a1SLionel Sambuc check_result result "expected_failure: Fail reason: The failure" 84*11be35a1SLionel Sambuc 85*11be35a1SLionel Sambuc atf_check -s eq:1 -e ignore "${h}" -r result expect_fail_but_pass 86*11be35a1SLionel Sambuc check_result result "failed: .*expecting a failure" 87*11be35a1SLionel Sambuc done 88*11be35a1SLionel Sambuc} 89*11be35a1SLionel Sambuc 90*11be35a1SLionel Sambucatf_test_case expect_exit 91*11be35a1SLionel Sambucexpect_exit_body() { 92*11be35a1SLionel Sambuc for h in $(get_helpers); do 93*11be35a1SLionel Sambuc atf_check -s eq:0 -e ignore "${h}" -r result expect_exit_any_and_exit 94*11be35a1SLionel Sambuc check_result result "expected_exit: Call will exit" 95*11be35a1SLionel Sambuc 96*11be35a1SLionel Sambuc atf_check -s eq:123 -e ignore "${h}" -r result expect_exit_code_and_exit 97*11be35a1SLionel Sambuc check_result result "expected_exit\(123\): Call will exit" 98*11be35a1SLionel Sambuc 99*11be35a1SLionel Sambuc atf_check -s eq:1 -e ignore "${h}" -r result expect_exit_but_pass 100*11be35a1SLionel Sambuc check_result result "failed: .*expected to exit" 101*11be35a1SLionel Sambuc done 102*11be35a1SLionel Sambuc} 103*11be35a1SLionel Sambuc 104*11be35a1SLionel Sambucatf_test_case expect_signal 105*11be35a1SLionel Sambucexpect_signal_body() { 106*11be35a1SLionel Sambuc for h in $(get_helpers); do 107*11be35a1SLionel Sambuc atf_check -s signal:9 -e ignore "${h}" -r result \ 108*11be35a1SLionel Sambuc expect_signal_any_and_signal 109*11be35a1SLionel Sambuc check_result result "expected_signal: Call will signal" 110*11be35a1SLionel Sambuc 111*11be35a1SLionel Sambuc atf_check -s signal:hup -e ignore "${h}" -r result \ 112*11be35a1SLionel Sambuc expect_signal_no_and_signal 113*11be35a1SLionel Sambuc check_result result "expected_signal\(1\): Call will signal" 114*11be35a1SLionel Sambuc 115*11be35a1SLionel Sambuc atf_check -s eq:1 -e ignore "${h}" -r result \ 116*11be35a1SLionel Sambuc expect_signal_but_pass 117*11be35a1SLionel Sambuc check_result result "failed: .*termination signal" 118*11be35a1SLionel Sambuc done 119*11be35a1SLionel Sambuc} 120*11be35a1SLionel Sambuc 121*11be35a1SLionel Sambucatf_test_case expect_death 122*11be35a1SLionel Sambucexpect_death_body() { 123*11be35a1SLionel Sambuc for h in $(get_helpers); do 124*11be35a1SLionel Sambuc atf_check -s eq:123 -e ignore "${h}" -r result expect_death_and_exit 125*11be35a1SLionel Sambuc check_result result "expected_death: Exit case" 126*11be35a1SLionel Sambuc 127*11be35a1SLionel Sambuc atf_check -s signal:kill -e ignore "${h}" -r result \ 128*11be35a1SLionel Sambuc expect_death_and_signal 129*11be35a1SLionel Sambuc check_result result "expected_death: Signal case" 130*11be35a1SLionel Sambuc 131*11be35a1SLionel Sambuc atf_check -s eq:1 -e ignore "${h}" -r result expect_death_but_pass 132*11be35a1SLionel Sambuc check_result result "failed: .*terminate abruptly" 133*11be35a1SLionel Sambuc done 134*11be35a1SLionel Sambuc} 135*11be35a1SLionel Sambuc 136*11be35a1SLionel Sambucatf_test_case expect_timeout 137*11be35a1SLionel Sambucexpect_timeout_body() { 138*11be35a1SLionel Sambuc for h in $(get_helpers); do 139*11be35a1SLionel Sambuc atf_check -s eq:1 -e ignore "${h}" -r result expect_timeout_but_pass 140*11be35a1SLionel Sambuc check_result result "failed: Test case was expected to hang but it" \ 141*11be35a1SLionel Sambuc "continued execution" 142*11be35a1SLionel Sambuc done 143*11be35a1SLionel Sambuc} 144*11be35a1SLionel Sambuc 145*11be35a1SLionel Sambucatf_init_test_cases() 146*11be35a1SLionel Sambuc{ 147*11be35a1SLionel Sambuc atf_add_test_case expect_pass 148*11be35a1SLionel Sambuc atf_add_test_case expect_fail 149*11be35a1SLionel Sambuc atf_add_test_case expect_exit 150*11be35a1SLionel Sambuc atf_add_test_case expect_signal 151*11be35a1SLionel Sambuc atf_add_test_case expect_death 152*11be35a1SLionel Sambuc atf_add_test_case expect_timeout 153*11be35a1SLionel Sambuc} 154*11be35a1SLionel Sambuc 155*11be35a1SLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 156