nixpkgs-suyu/nixos/tests/power-profiles-daemon.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.8 KiB
Nix
Raw Permalink Normal View History

2020-09-15 10:15:48 +02:00
import ./make-test-python.nix ({ pkgs, ... }:
{
name = "power-profiles-daemon";
meta = with pkgs.lib.maintainers; {
2020-09-15 10:15:48 +02:00
maintainers = [ mvnetbiz ];
};
2022-03-21 00:15:30 +01:00
nodes.machine = { pkgs, ... }: {
security.polkit.enable = true;
2020-09-15 10:15:48 +02:00
services.power-profiles-daemon.enable = true;
environment.systemPackages = [ pkgs.glib pkgs.power-profiles-daemon ];
2020-09-15 10:15:48 +02:00
};
testScript = ''
def get_profile():
return machine.succeed(
"""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'
2020-09-15 10:15:48 +02:00
"""
)
def set_profile(profile):
return machine.succeed(
"""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}'>"
2020-09-15 10:15:48 +02:00
""".format(
profile=profile
)
)
machine.wait_for_unit("multi-user.target")
set_profile("power-saver")
profile = get_profile()
if not "power-saver" in profile:
raise Exception("Unable to set power-saver profile")
set_profile("balanced")
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")
2020-09-15 10:15:48 +02:00
'';
})