[gnome-settings-daemon/wip/benzea/backlight: 7/9] power: Test backlight steps and rounding
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/benzea/backlight: 7/9] power: Test backlight steps and rounding
- Date: Thu, 27 Sep 2018 07:12:57 +0000 (UTC)
commit 94aa286b6e1ffeedbcc4ed124a782ffb6b01decd
Author: Benjamin Berg <bberg redhat com>
Date: Fri Apr 20 18:37:22 2018 +0200
power: Test backlight steps and rounding
This adds a test for the step size and rounding including cases where
the backlight only has very few steps.
plugins/power/gsd-backlight.c | 2 ++
plugins/power/test.py | 63 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 63 insertions(+), 2 deletions(-)
---
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c
index 259a0de7..d72eb34b 100644
--- a/plugins/power/gsd-backlight.c
+++ b/plugins/power/gsd-backlight.c
@@ -743,6 +743,8 @@ found:
backlight->brightness_target = backlight->brightness_val;
backlight->brightness_step = MAX(backlight->brightness_step,
BRIGHTNESS_STEP_AMOUNT(backlight->brightness_max - backlight->brightness_min + 1));
+ g_debug ("Step size for backlight is %i.", backlight->brightness_step);
+
return TRUE;
}
diff --git a/plugins/power/test.py b/plugins/power/test.py
index 86eb74a5..a7fb9fb1 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -54,6 +54,8 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
os.environ['UMOCKDEV_DIR'] = self.testbed.get_root_dir()
# Create a mock backlight device
+ # Note that this function creates a different backlight device based on
+ # the name of the test.
self.add_backlight()
# start mock upowerd
@@ -209,7 +211,17 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
def get_status(self):
return self.obj_session_presence_props.Get('org.gnome.SessionManager.Presence', 'status')
- def add_backlight(self, _type="raw", brightness=50, max_brightness=100):
+ def backlight_defaults(self):
+ # Hack to modify the brightness defaults before starting gsd-power.
+ # The alternative would be to create two separate test files.
+ if 'legacy_brightness' in self.id():
+ return 15, 15
+ else:
+ return 100, 50
+
+ def add_backlight(self, _type="raw"):
+ max_brightness, brightness = self.backlight_defaults()
+
# Undo mangling done in GSD
if max_brightness >= 99:
max_brightness += 1
@@ -222,7 +234,9 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
'brightness', str(brightness)],
[])
- def get_brightness(self, max_brightness=100):
+ def get_brightness(self):
+ max_brightness = int(open(os.path.join(self.testbed.get_root_dir() + self.backlight,
'max_brightness')).read())
+
# self.backlight contains the leading slash, so os.path.join doesn't quite work
res = int(open(os.path.join(self.testbed.get_root_dir() + self.backlight, 'brightness')).read())
# Undo mangling done in GSD
@@ -1107,5 +1121,50 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
time.sleep(1.0)
self.assertEqual(self.get_brightness(), 90)
+ def test_brightness_step(self):
+ # 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):
+ # 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):
+ 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)
+
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 0)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 0)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 10)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 1)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 20)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 3)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 25)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 4)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 50)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 7)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 52)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 8)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 56)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 8)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 57)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 9)
+ obj_gsd_power_prop_iface.Set('org.gnome.SettingsDaemon.Power.Screen', 'Brightness', 98)
+ time.sleep(0.2)
+ self.assertEqual(self.get_brightness(), 15)
+
# avoid writing to stderr
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]