Module Name: othersrc Committed By: agc Date: Sun May 29 20:47:56 UTC 2016
Added Files: othersrc/external/bsd/human2atf: Makefile README Testspec.template human2atf.1 human2atf.sh Log Message: Add human2atf, a means of generating ATF test scripts through a short test specification file. human2atf is a frontend for the ATF test harness. The idea is to provide an easy/simple way to sepcify tests, and to provide the correct environment for running these test cases. In order to accomplish this, a specfile, (by default Testspec) is given to human2atf, which is a shell script which produces the test Makefile, and t_*.sh shell script used by atf. The Testspec file is itself a shell file fragment. It specifies the names of the files which are to be used in testing, which are typically input files to the command being tested, and expected output files. Care should be taken in naming test sets so that a name that is a shell variable is used. It is advised that individual test cases are grouped into functionally-related test sets. This is not enforced, but is good practice since the tests are used together as a regression test suite, and so changes to utilities may show up in certain parts of the utility being tested, but not in others. Grouping indivual functionally-related test cases into a test set for that functionality is thus a good idea. Some hand-rolled tests in the tree use shell "here" documents, which can interfere with control flow unless used carefully. To avoid this, human2atf encodes its input and expected output files using base64 uuencoding, so that the contents of such files do not affect the way that the human2atf shell script itself works. For a test set, all that need to be specified are: + the testset name + any input and expected output files + the test cases themselves To use a worked example, to enable atf tests for a (possibly fictional) utility called b2e, a Testspec file was drawn up: TESTNAME=b2e TESTSET_1_NAME=basics TESTSET_1_FILES=' 1.in 1.expected 2.in 2.expected ' TESTSET_1_CASE_1="-s eq:0 -o file:1.expected -e empty b2e < 1.in" TESTSET_1_CASE_2="-s eq:0 -o file:2.expected -e empty b2e < 2.in" TESTSET_2_NAME=extended TESTSET_2_FILES=' 3.in 3.expected 4.in 4.expected 5.in 5.expected ' TESTSET_2_CASE_1="-s eq:0 -o file:3.expected -e empty b2e < 3.in" TESTSET_2_CASE_2="-s eq:0 -o file:4.expected -e empty b2e < 4.in" DISABLE_TESTSET_2_CASE_3="-s eq:0 -o file:5.expected -e empty b2e < 5.in" This specifies 2 test sets, the first set containing 2 test cases, and the second set containing 3 test cases. The first test set is for basic test cases, the second set is for extended tests (see the TESTSET_n_NAME definition). Test cases must be numbered in increasing order from 1, and may not miss numbers. (When the human2atf test script finds that a test case is not defined, it stops processing). The same numbering restrictions are in place for test sets. To provide the tests a useful environment in which to function, input and expected output files are specified. These are given in the TESTSET_n_FILES definition. Individual test cases are specified using the TESTSET_n_CASE_m style of definition. Occasionally, we will want to add a test and its supporting files, but leave it disabled (until appropriate functionality is written or debugged fully, for example) - for that case, the DISABLE_TESTSET_n_CASE_m definition is used. I opted to leave the atf-style of command invocation in there as the expected output file is specified in the test case itself but not as part of the command, so it seemed simpler to do it that way. Test execution (the directory and Makefile in tests/usr.bin had already been set up): [12:34:14] agc@netbsd-002 ~/local/human2atf-20160528 [3068] > ./human2atf -f Testspec2 Generating Makefile for b2e tests as tests-Makefile Generating test harness t_b2e.sh for b2e [12:34:19] agc@netbsd-002 ~/local/human2atf-20160528 [3069] > sudo cp t_b2e.sh =1 [12:34:30] agc@netbsd-002 ~/local/human2atf-20160528 [3070] > pushd +1 /usr/tests/usr.bin/b2e ~/local/human2atf-20160528 [12:34:33] agc@netbsd-002 ...tests/usr.bin/b2e [3071] > l total 20 drwxr-xr-x 2 root wheel 512 May 28 23:23 . drwxr-xr-x 35 root wheel 1024 May 28 19:17 .. -rw-r--r-- 1 root wheel 136 May 28 19:18 Atffile -rw-r--r-- 1 root wheel 112 May 28 19:18 Makefile -rw-r--r-- 1 root wheel 2184 May 28 23:23 atf-run.log -rwxr-xr-x 1 root wheel 3368 May 28 23:23 t_b2e -rw-r--r-- 1 root wheel 3751 May 29 12:34 t_b2e.sh [12:34:34] agc@netbsd-002 ...tests/usr.bin/b2e [3072] > sudo make # build b2e/t_b2e echo '#! /usr/bin/atf-sh' >t_b2e.tmp cat t_b2e.sh >>t_b2e.tmp chmod +x t_b2e.tmp mv t_b2e.tmp t_b2e [12:34:39] agc@netbsd-002 ...tests/usr.bin/b2e [3073] > sudo make test *** WARNING: make test is experimental *** *** Using this test does not preclude you from running the tests *** installed in /usr/tests. This test run may raise false *** positives and/or false negatives. Tests root: /usr/tests/usr.bin/b2e t_b2e (1/1): 2 test cases b2e_testset_1_basics: [0.031023s] Passed. b2e_testset_2_extended: [0.026240s] Passed. [0.060611s] Summary for 1 test programs: 2 passed test cases. 0 failed test cases. 0 expected failed test cases. 0 skipped test cases. *** The verbatim output of atf-run has been saved to /usr/tests/usr.bin/b2e/atf-run.log *** Once again, note that make test is unsupported. [12:34:43] agc@netbsd-002 ...tests/usr.bin/b2e [3074] > Alistair Crooks Sun May 29 12:41:19 PDT 2016 To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/human2atf/Makefile \ othersrc/external/bsd/human2atf/README \ othersrc/external/bsd/human2atf/Testspec.template \ othersrc/external/bsd/human2atf/human2atf.1 \ othersrc/external/bsd/human2atf/human2atf.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Added files: Index: othersrc/external/bsd/human2atf/Makefile diff -u /dev/null othersrc/external/bsd/human2atf/Makefile:1.1 --- /dev/null Sun May 29 20:47:56 2016 +++ othersrc/external/bsd/human2atf/Makefile Sun May 29 20:47:56 2016 @@ -0,0 +1,7 @@ +# $NetBSD: Makefile,v 1.1 2016/05/29 20:47:56 agc Exp $ + +SCRIPTS= human2atf +SCRIPTSDIR= /usr/bin +MAN= human2atf.1 + +.include <bsd.prog.mk> Index: othersrc/external/bsd/human2atf/README diff -u /dev/null othersrc/external/bsd/human2atf/README:1.1 --- /dev/null Sun May 29 20:47:56 2016 +++ othersrc/external/bsd/human2atf/README Sun May 29 20:47:56 2016 @@ -0,0 +1,135 @@ +human2atf is a frontend for the ATF test harness. The idea is to provide +an easy/simple way to sepcify tests, and to provide the correct +environment for running these test cases. + +In order to accomplish this, a specfile, (by default Testspec) is +given to human2atf, which is a shell script which produces the test +Makefile, and t_*.sh shell script used by atf. The Testspec file is +itself a shell file fragment. It specifies the names of the files +which are to be used in testing, which are typically input files to +the command being tested, and expected output files. Care should be +taken in naming test sets so that a name that is a shell variable is +used. + +It is advised that individual test cases are grouped into +functionally-related test sets. This is not enforced, but is good +practice since the tests are used together as a regression test suite, +and so changes to utilities may show up in certain parts of the +utility being tested, but not in others. Grouping indivual +functionally-related test cases into a test set for that functionality +is thus a good idea. + +Some hand-rolled tests in the tree use shell "here" documents, which +can interfere with control flow unless used carefully. To avoid this, +human2atf encodes its input and expected output files using base64 +uuencoding, so that the contents of such files do not affect the way +that the human2atf shell script itself works. + +For a test set, all that need to be specified are: + + the testset name + + any input and expected output files + + the test cases themselves + +To use a worked example, to enable atf tests for a (possibly fictional) +utility called b2e, a Testspec file was drawn up: + + TESTNAME=b2e + + TESTSET_1_NAME=basics + TESTSET_1_FILES=' + 1.in + 1.expected + 2.in + 2.expected + ' + TESTSET_1_CASE_1="-s eq:0 -o file:1.expected -e empty b2e < 1.in" + TESTSET_1_CASE_2="-s eq:0 -o file:2.expected -e empty b2e < 2.in" + + TESTSET_2_NAME=extended + TESTSET_2_FILES=' + 3.in + 3.expected + 4.in + 4.expected + 5.in + 5.expected + ' + TESTSET_2_CASE_1="-s eq:0 -o file:3.expected -e empty b2e < 3.in" + TESTSET_2_CASE_2="-s eq:0 -o file:4.expected -e empty b2e < 4.in" + DISABLE_TESTSET_2_CASE_3="-s eq:0 -o file:5.expected -e empty b2e < 5.in" + +This specifies 2 test sets, the first set containing 2 test cases, and +the second set containing 3 test cases. The first test set is for +basic test cases, the second set is for extended tests (see the +TESTSET_n_NAME definition). Test cases must be numbered in increasing +order from 1, and may not miss numbers. (When the human2atf test +script finds that a test case is not defined, it stops processing). + +The same numbering restrictions are in place for test sets. + +To provide the tests a useful environment in which to function, input +and expected output files are specified. These are given in the +TESTSET_n_FILES definition. + +Individual test cases are specified using the TESTSET_n_CASE_m style of +definition. + +Occasionally, we will want to add a test and its supporting files, but +leave it disabled (until appropriate functionality is written or +debugged fully, for example) - for that case, the +DISABLE_TESTSET_n_CASE_m definition is used. + +I opted to leave the atf-style of command invocation in there as the +expected output file is specified in the test case itself but not as +part of the command, so it seemed simpler to do it that way. + +Test execution (the directory and Makefile in tests/usr.bin had +already been set up): + + [12:34:14] agc@netbsd-002 ~/local/human2atf-20160528 [3068] > ./human2atf.sh -f Testspec2 + Generating Makefile for b2e tests as tests-Makefile + Generating test harness t_b2e.sh for b2e + [12:34:19] agc@netbsd-002 ~/local/human2atf-20160528 [3069] > sudo cp t_b2e.sh =1 + [12:34:30] agc@netbsd-002 ~/local/human2atf-20160528 [3070] > pushd +1 + /usr/tests/usr.bin/b2e ~/local/human2atf-20160528 + [12:34:33] agc@netbsd-002 ...tests/usr.bin/b2e [3071] > l + total 20 + drwxr-xr-x 2 root wheel 512 May 28 23:23 . + drwxr-xr-x 35 root wheel 1024 May 28 19:17 .. + -rw-r--r-- 1 root wheel 136 May 28 19:18 Atffile + -rw-r--r-- 1 root wheel 112 May 28 19:18 Makefile + -rw-r--r-- 1 root wheel 2184 May 28 23:23 atf-run.log + -rwxr-xr-x 1 root wheel 3368 May 28 23:23 t_b2e + -rw-r--r-- 1 root wheel 3751 May 29 12:34 t_b2e.sh + [12:34:34] agc@netbsd-002 ...tests/usr.bin/b2e [3072] > sudo make + # build b2e/t_b2e + echo '#! /usr/bin/atf-sh' >t_b2e.tmp + cat t_b2e.sh >>t_b2e.tmp + chmod +x t_b2e.tmp + mv t_b2e.tmp t_b2e + [12:34:39] agc@netbsd-002 ...tests/usr.bin/b2e [3073] > sudo make test + *** WARNING: make test is experimental + *** + *** Using this test does not preclude you from running the tests + *** installed in /usr/tests. This test run may raise false + *** positives and/or false negatives. + + Tests root: /usr/tests/usr.bin/b2e + + t_b2e (1/1): 2 test cases + b2e_testset_1_basics: [0.031023s] Passed. + b2e_testset_2_extended: [0.026240s] Passed. + [0.060611s] + + Summary for 1 test programs: + 2 passed test cases. + 0 failed test cases. + 0 expected failed test cases. + 0 skipped test cases. + + *** The verbatim output of atf-run has been saved to /usr/tests/usr.bin/b2e/atf-run.log + *** Once again, note that make test is unsupported. + [12:34:43] agc@netbsd-002 ...tests/usr.bin/b2e [3074] > + +Alistair Crooks +Sun May 29 12:41:19 PDT 2016 Index: othersrc/external/bsd/human2atf/Testspec.template diff -u /dev/null othersrc/external/bsd/human2atf/Testspec.template:1.1 --- /dev/null Sun May 29 20:47:56 2016 +++ othersrc/external/bsd/human2atf/Testspec.template Sun May 29 20:47:56 2016 @@ -0,0 +1,52 @@ +#! /bin/sh + +# $NetBSD: Testspec.template,v 1.1 2016/05/29 20:47:56 agc Exp $ + +# Copyright (c) 2016 Alistair Crooks <a...@netbsd.org> +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. 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 AUTHOR ``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 AUTHOR 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. +# + +TESTNAME=utility_being_tested + +TESTSET_1_NAME=basic_test_set +TESTSET_1_FILES=' +1.in +1.expected +2.in +2.expected +' +TESTSET_1_CASE_1="-s eq:0 -o file:1.expected -e empty b2e < 1.in" +TESTSET_1_CASE_2="-s eq:0 -o file:2.expected -e empty b2e < 2.in" + +TESTSET_2_NAME=extended_test_set +TESTSET_2_FILES=' +3.in +3.expected +4.in +4.expected +5.in +5.expected +' +TESTSET_2_CASE_1="-s eq:0 -o file:3.expected -e empty b2e < 3.in" +TESTSET_2_CASE_2="-s eq:0 -o file:4.expected -e empty b2e < 4.in" +DISABLE_TESTSET_2_CASE_3="-s eq:0 -o file:5.expected -e empty b2e < 5.in" Index: othersrc/external/bsd/human2atf/human2atf.1 diff -u /dev/null othersrc/external/bsd/human2atf/human2atf.1:1.1 --- /dev/null Sun May 29 20:47:56 2016 +++ othersrc/external/bsd/human2atf/human2atf.1 Sun May 29 20:47:56 2016 @@ -0,0 +1,119 @@ +.\" $NetBSD: human2atf.1,v 1.1 2016/05/29 20:47:56 agc Exp $ +.\" +.\" Copyright (c) 2016 Alistair Crooks <a...@netbsd.org> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. 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 AUTHOR ``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 AUTHOR 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. +.\" +.Dd May 29, 2016 +.Dt HUMAN2ATF 1 +.Os +.Sh NAME +.Nm human2atf +.Nd utility to generate ATF test harness script +.Sh SYNOPSIS +.Nm +.Fl v +.Op Fl f Ar TestspecFile +.Sh DESCRIPTION +The +.Nm +command generates a Makefile and test shell script, suitable for +use as input to +.Xr atf 7 . +It uses a test specification file, which is in the form of a shell script fragment, +to set up various high-level definitions, which are then expanded into a +test shell script. +It is aimed at using a very small and succinct vocabulary to be +able to specify the test sets, and individual test cases. +.Pp +The following options are available: +.Bl -tag -width raidN123 +.It Fl f Ar Testspec +Use the definitions in the file given as the argument in place +of the default file, which is named +.Dq Testspec . +.It Fl v +Perform operations in a verbose manner (useful for debugging) +.El +.Pp +.Sh RETURN VALUES +The +.Nm +utility will return 0 for success, +and non-zero for failure. +.Sh EXAMPLES +.Bd -literal +% ./human2atf.sh -f Testspec2 +Generating Makefile for b2e tests as tests-Makefile +Generating test harness t_b2e.sh for b2e +% sudo cp t_b2e.sh =1 +% pushd +1 +/usr/tests/usr.bin/b2e ~/local/human2atf-20160528 +% l +total 20 +drwxr-xr-x 2 root wheel 512 May 28 23:23 . +drwxr-xr-x 35 root wheel 1024 May 28 19:17 .. +-rw-r--r-- 1 root wheel 136 May 28 19:18 Atffile +-rw-r--r-- 1 root wheel 112 May 28 19:18 Makefile +-rw-r--r-- 1 root wheel 2184 May 28 23:23 atf-run.log +-rwxr-xr-x 1 root wheel 3368 May 28 23:23 t_b2e +-rw-r--r-- 1 root wheel 3751 May 29 12:34 t_b2e.sh +% sudo make +# build b2e/t_b2e +echo '#! /usr/bin/atf-sh' >t_b2e.tmp +cat t_b2e.sh >>t_b2e.tmp +chmod +x t_b2e.tmp +mv t_b2e.tmp t_b2e +% sudo make test +*** WARNING: make test is experimental +*** +*** Using this test does not preclude you from running the tests +*** installed in /usr/tests. This test run may raise false +*** positives and/or false negatives. + +Tests root: /usr/tests/usr.bin/b2e + +t_b2e (1/1): 2 test cases + b2e_testset_1_basics: [0.031023s] Passed. + b2e_testset_2_extended: [0.026240s] Passed. +[0.060611s] + +Summary for 1 test programs: + 2 passed test cases. + 0 failed test cases. + 0 expected failed test cases. + 0 skipped test cases. + +*** The verbatim output of atf-run has been saved to /usr/tests/usr.bin/b2e/atf-run.log +*** Once again, note that make test is unsupported. +% +.Ed +.Sh SEE ALSO +.Xr atf 7 +.Sh HISTORY +The +.Nm +command first appeared in +.Nx 8.0 . +.Sh AUTHORS +.An -nosplit +.An Alistair Crooks Aq Mt a...@netbsd.org Index: othersrc/external/bsd/human2atf/human2atf.sh diff -u /dev/null othersrc/external/bsd/human2atf/human2atf.sh:1.1 --- /dev/null Sun May 29 20:47:56 2016 +++ othersrc/external/bsd/human2atf/human2atf.sh Sun May 29 20:47:56 2016 @@ -0,0 +1,180 @@ +#! /bin/sh + +# $NetBSD: human2atf.sh,v 1.1 2016/05/29 20:47:56 agc Exp $ + +# Copyright (c) 2016 Alistair Crooks <a...@netbsd.org> +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. 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 AUTHOR ``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 AUTHOR 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. +# + +TESTNAME="" +TESTSPEC=Testspec +args=$(getopt f:v $*) +set -- $args +while [ $# -gt 0 ]; do + case "$1" in + -f) TESTSPEC=$2; shift ;; + -v) set -x ;; + *) break; + esac + shift +done + +case "${TESTSPEC}" in +/*) ;; +*) TESTSPEC=./${TESTSPEC} +esac + +if [ -e ./${TESTSPEC} ]; then + . ./${TESTSPEC} +else + echo "No Testspec file \"${TESTSPEC}\"" >&2 + exit 1 +fi + +case "${TESTNAME}" in +"") echo "Usage: human2atf name" >&2 + exit 1 + ;; +esac + +echo "Generating Makefile for ${TESTNAME} tests as tests-Makefile" + +cat > tests-Makefile << EOF +# \$NetBSD\$ + +.include <bsd.own.mk> + +TESTSDIR= \${TESTSBASE}/usr.bin/${TESTNAME} + +TESTS_SH+= t_${TESTNAME} + +.include <bsd.test.mk> +EOF + +output=t_${TESTNAME}.sh + +echo "Generating test harness ${output} for ${TESTNAME}" + +cat > ${output} << human2atf_EOF +#! /bin/sh + +# \$NetBSD\$ + +# +# Copyright (c) 2016 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Alistair Crooks (a...@netbsd.org) +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. +# + +# Define test sets with atf_test_case +# There may well be only one test set - these are tests for different +# functionality, so netpgpverify has 2 sets, 1 for RSA and 1 for DSA +# each test set has a +# + *_head() function, to define the set, and +# + *_body(), to set up the supporting input and expected output files +# and some atf_check calls, which actually carry out the tests + +# any binary files should be uuencoded +# we need to give the input and expected output files like this as tests +# take place in a clean directory, so we need to be able to set them up +# from the shell script + +human2atf_EOF + +setnames="" +setnum=1 +while true; do + eval setname=\$TESTSET_${setnum}_NAME + if [ -z "${setname}" ]; then + break + fi + setnames="${setnames} ${TESTNAME}_testset_${setnum}_${setname}" + cat >> ${output} << human2atf_EOF +# Test set ${setnum} (${setname}) for ${TESTNAME} +atf_test_case ${TESTNAME}_testset_${setnum}_${setname} + +${TESTNAME}_testset_${setnum}_${setname}_head() { + atf_set "descr" "Test set ${setnum} (${setname}) for ${TESTNAME}" +} +${TESTNAME}_testset_${setnum}_${setname}_body() { +human2atf_EOF + eval filelist=\$TESTSET_${setnum}_FILES + for f in ${filelist}; do + if [ ! -f ${f} ]; then + echo "File ${f} not found" >&2 + continue + fi + echo " uudecode << EOF" >> ${output} + uuencode -m ${f} ${f} >> ${output} + echo EOF >> ${output} + done + casenum=1 + while true; do + eval cmd=\$TESTSET_${setnum}_CASE_${casenum} + if [ -n "${cmd}" ]; then + echo " atf_check ${cmd}" >> ${output} + else + eval cmd=\$DISABLE_TESTSET_${setnum}_CASE_${casenum} + if [ -n "${cmd}" ]; then + echo " #atf_check ${cmd}" >> ${output} + else + break + fi + fi + casenum=$(( casenum + 1 )) + done + echo '}' >> ${output} + echo '' >> ${output} + setnum=$(( setnum + 1 )) +done + +echo '# all test sets' >> ${output} +echo 'atf_init_test_cases() {' >> ${output} +for s in ${setnames}; do + echo " atf_add_test_case ${s}" >> ${output} +done +echo '}' >> ${output} +echo '' >> ${output}