Annotation of embedaddon/miniupnpc/testminiwget.sh, revision 1.1.1.3

1.1       misho       1: #!/bin/sh
1.1.1.3 ! misho       2: # $Id: testminiwget.sh,v 1.20 2022/10/21 21:09:42 nanard Exp $
        !             3: # vim: tabstop=4 shiftwidth=4 noexpandtab
1.1       misho       4: # project miniupnp : http://miniupnp.free.fr/
1.1.1.3 ! misho       5: #                    or https://miniupnp.tuxfamily.org/
        !             6: # (c) 2011-2022 Thomas Bernard
1.1       misho       7: #
                      8: # test program for miniwget.c
                      9: # is usually invoked by "make check"
                     10: #
                     11: # This test program :
                     12: #  1 - launches a local HTTP server (minihttptestserver)
1.1.1.3 ! misho      13: #  2 - uses testminiwget to retrieve data from this server
1.1       misho      14: #  3 - compares served and received data
                     15: #  4 - kills the local HTTP server and exits
                     16: #
1.1.1.2   misho      17: # The script was tested and works with ksh, bash
1.1.1.3 ! misho      18: # it should now also run with dash
1.1       misho      19: 
1.1.1.3 ! misho      20: TMPD=`mktemp -d -t miniwgetXXXXXXXXXX`
        !            21: if [ -z "$TESTSERVER" ] ; then
        !            22:   TESTSERVER=./build/minihttptestserver
        !            23: fi
        !            24: if [ -z "$TESTMINIWGET" ] ; then
        !            25:   TESTMINIWGET=./build/testminiwget
        !            26: fi
        !            27: HTTPSERVEROUT="${TMPD}/httpserverout"
        !            28: EXPECTEDFILE="${TMPD}/expectedfile"
        !            29: DOWNLOADEDFILE="${TMPD}/downloadedfile"
1.1       misho      30: PORT=
                     31: RET=0
1.1.1.3 ! misho      32: IPCONFIG=$(which ifconfig)
        !            33: IP=$(which ip)
        !            34: if [ "$IP" ] ; then
        !            35:    if ! $IP addr | grep inet6 ; then
        !            36:        HAVE_IPV6=no
        !            37:    fi
        !            38: else
        !            39:    if [ -z "$IPCONFIG" ] ; then
        !            40:        IPCONFIG="/sbin/ifconfig"
        !            41:    fi
        !            42: 
        !            43:    if ! $IPCONFIG -a | grep inet6 ; then
        !            44:        HAVE_IPV6=no
        !            45:    fi
        !            46: fi
1.1       misho      47: 
1.1.1.2   misho      48: case "$HAVE_IPV6" in
                     49:     n|no|0)
                     50:         ADDR=localhost
                     51:         SERVERARGS=""
                     52:         ;;
                     53:     *)
                     54:         ADDR="[::1]"
                     55:         SERVERARGS="-6"
                     56:         ;;
                     57: 
                     58: esac
                     59: 
1.1.1.3 ! misho      60: if [ ! -x "$TESTSERVER" ] || [ ! -x "$TESTMINIWGET" ] ; then
        !            61:    echo "Please build $TESTSERVER and $TESTMINIWGET"
        !            62:    #make minihttptestserver
        !            63:    #make testminiwget
        !            64:    exit 1
        !            65: fi
1.1       misho      66: 
                     67: # launching the test HTTP server
1.1.1.3 ! misho      68: $TESTSERVER $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
        !            69: SERVERPID=$!
1.1.1.2   misho      70: while [ -z "$PORT" ]; do
                     71:    sleep 1
1.1       misho      72:    PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `
                     73: done
1.1.1.3 ! misho      74: if [ "$PORT" = "*** ERROR ***" ]; then
        !            75:    echo "HTTP test server error"
        !            76:    echo "Network config :"
        !            77:    $IPCONFIG -a
        !            78:    exit 2
        !            79: fi
1.1       misho      80: echo "Test HTTP server is listening on $PORT"
                     81: 
                     82: URL1="http://$ADDR:$PORT/index.html"
                     83: URL2="http://$ADDR:$PORT/chunked"
                     84: URL3="http://$ADDR:$PORT/addcrap"
1.1.1.3 ! misho      85: URL4="http://$ADDR:$PORT/malformed"
1.1       misho      86: 
                     87: echo "standard test ..."
1.1.1.3 ! misho      88: $TESTMINIWGET $URL1 "${DOWNLOADEDFILE}.1"
1.1       misho      89: if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then
                     90:    echo "ok"
                     91: else
                     92:    echo "standard test FAILED"
                     93:    RET=1
                     94: fi
                     95: 
                     96: echo "chunked transfert encoding test ..."
1.1.1.3 ! misho      97: $TESTMINIWGET $URL2 "${DOWNLOADEDFILE}.2"
1.1       misho      98: if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then
                     99:    echo "ok"
                    100: else
                    101:    echo "chunked transfert encoding test FAILED"
                    102:    RET=1
                    103: fi
                    104: 
                    105: echo "response too long test ..."
1.1.1.3 ! misho     106: $TESTMINIWGET $URL3 "${DOWNLOADEDFILE}.3"
1.1       misho     107: if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then
                    108:    echo "ok"
                    109: else
                    110:    echo "response too long test FAILED"
                    111:    RET=1
                    112: fi
                    113: 
1.1.1.3 ! misho     114: echo "malformed response test ..."
        !           115: $TESTMINIWGET $URL4 "${DOWNLOADEDFILE}.4"
        !           116: 
1.1       misho     117: # kill the test HTTP server
1.1.1.3 ! misho     118: kill $SERVERPID
        !           119: wait $SERVERPID
1.1       misho     120: 
                    121: # remove temporary files (for success cases)
                    122: if [ $RET -eq 0 ]; then
                    123:    rm -f "${DOWNLOADEDFILE}.1"
                    124:    rm -f "${DOWNLOADEDFILE}.2"
                    125:    rm -f "${DOWNLOADEDFILE}.3"
                    126:    rm -f $EXPECTEDFILE $HTTPSERVEROUT
1.1.1.3 ! misho     127:    rmdir ${TMPD}
1.1       misho     128: else
                    129:    echo "at least one of the test FAILED"
1.1.1.3 ! misho     130:    echo "directory ${TMPD} is left intact"
1.1       misho     131: fi
                    132: exit $RET
                    133: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>