mirror of
https://gitlab.freedesktop.org/upower/power-profiles-daemon.git
synced 2026-05-06 02:18:02 +02:00
platform-profile: Fix ThinkPad lapmode detection with libgudev <= 234
g_udev_device_get_sysfs_attr_as_boolean_uncached in libgudev <= 234 does not work, see: https://gitlab.gnome.org/GNOME/libgudev/-/issues/7 Since the dytc_lapmode file always contains an integer 0/1 value we can easily workaround this libgudev issue by switching to g_udev_device_get_sysfs_attr_as_int_uncached. Also update the tests to include the '\n' for the dytc_lapmode sysfs attribute values, like on real hardware.
This commit is contained in:
parent
1cbeca326e
commit
efa7e4f48e
2 changed files with 9 additions and 9 deletions
|
|
@ -23,7 +23,7 @@ struct _PpdDriverPlatformProfile
|
|||
|
||||
PpdProbeResult probe_result;
|
||||
GUdevDevice *device;
|
||||
gboolean lapmode;
|
||||
int lapmode;
|
||||
PpdProfile acpi_platform_profile;
|
||||
GFileMonitor *lapmode_mon;
|
||||
GFileMonitor *acpi_platform_profile_mon;
|
||||
|
|
@ -112,9 +112,9 @@ verify_acpi_platform_profile_choices (void)
|
|||
static void
|
||||
update_dytc_lapmode_state (PpdDriverPlatformProfile *self)
|
||||
{
|
||||
gboolean new_lapmode;
|
||||
int new_lapmode;
|
||||
|
||||
new_lapmode = g_udev_device_get_sysfs_attr_as_boolean_uncached (self->device, LAPMODE_SYSFS_NAME);
|
||||
new_lapmode = g_udev_device_get_sysfs_attr_as_int_uncached (self->device, LAPMODE_SYSFS_NAME);
|
||||
if (new_lapmode == self->lapmode)
|
||||
return;
|
||||
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ class Tests(dbusmock.DBusTestCase):
|
|||
|
||||
def create_dytc_device(self):
|
||||
self.tp_acpi = self.testbed.add_device('platform', 'thinkpad_acpi', None,
|
||||
['dytc_lapmode', '0'],
|
||||
['dytc_lapmode', '0\n'],
|
||||
[ 'DEVPATH', '/devices/platform/thinkpad_acpi' ]
|
||||
)
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.assertEqual(self.get_dbus_property('ActiveProfile'), 'performance')
|
||||
|
||||
# Inhibit
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1')
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1\n')
|
||||
self.assertEventually(lambda: self.have_text_in_log('dytc_lapmode is now on'))
|
||||
self.assertEqual(self.get_dbus_property('PerformanceInhibited'), 'lap-detected')
|
||||
self.assertEqual(self.get_dbus_property('ActiveProfile'), 'balanced')
|
||||
|
|
@ -413,12 +413,12 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.assertEventually(lambda: self.read_file (os.path.join(self.testbed.get_root_dir(), "sys/firmware/acpi/platform_profile")) == b'balanced')
|
||||
|
||||
# lapmode detected, but performance wasn't selected anyway
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1')
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1\n')
|
||||
self.assertEventually(lambda: self.get_dbus_property('PerformanceInhibited') == 'lap-detected')
|
||||
self.assertEqual(self.get_dbus_property('ActiveProfile'), 'balanced')
|
||||
|
||||
# Reset lapmode
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '0')
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '0\n')
|
||||
self.assertEventually(lambda: self.get_dbus_property('PerformanceInhibited') == '')
|
||||
|
||||
# Set performance mode
|
||||
|
|
@ -427,14 +427,14 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.assertEventually(lambda: self.read_file (os.path.join(self.testbed.get_root_dir(), "sys/firmware/acpi/platform_profile")) == b'performance')
|
||||
|
||||
# And turn on lapmode
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1')
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '1\n')
|
||||
self.assertEventually(lambda: self.read_file (os.path.join(self.testbed.get_root_dir(), "sys/firmware/acpi/platform_profile")) == b'balanced')
|
||||
|
||||
self.assertEqual(self.get_dbus_property('ActiveProfile'), 'balanced')
|
||||
self.assertEqual(self.get_dbus_property('PerformanceInhibited'), 'lap-detected')
|
||||
|
||||
# Turn off lapmode, profile stays balanced
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '0')
|
||||
self.testbed.set_attribute(self.tp_acpi, 'dytc_lapmode', '0\n')
|
||||
self.assertEventually(lambda: self.get_dbus_property('PerformanceInhibited') == '')
|
||||
self.assertEventually(lambda: self.read_file (os.path.join(self.testbed.get_root_dir(), "sys/firmware/acpi/platform_profile")) == b'balanced')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue