Home | History | Annotate | Download | only in power_Draw
      1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import logging, time
      6 from autotest_lib.client.bin import test
      7 from autotest_lib.client.bin import utils
      8 from autotest_lib.client.cros.power import power_status
      9 
     10 
     11 class power_Draw(test.test):
     12     version = 1
     13 
     14 
     15     def run_once(self, seconds=200, sleep=10):
     16         status = power_status.get_status()
     17         if status.on_ac():
     18             logging.warning('AC power is online -- '
     19                          'unable to monitor energy consumption')
     20             return
     21 
     22         # If powerd is running, stop it, so that it cannot interfere with the
     23         # backlight adjustments in this test.
     24         if utils.system_output('status powerd').find('start/running') != -1:
     25             powerd_running = True
     26             utils.system_output('stop powerd')
     27         else:
     28             powerd_running = False
     29 
     30         start_energy = status.battery[0].energy
     31         self._tlog = power_status.TempLogger([], seconds_period=sleep)
     32         self._tlog.start()
     33 
     34         # Let the test run
     35         for i in range(0, seconds, sleep):
     36             time.sleep(sleep)
     37             status.refresh()
     38 
     39         status.refresh()
     40         end_energy = status.battery[0].energy
     41 
     42         consumed_energy = start_energy - end_energy
     43         energy_rate = consumed_energy * 60 * 60 / seconds
     44 
     45         keyvals = self._tlog.calc()
     46         keyvals['wh_energy_full'] = status.battery[0].energy_full
     47         keyvals['wh_start_energy'] = start_energy
     48         keyvals['wh_end_energy'] = end_energy
     49         keyvals['wh_consumed_energy'] = consumed_energy
     50         keyvals['w_average_energy_rate'] = energy_rate
     51         keyvals['w_end_energy_rate'] = status.battery[0].energy_rate
     52 
     53         self.write_perf_keyval(keyvals)
     54 
     55         # Restore powerd if it was originally running.
     56         if powerd_running:
     57             utils.system_output('start powerd');
     58