aboutsummaryrefslogtreecommitdiff
path: root/src/testzzuf
diff options
context:
space:
mode:
Diffstat (limited to 'src/testzzuf')
-rw-r--r--src/testzzuf/Makefile.am29
-rw-r--r--src/testzzuf/test_get.c107
-rwxr-xr-xsrc/testzzuf/zzuf_socat_test_runner.sh118
-rwxr-xr-xsrc/testzzuf/zzuf_test_runner.sh45
4 files changed, 251 insertions, 48 deletions
diff --git a/src/testzzuf/Makefile.am b/src/testzzuf/Makefile.am
index 23b96d66..f38c6d0e 100644
--- a/src/testzzuf/Makefile.am
+++ b/src/testzzuf/Makefile.am
@@ -10,6 +10,15 @@ ZZUF_SEED = 0
10# Additional flags for zzuf 10# Additional flags for zzuf
11ZZUF_FLAGS = 11ZZUF_FLAGS =
12 12
13# Additional flags for socat (if socat is used)
14SOCAT_FLAGS =
15
16if FORCE_USE_ZZUF_SOCAT
17TEST_RUNNER_SCRIPT = zzuf_socat_test_runner.sh
18else
19TEST_RUNNER_SCRIPT = zzuf_test_runner.sh
20endif
21
13AM_CPPFLAGS = \ 22AM_CPPFLAGS = \
14 -I$(top_srcdir)/src/include \ 23 -I$(top_srcdir)/src/include \
15 -I$(top_srcdir)/src/microhttpd \ 24 -I$(top_srcdir)/src/microhttpd \
@@ -23,7 +32,9 @@ AM_LDFLAGS = $(LDFLAGS_ac)
23AM_TESTS_ENVIRONMENT = $(TESTS_ENVIRONMENT_ac) \ 32AM_TESTS_ENVIRONMENT = $(TESTS_ENVIRONMENT_ac) \
24 ZZUF="$(ZZUF)" ; export ZZUF ; \ 33 ZZUF="$(ZZUF)" ; export ZZUF ; \
25 ZZUF_SEED="$(ZZUF_SEED)" ; export ZZUF_SEED ; \ 34 ZZUF_SEED="$(ZZUF_SEED)" ; export ZZUF_SEED ; \
26 ZZUF_FLAGS="$(ZZUF_FLAGS)" ; export ZZUF_FLAGS ; 35 ZZUF_FLAGS="$(ZZUF_FLAGS)" ; export ZZUF_FLAGS ; \
36 SOCAT="$(SOCAT)" ; export SOCAT ; \
37 SOCAT_FLAGS="$(SOCAT_FLAGS)" ; export SOCAT_FLAGS ;
27 38
28if USE_COVERAGE 39if USE_COVERAGE
29 AM_CFLAGS += -fprofile-arcs -ftest-coverage 40 AM_CFLAGS += -fprofile-arcs -ftest-coverage
@@ -70,9 +81,21 @@ check_PROGRAMS = \
70 81
71TESTS = $(check_PROGRAMS) 82TESTS = $(check_PROGRAMS)
72 83
73dist_check_SCRIPTS = zzuf_test_runner.sh 84dist_check_SCRIPTS = zzuf_test_runner.sh zzuf_socat_test_runner.sh
85
86LOG_COMPILER = @SHELL@ "$(srcdir)/$(TEST_RUNNER_SCRIPT)"
87
88if VHEAVY_TESTS
89check_SCRIPTS = warn_vheavy_use
90
91.PHONY: warn_vheavy_use
92endif
74 93
75LOG_COMPILER = @SHELL@ $(srcdir)/zzuf_test_runner.sh 94warn_vheavy_use:
95 @echo "NOTICE" ; \
96 echo "NOTICE: Full heavy tests are enabled. Each test may take up to several minutes to complete." ; \
97 echo "NOTICE"
98
76 99
77tests_common_sources = mhd_debug_funcs.h mhd_debug_funcs.c 100tests_common_sources = mhd_debug_funcs.h mhd_debug_funcs.c
78 101
diff --git a/src/testzzuf/test_get.c b/src/testzzuf/test_get.c
index 904808bc..94a4e833 100644
--- a/src/testzzuf/test_get.c
+++ b/src/testzzuf/test_get.c
@@ -96,8 +96,14 @@ static int use_post_form;
96static int use_long_header; 96static int use_long_header;
97static int use_long_uri; 97static int use_long_uri;
98static int use_close; 98static int use_close;
99static int run_with_socat;
99 100
100#define TEST_BASE_URI "http:/" "/127.0.0.1/test_uri" 101#define TEST_BASE_URI "http:/" "/127.0.0.1/test_uri"
102#define TEST_BASE_URI_SOCAT "http:/" "/127.0.0.121/test_uri"
103
104#define SOCAT_PORT 10121
105
106#define TEST_BASE_PORT 4010
101 107
102#define EMPTY_PAGE "Empty page." 108#define EMPTY_PAGE "Empty page."
103#define EMPTY_PAGE_ALT "Alternative empty page." 109#define EMPTY_PAGE_ALT "Alternative empty page."
@@ -959,19 +965,24 @@ setupCURL (struct CBC *cbc, uint16_t port
959 CURLcode e; 965 CURLcode e;
960 char *buf; 966 char *buf;
961 const char *uri_to_use; 967 const char *uri_to_use;
968 const char *base_uri;
962 969
963#ifndef TEST_USE_STATIC_POST_DATA 970#ifndef TEST_USE_STATIC_POST_DATA
964 *mime = NULL; 971 *mime = NULL;
965#endif /* ! TEST_USE_STATIC_POST_DATA */ 972#endif /* ! TEST_USE_STATIC_POST_DATA */
966 973
974 base_uri = run_with_socat ? TEST_BASE_URI_SOCAT : TEST_BASE_URI;
967 if (! use_long_uri) 975 if (! use_long_uri)
968 { 976 {
969 uri_to_use = TEST_BASE_URI; 977 uri_to_use = base_uri;
970 buf = NULL; 978 buf = NULL;
971 } 979 }
972 else 980 else
973 { 981 {
974 size_t pos; 982 size_t pos;
983 size_t base_uri_len;
984
985 base_uri_len = strlen (base_uri);
975 buf = malloc (TEST_STRING_VLONG_LEN + 1); 986 buf = malloc (TEST_STRING_VLONG_LEN + 1);
976 if (NULL == buf) 987 if (NULL == buf)
977 { 988 {
@@ -979,8 +990,8 @@ setupCURL (struct CBC *cbc, uint16_t port
979 "at line %d.\n", (int) __LINE__); 990 "at line %d.\n", (int) __LINE__);
980 return NULL; 991 return NULL;
981 } 992 }
982 memcpy (buf, TEST_BASE_URI, MHD_STATICSTR_LEN_ (TEST_BASE_URI)); 993 memcpy (buf, base_uri, base_uri_len);
983 for (pos = MHD_STATICSTR_LEN_ (TEST_BASE_URI); 994 for (pos = base_uri_len;
984 pos < TEST_STRING_VLONG_LEN; 995 pos < TEST_STRING_VLONG_LEN;
985 ++pos) 996 ++pos)
986 { 997 {
@@ -993,6 +1004,8 @@ setupCURL (struct CBC *cbc, uint16_t port
993 buf[TEST_STRING_VLONG_LEN] = 0; 1004 buf[TEST_STRING_VLONG_LEN] = 0;
994 uri_to_use = buf; 1005 uri_to_use = buf;
995 } 1006 }
1007 if (run_with_socat)
1008 port = SOCAT_PORT;
996 1009
997 c = curl_easy_init (); 1010 c = curl_easy_init ();
998 if (NULL == c) 1011 if (NULL == c)
@@ -1189,8 +1202,10 @@ start_daemon_for_test (unsigned int daemon_flags, uint16_t *pport,
1189 "at line %d.\n", (int) __LINE__); 1202 "at line %d.\n", (int) __LINE__);
1190 return NULL; 1203 return NULL;
1191 } 1204 }
1205
1192 /* Do not use accept4() as only accept() is intercepted by zzuf */ 1206 /* Do not use accept4() as only accept() is intercepted by zzuf */
1193 MHD_avoid_accept4_ (d); 1207 if (! run_with_socat)
1208 MHD_avoid_accept4_ (d);
1194 1209
1195 if (0 == *pport) 1210 if (0 == *pport)
1196 { 1211 {
@@ -1516,44 +1531,49 @@ run_all_checks (void)
1516 unsigned int testRes; 1531 unsigned int testRes;
1517 unsigned int ret = 0; 1532 unsigned int ret = 0;
1518 1533
1519 if (MHD_are_sanitizers_enabled_ ()) 1534 if (! run_with_socat)
1520 { 1535 {
1521 fprintf (stderr, "The test does not work with sanitizers. " 1536 if (MHD_are_sanitizers_enabled_ ())
1522 "At line %d.\n", (int) __LINE__); 1537 {
1523 return 77; 1538 fprintf (stderr, "Direct run with zzuf does not work with sanitizers. "
1524 } 1539 "At line %d.\n", (int) __LINE__);
1525 if (! MHD_is_avoid_accept4_possible_ ()) 1540 return 77;
1526 { 1541 }
1527 fprintf (stderr, 1542 if (! MHD_is_avoid_accept4_possible_ ())
1528 "Non-debug build of MHD on this platform use accept4() function. " 1543 {
1529 "Test with zzuf is not possible. " 1544 fprintf (stderr,
1530 "At line %d.\n", (int) __LINE__); 1545 "Non-debug build of MHD on this platform use accept4() function. "
1531 return 77; 1546 "Direct run with zzuf is not possible. "
1547 "At line %d.\n", (int) __LINE__);
1548 return 77;
1549 }
1550 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
1551 port = 0; /* Use system automatic assignment */
1552 else
1553 {
1554 port = TEST_BASE_PORT; /* Use predefined port, may break parallel testing of another MHD build */
1555 if (oneone)
1556 port += 100;
1557 if (use_long_uri)
1558 port += 30;
1559 else if (use_long_header)
1560 port += 35;
1561 else if (use_get_chunked)
1562 port += 0;
1563 else if (use_get)
1564 port += 5;
1565 else if (use_post_form)
1566 port += 10;
1567 else if (use_post)
1568 port += 15;
1569 else if (use_put_large)
1570 port += 20;
1571 else if (use_put_chunked)
1572 port += 25;
1573 }
1532 } 1574 }
1533 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
1534 port = 0; /* Use system automatic assignment */
1535 else 1575 else
1536 { 1576 port = TEST_BASE_PORT; /* Use predefined port, may break parallel testing of another MHD build */
1537 port = 4010; /* Use predefined port, may break parallel testing of another MHD build */
1538 if (oneone)
1539 port += 100;
1540 if (use_long_uri)
1541 port += 30;
1542 else if (use_long_header)
1543 port += 35;
1544 else if (use_get_chunked)
1545 port += 0;
1546 else if (use_get)
1547 port += 5;
1548 else if (use_post_form)
1549 port += 10;
1550 else if (use_post)
1551 port += 15;
1552 else if (use_put_large)
1553 port += 20;
1554 else if (use_put_chunked)
1555 port += 25;
1556 }
1557 1577
1558 if (! dry_run && (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))) 1578 if (! dry_run && (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS)))
1559 { 1579 {
@@ -1600,6 +1620,7 @@ int
1600main (int argc, char *const *argv) 1620main (int argc, char *const *argv)
1601{ 1621{
1602 unsigned int res; 1622 unsigned int res;
1623 int use_magic_exit_codes;
1603 1624
1604 oneone = ! has_in_name (argv[0], "10"); 1625 oneone = ! has_in_name (argv[0], "10");
1605 use_get = has_in_name (argv[0], "_get"); 1626 use_get = has_in_name (argv[0], "_get");
@@ -1613,6 +1634,7 @@ main (int argc, char *const *argv)
1613 use_long_uri = has_in_name (argv[0], "_long_uri"); 1634 use_long_uri = has_in_name (argv[0], "_long_uri");
1614 use_close = has_in_name (argv[0], "_close"); 1635 use_close = has_in_name (argv[0], "_close");
1615 1636
1637 run_with_socat = has_param (argc, argv, "--with-socat");
1616 dry_run = has_param (argc, argv, "--dry-run") || 1638 dry_run = has_param (argc, argv, "--dry-run") ||
1617 has_param (argc, argv, "-n"); 1639 has_param (argc, argv, "-n");
1618 1640
@@ -1623,17 +1645,18 @@ main (int argc, char *const *argv)
1623 "for the test type.\n", argv[0] ? argv[0] : "(NULL)"); 1645 "for the test type.\n", argv[0] ? argv[0] : "(NULL)");
1624 return 99; 1646 return 99;
1625 } 1647 }
1648 use_magic_exit_codes = run_with_socat || dry_run;
1626 1649
1627 /* zzuf cannot bypass exit values. 1650 /* zzuf cannot bypass exit values.
1628 Unless 'dry run' is used, do not return errors for external error 1651 Unless 'dry run' is used, do not return errors for external error
1629 conditions (like out-of-memory) as they will be reported as test failures. */ 1652 conditions (like out-of-memory) as they will be reported as test failures. */
1630 if (! test_global_init ()) 1653 if (! test_global_init ())
1631 return dry_run ? 99 : 0; 1654 return use_magic_exit_codes ? 99 : 0;
1632 res = run_all_checks (); 1655 res = run_all_checks ();
1633 test_global_deinit (); 1656 test_global_deinit ();
1634 if (99 == res) 1657 if (99 == res)
1635 return dry_run ? 99 : 0; 1658 return use_magic_exit_codes ? 99 : 0;
1636 if (77 == res) 1659 if (77 == res)
1637 return dry_run ? 77 : 0; 1660 return use_magic_exit_codes ? 77 : 0;
1638 return (0 == res) ? 0 : 1; /* 0 == pass */ 1661 return (0 == res) ? 0 : 1; /* 0 == pass */
1639} 1662}
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
diff --git a/src/testzzuf/zzuf_test_runner.sh b/src/testzzuf/zzuf_test_runner.sh
index aa1dfdde..40367639 100755
--- a/src/testzzuf/zzuf_test_runner.sh
+++ b/src/testzzuf/zzuf_test_runner.sh
@@ -13,6 +13,40 @@ if command -v "${ZZUF}" > /dev/null 2>&1 ; then : ; else
13 exit 77 13 exit 77
14fi 14fi
15 15
16run_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
16# zzuf cannot pass-through the return value of checked program 50# zzuf cannot pass-through the return value of checked program
17# so try the direct dry-run first to get possibe 77 or 99 codes 51# so try the direct dry-run first to get possibe 77 or 99 codes
18echo "## Dry-run of the $@..." 52echo "## Dry-run of the $@..."
@@ -20,7 +54,11 @@ if "$@" --dry-run ; then
20 echo "# Dry-run succeded." 54 echo "# Dry-run succeded."
21else 55else
22 res_code=$? 56 res_code=$?
23 echo "Dry-run failed with exit code $res_code. $@ will not be run with zzuf." 1>&2 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
24 exit $res_code 62 exit $res_code
25fi 63fi
26 64
@@ -46,8 +84,9 @@ if "$ZZUF" ${zzuf_all_params} "$@" --dry-run ; then
46 echo "# Dry-run with zzuf succeded." 84 echo "# Dry-run with zzuf succeded."
47else 85else
48 res_code=$? 86 res_code=$?
49 echo "$@ cannot be run with zzuf. The test is skipped." 1>&2 87 echo "$@ cannot be run with zzuf directly." 1>&2
50 exit 77 88 run_with_socat "$@"
89 exit $res_code
51fi 90fi
52 91
53echo "## Real test of $@ with zzuf..." 92echo "## Real test of $@ with zzuf..."