summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Van Assche <me@dylanvanassche.be>2021-08-10 13:27:56 +0200
committerBastien Nocera <hadess@hadess.net>2021-08-17 14:31:25 +0200
commit3acbedca26619e6313f70b147024c1c3b92efbd9 (patch)
tree971679a8e9673108885809ade4f997cffa105014
parent0dc2a521be870d9663a459a03f5ec38a7e33e6ab (diff)
downloadupower-3acbedca26619e6313f70b147024c1c3b92efbd9.tar.gz
tests: Test inhibitor lock for critical action
Inhibitor lock should be taken between the critical action notification and the execution of the critical action. Requires python-dbusmock > 0.23.1, test is skipped on lower versions. python-dbusmock in the CI is installed from git and bumped version to 0.23.2 until a new release is available.
-rw-r--r--.gitlab-ci.yml9
-rwxr-xr-xsrc/linux/integration-test55
2 files changed, 59 insertions, 5 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b83f7aa..ba1b79b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,12 +22,19 @@ variables:
libplist-devel
umockdev
python3-dbus
- python3-dbusmock
+ python3-pip
+ python3-packaging
+ git
LAST_ABI_BREAK: "e294444496e8bbcd91a3605874f59562e14c34ec"
build_stable:
before_script:
- dnf update -y --nogpgcheck && dnf install -y --nogpgcheck $DEPENDENCIES
+ - git clone https://github.com/martinpitt/python-dbusmock.git /tmp/python-dbusmock
+ - echo '## [0.23.2] - UNRELEASED' | cat - /tmp/python-dbusmock/NEWS > /tmp/python-dbusmock/NEWS.tmp
+ - mv /tmp/python-dbusmock/NEWS.tmp /tmp/python-dbusmock/NEWS
+ - sed -i 's,0.23.1,0.23.2,' /tmp/python-dbusmock/dbusmock/__init__.py
+ - pip install /tmp/python-dbusmock
script:
- mkdir _build
- cd _build
diff --git a/src/linux/integration-test b/src/linux/integration-test
index 211f445..2a54417 100755
--- a/src/linux/integration-test
+++ b/src/linux/integration-test
@@ -24,6 +24,7 @@ import tempfile
import subprocess
import unittest
import time
+from packaging.version import parse as parse_version
try:
import gi
@@ -52,6 +53,7 @@ except ImportError:
UP = 'org.freedesktop.UPower'
UP_DEVICE = 'org.freedesktop.UPower.Device'
UP_DISPLAY_OBJECT_PATH = '/org/freedesktop/UPower/devices/DisplayDevice'
+UP_DAEMON_ACTION_DELAY = 20
DEVICE_IFACE = 'org.bluez.Device1'
BATTERY_IFACE = 'org.bluez.Battery1'
@@ -292,7 +294,7 @@ class Tests(dbusmock.DBusTestCase):
with open(self.log.name) as f:
return f.read().count(text)
- def assertEventually(self, condition, message=None, timeout=50):
+ def assertEventually(self, condition, message=None, timeout=50, value=True):
'''Assert that condition function eventually returns True.
Timeout is in deciseconds, defaulting to 50 (5 seconds). message is
@@ -302,7 +304,7 @@ class Tests(dbusmock.DBusTestCase):
context = GLib.MainContext.default()
while context.iteration(False):
pass
- if condition():
+ if condition() == value:
break
timeout -= 1
time.sleep(0.1)
@@ -979,6 +981,51 @@ class Tests(dbusmock.DBusTestCase):
self.stop_daemon()
+ @unittest.skipIf(parse_version(dbusmock.__version__) <= parse_version('0.23.1'), 'Not supported in dbusmock version')
+ def test_prevent_sleep_until_critical_action_is_executed(self):
+ '''check that critical action is executed when trying to suspend'''
+
+ bat0 = self.testbed.add_device('power_supply', 'BAT0', None,
+ ['type', 'Battery',
+ 'present', '1',
+ 'status', 'Discharging',
+ 'energy_full', '60000000',
+ 'energy_full_design', '80000000',
+ 'energy_now', '50000000',
+ 'voltage_now', '12000000'], [])
+
+ config = tempfile.NamedTemporaryFile(delete=False, mode='w')
+ config.write("[UPower]\n")
+ config.write("UsePercentageForPolicy=true\n")
+ config.write("PercentageAction=5\n")
+ config.write("CriticalPowerAction=Hibernate\n")
+ config.close()
+
+ self.start_logind()
+ self.start_daemon(cfgfile=config.name)
+
+ # delay inhibitor taken
+ self.assertEqual(len(self.logind_obj.ListInhibitors()), 1)
+
+ devs = self.proxy.EnumerateDevices()
+ self.assertEqual(len(devs), 1)
+ bat0_up = devs[0]
+
+ # simulate that battery has 1% (less than PercentageAction)
+ self.testbed.set_attribute(bat0, 'energy_now', '600000')
+ self.testbed.uevent(bat0, 'change')
+
+ # critical action is scheduled, a block inhibitor lock is taken besides a delay inhibitor lock
+ time.sleep(0.5)
+ self.assertEventually(lambda: self.get_dbus_display_property('WarningLevel'), value=UP_DEVICE_LEVEL_ACTION)
+ self.assertEqual(len(self.logind_obj.ListInhibitors()), 2)
+
+ time.sleep(UP_DAEMON_ACTION_DELAY + 0.5) # wait for UP_DAEMON_ACTION_DELAY
+ self.assertEqual(self.count_text_in_log("About to call logind method Hibernate"), 1)
+
+ # block inhibitor lock is released
+ self.assertEqual(len(self.logind_obj.ListInhibitors()), 1)
+
def test_critical_action_is_taken_repeatedly(self):
'''check that critical action works repeatedly (eg. after resume)'''
@@ -1012,7 +1059,7 @@ class Tests(dbusmock.DBusTestCase):
time.sleep(0.5)
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
- time.sleep(20.5) # wait for UP_DAEMON_ACTION_DELAY
+ time.sleep(UP_DAEMON_ACTION_DELAY + 0.5) # wait for UP_DAEMON_ACTION_DELAY
self.assertEqual(self.count_text_in_log("About to call logind method Hibernate"), 1)
# simulate that battery was charged to 100% during sleep
@@ -1029,7 +1076,7 @@ class Tests(dbusmock.DBusTestCase):
time.sleep(0.5)
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
- time.sleep(20.5) # wait for UP_DAEMON_ACTION_DELAY
+ time.sleep(UP_DAEMON_ACTION_DELAY + 0.5) # wait for UP_DAEMON_ACTION_DELAY
self.assertEqual(self.count_text_in_log("About to call logind method Hibernate"), 2)
self.stop_daemon()