mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-09 05:58:24 +02:00
test: the test for CriticalPowerAction=Suspend
The test cases for AllowRiskyCriticalPowerAction=true and false when CriticalPowerAction=Suspend.
This commit is contained in:
parent
69436647c5
commit
544eba5543
1 changed files with 95 additions and 0 deletions
|
|
@ -1237,6 +1237,101 @@ class Tests(dbusmock.DBusTestCase):
|
|||
|
||||
os.unlink(config.name)
|
||||
|
||||
def test_critical_action_is_suspend_and_AllowRiskyCriticalPowerAction_is_true(self):
|
||||
'''check that critical action is 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("AllowRiskyCriticalPowerAction=true\n")
|
||||
config.write("CriticalPowerAction=Suspend\n")
|
||||
config.close()
|
||||
|
||||
self.start_daemon(cfgfile=config.name, warns=True)
|
||||
|
||||
devs = self.proxy.EnumerateDevices()
|
||||
self.assertEqual(len(devs), 1)
|
||||
bat0_up = devs[0]
|
||||
|
||||
# check warning message when CriticalPowerAction=Suspend and AllowRiskyCriticalPowerAction=true
|
||||
self.daemon_log.check_line(
|
||||
"The \"Suspend\" CriticalPowerAction setting is considered risky:"
|
||||
" abrupt power loss due to battery exhaustion may lead to data"
|
||||
" corruption. Use AllowRiskyCriticalPowerAction=false to disable"
|
||||
" support for risky settings.",
|
||||
timeout=UP_DAEMON_ACTION_DELAY + 0.5)
|
||||
|
||||
# simulate that battery has 1% (less than PercentageAction)
|
||||
self.testbed.set_attribute(bat0, 'energy_now', '600000')
|
||||
self.testbed.uevent(bat0, 'change')
|
||||
|
||||
time.sleep(0.5)
|
||||
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
|
||||
|
||||
self.daemon_log.check_line("About to call logind method Suspend", timeout=UP_DAEMON_ACTION_DELAY + 0.5)
|
||||
|
||||
self.stop_daemon()
|
||||
|
||||
os.unlink(config.name)
|
||||
|
||||
def test_critical_action_is_suspend_and_AllowRiskyCriticalPowerAction_is_false(self):
|
||||
'''check that critical action is 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("AllowRiskyCriticalPowerAction=false\n")
|
||||
config.write("CriticalPowerAction=Suspend\n")
|
||||
config.close()
|
||||
|
||||
self.start_daemon(cfgfile=config.name, warns=True)
|
||||
|
||||
devs = self.proxy.EnumerateDevices()
|
||||
self.assertEqual(len(devs), 1)
|
||||
bat0_up = devs[0]
|
||||
|
||||
# check warning message when CriticalPowerAction=Suspend and AllowRiskyCriticalPowerAction=false
|
||||
self.daemon_log.check_line(
|
||||
"The \"Suspend\" CriticalPowerAction setting is considered risky:"
|
||||
" abrupt power loss due to battery exhaustion may lead to data"
|
||||
" corruption. The system will perform \"HybridSleep\" instead."
|
||||
" Use AllowRiskyCriticalPowerAction=true to enable support for"
|
||||
" risky settings.",
|
||||
timeout=UP_DAEMON_ACTION_DELAY + 0.5)
|
||||
|
||||
# simulate that battery has 1% (less than PercentageAction)
|
||||
self.testbed.set_attribute(bat0, 'energy_now', '600000')
|
||||
self.testbed.uevent(bat0, 'change')
|
||||
|
||||
time.sleep(0.5)
|
||||
self.assertEqual(self.get_dbus_display_property('WarningLevel'), UP_DEVICE_LEVEL_ACTION)
|
||||
|
||||
self.daemon_log.check_line("About to call logind method HybridSleep", timeout=UP_DAEMON_ACTION_DELAY + 0.5)
|
||||
|
||||
self.stop_daemon()
|
||||
|
||||
os.unlink(config.name)
|
||||
|
||||
def test_low_battery_changes_history_save_interval(self):
|
||||
'''check that we save the history more quickly on low battery'''
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue