Exemplo n.º 1
0
def do_suspend(suspend_seconds, delay_seconds=0):
    """Do a suspend using the power manager.

    Wait for |delay_seconds|, suspend the system to RAM (S3), waking up again
    after having been suspended for |suspend_seconds|, using the
    powerd_dbus_suspend program. Function will block until suspend/resume
    has completed or failed. Returns the wake alarm time from the RTC as epoch.

    @param suspend_seconds: Number of seconds to suspend the DUT.
    @param delay_seconds: Number of seconds wait before suspending the DUT.

    """

    # stop check_ethernet.hook from running until the test exits
    global pause_ethernet_fd
    if pause_ethernet_fd == 0:
        # we don't write to the file - but we might need to create it.
        pause_ethernet_fd = open(PAUSE_ETHERNET_HOOK_FILE, 'a+')

        if pause_ethernet_fd > 0:
            try:
                # this is a blocking call unless an error occurs.
                fcntl.flock(pause_ethernet_fd, fcntl.LOCK_SH)
            except IOError:
                pass

    alarm, wakeup_count = prepare_wakeup(suspend_seconds)
    upstart.ensure_running('powerd')
    command = ('/usr/bin/powerd_dbus_suspend --delay=%d --timeout=30 '
               '--wakeup_count=%d') % (delay_seconds, wakeup_count)
    logging.info("Running '%s'", command)
    os.system(command)
    check_wakeup(alarm)
    return alarm
def suspend_bg_for_dark_resume(delay_seconds=0):
    """Do a non-blocking indefinite suspend using power manager. ONLY USE THIS
    IF YOU ARE ABSOLUTELY CERTAIN YOU NEED TO.

    Wait for |delay_seconds|, then suspend to RAM (S3). This does not set an RTC
    alarm and does not pass an external wakeup count. It is meant to be used for
    dark resume testing, where the server-side API exposes it in such a fashion
    that the DUT will be woken by the server no matter how the test is exited.

    @param delay_seconds: Number of seconds wait before suspending the DUT.

    """
    upstart.ensure_running('powerd')
    command = ('/usr/bin/powerd_dbus_suspend --delay=%d '
               '--timeout=30') % delay_seconds
    logging.info("Running '%s'", command)
    process = multiprocessing.Process(target=os.system, args=(command, ))
    process.start()
def do_suspend(suspend_seconds, delay_seconds=0):
    """Do a suspend using the power manager.

    Wait for |delay_seconds|, suspend the system to RAM (S3), waking up again
    after having been suspended for |suspend_seconds|, using the
    powerd_dbus_suspend program. Function will block until suspend/resume
    has completed or failed. Returns the wake alarm time from the RTC as epoch.

    @param suspend_seconds: Number of seconds to suspend the DUT.
    @param delay_seconds: Number of seconds wait before suspending the DUT.

    """
    alarm, wakeup_count = prepare_wakeup(suspend_seconds)
    upstart.ensure_running('powerd')
    command = ('/usr/bin/powerd_dbus_suspend --delay=%d --timeout=30 '
               '--wakeup_count=%d') % (delay_seconds, wakeup_count)
    logging.info("Running '%s'", command)
    os.system(command)
    check_wakeup(alarm)
    return alarm
Exemplo n.º 4
0
    def run_upstart_tests(self):
        """
        Run some sanity tests for cupsd and the upstart-socket-bridge
        socket-activation.
        """
        upstart.ensure_running('upstart-socket-bridge')

        if not self.wait_for_path_exists(self._CUPS_SOCK_PATH):
            raise error.TestFail('Missing CUPS socket: %s',
                                 self._CUPS_SOCK_PATH)

        # Make sure CUPS is stopped, so we can test on-demand launch.
        if upstart.is_running('cupsd'):
            upstart.stop_job('cupsd')

        self.check_cups_is_responding()

        # Now try stopping socket bridge, to see it clean up its files.
        upstart.stop_job('upstart-socket-bridge')
        upstart.stop_job('cupsd')

        if os.path.exists(self._CUPS_SOCK_PATH):
            raise error.TestFail('CUPS socket was not cleaned up: %s',
                                 self._CUPS_SOCK_PATH)

        # Create dummy file, to see if upstart-socket-bridge will clear it out
        # properly.
        utils.system('touch %s' % self._CUPS_SOCK_PATH)

        upstart.restart_job('upstart-socket-bridge')

        if not os.path.exists(self._CUPS_SOCK_PATH):
            raise error.TestFail('Missing CUPS socket: %s',
                                 self._CUPS_SOCK_PATH)

        self.check_cups_is_responding()