n2n/Makefile.in
Hamish Coleman b735ad6b9e
added test framework and code coverage reporting (#797)
* Add a simple test framework

* Add a code coverage report example oneliner

* Move the coverage report into a separate directory

* Add a github action to run tests and publish a branch with the coverage report

* Fix: Missing job separator

* Fix: remember to actually run configure

* Fix: Gotta autogen before I configure

* Dont try to upload coverage report unless this is a push

* Clearly show the git ref tested in the coverage report

* Add a test for the various transforms

* Add tests for the elliptic curve and pearson hash

* Ensure we ignore new generated output

* Remove unneeded boilerplate from the compression tests

* Add an example of a test of the encoded wire packets

* Ensure that correctly testable data is output even when zstd is not compiled

* Factor test runner out into its own script and attempt to add it to the cmake file

* Tell cmake about a new object file

* Stop trying to make Cmake work...

* Stop trying to make cmake work, round 2

* In the middle of a thousand lines of cmake output was one important one - windows could not find assert() - try again

* Try again to plumb the tests into cmake

* Add missing library to our superset install line

* Fix build error when libcap-dev is installed

* Switch to using artifact uploads instead of pages to store/show the coverage report

* Fix artifact upload yaml

* Upload coverage report to codecov

* Fix codecov - clearly it doesnt do a recursive search for coverage files

* Fix codecov - my hopeful use of a list of directories didnt work

* Fix codecov - unfortunately, it doesnt just consume the coverage data and needs us to generate the gcov output

* Fix codecov - nope, it still doesnt recursively search

* Fix codecov - it really helps if I run the gcov data generator

* Add a simple matrix build

* Fix older ubuntu versions of gcovr that do not support the '--html-title' option

* Ensure we use gcover options that are identical on older ubuntu

* Improve coverage generation and required build packages
2021-09-27 15:26:06 +05:45

171 lines
5.1 KiB
Makefile

# NOTE: these are needed by the configure.in inside the packages folder
N2N_VERSION_SHORT=@N2N_VERSION_SHORT@
GIT_COMMITS=@GIT_COMMITS@
GIT_DESCRIBE=$(shell git describe --always --dirty)
########
CC=@CC@
AR=@AR@
#Ultrasparc64 users experiencing SIGBUS should try the following gcc options
#(thanks to Robert Gibbon)
PLATOPTS_SPARC64=-mcpu=ultrasparc -pipe -fomit-frame-pointer -ffast-math -finline-functions -fweb -frename-registers -mapp-regs
N2N_OBJS_OPT=
CFLAGS=@CFLAGS@ -I ./include
LDFLAGS=@LDFLAGS@ -L .
OPENSSL_CFLAGS=$(shell pkg-config openssl; echo $$?)
ifeq ($(OPENSSL_CFLAGS), 0)
CFLAGS+=$(shell pkg-config --cflags-only-I openssl)
endif
WARN=-Wall
CFLAGS+=$(DEBUG) $(OPTIMIZATION) $(WARN) $(OPTIONS) $(PLATOPTS)
INSTALL=install
MKDIR=mkdir -p
OS := $(shell uname -s)
INSTALL_PROG=$(INSTALL) -m755
INSTALL_DOC=$(INSTALL) -m644
# DESTDIR set in debian make system
PREFIX?=$(DESTDIR)/usr
#BINDIR=$(PREFIX)/bin
ifeq ($(OS),Darwin)
SBINDIR=$(PREFIX)/local/sbin
else
SBINDIR=$(PREFIX)/sbin
endif
MANDIR?=$(PREFIX)/share/man
MAN1DIR=$(MANDIR)/man1
MAN7DIR=$(MANDIR)/man7
MAN8DIR=$(MANDIR)/man8
N2N_LIB=libn2n.a
N2N_OBJS=$(patsubst src/%.c, src/%.o, $(wildcard src/*.c))
N2N_DEPS=$(wildcard include/*.h) $(wildcard src/*.c) Makefile
LDLIBS+=-ln2n
LDLIBS+=@N2N_LIBS@
#For OpenSolaris (Solaris too?)
ifeq ($(shell uname), SunOS)
LDLIBS+=-lsocket -lnsl
endif
APPS=edge
APPS+=supernode
APPS+=example_edge_embed_quick_edge_init
APPS+=example_edge_embed
APPS+=example_sn_embed
DOCS=edge.8.gz supernode.1.gz n2n.7.gz
.PHONY: steps build push all clean install tools test cover gcov build-dep
all: $(APPS) $(DOCS) tools
tools: $(N2N_LIB)
$(MAKE) -C $@
src/edge.o: $(N2N_DEPS)
src/supernode.o: $(N2N_DEPS)
src/example_edge_embed_quick_edge_init.o: $(N2N_DEPS)
src/example_sn_embed.o: $(N2N_DEPS)
src/example_edge_embed.o: $(N2N_DEPS)
src/edge: $(N2N_LIB)
src/supernode: $(N2N_LIB)
src/example_edge_embed_quick_edge_init: $(N2N_LIB)
src/example_sn_embed: $(N2N_LIB)
src/example_edge_embed: $(N2N_LIB)
%: src/%
cp $< $@
%.gz : %
gzip -c $< > $@
$(N2N_LIB): $(N2N_OBJS)
$(AR) rcs $(N2N_LIB) $(N2N_OBJS)
# $(RANLIB) $@
test: tools
tools/test_harness
# To generate coverage information, run configure with
# CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="--coverage"
# and run the desired tests. Ensure that package gcovr is installed
# and then run "make cover"
cover:
mkdir -p coverage
gcovr -s --html --html-details --output=coverage/index.html
# Use coverage data to generate gcov text report files.
# Unfortunately, these end up in the wrong directory due to the
# makefile layout
# The steps to use this are similar to the "make cover" above
gcov:
gcov $(N2N_OBJS)
$(MAKE) -C tools gcov
# This is the superset of all packages that might be needed.
# It is a convinent target to use during development or from a CI/CD system
build-dep:
sudo apt install build-essential autoconf libcap-dev libzstd-dev gcovr
clean:
rm -rf $(N2N_OBJS) $(N2N_LIB) $(APPS) $(DOCS) coverage/ *.dSYM *~
rm -f tests/*.out src/*.gcno src/*.gcda
$(MAKE) -C tools clean
install: edge supernode edge.8.gz supernode.1.gz n2n.7.gz
echo "MANDIR=$(MANDIR)"
$(MKDIR) $(SBINDIR) $(MAN1DIR) $(MAN7DIR) $(MAN8DIR)
$(INSTALL_PROG) supernode $(SBINDIR)/
$(INSTALL_PROG) edge $(SBINDIR)/
$(INSTALL_DOC) edge.8.gz $(MAN8DIR)/
$(INSTALL_DOC) supernode.1.gz $(MAN1DIR)/
$(INSTALL_DOC) n2n.7.gz $(MAN7DIR)/
$(MAKE) -C tools install
# Docker builder section
DOCKER_IMAGE_NAME=ntop/supernode
DOCKER_IMAGE_VERSION=$N2N_VERSION_SHORT
N2N_COMMIT_HASH=@GIT_REVISION@
default: steps
steps:
if [ "$(TARGET_ARCHITECTURE)" = "arm32v7" ] || [ "$(TARGET_ARCHITECTURE)" = "" ]; then DOCKER_IMAGE_FILENAME="Dockerfile.arm32v7" DOCKER_IMAGE_TAGNAME=$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)-arm32v7 make build; fi
if [ "$(TARGET_ARCHITECTURE)" = "x86_64" ] || [ "$(TARGET_ARCHITECTURE)" = "" ]; then DOCKER_IMAGE_FILENAME="Dockerfile.x86_64" DOCKER_IMAGE_TAGNAME=$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)-x86_64 make build; fi
build:
$(eval OS := $(shell uname -s))
$(eval ARCHITECTURE := $(shell export DOCKER_IMAGE_TAGNAME="$(DOCKER_IMAGE_TAGNAME)"; echo $$DOCKER_IMAGE_TAGNAME | grep -oe -.*))
docker build --target builder --build-arg COMMIT_HASH=$(N2N_COMMIT_HASH) -t $(DOCKER_IMAGE_TAGNAME) -f image-platforms/$(DOCKER_IMAGE_FILENAME) .
docker container create --name builder $(DOCKER_IMAGE_TAGNAME)
if [ ! -d "./build" ]; then mkdir ./build; fi
docker container cp builder:/usr/src/n2n/supernode ./build/supernode-$(OS)$(ARCHITECTURE)
docker container cp builder:/usr/src/n2n/edge ./build/edge-$(OS)$(ARCHITECTURE)
docker container rm -f builder
docker build --build-arg COMMIT_HASH=$(N2N_COMMIT_HASH) -t $(DOCKER_IMAGE_TAGNAME) -f image-platforms/$(DOCKER_IMAGE_FILENAME) .
docker tag $(DOCKER_IMAGE_TAGNAME) $(DOCKER_IMAGE_NAME):latest$(ARCHITECTURE)
push:
if [ ! "$(TARGET_ARCHITECTURE)" = "" ]; then \
docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)-$(TARGET_ARCHITECTURE); \
docker push $(DOCKER_IMAGE_NAME):latest-$(TARGET_ARCHITECTURE); \
else \
echo "Please pass TARGET_ARCHITECTURE, see README.md."; \
fi
# End Docker builder section