blob: 0f8123cd55ec10b2ae9c2f5447f4750f01163e2c [file] [log] [blame]
# Copyright (c) 2012 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
from autotest_lib.client.common_lib import error
from autotest_lib.server.cros.faftsequence import FAFTSequence
class firmware_ECBattery(FAFTSequence):
"""
Servo based EC thermal battery status report test.
"""
version = 1
# Battery status path in sysfs
BATTERY_STATUS = '/sys/class/power_supply/BAT0/status'
# Battery voltage reading path in sysfs
BATTERY_VOLTAGE_READING = '/sys/class/power_supply/BAT0/voltage_now'
# Battery current reading path in sysfs
BATTERY_CURRENT_READING = '/sys/class/power_supply/BAT0/current_now'
# Maximum allowed error of voltage reading in mV
VOLTAGE_MV_ERROR_MARGIN = 300
# Maximum allowed error of current reading in mA
CURRENT_MA_ERROR_MARGIN = 300
def _check_voltage_match(self):
"""Check if voltage reading from kernel and servo match.
Raises:
error.TestFail: Raised when the two reading mismatch by more than
VOLTAGE_MV_ERROR_MARGIN mV.
"""
servo_reading = int(self.servo.get('ppvar_vbat_mv'))
# Kernel gives voltage value in uV. Convert to mV here.
kernel_reading = int(self.faft_client.run_shell_command_get_output(
'cat %s' % self.BATTERY_VOLTAGE_READING)[0]) / 1000
if abs(servo_reading - kernel_reading) > self.VOLTAGE_MV_ERROR_MARGIN:
raise error.TestFail(
"Voltage reading from servo and kernel mismatch.")
def _check_current_match(self):
"""Check if current reading from kernel and servo match.
Raises:
error.TestFail: Raised when the two reading mismatch by more than
CURRENT_MA_ERROR_MARGIN mA.
"""
servo_reading = int(self.servo.get('ppvar_vbat_ma'))
# Kernel gives current value in uA. Convert to mA here.
kernel_reading = int(self.faft_client.run_shell_command_get_output(
'cat %s' % self.BATTERY_CURRENT_READING)[0]) / 1000
status = self.faft_client.run_shell_command_get_output(
'cat %s' % self.BATTERY_STATUS)[0]
# If battery is not discharging, servo gives negative value.
if status != "Discharging":
servo_reading = -servo_reading
if abs(servo_reading - kernel_reading) > self.CURRENT_MA_ERROR_MARGIN:
raise error.TestFail(
"Current reading from servo and kernel mismatch.")
def run_once(self, host=None):
logging.info("Checking battery current reading...")
self._check_current_match()
logging.info("Checking battery voltage reading...")
self._check_voltage_match()