diff options
author | Benjamin Berg <bberg@redhat.com> | 2022-03-22 16:57:25 +0100 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2022-03-23 15:39:20 +0100 |
commit | 5671b3c3b5e00d45f6462b657f6dc83bdcb01763 (patch) | |
tree | 8ebf78c96124d434b2c385b442eaba5adaf280ee | |
parent | 9cac01e9e1d48a82eca3f1f68486e9b0e6f94588 (diff) | |
download | gnome-settings-daemon-5671b3c3b5e00d45f6462b657f6dc83bdcb01763.tar.gz |
power: Switch brightness test to use the logind interface
-rw-r--r-- | plugins/power/gsd-backlight.c | 36 | ||||
-rwxr-xr-x | plugins/power/test-backlight-helper | 5 | ||||
-rwxr-xr-x | plugins/power/test.py | 44 | ||||
-rw-r--r-- | tests/gsdtestcase.py | 9 |
4 files changed, 31 insertions, 63 deletions
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c index 8aca2c6c..dbf538a6 100644 --- a/plugins/power/gsd-backlight.c +++ b/plugins/power/gsd-backlight.c @@ -348,7 +348,6 @@ gsd_backlight_run_set_helper (GsdBacklight *backlight, GTask *task) { GSubprocess *proc = NULL; BacklightHelperData *data = g_task_get_task_data (task); - const gchar *gsd_backlight_helper = NULL; GError *error = NULL; g_assert (backlight->active_task == NULL); @@ -359,21 +358,12 @@ gsd_backlight_run_set_helper (GsdBacklight *backlight, GTask *task) /* This is solely for use by the test environment. If given, execute * this helper instead of the internal helper using pkexec */ - gsd_backlight_helper = g_getenv ("GSD_BACKLIGHT_HELPER"); - if (!gsd_backlight_helper) { - proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE, - &error, - "pkexec", - LIBEXECDIR "/gsd-backlight-helper", - g_udev_device_get_sysfs_path (backlight->udev_device), - data->value_str, NULL); - } else { - proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE, - &error, - gsd_backlight_helper, - g_udev_device_get_sysfs_path (backlight->udev_device), - data->value_str, NULL); - } + proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE, + &error, + "pkexec", + LIBEXECDIR "/gsd-backlight-helper", + g_udev_device_get_sysfs_path (backlight->udev_device), + data->value_str, NULL); if (proc == NULL) { gsd_backlight_set_helper_return (backlight, task, -1, error); @@ -884,8 +874,18 @@ gsd_backlight_initable_init (GInitable *initable, g_clear_error (&logind_error); g_clear_object (&backlight->logind_proxy); } else { - /* Fail on anything else */ - g_clear_object (&backlight->logind_proxy); + /* python-dbusmock throws a TypeError here as of 0.27.3 + * https://github.com/martinpitt/python-dbusmock/pull/117 + */ + g_autofree char *dbus_error = NULL; + + dbus_error = g_dbus_error_get_remote_error (logind_error); + if (g_strcmp0 (dbus_error, "org.freedesktop.DBus.Python.TypeError") == 0) { + g_clear_error (&logind_error); + } else { + /* Fail on anything else */ + g_clear_object (&backlight->logind_proxy); + } } } diff --git a/plugins/power/test-backlight-helper b/plugins/power/test-backlight-helper deleted file mode 100755 index 2dceacd8..00000000 --- a/plugins/power/test-backlight-helper +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# Simulate a slow call and just write the given brightness value to the device -sleep 0.2 -echo "$2" >"$1/brightness" diff --git a/plugins/power/test.py b/plugins/power/test.py index beb88b42..0dd7a68b 100755 --- a/plugins/power/test.py +++ b/plugins/power/test.py @@ -88,15 +88,15 @@ class PowerPluginBase(gsdtestcase.GSDTestCase): os.environ['GSD_MOCK_EXTERNAL_MONITOR_FILE'] = self.mock_external_monitor_file self.addCleanup(self.delete_external_monitor_file) - self.check_logind_gnome_session() - self.start_logind() - self.addCleanup(self.stop_logind) - # Setup umockdev testbed self.testbed = UMockdev.Testbed.new() self.addCleanup(self.cleanup_testbed) os.environ['UMOCKDEV_DIR'] = self.testbed.get_root_dir() + self.check_logind_gnome_session() + self.start_logind() + self.addCleanup(self.stop_logind) + # Create a mock backlight device # Note that this function creates a different or even no backlight # device based on the name of the test. @@ -156,8 +156,6 @@ class PowerPluginBase(gsdtestcase.GSDTestCase): # Disable PulseAudio output from libcanberra env['CANBERRA_DRIVER'] = 'null' - # Use dummy script as testing backlight helper - env['GSD_BACKLIGHT_HELPER'] = os.path.join (project_root, 'plugins', 'power', 'test-backlight-helper') if 'POWER_LD_PRELOAD' in env: if 'LD_PRELOAD' in env and env['LD_PRELOAD']: env['LD_PRELOAD'] = ':'.join((env['POWER_LD_PRELOAD'], env['LD_PRELOAD'])) @@ -1110,12 +1108,9 @@ class PowerPluginTest8(PowerPluginBase): obj_gsd_power_screen_iface.StepUp() self.assertEqual(self.get_brightness(), 70) stop = time.time() - # This needs to take more than 0.8 seconds as each write is delayed by - # 0.2 seconds by the test backlight helper - self.assertGreater(stop - start, 0.8) # Now, the same thing should work fine if we step multiple times, - # even if we are so quick that compression will happen. + # even if we are really quick in submitting multiple requests. # Use a list to keep rack of replies (as integer is immutable and would # not be modified in the outer scope) replies = [0] @@ -1144,35 +1139,6 @@ class PowerPluginTest8(PowerPluginBase): self.assertEqual(replies[0], 4) # Four steps down, so back at 50% self.assertEqual(self.get_brightness(), 50) - # And compression must have happened, so it should take less than 0.8s - self.assertLess(stop - start, 0.8) - - def test_brightness_compression(self): - '''Check that compression also happens when setting the property''' - - if self.skip_sysfs_backlight: - self.skipTest("sysfs backlight support required for test") - - # Now test that the compression works correctly. - # NOTE: Relies on the implementation detail, that the property setter - # returns immediately rather than waiting for the brightness to - # be updated. - # Should this ever be fixed, then this will need to be changed to use - # async dbus calls similar to the stepping code - - obj_gsd_power = self.session_bus_con.get_object( - 'org.gnome.SettingsDaemon.Power', '/org/gnome/SettingsDaemon/Power') - obj_gsd_power_prop_iface = dbus.Interface(obj_gsd_power, dbus.PROPERTIES_IFACE) - - # Quickly ramp the brightness up - for brightness in range(70, 91): - obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', brightness) - - # The brightness of 80 should be in effect after slightly more than - # 0.4 seconds. If compression does not work as expected, this would take - # more than 5 seconds for the 20 steps. - time.sleep(2.0) - self.assertEqual(self.get_brightness(), 90) def test_brightness_uevent(self): if self.skip_sysfs_backlight: diff --git a/tests/gsdtestcase.py b/tests/gsdtestcase.py index 51f18250..96a57efd 100644 --- a/tests/gsdtestcase.py +++ b/tests/gsdtestcase.py @@ -225,7 +225,14 @@ class GSDTestCase(X11SessionTestCase): self.logind_obj.AddMethod('org.freedesktop.login1.Manager', 'SuspendThenHibernate', 'b', '', '') self.logind_obj.AddMethod('org.freedesktop.login1.Manager', 'CanSuspendThenHibernate', '', 's', 'ret = "%s"' % parameters.get('CanSuspendThenHibernate', 'yes')) - self.logind_obj.AddMethod('org.freedesktop.login1.Session', 'SetBrightness', 'ssu', '', '') + # add "auto" session, it is all we really need + self.logind_obj.AddSession('session_test', 'seat_test', 1234, 'testuser', True) + obj = self.logind_obj.AddSession('auto', 'seat_test', 1234, 'testuser', True) + bus = self.get_dbus(True) + obj = bus.get_object("org.freedesktop.login1", obj) + + # Monkey patch in our SetBrightness method; and make it take a little bit of time to open a window for race conditions + obj.AddMethod('org.freedesktop.login1.Session', 'SetBrightness', 'ssu', '', 'import time; time.sleep(0.1); open(os.path.join("/sys/class/" + args[0] + "/" + args[1] + "/brightness"), "w", encoding="ascii").write(str(args[2]))') def stop_logind(self): '''stop mock logind''' |