Fix sysfs_battery.py hang without battery
If battery is not present, test case should fail instead of sticking
BUG=chrome-os-partner:24928
TEST=manaully test on DUT w/o battery
Change-Id: I2364ef577a0aa9b9200bf83119dd82cf5b2109e2
Reviewed-on: https://chromium-review.googlesource.com/182014
Reviewed-by: Justin Chuang <jchuang@chromium.org>
Commit-Queue: Heng-ruey Hsu <henryhsu@chromium.org>
Tested-by: Heng-ruey Hsu <henryhsu@chromium.org>
diff --git a/py/test/pytests/sysfs_battery.py b/py/test/pytests/sysfs_battery.py
index f87af89..45c1603 100644
--- a/py/test/pytests/sysfs_battery.py
+++ b/py/test/pytests/sysfs_battery.py
@@ -22,6 +22,7 @@
_CSS = '#state {text-align:left;}'
class SysfsBatteryTest(unittest.TestCase):
+ """Checks battery status."""
ARGS = [
Arg('maximum_cycle_count', int,
'Maximum cycle count allowed to pass test', optional=True,
@@ -45,7 +46,8 @@
wearPct = None
power = system.GetBoard().power
- if not power.CheckBatteryPresent():
+ battery_present = power.CheckBatteryPresent()
+ if not battery_present:
msg = 'Cannot find battery path'
elif power.GetChargePct() is None:
msg = 'Cannot get charge percentage'
@@ -60,23 +62,27 @@
else:
success = True
- health = power.GetBatteryAttribute('health')
- if success and self.args.verify_battery_health_good:
- if health is None or health.lower() != 'good':
- msg = 'Battery health is %s, not Good' % health
- success = False
- cycleCount = power.GetBatteryAttribute('cycle_count')
- if success and self.args.maximum_cycle_count is not None:
- if int(cycleCount) > self.args.maximum_cycle_count:
- msg = 'Battery cycle count is too high: %s' % cycleCount
- success = False
- capacity = power.GetBatteryAttribute('capacity')
- manufacturer = power.GetBatteryAttribute('manufacturer')
- temp = power.GetBatteryAttribute('temp')
+ if battery_present:
+ health = power.GetBatteryAttribute('health')
+ if success and self.args.verify_battery_health_good:
+ if health is None or health.lower() != 'good':
+ msg = 'Battery health is %s, not Good' % health
+ success = False
- Log('battery_checked', wearPct=wearPct, allowed=wearAllowedPct,
- health=health, cycleCount=cycleCount, capacity=capacity,
- manufacturer=manufacturer, temp=temp, success=success)
+ cycleCount = power.GetBatteryAttribute('cycle_count')
+ if success and self.args.maximum_cycle_count is not None:
+ if int(cycleCount) > self.args.maximum_cycle_count:
+ msg = 'Battery cycle count is too high: %s' % cycleCount
+ success = False
+
+ capacity = power.GetBatteryAttribute('capacity')
+ manufacturer = power.GetBatteryAttribute('manufacturer')
+ temp = power.GetBatteryAttribute('temp')
+
+ Log('battery_checked', wearPct=wearPct, allowed=wearAllowedPct,
+ health=health, cycleCount=cycleCount, capacity=capacity,
+ manufacturer=manufacturer, temp=temp, success=success)
+
if success:
self._ui.Pass()
else: