power-profiles-daemon/tests/legacy_integration_test.py
Mario Limonciello 266d2b7bf8 Introduce a 4th power state on the modern interface
This maps out more closely to how the Windows power slider behaves,
in that it has 4 states for a user to select.

The 4 new states are:
 * power-saver
 * balanced-power
 * balanced-performance
 * performance

To avoid regressions from other software that uses power-profiles-daemon
the legacy interface only advertises support for the 3 previous states.

For example if a client tries to set 'balanced' on the legacy interface
it will map out to 'balanced-power' to the daemon.
If the daemon is currently in 'balanced-performance' it will still report
'balanced' to the client.
2024-02-26 21:53:26 -06:00

77 lines
2.5 KiB
Python

#!/usr/bin/python3
# power-profiles-daemon integration test suite
#
# Run in built tree to test local built binaries, or from anywhere else to test
# system installed binaries.
#
# Copyright: (C) 2011 Martin Pitt <martin.pitt@ubuntu.com>
# (C) 2020 Bastien Nocera <hadess@hadess.net>
# (C) 2021 David Redondo <kde@david-redondo.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import os
import subprocess
import sys
import unittest
from integration_test import Tests
class LegacyDBusNameTests(Tests):
"""This will repeats all the tests in the Tests class using the legacy dbus name"""
PP = "net.hadess.PowerProfiles"
PP_PATH = "/net/hadess/PowerProfiles"
PP_INTERFACE = "net.hadess.PowerProfiles"
legacy = True
max_profiles = 3
default_state = "balanced"
def test_powerprofilesctl_legacy_commands(self):
"""Check ONLY legacy profile names work"""
self.start_daemon()
tool = self.get_powerprofilesctl()
self.assertEqual(self.get_dbus_property("ActiveProfile"), self.default_state)
# try to set to modern profile name on legacy interface
with self.assertRaises(subprocess.CalledProcessError) as error:
subprocess.check_output(
tool + ["set", "balanced-power"],
stderr=subprocess.PIPE,
universal_newlines=True,
)
self.assertNotIn("Traceback", error.exception.stderr)
# try to set using legacy profile name on legacy interface
cmd = subprocess.run(
tool + ["set", "balanced"], capture_output=True, check=True
)
self.assertEqual(cmd.returncode, 0)
if __name__ == "__main__":
# run ourselves under umockdev
if "umockdev" not in os.environ.get("LD_PRELOAD", ""):
os.execvp("umockdev-wrapper", ["umockdev-wrapper", sys.executable] + sys.argv)
prog = unittest.main(exit=False)
if prog.result.errors or prog.result.failures:
sys.exit(1)
# Translate to skip error
if prog.result.testsRun == len(prog.result.skipped):
sys.exit(77)