diff options
author | Maciej Kisielewski <maciej.kisielewski@canonical.com> | 2018-06-21 13:44:43 +0200 |
---|---|---|
committer | Maciej Kisielewski <maciej.kisielewski@canonical.com> | 2018-06-21 13:44:43 +0200 |
commit | 29d386b3125c7ed054bd5297b0a756b7c62f2c5e (patch) | |
tree | 9936fa576a1548ba90c36e8c0a8fc14a50365f8c | |
parent | 01ee89075c87a80af3149b4c3fcdafec57e25255 (diff) |
pm_test: introduce dry-run mode
Debugging and improving the pm_test is difficult and time consuming due to the suspend/hibernate cycles and reboots. Also, not all systems support S3/S4 states. To use the dry mode export PM_TEST_DRY_RUN=1 to your environment Signed-off-by: Maciej Kisielewski <maciej.kisielewski@canonical.com>
-rwxr-xr-x | bin/pm_test | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/bin/pm_test b/bin/pm_test index e8e6263..8645907 100755 --- a/bin/pm_test +++ b/bin/pm_test @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +""" +If you're debugging this program, set PM_TEST_DRY_RUN in your environment. +It will make the script not run actual S3, S4, reboot and poweroff commands. +""" import gi import logging import logging.handlers @@ -42,8 +46,13 @@ def main(): logging.debug('Arguments: {0!r}'.format(args)) logging.debug('Extra Arguments: {0!r}'.format(extra_args)) + dry_run = os.environ.get('PM_TEST_DRY_RUN', False) + if dry_run: + logging.info("Running in dry-run mode") + try: - operation = PowerManagementOperation(args, extra_args, user=username) + operation = PowerManagementOperation( + args, extra_args, user=username, dry_run=dry_run) operation.setup() operation.run() except (TestCancelled, TestFailed) as exception: @@ -65,10 +74,11 @@ def main(): class PowerManagementOperation(): SLEEP_TIME = 5 - def __init__(self, args, extra_args, user=None): + def __init__(self, args, extra_args, user=None, dry_run=False): self.args = args self.extra_args = extra_args self.user = user + self.dry_run = dry_run def setup(self): """ @@ -129,11 +139,17 @@ class PowerManagementOperation(): logging.info('Executing new {0!r} operation...' .format(self.args.pm_operation)) logging.debug('Executing: {0!r}...'.format(command_str)) - # The PM operation is performed asynchronously so let's just wait - # indefinitely until it happens and someone comes along to kill us. - # This addresses LP: #1413134 - subprocess.check_call(command_str, shell=True) - signal.pause() + if self.dry_run: + print("\n\nRUNNING IN DRY-RUN MODE") + print("Normally the program would run: {}".format(command_str)) + print("Waiting for Enter instead") + input() + else: + # The PM operation is performed asynchronously so let's just wait + # indefinitely until it happens and someone comes along to kill us. + # This addresses LP: #1413134 + subprocess.check_call(command_str, shell=True) + signal.pause() def run_suspend_cycles(self, cycles_count, fwts): """Run suspend and resume cycles.""" @@ -156,15 +172,21 @@ class PowerManagementOperation(): command_str = command_tpl.format(script_path, cycles_count) logging.info('Running suspend/resume cycles') logging.debug('Executing: {0!r}...'.format(command_str)) - try: - # We call sleep_test or fwts_test script and log its output as it - # contains average times we need to compute global average times - # later. - logging.info(subprocess.check_output( - command_str, universal_newlines=True, shell=True)) - except subprocess.CalledProcessError as e: - logging.error('Error while running {0}:'.format(e.cmd)) - logging.error(e.output) + if self.dry_run: + print("\n\nRUNNING IN DRY-RUN MODE") + print("Normally the program would run: {}".format(command_str)) + print("Waiting for Enter instead") + input() + else: + try: + # We call sleep_test or fwts_test script and log its output as + # it contains average times we need to compute global average + # times later. + logging.info(subprocess.check_output( + command_str, universal_newlines=True, shell=True)) + except subprocess.CalledProcessError as e: + logging.error('Error while running {0}:'.format(e.cmd)) + logging.error(e.output) def summary(self): """ |