diff --git a/providers/base/units/suspend/suspend.pxu b/providers/base/units/suspend/suspend.pxu index d1c45640e0..eb992dda75 100644 --- a/providers/base/units/suspend/suspend.pxu +++ b/providers/base/units/suspend/suspend.pxu @@ -48,6 +48,16 @@ estimated_duration: 1.2 _summary: Dumps memory info to a file for comparison after suspend command: meminfo_resource.py > "$PLAINBOX_SESSION_SHARE"/meminfo_before_suspend +plugin: shell +category_id: com.canonical.plainbox::suspend +id: suspend/power_mode_before_suspend +estimated_duration: 1.2 +requires: + module.name == 'platform_profile' + package.name == 'power-profiles-daemon' +_summary: Dumps power_mode info to a file for comparison after suspend +command: power_mode_resource.py > "$PLAINBOX_SESSION_SHARE"/power_mode_before_suspend + unit: template template-resource: device template-filter: device.category == 'NETWORK' @@ -583,6 +593,30 @@ _description: Verify that all memory is available after resuming from suspend. command: meminfo_resource.py | diff "$PLAINBOX_SESSION_SHARE"/meminfo_before_suspend - +plugin: shell +category_id: com.canonical.plainbox::suspend +id: suspend/power_mode_after_suspend +estimated_duration: 1.2 +requires: + module.name == 'platform_profile' + package.name == 'power-profiles-daemon' +depends: suspend/suspend_advanced_auto suspend/power_mode_before_suspend +_description: + Verify that power mode is changed after resuming from suspend. +command: power_mode_resource.py | diff "$PLAINBOX_SESSION_SHARE"/power_mode_before_suspend - + +plugin: shell +category_id: com.canonical.plainbox::suspend +id: suspend/power_mode_after_suspend_auto +estimated_duration: 1.2 +requires: + module.name == 'platform_profile' + package.name == 'power-profiles-daemon' +depends: suspend/suspend_advanced_auto suspend/power_mode_before_suspend +_description: + Verify that power mode is changed after resuming from suspend. +command: power_mode_resource.py | diff "$PLAINBOX_SESSION_SHARE"/power_mode_before_suspend - + plugin: manual category_id: com.canonical.plainbox::suspend id: suspend/display_after_suspend diff --git a/providers/resource/bin/power_mode_resource.py b/providers/resource/bin/power_mode_resource.py new file mode 100755 index 0000000000..46474a9669 --- /dev/null +++ b/providers/resource/bin/power_mode_resource.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# This file is part of Checkbox. +# +# Copyright 2023 Canonical Ltd. +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. + +# +# Checkbox is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Checkbox. If not, see . +# + +"""Modules providing a function running os or sys commands.""" +import sys +import os + + +def main(): + """Dump the power mode.""" + sysfs_root = "/sys/firmware/acpi/" + if not os.path.isdir(sysfs_root): + return 1 + + profile_filename = os.path.join(sysfs_root, "platform_profile") + if (not os.path.isfile(profile_filename) or + not os.access(profile_filename, os.R_OK)): + return 1 + + with open(profile_filename, "rt", encoding="utf-8") as stream: + profile = stream.read().strip().split() + if len(profile) < 1: + return 1 + else: + print(profile[0]) + # uncomment the following line to do local testing + #os.system(f"powerprofilesctl set power-saver") + return 0 + + +if __name__ == "__main__": + sys.exit(main())