]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[rt46602] Pass port numbers to tests via environment variables
authorStephen Morris <stephen@isc.org>
Thu, 14 Dec 2017 15:02:01 +0000 (15:02 +0000)
committerEvan Hunt <each@isc.org>
Sun, 25 Feb 2018 17:26:20 +0000 (09:26 -0800)
(cherry picked from commit f5d8f079008b648d2e343543e66dd728054c6101)
(cherry picked from commit f10b6cfeb6a78e9bf81d4199d4cc6ba10cae5bfb)
(cherry picked from commit 73d352793141d17eded65b0f93dadfc9ab28711a)

bin/tests/system/README
bin/tests/system/allow_query/setup.sh
bin/tests/system/allow_query/tests.sh
bin/tests/system/conf.sh.in
bin/tests/system/getopts.sh [deleted file]
bin/tests/system/rpz/setup.sh
bin/tests/system/rpz/tests.sh
bin/tests/system/rrl/tests.sh
bin/tests/system/run.sh

index 3a73a2b32c2fa583fa0ba5d9169ce830bf51488c..abd79abff2ff614df5a4ddaf7de8531766a6b82b 100644 (file)
@@ -65,7 +65,7 @@ Running the Tests
 ===
 The tests can be run individually using the following command:
 
-    sh run.sh [flags] <test-name>
+    sh run.sh [flags] <test-name> [<test-arguments>]
 
 e.g.
 
@@ -73,8 +73,12 @@ e.g.
 
 Optional flags are:
 
-    -p <number>     Sets the range of ports used by the test.  If not
-                    specified, the test will use ports 5300 to 5309.
+    -p <number>     Sets the range of ports used by the test.  A block of 10
+                    ports is available for each test, the number given to the
+                    "-p" switch being the number of the start of that block
+                    (e.g.  "-p 7900" will mean that the test is able to use
+                    ports 7900 through 7909).  If not specified, the test will
+                    use ports 5300 to 5309.
     -n              Noclean - do not remove the output files if the test
                     completes successfully.  By default, files created by the
                     test are deleted if it passes;  they are not deleted if the
@@ -85,17 +89,27 @@ Optional flags are:
                     Python or Perl) that feature test-specific behavior. The
                     servers are automatically started before the test is run
                     and stopped after it ends.  This flag leaves them running
-                    at the end of the test.
+                    at the end of the test, so that additional queries can be
+                    sent by hand.  To stop the servers afterwards, use the
+                    command "sh stop.sh <test-name>".
     -d <arg>        Arguments to the "date" command used to produce the
                     start and end time of the tests.  For example, the
                     switch
 
                         -d "+%Y-%m-%d:%h:%M:%s"
 
-                    would cause the "S" and "E" messages (see below) to have the
-                    date looking like "2017-11-23:16:06:32" instead of the
+                    would cause the "S" and "E" messages (see below) to have
+                    the date looking like "2017-11-23:16:06:32" instead of the
                     default "Thu, 23 Nov 2017 16:06:32 +0000".
 
+Arguments are:
+
+    test-name       Mandatory. The name of the test, which is the name of the
+                    subdirectory in bin/tests/system holding the test files.
+
+    test-arguments  Optional arguments that are passed to each of the test's
+                    scripts.
+
 To run all the system tests, type either:
 
     sh runall.sh [numproc]
@@ -108,7 +122,7 @@ When running all the tests, the output is sent to the file systests.output
 (in the bin/tests/system) directory.
 
 The "numproc" option specifies the maximum number of tests that can run
-simultaneously.  The default is 1, which means that all the test run
+simultaneously.  The default is 1, which means that all of the tests run
 sequentially. If greater than 1, up to "numproc" tests will run simultaneously.
 (Each will use a unique set of ports, so there is no danger of them interfering
 with one another.)
@@ -196,7 +210,7 @@ files produced by the tests should be deleted first.
 Deletion of files produced by an individual test can be done with the
 command:
 
