Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 May 2021 19:40:36 GMT
From:      Alexey Dokuchaev <danfe@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: a9a4a7c88c78 - main - net/arataga: hook the unit tests to our framework.
Message-ID:  <202105311940.14VJeaj4067551@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by danfe:

URL: https://cgit.FreeBSD.org/ports/commit/?id=a9a4a7c88c78be530d58add7bff01a8be0c724bf

commit a9a4a7c88c78be530d58add7bff01a8be0c724bf
Author:     Alexey Dokuchaev <danfe@FreeBSD.org>
AuthorDate: 2021-05-31 19:26:56 +0000
Commit:     Alexey Dokuchaev <danfe@FreeBSD.org>
CommitDate: 2021-05-31 19:39:35 +0000

    net/arataga: hook the unit tests to our framework.
---
 net/arataga/Makefile       |  4 ++
 net/arataga/files/makefile | 92 +++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 91 insertions(+), 5 deletions(-)

diff --git a/net/arataga/Makefile b/net/arataga/Makefile
index 237ce2aa02c6..a70d00b2ba8b 100644
--- a/net/arataga/Makefile
+++ b/net/arataga/Makefile
@@ -21,12 +21,16 @@ BUILD_DEPENDS=	${LOCALBASE}/include/spdlog/spdlog.h:devel/spdlog \
 LIB_DEPENDS=	libso.${_SO5_LIBVER}.so:devel/sobjectizer \
 		libfmt.so:devel/libfmt \
 		libhttp_parser.so:www/http-parser
+TEST_DEPENDS=	${LOCALBASE}/include/doctest/doctest.h:devel/doctest
 
 USES=		compiler:c++17-lang gmake
 MAKEFILE=	${FILESDIR}/makefile
 MAKE_ENV=	SO5_LIBVER=${_SO5_LIBVER}
 WRKSRC_SUBDIR=	${PORTNAME}
 
+TEST_TARGET=	run_unit_tests
+TEST_WRKSRC=	${WRKSRC}/../tests
+
 USE_GITHUB=	yes
 GH_ACCOUNT=	Stiffstream
 GH_PROJECT=	noexcept-ctcheck:nectc restinio:rinio so5extra:so5e
diff --git a/net/arataga/files/makefile b/net/arataga/files/makefile
index 5a25314533f4..5ee132825d72 100644
--- a/net/arataga/files/makefile
+++ b/net/arataga/files/makefile
@@ -1,7 +1,9 @@
 CXXFLAGS+=	-std=c++17 -Wall -Wextra
-CPPFLAGS+=	-I. -I.. -I$(LOCALBASE)/include -DSPDLOG_FMT_EXTERNAL
-LDFLAGS+=	-pthread $(LOCALBASE)/lib/libso.$(SO5_LIBVER).so \
-		-L$(LOCALBASE)/lib -lfmt -lhttp_parser
+CPPFLAGS+=	-I.$(if $(findstring run_unit_tests,$(MAKECMDGOALS)),./arataga)
+CPPFLAGS+=	-I.. -I$(LOCALBASE)/include -DSPDLOG_FMT_EXTERNAL
+LDFLAGS+=	-L$(LOCALBASE)/lib
+LIBS=		-lpthread $(LOCALBASE)/lib/libso.$(SO5_LIBVER).so \
+		-lfmt -lhttp_parser
 
 oess_OBJS=	oess_2/defs/err_code.o \
 		oess_2/defs/ex.o \
@@ -57,7 +59,8 @@ all_OBJS=	$(oess_OBJS) $(stats_OBJS) config.o $(logging_OBJS) \
 CCACHE?=	$(shell command -v ccache)
 
 %.o: %.cpp
-	$(CCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $<
+# XXX: $@ does not play well with VPATH :(
+	$(CCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(<:.cpp=.o) -c $<
 
 arataga: $(all_OBJS)
 	$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
@@ -67,4 +70,83 @@ all: arataga
 install: arataga
 	$(BSD_INSTALL_PROGRAM) $^ $(DESTDIR)$(PREFIX)/bin
 
-.PHONY: all install
+UNIT_TESTS=	config_parser local_user_list_data dns_types \
+		socks5_1 socks5_2 socks5_3 \
+		http_1 http_2 http_3 http_4 http_5
+
+# Tests live in (and built from) their own subdirectory, but use main
+# project files as well, so use VPATH to help make(1) find them.
+VPATH=		../arataga
+
+config_parser_test_OBJS=\
+		config_parser/main.o \
+		config.o
+config_parser_test_LIBS=	-lfmt
+
+local_user_list_data_test_OBJS=\
+		local_user_list_data/main.o \
+		user_list_auth_data.o
+local_user_list_data_test_LIBS=	-lfmt
+
+dns_types_test_OBJS=\
+		dns_types/main.o \
+		oess_2/defs/err_code.o \
+		oess_2/defs/ex.o \
+		oess_2/defs/quantity.o \
+		oess_2/io/binbuffer.o \
+		oess_2/io/bstring_buf.o \
+		oess_2/io/fixed_mem_buf.o \
+		oess_2/io/stream.o
+dns_types_test_LIBS=	-lfmt
+
+# These object files are common to (shared by) SOCKS and HTTP tests.
+common_test_OBJS=\
+		connection_handler_simulator/impl.o \
+		$(connection_handlers_OBJS) $(logging_OBJS)
+
+socks5_1_test_OBJS=	socks5/bind_pdu/main.o $(common_test_OBJS)
+socks5_1_test_LIBS=	$(LIBS)
+
+socks5_2_test_OBJS=	socks5/command_pdu/main.o $(common_test_OBJS)
+socks5_2_test_LIBS=	$(LIBS)
+
+socks5_3_test_OBJS=	socks5/illegal_first_pdu/main.o $(common_test_OBJS)
+socks5_3_test_LIBS=	$(LIBS)
+
+socks5_4_test_OBJS=	socks5/username_password_auth/main.o $(common_test_OBJS)
+socks5_4_test_LIBS=	$(LIBS)
+
+http_1_test_OBJS=	http/auth_params/main.o $(common_test_OBJS)
+http_1_test_LIBS=	$(LIBS)
+
+http_2_test_OBJS=	http/chunked_encoding/main.o $(common_test_OBJS)
+http_2_test_LIBS=	$(LIBS)
+
+http_3_test_OBJS=	http/connect_data_transfer/main.o $(common_test_OBJS)
+http_3_test_LIBS=	$(LIBS)
+
+http_4_test_OBJS=	http/http_fields/main.o $(common_test_OBJS)
+http_4_test_LIBS=	$(LIBS)
+
+http_5_test_OBJS=	http/illegal_responses/main.o $(common_test_OBJS)
+http_5_test_LIBS=	$(LIBS)
+
+define make_test
+$(1)_test: $$($(1)_test_OBJS)
+# XXX: again, if object file is missing, make(1) will build it, but
+# $^ will contain incorrect path if prerequisite was found via VPATH.
+	$(CXX) $(LDFLAGS) -o $$@ $$(foreach o,$$^,$$(if $$(wildcard \
+		$$o),$$o,$(VPATH)/$$o)) $$($(1)_test_LIBS)
+
+run_$(1)_test: $(1)_test
+# At least one test (local_user_list_data) reads configuration files
+# and expects to be run from the project's top directory.
+	cd .. && tests/$$<
+
+.PHONY: run_$(1)_test
+run_unit_tests: run_$(1)_test
+endef
+
+$(foreach t,$(UNIT_TESTS),$(eval $(call make_test,$(t))))
+
+.PHONY: all install run_unit_tests



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105311940.14VJeaj4067551>