Author: gnichols
Date: 2012-09-06 15:26:19 +0000 (Thu, 06 Sep 2012)
New Revision: 1373
Removed:
trunk/tests/battery/runtest.sh
Modified:
trunk/tests/battery/battery.py
Log:
843604 - battery test should not use HAL
Modified: trunk/tests/battery/battery.py
===================================================================
--- trunk/tests/battery/battery.py 2012-09-06 15:11:11 UTC (rev 1372)
+++ trunk/tests/battery/battery.py 2012-09-06 15:26:19 UTC (rev 1373)
@@ -1,9 +1,9 @@
#!/usr/bin/python
-# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
-# is made available to anyone wishing to use, modify, copy, or
-# redistribute it subject to the terms and conditions of the GNU General
+# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
# Public License v.2.
-#
+#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
@@ -18,179 +18,183 @@
from v7.test import Test
from v7.tags import Constants, DeviceClass, TestTag
-from v7.hal import Hal
+from v7.udevDeviceDetector import UdevDeviceDetector
-class BatteryTest(Test):
-
+class BatteryTest(Test):
+
def __init__(self):
Test.__init__(self, name="battery")
self.acAdapterDevice = None
self.deviceClass = DeviceClass.battery
-
+ self.unitFactor = 1000 # parse from mu-Ah to mAh
+ self.units = "mAh"
+
def tags(self):
- return [TestTag.interactive, TestTag.certification, TestTag.portable]
-
+ return [TestTag.interactive, TestTag.certification, TestTag.portable]
+
def setACAdapterDevice(self, device):
self.acAdapterDevice = device
def getACAdapterDevice(self):
return self.acAdapterDevice
-
+
def plan(self, planner):
tests = list()
acAdapterDevice = None
- devices = planner.getHalDeviceDetector().getDevices()
+ devices = planner.getUdevDeviceDetector().getDevices()
for device in devices:
- if 'battery' in device.getProperty("info.category") and
device.getProperty("battery.present"):
- test = self.makeCopy()
- test.setDevice(device)
- tests.append(test)
- if 'ac_adapter' in device.getProperty("info.category"):
- acAdapterDevice = device
+ if "power_supply" in device.getProperty("SUBSYSTEM"):
+ if "BAT" in device.getProperty("POWER_SUPPLY_NAME"):
+ test = self.makeCopy()
+ test.setDevice(device)
+ tests.append(test)
+ if "AC" in device.getProperty("POWER_SUPPLY_NAME"):
+ acAdapterDevice = device
if acAdapterDevice:
for test in tests:
test.setACAdapterDevice(acAdapterDevice)
return tests
-
+
def getDevices(self):
""" get the battery and ac adapter devices """
- hal = Hal()
- for device in hal.getDevices():
- if "ac_adapter" in device.getProperty("info.category"):
- self.setACAdapterDevice(device)
- if device.getUDI() == self.getUDI():
- if device.getProperty("battery.present"):
+ devices = UdevDeviceDetector().getDevices()
+ for device in devices:
+ if "power_supply" in device.getProperty("SUBSYSTEM"):
+ if "AC" in device.getProperty("POWER_SUPPLY_NAME"):
+ self.setACAdapterDevice(device)
+ if "BAT" in device.getProperty("POWER_SUPPLY_NAME"):
self.setDevice(device)
- else:
- print "Error: battery %s is not present" % device.getUDI()
-
+
+ if not self.getDevice():
+ print "Error: battery is not present"
if not self.getDevice() or not self.getACAdapterDevice():
- print "Error: could not find HAL device for battery and AC
Adapter"
+ print "Error: could not find udev device for battery and AC
Adapter"
return False
-
+
return True
-
+
def getStatus(self):
+ levelFull = ''
+ level = ''
""" get battery and ac adapter status """
if self.getDevices():
- self.acAdapterPresent =
self.acAdapterDevice.getProperty("ac_adapter.present")
- self.levelPercentage =
self.device.getProperty("battery.charge_level.percentage")
- self.level =
self.device.getProperty("battery.charge_level.current")
- self.levelUnits =
self.device.getProperty("battery.charge_level.unit")
- self.isCharging =
self.device.getProperty("battery.rechargeable.is_charging")
- self.isDischarging =
self.device.getProperty("battery.rechargeable.is_discharging")
+ self.acAdapterPresent =
bool(int(self.getACAdapterDevice().getProperty("POWER_SUPPLY_ONLINE")))
+ # fedora uses "ENERGY" instead of "CHARGE"
+ levelFull = self.device.getProperty("POWER_SUPPLY_CHARGE_FULL")
+ if not levelFull:
+ levelFull =
self.device.getProperty("POWER_SUPPLY_ENERGY_FULL")
+ if levelFull:
+ self.levelFull = int(levelFull) / self.unitFactor
+ level = self.device.getProperty("POWER_SUPPLY_CHARGE_NOW")
+ if not level:
+ level = self.device.getProperty("POWER_SUPPLY_ENERGY_NOW")
+ self.level = int(level) / self.unitFactor
+ self.chargingStatus =
self.device.getProperty("POWER_SUPPLY_STATUS").lower()
return True
-
- #otherwise
+
+ #otherwise
return False
-
+
def printStatus(self):
- state = "is not"
- if self.acAdapterPresent:
- state = "is"
+ state = "is" if self.acAdapterPresent else "is not"
+ print "-------------------------------"
print "AC Adapter %s connected" % state
print "Battery:"
- print " charged to %s%% - %s %s" % ( self.levelPercentage,
self.level, self.levelUnits)
- state = "is not"
- if self.isCharging:
- state = "is"
- print " %s charging" % state
- state = "is not"
- if self.isDischarging:
- state = "is"
- print " %s discharging" % state
-
+ levelPercentage = 100 * self.level / self.levelFull
+ print " charged to %s%% - %s %s" % ( levelPercentage, self.level,
self.units)
+ print " current charging status is %s" % self.chargingStatus
+ print "-------------------------------"
+
def checkStatus(self):
success = True
delta = 10 # in units of charge level
- waitTime = 10 # seconds to wait each try
+ waitTime = 10 # seconds to wait each try
tryLimit = 10 # number of times to look for level change
-
+
self.getStatus()
-
- state = None
- if self.isDischarging:
- state = "discharging"
+
+ if self.chargingStatus == "discharging":
if self.acAdapterPresent:
print "Error: battery is discharging while AC adapter is
connected"
success = False
-
- if self.isCharging:
- state = "charging"
+
+ if self.chargingStatus == "charging":
if not self.acAdapterPresent:
print "Error: battery is charging while AC adapter is
disconnected"
success = False
-
-
- if self.isDischarging or self.isCharging:
-
+
+ if self.chargingStatus == "charging" or self.chargingStatus ==
"discharging":
+
# check for changes in battery level.
tries = 0
level = self.level
while True:
self.getStatus()
- if ((self.isCharging and self.level > level + delta)
- or (self.isDischarging and self.level < level - delta)):
- print "verified battery is %s" % state
+ if ((self.chargingStatus == "charging" and self.level >
level + delta)
+ or (self.chargingStatus == "discharging" and self.level
< level - delta)):
+ print "verified battery is %s" % self.chargingStatus
break
if tries > tryLimit:
- print "Error: could not verify battery %s" % state
+ print "Error: could not verify battery %s" %
self.chargingStatus
success = False
break
tries = tries + 1
- print "waiting to verify battery %s more than %s %s" % (state,
delta, self.levelUnits)
+ print "waiting to verify battery %s more than %s %s" %
(self.chargingStatus, delta, self.units)
sys.stdout.flush()
time.sleep(waitTime)
-
+ else:
+ print "Error: could not verify battery charging status, current status
is %s" % self.chargingStatus
+ success = False
return success
-
-
+
+
def run(self):
FAILED = 1
PASSED = 0
-
+
if self.getMode() == Constants.auto:
print "Error: battery test can not be run in auto mode, as it requires
the tester to disconnect power"
return FAILED
-
+
+ if not self.getStatus():
+ return FAILED
+ self.printStatus()
+
action = None
testedConnected = False
testedDisconnected = False
- while True:
-
+ while not testedConnected or not testedDisconnected:
+ # ask user to add/remove AC power
+ action = "disconnect" if self.acAdapterPresent else
"connect"
+ if not self.promptConfirm("Please %s AC Power - continue? " %
action):
+ return FAILED
+
if not self.getStatus():
return FAILED
- self.printStatus()
+ if action == "connect":
+ if self.acAdapterPresent:
+ testedConnected = True
+ else:
+ print "AC Power is not connected!"
+ continue
+ elif action == "disconnect":
+ if self.acAdapterPresent:
+ print "AC Power is not disconnected!"
+ continue
+ else:
+ testedDisconnected = True
+
if not self.checkStatus():
return FAILED
-
- # ask user to add/remove AC power
- if self.acAdapterPresent:
- testedConnected = True
- action = "disconnect"
- else:
- testedDisconnected = True
- action = "connect"
-
- if not testedConnected or not testedDisconnected:
- if not self.promptConfirm("Please %s AC Power - continue? " %
action):
- return FAILED
- else:
- break
-
+
+ if not self.getStatus():
+ return FAILED
+ self.printStatus()
+
return PASSED
-
+
if __name__ == "__main__":
test = BatteryTest()
returnValue = test.do(sys.argv)
sys.exit(returnValue)
-
-
-
-
-
-
-
-
-
Deleted: trunk/tests/battery/runtest.sh
===================================================================
--- trunk/tests/battery/runtest.sh 2012-09-06 15:11:11 UTC (rev 1372)
+++ trunk/tests/battery/runtest.sh 2012-09-06 15:26:19 UTC (rev 1373)
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-v7-run-simple-test ${TEST:-$(basename $PWD)} ./battery.py
Show replies by date