Skip to content

eBPF-based security platform

ci: reuse the VM build image for guest coverage

Andrea Lattuada2e517ec2335b
diff --git a/.github/scripts/coverage.sh b/.github/scripts/coverage.sh
index fccadfee..92ea7268 100755
--- a/.github/scripts/coverage.sh
+++ b/.github/scripts/coverage.sh
@@ -6,7 +6,7 @@
# write coverage/shirudo.lcov from the counters of the host's binaries
# and, where the test VMs ran, of the target in each guest.
#
-# .github/scripts/coverage.sh
+# .github/scripts/coverage.sh [--sudo-container]
set -eu
@@ -77,14 +77,26 @@ if [ "${1:-}" = target ]; then
exit 0
fi
+sudo_container=${1:-}
+
+capture_guest() {
+ set -- testing/container/run.sh -v "$PWD/coverage" -- \
+ "$PWD/.github/scripts/coverage.sh" target "$1"
+ if [ "$sudo_container" = --sudo-container ]; then
+ set -- sudo "$@"
+ fi
+ # Keep the tracefile owned by the caller even if the container runs as root.
+ : >coverage/target.lcov
+ "$@"
+}
+
capture gcno --initial --output-file coverage/baseline.lcov
capture gcda --output-file coverage/run.lcov
set -- --add-tracefile coverage/baseline.lcov --add-tracefile coverage/run.lcov
for bundle in build/test-vm/host-bundle-*; do
[ -d "$bundle/coverage" ] || continue
- testing/container/run.sh -v "$PWD/coverage" -- \
- "$PWD/.github/scripts/coverage.sh" target "$PWD/$bundle"
+ capture_guest "$PWD/$bundle"
set -- "$@" --add-tracefile coverage/target.lcov
break
done
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index 402a24b7..c3ac2669 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -95,7 +95,7 @@ jobs:
- name: Merge the counters of the host and the guests
id: collect
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
- run: .github/scripts/coverage.sh
+ run: .github/scripts/coverage.sh --sudo-container
- name: Upload coverage to Coveralls
if: ${{ !cancelled() && steps.collect.outcome == 'success' }}
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index c58dbcf9..f292bf61 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -105,6 +105,9 @@ them in ``build/test-vm/coverage/``. :src:`.github/scripts/coverage.sh`
reads them in the build container, whose gcov matches the compiler of the
target, and merges them with the host's.
+If the tests ran under ``sudo``, pass ``--sudo-container`` to
+``coverage.sh`` to reuse root's build image for guest coverage.
+
The report leaves out test code, vendored code and BPF programs, and counts
nothing for a process that is killed, as the loads that ``t6143`` and
``t6144`` interrupt are, since gcov writes its counters at exit.