zzuf_test_runner.sh (2480B)
1 #!/bin/sh 2 3 mhd_listen_ip='127.0.0.1' 4 max_runtime_sec='1800' 5 6 if test "x${ZZUF}" = "xno" ; then 7 echo "zzuf command missing" 1>&2 8 exit 77 9 fi 10 11 if command -v "${ZZUF}" > /dev/null 2>&1 ; then : ; else 12 echo "zzuf command missing" 1>&2 13 exit 77 14 fi 15 16 run_with_socat () 17 { 18 echo "Trying to run the test with socat..." 19 script_dir="" 20 if command -v dirname > /dev/null 2>&1 ; then 21 test_dir=`dirname /` 22 if test "x${test_dir}" = "x/" ; then 23 if dirname "$1" > /dev/null 2>&1 ; then 24 script_dir=`dirname "$1"` 25 if test -n "${script_dir}" ; then 26 # Assume script is not in the root dir 27 script_dir="${script_dir}/" 28 else 29 script_dir="./" 30 fi 31 fi 32 fi 33 fi 34 if test -z "${script_dir}" ; then 35 if echo "$1" | sed 's|[^/]*$||' > /dev/null 2>&1 ; then 36 script_dir=`echo "$1" | sed 's|[^/]*$||'` 37 if test -z "${script_dir}" ; then 38 script_dir="./" 39 fi 40 fi 41 fi 42 if test -z "${script_dir}" ; then 43 echo "Cannot determine script location, will try current directory." 1>&2 44 script_dir="./" 45 fi 46 $SHELL "${script_dir}zzuf_socat_test_runner.sh" "$@" 47 exit $? 48 } 49 50 # zzuf cannot pass-through the return value of checked program 51 # so try the direct dry-run first to get possible 77 or 99 codes 52 echo "## Dry-run of the $@..." 53 if "$@" --dry-run ; then 54 echo "# Dry-run succeeded." 55 else 56 res_code=$? 57 echo "Dry-run failed with exit code $res_code." 1>&2 58 if test $res_code -ne 99; then 59 run_with_socat "$@" 60 fi 61 echo "$@ will not be run with zzuf." 1>&2 62 exit $res_code 63 fi 64 65 # fuzz the input only for IP ${mhd_listen_ip}. libcurl uses another IP 66 # in this test therefore libcurl input is not fuzzed. 67 zzuf_all_params="--ratio=0.001:0.4 --autoinc --verbose --signal \ 68 --max-usertime=${max_runtime_sec} --check-exit --network \ 69 --allow=${mhd_listen_ip} --exclude=." 70 71 if test -n "${ZZUF_SEED}" ; then 72 zzuf_all_params="${zzuf_all_params} --seed=${ZZUF_SEED}" 73 fi 74 75 if test -n "${ZZUF_FLAGS}" ; then 76 zzuf_all_params="${zzuf_all_params} ${ZZUF_FLAGS}" 77 fi 78 79 # Uncomment the next line to see more data in logs 80 #zzuf_all_params="${zzuf_all_params} -dd" 81 82 echo "## Dry-run of the $@ with zzuf..." 83 if "$ZZUF" ${zzuf_all_params} "$@" --dry-run ; then 84 echo "# Dry-run with zzuf succeeded." 85 else 86 res_code=$? 87 echo "$@ cannot be run with zzuf directly." 1>&2 88 run_with_socat "$@" 89 exit $res_code 90 fi 91 92 echo "## Real test of $@ with zzuf..." 93 "$ZZUF" ${zzuf_all_params} "$@" 94 exit $?