From 54d0854153135680923c0ff302624af093029d01 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 1 Dec 2015 18:27:38 +0000 Subject: [PATCH] MFC r269902,r270101: r269902: Convert bin/sh/tests to ATF The new code uses a "test discovery mechanism" to determine what tests are available for execution The test shell can be specified via: kyua test -v test_suites.FreeBSD.bin.sh.test_shell=/path/to/test/sh Sponsored by: EMC / Isilon Storage Division Approved by: jmmv (mentor) Reviewed by: jilles (maintainer) r270101 (by jilles): sh: Don't hardcode relative paths in the tests stderr files. These paths have had to be adjusted to changes in the testsuite runner several times, so modify the tests to remove the need for such adjustment. A cp in functional_test.sh is now unneeded, but this matters little in performance. git-svn-id: svn://svn.freebsd.org/base/stable/10@291604 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- bin/sh/tests/Makefile | 17 +++-- bin/sh/tests/builtins/Makefile | 8 ++- bin/sh/tests/errors/Makefile | 8 ++- bin/sh/tests/errors/bad-parm-exp2.2 | 2 +- bin/sh/tests/errors/bad-parm-exp2.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp3.2 | 2 +- bin/sh/tests/errors/bad-parm-exp3.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp4.2 | 2 +- bin/sh/tests/errors/bad-parm-exp4.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp5.2 | 2 +- bin/sh/tests/errors/bad-parm-exp5.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp6.2 | 2 +- bin/sh/tests/errors/bad-parm-exp6.2.stderr | 2 +- bin/sh/tests/execution/Makefile | 8 ++- bin/sh/tests/expansion/Makefile | 8 ++- bin/sh/tests/functional_test.sh | 72 ++++++++++++++++++++++ bin/sh/tests/legacy_test.sh | 46 -------------- bin/sh/tests/parameters/Makefile | 8 ++- bin/sh/tests/parser/Makefile | 8 ++- bin/sh/tests/set-e/Makefile | 8 ++- tools/build/mk/OptionalObsoleteFiles.inc | 1 + 21 files changed, 126 insertions(+), 86 deletions(-) create mode 100755 bin/sh/tests/functional_test.sh delete mode 100644 bin/sh/tests/legacy_test.sh diff --git a/bin/sh/tests/Makefile b/bin/sh/tests/Makefile index 51c6dc443..c092962ae 100644 --- a/bin/sh/tests/Makefile +++ b/bin/sh/tests/Makefile @@ -4,15 +4,12 @@ TESTSDIR= ${TESTSBASE}/bin/sh -TAP_TESTS_SH= legacy_test -TAP_TESTS_SH_SED_legacy_test= -e 's,__SH__,/bin/sh,g' -# Some tests in here are silently not run when the tests are executed as -# root. Explicitly tell Kyua to drop privileges. -# -# TODO(jmmv): Kyua needs to do this by default, not only when explicitly -# requested. See https://code.google.com/p/kyua/issues/detail?id=6 -TEST_METADATA.legacy_test+= required_user="unprivileged" - -SUBDIR+= builtins errors execution expansion parameters parser set-e +TESTS_SUBDIRS+= builtins +TESTS_SUBDIRS+= errors +TESTS_SUBDIRS+= execution +TESTS_SUBDIRS+= expansion +TESTS_SUBDIRS+= parameters +TESTS_SUBDIRS+= parser +TESTS_SUBDIRS+= set-e .include diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index ec4cab630..527c1b384 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -2,8 +2,12 @@ .include -FILESDIR= ${TESTSBASE}/bin/sh/builtins -KYUAFILE= no +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= alias.0 alias.0.stdout FILES+= alias.1 alias.1.stderr diff --git a/bin/sh/tests/errors/Makefile b/bin/sh/tests/errors/Makefile index ab04f1475..51a766f6f 100644 --- a/bin/sh/tests/errors/Makefile +++ b/bin/sh/tests/errors/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/errors -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= assignment-error1.0 FILES+= assignment-error2.0 diff --git a/bin/sh/tests/errors/bad-parm-exp2.2 b/bin/sh/tests/errors/bad-parm-exp2.2 index 7e13d2b89..a0826ecf9 100644 --- a/bin/sh/tests/errors/bad-parm-exp2.2 +++ b/bin/sh/tests/errors/bad-parm-exp2.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${} +eval '${}' diff --git a/bin/sh/tests/errors/bad-parm-exp2.2.stderr b/bin/sh/tests/errors/bad-parm-exp2.2.stderr index d027a5ad4..51ea69ca9 100644 --- a/bin/sh/tests/errors/bad-parm-exp2.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp2.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp2.2: ${}: Bad substitution +eval: ${}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp3.2 b/bin/sh/tests/errors/bad-parm-exp3.2 index a5ecba5a7..bb41208f2 100644 --- a/bin/sh/tests/errors/bad-parm-exp3.2 +++ b/bin/sh/tests/errors/bad-parm-exp3.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${foo/} +eval '${foo/}' diff --git a/bin/sh/tests/errors/bad-parm-exp3.2.stderr b/bin/sh/tests/errors/bad-parm-exp3.2.stderr index ef40251f2..70473f9a8 100644 --- a/bin/sh/tests/errors/bad-parm-exp3.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp3.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp3.2: ${foo/}: Bad substitution +eval: ${foo/}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp4.2 b/bin/sh/tests/errors/bad-parm-exp4.2 index 9eec8d084..2837f9b5b 100644 --- a/bin/sh/tests/errors/bad-parm-exp4.2 +++ b/bin/sh/tests/errors/bad-parm-exp4.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${foo:@abc} +eval '${foo:@abc}' diff --git a/bin/sh/tests/errors/bad-parm-exp4.2.stderr b/bin/sh/tests/errors/bad-parm-exp4.2.stderr index 89bd80f0e..3363f5177 100644 --- a/bin/sh/tests/errors/bad-parm-exp4.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp4.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp4.2: ${foo:@...}: Bad substitution +eval: ${foo:@...}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp5.2 b/bin/sh/tests/errors/bad-parm-exp5.2 index 459281f04..1ba343bb7 100644 --- a/bin/sh/tests/errors/bad-parm-exp5.2 +++ b/bin/sh/tests/errors/bad-parm-exp5.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${/} +eval '${/}' diff --git a/bin/sh/tests/errors/bad-parm-exp5.2.stderr b/bin/sh/tests/errors/bad-parm-exp5.2.stderr index 89b19978f..13763f8ed 100644 --- a/bin/sh/tests/errors/bad-parm-exp5.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp5.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp5.2: ${/}: Bad substitution +eval: ${/}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp6.2 b/bin/sh/tests/errors/bad-parm-exp6.2 index ba51442fb..b53a91b36 100644 --- a/bin/sh/tests/errors/bad-parm-exp6.2 +++ b/bin/sh/tests/errors/bad-parm-exp6.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${#foo^} +eval '${#foo^}' diff --git a/bin/sh/tests/errors/bad-parm-exp6.2.stderr b/bin/sh/tests/errors/bad-parm-exp6.2.stderr index dbf14b596..cc56f65b6 100644 --- a/bin/sh/tests/errors/bad-parm-exp6.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp6.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp6.2: ${foo...}: Bad substitution +eval: ${foo...}: Bad substitution diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile index 302d0d824..2653d5ffe 100644 --- a/bin/sh/tests/execution/Makefile +++ b/bin/sh/tests/execution/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/execution -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= bg1.0 FILES+= bg2.0 diff --git a/bin/sh/tests/expansion/Makefile b/bin/sh/tests/expansion/Makefile index e62fea4f0..d6f3c1a01 100644 --- a/bin/sh/tests/expansion/Makefile +++ b/bin/sh/tests/expansion/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/expansion -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= arith1.0 FILES+= arith2.0 diff --git a/bin/sh/tests/functional_test.sh b/bin/sh/tests/functional_test.sh new file mode 100755 index 000000000..698053885 --- /dev/null +++ b/bin/sh/tests/functional_test.sh @@ -0,0 +1,72 @@ +# +# Copyright 2014 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# $FreeBSD$ + +SRCDIR=$(atf_get_srcdir) + +check() +{ + local tc=${1}; shift + + export SH=$(atf_config_get bin.sh.test_shell /bin/sh) + + local err_file="${SRCDIR}/${tc}.stderr" + [ -f "${err_file}" ] && err_flag="-e file:${err_file}" + local out_file="${SRCDIR}/${tc}.stdout" + [ -f "${out_file}" ] && out_flag="-o file:${out_file}" + + atf_check -s exit:${tc##*.} ${err_flag} ${out_flag} ${SH} "${SRCDIR}/${tc}" +} + +add_testcase() +{ + local tc=${1} + local tc_escaped word + + case "${tc%.*}" in + *-*) + local IFS="-" + for word in ${tc%.*}; do + tc_escaped="${tc_escaped:+${tc_escaped}_}${word}" + done + ;; + *) + tc_escaped=${tc%.*} + ;; + esac + + atf_test_case ${tc_escaped} + eval "${tc_escaped}_body() { check ${tc}; }" + atf_add_test_case ${tc_escaped} +} + +atf_init_test_cases() +{ + for path in $(find -Es "${SRCDIR}" -regex '.*\.[0-9]+$'); do + add_testcase ${path##*/} + done +} diff --git a/bin/sh/tests/legacy_test.sh b/bin/sh/tests/legacy_test.sh deleted file mode 100644 index d43f5ddd8..000000000 --- a/bin/sh/tests/legacy_test.sh +++ /dev/null @@ -1,46 +0,0 @@ -# $FreeBSD$ - -: ${SH:="__SH__"} -export SH - -# TODO(jmmv): The Kyua TAP interface should be passing us the value of -# "srcdir" as an environment variable, just as it does with the ATF -# interface in the form of a configuration variable. For now, just try -# to guess this. -: ${TESTS_DATA:=$(dirname ${0})} - -COUNTER=1 - -do_test() { - c=${COUNTER} - COUNTER=$((COUNTER+1)) - ${SH} $1 > tmp.stdout 2> tmp.stderr - if [ $? -ne $2 ]; then - echo "not ok ${c} - ${1} # wrong exit status" - rm tmp.stdout tmp.stderr - return - fi - sed -I '' -e "s|^${TESTS_DATA}|.|" tmp.stderr - for i in stdout stderr; do - if [ -f ${1}.${i} ]; then - if ! cmp -s tmp.${i} ${1}.${i}; then - echo "not ok ${c} - ${1} # wrong output on ${i}" - rm tmp.stdout tmp.stderr - return - fi - elif [ -s tmp.${i} ]; then - echo "not ok ${c} - ${1} # wrong output on ${i}" - rm tmp.stdout tmp.stderr - return - fi - done - echo "ok ${c} - ${1}" - rm tmp.stdout tmp.stderr -} - -TESTS=$(find -Es ${TESTS_DATA} -regex ".*\.[0-9]+") -printf "1..%d\n" $(echo ${TESTS} | wc -w) - -for i in ${TESTS} ; do - do_test ${i} ${i##*.} -done diff --git a/bin/sh/tests/parameters/Makefile b/bin/sh/tests/parameters/Makefile index e31b78f44..aa1462f40 100644 --- a/bin/sh/tests/parameters/Makefile +++ b/bin/sh/tests/parameters/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/parameters -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= env1.0 FILES+= exitstatus1.0 diff --git a/bin/sh/tests/parser/Makefile b/bin/sh/tests/parser/Makefile index b769a30fe..63f4e8f8c 100644 --- a/bin/sh/tests/parser/Makefile +++ b/bin/sh/tests/parser/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/parser -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= alias1.0 FILES+= alias2.0 diff --git a/bin/sh/tests/set-e/Makefile b/bin/sh/tests/set-e/Makefile index 55d79174f..f733b60b1 100644 --- a/bin/sh/tests/set-e/Makefile +++ b/bin/sh/tests/set-e/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/set-e -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= and1.0 FILES+= and2.1 diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc index 549b7b6ee..4361d08f5 100644 --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -4468,6 +4468,7 @@ OLD_FILES+=usr/share/aclocal/atf-common.m4 OLD_FILES+=usr/share/aclocal/atf-sh.m4 OLD_DIRS+=usr/share/aclocal OLD_FILES+=usr/tests/bin/date/legacy_test +OLD_FILES+=usr/tests/bin/sh/legacy_test OLD_FILES+=usr/tests/lib/atf/libatf-c/test_helpers_test OLD_FILES+=usr/tests/lib/atf/test-programs/fork_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/application_test -- 2.42.0