Massively simplified the tests

This commit is contained in:
Andras Fekete
2023-08-18 09:41:13 -04:00
parent 7023f86e66
commit bc7c8af5de

View File

@@ -17,67 +17,53 @@ cleanup () {
trap cleanup err exit trap cleanup err exit
WOLFSSL_ROOT=$(pwd) WOLFSSL_ROOT=${WOLFSSL_ROOT:-$(pwd)}
if [ -z $UDP_PROXY_PATH ];then UDP_PROXY_BIN=${UDP_PROXY_BIN:-"udp_proxy"}
UDP_PROXY_PATH=$WOLFSSL_ROOT/../udp-proxy/udp_proxy PROXY_PORT=1234
fi SERVER_PORT=4321
PROXY_PORT=12345
SERVER_PORT=11111
NEW_SESSION_TICKET_SIZE=200
KEY_UPDATE_SIZE=35 KEY_UPDATE_SIZE=35
# $WOLFSSL_ROOT/tests/unit.test tests/test-dtls13.conf # $WOLFSSL_ROOT/tests/unit.test tests/test-dtls13.conf
set -o pipefail
prepend() { # Usage: cmd 2>&1 | prepend "sometext "
while read line; do echo "${1}${line}"; done
}
run_test() { # usage: run_test "<udp-proxy args>" "<server args>" "<client args>"
stdbuf -oL -eL $UDP_PROXY_BIN -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -u $1 2>&1 | prepend "[udp-proxy] " &
UDP_PROXY_PID=$(($! - 1))
echo "UDP-proxy: $UDP_PROXY_PID"
stdbuf -oL -eL $WOLFSSL_ROOT/examples/server/server -u -p$SERVER_PORT $2 2>&1 | prepend "[server] " &
SERVER_PID=$!
sleep 0.2
timeout -s KILL 5m stdbuf -oL -eL $WOLFSSL_ROOT/examples/client/client -u -p$PROXY_PORT $3 2>&1 | prepend "[client] "
wait $SERVER_PID
SERVER_PID=
kill -INT $UDP_PROXY_PID
sleep 0.2 && kill $UDP_PROXY_PID || true
UDP_PROXY_PID=
echo "Test complete"
}
test_dropping_packets () { test_dropping_packets () {
for i in $(seq 0 11);do for i in $(seq 0 11);do
echo -e "\ndropping packet $i\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp echo -e "\ndropping packet $i\n"
$UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -f $i -u >>/tmp/udp & run_test "-f $i" "-v4 -Ta" "-v4"
UDP_PROXY_PID=$!
$WOLFSSL_ROOT/examples/server/server -v4 -u -Ta 2>>/tmp/serr &
SERVER_PID=$!
sleep 0.2
$WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT 2>>/tmp/cerr
wait $SERVER_PID
SERVER_PID=
kill $UDP_PROXY_PID
UDP_PROXY_PID=
done done
echo -e "\nTesting WANT_WRITE\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp
# dropping last ack would be client error as wolfssl_read doesn't support WANT_WRITE as returned error # dropping last ack would be client error as wolfssl_read doesn't support WANT_WRITE as returned error
for i in $(seq 0 10);do for i in $(seq 0 10);do
echo -e "\ndropping packet $i\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp echo -e "\nTesting WANT_WRITE: dropping packet $i\n"
$UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -f $i -u >>/tmp/udp & run_test "-f $i" "-v4 -Ta -6" "-v4 -6"
UDP_PROXY_PID=$!
$WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -6 2>>/tmp/serr &
SERVER_PID=$!
sleep 0.2
$WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -6 2>>/tmp/cerr
wait $SERVER_PID
SERVER_PID=
kill $UDP_PROXY_PID
UDP_PROXY_PID=
done done
} }
# this test is based on detecting newSessionTicket message by its size. This is rather fragile. # this test is based on detecting newSessionTicket message by its size. This is rather fragile.
test_dropping_new_session_ticket() { test_dropping_new_session_ticket() { # usage: test_dropping_new_session_ticket <size>
echo -e "\ndropping new session ticket packet of size $NEW_SESSION_TICKET_SIZE\n" | tee -a /tmp/serr | tee -a /tmp/cerr | tee -a /tmp/udp echo -e "\ndropping new session ticket packet of size $1\n"
$UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -F $NEW_SESSION_TICKET_SIZE -u >>/tmp/udp & run_test "-F $1" "-v4 -w" "-v4 -w --waitTicket"
UDP_PROXY_PID=$!
$WOLFSSL_ROOT/examples/server/server -v4 -w -u 2>>/tmp/serr &
SERVER_PID=$!
sleep 0.2
now=$(date +%s.%N)
$WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -w --waitTicket 2>>/tmp/cerr
elapsed=$(echo $(date +%s.%N) - $now | bc)
echo "it took ${elapsed} sec(s)" >> /tmp/udp
wait $SERVER_PID
SERVER_PID=
kill $UDP_PROXY_PID
UDP_PROXY_PID=
} }
test_permutations () { test_permutations () {
@@ -88,25 +74,12 @@ for p in itertools.permutations("$2"):
print(''.join(p)) print(''.join(p))
EOF EOF
) )
echo "Testing $SIDE msg permutations"
for i in $PERMUTATIONS;do for i in $PERMUTATIONS;do
echo -n "Testing $SIDE order $i" echo -n "\nTesting $SIDE permutations order $i...\n"
UDP_LOGFILE=/tmp/udp-$SIDE-$i UDP_LOGFILE=/tmp/udp-$SIDE-$i
$UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -u -r $i -l $UDP_LOGFILE -S $SIDE & rm -f $UDP_LOGFILE
UDP_PROXY_PID=$! run_test "-r $i -S $SIDE -l $UDP_LOGFILE" "-v4 -Ta -w" "-v4 -w"
$WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -w &> /tmp/serr & echo "...produced $(grep -P 'client:|server:' $UDP_LOGFILE | wc -l) messages"
SERVER_PID=$!
sleep 0.2
now=$(date +%s.%N)
$WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -w &> /tmp/cerr
elapsed=$(echo $(date +%s.%N) - $now | bc)
udp_lines=$(grep -P 'client:|server:' $UDP_LOGFILE | wc -l)
echo " took ${elapsed} sec(s) and produced ${udp_lines} messages"
wait $SERVER_PID
SERVER_PID=
kill $UDP_PROXY_PID
UDP_PROXY_PID=
rm $UDP_LOGFILE
done done
echo "All $SIDE msg permutations succeeded" echo "All $SIDE msg permutations succeeded"
} }
@@ -124,29 +97,17 @@ for i in tt:
EOF EOF
) )
for DELAY in $DELAYS;do for DELAY in $DELAYS;do
echo -n "Testing delay $DELAY" echo -n "\nTesting delay $DELAY...\n"
UDP_LOGFILE=/tmp/udp-delay-$DELAY UDP_LOGFILE=/tmp/udp-delay-$DELAY
$UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -u -l "$UDP_LOGFILE" -t $DELAY & rm -f $UDP_LOGFILE
UDP_PROXY_PID=$! run_test "-l $UDP_LOGFILE -t $DELAY" "-v4 -Ta -w" "-v4 -w"
$WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -w &> /tmp/serr & echo "...produced $(grep -P 'client:|server:' $UDP_LOGFILE | wc -l) messages"
SERVER_PID=$!
sleep 0.2
now=$(date +%s.%N)
$WOLFSSL_ROOT/examples/client/client -v4 -u -p$PROXY_PORT -w &> /tmp/cerr
elapsed=$(echo $(date +%s.%N) - $now | bc)
udp_lines=$(grep -P 'client:|server:' "$UDP_LOGFILE" | wc -l)
echo " took ${elapsed} sec(s) and produced ${udp_lines} messages"
wait $SERVER_PID
SERVER_PID=
kill $UDP_PROXY_PID
UDP_PROXY_PID=
rm "$UDP_LOGFILE"
done done
} }
test_dropping_packets test_dropping_packets
test_permutations client 012 test_permutations client 012
test_dropping_new_session_ticket test_dropping_new_session_ticket 200
if [ ! -z $DTLS13_DO_SERVER_PERMUTATION_TEST ];then if [ ! -z $DTLS13_DO_SERVER_PERMUTATION_TEST ];then
test_permutations server 0123456 test_permutations server 0123456