-    (cd testname ; sh clean.sh)
+    sh clean.sh <test-name>
 
 Deletion of the files produced by the set of tests (e.g. after the execution
 of "runall.sh") can be deleted by the command:
@@ -251,29 +265,28 @@ ans<N>      Like ns[X], but these are simple mock name servers implemented in
 Port Usage
 ---
 In order for the tests to run in parallel, each test requires a unique set of
-ports.  These are specified by the "-p" option passed to "run.sh".  This option
-is then passed to each of the test control scripts listed above.
+ports.  These are specified by the "-p" option passed to "run.sh", which sets
+environment variables that the scripts listed above can reference.
 
 The convention used in the system tests is that the number passed is the start
 of a range of 10 ports.  The test is free to use the ports as required,
 although present usage is that the lowest port is used as the query port and
-the highest is used as the control port.  This is reinforced by the script
-getopts.sh: if used to parse the "-p" option (see below), the script sets the
-following shell variables:
+the highest is used as the control port.  This is reinforced by the environment
+variables set by run.sh. These are:
+
+    PORT                     Number to be used for the query port.
+    CONTROLPORT              Number to be used as the RNDC control port.
+    EXTRAPORT1 - EXTRAPORT8  Eight port numbers that can be use as needed.
+
+Two other environment variables are defined:
 
-    port                Number to be used for the query port.
-    controlport         Number to be used as the RNDC control port.
-    aport1 - aport8     Eight port numbers that the test can use as needed.
+    LOWPORT                  The lowest port number in the range.
+    HIGHPORT                 The highest port number in the range.
 
 When running tests in paralel (i.e. giving a value of "numproc" greater than 1
 in the "make" or "runall.sh" commands listed above), it is guaranteed that each
 test will get a set of unique port numbers.
 
-In addition, the "getopts.sh" script also defines the following symbols:
-
-    portlow             Lowest port number in the range.
-    porthigh            Highest port number in the range.
-
 
 Writing a Test
 ---
@@ -283,51 +296,19 @@ nameserver instances) to run.  Certain expectations are put on each script:
 
 General
 ---
-Each of the four scripts will be invoked with the command
+1. Each of the four scripts will be invoked with the command
+
+    sh <script> [<arguments>]
 
-    sh <script> -p <baseport> -- <arguments>
+Thhe optional arguments are test-specific.  They are
 
 Each script should start with the following lines:
 
     SYSTEMTESTTOP=..
     . $SYSTEMTESTTOP/conf.sh
-    . $SYSTEMTESTTOP/getopts.sh
 
 "conf.sh" defines a series of environment variables together with functions
-useful for the test scripts.  "getopts.sh" parses the "-p" option and sets the
-shell variables listed above. (They are not combined into one script because,
-in certain instances - notably in "run.sh" - some processing is required
-between the setting of the environment variables and the parsing of the port).
-
-The "--" between the "-p <baseport>" and any other arguments is required:
-without it, any other switches passed to the script would be parsed by
-getopts.sh, which would return an error because it would not recognise them.
-getopts.sh removes the "-p <port> --" from the argument list, leaving the
-script free to do its own parsing of any additional arguments.
-
-For example, if "test.sh" is invoked as:
-
-    sh tests.sh -p 12340 -- -D 1
-
-... and it includes the three lines listed above, after the execution of the
-code in getopts.sh, the following variables would be defined (with their
-associated values):
-
-    port        12340
-    aport1      12341
-    aport2      12342
-      :           :
-    aport8      12348
-    controlport 12349
-    portlow     12340
-    porthigh    12349
-
-    $1          -D
-    $2          1
-
-Should a script need to invoke another, it should pass the base port with the
-"-p" switch and add any additional arguments after the "--", i.e.  using the
-same format as listed above in the example for invoking "tests.sh"
+useful for the test scripts.
 
 
 prereq.sh
