summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Gerstner <matthias.gerstner@suse.de>2022-10-27 12:32:44 +0200
committerDaniel Wagner <wagi@monom.org>2022-11-03 08:10:26 +0100
commit38aeb4e4a6e7468e5f54ce654ac54f819c7b5ae7 (patch)
tree4122fff61324a5b61be88d935cd9a69c7f9688f7
parenta9212a41cff527852459a1dc9e91b855bc545124 (diff)
downloadconnman-38aeb4e4a6e7468e5f54ce654ac54f819c7b5ae7.tar.gz
dnsproxy-simple-test: improve test coverage and test flexibility
- enable debug() macro for test invocation which allows to get test logs - actually trigger caching logic explicitly by querying the same configurations twice in succession - count the number of cache hits to catch regressions in the caching functionality - support custom domains for testing specified on the command line
-rw-r--r--Makefile.am2
-rw-r--r--src/dnsproxy.c6
-rwxr-xr-xtools/dnsproxy-simple-test113
3 files changed, 104 insertions, 17 deletions
diff --git a/Makefile.am b/Makefile.am
index c108b8f3..1a3dbe3c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -438,7 +438,7 @@ testdir = $(pkglibdir)/test
test_SCRIPTS = $(test_scripts)
if INTERNAL_DNS_BACKEND
-tools_dnsproxy_standalone_CFLAGS = $(src_connmand_CFLAGS) -I$(srcdir)/src
+tools_dnsproxy_standalone_CFLAGS = $(src_connmand_CFLAGS) -I$(srcdir)/src -DDNSPROXY_DEBUG
tools_dnsproxy_standalone_SOURCES = tools/dnsproxy-standalone.c $(src_connmand_SOURCES)
# for EXTRA_PROGRAMS the BUILT_SOURCES aren't automatically added as
# dependency, so let's do it explicitly
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index a810b676..78621063 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -41,7 +41,11 @@
#include "connman.h"
-#define debug(fmt...) do { } while (0)
+#ifdef DNSPROXY_DEBUG
+# define debug(fmt...) do { fprintf(stderr, fmt); fprintf(stderr, "\n"); } while (0)
+#else
+# define debug(fmt...) do { } while (0)
+#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
struct domain_hdr {
diff --git a/tools/dnsproxy-simple-test b/tools/dnsproxy-simple-test
index b8fd7f77..5c2f7292 100755
--- a/tools/dnsproxy-simple-test
+++ b/tools/dnsproxy-simple-test
@@ -6,9 +6,25 @@
echoerr() {
echo $@ 1>&2
+ echo -e "\n >>> ERROR OCCURED <<< \n" 1>&2
exit 1
}
+
+showlog() {
+ if [ -z "$SHOW_LOG" -o -z "$logfile" ]; then
+ return
+ fi
+
+ echo
+ echo "======== debug log ==========="
+ cat "$logfile"
+ echo "===== end debug log =========="
+ echo
+}
+
+TRANSPORTS="-U -T"
+
while [ $# -gt 0 ]; do
case "$1" in
"--valgrind")
@@ -16,10 +32,39 @@ while [ $# -gt 0 ]; do
if [ -z "$VALGRIND" ]; then
echoerr "no valgrind executable found"
fi
+ # log valgrind output to stdout, since stderr is used for
+ # debug output from dnsproxy.c already and we want to parse
+ # that.
+ # also cause an error exit it valgrind error occur so that
+ # they're easily noticed.
+ VALGRIND="$VALGRIND --log-fd=1 --error-exitcode=10"
+ ;;
+ "--gdb")
+ WAIT_GDB=1
+ # wait forever to avoid timeout conditions during debugging
+ HOST_OPTS="-w"
+ ;;
+ "--show-log")
+ SHOW_LOG=1
+ ;;
+ "--testdomain="*)
+ TESTDOMAIN=`echo $1 | cut -d '=' -f2-`
+ CUSTOM_TESTDOMAIN=1
+ ;;
+ "--only-tcp")
+ TRANSPORTS="-T"
+ ;;
+ "--only-udp")
+ TRANSPORTS="-U"
;;
"-h")
- echo "$0 [--valgrind]"
+ echo "$0 [--valgrind] [--gdb] [--show-log] [--only-tcp] [--only-udp] [--testdomain=<mydomain>]"
echo "--valgrind: run dnsproxy-standalone in valgrind"
+ echo "--gdb: allows you to attach via GDB before tests are started"
+ echo "--show-log: dump debug log from dnsproxy at end of test"
+ echo "--only-tcp: only perform TCP protocol based tests"
+ echo "--only-udp: only perform UDP protocol based tests"
+ echo "--testdomain=<mydomain>: the domain name to resolve"
exit 2
;;
*)
@@ -29,6 +74,11 @@ while [ $# -gt 0 ]; do
shift
done
+if [ -n "$VALGRIND" -a -n "$WAIT_GDB" ]; then
+ echo "Cannot mix valgrind frontend and GDB attachment" 1>&2
+ exit 2
+fi
+
if [ -e "Makefile" ]; then
BUILDROOT="$PWD"
else
@@ -66,7 +116,8 @@ fi
PORT=8053
# run the proxy in the background
-$VALGRIND $DNSPROXY $PORT "$DOMAIN1" "$NS1" &
+logfile=`mktemp`
+$VALGRIND $DNSPROXY $PORT "$DOMAIN1" "$NS1" 2>"$logfile" &
proxy_pid=$!
cleanup() {
@@ -77,6 +128,13 @@ cleanup() {
wait $proxy_pid
ret=$?
proxy_pid=-1
+ if [ -n "$logfile" ]; then
+ if [ -n "$SHOW_LOG" ]; then
+ showlog
+ fi
+ rm -f "$logfile"
+ unset logfile
+ fi
return $ret
}
@@ -85,24 +143,49 @@ trap cleanup err exit
sleep 1
echo -e "\n\n"
-# test both UDP and TCP mode
-for TRANSPORT in -U -T; do
- # test both IPv4 and IPv6
- for IP in -4 -6; do
- echo "Testing resolution using transport $TRANSPORT and IP${IP}"
- set -x
- $HOST $TRANSPORT $IP -p$PORT www.example.com 127.0.0.1
- RES=$?
- set +x
- if [ $RES -ne 0 ]; then
- echoerr "resolution failed"
- fi
+if [ -n "$WAIT_GDB" ]; then
+ echo "You can now attach to the dnsproxy process at PID $proxy_pid."
+ echo "Press ENTER to continue test execution"
+ read _
+fi
+
+if [ -z "$TESTDOMAIN" ]; then
+ TESTDOMAIN="www.example.com"
+fi
- echo -e "\n\n"
+# perform each test twice to actually get cached responses served for each
+# combination
+for I in `seq 2`; do
+ # test both UDP and TCP mode
+ for TRANSPORT in $TRANSPORTS; do
+ # test both IPv4 and IPv6
+ for IP in -4 -6; do
+ echo "Testing resolution using transport $TRANSPORT and IP${IP}"
+ set -x
+ $HOST $HOST_OPTS $TRANSPORT $IP -p$PORT $TESTDOMAIN 127.0.0.1
+ RES=$?
+ set +x
+ if [ $RES -ne 0 ]; then
+ echoerr "resolution failed"
+ fi
+
+ echo -e "\n\n"
+ done
done
done
+NUM_HITS=`grep "cache hit.*$TESTDOMAIN" "$logfile" | wc -l`
+
echo -e "\n\nDNS resolution succeeded for all test combinations"
+echo -e "\nNumber of cache hits: $NUM_HITS\n"
+# assert we have seen the expected number of cache hits in the log
+# this is the amount of cache hits for the default domain tests as seen before
+# refactoring of dnsproxy started.
+if [ -z "$CUSTOM_TESTDOMAIN" -a "$NUM_HITS" -ne 15 ]; then
+ echoerr "Unexpected number of cache hits encountered"
+elif [ "$NUM_HITS" -lt 8 ]; then
+ echoerr "Too low number of cache hits encountered"
+fi
cleanup
if [ $? -eq 0 ]; then
exit 0