aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf/zzuf_socat_test_runner.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf/zzuf_socat_test_runner.sh')
-rwxr-xr-xsrc/testzzuf/zzuf_socat_test_runner.sh118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/testzzuf/zzuf_socat_test_runner.sh b/src/testzzuf/zzuf_socat_test_runner.sh
new file mode 100755
index 00000000..6bc4ef37
--- /dev/null
+++ b/src/testzzuf/zzuf_socat_test_runner.sh
@@ -0,0 +1,118 @@
1#!/bin/sh
2
3if set -m ; then : ; else
4 echo "The shell $SHELL does not support background jobs, the test cannot run." 1>&2
5 exit 77
6fi
7
8socat_listen_ip='127.0.0.121'
9socat_listen_port='10121'
10mhd_listen_port='4010'
11max_runtime_sec='300'
12
13if test "x${ZZUF}" = "xno" ; then
14 echo "zzuf command missing" 1>&2
15 exit 77
16fi
17
18if command -v "${ZZUF}" > /dev/null 2>&1 ; then : ; else
19 echo "zzuf command missing" 1>&2
20 exit 77
21fi
22
23if test "x${SOCAT}" = "xno" ; then
24 echo "socat command missing" 1>&2
25 exit 77
26fi
27
28if command -v "${SOCAT}" > /dev/null 2>&1 ; then : ; else
29 echo "socat command missing" 1>&2
30 exit 77
31fi
32
33socat_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
38echo "## Trying to run socat to test ports availability..."
39if "${SOCAT}" ${socat_test_params} ; then
40 echo "Success."
41else
42 echo "socat test run failed" 1>&2
43 exit 77
44fi
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.
48zzuf_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
51if test -n "${ZZUF_SEED}" ; then
52 zzuf_all_params="${zzuf_all_params} --seed=${ZZUF_SEED}"
53fi
54
55if test -n "${ZZUF_FLAGS}" ; then
56 zzuf_all_params="${zzuf_all_params} ${ZZUF_FLAGS}"
57fi
58
59# Uncomment the next line to see more zzuf data in logs
60#zzuf_all_params="${zzuf_all_params} -dd"
61
62socat_options="-ls -lu \
63 -T3 -4"
64socat_addr1="TCP-LISTEN:${socat_listen_port},bind=${socat_listen_ip},reuseaddr,nodelay,linger=2,linger2=1,accept-timeout=${max_runtime_sec},fork"
65socat_addr2="TCP:127.0.0.1:${mhd_listen_port},reuseaddr,connect-timeout=3,nodelay,linger=2,linger2=1"
66
67if test -n "${SOCAT_FLAGS}" ; then
68 socat_options="${socat_options} ${SOCAT_FLAGS}"
69fi
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
77stop_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
91echo "## Starting zzuf with socat to reflect fuzzed traffic..."
92trap 'stop_zzuf_socat' EXIT
93zzuf_pid="starting"
94"${ZZUF}" ${zzuf_all_params} "${SOCAT}" ${socat_options} ${socat_addr1} ${socat_addr2} &
95if test $? -eq 0 ; then
96 zzuf_pid=$!
97 echo "zzuf with socat has been started."
98else
99 zzuf_pid=''
100 echo "Failed to start zzuf with socat" 1>&2
101 exit 99
102fi
103
104echo "## Starting real test of $@ with traffic fuzzed by zzuf with socat..."
105"$@" --with-socat
106test_result=$?
107trap - EXIT
108echo "$@ has exited with the return code $test_result"
109if 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
115fi
116kill -TERM ${zzuf_pid} -${zzuf_pid}
117zzuf_pid=''
118exit $test_result