blob: d0c64f18e21c146e2fda1d936dd3a4a47a0d7d3e [file] [log] [blame]
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging, time
from autotest_lib.client.bin import test
from autotest_lib.client.bin import utils
from autotest_lib.client.cros.power import power_status
class power_Draw(test.test):
version = 1
def run_once(self, seconds=200, sleep=10):
status = power_status.get_status()
if status.on_ac():
logging.warning('AC power is online -- '
'unable to monitor energy consumption')
# If powerd is running, stop it, so that it cannot interfere with the
# backlight adjustments in this test.
if utils.system_output('status powerd').find('start/running') != -1:
powerd_running = True
utils.system_output('stop powerd')
powerd_running = False
start_energy = status.battery[0].energy
self._tlog = power_status.TempLogger([], seconds_period=sleep)
# Let the test run
for i in range(0, seconds, sleep):
end_energy = status.battery[0].energy
consumed_energy = start_energy - end_energy
energy_rate = consumed_energy * 60 * 60 / seconds
keyvals = self._tlog.calc()
keyvals['wh_energy_full'] = status.battery[0].energy_full
keyvals['wh_start_energy'] = start_energy
keyvals['wh_end_energy'] = end_energy
keyvals['wh_consumed_energy'] = consumed_energy
keyvals['w_average_energy_rate'] = energy_rate
keyvals['w_end_energy_rate'] = status.battery[0].energy_rate
# Restore powerd if it was originally running.
if powerd_running:
utils.system_output('start powerd');