diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:59:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:59:48 +0000 |
commit | 3b9b6d0b8e7f798023c9d109c490449d528fde80 (patch) | |
tree | 2e1c188dd7b8d7475cd163de9ae02c428343669b /bin/tests/system/get_ports.sh | |
parent | Initial commit. (diff) | |
download | bind9-0cd617f6bad00b68e380aeb0024ef4dc1985191c.tar.xz bind9-0cd617f6bad00b68e380aeb0024ef4dc1985191c.zip |
Adding upstream version 1:9.18.19.upstream/1%9.18.19upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | bin/tests/system/get_ports.sh | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/bin/tests/system/get_ports.sh b/bin/tests/system/get_ports.sh new file mode 100755 index 0000000..b44e3ef --- /dev/null +++ b/bin/tests/system/get_ports.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# 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 https://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. + +get_sorted_test_names() { + find . -maxdepth 2 -mindepth 2 -type f \( -name "tests.sh" -o -name "tests*.py" \) | cut -d/ -f2 | sort -u +} + +total_tests=$(get_sorted_test_names | wc -l) +ports_per_test=20 + +port_min=5001 +port_max=$((32767 - (total_tests * ports_per_test))) + +baseport=0 +test_index=0 +while getopts "p:t:-:" 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 ;; + t | test) + test_index=$(get_sorted_test_names | awk "/^${OPTARG}\$/ { print NR }") + if [ -z "${test_index}" ]; then + echo "Test '${OPTARG}' not found" >&2 + exit 1 + fi + ;; + -) break ;; + *) echo "invalid option" >&2; exit 1 ;; + esac +done + +port_pool_size=$((port_max - port_min)) +if [ "${baseport}" -eq 0 ]; then + baseport="$((($(date +%s) / 3600 % port_pool_size) + port_min + (test_index * ports_per_test)))" +fi + +echo "export PORT=$((baseport))" +echo "export TLSPORT=$((baseport + 1))" +echo "export HTTPPORT=$((baseport + 2))" +echo "export HTTPSPORT=$((baseport + 3))" +echo "export EXTRAPORT1=$((baseport + 4))" +echo "export EXTRAPORT2=$((baseport + 5))" +echo "export EXTRAPORT3=$((baseport + 6))" +echo "export EXTRAPORT4=$((baseport + 7))" +echo "export EXTRAPORT5=$((baseport + 8))" +echo "export EXTRAPORT6=$((baseport + 9))" +echo "export EXTRAPORT7=$((baseport + 10))" +echo "export EXTRAPORT8=$((baseport + 11))" +echo "export CONTROLPORT=$((baseport + 12))" + +# Local Variables: +# sh-basic-offset: 4 +# End: |