[libsoup] Enable code coverage analysis and reporting



commit 194299d65eb4ff696064ad2ad1126512a9180854
Author: Diego Pino Garcia <dpino igalia com>
Date:   Tue Jul 28 11:26:26 2020 +0200

    Enable code coverage analysis and reporting

 .gitlab-ci.yml                | 30 +++++++++++++++++++++++++++++-
 .gitlab-ci/coverage-docker.sh | 33 +++++++++++++++++++++++++++++++++
 .gitlab-ci/fixup-cov-paths.py | 29 +++++++++++++++++++++++++++++
 .gitlab-ci/lcovrc             | 13 +++++++++++++
 4 files changed, 104 insertions(+), 1 deletion(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3a4312bc..8165e9fb 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,11 @@
 image: registry.gitlab.gnome.org/gnome/libsoup/master:v5
 
+stages:
+  - build
+  - coverage
+
 .build:
+  stage: build
   tags:
     # We need runners supporting IPv6:
     # https://gitlab.gnome.org/Infrastructure/GitLab/issues/313
@@ -8,11 +13,34 @@ image: registry.gitlab.gnome.org/gnome/libsoup/master:v5
 
 fedora-meson-x86_64:
   extends: .build
+  variables:
+    CFLAGS: "-coverage -ftest-coverage -fprofile-arcs"
   script:
     - meson _build -Dauto_features=enabled
     - ninja -C _build
+    - mkdir -p _coverage
+    - lcov --config-file .gitlab-ci/lcovrc --directory _build --capture --initial --output-file 
"_coverage/${CI_JOB_NAME}-baseline.lcov"
     - ninja -C _build test
+    - lcov --config-file .gitlab-ci/lcovrc --directory _build --capture --output-file 
"_coverage/${CI_JOB_NAME}.lcov"
   artifacts:
+    reports:
+      junit: "_build/${CI_JOB_NAME}-report.xml"
+    name: "libsoup-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}"
+    when: always
     paths:
+      - "_build/config.h"
       - "_build/meson-logs"
-    when: on_failure
+      - "_build/${CI_JOB_NAME}-report.xml"
+      - "_coverage"
+
+coverage:
+  stage: coverage
+  except:
+    - tags
+  artifacts:
+    name: "libsoup-${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}"
+    paths:
+      - _coverage/
+  script:
+    - bash -x ./.gitlab-ci/coverage-docker.sh
+  coverage: '/^\s+lines\.+:\s+([\d.]+\%)\s+/'
diff --git a/.gitlab-ci/coverage-docker.sh b/.gitlab-ci/coverage-docker.sh
new file mode 100644
index 00000000..9e9487d7
--- /dev/null
+++ b/.gitlab-ci/coverage-docker.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+set -e
+
+# Fixup Windows paths
+lcov_paths=$(find _coverage -name "*.lcov" -print)
+python3 ./.gitlab-ci/fixup-cov-paths.py ${lcov_paths}
+
+for path in _coverage/*.lcov; do
+    # Remove coverage from generated code in the build directory
+    lcov --config-file .gitlab-ci/lcovrc -r "${path}" '*/_build/*' -o "$(pwd)/${path}"
+    # Remove any coverage from system files
+    lcov --config-file .gitlab-ci/lcovrc -e "${path}" "$(pwd)/*" -o "$(pwd)/${path}"
+done
+
+genhtml \
+    --ignore-errors=source \
+    --config-file .gitlab-ci/lcovrc \
+    _coverage/*.lcov \
+    -o _coverage/coverage
+
+cd _coverage
+rm -f *.lcov
+
+cat >index.html <<EOL
+<html>
+<body>
+<ul>
+<li><a href="coverage/index.html">Coverage</a></li>
+</ul>
+</body>
+</html>
+EOL
diff --git a/.gitlab-ci/fixup-cov-paths.py b/.gitlab-ci/fixup-cov-paths.py
new file mode 100644
index 00000000..83190058
--- /dev/null
+++ b/.gitlab-ci/fixup-cov-paths.py
@@ -0,0 +1,29 @@
+import sys
+import os
+import io
+
+
+def main(argv):
+    # Fix paths in lcov files generated on a Windows host so they match our
+    # current source layout.
+    paths = argv[1:]
+
+    for path in paths:
+        print("cov-fixup:", path)
+        text = io.open(path, "r", encoding="utf-8").read()
+        text = text.replace("\\\\", "/")
+        libsoup_dir = "/libsoup/"
+        end = text.index(libsoup_dir)
+        start = text[:end].rindex(":") + 1
+        old_root = text[start:end]
+        assert os.path.basename(os.getcwd()) == "libsoup"
+        new_root = os.path.dirname(os.getcwd())
+        if old_root != new_root:
+            print("replacing %r with %r" % (old_root, new_root))
+        text = text.replace(old_root, new_root)
+        with io.open(path, "w", encoding="utf-8") as h:
+            h.write(text)
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))
diff --git a/.gitlab-ci/lcovrc b/.gitlab-ci/lcovrc
new file mode 100644
index 00000000..ac5997b7
--- /dev/null
+++ b/.gitlab-ci/lcovrc
@@ -0,0 +1,13 @@
+# lcov and genhtml configuration
+# See http://ltp.sourceforge.net/coverage/lcov/lcovrc.5.php
+
+# Always enable branch coverage
+lcov_branch_coverage = 1
+
+# Exclude precondition assertions, as we can never reasonably get full branch
+# coverage of them, as they should never normally fail.
+# See https://github.com/linux-test-project/lcov/issues/44
+lcov_excl_br_line = LCOV_EXCL_BR_LINE|g_return_if_fail|g_return_val_if_fail|g_assert|g_assert_
+
+# Similarly for unreachable assertions.
+lcov_excl_line = LCOV_EXCL_LINE|g_return_if_reached|g_return_val_if_reached|g_assert_not_reached


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]