[gnome-settings-daemon/wip/benzea/sysfs-backlight-switch: 16/16] power: Build and test sysfs backlight support only on Linux
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/benzea/sysfs-backlight-switch: 16/16] power: Build and test sysfs backlight support only on Linux
- Date: Sat, 23 Feb 2019 10:39:43 +0000 (UTC)
commit 03a0ac61f03701424d77c74bc66f47f757552cb3
Author: Benjamin Berg <bberg redhat com>
Date: Thu Jan 24 15:43:48 2019 +0100
power: Build and test sysfs backlight support only on Linux
Configuring the backlight using sysfs is only supported on linux. We
depend on GUdev on linux, so that we can just check for the platform.
This avoids enabling the sysfs backlight helper on platforms that have
GUdev but do not support backlight control using sysfs.
plugins/power/gsd-backlight.c | 28 ++++++++++++++--------------
plugins/power/meson.build | 5 +++--
plugins/power/test.py | 35 +++++++++++++++++++++++++++++++----
3 files changed, 48 insertions(+), 20 deletions(-)
---
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c
index 8b810619..e60c649d 100644
--- a/plugins/power/gsd-backlight.c
+++ b/plugins/power/gsd-backlight.c
@@ -25,9 +25,9 @@
#include "gsd-power-constants.h"
#include "gsd-power-manager.h"
-#ifdef HAVE_GUDEV
+#ifdef __linux__
#include <gudev/gudev.h>
-#endif /* HAVE_GUDEV */
+#endif /* __linux__ */
struct _GsdBacklight
{
@@ -39,7 +39,7 @@ struct _GsdBacklight
gint brightness_target;
gint brightness_step;
-#ifdef HAVE_GUDEV
+#ifdef __linux__
GUdevClient *udev;
GUdevDevice *udev_device;
@@ -47,7 +47,7 @@ struct _GsdBacklight
GQueue tasks;
gint idle_update;
-#endif
+#endif /* __linux__ */
GnomeRRScreen *rr_screen;
gboolean builtin_display_disabled;
@@ -71,7 +71,7 @@ G_DEFINE_TYPE_EXTENDED (GsdBacklight, gsd_backlight, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
gsd_backlight_initable_iface_init);)
-#ifdef HAVE_GUDEV
+#ifdef __linux__
static GUdevDevice*
gsd_backlight_udev_get_type (GList *devices, const gchar *type)
{
@@ -396,7 +396,7 @@ gsd_backlight_process_taskqueue (GsdBacklight *backlight)
/* And run it! */
gsd_backlight_run_set_helper (backlight, to_run);
}
-#endif /* HAVE_GUDEV */
+#endif /* __linux__ */
static GnomeRROutput*
gsd_backlight_rr_find_output (GsdBacklight *backlight, gboolean controllable)
@@ -471,7 +471,7 @@ gsd_backlight_set_brightness_val_async (GsdBacklight *backlight,
task = g_task_new (backlight, cancellable, callback, user_data);
-#ifdef HAVE_GUDEV
+#ifdef __linux__
if (backlight->udev_device != NULL) {
BacklightHelperData *task_data;
@@ -485,7 +485,7 @@ gsd_backlight_set_brightness_val_async (GsdBacklight *backlight,
return;
}
-#endif /* HAVE_GUDEV */
+#endif /* __linux__ */
/* Fallback to setting via GNOME RR/X11 */
output = gsd_backlight_rr_find_output (backlight, TRUE);
@@ -752,11 +752,11 @@ gsd_backlight_initable_init (GInitable *initable,
return FALSE;
}
-#ifdef HAVE_GUDEV
+#ifdef __linux__
/* Try finding a udev device. */
if (gsd_backlight_udev_init (backlight))
goto found;
-#endif /* HAVE_GUDEV */
+#endif /* __linux__ */
/* Try GNOME RR as a fallback. */
output = gsd_backlight_rr_find_output (backlight, TRUE);
@@ -791,7 +791,7 @@ gsd_backlight_finalize (GObject *object)
{
GsdBacklight *backlight = GSD_BACKLIGHT (object);
-#ifdef HAVE_GUDEV
+#ifdef __linux__
g_assert (backlight->active_task == NULL);
g_assert (g_queue_is_empty (&backlight->tasks));
g_clear_object (&backlight->udev);
@@ -800,7 +800,7 @@ gsd_backlight_finalize (GObject *object)
g_source_remove (backlight->idle_update);
backlight->idle_update = 0;
}
-#endif /* HAVE_GUDEV */
+#endif /* __linux__ */
g_clear_object (&backlight->rr_screen);
}
@@ -843,10 +843,10 @@ gsd_backlight_init (GsdBacklight *backlight)
backlight->brightness_val = -1;
backlight->brightness_step = 1;
-#ifdef HAVE_GUDEV
+#ifdef __linux__
backlight->active_task = NULL;
g_queue_init (&backlight->tasks);
-#endif /* HAVE_GUDEV */
+#endif /* __linux__ */
}
GsdBacklight *
diff --git a/plugins/power/meson.build b/plugins/power/meson.build
index 1734c5e5..8babf97f 100644
--- a/plugins/power/meson.build
+++ b/plugins/power/meson.build
@@ -24,7 +24,7 @@ native_deps = [
dependency('gio-2.0', native:true)
]
-if enable_gudev
+if host_is_linux
deps += gudev_dep
endif
@@ -66,7 +66,7 @@ gsd_power_enums_update = executable(
native: true
)
-if enable_gudev
+if host_is_linux
policy = 'org.gnome.settings-daemon.plugins.power.policy'
policy_in = configure_file(
@@ -130,6 +130,7 @@ envs.set('BUILDDIR', meson.current_build_dir())
envs.set('TOP_BUILDDIR', meson.build_root())
envs.set('LD_PRELOAD', 'libumockdev-preload.so.0')
envs.set('NO_AT_BRIDGE', '1')
+envs.set('HAVE_SYSFS_BACKLIGHT', host_is_linux ? '1' : '0')
if get_option('b_sanitize').split(',').contains('address')
# libasan needs to be loaded first; so we need to explicitly preload it
diff --git a/plugins/power/test.py b/plugins/power/test.py
index 8e3bde86..1faa7924 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -60,6 +60,11 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
# device based on the name of the test.
self.add_backlight()
+ if 'HAVE_SYSFS_BACKLIGHT' in os.environ and os.environ['HAVE_SYSFS_BACKLIGHT'] == 1:
+ self.skip_sysfs_backlight = False
+ else:
+ self.skip_sysfs_backlight = True
+
# start mock upowerd
(self.upowerd, self.obj_upower) = self.spawn_server_template(
'upower', {'DaemonVersion': '0.99', 'OnBattery': True, 'LidIsClosed': False},
stdout=subprocess.PIPE)
@@ -544,7 +549,8 @@ class PowerPluginTest1(PowerPluginBase):
time.sleep(0.5)
self.reset_idle_timer()
self.check_unblank(2)
- self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 'incorrect
unblanked brightness (%d != %d)' % (self.get_brightness(), gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
+ if not self.skip_sysfs_backlight:
+ self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS ,
'incorrect unblanked brightness (%d != %d)' % (self.get_brightness(),
gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
# Check for no blank before the normal blank timeout
self.check_no_blank(gsdpowerconstants.SCREENSAVER_TIMEOUT_BLANK - 4)
@@ -796,8 +802,9 @@ class PowerPluginTest5(PowerPluginBase):
self.check_dim(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY + 1)
# Give time for the brightness to change
time.sleep(2)
- level = self.get_brightness();
- self.assertTrue(level == dim_level, 'incorrect dim brightness (%d != %d)' % (level, dim_level))
+ if not self.skip_sysfs_backlight:
+ level = self.get_brightness();
+ self.assertTrue(level == dim_level, 'incorrect dim brightness (%d != %d)' % (level, dim_level))
self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE)
@@ -817,7 +824,8 @@ class PowerPluginTest5(PowerPluginBase):
time.sleep(1)
# And check that we have the pre-dim brightness
- self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 'incorrect
unblanked brightness (%d != %d)' % (self.get_brightness(), gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
+ if not self.skip_sysfs_backlight:
+ self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS ,
'incorrect unblanked brightness (%d != %d)' % (self.get_brightness(),
gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
def test_lid_close_inhibition(self):
'''Check that we correctly inhibit suspend with an external monitor'''
@@ -1049,6 +1057,9 @@ class PowerPluginTest8(PowerPluginBase):
def test_brightness_stepping(self):
'''Check that stepping the backlight works as expected'''
+ if self.skip_sysfs_backlight:
+ self.skipTest("sysfs backlight support required for test")
+
obj_gsd_power = self.session_bus_con.get_object(
'org.gnome.SettingsDaemon.Power', '/org/gnome/SettingsDaemon/Power')
obj_gsd_power_screen_iface = dbus.Interface(obj_gsd_power, 'org.gnome.SettingsDaemon.Power.Screen')
@@ -1104,6 +1115,10 @@ class PowerPluginTest8(PowerPluginBase):
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
@@ -1126,6 +1141,9 @@ class PowerPluginTest8(PowerPluginBase):
self.assertEqual(self.get_brightness(), 90)
def test_brightness_uevent(self):
+ if self.skip_sysfs_backlight:
+ self.skipTest("sysfs backlight support required for test")
+
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)
@@ -1146,18 +1164,27 @@ class PowerPluginTest8(PowerPluginBase):
self.assertEqual(80, brightness)
def test_brightness_step(self):
+ if self.skip_sysfs_backlight:
+ self.skipTest("sysfs backlight support required for test")
+
# We cannot use check_plugin_log here because the startup check already
# read the relevant message.
log = open(self.plugin_log_write.name, 'rb').read()
self.assertIn(b'Step size for backlight is 5.', log)
def test_legacy_brightness_step(self):
+ if self.skip_sysfs_backlight:
+ self.skipTest("sysfs backlight support required for test")
+
# We cannot use check_plugin_log here because the startup check already
# read the relevant message.
log = open(self.plugin_log_write.name, 'rb').read()
self.assertIn(b'Step size for backlight is 1.', log)
def test_legacy_brightness_rounding(self):
+ if self.skip_sysfs_backlight:
+ self.skipTest("sysfs backlight support required for test")
+
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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]