@@ -336,8 +317,9 @@ As noted above, this is optional.  If present, it should check whether specific
 software needed to run the test is available and/or whether BIND has been
 configured with the appropriate options required.
 
-    * If the software required to run the test is present and the BIND configure
-      options are correct, prereq.sh should return with a status code of 0.
+    * If the software required to run the test is present and the BIND
+      configure options are correct, prereq.sh should return with a status code
+       of 0.
 
     * If the software required to run the test is not available and/or BIND
       has not been configured with the appropriate options, prereq.sh should
@@ -360,10 +342,10 @@ Instead, setup.sh is responsible for editing the configuration files to set the
 port numbers.
 
 To do this, configuration files should be supplied in the form of templates
-containing tokens identifying ports.  The tokens have the same name as the shell
-variables listed above, but in upper-case and prefixed and suffixed by the "@"
-symbol.  For example, a fragment of a configuration file template might look
-like:
+containing tokens identifying ports.  The tokens have the same name as the
+shell variables listed above, but in upper-case and prefixed and suffixed by
+the "@" symbol.  For example, a fragment of a configuration file template might
+look like:
 
     controls {
         inet 10.53.0.1 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
@@ -378,32 +360,19 @@ like:
     };
 
 setup.sh should copy the template to the desired filename using the
-"copy_setports" shell function defined in "getopts.sh", i.e.
+"copy_setports" shell function defined in "conf.sh", i.e.
 
     copy_setports ns1/named.conf.in ns1/named.conf
 
-This replaces the tokens @PORT@, @CONTROLPORT@, @APORT1@ through @APORT8@ with
-the contents of the shell variables listed above.  setup.sh should do this for
-all configuration files required when the test starts.
-
-A second important responsibility of setup.sh is to create a file called
-named.port in each "named" nameserver directory that defines the query port for
-that server, e.g.
-
-    echo $port > ns1/named.port
-
-The file is used by the framework to determine the port it should use to query
-the nameserver.  In most cases, all nameservers will use the same port number
-for queries.  Some tests may require a different port to be used for queries,
-which is why this task has been delegated to test-specific setup rather than be
-part of the framework.
-
+This replaces the tokens @PORT@, @CONTROLPORT@, @EXTRAPORT1@ through
+@EXTRAPORT8@ with the contents of the shell variables listed above.  setup.sh
+should do this for all configuration files required when the test starts.
 
 tests.sh
 ---
-This is the main test file and the contents depend on the test. The contents are
-completely up to the developer, although most test scripts have a form similar
-to the following for each test:
+This is the main test file and the contents depend on the test. The contents
+are completely up to the developer, although most test scripts have a form
+similar to the following for each test:
 
     1. n=`expr $n + 1`
     2. echo_i "prime cache nodata.example ($n)"
index 7c28fab4bb3cfa567419074c93ae0cffeaa7b8cf..b2d09807f632f565629d0cdbcae027a9051291fc 100644 (file)
@@ -14,8 +14,8 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-. ../getopts.sh
+SYSTEMTESTTOP=..
+. $SYSTEMTESTTOP/conf.sh
 
 copy_setports ../common/controls.conf.in ns2/controls.conf
 copy_setports  ns2/named01.conf.in ns2/named.conf
-echo "${port}" > ns2/named.port
index 95da6a010d3517d905d918df7e8e35f3c48d3118..4d2b4209bef3fa045ee39cfe946de7057d56a971 100644 (file)
 
 SYSTEMTESTTOP=..
 . $SYSTEMTESTTOP/conf.sh
-. $SYSTEMTESTTOP/getopts.sh
 
