Esempio n. 1
0
    def run_once(self, run_time_sec=60):
        if run_time_sec < 10:
            raise error.TestFail('Must run for at least 10 seconds')

        with chrome.Chrome():
            # Audio loop time should be significantly shorter than
            # |run_time_sec| time, so that the total playback time doesn't
            # exceed it by much.
            audio_loop_time_sec = min(10, run_time_sec / 10 + 0.5)

            # Set a low audio volume to avoid annoying people during tests.
            audio_helper.set_volume_levels(10, 100)

            # Start playing audio file.
            self._enable_audio_playback = True
            thread = threading.Thread(target=self._play_audio,
                                      args=(audio_loop_time_sec, ))
            thread.start()

            # Restart powerd with timeouts for quick idle events.
            gap_ms = run_time_sec * 1000 / 4
            dim_ms = min(10000, gap_ms)
            off_ms = min(20000, gap_ms * 2)
            suspend_ms = min(30000, gap_ms * 3)
            prefs = {
                'disable_idle_suspend': 0,
                'ignore_external_policy': 1,
                'plugged_dim_ms': dim_ms,
                'plugged_off_ms': off_ms,
                'plugged_suspend_ms': suspend_ms,
                'unplugged_dim_ms': dim_ms,
                'unplugged_off_ms': off_ms,
                'unplugged_suspend_ms': suspend_ms
            }
            self._pref_change = power_utils.PowerPrefChanger(prefs)

            # Set an alarm to wake up the system in case the audio detector
            # fails and the system suspends.
            alarm_time = rtc.get_seconds() + run_time_sec
            rtc.set_wake_alarm(alarm_time)

            time.sleep(run_time_sec)

            # Stop powerd to avoid suspending when the audio stops.
            utils.system_output('stop powerd')

            # Stop audio and wait for the audio thread to terminate.
            self._enable_audio_playback = False
            thread.join(timeout=(audio_loop_time_sec * 2))
            if thread.is_alive():
                logging.error('Audio thread did not terminate at end of test.')

            # Check powerd's log to make sure that no suspend took place.
            powerd_log_path = '/var/log/power_manager/powerd.LATEST'
            log = open(powerd_log_path, 'r').read()
            if log.find('Starting suspend') != -1:
                err_str = 'System suspended while audio was playing.'
                raise error.TestFail(err_str)
Esempio n. 2
0
    def run_once(self, run_time_sec=60):
        """
        @param run_time_sec: time to run the test
        """
        if run_time_sec < 30:
            raise error.TestError('Must run for at least 30 seconds')

        with chrome.Chrome(init_network_controller=True) as cr:
            # Start powerd if not started.  Set timeouts for quick idle events.
            run_time_ms = run_time_sec * 1000
            # At the time of writing this test, the video detector gets a status
            # update from Chrome every ten seconds.
            dim_ms = 10000
            off_ms = max(3600000, run_time_ms * 10)
            prefs = {
                'has_ambient_light_sensor': 0,
                'ignore_external_policy': 1,
                'plugged_dim_ms': dim_ms,
                'plugged_off_ms': off_ms,
                'unplugged_dim_ms': dim_ms,
                'unplugged_off_ms': off_ms,
            }
            self._pref_change = power_utils.PowerPrefChanger(prefs)

            keyvals = {}

            # Start with max brightness, so we can easily detect dimming.
            power_utils.BacklightController().set_brightness_to_max()
            backlight = power_utils.Backlight()
            initial_brightness = \
                base_utils.wait_for_value(backlight.get_max_level)

            # Open a tab to play video.
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab = cr.browser.tabs[0]
            tab.Navigate(
                cr.browser.platform.http_server.UrlOf(
                    os.path.join(self.bindir, 'fade.html')))
            tab.WaitForDocumentReadyStateToBeComplete()

            # Sleep until the runtime is up.
            time.sleep(run_time_sec)

            # Stop powerd to avoid dimming when the video stops.
            utils.system_output('stop powerd')

            final_brightness = backlight.get_level()

            # Check that the backlight stayed the same.
            if initial_brightness != final_brightness:
                raise error.TestFail(
                    ('Backlight level changed from %d to %d when it should ' + \
                     'have stayed the same.') %
                    (initial_brightness, final_brightness))

            keyvals['initial_brightness'] = initial_brightness
            keyvals['final_brightness'] = final_brightness
            self.write_perf_keyval(keyvals)
Esempio n. 3
0
 def _configure_suspend_state(self):
     """Configure the suspend state as requested."""
     if self._suspend_state:
         available_suspend_states = utils.read_one_line('/sys/power/state')
         if self._suspend_state not in available_suspend_states:
             raise error.TestNAError('Invalid suspend state: ' +
                                     self._suspend_state)
         # Check the current state. If it is same as the one requested,
         # we don't want to call PowerPrefChanger(restarts powerd).
         if self._suspend_state == power_utils.get_sleep_state():
             return
         should_freeze = '1' if self._suspend_state == 'freeze' else '0'
         new_prefs = {self._SUSPEND_STATE_PREF_FILE: should_freeze}
         self._power_pref_changer = power_utils.PowerPrefChanger(new_prefs)
