Bug 1081167 - [mozdevice] Fix uptime info and command line info for ADB connected devices. r=wlach
--- a/testing/mozbase/mozdevice/adb_tests/test_devicemanagerADB.py
+++ b/testing/mozbase/mozdevice/adb_tests/test_devicemanagerADB.py
@@ -169,19 +169,17 @@ class TestFileOperations(DeviceManagerAD
class TestOther(DeviceManagerADBTestCase):
def test_get_list_of_processes(self):
self.assertEquals(type(self.dm.getProcessList()), list)
def test_get_current_time(self):
self.assertEquals(type(self.dm.getCurrentTime()), int)
def test_get_info(self):
- self.assertEquals(self.dm.getInfo(), {})
- # Commented since it is too nosiy
- #self.assertEquals(self.dm.getInfo("all"), dict)
+ self.assertEquals(type(self.dm.getInfo()), dict)
def test_list_devices(self):
self.assertEquals(len(list(self.dm.devices())), 1)
def test_shell(self):
out = StringIO()
self.dm.shell(["echo", "$COMPANY", ";", "pwd"], out,
env={"COMPANY":"Mozilla"}, cwd="/", timeout=4, root=True)
--- a/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
+++ b/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
@@ -492,36 +492,33 @@ class DeviceManagerADB(DeviceManager):
def getCurrentTime(self):
timestr = str(self._runCmd(["shell", "date", "+%s"]).output[0])
if (not timestr or not timestr.isdigit()):
raise DMError("Unable to get current time using date (got: '%s')" % timestr)
return int(timestr)*1000
def getInfo(self, directive=None):
+ directive = directive or "all"
ret = {}
- if (directive == "id" or directive == "all"):
+ if directive == "id" or directive == "all":
ret["id"] = self._runCmd(["get-serialno"]).output[0]
- if (directive == "os" or directive == "all"):
- ret["os"] = self._runCmd(["shell", "getprop", "ro.build.display.id"]).output[0]
- if (directive == "uptime" or directive == "all"):
- utime = self._runCmd(["shell", "uptime"]).output[0]
+ if directive == "os" or directive == "all":
+ ret["os"] = self.shellCheckOutput(["getprop", "ro.build.display.id"])
+ if directive == "uptime" or directive == "all":
+ utime = self.shellCheckOutput(["uptime"])
if (not utime):
raise DMError("error getting uptime")
- utime = utime[9:]
- hours = utime[0:utime.find(":")]
- utime = utime[utime[1:].find(":") + 2:]
- minutes = utime[0:utime.find(":")]
- utime = utime[utime[1:].find(":") + 2:]
- seconds = utime[0:utime.find(",")]
- ret["uptime"] = ["0 days " + hours + " hours " + minutes + " minutes " + seconds + " seconds"]
- if (directive == "process" or directive == "all"):
- ret["process"] = self._runCmd(["shell", "ps"]).output
- if (directive == "systime" or directive == "all"):
- ret["systime"] = self._runCmd(["shell", "date"]).output[0]
+ m = re.match("up time: ((\d+) days, )*(\d{2}):(\d{2}):(\d{2})", utime)
+ ret["uptime"] = "%d days %d hours %d minutes %d seconds" % tuple(
+ [int(g or 0) for g in m.groups()[1:]])
+ if directive == "process" or directive == "all":
+ ret["process"] = self.shellCheckOutput(["ps"])
+ if directive == "systime" or directive == "all":
+ ret["systime"] = self.shellCheckOutput(["date"])
self._logger.info(ret)
return ret
def uninstallApp(self, appName, installPath=None):
status = self._runCmd(["uninstall", appName]).output[0].strip()
if status != 'Success':
raise DMError("uninstall failed for %s. Got: %s" % (appName, status))
--- a/testing/mozbase/mozdevice/mozdevice/dmcli.py
+++ b/testing/mozbase/mozdevice/mozdevice/dmcli.py
@@ -277,24 +277,21 @@ class DMCli(object):
buf = StringIO.StringIO()
self.dm.shell(args.command, buf, root=args.root)
print str(buf.getvalue()[0:-1]).rstrip()
def getinfo(self, args):
info = self.dm.getInfo(directive=args.directive)
for (infokey, infoitem) in sorted(info.iteritems()):
if infokey == "process":
- pass # skip process list: get that through ps
- elif not args.directive and not infoitem:
- print "%s:" % infokey.upper()
- elif not args.directive:
- for line in infoitem:
- print "%s: %s" % (infokey.upper(), line)
+ pass # skip process list: get that through ps
+ elif args.directive is None:
+ print "%s: %s" % (infokey.upper(), infoitem)
else:
- print "%s" % "\n".join(infoitem)
+ print infoitem
def logcat(self, args):
print ''.join(self.dm.getLogcat())
def clearlogcat(self, args):
self.dm.recordLogcat()
def reboot(self, args):