Bug 1516913 - [mozdevice] _get_exitcode should handle the case in where the exitcode marker is not at EOF, r=jmaher.
authorBob Clary <bclary@bclary.com>
Mon, 31 Dec 2018 10:14:25 -0800
changeset 509311 8d7092d3884f197a5679a44ad6101621af72f825
parent 509310 13191d88873d83a81b29cf5a7cc7a5be025faecd
child 509312 2bdcac07076ada82ef762264eec42a2f1c76b7d1
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1516913
milestone66.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 1516913 - [mozdevice] _get_exitcode should handle the case in where the exitcode marker is not at EOF, r=jmaher.
testing/mozbase/mozdevice/mozdevice/adb.py
--- a/testing/mozbase/mozdevice/mozdevice/adb.py
+++ b/testing/mozbase/mozdevice/mozdevice/adb.py
@@ -852,16 +852,17 @@ class ADBDevice(ADBCommand):
 
         return " ".join(quoted_cmd)
 
     @staticmethod
     def _get_exitcode(file_obj):
         """Get the exitcode from the last line of the file_obj for shell
         commands.
         """
+        re_returncode = re.compile(r'adb_returncode=([0-9]+)')
         file_obj.seek(0, os.SEEK_END)
 
         line = ''
         length = file_obj.tell()
         offset = 1
         while length - offset >= 0:
             file_obj.seek(-offset, os.SEEK_END)
             char = file_obj.read(1)
@@ -869,23 +870,38 @@ class ADBDevice(ADBCommand):
                 break
             if char != '\r' and char != '\n':
                 line = char + line
             elif line:
                 # we have collected everything up to the beginning of the line
                 break
             offset += 1
 
-        match = re.match(r'rc=([0-9]+)', line)
+        match = re_returncode.match(line)
         if match:
             exitcode = int(match.group(1))
+            # Set the position in the file to the position of the
+            # adb_returncode and truncate it from the output.
             file_obj.seek(-1, os.SEEK_CUR)
             file_obj.truncate()
         else:
             exitcode = None
+            # We may have a situation where the adb_returncode= is not
+            # at the end of the output. This happens at least in the
+            # failure jit-tests on arm. To work around this
+            # possibility, we can search the entire output for the
+            # appropriate match.
+            file_obj.seek(0, os.SEEK_SET)
+            for line in file_obj:
+                match = re_returncode.search(line)
+                if match:
+                    exitcode = int(match.group(1))
+                    break
+            # Reset the position in the file to the end.
+            file_obj.seek(0, os.SEEK_END)
 
         return exitcode
 
     def is_path_internal_storage(self, path, timeout=None):
         """
         Return True if the path matches an internal storage path
         as defined by either '/sdcard', '/mnt/sdcard', or any of the
         .*_STORAGE environment variables on the device otherwise False.
@@ -1303,17 +1319,17 @@ class ADBDevice(ADBCommand):
 
         # prepend cwd and env to command if necessary
         if cwd:
             cmd = "cd %s && %s" % (cwd, cmd)
         if env:
             envstr = '&& '.join(map(lambda x: 'export %s=%s' %
                                     (x[0], x[1]), env.iteritems()))
             cmd = envstr + "&& " + cmd
-        cmd += "; echo rc=$?"
+        cmd += "; echo adb_returncode=$?"
 
         args = [self._adb_path]
         if self._adb_host:
             args.extend(['-H', self._adb_host])
         if self._adb_port:
             args.extend(['-P', str(self._adb_port)])
         if self._device_serial:
             args.extend(['-s', self._device_serial])