Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions scripts/ocsp-stapling.test
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,56 @@ fi
fi

# need a unique port since may run the same time as testsuite
# Track ports already assigned in this script run to prevent intra-run collisions
used_ports=()

generate_port() {
#-------------------------------------------------------------------------#
# Generate a random port number
# Generate a random port number, guaranteed unique within this script run.
# Checks both the intra-run used_ports list and system-level bound ports.
#-------------------------------------------------------------------------#
local attempts=0 collision p

while true; do
if [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "msys"
|| "$OSTYPE" == "cygwin"* ]]; then
p=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
p=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi

if [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "msys"
|| "$OSTYPE" == "cygwin"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi
# Check against ports already assigned in this run
collision=0
for up in "${used_ports[@]}"; do
if [ "$up" = "$p" ]; then
collision=1
break
fi
done

# Also check if the port is already bound on this system
if [ $collision -eq 0 ]; then
if command -v ss &>/dev/null; then
ss -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
elif command -v netstat &>/dev/null; then
netstat -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
fi
fi

[ $collision -eq 0 ] && break

((attempts++))
if [ $attempts -ge 100 ]; then
echo "ERROR: generate_port could not find a free port after 100 attempts"
exit 1
fi
done

port=$p
used_ports+=("$p")
}

# Start OpenSSL server that has no OCSP responses to return
Expand Down
56 changes: 46 additions & 10 deletions scripts/ocsp-stapling2.test
Original file line number Diff line number Diff line change
Expand Up @@ -478,20 +478,56 @@ fi
printf '%s\n\n' "Test successfully REVOKED!"

# need a unique port since may run the same time as testsuite
# Track ports already assigned in this script run to prevent intra-run collisions
used_ports=()

generate_port() {
#-------------------------------------------------------------------------#
# Generate a random port number
# Generate a random port number, guaranteed unique within this script run.
# Checks both the intra-run used_ports list and system-level bound ports.
#-------------------------------------------------------------------------#
local attempts=0 collision p

while true; do
if [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "msys"
|| "$OSTYPE" == "cygwin" ]]; then
p=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
p=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi

if [[ "$OSTYPE" == "linux"* || "$OSTYPE" == "msys"
|| "$OSTYPE" == "cygwin" ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi
# Check against ports already assigned in this run
collision=0
for up in "${used_ports[@]}"; do
if [ "$up" = "$p" ]; then
collision=1
break
fi
done

# Also check if the port is already bound on this system
if [ $collision -eq 0 ]; then
if command -v ss &>/dev/null; then
ss -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
elif command -v netstat &>/dev/null; then
netstat -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
fi
fi

[ $collision -eq 0 ] && break

((attempts++))
if [ $attempts -ge 100 ]; then
echo "ERROR: generate_port could not find a free port after 100 attempts"
exit 1
fi
done

port=$p
used_ports+=("$p")
}

# Start OpenSSL server that has no OCSP responses to return
Expand Down
54 changes: 45 additions & 9 deletions scripts/ocsp-stapling_tls13multi.test
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,55 @@ if [ "$dtls13" == "yes" ]; then
fi

# need a unique port since may run the same time as testsuite
# Track ports already assigned in this script run to prevent intra-run collisions
used_ports=()

generate_port() {
#-------------------------------------------------------------------------#
# Generate a random port number
# Generate a random port number, guaranteed unique within this script run.
# Checks both the intra-run used_ports list and system-level bound ports.
#-------------------------------------------------------------------------#
local attempts=0 collision p

while true; do
if [[ "$OSTYPE" == "linux"* ]]; then
p=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
p=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi

if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi
# Check against ports already assigned in this run
collision=0
for up in "${used_ports[@]}"; do
if [ "$up" = "$p" ]; then
collision=1
break
fi
done

# Also check if the port is already bound on this system
if [ $collision -eq 0 ]; then
if command -v ss &>/dev/null; then
ss -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
elif command -v netstat &>/dev/null; then
netstat -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
fi
fi

[ $collision -eq 0 ] && break

((attempts++))
if [ $attempts -ge 100 ]; then
echo "ERROR: generate_port could not find a free port after 100 attempts"
exit 1
fi
done

port=$p
used_ports+=("$p")
}

printf '%s\n\n' "------------------- TESTS COMPLETE ---------------------------"
Expand Down
54 changes: 45 additions & 9 deletions scripts/openssl.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,55 @@ fi
echo "WOLFSSL_OPENSSL_TEST set, running test..."

# need a unique port since may run the same time as testsuite
# Track ports already assigned in this script run to prevent intra-run collisions
used_ports=()

generate_port() {
#-------------------------------------------------------------------------#
# Generate a random port number
# Generate a random port number, guaranteed unique within this script run.
# Checks both the intra-run used_ports list and system-level bound ports.
#-------------------------------------------------------------------------#
local attempts=0 collision p

if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi
while true; do
if [[ "$OSTYPE" == "linux"* ]]; then
p=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
p=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi

# Check against ports already assigned in this run
collision=0
for up in "${used_ports[@]}"; do
if [ "$up" = "$p" ]; then
collision=1
break
fi
done

# Also check if the port is already bound on this system
if [ $collision -eq 0 ]; then
if command -v ss &>/dev/null; then
ss -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
elif command -v netstat &>/dev/null; then
netstat -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
fi
fi

[ $collision -eq 0 ] && break

((attempts++))
if [ $attempts -ge 100 ]; then
echo "ERROR: generate_port could not find a free port after 100 attempts"
exit 1
fi
done

port=$p
used_ports+=("$p")
}

no_pid=-1
Expand Down
54 changes: 45 additions & 9 deletions scripts/openssl_srtp.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,55 @@ OPENSSL=${OPENSSL:="openssl"}
WOLFSSL_CLIENT=${WOLFSSL_CLIENT:="./examples/client/client"}

# need a unique port since may run the same time as testsuite
# Track ports already assigned in this script run to prevent intra-run collisions
used_ports=()

generate_port() {
#-------------------------------------------------------------------------#
# Generate a random port number
# Generate a random port number, guaranteed unique within this script run.
# Checks both the intra-run used_ports list and system-level bound ports.
#-------------------------------------------------------------------------#
local attempts=0 collision p

while true; do
if [[ "$OSTYPE" == "linux"* ]]; then
p=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
p=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi

# Check against ports already assigned in this run
collision=0
for up in "${used_ports[@]}"; do
if [ "$up" = "$p" ]; then
collision=1
break
fi
done

# Also check if the port is already bound on this system
if [ $collision -eq 0 ]; then
if command -v ss &>/dev/null; then
ss -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
elif command -v netstat &>/dev/null; then
netstat -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
fi
fi

[ $collision -eq 0 ] && break

((attempts++))
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this script set -e is enabled, and ((attempts++)) will return a non-zero status the first time it runs (because the arithmetic expression evaluates to 0 before increment). That can cause the whole test script to exit early on the first detected collision instead of retrying. Use an increment form that won’t trip set -e (e.g., attempts=$((attempts + 1))), or explicitly ignore the status (e.g., ((attempts++)) || true).

Suggested change
((attempts++))
attempts=$((attempts + 1))

Copilot uses AI. Check for mistakes.
if [ $attempts -ge 100 ]; then
echo "ERROR: generate_port could not find a free port after 100 attempts"
exit 1
fi
done

if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "Unknown OS TYPE"
exit 1
fi
port=$p
used_ports+=("$p")
}

# get size of key material based on the profile
Expand Down
54 changes: 45 additions & 9 deletions scripts/rsapss.test
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,55 @@ elif [ "${AM_BWRAPPED-}" != "yes" ]; then
fi

# need a unique port since may run the same time as testsuite
# Track ports already assigned in this script run to prevent intra-run collisions
used_ports=()

generate_port() {
#-------------------------------------------------------------------------#
# Generate a random port number
# Generate a random port number, guaranteed unique within this script run.
# Checks both the intra-run used_ports list and system-level bound ports.
#-------------------------------------------------------------------------#
local attempts=0 collision p

if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "skipping due to unsupported OS"
exit 0
fi
while true; do
if [[ "$OSTYPE" == "linux"* ]]; then
p=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
p=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "skipping due to unsupported OS"
exit 0
fi

# Check against ports already assigned in this run
collision=0
for up in "${used_ports[@]}"; do
if [ "$up" = "$p" ]; then
collision=1
break
fi
done

# Also check if the port is already bound on this system
if [ $collision -eq 0 ]; then
if command -v ss &>/dev/null; then
ss -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
elif command -v netstat &>/dev/null; then
netstat -lnt 2>/dev/null | grep -q ":${p}[[:space:]]" && collision=1
fi
fi

[ $collision -eq 0 ] && break

((attempts++))
if [ $attempts -ge 100 ]; then
echo "ERROR: generate_port could not find a free port after 100 attempts"
exit 1
fi
done

port=$p
used_ports+=("$p")
}

WOLFSSL_SERVER=./examples/server/server
Expand Down