Skip to content

eBPF-based security platform

ci: run the target suite in the test VM

Puranjay Mohand017c895d0cb
diff --git a/.github/scripts/target-tests.sh b/.github/scripts/target-tests.sh
new file mode 100755
index 00000000..f7cc0fbb
--- /dev/null
+++ b/.github/scripts/target-tests.sh
@@ -0,0 +1,123 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# .github/scripts/target-tests.sh -- run the target suite in the test VM as
+# make -C testing test-tgt does on a developer's host. setup makes the
+# runner the VM host: KVM, the VM's packages, the bpf-next kernel unless a
+# restored copy is current, and the OpenSSL 3.5 toolchain from
+# vm-toolchain.sh. staging runs the suite as is, production boots the
+# guest from a dracut initrd.
+#
+# .github/scripts/target-tests.sh setup|staging|production
+#
+# Runs as a user with passwordless sudo, from the checkout.
+
+set -eu
+
+cd "$(git rev-parse --show-toplevel)"
+
+kernel=artifacts/bpf-next-kernel-debs
+
+# What the job log alone does not show: refusals by AppArmor, the passt
+# helper libguestfs networks its appliance through, and, for each guest
+# that did not pass, what it and the suites in it printed.
+diagnose() {
+ echo '::group::Diagnostics'
+ sudo dmesg | grep 'apparmor="DENIED"' | tail -n 20 || :
+ sudo journalctl -b --no-pager -t passt | tail -n 20 || :
+ for vm in build/test-vm/vms/*; do
+ [ "$(cat "$vm/result/status" 2>/dev/null)" != 0 ] || continue
+ for log in "$vm/result/guest.log" "$vm/console.log"; do
+ [ -f "$log" ] || continue
+ echo "== $log"
+ cat "$log"
+ done
+ done
+ echo '::endgroup::'
+}
+
+# The production run leaves root's files behind; the caches need them.
+finish() {
+ status=$?
+ sudo chown -R "$(id -u):$(id -g)" artifacts build 2>/dev/null || :
+ [ "$status" -eq 0 ] || diagnose
+ exit "$status"
+}
+
+setup() {
+ sudo rm -rf /opt/ghc /usr/local/lib/android /usr/share/dotnet
+
+ # /dev/kvm belongs to root on the runner.
+ echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' |
+ sudo tee /etc/udev/rules.d/99-kvm.rules >/dev/null
+ sudo udevadm control --reload-rules
+ sudo udevadm trigger --name-match=kvm
+
+ # A restored kernel is older than the checkout of the script that
+ # built it.
+ if [ -s "$kernel/bzImage.sha256sum" ]; then
+ touch "$kernel/bzImage.sha256sum"
+ fi
+ make -C testing kernel
+
+ mkdir -p build
+ sudo BPF_VMLINUX_BTF="$PWD/$kernel/vmlinux.btf" \
+ .github/scripts/vm-toolchain.sh \
+ autoconf autoconf-archive automake clang-20 cloud-image-utils \
+ dracut-core file isc-dhcp-client libguestfs-tools libltdl-dev \
+ libtool libzstd-dev qemu-system-x86 qemu-utils swtpm \
+ swtpm-tools tpm2-tools
+
+ # Ubuntu 24.04's clang 18 lacks the BPF address-space casts the
+ # arena upatches need, and shirudo-build runs /usr/bin/clang.
+ sudo ln -sf clang-20 /usr/bin/clang
+
+ # Ubuntu's dracut 060 looks for systemd-pcrphase, which systemd 255
+ # calls systemd-pcrextend, and so leaves out the PCR phase
+ # measurement shirudo's initrd needs.
+ if [ ! -e /usr/lib/systemd/systemd-pcrphase ]; then
+ sudo ln -s systemd-pcrextend /usr/lib/systemd/systemd-pcrphase
+ fi
+
+ # libguestfs networks the appliance through passt. Ubuntu's AppArmor
+ # profile for passt refuses the socket libguestfs asks for under
+ # XDG_RUNTIME_DIR, and without that profile Ubuntu's restriction of
+ # unprivileged user namespaces keeps passt from sandboxing itself.
+ # The runner is discarded after the job, so lift both.
+ apparmor=/sys/kernel/security/apparmor
+ if sudo grep -q '^passt ' "$apparmor/profiles" 2>/dev/null; then
+ printf passt | sudo tee "$apparmor/.remove" >/dev/null
+ fi
+ if [ -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
+ sudo sysctl -q -w kernel.apparmor_restrict_unprivileged_userns=0
+ fi
+}
+
+case "${1:-}" in
+setup|staging|production) ;;
+*)
+ echo "usage: $0 setup|staging|production" >&2
+ exit 2
+ ;;
+esac
+
+trap finish EXIT
+
+if [ "$1" = setup ]; then
+ setup
+ exit 0
+fi
+
+# shellcheck source=/dev/null
+. build/vm-toolchain.env
+
+# A guest that boots runs the suite in minutes; one that hangs, in
+# emergency mode for instance, would otherwise hold the job for an hour.
+export TEST_VM_TIMEOUT=900
+
+if [ "$1" = staging ]; then
+ make -C testing test-tgt
+else
+ sudo -E env PATH="$PATH" make -C testing test-tgt TEST_VM_INITRD=1
+fi
diff --git a/.github/workflows/target-tests.yml b/.github/workflows/target-tests.yml
new file mode 100644
index 00000000..f8aa5ab2
--- /dev/null
+++ b/.github/workflows/target-tests.yml
@@ -0,0 +1,90 @@
+name: Target tests
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+# A new push to the pull request supersedes the run in progress.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ test-tgt:
+ name: Target suite in the test VM, staging and production
+ runs-on: ubuntu-latest
+ timeout-minutes: 150
+
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v4
+
+ # bpf-next moves daily; a week-old kernel still tests the tree, and
+ # building one takes most of the run.
+ - name: Name the kernel cache week
+ id: week
+ run: echo "week=$(date -u +%G-W%V)" >> "$GITHUB_OUTPUT"
+
+ - name: Restore the bpf-next kernel
+ id: kernel
+ uses: actions/cache/restore@v4
+ with:
+ path: artifacts/bpf-next-kernel-debs
+ key: test-vm-kernel-${{ steps.week.outputs.week }}-${{ hashFiles('contrib/build-kernel-package.sh', 'contrib/test-vm-arch.sh') }}
+
+ - name: Restore the static target dependencies
+ id: target-deps
+ uses: actions/cache/restore@v4
+ with:
+ path: build/target-deps
+ key: target-deps-${{ hashFiles('Makefile.target-deps') }}
+
+ - name: Restore the VM images
+ id: images
+ uses: actions/cache/restore@v4
+ with:
+ path: build/test-vm/cache
+ key: test-vm-images-${{ hashFiles('contrib/test-vm-runtime-packages', 'contrib/prepare-test-vm-runtime.sh', 'contrib/build-test-vm-bundle.sh', 'contrib/test-vm-arch.sh') }}
+
+ - name: Prepare the runner as the VM host
+ run: .github/scripts/target-tests.sh setup
+
+ - name: Run the target suite in the staging configuration
+ run: .github/scripts/target-tests.sh staging
+
+ # Every unit with a private mount namespace fails after switch-root
+ # since d2ffd16 ("bpf: refuse unmounting any mount above the
+ # private bpffs"); the step reports without failing the job until
+ # that is fixed.
+ - name: Run the target suite in the production configuration
+ continue-on-error: true
+ run: .github/scripts/target-tests.sh production
+
+ # Each part is saved once it is complete, even when a later step
+ # fails, so that the next run does not build it again.
+ - name: Save the bpf-next kernel
+ if: always() && steps.kernel.outputs.cache-hit != 'true' && hashFiles('artifacts/bpf-next-kernel-debs/bzImage.sha256sum') != ''
+ uses: actions/cache/save@v4
+ with:
+ path: artifacts/bpf-next-kernel-debs
+ key: ${{ steps.kernel.outputs.cache-primary-key }}
+
+ - name: Save the static target dependencies
+ if: always() && steps.target-deps.outputs.cache-hit != 'true' && hashFiles('build/target-deps/lib/libcrypto.a') != '' && hashFiles('build/target-deps/curl/lib/libcurl.a') != ''
+ uses: actions/cache/save@v4
+ with:
+ path: build/target-deps
+ key: ${{ steps.target-deps.outputs.cache-primary-key }}
+
+ - name: Save the VM images
+ if: always() && steps.images.outputs.cache-hit != 'true' && hashFiles('build/test-vm/cache/runtime/*.qcow2') != ''
+ uses: actions/cache/save@v4
+ with:
+ path: build/test-vm/cache
+ key: ${{ steps.images.outputs.cache-primary-key }}
diff --git a/AGENTS.md b/AGENTS.md
index 4b62eb99..7da43439 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -323,7 +323,8 @@ one usually still compiles and passes tests.
UBSan (CI does too); `make -C testing test-tgt` runs the target suite in the
QEMU/swtpm VM (`make -C testing help` lists the VM target groups).
- `make -C testing test-tgt TEST_VM_INITRD=1` boots the guest from a dracut initrd
- that runs `shirudo-initrd.service`; `make -C testing test-installer` runs
+ that runs `shirudo-initrd.service`; CI runs `test-tgt` both ways through
+ `.github/scripts/target-tests.sh`. `make -C testing test-installer` runs
`testing/t1300-installer-e2e.sh`, the installer end to end in a QEMU
guest with a vTPM, two reboots included.
- `make -C testing fuzz [FUZZ_SECONDS=60]` runs the libFuzzer targets in
diff --git a/Documentation/contributing.rst b/Documentation/contributing.rst
index c15639bf..fe0dbe00 100644
--- a/Documentation/contributing.rst
+++ b/Documentation/contributing.rst
@@ -201,7 +201,8 @@ Before sending
* Build both profiles and the helper (``make``, ``make shirudo-build``)
and run ``make -C testing test-op``; run ``make -C testing test-tgt`` when the change
- touches target-side behaviour. Run the host-side suite once more
+ touches target-side behaviour. CI runs the target suite in both
+ configurations as the ``Target tests`` check. Run the host-side suite once more
with ``make -C testing SANITIZE=address,undefined test-op`` when the change
touches memory handling or binary formats; CI runs the same sweep.
* Run ``make -C Documentation html-docs`` when the change touches ``Documentation/``;