Bug 728927 - A few more minor exception conditions in DeviceManagerSUT. r=jmaher
authorWilliam Lachance <wlachance@mozilla.com>
Tue, 21 Feb 2012 09:10:42 -0500
changeset 87263 d5803f488c08c5142bfb13aaa1b5aa724c514318
parent 87262 d40608e2e5948eb6bb39ad170ae60c6ae853d2e3
child 87288 cb3d33c37bda18cf7f2b62e172ece51b1373b1b1
push id6281
push userjmaher@mozilla.com
push dateTue, 21 Feb 2012 14:11:15 +0000
treeherdermozilla-inbound@d5803f488c08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs728927
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 728927 - A few more minor exception conditions in DeviceManagerSUT. r=jmaher
build/mobile/devicemanagerSUT.py
--- a/build/mobile/devicemanagerSUT.py
+++ b/build/mobile/devicemanagerSUT.py
@@ -204,27 +204,28 @@ class DeviceManagerSUT(DeviceManager):
           try:
             temp = self._sock.recv(1024)
             if (self.debug >= 4): print "response: " + str(temp)
           except:
             self._sock.close()
             self._sock = None
             return None
 
+          data += temp
+
           # If something goes wrong in the agent it will send back a string that
           # starts with '##AGENT-ERROR##'
-          if (self.agentErrorRE.match(temp)):
-            data = temp
+          if self.agentErrorRE.match(data):
             break
 
-          data += temp
-
           for line in data.splitlines():
-            if (promptre.match(line)):
+            if promptre.match(line):
               found = True
+              data = self._stripPrompt(data)
+              break
 
           # If we violently lose the connection to the device, this loop tends to spin,
           # this guard prevents that
           if (temp == ''):
             loopguard += 1
 
     if (shouldCloseSocket == True):
       try:
@@ -233,17 +234,17 @@ class DeviceManagerSUT(DeviceManager):
       except:
         self._sock = None
         return None
 
     return data
   
   # internal function
   # take a data blob and strip instances of the prompt '$>\x00'
-  def stripPrompt(self, data):
+  def _stripPrompt(self, data):
     promptre = re.compile(self.prompt_regex + '.*')
     retVal = []
     lines = data.split('\n')
     for line in lines:
       try:
         while (promptre.match(line)):
           pieces = line.split(self.prompt_sep)
           index = pieces.index('$>')
@@ -288,17 +289,17 @@ class DeviceManagerSUT(DeviceManager):
       retVal = self.verifySendCMD(['push ' + destname + ' ' + str(filesize) + '\r\n', data], newline = False)
     except(DMError):
       retVal = False
   
     if (self.debug >= 3): print "push returned: " + str(retVal)
 
     validated = False
     if (retVal):
-      retline = self.stripPrompt(retVal).strip() 
+      retline = retVal.strip()
       if (retline == None):
         # Then we failed to get back a hash from agent, try manual validation
         validated = self.validateFile(destname, localname)
       else:
         # Then we obtained a hash from push
         localHash = self.getLocalHash(localname)
         if (str(localHash) == str(retline)):
           validated = True
@@ -374,21 +375,19 @@ class DeviceManagerSUT(DeviceManager):
   def dirExists(self, dirname):
     match = ".*" + dirname + "$"
     dirre = re.compile(match)
     try:
       data = self.verifySendCMD(['cd ' + dirname, 'cwd'])
     except(DMError):
       return False
 
-    retVal = self.stripPrompt(data)
-    data = retVal.split('\n')
     found = False
-    for d in data:
-      if (dirre.match(d)): 
+    for d in data.splitlines():
+      if (dirre.match(d)):
         found = True
 
     return found
 
   # Because we always have / style paths we make this a lot easier with some
   # assumptions
   # external function
   # returns:
@@ -412,18 +411,17 @@ class DeviceManagerSUT(DeviceManager):
     rootdir = rootdir.rstrip('/')
     if (self.dirExists(rootdir) == False):
       return []
     try:
       data = self.verifySendCMD(['cd ' + rootdir, 'ls'])
     except(DMError):
       return []
 
-    retVal = self.stripPrompt(data)
-    files = filter(lambda x: x, retVal.split('\n'))
+    files = filter(lambda x: x, data.splitlines())
     if len(files) == 1 and files[0] == '<empty>':
       # special case on the agent: empty directories return just the string "<empty>"
       return []
     return files
 
   # external function
   # returns:
   #  success: output of telnet, i.e. "removing file: /mnt/sdcard/tests/test.txt"
@@ -455,21 +453,19 @@ class DeviceManagerSUT(DeviceManager):
   #  success: array of process tuples
   #  failure: []
   def getProcessList(self):
     try:
       data = self.verifySendCMD(['ps'])
     except DMError:
       return []
 
-    retVal = self.stripPrompt(data)
-    lines = retVal.split('\n')
     files = []