Esempio n. 4
0
    def run_once(self):
        with chrome.Chrome():
            # Just idle while power_SuspendStress does all the work. Existence
            # of the HWCLOCK_FILE tells us when it starts and when it's done.
            for _ in xrange(self._TEST_START_TIMEOUT):
                time.sleep(1)
                if os.path.exists(power_suspend.Suspender.HWCLOCK_FILE):
                    break
            else:
                raise error.TestError("Parallel test didn't create Suspender.")

            # These must not be enabled too soon, or the system might suspend
            # before a wakeup is scheduled. They must not be disabled too late
            # either, or we might suspend again after the parallel test is done.
            power_prefs = power_utils.PowerPrefChanger(self._IDLE_TIMINGS)

            while os.path.exists(power_suspend.Suspender.HWCLOCK_FILE):
                time.sleep(1)

            power_prefs.finalize()
    def run_once(self, run_time_sec=60):
        if run_time_sec < 10:
            raise error.TestFail('Must run for at least 10 seconds')

        with chrome.Chrome():
            # Audio loop time should be significantly shorter than
            # |run_time_sec| time, so that the total playback time doesn't
            # exceed it by much.
            audio_loop_time_sec = min(10, run_time_sec / 10 + 0.5)

            # Set a low audio volume to avoid annoying people during tests.
            audio_helper.set_volume_levels(10, 100)

            # Start a subprocess that uses dbus-monitor to listen for suspend
            # announcements from powerd and writes the output to a log.
            dbus_log_fd, dbus_log_name = tempfile.mkstemp()
            os.unlink(dbus_log_name)
            dbus_log = os.fdopen(dbus_log_fd)
            dbus_proc = subprocess.Popen(
                'dbus-monitor --monitor --system ' +
                '"type=\'signal\',interface=\'org.chromium.PowerManager\',' +
                'member=\'SuspendImminent\'"',
                shell=True,
                stdout=dbus_log)

            # Start playing audio file.
            self._enable_audio_playback = True
            thread = threading.Thread(target=self._play_audio,
                                      args=(audio_loop_time_sec, ))
            thread.start()

            # Restart powerd with timeouts for quick idle events.
            gap_ms = run_time_sec * 1000 / 4
            dim_ms = min(10000, gap_ms)
            off_ms = min(20000, gap_ms * 2)
            suspend_ms = min(30000, gap_ms * 3)
            prefs = {
                'disable_idle_suspend': 0,
                'ignore_external_policy': 1,
                'plugged_dim_ms': dim_ms,
                'plugged_off_ms': off_ms,
                'plugged_suspend_ms': suspend_ms,
                'unplugged_dim_ms': dim_ms,
                'unplugged_off_ms': off_ms,
                'unplugged_suspend_ms': suspend_ms
            }
            self._pref_change = power_utils.PowerPrefChanger(prefs)

            # Set an alarm to wake up the system in case the audio detector
            # fails and the system suspends.
            alarm_time = rtc.get_seconds() + run_time_sec
            rtc.set_wake_alarm(alarm_time)

            time.sleep(run_time_sec)

            # Stop powerd to avoid suspending when the audio stops.
            utils.system_output('stop powerd')

            # Stop audio and wait for the audio thread to terminate.
            self._enable_audio_playback = False
            thread.join(timeout=(audio_loop_time_sec * 2))
            if thread.is_alive():
                logging.error('Audio thread did not terminate at end of test.')

            # Check the D-Bus log to make sure that no suspend took place.
            # dbus-monitor logs messages about its initial connection to the bus
            # in addition to the signals that we asked it for, so look for the
            # signal name in its output.
            dbus_proc.kill()
            dbus_log.seek(0)
            if 'SuspendImminent' in dbus_log.read():
                err_str = 'System suspended while audio was playing.'
                raise error.TestFail(err_str)
