parallel.mk
/*.log
/*.trs
-/get_base_port.state
-/get_base_port.lock
+/get_ports.state
+/get_ports.lock
/run.sh
/run.log
/start.sh
AM_LOG_DRIVER_FLAGS = $(LOG_DRIVER_V)
LOG_COMPILER = $(builddir)/run.sh
-AM_LOG_FLAGS = -r -p "$$("$(srcdir)/get_base_port.sh")"
+AM_LOG_FLAGS = -r
$(TESTS): run.sh
clean-local:
- -rm -f get_base_port.state get_base_port.lock
+ -rm -f get_ports.state get_ports.lock
+++ /dev/null
-#!/bin/sh
-#
-# Copyright (C) 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/.
-#
-# See the COPYRIGHT file distributed with this work for additional
-# information regarding copyright ownership.
-
-# This script is a 'port' broker. It keeps track of ports given to the
-# individual system subtests, so every test is given a unique port range.
-
-lockfile=get_base_port.lock
-statefile=get_base_port.state
-
-ephemeral_port_min=49152
-ephemeral_port_max=65535
-
-get_base_port() {
- if ( set -o noclobber; echo "$$" > "${lockfile}" ) 2> /dev/null; then
- trap 'rm -f "${lockfile}"; exit $?' INT TERM EXIT
-
- base_port=$(cat "${statefile}" 2>/dev/null)
-
- if [ -z "${base_port}" ]; then
- base_port="${ephemeral_port_min}"
- fi
-
- if [ "$((base_port+100))" -gt "${ephemeral_port_max}" ]; then
- base_port="${ephemeral_port_min}"
- fi
-
- echo $((base_port+100)) > get_base_port.state
-
- # clean up after yourself, and release your trap
- rm -f "${lockfile}"
- trap - INT TERM EXIT
- echo "${base_port}"
- else
- echo 0
- fi
-}
-
-tries=10
-
-while [ "${tries}" -gt 0 ]; do
- base_port=$(get_base_port)
- if [ "${base_port}" -gt 0 ]; then
- echo "${base_port}"
- exit 0
- fi
- sleep 1
- tries=$((tries-1))
-done
-
-exit 1
--- /dev/null
+#!/bin/sh
+#
+# Copyright (C) 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/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+# This script is a 'port' broker. It keeps track of ports given to the
+# individual system subtests, so every test is given a unique port range.
+
+lockfile=get_ports.lock
+statefile=get_ports.state
+
+port_min=5001
+port_max=32767
+
+get_random() {
+ dd if=/dev/urandom bs=1 count=2 2>/dev/null | od -tu2 -An
+}
+
+get_port() {
+ tries=10
+ port=0
+ while [ "${tries}" -gt 0 ]; do
+ if ( set -o noclobber; echo "$$" > "${lockfile}" ) 2> /dev/null; then
+ trap 'rm -f "${lockfile}"; exit $?' INT TERM EXIT
+
+ port=$(cat "${statefile}" 2>/dev/null)
+
+ if [ -z "${port}" ]; then
+ if [ "$1" -gt 0 ]; then
+ port="$1"
+ else
+ port_range=$((port_max-port_min))
+ port=$(($(get_random)%port_range+port_range))
+ fi
+ fi
+
+ if [ "$((port+1))" -gt "${port_max}" ]; then
+ port="${port_min}"
+ fi
+
+ echo $((port+1)) > get_ports.state
+
+ # clean up after yourself, and release your trap
+ rm -f "${lockfile}"
+ trap - INT TERM EXIT
+
+ # we have our port
+ break
+ fi
+ sleep 1
+ tries=$((tries-1))
+ done
+ if [ "$port" -eq 0 ]; then
+ exit 1
+ fi
+ echo "$port"
+}
+
+baseport=0
+while getopts "p:-:" OPT; do
+ if [ "$OPT" = "-" ] && [ -n "$OPTARG" ]; then
+ OPT="${OPTARG%%=*}"
+ OPTARG="${OPTARG#$OPT}"
+ OPTARG="${OPTARG#=}"
+ fi
+
+ # shellcheck disable=SC2214
+ case "$OPT" in
+ p | port) baseport=$OPTARG ;;
+ -) break ;;
+ *) echo "invalid option" >&2; exit 1 ;;
+ esac
+done
+
+echo "export PORT=$(get_port "$baseport")"
+echo "export EXTRAPORT1=$(get_port)"
+echo "export EXTRAPORT2=$(get_port)"
+echo "export EXTRAPORT3=$(get_port)"
+echo "export EXTRAPORT4=$(get_port)"
+echo "export EXTRAPORT5=$(get_port)"
+echo "export EXTRAPORT6=$(get_port)"
+echo "export EXTRAPORT7=$(get_port)"
+echo "export EXTRAPORT8=$(get_port)"
+echo "export CONTROLPORT=$(get_port)"
+
+# Local Variables:
+# sh-basic-offset: 4
+# End:
builddir=@abs_builddir@
srcdir=@abs_srcdir@
+# shellcheck source=conf.sh
. ${builddir}/conf.sh
SYSTEMTESTTOP="$(cd -P -- "${builddir}" && pwd -P)"
)
stopservers=true
-baseport=5300
+# baseport == 0 means random
+baseport=0
if [ "${SYSTEMTEST_NO_CLEAN:-0}" -eq 1 ]; then
clean=false
do_run=false
log_flags="-r"
-while getopts "knp:r-:" OPT; do
+while getopts "sknp:r-:" OPT; do
log_flags="$log_flags -$OPT$OPTARG"
if [ "$OPT" = "-" ] && [ -n "$OPTARG" ]; then
OPT="${OPTARG%%=*}"
OPTARG="${OPTARG#=}"
fi
+ # shellcheck disable=SC2214
case "$OPT" in
k | keep) stopservers=false ;;
n | noclean) clean=false ;;
shift $((OPTIND-1))
if ! $do_run; then
- env - TESTS="$1" TEST_SUITE_LOG=run.log LOG_DRIVER_FLAGS="--verbose yes --color-tests yes" LOG_FLAGS="$log_flags" make -e check
- exit $?
+ if [ "$baseport" -eq 0 ]; then
+ log_flags="$log_flags -p 5300"
+ fi
+ env - TESTS="$*" TEST_SUITE_LOG=run.log LOG_DRIVER_FLAGS="--verbose yes --color-tests yes" LOG_FLAGS="$log_flags" make -e check
+ exit $?
fi
if [ $# -eq 0 ]; then
exit 1
fi
-# Define the number of ports allocated for each test, and the lowest and
-# highest valid values for the "-p" option.
-#
-# The lowest valid value is one more than the highest privileged port number
-# (1024).
-#
-# The highest valid value is calculated by noting that the value passed on the
-# command line is the lowest port number in a block of "numports" consecutive
-# ports and that the highest valid port number is 65,535.
-numport=100
-minvalid=$((1024 + 1))
-maxvalid=$((65535 - numport + 1))
-
-if ! [ "$baseport" -eq "$baseport" ] > /dev/null 2>&1; then
- echofail "$0: $systest: must specify a numeric value for the port" >&2
- exit 1
-elif [ "$baseport" -lt "$minvalid" ] || [ "$baseport" -gt "$maxvalid" ]; then
- echofail "$0: $systest: the specified port must be in the range $minvalid to $maxvalid" >&2
- exit 1
-fi
-# Name the first 10 ports in the set (it is assumed that each test has access
+# Get the first 10 ports in the set (it is assumed that each test has access
# to ten or more ports): 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 if this is
# true, the last digit of EXTRAPORTn is "n".
-PORT=$baseport
-EXTRAPORT1=$((baseport + 1))
-EXTRAPORT2=$((baseport + 2))
-EXTRAPORT3=$((baseport + 3))
-EXTRAPORT4=$((baseport + 4))
-EXTRAPORT5=$((baseport + 5))
-EXTRAPORT6=$((baseport + 6))
-EXTRAPORT7=$((baseport + 7))
-EXTRAPORT8=$((baseport + 8))
-CONTROLPORT=$((baseport + 9))
-
-LOWPORT=$baseport
-HIGHPORT=$((baseport + numport - 1))
-
-export PORT
-export EXTRAPORT1
-export EXTRAPORT2
-export EXTRAPORT3
-export EXTRAPORT4
-export EXTRAPORT5
-export EXTRAPORT6
-export EXTRAPORT7
-export EXTRAPORT8
-export CONTROLPORT
-
-export LOWPORT
-export HIGHPORT
+eval "$(${srcdir}/get_ports.sh -p "$baseport")"
echostart "S:$systest:$(date_with_args)"
echoinfo "T:$systest:1:A"
echoinfo "A:$systest:System test $systest"
-echoinfo "I:$systest:PORTRANGE:${LOWPORT} - ${HIGHPORT}"
+echoinfo "I:$systest:PORTS:${PORT},${EXTRAPORT1},${EXTRAPORT2},${EXTRAPORT3},${EXTRAPORT4},${EXTRAPORT5},${EXTRAPORT6},${EXTRAPORT7},${EXTRAPORT8},${CONTROLPORT}"
$PERL ${srcdir}/testsock.pl -p "$PORT" || {
echowarn "I:$systest:Network interface aliases not set up. Skipping test."
echofail "R:$systest:FAIL"
# Do not clean up - we need the evidence.
find "$systest/" -name 'core*' -or -name '*.core' | while read -r coredump; do
- SYSTESTDIR="$systest"
+ export SYSTESTDIR="$systest"
echoinfo "D:$systest:backtrace from $coredump start"
binary=$(gdb --batch --core="$coredump" | sed -ne "s/Core was generated by \`//;s/ .*'.$//p;")
"${top_builddir}/libtool" --mode=execute gdb \
./bin/tests/system/geoip2/prereq.sh SH 2019,2020
./bin/tests/system/geoip2/setup.sh SH 2019,2020
./bin/tests/system/geoip2/tests.sh SH 2019,2020
-./bin/tests/system/get_base_port.sh SH 2020
+./bin/tests/system/get_ports.sh SH 2020
./bin/tests/system/glue/clean.sh SH 2000,2001,2004,2007,2012,2014,2015,2016,2018,2019,2020
./bin/tests/system/glue/fi.good X 2000,2001,2018,2019,2020
./bin/tests/system/glue/noglue.good X 2000,2001,2018,2019,2020