Commit f5d8f079 authored by Stephen Morris's avatar Stephen Morris
Browse files

[rt46602] Pass port numbers to tests via environment variables

parent b2d90da0
......@@ -67,7 +67,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.
......@@ -75,8 +75,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
......@@ -87,17 +91,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]
......@@ -110,7 +124,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.)
......@@ -198,7 +212,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:
......@@ -253,29 +267,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
---
......@@ -285,51 +298,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
......@@ -338,8 +319,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
......@@ -362,10 +344,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; };
......@@ -380,32 +362,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)"
......
......@@ -8,8 +8,8 @@
# $Id: setup.sh,v 1.2 2010/11/16 01:37:36 sar Exp $
. ../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
......@@ -51,12 +51,11 @@
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"
}
......
......@@ -12,7 +12,6 @@ rm -f ns*/named.lock
rm -f ns*/named.memstats
rm -f ns*/named.conf
rm -f ns*/named.run
rm -f ns*/named.port
rm -f ns1/*dom*example.db
rm -f ns2/__catz__*db
rm -f ns2/named.conf.tmp
......
......@@ -20,7 +20,7 @@ options {
allow-new-zones yes;
pid-file "named.pid";
listen-on { 10.53.0.1; };
listen-on port @APORT1@ { 10.53.0.1; };
listen-on port @EXTRAPORT1@ { 10.53.0.1; };
listen-on-v6 { none; };
notify no;
recursion no;
......
......@@ -29,7 +29,7 @@ options {
in-memory no
zone-directory "zonedir";
zone "catalog2.example"
default-masters { 10.53.0.1 port @APORT1@; }
default-masters { 10.53.0.1 port @EXTRAPORT1@; }
in-memory yes;
zone "catalog3.example"
default-masters { 10.53.0.1; }
......
......@@ -8,7 +8,6 @@
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
. $SYSTEMTESTTOP/getopts.sh
copy_setports ns1/named.conf.in ns1/named.conf
copy_setports ns2/named.conf.in ns2/named.conf
......@@ -20,7 +19,3 @@ cp -f ns1/catalog.example.db.in ns1/catalog3.example.db
cp -f ns1/catalog.example.db.in ns1/catalog4.example.db
mkdir -p ns2/zonedir
echo "${port}" > ns1/named.port
echo "${port}" > ns2/named.port
echo "${port}" > ns3/named.port
This diff is collapsed.
......@@ -225,6 +225,29 @@ nextpart () {
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
#
......
#!/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
}
......@@ -12,7 +12,6 @@ set -e
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
. $SYSTEMTESTTOP/getopts.sh
QPERF=`$SHELL qperf.sh`
......
......@@ -13,7 +13,6 @@
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
. $SYSTEMTESTTOP/getopts.sh
ns=10.53.0
ns1=$ns.1 # root, defining the others
......@@ -67,7 +66,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
......
......@@ -12,7 +12,6 @@ rm -f dig.out.*
rm -f ns*/named.lock
rm -f ns*/named.memstats
rm -f ns*/*.run
rm -f ns*/named.port
rm -f ns*/*core *core
rm -f ns*/named.conf
......
......@@ -12,7 +12,6 @@ set -e
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
. $SYSTEMTESTTOP/getopts.sh
USAGE="$0: [-xD]"
DEBUG=
......@@ -36,18 +35,13 @@ OPTIND=1
$PERL testgen.pl
copy_setports ns1/named.conf.in ns1/named.conf
echo "${port}" > ns1/named.port
copy_setports ns2/named.conf.header.in ns2/named.conf.header
echo "${port}" > ns2/named.port
copy_setports ns2/named.default.conf ns2/named.conf
copy_setports ns3/named1.conf.in ns3/named.conf
echo "${port}" > ns3/named.port
copy_setports ns4/named.conf.in ns4/named.conf
echo "${port}" > ns4/named.port
copy_setports ans5/ans.pl.in ans5/ans.pl
......
......@@ -9,7 +9,6 @@
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
. $SYSTEMTESTTOP/getopts.sh
#set -x
......
......@@ -37,13 +37,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
......@@ -54,7 +90,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
......@@ -67,7 +103,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;
......@@ -89,14 +125,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
......@@ -122,7 +158,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
......
......@@ -6,8 +6,8 @@
rm -f test.output
rm -f dig.out.test*
rm -f ns1/named.conf ns1/named.port
rm -f ans2/ans.pl ans2/named.port
rm -f ns3/named.conf ns3/named.port
rm -f ns1/named.conf
rm -f ans2/ans.pl
rm -f ns3/named.conf
rm -f ns3/root.bk
rm -f rndc.out.test*
......@@ -5,13 +5,9 @@
# 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/.
. ../getopts.sh
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
copy_setports ns1/named1.conf.in ns1/named.conf
echo "${port}" > ns1/named.port
copy_setports ans2/ans.pl.in ans2/ans.pl
echo "${port}" > ans2/named.port
copy_setports ns3/named.conf.in ns3/named.conf
echo "${port}" > ns3/named.port
......@@ -8,31 +8,30 @@
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
. $SYSTEMTESTTOP/getopts.sh