-DIGOPTS="+tcp +nosea +nostat +nocmd +norec +noques +noauth +noadd +nostats +dnssec -p ${port}"
+DIGOPTS="+tcp +nosea +nostat +nocmd +norec +noques +noauth +noadd +nostats +dnssec -p ${PORT}"
 
 rndc_reload() {
-    RNDCOUT=`$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p ${controlport} reload 2>&1`
+    RNDCOUT=`$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p ${CONTROLPORT} reload 2>&1`
     echo_i "ns2 $RNDCOUT"
 }
 
index 1666b491dda083894f8552a2af77c9df01a4166c..b7857b8ff9f7cf10cd7dc59c1e217b14fb8e6883 100644 (file)
@@ -191,6 +191,42 @@ echo_i() {
     echoinfo "I:$TESTNAME:$@"
 }
 
+#
+# Useful functions in test scripts
+#
+
+# nextpart: read everything that's been appended to a file since the
+# last time 'nextpart' was called.
+nextpart () {
+    [ -f $1.prev ] || echo "0" > $1.prev
+    prev=`cat $1.prev`
+    awk "NR > $prev "'{ print }
+         END          { print NR > "/dev/stderr" }' $1 2> $1.prev
+}
+
+# copy_setports - Copy Configuration File and Replace Ports
+#
+# Convenience function to copy a configuration file, replacing the symbols
+# QUERYPORT, CONTROLPORT and EXTRAPORT[1-8] with the values of the equivalent
+# environment variables. (These values are set by "run.sh", which calls the
+# scripts invoking this function.)
+#
+# Usage:
+#   copy_setports infile outfile
+
+copy_setports() {
+    sed -e "s/@PORT@/${PORT}/g" \
+        -e "s/@EXTRAPORT1@/${EXTRAPORT1}/g" \
+        -e "s/@EXTRAPORT2@/${EXTRAPORT1}/g" \
+        -e "s/@EXTRAPORT3@/${EXTRAPORT1}/g" \
+        -e "s/@EXTRAPORT4@/${EXTRAPORT1}/g" \
+        -e "s/@EXTRAPORT5@/${EXTRAPORT1}/g" \
+        -e "s/@EXTRAPORT6@/${EXTRAPORT1}/g" \
+        -e "s/@EXTRAPORT7@/${EXTRAPORT1}/g" \
+        -e "s/@EXTRAPORT8@/${EXTRAPORT1}/g" \
+        -e "s/@CONTROLPORT@/${CONTROLPORT}/g" $1 > $2
+}
+
 #
 # Export command paths
 #
