Bug 900629 - Mirror mozdevice 0.29;r=ahal
authorWilliam Lachance <wlachance@mozilla.com>
Thu, 01 Aug 2013 16:08:18 -0400
changeset 140935 5329f984f9495b699a23af88d911b1a1af16f03a
parent 140934 d1c59561ebdfcee1d1b9dc3ca71aaca51a2a174b
child 140936 f4bb9ef3bf6389222d1dff4228bbfb4d56f9b4aa
push id31924
push userwlachance@mozilla.com
push dateThu, 01 Aug 2013 20:08:31 +0000
treeherdermozilla-inbound@5329f984f949 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs900629
milestone25.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 900629 - Mirror mozdevice 0.29;r=ahal
testing/mozbase/mozdevice/mozdevice/devicemanager.py
testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
testing/mozbase/mozdevice/mozdevice/devicemanagerSUT.py
testing/mozbase/mozdevice/setup.py
testing/mozbase/mozdevice/tests/sut_push.py
--- a/testing/mozbase/mozdevice/mozdevice/devicemanager.py
+++ b/testing/mozbase/mozdevice/mozdevice/devicemanager.py
@@ -164,17 +164,17 @@ class DeviceManager(object):
             buf = self.pullFile(tempScreenshotFile)
             width = int(struct.unpack("I", buf[0:4])[0])
             height = int(struct.unpack("I", buf[4:8])[0])
             with open(filename, 'w') as pngfile:
                 pngfile.write(self._writePNG(buf[12:], width, height))
             self.removeFile(tempScreenshotFile)
 
     @abstractmethod
