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

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

65 lines
2.0 KiB
Nix
Raw Normal View History

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