-    for line in lines:
-      if (line.strip() != ''):
+    for line in data.splitlines():
+      if line:
         pidproc = line.strip().split()
         if (len(pidproc) == 2):
           files += [[pidproc[0], pidproc[1]]]
         elif (len(pidproc) == 3):
           #android returns <userID> <procID> <procName>
           files += [[pidproc[1], pidproc[2], pidproc[0]]]     
     return files
 
@@ -547,29 +543,29 @@ class DeviceManagerSUT(DeviceManager):
   #  success: tmpdir, string
   #  failure: None
   def getTempDir(self):
     try:
       data = self.verifySendCMD(['tmpd'])
     except(DMError):
       return None
 
-    return self.stripPrompt(data).strip('\n')
+    return data.strip()
 
   # external function
   # returns:
   #  success: filecontents
   #  failure: None
   def catFile(self, remoteFile):
     try:
       data = self.verifySendCMD(['cat ' + remoteFile])
     except(DMError):
       return None
 
-    return self.stripPrompt(data)
+    return data
   
   # external function
   # returns:
   #  success: output of pullfile, string
   #  failure: None
   def pullFile(self, remoteFile):
     """Returns contents of remoteFile using the "pull" command.
     The "pull" command is different from other commands in that DeviceManager
@@ -749,17 +745,18 @@ class DeviceManagerSUT(DeviceManager):
   def isDir(self, remotePath):
     try:
       data = self.verifySendCMD(['isdir ' + remotePath])
     except(DMError):
       # normally there should be no error here; a nonexistent file/directory will
       # return the string "<filename>: No such file or directory".
       # However, I've seen AGENT-WARNING returned before. 
       return False
-    retVal = self.stripPrompt(data).strip()
+
+    retVal = data.strip()
     if not retVal:
       raise FileError('isdir returned null')
     return retVal == 'TRUE'
 
   # true/false check if the two files have the same md5 sum
   # external function
   # returns:
   #  success: True
@@ -782,19 +779,19 @@ class DeviceManagerSUT(DeviceManager):
   #  success: MD5 hash for given filename
   #  failure: None
   def getRemoteHash(self, filename):
     try:
       data = self.verifySendCMD(['hash ' + filename])
     except(DMError):
       return None
 
-    retVal = self.stripPrompt(data)
-    if (retVal != None):
-      retVal = retVal.strip('\n')
+    retVal = None
+    if data:
+      retVal = data.strip()
     if (self.debug >= 3): print "remote hash returned: '" + retVal + "'"
     return retVal
     
   # Gets the device root for the testing area on the device
   # For all devices we will use / type slashes and depend on the device-agent
   # to sort those out.  The agent will return us the device location where we
   # should store things, we will then create our /tests structure relative to
   # that returned path.
@@ -810,33 +807,32 @@ class DeviceManagerSUT(DeviceManager):
   # returns:
   #  success: path for device root
   #  failure: None
   def getDeviceRoot(self):
     try:
       data = self.verifySendCMD(['testroot'])
     except:
       return None
-  
-    deviceRoot = self.stripPrompt(data).strip('\n') + '/tests'
+
+    deviceRoot = data.strip() + '/tests'
 
     if (not self.dirExists(deviceRoot)):
       if (self.mkDir(deviceRoot) == None):
         return None
 
     return deviceRoot
 
   def getAppRoot(self, packageName):
     try:
       data = self.verifySendCMD(['getapproot '+packageName])
     except:
       return None
-  
-    appRoot = self.stripPrompt(data).strip('\n')
-    return appRoot
+
+    return data.strip()
 
   # external function
   # returns:
   #  success: output of unzip command
   #  failure: None
   def unpackFile(self, filename):
     devroot = self.getDeviceRoot()
     if (devroot == None):
@@ -920,17 +916,16 @@ class DeviceManagerSUT(DeviceManager):
                   'disk','power']
     if (directive in directives):
       directives = [directive]
 
     for d in directives:
       data = self.verifySendCMD(['info ' + d])
       if (data is None):
         continue
-      data = self.stripPrompt(data)
       data = collapseSpaces.sub(' ', data)
       result[d] = data.split('\n')
 
     # Get rid of any 0 length members of the arrays
     for k, v in result.iteritems():
       result[k] = filter(lambda x: x != '', result[k])
     
     # Format the process output
@@ -1050,17 +1045,17 @@ class DeviceManagerSUT(DeviceManager):
   #  success: time in ms
   #  failure: None
   def getCurrentTime(self):
     try:
       data = self.verifySendCMD(['clok'])
     except(DMError):
       return None
 
-    return self.stripPrompt(data).strip('\n')
+    return data.strip()
 
   """
     Connect the ipaddress and port for a callback ping.  Defaults to current IP address
     And ports starting at 30000.
     NOTE: the detection for current IP address only works on Linux!
   """
   # external function
   # returns: