diff options
-rwxr-xr-x | bin/pm_test | 64 | ||||
-rw-r--r-- | units/power-management/jobs.pxu | 4 | ||||
-rw-r--r-- | units/stress/jobs.pxu | 9 |
3 files changed, 50 insertions, 27 deletions
diff --git a/bin/pm_test b/bin/pm_test index a5cd024..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): """ @@ -575,11 +597,11 @@ autologin-user-timeout=0 shutil.copystat(self.config_filename, backup_filename) break - with open(self.config_filename, 'w') as f: - if self.config_filename == '/etc/lightdm/lightdm.conf': - f.write(self.template.format(username=self.user)) - elif self.config_filename == '/etc/gdm3/custom.conf': - self.parser.write(f) + with open(self.config_filename, 'w') as f: + if self.config_filename == '/etc/lightdm/lightdm.conf': + f.write(self.template.format(username=self.user)) + elif self.config_filename == '/etc/gdm3/custom.conf': + self.parser.write(f) def disable(self): """ diff --git a/units/power-management/jobs.pxu b/units/power-management/jobs.pxu index be640c3..9f8f62e 100644 --- a/units/power-management/jobs.pxu +++ b/units/power-management/jobs.pxu @@ -36,7 +36,7 @@ id: power-management/poweroff estimated_duration: 120.0 depends: power-management/fwts_wakealarm user: root -environ: PLAINBOX_SESSION_SHARE +environ: PLAINBOX_SESSION_SHARE PM_TEST_DRY_RUN requires: executable.name == 'fwts' command: pm_test --silent --checkbox-respawn-cmd $PLAINBOX_SESSION_SHARE/__respawn_checkbox poweroff --log-level=debug --log-dir=$PLAINBOX_SESSION_SHARE flags: noreturn @@ -58,7 +58,7 @@ category_id: com.canonical.plainbox::power-management id: power-management/reboot estimated_duration: 120.0 user: root -environ: PLAINBOX_SESSION_SHARE +environ: PLAINBOX_SESSION_SHARE PM_TEST_DRY_RUN requires: executable.name == 'fwts' command: pm_test --silent --checkbox-respawn-cmd $PLAINBOX_SESSION_SHARE/__respawn_checkbox reboot --log-level=debug --log-dir=$PLAINBOX_SESSION_SHARE flags: noreturn diff --git a/units/stress/jobs.pxu b/units/stress/jobs.pxu index 8d25af9..e0c2e0a 100644 --- a/units/stress/jobs.pxu +++ b/units/stress/jobs.pxu @@ -76,6 +76,7 @@ requires: executable.name == 'x-terminal-emulator' flags: noreturn user: root +environ: PM_TEST_DRY_RUN command: pm_test reboot --checkbox-respawn-cmd $PLAINBOX_SESSION_SHARE/__respawn_checkbox --fwts --log-level=debug --log-dir=$PLAINBOX_SESSION_SHARE --suspends-before-reboot=30 -r 3 --silent _description: @@ -226,7 +227,7 @@ requires: executable.name == 'fwts' command: pm_test --checkbox-respawn-cmd $PLAINBOX_SESSION_SHARE/__respawn_checkbox -r 100 --silent --log-level=notset reboot --log-dir=$PLAINBOX_SESSION_SHARE flags: noreturn user: root -environ: PLAINBOX_SESSION_SHARE +environ: PLAINBOX_SESSION_SHARE PM_TEST_DRY_RUN _description: Stress reboot system (100 cycles) @@ -248,7 +249,7 @@ command: pm_test --checkbox-respawn-cmd $PLAINBOX_SESSION_SHARE/__respawn_checkb flags: noreturn estimated_duration: 2700 user: root -environ: PLAINBOX_SESSION_SHARE +environ: PLAINBOX_SESSION_SHARE PM_TEST_DRY_RUN _description: Stress reboot system (30 cycles) @@ -270,7 +271,7 @@ requires: command: pm_test --checkbox-respawn-cmd $PLAINBOX_SESSION_SHARE/__respawn_checkbox -r 100 --silent --log-level=notset poweroff --log-dir=$PLAINBOX_SESSION_SHARE flags: noreturn user: root -environ: PLAINBOX_SESSION_SHARE +environ: PLAINBOX_SESSION_SHARE PM_TEST_DRY_RUN _description: Stress poweroff system (100 cycles) @@ -293,7 +294,7 @@ command: pm_test --checkbox-respawn-cmd $PLAINBOX_SESSION_SHARE/__respawn_checkb flags: noreturn estimated_duration: 3600 user: root -environ: PLAINBOX_SESSION_SHARE +environ: PLAINBOX_SESSION_SHARE PM_TEST_DRY_RUN _description: Stress poweroff system (30 cycles) |