File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpc / testminiwget.sh
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Sep 27 11:21:37 2023 UTC (8 months, 2 weeks ago) by misho
Branches: miniupnpc, elwix, MAIN
CVS tags: v2_2_5p0, HEAD
Version 2.2.5p0

    1: #!/bin/sh
    2: # $Id: testminiwget.sh,v 1.1.1.3 2023/09/27 11:21:37 misho Exp $
    3: # vim: tabstop=4 shiftwidth=4 noexpandtab
    4: # project miniupnp : http://miniupnp.free.fr/
    5: #                    or https://miniupnp.tuxfamily.org/
    6: # (c) 2011-2022 Thomas Bernard
    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)
   13: #  2 - uses testminiwget to retrieve data from this server
   14: #  3 - compares served and received data
   15: #  4 - kills the local HTTP server and exits
   16: #
   17: # The script was tested and works with ksh, bash
   18: # it should now also run with dash
   19: 
   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"
   30: PORT=
   31: RET=0
   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
   47: 
   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: 
   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
   66: 
   67: # launching the test HTTP server
   68: $TESTSERVER $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
   69: SERVERPID=$!
   70: while [ -z "$PORT" ]; do
   71: 	sleep 1
   72: 	PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `
   73: done
   74: if [ "$PORT" = "*** ERROR ***" ]; then
   75: 	echo "HTTP test server error"
   76: 	echo "Network config :"
   77: 	$IPCONFIG -a
   78: 	exit 2
   79: fi
   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"
   85: URL4="http://$ADDR:$PORT/malformed"
   86: 
   87: echo "standard test ..."
   88: $TESTMINIWGET $URL1 "${DOWNLOADEDFILE}.1"
   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 ..."
   97: $TESTMINIWGET $URL2 "${DOWNLOADEDFILE}.2"
   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 ..."
  106: $TESTMINIWGET $URL3 "${DOWNLOADEDFILE}.3"
  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: 
  114: echo "malformed response test ..."
  115: $TESTMINIWGET $URL4 "${DOWNLOADEDFILE}.4"
  116: 
  117: # kill the test HTTP server
  118: kill $SERVERPID
  119: wait $SERVERPID
  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
  127: 	rmdir ${TMPD}
  128: else
  129: 	echo "at least one of the test FAILED"
  130: 	echo "directory ${TMPD} is left intact"
  131: fi
  132: exit $RET
  133: 

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