Hi! Maxime Devos <maximede...@telenet.be> skribis:
> On 05-09-2022 14:56, Ludovic Courtès wrote: >> I’d like to test whether UPower invokes the intended critical action, >> but I’m not sure how to simulate a low battery level. Thoughts? > > I've found a 'Virtual Battery Driver': https://lwn.net/Articles/440097/ > > The gmane links are dead, but the linux source tree as a > drivers/power/supply/test_power.c that seems to be about the same > thing. I was able to give that a try. Since the default ‘percentage-action’ in <upower-configuration> is 2, I did this (I configured syslogd to log to /dev/console): --8<---------------cut here---------------start------------->8--- root@antelope ~# modprobe test-power ac_online=off usb_online=off battery_capacity=2 battery_status=discharging modprobe test-power ac_online=off usb_online=off battery_capacity=2 battery_status=discharging Oct 2 17:00:20 localhost vmunix: [ 44.294530] __power_supply_register: Expected proper parent device for 'test_ac' Oct 2 17:00:20 localhost vmunix: [ 44.295049] __power_supply_register: Expected proper parent device for 'test_battery' Oct 2 17:00:20 localhost vmunix: [ 44.295147] __power_supply_register: Expected proper parent device for 'test_usb' root@antelope ~# Oct 2 17:00:20 localhost shepherd[1]: [upowerd] Oct 2 17:00:20 localhost shepherd[1]: [upowerd] (upowerd:186): UPower-Linux-WARNING **: 17:00:20.457: no valid voltage value found for device /sys/devices/virtual/power_supply/test_battery, assuming 10V Oct 2 17:00:20 localhost shepherd[1]: [upowerd] Oct 2 17:00:20 localhost shepherd[1]: [upowerd] (upowerd:186): UPower-Linux-WARNING **: 17:00:20.473: USB power supply /sys/devices/virtual/power_supply/test_usb without usb_type property, please report root@antelope ~# Oct 2 17:00:41 localhost elogind[185]: System is powering down.. Oct 2 17:00:41 localhost elogind[185]: System is powering down.. Oct 2 17:00:41 localhost shepherd[1]: Exiting shepherd... Oct 2 17:00:41 localhost shepherd[1]: Service ntpd has been stopped. Oct 2 17:00:41 localhost ntpd[184]: ntpd exiting on signal 15 (Terminated) Oct 2 17:00:41 localhost avahi-daemon[191]: Got SIGTERM, quitting. Oct 2 17:00:41 localhost avahi-daemon[191]: Leaving mDNS multicast group on interface ens3.IPv6 with address fec0::e35c:509d:d937:2087. Oct 2 17:00:41 localhost avahi-daemon[191]: Leaving mDNS multicast group on interface ens3.IPv4 with address 10.0.2.15. Oct 2 17:00:41 localhost shepherd[1]: Service avahi-daemon has been stopped. Oct 2 17:00:41 localhost NetworkManager[183]: <info> [1664722841.2220] caught SIGTERM, shutting down normally. Oct 2 17:00:41 localhost shepherd[1]: Service networking has been stopped. Oct 2 17:00:41 localhost shepherd[1]: Service console-font-tty6 has been stopped. Oct 2 17:00:41 localhost shepherd[1]: Service term-tty6 has been stopped. Oct 2 17:00:41 localhost NetworkManager[183]: <info> [1664722841.2318] dhcp4 (ens3): canceled DHCP transaction Oct 2 17:00:41 localhost NetworkManager[183]: <info> [1664722841.2318] dhcp4 (ens3): activation: beginning transaction (timeout in 45 seconds) Oct 2 17:00:41 localhost NetworkManager[183]: <info> [1664722841.2318] dhcp4 (ens3): state changed no lease Oct 2 17:00:41 localhost NetworkManager[183]: <info> [1664722841.2326] manager: NetworkManager state is now CONNECTED_SITE Oct 2 17:00:41 localhost NetworkManager[183]: <info> [1664722841.2335] exiting (success) Oct 2 17:00:41 localhost avahi-daemon[191]: Leaving mDNS multicast group on interface lo.IPv6 with address ::1. Oct 2 17:00:41 localhost syslogd: exiting on signal 15 [ 70.670560] reboot: Power down --8<---------------cut here---------------end--------------->8--- So 20s after a battery at 2% got plugged in, UPower told elogind to turn off the VM, which told shepherd to do that—exactly as expected. It’s kinda disappointing to debug something just to find out it’s working as advertised. I think the conclusion is that 2% is too low a threshold, at least for my laptop, or maybe the charge estimate is slightly off on my laptop. I’ll raise that threshold and see if it works correctly next time I run out of battery… If someone has better ideas, I’d love to hear them! Ludo’.