]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Enable Test Coverage Visualization for merge requests
authorMichal Nowak <mnowak@isc.org>
Thu, 22 Oct 2020 07:36:17 +0000 (09:36 +0200)
committerMichal Nowak <mnowak@isc.org>
Tue, 27 Oct 2020 14:57:06 +0000 (15:57 +0100)
This feature allows GitLab to visualize test coverage information in the
file diff view of merge requests.

This commit makes the gcov CI job depend on the following chain of jobs:

    gcc:buster:amd64 → unit:gcc:buster:amd64 → system:gcc:buster:amd64

The reason for running the last two jobs above sequentially rather than
in parallel is that both of them create *.gcda files (containing
coverage data) in the same locations.  While some way of merging these
files from different job artifact archives could probably be designed
with the help of additional tools, the simplest thing to do is not to
run unit test and system test jobs in parallel, carrying *.gcda files
over between jobs as gcov knows how to append coverage data to existing
*.gcda files.

Also note that test coverage will not be visualized if any of the jobs
in the above dependency chain fails (because the gcov job will not be
run).

(cherry picked from commit 2dabf328c406036e012a9b0b30ed952785565d51)

.gitlab-ci.yml

index 2b79dd9a697642710755cfcd84d12620f5ede35a..7018b2870ac369466f97bebe6b82b31dd5240134 100644 (file)
@@ -289,6 +289,13 @@ stages:
     expire_in: "1 day"
     when: on_failure
 
+.system_test_gcov: &system_test_gcov_job
+  <<: *system_test_common
+  artifacts:
+    untracked: true
+    expire_in: "1 day"
+    when: always
+
 .system_test_tsan: &system_test_tsan_job
   <<: *system_test_common
   allow_failure: true
@@ -347,6 +354,13 @@ stages:
     expire_in: "1 day"
     when: on_failure
 
+.unit_test_gcov: &unit_test_gcov_job
+  <<: *unit_test_common
+  artifacts:
+    untracked: true
+    expire_in: "1 day"
+    when: always
+
 .unit_test_tsan: &unit_test_tsan_job
   <<: *unit_test_common
   after_script:
@@ -662,20 +676,22 @@ unit:gcc:stretch:amd64:
 gcc:buster:amd64:
   variables:
     CC: gcc
-    CFLAGS: "${CFLAGS_COMMON}"
+    CFLAGS: "${CFLAGS_COMMON} --coverage -O0"
+    LDFLAGS: "--coverage"
+    EXTRA_CONFIGURE: "--enable-dnstap --with-libidn2"
   <<: *debian_buster_amd64_image
   <<: *build_job
 
 system:gcc:buster:amd64:
   <<: *debian_buster_amd64_image
-  <<: *system_test_job
+  <<: *system_test_gcov_job
   needs:
-    - job: gcc:buster:amd64
+    - job: unit:gcc:buster:amd64
       artifacts: true
 
 unit:gcc:buster:amd64:
   <<: *debian_buster_amd64_image
-  <<: *unit_test_job
+  <<: *unit_test_gcov_job
   needs:
     - job: gcc:buster:amd64
       artifacts: true
@@ -1502,22 +1518,12 @@ abi-check:
 
 gcov:
   <<: *base_image
-  stage: build
+  <<: *default_triggering_rules
+  stage: postcheck
   needs:
-    - job: autoreconf
+    - job: system:gcc:buster:amd64
       artifacts: true
-  variables:
-    CC: gcc
-    CFLAGS: "${CFLAGS_COMMON} --coverage -O0"
-    LDFLAGS: "--coverage"
-    EXTRA_CONFIGURE: "--enable-dnstap --with-libidn2"
   script:
-    - *configure
-    - *setup_interfaces
-    - *setup_softhsm
-    - make -j${BUILD_PARALLEL_JOBS:-1} -k all V=1
-    - make -k unit || true
-    - make -C bin/tests/system -j${TEST_PARALLEL_JOBS:-1} -k test V=1 || true
     # *.gcno and *.gcda files generated for shared library objects are created
     # in directories in which gcovr is unable to process them properly
     # (.../.libs/...).  Move such *.gcno and *.gcda files one level higher.
@@ -1528,15 +1534,20 @@ gcov:
     # These drivers are built into bin/named/named in a way which trips up
     # gcovr.  Copy them to where gcovr expects them.
     - cp contrib/dlz/drivers/dlz_drivers.c contrib/dlz/drivers/dlz_filesystem_driver.c contrib/dlz/drivers/sdlz_helper.c bin/named/
+    # Generate XML file in the Cobertura XML format suitable for use by GitLab
+    # for the purpose of displaying code coverage information in the diff view
+    # of a given merge request.
+    - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories libltdl --exclude-directories lib/samples --exclude 'lib/.*/tests/.*' --xml -o coverage.xml
     - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories libltdl --exclude-directories lib/samples --exclude 'lib/.*/tests/.*' --html-details -o coverage.html
     - gcovr --root . --exclude-directories bin/tests --exclude-directories doc --exclude-directories libltdl --exclude-directories lib/samples --exclude 'lib/.*/tests/.*' -o coverage.txt
     - tail -n 3 coverage.txt
   artifacts:
     paths:
       - coverage*.html
-  only:
-    - main@isc-projects/bind9
-    - /^v9_[1-9][0-9]$/@isc-projects/bind9
+      - coverage.txt
+      - coverage.xml
+    reports:
+      cobertura: coverage.xml
 
 # Pairwise testing of ./configure options