def async_suspend():
    try:
        time.sleep(5) # allow some time to start capturing
        sys_power.kernel_suspend(10)
    except:
        # Any exception will be re-raised in main process, but the stack trace
        # will be wrong. Log it here with the correct stack trace.
        logging.exception('suspend raised exception')
        raise
Example #2
0
    def _suspend_with_video(self, browser, tab, video_url):
        logging.info('testing %s', video_url)
        tab.EvaluateJavaScript('play("%s")' % video_url)

        self._check_video_is_playing(tab)

        time.sleep(2)
        sys_power.kernel_suspend(10)
        time.sleep(2)

        self._check_video_is_playing(tab)
    def run_once(self):
        # create processs pool with enough workers to spin all CPUs
        cpus = multiprocessing.cpu_count()
        logging.info('found %d cpus', cpus)
        workers = max(16, cpus * 2)
        pool = multiprocessing.Pool(workers)

        try:
            # fill all CPUs with a spinning task
            logging.info('starting %d workers', workers)
            results = [pool.apply_async(cpu_stress) for _ in xrange(workers)]

            # wait for things to settle
            logging.info('spinning for %d seconds', SUSPEND_BURN_SECONDS)
            if sleep_and_measure_cpu(SUSPEND_BURN_SECONDS) < MIN_CPU_USAGE:
                # There should be no idle time accounted while we're spinning.
                raise error.TestError(
                    'unexpected CPU idle time while spinning')

            # go to suspend
            sys_power.kernel_suspend(10)

            # keep spinning after userland resumes
            logging.info('spinning for %d more seconds', RESUME_BURN_SECONDS)
            if sleep_and_measure_cpu(RESUME_BURN_SECONDS) < MIN_CPU_USAGE:
                # There should be no idle time accounted while we're spinning.
                raise error.TestError('unexpected CPU idle time after resume')

            # check workers: if computation completed, something is wrong
            for result in results:
                if result.ready():
                    logging.error('worker finished: %s', result.get())
                    raise error.TestError('worker terminated!')

        finally:
            # kill off the workers
            logging.info('killing %d workers', workers)
            pool.terminate()
Example #4
0
    def run_once(self, resume_percent=70):
        results = {}
        backlight = power_utils.Backlight()

        results['initial_brightness'] = backlight.get_level()
        max_level = backlight.get_max_level()
        resume_level = int(round(max_level * resume_percent / 100))

        # If the current brightness is the same as the requested brightness,
        # request 100 - |resume_brightness| instead.
        if resume_level == results['initial_brightness']:
            resume_level = max_level - resume_level
        backlight.set_resume_level(resume_level)

        sys_power.kernel_suspend(seconds=5)

        final_level = backlight.get_level()
        if final_level != resume_level:
            raise error.TestFail(
                ('Brightness level after resume did not match requested ' + \
                 'brightness: %d vs %d') % (final_level, resume_level))

        results['resume_brightness'] = resume_level
        self.write_perf_keyval(results)
 def run_once(self):
     sys_power.kernel_suspend(10)
 def run_once(self, seconds=10):
     # go to suspend
     sys_power.kernel_suspend(seconds)