From bc7c8af5de8ea163e500739e5b1a6078ab455988 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 18 Aug 2023 09:41:13 -0400 Subject: [PATCH] Massively simplified the tests --- scripts/dtls13.test | 123 +++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 81 deletions(-) diff --git a/scripts/dtls13.test b/scripts/dtls13.test index 1eb112686..cf67bb0c6 100755 --- a/scripts/dtls13.test +++ b/scripts/dtls13.test @@ -17,67 +17,53 @@ cleanup () { trap cleanup err exit -WOLFSSL_ROOT=$(pwd) -if [ -z $UDP_PROXY_PATH ];then -UDP_PROXY_PATH=$WOLFSSL_ROOT/../udp-proxy/udp_proxy -fi -PROXY_PORT=12345 -SERVER_PORT=11111 -NEW_SESSION_TICKET_SIZE=200 +WOLFSSL_ROOT=${WOLFSSL_ROOT:-$(pwd)} +UDP_PROXY_BIN=${UDP_PROXY_BIN:-"udp_proxy"} +PROXY_PORT=1234 +SERVER_PORT=4321 KEY_UPDATE_SIZE=35 # $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 "" "" "" + 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 () { 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 - $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -f $i -u >>/tmp/udp & - 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= + echo -e "\ndropping packet $i\n" + run_test "-f $i" "-v4 -Ta" "-v4" 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 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 - $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -f $i -u >>/tmp/udp & - 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= + echo -e "\nTesting WANT_WRITE: dropping packet $i\n" + run_test "-f $i" "-v4 -Ta -6" "-v4 -6" done } # this test is based on detecting newSessionTicket message by its size. This is rather fragile. -test_dropping_new_session_ticket() { - 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 - $UDP_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -F $NEW_SESSION_TICKET_SIZE -u >>/tmp/udp & - 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_dropping_new_session_ticket() { # usage: test_dropping_new_session_ticket + echo -e "\ndropping new session ticket packet of size $1\n" + run_test "-F $1" "-v4 -w" "-v4 -w --waitTicket" } test_permutations () { @@ -88,25 +74,12 @@ for p in itertools.permutations("$2"): print(''.join(p)) EOF ) - echo "Testing $SIDE msg permutations" 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_PROXY_PATH -p $PROXY_PORT -s 127.0.0.1:$SERVER_PORT -u -r $i -l $UDP_LOGFILE -S $SIDE & - UDP_PROXY_PID=$! - $WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -w &> /tmp/serr & - 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 + rm -f $UDP_LOGFILE + run_test "-r $i -S $SIDE -l $UDP_LOGFILE" "-v4 -Ta -w" "-v4 -w" + echo "...produced $(grep -P 'client:|server:' $UDP_LOGFILE | wc -l) messages" done echo "All $SIDE msg permutations succeeded" } @@ -124,29 +97,17 @@ for i in tt: EOF ) for DELAY in $DELAYS;do - echo -n "Testing delay $DELAY" + echo -n "\nTesting delay $DELAY...\n" 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 & - UDP_PROXY_PID=$! - $WOLFSSL_ROOT/examples/server/server -v4 -u -Ta -w &> /tmp/serr & - 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" + rm -f $UDP_LOGFILE + run_test "-l $UDP_LOGFILE -t $DELAY" "-v4 -Ta -w" "-v4 -w" + echo "...produced $(grep -P 'client:|server:' $UDP_LOGFILE | wc -l) messages" done } test_dropping_packets test_permutations client 012 -test_dropping_new_session_ticket +test_dropping_new_session_ticket 200 if [ ! -z $DTLS13_DO_SERVER_PERMUTATION_TEST ];then test_permutations server 0123456