From f30eba63cb3f5e3aa5d81d6b31d1ba2fdee1e5c4 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 3 Jan 2023 14:31:49 +0100 Subject: Add test coverage info --- Makefile | 8 +++++--- common.mk | 13 ++++++++++++ debian/control | 2 +- tests/Makefile | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index cc79b02..d9b55db 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ PLUGINS= \ webbox \ weblog -CXXFLAGS+=-fPIE -DVERSION=\"$(VERSION)\" +CXXFLAGS+=-fPIE LDLIBS+=\ -lreichwein \ @@ -58,8 +58,7 @@ all: build $(PROJECTNAME): $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ -$(PLUGINS): - cd plugins/$@ && $(MAKE) +dep: $(SRC:.cpp=.d) %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< @@ -67,6 +66,9 @@ $(PLUGINS): %.o: %.cpp %.d $(CXX) $(CXXFLAGS) -c $< -o $@ +$(PLUGINS): + cd plugins/$@ && $(MAKE) + # dependencies ADD_DEP=Makefile diff --git a/common.mk b/common.mk index badfc9d..9f1d074 100644 --- a/common.mk +++ b/common.mk @@ -73,17 +73,30 @@ LIBS+= \ #-lc++abi #-lc++fs #-lstdc++fs +LLVMPROFDATA=llvm-profdata-11 +LLVMCOV=llvm-cov-11 +CXXTYPE=clang++ else ifeq ($(CXX),clang++-14) LIBS+= \ -fuse-ld=lld-14 \ -lstdc++ +LLVMPROFDATA=llvm-profdata-14 +LLVMCOV=llvm-cov-14 +CXXTYPE=clang++ else ifeq ($(CXX),clang++-13) LIBS+= \ -fuse-ld=lld-13 \ -lstdc++ +LLVMPROFDATA=llvm-profdata-13 +LLVMCOV=llvm-cov-13 +CXXTYPE=clang++ else LIBS+= \ -lstdc++ \ -lstdc++fs +CXXTYPE=g++ endif +SRC_ROOT=$(shell echo $(MAKEFILE_LIST) | tr " " "\n" | grep common.mk | sed -e 's/\([^ ]*\)common.mk/\1/g') +VERSION=$(shell dpkg-parsechangelog --show-field Version --file $(SRC_ROOT)/debian/changelog) +CXXFLAGS+=-DVERSION=\"$(VERSION)\" diff --git a/debian/control b/debian/control index 8a0a9fd..a48c5df 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: webserver Section: httpd Priority: optional Maintainer: Roland Reichwein -Build-Depends: debhelper (>= 12), libssl-dev, libboost-all-dev | libboost1.71-all-dev, clang-13 | clang-11 | clang | g++-11 | g++, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libreichwein-dev +Build-Depends: debhelper (>= 12), libssl-dev, libboost-all-dev | libboost1.71-all-dev, clang | g++, llvm | g++, lld | g++, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libreichwein-dev, gcovr Standards-Version: 4.5.0 Homepage: http://www.reichwein.it/webserver/ diff --git a/tests/Makefile b/tests/Makefile index d4c53cb..338800a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,7 +1,18 @@ +CXXFLAGS=-g -O0 + include ../common.mk PROJECTNAME=test-webserver +ifeq ($(CXXTYPE),clang++) +CXXFLAGS+=-fprofile-instr-generate -fcoverage-mapping +LDFLAGS+=-fprofile-instr-generate -fcoverage-mapping +else +# GCC +CXXFLAGS+=--coverage +LDFLAGS+=--coverage +endif + CXXFLAGS+= -I. -fPIE CXXTESTFLAGS= @@ -19,15 +30,36 @@ LIBS=\ LDFLAGS+=-pie +UNITS=\ + auth.cpp \ + base64.cpp \ + config.cpp \ + http.cpp \ + https.cpp \ + os.cpp \ + plugin.cpp \ + privileges.cpp \ + response.cpp \ + statistics.cpp \ + server.cpp \ + webserver.cpp + TESTSRC=\ test-environment.cpp \ test-webserver.cpp \ $(PROGSRC) build: $(PROJECTNAME) +ifeq ($(CXXTYPE),clang++) + LLVM_PROFILE_FILE="$(PROJECTNAME).profraw" ./$(PROJECTNAME) + $(LLVMPROFDATA) merge -sparse $(PROJECTNAME).profraw -o $(PROJECTNAME).profdata + $(LLVMCOV) report --ignore-filename-regex='google' --ignore-filename-regex='test-' --show-region-summary=0 -instr-profile $(PROJECTNAME).profdata $(PROJECTNAME) +else ./$(PROJECTNAME) + gcovr -r .. +endif -$(PROJECTNAME): $(TESTSRC:.cpp=.o) +$(PROJECTNAME): $(TESTSRC:.cpp=.o) $(UNITS:.cpp=.o) $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ dep: $(TESTSRC:.cpp=.d) @@ -38,10 +70,37 @@ dep: $(TESTSRC:.cpp=.d) %.o: %.cpp %.d $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +auth.o: ../auth.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +base64.o: ../base64.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +config.o: ../config.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +http.o: ../http.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +https.o: ../https.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +os.o: ../os.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +plugin.o: ../plugin.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +privileges.o: ../privileges.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +response.o: ../response.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +statistics.o: ../statistics.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +server.o: ../server.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ +webserver.o: ../webserver.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + +ADD_DEP=Makefile + # misc --------------------------------------------------- clean: - -rm -f *.o *.a *.d $(PROJECTNAME) + -rm -f *.o *.a *.d $(PROJECTNAME) *.gcda *.gcno *.profraw *.profdata *.gcov .PHONY: clean all install -- cgit v1.2.3