Repository navigation
Rebuild headlines from live packs when a dead pack poisons DisplayDevice #12789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ujo4eva
wants to merge
2
commits into
omacom:quattro
Choose a base branch
from
ujo4eva:fix/battery-dead-pack-liveness
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| tmp_dir=$(mktemp -d) | ||
| trap 'rm -rf "$tmp_dir"' EXIT | ||
|
|
||
| # Dual-battery ThinkPad whose internal pack (BAT0) is dead: no voltage, no | ||
| # stored energy, enumerated first by UPower. The removable pack (BAT1) powers | ||
| # the machine. DisplayDevice itself is correct here (dead pack advertises 0). | ||
| mkdir -p "$tmp_dir/bin" | ||
| mkdir -p "$tmp_dir/power/BAT0" "$tmp_dir/power/BAT1" | ||
|
|
||
| printf 'Battery\n' >"$tmp_dir/power/BAT0/type" | ||
| printf '1\n' >"$tmp_dir/power/BAT0/present" | ||
| printf '0\n' >"$tmp_dir/power/BAT0/voltage_now" | ||
| printf '0\n' >"$tmp_dir/power/BAT0/energy_now" | ||
| printf '0\n' >"$tmp_dir/power/BAT0/energy_full" | ||
| printf '%s\n' -1 >"$tmp_dir/power/BAT0/cycle_count" | ||
|
|
||
| printf 'Battery\n' >"$tmp_dir/power/BAT1/type" | ||
| printf '1\n' >"$tmp_dir/power/BAT1/present" | ||
| printf '12300000\n' >"$tmp_dir/power/BAT1/voltage_now" | ||
| printf '27300000\n' >"$tmp_dir/power/BAT1/energy_now" | ||
| printf '46500000\n' >"$tmp_dir/power/BAT1/energy_full" | ||
| printf '5\n' >"$tmp_dir/power/BAT1/cycle_count" | ||
|
|
||
| # A wireless mouse also reports type Battery, but its scope marks it as a | ||
| # peripheral: it must not leak into cycle counts. | ||
| mkdir -p "$tmp_dir/power/hidpp_battery_0" | ||
| printf 'Battery\n' >"$tmp_dir/power/hidpp_battery_0/type" | ||
| printf 'Device\n' >"$tmp_dir/power/hidpp_battery_0/scope" | ||
| printf '99\n' >"$tmp_dir/power/hidpp_battery_0/cycle_count" | ||
|
|
||
| cat >"$tmp_dir/bin/upower" <<'STUB' | ||
| #!/bin/bash | ||
|
|
||
| if [[ $1 == "-e" ]]; then | ||
| echo "/org/freedesktop/UPower/devices/battery_BAT0" | ||
| echo "/org/freedesktop/UPower/devices/battery_BAT1" | ||
| echo "/org/freedesktop/UPower/devices/DisplayDevice" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ $1 == "-i" && $2 == "/org/freedesktop/UPower/devices/DisplayDevice" ]]; then | ||
| cat <<'INFO' | ||
| native-path: DisplayDevice | ||
| state: charging | ||
| energy: 27.3 Wh | ||
| energy-full: 46.5 Wh | ||
| energy-rate: 30.9 W | ||
| time to full: 1.2 hours | ||
| percentage: 58% | ||
| INFO | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ $1 == "-i" ]]; then | ||
| cat <<'INFO' | ||
| native-path: BAT0 | ||
| state: pending-charge | ||
| energy: 0 Wh | ||
| energy-full: 0 Wh | ||
| energy-rate: 0 W | ||
| percentage: 0% | ||
| charge-start-threshold: 75% | ||
| charge-end-threshold: 80% | ||
| INFO | ||
| exit 0 | ||
| fi | ||
|
|
||
| exit 1 | ||
| STUB | ||
| chmod +x "$tmp_dir/bin/upower" | ||
|
|
||
| shell_output=$(OMARCHY_POWER_SUPPLY_PATH="$tmp_dir/power" PATH="$tmp_dir/bin:$PATH" "$ROOT/bin/omarchy-battery-status" --shell) | ||
|
|
||
| grep -Fx $'percentage\t58%' <<<"$shell_output" >/dev/null || fail "dual battery reports the aggregate percentage, not the dead pack's 0%" "$shell_output" | ||
| grep -Fx $'state\tcharging' <<<"$shell_output" >/dev/null || fail "dual battery reports the aggregate state, not the dead pack's pending-charge" "$shell_output" | ||
| grep -Fx $'size\t46Wh' <<<"$shell_output" >/dev/null || fail "dual battery reports the aggregate capacity, not the dead pack's 0Wh" "$shell_output" | ||
| grep -Fx $'cycles\t5' <<<"$shell_output" >/dev/null || fail "dual battery reports the live pack's cycle count, not the dead pack's" "$shell_output" | ||
| grep -Fx $'threshold\t75-80%' <<<"$shell_output" >/dev/null || fail "threshold still comes from the first battery's UPower info" "$shell_output" | ||
|
|
||
| pass "dual-battery machine with a dead pack reports the working battery" | ||
|
|
||
| # Both packs alive: each pack contributes its own cycle count, in sysfs order. | ||
| mkdir -p "$tmp_dir/power2/BAT0" "$tmp_dir/power2/BAT1" | ||
|
|
||
| printf 'Battery\n' >"$tmp_dir/power2/BAT0/type" | ||
| printf '1\n' >"$tmp_dir/power2/BAT0/present" | ||
| printf '12000000\n' >"$tmp_dir/power2/BAT0/voltage_now" | ||
| printf '7\n' >"$tmp_dir/power2/BAT0/cycle_count" | ||
|
|
||
| printf 'Battery\n' >"$tmp_dir/power2/BAT1/type" | ||
| printf '1\n' >"$tmp_dir/power2/BAT1/present" | ||
| printf '12600000\n' >"$tmp_dir/power2/BAT1/voltage_now" | ||
| printf '5\n' >"$tmp_dir/power2/BAT1/cycle_count" | ||
|
|
||
| shell_output=$(OMARCHY_POWER_SUPPLY_PATH="$tmp_dir/power2" PATH="$tmp_dir/bin:$PATH" "$ROOT/bin/omarchy-battery-status" --shell) | ||
|
|
||
| grep -Fx $'cycles\t7 / 5' <<<"$shell_output" >/dev/null || fail "two live packs report both cycle counts in sysfs order" "$shell_output" | ||
|
|
||
| pass "dual-battery machine with two live packs lists both cycle counts" | ||
|
|
||
| # UPower's composite DisplayDevice keeps a dead pack's advertised energy-full | ||
| # in the percentage denominator: a 20.65Wh corpse next to a 20.94Wh live pack | ||
| # near full reads as 49% with a ten-hour charge (#7916). Headline figures must | ||
| # follow the packs that actually hold a charge — and a dead pack still | ||
| # advertising its old energy_full must not count as alive. | ||
| mkdir -p "$tmp_dir/power3/BAT0" "$tmp_dir/power3/BAT1" "$tmp_dir/bin3" | ||
|
|
||
| printf 'Battery\n' >"$tmp_dir/power3/BAT0/type" | ||
| printf '1\n' >"$tmp_dir/power3/BAT0/present" | ||
| printf '0\n' >"$tmp_dir/power3/BAT0/voltage_now" | ||
| printf '0\n' >"$tmp_dir/power3/BAT0/energy_now" | ||
| printf '20650000\n' >"$tmp_dir/power3/BAT0/energy_full" | ||
|
|
||
| printf 'Battery\n' >"$tmp_dir/power3/BAT1/type" | ||
| printf '1\n' >"$tmp_dir/power3/BAT1/present" | ||
| printf '12300000\n' >"$tmp_dir/power3/BAT1/voltage_now" | ||
| printf '20400000\n' >"$tmp_dir/power3/BAT1/energy_now" | ||
| printf '20940000\n' >"$tmp_dir/power3/BAT1/energy_full" | ||
|
|
||
| cat >"$tmp_dir/bin3/upower" <<'STUB' | ||
| #!/bin/bash | ||
|
|
||
| if [[ $1 == "-e" ]]; then | ||
| echo "/org/freedesktop/UPower/devices/battery_BAT0" | ||
| echo "/org/freedesktop/UPower/devices/battery_BAT1" | ||
| echo "/org/freedesktop/UPower/devices/DisplayDevice" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ $1 == "-i" && $2 == "/org/freedesktop/UPower/devices/DisplayDevice" ]]; then | ||
| cat <<'INFO' | ||
| native-path: DisplayDevice | ||
| state: charging | ||
| energy: 20.4 Wh | ||
| energy-full: 41.59 Wh | ||
| energy-rate: 2.2 W | ||
| time to full: 9.6 hours | ||
| percentage: 49% | ||
| INFO | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ $1 == "-i" ]]; then | ||
| cat <<'INFO' | ||
| native-path: BAT0 | ||
| state: pending-charge | ||
| percentage: 0% | ||
| INFO | ||
| exit 0 | ||
| fi | ||
|
|
||
| exit 1 | ||
| STUB | ||
| chmod +x "$tmp_dir/bin3/upower" | ||
|
|
||
| shell_output=$(OMARCHY_POWER_SUPPLY_PATH="$tmp_dir/power3" PATH="$tmp_dir/bin3:$PATH" "$ROOT/bin/omarchy-battery-status" --shell) | ||
|
|
||
| grep -Fx $'percentage\t97%' <<<"$shell_output" >/dev/null || fail "a dead pack's energy-full stays out of the percentage denominator" "$shell_output" | ||
| grep -Fx $'state\tcharging' <<<"$shell_output" >/dev/null || fail "the live pack's charging state survives a dead sibling" "$shell_output" | ||
| grep -Fx $'size\t20Wh' <<<"$shell_output" >/dev/null || fail "capacity counts only packs that hold a charge" "$shell_output" | ||
| grep -Fx $'time\t14m' <<<"$shell_output" >/dev/null || fail "time to full is not stretched by a dead pack's capacity" "$shell_output" | ||
|
|
||
| pass "a dead pack's advertised capacity does not drag down the headline figures" | ||
|
|
||
| # energy_now and energy_full are read separately, so a capacity update in | ||
| # between can leave the live pack reporting more than its full. The headline | ||
| # caps at 100% and time to full does not go negative. | ||
| printf '21100000\n' >"$tmp_dir/power3/BAT1/energy_now" | ||
|
|
||
| shell_output=$(OMARCHY_POWER_SUPPLY_PATH="$tmp_dir/power3" PATH="$tmp_dir/bin3:$PATH" "$ROOT/bin/omarchy-battery-status" --shell) | ||
|
|
||
| grep -Fx $'percentage\t100%' <<<"$shell_output" >/dev/null || fail "a pack reading above its full caps the percentage at 100%" "$shell_output" | ||
| grep -Fx $'time\t0m' <<<"$shell_output" >/dev/null || fail "a pack reading above its full gives no negative time to full" "$shell_output" | ||
|
|
||
| pass "a pack reading above its full stays within bounds" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.