a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt# Copyright (c) 2007 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# All rights reserved.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Redistribution and use in source and binary forms, with or without
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# modification, are permitted provided that the following conditions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# are met:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# 1. Redistributions of source code must retain the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# notice, this list of conditions and the following disclaimer.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# 2. Redistributions in binary form must reproduce the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# notice, this list of conditions and the following disclaimer in the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# documentation and/or other materials provided with the distribution.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntcheck_result() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt file="${1}"; shift
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check -s eq:0 -o match:"${*}" -e empty cat "${file}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt rm "${file}"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_test_case expect_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexpect_pass_body() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for h in $(get_helpers); do
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:0 -e ignore "${h}" -r result expect_pass_and_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "passed"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:1 -e ignore "${h}" -r result \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt expect_pass_but_fail_requirement
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: Some reason"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # atf-sh does not support non-fatal failures yet; skip checks for
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # such conditions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case "${h}" in *sh_helpers*) continue ;; esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check -s eq:1 -o empty -e match:"Some reason" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "${h}" -r result expect_pass_but_fail_check
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: 1 checks failed"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_test_case expect_fail
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexpect_fail_body() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for h in $(get_helpers c_helpers cpp_helpers); do
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check -s eq:0 "${h}" -r result expect_fail_and_fail_requirement
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_failure: Fail reason: The failure"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check -s eq:1 -e match:"Expected check failure: Fail first: abc" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt -e not-match:"And fail again" "${h}" -r result expect_fail_but_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: .*expecting a failure"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # atf-sh does not support non-fatal failures yet; skip checks for
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # such conditions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case "${h}" in *sh_helpers*) continue ;; esac
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check -s eq:0 -e match:"Expected check failure: Fail first: abc" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt -e match:"Expected check failure: And fail again: def" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "${h}" -r result expect_fail_and_fail_check
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_failure: And fail again: 2 checks" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "failed as expected"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # atf-sh does not support non-fatal failures yet; skip checks for
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # such conditions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for h in $(get_helpers sh_helpers); do
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:0 -e ignore "${h}" -r result \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt expect_fail_and_fail_requirement
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_failure: Fail reason: The failure"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:1 -e ignore "${h}" -r result expect_fail_but_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: .*expecting a failure"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_test_case expect_exit
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexpect_exit_body() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for h in $(get_helpers); do
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:0 -e ignore "${h}" -r result expect_exit_any_and_exit
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_exit: Call will exit"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:123 -e ignore "${h}" -r result expect_exit_code_and_exit
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_exit\(123\): Call will exit"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:1 -e ignore "${h}" -r result expect_exit_but_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: .*expected to exit"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_test_case expect_signal
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexpect_signal_body() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for h in $(get_helpers); do
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s signal:9 -e ignore "${h}" -r result \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt expect_signal_any_and_signal
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_signal: Call will signal"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s signal:hup -e ignore "${h}" -r result \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt expect_signal_no_and_signal
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_signal\(1\): Call will signal"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:1 -e ignore "${h}" -r result \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt expect_signal_but_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: .*termination signal"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_test_case expect_death
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexpect_death_body() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for h in $(get_helpers); do
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:123 -e ignore "${h}" -r result expect_death_and_exit
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_death: Exit case"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s signal:kill -e ignore "${h}" -r result \
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt expect_death_and_signal
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "expected_death: Signal case"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:1 -e ignore "${h}" -r result expect_death_but_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: .*terminate abruptly"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_test_case expect_timeout
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntexpect_timeout_body() {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for h in $(get_helpers); do
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_check -s eq:1 -e ignore "${h}" -r result expect_timeout_but_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_result result "failed: Test case was expected to hang but it" \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "continued execution"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt done
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_init_test_cases()
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_add_test_case expect_pass
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_add_test_case expect_fail
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_add_test_case expect_exit
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_add_test_case expect_signal
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_add_test_case expect_death
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_add_test_case expect_timeout
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4