2021-02-13 14:23:35 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
|
|
|
|
|
|
|
{
|
|
|
|
name = "power-profiles-daemon";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ mvnetbiz ];
|
|
|
|
};
|
2022-04-03 18:54:34 +00:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2023-04-29 16:46:19 +00:00
|
|
|
security.polkit.enable = true;
|
2021-02-13 14:23:35 +00:00
|
|
|
services.power-profiles-daemon.enable = true;
|
2024-02-29 20:09:43 +00:00
|
|
|
environment.systemPackages = [ pkgs.glib pkgs.power-profiles-daemon ];
|
2021-02-13 14:23:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
def get_profile():
|
|
|
|
return machine.succeed(
|
2024-02-29 20:09:43 +00:00
|
|
|
"""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'
|
2021-02-13 14:23:35 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def set_profile(profile):
|
|
|
|
return machine.succeed(
|
2024-02-29 20:09:43 +00:00
|
|
|
"""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}'>"
|
2021-02-13 14:23:35 +00: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")
|
2024-02-29 20:09:43 +00:00
|
|
|
|
|
|
|
# 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")
|
2021-02-13 14:23:35 +00:00
|
|
|
'';
|
|
|
|
})
|