Files
Waybar/test/smoke/hardware.sh
T
Alex 74f0d3393a ci(smoke): fix the mpd / hardware / leak tiers so they actually run
The first run went green but the best-effort tiers silently didn't exercise
anything:

- state.sh: the mpd `audio_output { ... }` block was on one line, which mpd
  rejects ("Unknown tokens after '{'"), so mpd never started and the mpd
  sub-tier (the #5183 empty-queue repro) skipped. Split the block across lines.
  Also move teardown into a cleanup() with `|| true` so a dead-pid kill under
  `set -e` no longer makes the step exit 1.
- hardware.sh: umockdev-run's LD_PRELOAD lands ahead of the linked-in ASan
  runtime, so ASan aborted before main() ("ASan runtime does not come first")
  and waybar never started -- the backlight/slider (#5179) path wasn't tested.
  Set verify_asan_link_order=0 so the instrumented binary runs under the preload.
- leakcheck.sh: abort_on_error=1 turned LSan's exit report into a core dump;
  force abort_on_error=0 for this report-only tier.
- lib.sh: assert_clean now also flags "ASan runtime does not come first" so a
  future preload/link-order regression fails loudly instead of passing.
2026-07-05 22:39:35 +02:00

93 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Tier — fake-hardware coverage via umockdev. Modules that read sysfs/udev
# (backlight, its slider, battery) can't run in a headless runner, so they were
# never smoke-tested and a construct/update crash like #5179 (backlight/slider)
# could ship unseen. umockdev-run intercepts sysfs/udev and feeds waybar a mock
# device, so the real code path runs under ASan.
#
# Best-effort: skipped if umockdev isn't installed. The .umockdev descriptions
# below may need tuning per distro; keep this continue-on-error in CI.
#
# Usage: hardware.sh
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib.sh
source "$DIR/lib.sh"
if ! command -v umockdev-run >/dev/null; then
echo "(umockdev not installed, skipping hardware tier)"; exit 0
fi
smoke::setup
# waybar is linked with ASan, but umockdev-run injects its own LD_PRELOAD, which
# lands ahead of the ASan runtime and makes ASan abort before main() ("ASan
# runtime does not come first"). Disabling the link-order check lets the
# instrumented binary run under the preload.
export ASAN_OPTIONS="${ASAN_OPTIONS}:verify_asan_link_order=0"
smoke::start_compositor
trap smoke::stop EXIT
fail=0
BL_DEV="$(mktemp --suffix=.umockdev)"
cat > "$BL_DEV" <<'EOF'
P: /devices/platform/fake_backlight/backlight/intel_backlight
E: SUBSYSTEM=backlight
A: brightness=500
A: max_brightness=1000
A: actual_brightness=500
A: bl_power=0
EOF
BAT_DEV="$(mktemp --suffix=.umockdev)"
cat > "$BAT_DEV" <<'EOF'
P: /devices/platform/fake_battery/power_supply/BAT0
E: SUBSYSTEM=power_supply
E: POWER_SUPPLY_NAME=BAT0
A: type=Battery
A: present=1
A: status=Discharging
A: capacity=55
A: energy_now=5500000
A: energy_full=10000000
A: power_now=1000000
EOF
# run_mock <name> <umockdev-file> <config-json>
run_mock() {
local name="$1" dev="$2" mod="$3" cfg
echo "::group::hardware: $name"
cfg="$(mktemp --suffix=.json)"
cat > "$cfg" <<EOF
{ "layer": "top", "position": "top", "height": 30,
"modules-center": ["$name"], $mod }
EOF
WAYBAR_WRAP="umockdev-run --device $dev --" smoke::launch_waybar "$cfg" "$DIR/style.css" 5
smoke::assert_alive || fail=1
smoke::assert_clean || fail=1
smoke::stop; WAYBAR_PID=""
echo "::endgroup::"
}
run_mock "backlight" "$BL_DEV" '"backlight": {"format":"{percent}%"}'
run_mock "backlight/slider" "$BL_DEV" '"backlight/slider": {"min":0,"max":100,"orientation":"horizontal"}'
run_mock "battery" "$BAT_DEV" '"battery": {"format":"{capacity}%"}'
# Slider inside a group -- the exact shape from #5179 (box#backlight-group).
echo "::group::hardware: backlight/slider in a group"
cfg="$(mktemp --suffix=.json)"
cat > "$cfg" <<'EOF'
{ "layer": "top", "position": "top", "height": 30,
"modules-center": ["group/bl"],
"group/bl": { "modules": ["backlight/slider"] },
"backlight/slider": { "min": 0, "max": 100, "orientation": "horizontal" } }
EOF
WAYBAR_WRAP="umockdev-run --device $BL_DEV --" smoke::launch_waybar "$cfg" "$DIR/style.css" 5
smoke::assert_alive || fail=1
smoke::assert_clean || fail=1
smoke::stop; WAYBAR_PID=""
echo "::endgroup::"
[ "$fail" = 0 ] || { echo "::error::hardware tier failed"; exit 1; }
echo "✓ fake-hardware tier passed"