Esempio n. 6
0
    def run_once(self):
        # Require that this test be run on battery with at least 5% charge
        status = power_status.get_status()
        status.assert_battery_state(5)

        prefs = {
            'has_ambient_light_sensor': 0,
            'ignore_external_policy': 1,
            'plugged_dim_ms': 7200000,
            'plugged_off_ms': 9000000,
            'plugged_suspend_ms': 18000000,
            'unplugged_dim_ms': 7200000,
            'unplugged_off_ms': 9000000,
            'unplugged_suspend_ms': 18000000
        }
        self._pref_change = power_utils.PowerPrefChanger(prefs)

        keyvals = {}
        num_errors = 0

        # These are the expected ratios of energy rate between max, min, and off
        # (zero) brightness levels.  e.g. when changing from max to min, the
        # energy rate must become <= (max_energy_rate * max_to_min_factor).
        max_to_min_factor = \
            1.0 - self._energy_rate_change_threshold_percent / 100.0
        min_to_off_factor = \
            1.0 - self._energy_rate_change_threshold_percent / 100.0
        off_to_max_factor = 1.0 / (max_to_min_factor * min_to_off_factor)

        # Determine the number of outputs that are on.
        starting_num_outputs_on = get_num_outputs_on()
        if starting_num_outputs_on == 0:
            raise error.TestFail('At least one display output must be on.')
        keyvals['starting_num_outputs_on'] = starting_num_outputs_on

        self._backlight = power_utils.Backlight()
        keyvals['max_brightness'] = self._backlight.get_max_level()
        if keyvals['max_brightness'] <= self._min_num_steps:
            raise error.TestFail('Must have at least %d backlight levels' %
                                 (self._min_num_steps + 1))

        keyvals['initial_brightness'] = self._backlight.get_level()

        self._wait_for_stable_energy_rate()
        keyvals['initial_power_w'] = self._get_current_energy_rate()

        self._backlight_controller = power_utils.BacklightController()
        self._backlight_controller.set_brightness_to_max()

        current_brightness = \
            utils.wait_for_value(self._backlight.get_level,
                                 max_threshold=keyvals['max_brightness'])
        if current_brightness != keyvals['max_brightness']:
            num_errors += 1
            logging.error(('Failed to increase brightness to max, ' + \
                           'brightness is %d.') % current_brightness)
        else:
            self._wait_for_stable_energy_rate()
            keyvals['max_brightness_power_w'] = self._get_current_energy_rate()

        # Set brightness to minimum without going to zero.
        # Note that we don't know what the minimum brightness is, so just set
        # min_threshold=0 to use the timeout to wait for the brightness to
        # settle.
        self._backlight_controller.set_brightness_to_min()
        current_brightness = utils.wait_for_value(
            self._backlight.get_level,
            min_threshold=(keyvals['max_brightness'] / 2 - 1))
        if current_brightness >= keyvals['max_brightness'] / 2 or \
           current_brightness == 0:
            num_errors += 1
            logging.error('Brightness is not at minimum non-zero level: %d' %
                          current_brightness)
        else:
            self._wait_for_stable_energy_rate()
            keyvals['min_brightness_power_w'] = self._get_current_energy_rate()

        # Turn off the screen by decreasing brightness one more time with
        # allow_off=True.
        self._backlight_controller.decrease_brightness(True)
        current_brightness = utils.wait_for_value(self._backlight.get_level,
                                                  min_threshold=0)
        if current_brightness != 0:
            num_errors += 1
            logging.error('Brightness is %d, expecting 0.' %
                          current_brightness)

        # Wait for screen to turn off.
        num_outputs_on = utils.wait_for_value(
            get_num_outputs_on, min_threshold=(starting_num_outputs_on - 1))
        keyvals['outputs_on_after_screen_off'] = num_outputs_on
        if num_outputs_on >= starting_num_outputs_on:
            num_errors += 1
            logging.error('At least one display must have been turned off. ' + \
                          'Number of displays on: %s' % num_outputs_on)
        else:
            self._wait_for_stable_energy_rate()
            keyvals['screen_off_power_w'] = self._get_current_energy_rate()

        # Set brightness to max.
        self._backlight_controller.set_brightness_to_max()
        current_brightness = utils.wait_for_value(
            self._backlight.get_level, max_threshold=keyvals['max_brightness'])
        if current_brightness != keyvals['max_brightness']:
            num_errors += 1
            logging.error(('Failed to increase brightness to max, ' + \
                           'brightness is %d.') % current_brightness)

        # Verify that the same number of outputs are on as before.
        num_outputs_on = get_num_outputs_on()
        keyvals['outputs_on_at_end'] = num_outputs_on
        if num_outputs_on != starting_num_outputs_on:
            num_errors += 1
            logging.error(('Number of displays turned on should be same as ' + \
                           'at start.  Number of displays on: %s') %
                          num_outputs_on)

        self._wait_for_stable_energy_rate()
        keyvals['final_power_w'] = self._get_current_energy_rate()

        # Energy rate must have changed significantly between transitions.
        if 'max_brightness_power_w' in keyvals and \
           'min_brightness_power_w' in keyvals and \
           keyvals['min_brightness_power_w'] >= \
               keyvals['max_brightness_power_w'] * max_to_min_factor:
            num_errors += 1
            logging.error('Power draw did not decrease enough when ' + \
                          'brightness was decreased from max to min.')

        if 'screen_off_power_w' in keyvals and \
           'min_brightness_power_w' in keyvals and \
           keyvals['screen_off_power_w'] >= \
               keyvals['min_brightness_power_w'] * min_to_off_factor:
            num_errors += 1
            logging.error('Power draw did not decrease enough when screen ' + \
                          'was turned off.')

        if num_outputs_on == starting_num_outputs_on and \
           'screen_off_power_w' in keyvals and \
           keyvals['final_power_w'] <= \
               keyvals['screen_off_power_w'] * off_to_max_factor:
            num_errors += 1
            logging.error('Power draw did not increase enough after ' + \
                          'turning screen on.')

        self.write_perf_keyval(keyvals)

        if num_errors > 0:
            raise error.TestFail('Test failed with %d errors' % num_errors)