libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

zzuf_socat_test_runner.sh (3375B)


      1 #!/bin/sh
      2 
      3 if set -m ; then : ; else
      4   echo "The shell $SHELL does not support background jobs, the test cannot run." 1>&2
      5   exit 77
      6 fi
      7 
      8 socat_listen_ip='127.0.0.121'
      9 socat_listen_port='10121'
     10 mhd_listen_port='4010'
     11 max_runtime_sec='1800'
     12 
     13 if test "x${ZZUF}" = "xno" ; then
     14   echo "zzuf command missing" 1>&2
     15   exit 77
     16 fi
     17 
     18 if command -v "${ZZUF}" > /dev/null 2>&1 ; then : ; else
     19   echo "zzuf command missing" 1>&2
     20   exit 77
     21 fi
     22 
     23 if test "x${SOCAT}" = "xno" ; then
     24   echo "socat command missing" 1>&2
     25   exit 77
     26 fi
     27 
     28 if command -v "${SOCAT}" > /dev/null 2>&1 ; then : ; else
     29   echo "socat command missing" 1>&2
     30   exit 77
     31 fi
     32 
     33 socat_test_params="-ls -lu \
     34   -T0.1 -4 \
     35   TCP-LISTEN:${socat_listen_port},bind=${socat_listen_ip},reuseaddr,linger=2,linger2=1,accept-timeout=0.1 \
     36   TCP:127.0.0.1:${mhd_listen_port},reuseaddr"
     37  
     38 echo "## Trying to run socat to test ports availability..."
     39 if "${SOCAT}" ${socat_test_params} ; then
     40   echo "Success."
     41 else
     42   echo "socat test run failed" 1>&2
     43   exit 77
     44 fi
     45 
     46 # fuzz the input only for IP ${socat_listen_ip}. libcurl uses another IP
     47 # in this test therefore libcurl input is not fuzzed.
     48 zzuf_all_params="--ratio=0.001:0.4 --autoinc --verbose --signal \
     49  --max-usertime=${max_runtime_sec} --check-exit --network --allow=${socat_listen_ip} --exclude=."
     50 
     51 if test -n "${ZZUF_SEED}" ; then
     52   zzuf_all_params="${zzuf_all_params} --seed=${ZZUF_SEED}"
     53 fi
     54 
     55 if test -n "${ZZUF_FLAGS}" ; then
     56   zzuf_all_params="${zzuf_all_params} ${ZZUF_FLAGS}"
     57 fi
     58 
     59 # Uncomment the next line to see more zzuf data in logs
     60 #zzuf_all_params="${zzuf_all_params} -dd"
     61 
     62 socat_options="-ls -lu \
     63   -T3 -4"
     64 socat_addr1="TCP-LISTEN:${socat_listen_port},bind=${socat_listen_ip},reuseaddr,nodelay,linger=2,linger2=1,accept-timeout=${max_runtime_sec},fork"
     65 socat_addr2="TCP:127.0.0.1:${mhd_listen_port},reuseaddr,connect-timeout=3,nodelay,linger=2,linger2=1"
     66  
     67 if test -n "${SOCAT_FLAGS}" ; then
     68   socat_options="${socat_options} ${SOCAT_FLAGS}"
     69 fi
     70 
     71 # Uncomment the next line to see more socat data in logs
     72 #socat_options="${socat_options} -dd -D"
     73 
     74 # Uncomment the next line to see all traffic in logs
     75 #socat_options="${socat_options} -v"
     76  
     77 stop_zzuf_socat ()
     78 {
     79   trap - EXIT
     80   if test -n "$zzuf_pid" ; then
     81     echo "The test has been interrupted." 1>&2
     82     test "x$zzuf_pid" = "xstarting" && zzuf_pid=$!
     83     # Finish zzuf + socat
     84     kill -TERM ${zzuf_pid} -${zzuf_pid}
     85     # Finish the test
     86     kill -INT %2 2> /dev/null || kill -INT %1 2> /dev/null
     87     exit 99
     88   fi
     89 }
     90 
     91 echo "## Starting zzuf with socat to reflect fuzzed traffic..."
     92 trap 'stop_zzuf_socat' EXIT
     93 zzuf_pid="starting"
     94 "${ZZUF}" ${zzuf_all_params} "${SOCAT}" ${socat_options} ${socat_addr1} ${socat_addr2} &
     95 if test $? -eq 0 ; then
     96   zzuf_pid=$!
     97   echo "zzuf with socat has been started."
     98 else
     99   zzuf_pid=''
    100   echo "Failed to start zzuf with socat" 1>&2
    101   exit 99
    102 fi
    103 
    104 echo "## Starting real test of $@ with traffic fuzzed by zzuf with socat..."
    105 "$@" --with-socat
    106 test_result=$?
    107 trap - EXIT
    108 echo "$@ has exited with the return code $test_result" 
    109 if kill -s 0 -- $$ 2> /dev/null ; then
    110   if kill -s 0 -- ${zzuf_pid} -${zzuf_pid} ; then : ; else
    111     echo "No running zzuf with socat is detected after the test." 1>&2
    112     echo "Looks like zzuf ended prematurely, at least part of the testing has not been performed." 1>&2
    113     test_result=99
    114   fi
    115 fi
    116 kill -TERM ${zzuf_pid} -${zzuf_pid}
    117 zzuf_pid=''
    118 exit $test_result