-    def pushFile(self, localFilename, remoteFilename, retryLimit=1):
+    def pushFile(self, localFilename, remoteFilename, retryLimit=1, createDir=True):
         """
         Copies localname from the host to destname on the device.
         """
 
     @abstractmethod
     def pushDir(self, localDirname, remoteDirname, retryLimit=1):
         """
         Push local directory from host to remote directory on the device,
--- a/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
+++ b/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py
@@ -186,17 +186,17 @@ class DeviceManagerADB(DeviceManager):
         return devices
 
     def _connectRemoteADB(self):
         self._checkCmd(["connect", self.host + ":" + str(self.port)])
 
     def _disconnectRemoteADB(self):
         self._checkCmd(["disconnect", self.host + ":" + str(self.port)])
 
-    def pushFile(self, localname, destname, retryLimit=None):
+    def pushFile(self, localname, destname, retryLimit=None, createDir=True):
         # you might expect us to put the file *in* the directory in this case,
         # but that would be different behaviour from devicemanagerSUT. Throw
         # an exception so we have the same behaviour between the two
         # implementations
         retryLimit = retryLimit or self.retryLimit
         if self.dirExists(destname):
             raise DMError("Attempted to push a file (%s) to a directory (%s)!" %
                           (localname, destname))
@@ -227,17 +227,17 @@ class DeviceManagerADB(DeviceManager):
         if not self.dirExists(remoteDir):
             self.mkDirs(remoteDir+"/x")
         if self._useZip:
             try:
                 localZip = tempfile.mktemp() + ".zip"
                 remoteZip = remoteDir + "/adbdmtmp.zip"
                 subprocess.Popen(["zip", "-r", localZip, '.'], cwd=localDir,
                                  stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
-                self.pushFile(localZip, remoteZip, retryLimit=retryLimit)
+                self.pushFile(localZip, remoteZip, retryLimit=retryLimit, createDir=False)
                 os.remove(localZip)
                 data = self._runCmdAs(["shell", "unzip", "-o", remoteZip,
                                        "-d", remoteDir]).stdout.read()
                 self._checkCmdAs(["shell", "rm", remoteZip], retryLimit=retryLimit)
                 if re.search("unzip: exiting", data) or re.search("Operation not permitted", data):
                     raise Exception("unzip failed, or permissions error")
             except:
                 self._logger.info("zip/unzip failure: falling back to normal push")
--- a/testing/mozbase/mozdevice/mozdevice/devicemanagerSUT.py
+++ b/testing/mozbase/mozdevice/mozdevice/devicemanagerSUT.py
@@ -225,17 +225,17 @@ class DeviceManagerSUT(DeviceManager):
                 while not foundPrompt:
                     socketClosed = False
                     errStr = ''
                     temp = ''
                     self._logger.debug("recv'ing...")
 
                     # Get our response
                     try:
-                          # Wait up to a second for socket to become ready for reading...
+                        # Wait up to a second for socket to become ready for reading...
                         if select.select([self._sock], [], [], select_timeout)[0]:
                             temp = self._sock.recv(1024)
                             self._logger.debug("response: %s" % temp)
                             timer = 0
                             if not temp:
                                 socketClosed = True
                                 errStr = 'connection closed'
                         timer += select_timeout
@@ -333,19 +333,20 @@ class DeviceManagerSUT(DeviceManager):
         if lastline:
             m = re.search('return code \[([0-9]+)\]', lastline)
             if m:
                 return int(m.group(1))
 
         # woops, we couldn't find an end of line/return value
         raise DMError("Automation Error: Error finding end of line/return value when running '%s'" % cmdline)
 
-    def pushFile(self, localname, destname, retryLimit = None):
+    def pushFile(self, localname, destname, retryLimit=None, createDir=True):
         retryLimit = retryLimit or self.retryLimit
-        self.mkDirs(destname)
+        if createDir:
+            self.mkDirs(destname)
 
         try:
             filesize = os.path.getsize(localname)
             with open(localname, 'rb') as f:
                 remoteHash = self._runCmds([{ 'cmd': 'push ' + destname + ' ' + str(filesize),
                                               'data': f.read() }], retryLimit=retryLimit).strip()
         except OSError:
             raise DMError("DeviceManager: Error reading file to push")
@@ -377,18 +378,17 @@ class DeviceManagerSUT(DeviceManager):
                 if subpath == "":
                     remoteRoot = remoteDir
 
                 parent = os.path.dirname(remoteName)
                 if parent not in existentDirectories:
                     self.mkDirs(remoteName)
                     existentDirectories.append(parent)
 
-                self.pushFile(os.path.join(root, f), remoteName, retryLimit=retryLimit)
-
+                self.pushFile(os.path.join(root, f), remoteName, retryLimit=retryLimit, createDir=False)
 
     def dirExists(self, remotePath):
         ret = self._runCmds([{ 'cmd': 'isdir ' + remotePath }]).strip()
         if not ret:
             raise DMError('Automation Error: DeviceManager isdir returned null')
 
         return ret == 'TRUE'
 
@@ -557,40 +557,33 @@ class DeviceManagerSUT(DeviceManager):
             self._logger.error(err_str)
             self._sock = None
             raise DMError(err_str)
 
         # FIXME: We could possibly move these socket-reading functions up to
         # the class level if we wanted to refactor sendCMD().  For now they are
         # only used to pull files.
 
-        def uread(to_recv, error_msg, timeout=None):
+        def uread(to_recv, error_msg):
             """ unbuffered read """
-            timer = 0
-            select_timeout = 1
-            if not timeout:
-                timeout = self.default_timeout
-
             try:
-                if select.select([self._sock], [], [], select_timeout)[0]:
+                data = ""
+                if select.select([self._sock], [], [], self.default_timeout)[0]:
                     data = self._sock.recv(to_recv)
-                    timer = 0
-                timer += select_timeout
-                if timer > timeout:
-                    err('timeout in uread while retrieving file')
+                if not data:
+                    # timed out waiting for response or error response
+                    err(error_msg)
 
-                if not data:
-                    err(error_msg)
                 return data
             except:
                 err(error_msg)
 
         def read_until_char(c, buf, error_msg):
             """ read until 'c' is found; buffer rest """
-            while not '\n' in buf:
+            while not c in buf:
                 data = uread(1024, error_msg)
                 buf += data
             return buf.partition(c)
 
         def read_exact(total_to_recv, buf, error_msg):
             """ read exact number of 'total_to_recv' bytes """
             while len(buf) < total_to_recv:
                 to_recv = min(total_to_recv - len(buf), 1024)
--- a/testing/mozbase/mozdevice/setup.py
+++ b/testing/mozbase/mozdevice/setup.py
@@ -1,15 +1,15 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from setuptools import setup
 
-PACKAGE_VERSION = '0.28'
+PACKAGE_VERSION = '0.29'
 
 setup(name='mozdevice',
       version=PACKAGE_VERSION,
       description="Mozilla-authored device management",
       long_description="see http://mozbase.readthedocs.org/",
       classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       keywords='',
       author='Mozilla Automation and Testing Team',
--- a/testing/mozbase/mozdevice/tests/sut_push.py
+++ b/testing/mozbase/mozdevice/tests/sut_push.py
@@ -40,24 +40,22 @@ class PushTest(unittest.TestCase):
         tempdir = tempfile.mkdtemp()
         complex_path = os.path.join(tempdir, "baz")
         os.mkdir(complex_path)
         f = tempfile.NamedTemporaryFile(dir=complex_path)
         f.write(pushfile)
         f.flush()
 
         subTests = [ { 'cmds': [ ("isdir /mnt/sdcard/baz", "TRUE"),
-                                 ("isdir /mnt/sdcard/baz", "TRUE"),
                                  ("push /mnt/sdcard/baz/%s %s\r\n%s" %
                                   (os.path.basename(f.name), len(pushfile),
                                    pushfile),
                                   expectedFileResponse) ],
                        'expectException': False },
                      { 'cmds': [ ("isdir /mnt/sdcard/baz", "TRUE"),
-                                 ("isdir /mnt/sdcard/baz", "TRUE"),
                                  ("push /mnt/sdcard/baz/%s %s\r\n%s" %
                                   (os.path.basename(f.name), len(pushfile),
                                    pushfile),
                                   "BADHASH") ],
                        'expectException': True },
                      { 'cmds': [ ("isdir /mnt/sdcard/baz", "FALSE"),
                                  ("isdir /mnt", "FALSE"),
                                  ("mkdr /mnt",