diff --git a/bin/tests/system/getopts.sh b/bin/tests/system/getopts.sh
deleted file mode 100644 (file)
index 001cad5..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2017  Internet Systems Consortium, Inc. ("ISC")
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# Shell script snippet, must be sourced.
-#
-# Most system tests require use of at least two ports: the nameserver query
-# port and a port for RNDC access.  In addition, some tests require additional
-# ports (e.g. for tests of transfers between nameservers).
-#
-# To allow tests to run in parallel, each test must be allocated a unique set
-# ports to use.
-#
-# This script is used during testing to parse the "-p" option on the command
-# line invoking scripts used during the test.  The option sets the base of
-# a block of 10 ports used by the test.  A shell symbol is set for each port:
-#
-# port         Port used for queries (default to 5300)
-# aport1       First additional port (set to $port + 1)
-#   :
-# aport8       Eighth additional port (set to $port + 8)
-# controlport  Port used for RNDC (set to $port + 9)
-#
-# The fiule also defines a simple shell function to
-
-port=5300
-
-while getopts ":p:" flag; do
-    case "$flag" in
-       p) port=$OPTARG ;;
-       -) break ;;
-       *) exit 1 ;;
-    esac
-done
-shift $(($OPTIND - 1))
-OPTIND=1
-
-# Ensure port is numeric, above 1024 (limit of privileged port) and that
-# the upper of the 10 ports notionally assigned does not exceed 65535.
-
-if [ "$((${port}+0))" != "${port}" ] || [ "${port}" -le 1024 ] || [ "${port}" -gt 65520 ]; then
-    echo "Base of port range ($port) must be numeric and in the range 1025 to 65520" >&2
-    exit 1
-fi
-
-aport1=$(($port + 1))
-aport2=$(($port + 2))
-aport3=$(($port + 3))
-aport4=$(($port + 4))
-aport5=$(($port + 5))
-aport6=$(($port + 6))
-aport7=$(($port + 7))
-aport8=$(($port + 8))
-controlport=$(($port + 9))
-
-# Two more symbols that denote the limits of the range.
-
-portlow=$port
-porthigh=$controlport
-
-
-# copy_setports - Copy Configuration File and Replace Ports
-#
-# Convenience function to copy a configuration file, replacing the symbols
-# PORT, CONTROLPORT and APORT[1-8] with the port numbers set by the "-p"
-# option passed to the script.
-#
-# Usage:
-#   copy_setports infile outfile
-
-copy_setports() {
-    sed -e "s/@PORT@/${port}/g" \
-        -e "s/@APORT1@/${aport1}/g" \
-        -e "s/@APORT2@/${aport1}/g" \
-        -e "s/@APORT3@/${aport1}/g" \
-        -e "s/@APORT4@/${aport1}/g" \
-        -e "s/@APORT5@/${aport1}/g" \
-        -e "s/@APORT6@/${aport1}/g" \
-        -e "s/@APORT7@/${aport1}/g" \
-        -e "s/@APORT8@/${aport1}/g" \
-        -e "s/@CONTROLPORT@/${controlport}/g" < $1 > $2
-}
index 246417427daf29a221c359d453c58fb2ef5abbf6..65a468a1853f0cf41987153296eba4dab1a6646c 100644 (file)
@@ -18,7 +18,6 @@ set -e
 
 SYSTEMTESTTOP=..
 . $SYSTEMTESTTOP/conf.sh
-. $SYSTEMTESTTOP/getopts.sh
 
 QPERF=`$SHELL qperf.sh`
 
index ba1861f600a90fe3f7af94ed92815eca04f91619..15c070b5ebb041ede3eeeb43a19db985b354d631 100644 (file)
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id$
-
-
 # test response policy zones (RPZ)
 
 SYSTEMTESTTOP=..
 . $SYSTEMTESTTOP/conf.sh
-. $SYSTEMTESTTOP/getopts.sh
 
 ns=10.53.0
 ns1=$ns.1              # root, defining the others
@@ -64,7 +60,7 @@ if [ -z "$DNSRPS_TEST_MODE" ]; then
         echo "I:'dnsrps-only' found: skipping native RPZ sub-test"
     else
         echo "I:running native RPZ sub-test"
-       $SHELL ./$0 -p $port -- -D1 $ARGS || status=1
+       $SHELL ./$0 -D1 $ARGS || status=1
     fi
 
     if [ -e dnsrps-off ]; then
index c2ac2b21daab451794169600e0443cc388ca50c2..49f71ea56248ceaa51672176cb7a9756b43df533 100644 (file)
@@ -17,7 +17,6 @@
 
 SYSTEMTESTTOP=..
 . $SYSTEMTESTTOP/conf.sh
-. $SYSTEMTESTTOP/getopts.sh
 
 #set -x
 
index 79a84f1bceca2330c0145de1673d29d6c209a018..1b4b9db487ec71c288e4529fb9bed8c82d62fa71 100644 (file)
@@ -46,13 +46,49 @@ shift
 
 test -d $test || { echofail "$0: $test: no such test" >&2; exit 1; }
 
