coverage_all.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. # The whole coverage measurement of the engine in one go: a clean coverage build (build-cov), the unit tests, the scene
  3. # regression render, every extra run of tools/analysis/coverage_*.sh and, with WITH_LAB=1, the desktop lab (an hour).
  4. # Writes the gcovr summary to <out dir>/coverage-summary.json and prints the totals. Needs the workshop library and
  5. # Wallpaper Engine's assets (LWE_WORKSHOP_DIR / LWE_ASSETS_DIR as for regress.py), nothing touches the real desktop.
  6. # Usage: [WITH_LAB=1] tools/analysis/coverage_all.sh [out dir, default ${XDG_CACHE_HOME:-~/.cache}/lwe-analysis/coverage]
  7. set -uo pipefail
  8. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  9. ROOT="$(cd "$HERE/../.." && pwd)"
  10. OUT=${1:-${XDG_CACHE_HOME:-$HOME/.cache}/lwe-analysis/coverage}
  11. export LWE_WORKSHOP_DIR=${LWE_WORKSHOP_DIR:-/workspace/SteamLibrary/steamapps/workshop/content/431960}
  12. export LWE_ASSETS_DIR=${LWE_ASSETS_DIR:-/workspace/SteamLibrary/steamapps/common/wallpaper_engine/assets}
  13. BUILD="$ROOT/build-cov"
  14. BINARY="$BUILD/output/linux-wallpaperengine"
  15. mkdir -p "$OUT"
  16. cd "$ROOT" || exit 1
  17. # -U_FORTIFY_SOURCE: the hardening block of CMakeLists.txt collides with CEF's flags under -Werror otherwise
  18. cmake -S . -B "$BUILD" -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=1 -DCMAKE_CXX_FLAGS="--coverage -U_FORTIFY_SOURCE" \
  19. -DCMAKE_C_FLAGS="--coverage" -DCMAKE_CXX_FLAGS_RELEASE=-O1 -DCMAKE_C_FLAGS_RELEASE=-O1 > "$OUT/cmake.log" 2>&1 || exit 1
  20. find "$BUILD" -name '*.gcda' -delete
  21. make -C "$BUILD" -j"$(nproc)" linux-wallpaperengine linux-wallpaperengine-lib linux-wallpaperengine-web-helper tests \
  22. > "$OUT/build.log" 2>&1 || { tail -20 "$OUT/build.log"; exit 1; }
  23. step () {
  24. local label=$1
  25. shift
  26. echo "== $label"
  27. "$@" > "$OUT/$label.log" 2>&1 || echo " (exit $?, see $OUT/$label.log)"
  28. }
  29. step unit-tests "$BUILD/output/tests"
  30. step regress python3 "$ROOT/tools/regression/regress.py" run --gpu --jobs 4 "$BINARY" "$OUT/regress"
  31. step extras "$HERE/coverage_extras.sh" "$BINARY"
  32. step testscenes "$HERE/coverage_testscenes.sh" "$BINARY"
  33. step audio "$HERE/coverage_audio.sh" "$BINARY"
  34. step media "$HERE/coverage_media.sh" "$BINARY"
  35. step options "$HERE/coverage_options.sh" "$BINARY"
  36. step playlists "$HERE/coverage_playlists.sh" "$BINARY"
  37. step scripts "$HERE/coverage_scripts.sh" "$BINARY"
  38. step shortcuts "$HERE/coverage_shortcuts.sh" "$BINARY"
  39. step cli "$HERE/coverage_cli.sh" "$BINARY"
  40. step power "$HERE/coverage_power.sh" "$BINARY"
  41. step hotswap-keys "$ROOT/tools/check_hotswap_keys.sh" "$BINARY"
  42. step signals "$ROOT/tools/check_signals_after_video_change.sh" "$BINARY"
  43. if [ -n "${WITH_LAB:-}" ]; then
  44. echo "== desktop lab"
  45. LWE_BINARY="$BINARY" python3 -m pytest tests/desktops -q -p no:cacheprovider > "$OUT/lab.log" 2>&1 || echo " (lab exit $?)"
  46. fi
  47. gcovr -r . --object-directory "$BUILD" --filter 'src/WallpaperEngine/' --exclude 'src/WallpaperEngine/Testing' -j "$(nproc)" \
  48. --gcov-ignore-parse-errors suspicious_hits.warn_once_per_file --json-summary "$OUT/coverage-summary.json" > /dev/null 2>&1
  49. python3 -I - "$OUT/coverage-summary.json" <<'PY'
  50. import json, sys
  51. data = json.load(open(sys.argv[1]))
  52. print("lines %d of %d: %.1f %%" % (data["line_covered"], data["line_total"], data["line_percent"]))
  53. # JS.cpp (1024 template instantiations) and Log.h (templates per translation unit) are counted many times over
  54. skip = ("Scripting/JS.cpp", "Logging/Log.h")
  55. files = [f for f in data["files"] if not f["filename"].endswith(skip)]
  56. total = sum(f["line_total"] for f in files)
  57. covered = sum(f["line_covered"] for f in files)
  58. print("without JS.cpp and Log.h: %.1f %%" % (100.0 * covered / total))
  59. PY