coverage_vms.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env bash
  2. # The coverage of what only runs in a VM: Gala (PantheonShell, the XWayland fallback), the Flatpak sandbox (HostWayland),
  3. # real DPMS and the other compositors of the VM matrix. The VMs run a coverage build of the portable release, made in the
  4. # Debian 12 rootfs under proot (GCC 12, glibc 2.35 like the release) whose launcher exports GCOV_PREFIX, so the profile data
  5. # lands in /tmp/lwe-gcov of the guest; release_check.sh copies it out (COLLECT_GCOV). The host's gcov (newer GCC) cannot read
  6. # that data and gcovr drops some of those files: tools/analysis/gcov12_report.py runs the rootfs's own gcov and reads its text output. A report of the VM runs is merged with the
  7. # host's (tools/analysis/merge_coverage.py): only lines the host build knows count, GCC 12 splits constructors and inlined
  8. # code differently from GCC 16, so a file's gain in a file that also runs on the host is not a VM-only gain.
  9. # Usage: tools/analysis/coverage_vms.sh <stage> [out dir]
  10. # build configure and build in the rootfs (build dir ~/.local/share/distro-rootfs/build-deb12-cov), package, candidate
  11. # run release_check.sh lanes (VMS="elementary debian-xfce fedora-kde arch-hypr"), arch-hypr also runs the Flatpak step
  12. # with FLATPAK_BUNDLE (a we_manager .flatpak)
  13. # report line counts of the collected data, merged with the host's report (build-cov must be a finished coverage run)
  14. set -uo pipefail
  15. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
  16. stage=${1:?build|run|report}
  17. OUT=${2:-$HOME/.cache/lwe-analysis/coverage-vms}
  18. B=$HOME/.local/share/distro-rootfs/build-deb12-cov
  19. ROOTFS=$HOME/.local/share/distro-rootfs/debian-12
  20. export PROOT=${PROOT:-$HOME/.local/share/arch-proot/proot}
  21. mkdir -p "$OUT"
  22. case $stage in
  23. build)
  24. mkdir -p "$B/out"
  25. [ -d "$B/cef" ] || cp -a "$HOME/.local/share/distro-rootfs/build-deb12/cef" "$B/cef"
  26. cat > "$B/build.sh" <<'EOS'
  27. #!/bin/bash
  28. set -e
  29. cmake -S /src -B /build -DCMAKE_BUILD_TYPE=Release -DDISABLE_KDE_FEATURES=OFF -DBUILD_TESTING=0 \
  30. "-DCMAKE_CXX_FLAGS=--coverage -U_FORTIFY_SOURCE -ffile-prefix-map=/src=/workspace/linux-wallpaperengine-kde" \
  31. "-DCMAKE_C_FLAGS=--coverage -ffile-prefix-map=/src=/workspace/linux-wallpaperengine-kde" \
  32. -DCMAKE_EXE_LINKER_FLAGS=--coverage -DCMAKE_SHARED_LINKER_FLAGS=--coverage > /build/configure.log 2>&1
  33. cmake --build /build --parallel 14 > /build/build.log 2>&1
  34. cd /src && tools/package_release.sh --portable /build lwe-cov /build/out
  35. EOS
  36. chmod +x "$B/build.sh"
  37. BINDS="-b $HERE:/src -b $B:/build" "$HERE/tools/distro_rootfs.sh" run "$ROOTFS" /build/build.sh || exit 1
  38. rm -rf "$B/candidate"
  39. mkdir -p "$B/candidate"
  40. tar -C "$B/candidate" -xzf "$B/out/lwe-cov.tar.gz"
  41. mv "$B/candidate/lwe-cov" "$B/candidate/lwe-hints"
  42. sed -i 's|^here=.*|&\nexport GCOV_PREFIX=/tmp/lwe-gcov GCOV_PREFIX_STRIP=0|' "$B/candidate/lwe-hints/linux-wallpaperengine"
  43. ;;
  44. run)
  45. for vm in ${VMS:-elementary debian-xfce fedora-kde arch-hypr}; do
  46. step=""
  47. [ "$vm" = arch-hypr ] && [ -n "${FLATPAK_BUNDLE:-}" ] && step="$HERE/tools/linuxvm/coverage_flatpak.sh"
  48. COLLECT_GCOV="$OUT/gcda" COVERAGE_STEP=$step FLATPAK_BUNDLE=${FLATPAK_BUNDLE:-} REPORT_DIR="$OUT/report-$vm" \
  49. "$HERE/tools/linuxvm/release_check.sh" --vm "$vm" --candidate "$B/candidate"
  50. done
  51. ;;
  52. report)
  53. cd "$HERE" || exit 1
  54. args=()
  55. for dir in "$OUT"/gcda/*/; do
  56. name=$(basename "$dir")
  57. rm -rf "$OUT/cov-$name"
  58. mkdir -p "$OUT/cov-$name"
  59. rsync -a --include='*/' --include='*.gcno' --exclude='*' "$B/CMakeFiles" "$B/spirv-cross" "$OUT/cov-$name/"
  60. cp -a "$dir/build/." "$OUT/cov-$name/"
  61. python3 "$HERE/tools/analysis/gcov12_report.py" "$OUT/cov-$name" "$OUT/vm-$name.json" > /dev/null
  62. args+=("$OUT/vm-$name.json")
  63. done
  64. gcovr -r . --object-directory build-cov --gcov-ignore-parse-errors suspicious_hits.warn_once_per_file \
  65. --filter 'src/WallpaperEngine/' --json "$OUT/host.json" > /dev/null 2>&1
  66. python3 "$HERE/tools/analysis/merge_coverage.py" "$OUT/host.json" "${args[@]}"
  67. ;;
  68. esac