aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-04-04 21:59:14 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-07-30 22:09:21 +0200
commitb503900b1456e8bd4b60d1deb0ef7cc3665676f1 (patch)
tree92e7a88c190caf23f810e0a828b6da926f11879a /tests
parent13c5d6801e3b9fdc71bec88c300243a939346a8d (diff)
First step of cleaning up the Makefile.in hell.first-step-to-automake-integration
The goal is to get rid of the Makefile.in's (replace it with Automake Makefile.am's) as they duplicate lot's of text. That decreases readability and is in general a bad design pattern. It seems appropriate to use Automake for an Autoconf based project. Currently achieved: * using libtool to build the core library (+libtool's semantic versioning) * out-of-source builds should work right now * introducing Automake based Makefile in src/ * removed some (maybe) unused GIT ignored files * provide some small python fixes Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/dga/Makefile.in28
-rwxr-xr-xtests/do-dga.sh.in (renamed from tests/do-dga.sh)14
-rwxr-xr-xtests/do-unit.sh32
-rwxr-xr-xtests/do-unit.sh.in20
-rwxr-xr-xtests/do.sh.in20
-rwxr-xr-xtests/do_valgrind.sh.in11
-rw-r--r--tests/unit/Makefile.in25
8 files changed, 76 insertions, 78 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 271516b87..b6d37ddf5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
-TESTS = do.sh
+TESTS = do.sh do-unit.sh
-EXTRA_DIST = ossfuzz.sh pcap result
+EXTRA_DIST = do_valgrind.sh do-dga.sh ossfuzz.sh pcap result
all:
@echo -n ""
diff --git a/tests/dga/Makefile.in b/tests/dga/Makefile.in
index fc94ed7e7..aa2fa5d86 100644
--- a/tests/dga/Makefile.in
+++ b/tests/dga/Makefile.in
@@ -1,25 +1,24 @@
CC=@CC@
CXX=@CXX@
-SRCHOME=../../src
-
-CFLAGS=-g -fPIC -DPIC -I$(SRCHOME)/include @JSONC_CFLAGS@ @PCAP_INC@ @CFLAGS@
-LIBNDPI=$(SRCHOME)/lib/libndpi.a
-LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @LIBS@ @ADDITIONAL_LIBS@ @JSONC_LIBS@ -lpthread @LDFLAGS@
-HEADERS=$(SRCHOME)/include/ndpi_api.h $(SRCHOME)/include/ndpi_typedefs.h $(SRCHOME)/include/ndpi_protocol_ids.h
+BUILD_SRC=../../src
+ROOT_SRC=@srcdir@/../../src
+ROOT_TESTS_DGA=@srcdir@
+
+CFLAGS=-g -fPIC -DPIC -I$(ROOT_SRC)/include -I$(BUILD_SRC)/include @JSONC_CFLAGS@ @PCAP_INC@ @CFLAGS@
+LIBNDPI=$(BUILD_SRC)/.libs/libndpi.a
+LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @LIBS@ @JSONC_LIBS@ -lpthread @LDFLAGS@
+HEADERS=$(BUILD_SRC)/include/ndpi_api.h $(ROOT_SRC)/include/ndpi_typedefs.h $(ROOT_SRC)/include/ndpi_protocol_ids.h
OBJS=dga_evaluate
PREFIX?=@prefix@
all: dga_evaluate
-EXECUTABLE_SOURCES := dga_evaluate.c
-COMMON_SOURCES := $(filter-out $(EXECUTABLE_SOURCES),$(wildcard *.c ))
-
dga_evaluate: $(LIBNDPI) dga_evaluate.o
$(CC) $(CFLAGS) dga_evaluate.o -o $@ $(LDFLAGS)
-%.o: %.c $(HEADERS) Makefile
- $(CC) $(CFLAGS) -c $< -o $@
+%.o: $(ROOT_TESTS_DGA)/%.c $(HEADERS) Makefile
+ $(CC) $(CFLAGS) -c $< -o $(notdir $@)
clean:
/bin/rm -f *.o dga_evaluate
@@ -30,7 +29,12 @@ install:
echo ""
distdir:
-
+ cp \
+ $(ROOT_TESTS_DGA)/dga_evaluate.c \
+ $(ROOT_TESTS_DGA)/README.md \
+ $(ROOT_TESTS_DGA)/test_dga.csv \
+ $(ROOT_TESTS_DGA)/test_non_dga.csv \
+ '$(distdir)/'
distclean: clean
/bin/rm -f Makefile
diff --git a/tests/do-dga.sh b/tests/do-dga.sh.in
index 93408a012..4c5bd8766 100755
--- a/tests/do-dga.sh
+++ b/tests/do-dga.sh.in
@@ -9,17 +9,17 @@ BASE_PRECISION=89
BASE_RECALL=41
# ----------------------------------------------------------------------------------------------------------------------
-DGA_EVALUATE="./dga/dga_evaluate"
-DGA_DATA="dga/test_dga.csv"
-NON_DGA_DATA="dga/test_non_dga.csv"
+DGA_EVALUATE="dga/dga_evaluate"
+DGA_DATA="@srcdir@/dga/test_dga.csv"
+NON_DGA_DATA="@srcdir@/dga/test_non_dga.csv"
DGA_DATA_SIZE=0
NON_DGA_DATA_SIZE=0
DATA_SIZE=0
RC=0
get_evaluation_data_size() {
- DGA_DATA_SIZE=`wc -l dga/test_dga.csv | awk '{split($0,a," "); print a[1]}'`
- NON_DGA_DATA_SIZE=`wc -l dga/test_non_dga.csv | awk '{split($0,a," "); print a[1]}'`
+ DGA_DATA_SIZE=`wc -l ${DGA_DATA} | awk '{split($0,a," "); print a[1]}'`
+ NON_DGA_DATA_SIZE=`wc -l ${NON_DGA_DATA} | awk '{split($0,a," "); print a[1]}'`
DATA_SIZE=$(( $NON_DGA_DATA_SIZE + $DGA_DATA_SIZE ))
}
@@ -29,9 +29,9 @@ evaluate_ndpi_dga_detection() {
# Precision: TP / (TP + FP)
# Recall: TP / (TP + FN)
- TP=`$DGA_EVALUATE dga/test_dga.csv`
+ TP=`$DGA_EVALUATE ${DGA_DATA}`
FN=$(( $DGA_DATA_SIZE - $TP ))
- FP=`$DGA_EVALUATE dga/test_non_dga.csv`
+ FP=`$DGA_EVALUATE ${NON_DGA_DATA}`
TN=$(( $NON_DGA_DATA_SIZE - $FP ))
ACCURACY=`echo "print(int(((${TP} + ${TN})/(${TP} + ${TN} + ${FP} + ${FN}))*100))" | python3`
diff --git a/tests/do-unit.sh b/tests/do-unit.sh
deleted file mode 100755
index 937be26ff..000000000
--- a/tests/do-unit.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-cd "$(dirname "${0}")"
-
-UNIT="./unit/unit"
-
-RC=0
-
-check_unit() {
-
- case "$CXXFLAGS" in
- # Skipping tests with sanitizer enabled due to use-of-uninitialized-value in json-c
- *sanitize* )
- echo "Skipping unit tests for this environment"
- return
- ;;
- * )
- echo ""
- echo "Running unit tests.."
- ;;
- esac
-
- $UNIT
- UNIT_RC=$?
- if [ $UNIT_RC -ne 0 ]; then
- RC=1
- fi
-}
-
-check_unit
-
-exit $RC
diff --git a/tests/do-unit.sh.in b/tests/do-unit.sh.in
new file mode 100755
index 000000000..cefc8a9ca
--- /dev/null
+++ b/tests/do-unit.sh.in
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+cd "$(dirname "${0}")"
+
+UNIT="./unit/unit"
+
+RC=0
+
+check_unit() {
+
+ $UNIT
+ UNIT_RC=$?
+ if [ $UNIT_RC -ne 0 ]; then
+ RC=1
+ fi
+}
+
+check_unit
+
+exit $RC
diff --git a/tests/do.sh.in b/tests/do.sh.in
index 01fad8497..4c081773b 100755
--- a/tests/do.sh.in
+++ b/tests/do.sh.in
@@ -1,26 +1,30 @@
#!/bin/sh
-cd "$(dirname "${0}")"
+BUILD_TESTS="$(realpath $(dirname "${0}"))"
+cd "$(dirname "${0}")/@srcdir@"
FUZZY_TESTING_ENABLED=@BUILD_FUZZTARGETS@
GCRYPT_ENABLED=@GCRYPT_ENABLED@
GCRYPT_PCAPS="gquic.pcap quic-23.pcap quic-24.pcap quic-27.pcap quic-28.pcap quic-29.pcap quic-mvfst-22.pcap quic-mvfst-27.pcapng quic-mvfst-exp.pcap quic_q50.pcap quic_t50.pcap quic_t51.pcap quic_0RTT.pcap quic_interop_V.pcapng quic-33.pcapng doq.pcapng doq_adguard.pcapng dlt_ppp.pcap os_detected.pcapng quic_frags_ch_out_of_order_same_packet_craziness.pcapng quic_frags_ch_in_multiple_packets.pcapng"
-READER="../example/ndpiReader -p ../example/protos.txt -c ../example/categories.txt -r ../example/risky_domains.txt -j ../example/ja3_fingerprints.csv -S ../example/sha1_fingerprints.csv"
+READER="${BUILD_TESTS}/../example/ndpiReader -p ../example/protos.txt -c ../example/categories.txt -r ../example/risky_domains.txt -j ../example/ja3_fingerprints.csv -S ../example/sha1_fingerprints.csv"
RC=0
PCAPS=`cd pcap; /bin/ls *.pcap *.pcapng`
-if [ ! -x "../example/ndpiReader" ]; then
- echo "$0: Missing $(realpath ../example/ndpiReader)"
- echo "$0: Run ./configure and make first"
+if [ ! -x "${BUILD_TESTS}/../example/ndpiReader" ]; then
+ echo "$0: Missing ${BUILD_TESTS}/../example/ndpiReader)"
+ echo "$0: Run make first."
exit 1
fi
fuzzy_testing() {
- if [ -f ../fuzz/fuzz_ndpi_reader ]; then
- ../fuzz/fuzz_ndpi_reader -max_total_time="${MAX_TOTAL_TIME:-592}" -print_pcs=1 -workers="${FUZZY_WORKERS:-0}" -jobs="${FUZZY_JOBS:-0}" pcap/
- fi
+ if [ -f "${BUILD_TESTS}/../fuzz/fuzz_ndpi_reader" ]; then
+ ${BUILD_TESTS}/../fuzz/fuzz_ndpi_reader \
+ -max_total_time="${MAX_TOTAL_TIME:-592}" -print_pcs=1 \
+ -workers="${FUZZY_WORKERS:-0}" -jobs="${FUZZY_JOBS:-0}" \
+ pcap/
+ fi
}
build_results() {
diff --git a/tests/do_valgrind.sh.in b/tests/do_valgrind.sh.in
index 8ab0509a8..c76cc6e1a 100755
--- a/tests/do_valgrind.sh.in
+++ b/tests/do_valgrind.sh.in
@@ -1,17 +1,18 @@
#!/bin/sh
-cd "$(dirname "${0}")"
+BUILD_TESTS="$(realpath $(dirname "${0}"))"
+cd "$(dirname "${0}")/@srcdir@"
GCRYPT_ENABLED=@GCRYPT_ENABLED@
GCRYPT_PCAPS="gquic.pcap quic-23.pcap quic-24.pcap quic-27.pcap quic-28.pcap quic-29.pcap quic-mvfst-22.pcap quic-mvfst-27.pcap quic-mvfst-exp.pcap quic_q50.pcap quic_t50.pcap quic_t51.pcap quic_0RTT.pcap quic_interop_V.pcapng quic-33.pcapng doq.pcapng doq_adguard.pcapng dlt_ppp.pcap"
-READER="valgrind -q --leak-check=full ../example/ndpiReader -p ../example/protos.txt -c ../example/categories.txt"
+READER="valgrind -q --leak-check=full ${BUILD_TESTS}/../example/ndpiReader -p ../example/protos.txt -c ../example/categories.txt"
RC=0
PCAPS=`cd pcap; /bin/ls *.pcap`
-if [ ! -x "../example/ndpiReader" ]; then
- echo "$0: Missing $(realpath ../example/ndpiReader)"
- echo "$0: Run ./configure and make first"
+if [ ! -x "${BUILD_TESTS}/../example/ndpiReader" ]; then
+ echo "$0: Missing $(realpath ${BUILD_TESTS}/../example/ndpiReader)"
+ echo "$0: Run make first."
exit 1
fi
diff --git a/tests/unit/Makefile.in b/tests/unit/Makefile.in
index efbd387c8..808a177dd 100644
--- a/tests/unit/Makefile.in
+++ b/tests/unit/Makefile.in
@@ -1,25 +1,24 @@
CC=@CC@
CXX=@CXX@
-SRCHOME=../../src
-
-CFLAGS=-g -fPIC -DPIC -I$(SRCHOME)/include @JSONC_CFLAGS@ @PCAP_INC@ @CFLAGS@
-LIBNDPI=$(SRCHOME)/lib/libndpi.a
-LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @LIBS@ @ADDITIONAL_LIBS@ @JSONC_LIBS@ -lpthread @LDFLAGS@
-HEADERS=$(SRCHOME)/include/ndpi_api.h $(SRCHOME)/include/ndpi_typedefs.h $(SRCHOME)/include/ndpi_protocol_ids.h
+BUILD_SRC=../../src
+ROOT_SRC=@srcdir@/../../src
+ROOT_TESTS_UNIT=@srcdir@
+
+CFLAGS=-g -fPIC -DPIC -I$(ROOT_SRC)/include -I$(BUILD_SRC)/include @JSONC_CFLAGS@ @PCAP_INC@ @CFLAGS@
+LIBNDPI=$(BUILD_SRC)/.libs/libndpi.a
+LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @LIBS@ @JSONC_LIBS@ -lpthread @LDFLAGS@
+HEADERS=$(BUILD_SRC)/include/ndpi_api.h $(ROOT_SRC)/include/ndpi_typedefs.h $(ROOT_SRC)/include/ndpi_protocol_ids.h
OBJS=unit
PREFIX?=@prefix@
all: unit
-EXECUTABLE_SOURCES := unit.c
-COMMON_SOURCES := $(filter-out $(EXECUTABLE_SOURCES),$(wildcard *.c ))
-
unit: $(LIBNDPI) unit.o
$(CC) $(CFLAGS) unit.o -o $@ $(LDFLAGS)
-%.o: %.c $(HEADERS) Makefile
- $(CC) $(CFLAGS) -c $< -o $@
+%.o: $(ROOT_TESTS_UNIT)/%.c $(HEADERS) Makefile
+ $(CC) $(CFLAGS) -c $< -o $(notdir $@)
clean:
/bin/rm -f *.o unit
@@ -30,7 +29,9 @@ install:
echo ""
distdir:
-
+ cp \
+ $(ROOT_TESTS_UNIT)/unit.c \
+ '$(distdir)/'
distclean: clean
/bin/rm -f Makefile