-# Validate the port number and obtain other port numbers.
-. $SYSTEMTESTTOP/getopts.sh -p "$baseport"
+# Define the number of ports allocated for this test, and the lowest and
+# highest valid values for the "-p" option.  The lowest valid value is one more
+# than the highest privileged port (1024).  As the number specifies the lowest
+# port number in a block of ports, the highest valid value is such that the
+# highest port number in that block is 65535.
+#
+# N.B.  It is assumed that the number of ports is >= 10.
+numport=10
+minvalid=`expr 1024 + 1`
+maxvalid=`expr 65535 - $numport + 1`
+
+test "$baseport" -eq "$baseport" > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+    echofail "Must specify a numeric value for the port"
+    exit 1
+elif [ $baseport -lt $minvalid -o $baseport -gt $maxvalid  ]; then
+    echofail "The port must be in the range $minvalid to $maxvalid" >&2
+    exit 1
+fi
+
+# Name the first 10 ports in the set: the query port, the control port and
+# eight extra ports.  Since the lowest numbered port (specified in the command
+# line) will usually be a multiple of 10, the names are chosen so that the
+# number of EXTRAPORTn is "n".
+export PORT=$baseport
+export EXTRAPORT1=`expr $baseport + 1`
+export EXTRAPORT2=`expr $baseport + 2`
+export EXTRAPORT3=`expr $baseport + 3`
+export EXTRAPORT4=`expr $baseport + 4`
+export EXTRAPORT5=`expr $baseport + 5`
+export EXTRAPORT6=`expr $baseport + 6`
+export EXTRAPORT7=`expr $baseport + 7`
+export EXTRAPORT8=`expr $baseport + 8`
+export CONTROLPORT=`expr $baseport + 9`
+
+export LOWPORT=$baseport
+export HIGHPORT=`expr $baseport + $numport - 1`
+
 
 echoinfo "S:$test:`date $dateargs`" >&2
 echoinfo "T:$test:1:A" >&2
 echoinfo "A:$test:System test $test" >&2
-echoinfo "I:$test:PORTRANGE:${portlow} - ${porthigh}"
+echoinfo "I:$test:PORTRANGE:${LOWPORT} - ${HIGHPORT}"
 
 if [ x${PERL:+set} = x ]
 then
@@ -63,7 +99,7 @@ then
 fi
 
 # Check for test-specific prerequisites.
-test ! -f $test/prereq.sh || ( cd $test && $SHELL prereq.sh -p "$port" -- "$@" )
+test ! -f $test/prereq.sh || ( cd $test && $SHELL prereq.sh "$@" )
 result=$?
 
 if [ $result -eq 0 ]; then
@@ -76,7 +112,7 @@ else
 fi
 
 # Test sockets after the prerequisites has been setup
-$PERL testsock.pl -p "${port}" || {
+$PERL testsock.pl -p $PORT  || {
     echowarn "I:$test:Network interface aliases not set up.  Skipping test." >&2;
     echowarn "R:$test:UNTESTED" >&2;
     echoinfo "E:$test:`date $dateargs`" >&2;
@@ -98,14 +134,14 @@ fi
 # Set up any dynamically generated test data
 if test -f $test/setup.sh
 then
-   ( cd $test && $SHELL setup.sh -p "$port" -- "$@" )
+   ( cd $test && $SHELL setup.sh "$@" )
 fi
 
 # Start name servers running
-$PERL start.pl --port $port $test || { echofail "R:$test:FAIL"; echoinfo "E:$test:`date $dateargs`"; exit 1; }
+$PERL start.pl --port $PORT $test || { echofail "R:$test:FAIL"; echoinfo "E:$test:`date $dateargs`"; exit 1; }
 
 # Run the tests
-( cd $test ; $SHELL tests.sh -p "$port" -- "$@" )
+( cd $test ; $SHELL tests.sh "$@" )
 status=$?
 
 if $stopservers
@@ -131,7 +167,7 @@ else
         rm -f $SYSTEMTESTTOP/random.data
         if test -f $test/clean.sh
         then
-                       ( cd $test && $SHELL clean.sh "-p" "$port" -- "$@" )
+               ( cd $test && $SHELL clean.sh "$@" )
         fi
         if test -d ../../../.git
         then