]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
CI: Add coverage CI target to parse code coverage and display it in MRs
authorMarek Vavruša <mvavrusa@cloudflare.com>
Sun, 26 Nov 2017 01:05:08 +0000 (17:05 -0800)
committerPetr Špaček <petr.spacek@nic.cz>
Tue, 28 Nov 2017 10:23:05 +0000 (11:23 +0100)
.gitlab-ci.yml
Makefile
config.mk
platform.mk

index 0abd53ccb7f3bf8f8346870ff75f0898a618ec9b..c19cc3ed717cf5f2cb77baf082fc287e046ae9d3 100644 (file)
@@ -4,6 +4,7 @@ variables:
   DEBIAN_FRONTEND: noninteractive
   LC_ALL: C.UTF-8
   GIT_SUBMODULE_STRATEGY: recursive
+  COVERAGE: '1'
 
 build:linux:amd64:
   stage: build
@@ -29,8 +30,13 @@ test:linux:amd64:
   stage: test
   script:
     - PREFIX=$(pwd)/.local make -k check
+    - make coverage-c COVERAGE_STAGE=gcov-check
   dependencies:
     - build:linux:amd64
+  artifacts:
+    expire_in: 1 hour
+    paths:
+      - ./*.info
   tags:
     - docker
     - linux
@@ -40,8 +46,13 @@ installcheck:linux:amd64:
   stage: test
   script:
     - PREFIX=$(pwd)/.local make -k installcheck
+    - make coverage-c coverage-lua COVERAGE_STAGE=gcov-installcheck
   dependencies:
     - build:linux:amd64
+  artifacts:
+    expire_in: 1 hour
+    paths:
+      - ./*.info
   tags:
     - docker
     - linux
@@ -51,8 +62,13 @@ deckard:linux:amd64:
   stage: test
   script:
     - PREFIX=$(pwd)/.local MAKEFLAGS="--jobs $(nproc) --keep-going" make check-integration
+    - make coverage-c coverage-lua COVERAGE_STAGE=gcov-deckard
   dependencies:
     - build:linux:amd64
+  artifacts:
+    expire_in: 1 hour
+    paths:
+      - ./*.info
   tags:
     - docker
     - linux
@@ -128,6 +144,20 @@ respdiff:linux:amd64:
     - linux
     - amd64
 
+coverage:linux:amd64:
+  stage: deploy
+  script:
+    - make coverage
+  coverage: '/lines\.+:\s(\d+.\d+\%)/'
+  dependencies:
+    - test:linux:amd64
+    - installcheck:linux:amd64
+    - deckard:linux:amd64
+  tags:
+    - docker
+    - linux
+    - amd64
+
 #arm_build:
 #  image: cznic/armhf-ubuntu:16.04
 #  stage: build
index d0381193afa871b0670a7ad530d6653b9985c89b..40f47bbf4445c5db6b9b991a6bb8a02a9e7460dc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,17 +10,14 @@ clean: contrib-clean lib-clean daemon-clean client-clean modules-clean \
 doc: doc-html
 lint: $(patsubst %.lua.in,%.lua,$(wildcard */*/*.lua.in))
        luacheck --codes --formatter TAP .
-coverage: $(wildcard */*/luacov.stats.out)
-       @echo "# C coverage in gcov.c.info"
-       @lcov --no-external --capture --directory . --output-file gcov.c.info > /dev/null
-       @if [ ! -z "$^" ]; then \
-               echo "# Lua coverage in luacov.stats.out and gcov.lua.info"; \
-               cat $^ > luacov.stats.out; \
-               ./scripts/luacov_to_info.lua $^ > gcov.lua.info; \
-               lcov --add-tracefile gcov.c.info --add-tracefile gcov.lua.info --output-file gcov.total.info; \
-       else \
-               lcov --add-tracefile gcov.c.info --output-file gcov.total.info; \
-       fi
+coverage-c:
+       @echo "# C coverage in $(COVERAGE_STAGE).c.info"
+       @$(LCOV) --no-external --capture --directory . --output-file $(COVERAGE_STAGE).c.info > /dev/null
+coverage-lua: $(wildcard */*/luacov.stats.out)
+       @echo "# Lua coverage in $(COVERAGE_STAGE).lua.info"
+       @if [ ! -z "$^" ]; then ./scripts/luacov_to_info.lua $^ > $(COVERAGE_STAGE).lua.info; fi
+coverage:
+       @$(LCOV) $(addprefix --add-tracefile ,$(wildcard $(COVERAGE_STAGE)*.info)) --output-file coverage.info
 
 .PHONY: all install check clean doc info
 
index 040b09670f34f4c64793ccec865695ca1ffcb73c..9b7930bcb64e09b1d4797faf98701729974a4c94 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -20,6 +20,7 @@ INCLUDEDIR ?= $(PREFIX)/include
 MODULEDIR ?= $(LIBDIR)/kdns_modules
 ETCDIR ?= $(PREFIX)/etc/kresd
 ROOTHINTS ?= $(ETCDIR)/root.hints
+COVERAGE_STAGE ?= gcov
 
 # Tools
 CC      ?= cc
index 03669a131585f1fa8a29d670cc41144df1c4c025..6df6ee9eddb2b5ab90655a032d2fc6dca03e678f 100644 (file)
@@ -8,6 +8,7 @@ CGO := go tool cgo
 GO := go
 CAT := cat
 SED := sed
+LCOV := lcov
 LIBEXT := .so
 AREXT  := .a
 LIBTYPE := shared