summaryrefslogtreecommitdiffstats
path: root/nsock/tests/run_tests.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:42:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:42:04 +0000
commit0d47952611198ef6b1163f366dc03922d20b1475 (patch)
tree3d840a3b8c0daef0754707bfb9f5e873b6b1ac13 /nsock/tests/run_tests.sh
parentInitial commit. (diff)
downloadnmap-upstream.tar.xz
nmap-upstream.zip
Adding upstream version 7.94+git20230807.3be01efb1+dfsg.upstream/7.94+git20230807.3be01efb1+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'nsock/tests/run_tests.sh')
-rwxr-xr-xnsock/tests/run_tests.sh86
1 files changed, 86 insertions, 0 deletions
diff --git a/nsock/tests/run_tests.sh b/nsock/tests/run_tests.sh
new file mode 100755
index 0000000..c0392f8
--- /dev/null
+++ b/nsock/tests/run_tests.sh
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# nsock regression test suite
+# Same license as nmap -- see https://nmap.org/book/man-legal.html
+
+# hackish, I should consider using a configuration file.
+PORT_UDP=$(grep "PORT_UDP " test-common.h | awk '{print $3}')
+PORT_TCP=$(grep "PORT_TCP " test-common.h | awk '{print $3}')
+PORT_TCPSSL=$(grep "PORT_TCPSSL " test-common.h | awk '{print $3}')
+
+EXEC_MAIN=./tests_main
+
+NCAT=${NCAT:-ncat}
+if [ ! -x "$NCAT" -a -z "$(which $NCAT)" ]; then
+ echo "Can't find your ncat: $NCAT"
+ echo "Trying ../../ncat/ncat"
+ NCAT="../../ncat/ncat"
+ if [ ! -x "$NCAT" ]; then
+ echo "You haven't built Ncat."
+ echo "Skipping nsock tests."
+ exit 0
+ fi
+fi
+
+
+if [ -n "$1" ]
+then
+ case "$1" in
+ "gdb")
+ TRACER="gdb --args"
+ ;;
+
+ "trace")
+ TRACER="strace"
+ ;;
+
+ "leak")
+ TRACER="valgrind --leak-check=yes"
+ ;;
+
+ "-h")
+ echo "Usage: `basename $0` [gdb|trace|leak]"
+ exit 0
+ ;;
+
+ *)
+ echo "Unknown mode $1"
+ exit 1
+ ;;
+ esac
+fi
+
+
+setup_echo_udp() {
+ $NCAT -l --udp --sh-exec cat 127.0.0.1 $PORT_UDP &
+ pid_udp=$!
+ echo "started UDP listener on port $PORT_UDP (pid $pid_udp)"
+}
+
+setup_echo_tcp() {
+ $NCAT -l --keep-open --sh-exec cat 127.0.0.1 $PORT_TCP &
+ pid_tcp=$!
+ echo "started TCP listener on port $PORT_TCP (pid $pid_tcp)"
+}
+
+setup_echo_tcpssl() {
+ $NCAT -l --ssl --keep-open --sh-exec cat 127.0.0.1 $PORT_TCPSSL &
+ pid_tcpssl=$!
+ echo "started TCP SSL listener on port $PORT_TCPSSL (pid $pid_tcpssl)"
+}
+
+cleanup_all() {
+ kill -s KILL $@ 2>&1 >> /dev/null
+}
+
+main() {
+ setup_echo_udp $PORT_UDP
+ setup_echo_tcp $PORT_TCP
+ $EXEC_MAIN --ssl && setup_echo_tcpssl $PORT_TCPSSL
+
+ $TRACER $EXEC_MAIN
+
+ cleanup_all $pid_udp $pid_tcp $pid_tcpssl
+}
+
+main