Bug 1516913 - [mozdevice] _get_exitcode should handle the case in where the exitcode marker is not at EOF, r=jmaher.

This commit is contained in:
Bob Clary 2018-12-31 10:14:25 -08:00
Родитель b63ca79965
Коммит eddb0836f7
1 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -857,6 +857,7 @@ class ADBDevice(ADBCommand):
"""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 = ''
@ -874,13 +875,28 @@ class ADBDevice(ADBCommand):
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
@ -1308,7 +1324,7 @@ class ADBDevice(ADBCommand):
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: