functional_test.sh revision 269902
1269902Sngie# 2269902Sngie# Copyright 2014 EMC Corp. 3269902Sngie# All rights reserved. 4269902Sngie# 5269902Sngie# Redistribution and use in source and binary forms, with or without 6269902Sngie# modification, are permitted provided that the following conditions are 7269902Sngie# met: 8269902Sngie# 9269902Sngie# * Redistributions of source code must retain the above copyright 10269902Sngie# notice, this list of conditions and the following disclaimer. 11269902Sngie# * Redistributions in binary form must reproduce the above copyright 12269902Sngie# notice, this list of conditions and the following disclaimer in the 13269902Sngie# documentation and/or other materials provided with the distribution. 14269902Sngie# 15269902Sngie# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16269902Sngie# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17269902Sngie# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18269902Sngie# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19269902Sngie# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20269902Sngie# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21269902Sngie# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22269902Sngie# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23269902Sngie# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24269902Sngie# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25269902Sngie# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26269902Sngie# 27269902Sngie# $FreeBSD: head/bin/sh/tests/functional_test.sh 269902 2014-08-13 04:14:50Z ngie $ 28269902Sngie 29269902SngieSRCDIR=$(atf_get_srcdir) 30269902Sngie 31269902Sngiecheck() 32269902Sngie{ 33269902Sngie local tc=${1}; shift 34269902Sngie 35269902Sngie export SH=$(atf_config_get bin.sh.test_shell /bin/sh) 36269902Sngie 37269902Sngie local err_file="${SRCDIR}/${tc}.stderr" 38269902Sngie [ -f "${err_file}" ] && err_flag="-e file:${err_file}" 39269902Sngie local out_file="${SRCDIR}/${tc}.stdout" 40269902Sngie [ -f "${out_file}" ] && out_flag="-o file:${out_file}" 41269902Sngie 42269902Sngie # We need to copy the testcase scenario file because some of the 43269902Sngie # testcases hardcode relative paths in the stderr/stdout. 44269902Sngie # 45269902Sngie # TODO: we might be able to generate this path at build time 46269902Sngie cp ${SRCDIR}/${tc} . 47269902Sngie 48269902Sngie atf_check -s exit:${tc##*.} ${err_flag} ${out_flag} ${SH} "./${tc}" 49269902Sngie} 50269902Sngie 51269902Sngieadd_testcase() 52269902Sngie{ 53269902Sngie local tc=${1} 54269902Sngie local tc_escaped word 55269902Sngie 56269902Sngie case "${tc%.*}" in 57269902Sngie *-*) 58269902Sngie local IFS="-" 59269902Sngie for word in ${tc%.*}; do 60269902Sngie tc_escaped="${tc_escaped:+${tc_escaped}_}${word}" 61269902Sngie done 62269902Sngie ;; 63269902Sngie *) 64269902Sngie tc_escaped=${tc%.*} 65269902Sngie ;; 66269902Sngie esac 67269902Sngie 68269902Sngie atf_test_case ${tc_escaped} 69269902Sngie eval "${tc_escaped}_body() { check ${tc}; }" 70269902Sngie atf_add_test_case ${tc_escaped} 71269902Sngie} 72269902Sngie 73269902Sngieatf_init_test_cases() 74269902Sngie{ 75269902Sngie for path in $(find -Es "${SRCDIR}" -regex '.*\.[0-9]+$'); do 76269902Sngie add_testcase ${path##*/} 77269902Sngie done 78269902Sngie} 79