From 544eba5543517c278498999cd2bd2d66fb6394fa Mon Sep 17 00:00:00 2001 From: Kate Hsuan Date: Wed, 24 Apr 2024 16:18:09 +0800 Subject: [PATCH] test: the test for CriticalPowerAction=Suspend The test cases for AllowRiskyCriticalPowerAction=true and false when CriticalPowerAction=Suspend. --- src/linux/integration-test.py | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/src/linux/integration-test.py b/src/linux/integration-test.py index 1ff58d2..5f5fc03 100755 --- a/src/linux/integration-test.py +++ b/src/linux/integration-test.py @@ -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'''