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