nixosTests.power-profiles-daemon: test profilectl CLI

We also take advantage of that change to point to the new dbus
canonical names.
This commit is contained in:
Félix Baylac Jacqué 2024-02-18 13:46:56 +01:00
parent 93679d4d0a
commit 1da7dfa57d

View File

@ -8,22 +8,22 @@ import ./make-test-python.nix ({ pkgs, ... }:
nodes.machine = { pkgs, ... }: {
security.polkit.enable = true;
services.power-profiles-daemon.enable = true;
environment.systemPackages = [ pkgs.glib ];
environment.systemPackages = [ pkgs.glib pkgs.power-profiles-daemon ];
};
testScript = ''
def get_profile():
return machine.succeed(
"""gdbus call --system --dest net.hadess.PowerProfiles --object-path /net/hadess/PowerProfiles \
--method org.freedesktop.DBus.Properties.Get 'net.hadess.PowerProfiles' 'ActiveProfile'
"""gdbus call --system --dest org.freedesktop.UPower.PowerProfiles --object-path /org/freedesktop/UPower/PowerProfiles \
--method org.freedesktop.DBus.Properties.Get 'org.freedesktop.UPower.PowerProfiles' 'ActiveProfile'
"""
)
def set_profile(profile):
return machine.succeed(
"""gdbus call --system --dest net.hadess.PowerProfiles --object-path /net/hadess/PowerProfiles \
--method org.freedesktop.DBus.Properties.Set 'net.hadess.PowerProfiles' 'ActiveProfile' "<'{profile}'>"
"""gdbus call --system --dest org.freedesktop.UPower.PowerProfiles --object-path /org/freedesktop/UPower/PowerProfiles \
--method org.freedesktop.DBus.Properties.Set 'org.freedesktop.UPower.PowerProfiles' 'ActiveProfile' "<'{profile}'>"
""".format(
profile=profile
)
@ -42,5 +42,16 @@ import ./make-test-python.nix ({ pkgs, ... }:
profile = get_profile()
if not "balanced" in profile:
raise Exception("Unable to set balanced profile")
# test powerprofilectl CLI
machine.succeed("powerprofilesctl set power-saver")
profile = get_profile()
if not "power-saver" in profile:
raise Exception("Unable to set power-saver profile with powerprofilectl")
machine.succeed("powerprofilesctl set balanced")
profile = get_profile()
if not "balanced" in profile:
raise Exception("Unable to set balanced profile with powerprofilectl")
'';
})