Bug 789496 - DeviceManagerSUT: always consume prompt after receiving agent warning. r=wlach

This commit is contained in:
Mark Cote 2012-09-10 11:33:11 -04:00
Родитель da52969f34
Коммит de0a808cbe
2 изменённых файлов: 36 добавлений и 11 удалений

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

@ -209,6 +209,7 @@ class DeviceManagerSUT(DeviceManager):
found = False
loopguard = 0
data = ""
commandFailed = False
while (found == False and (loopguard < recvGuard)):
temp = ''
@ -232,10 +233,12 @@ class DeviceManagerSUT(DeviceManager):
# If something goes wrong in the agent it will send back a string that
# starts with '##AGENT-WARNING##'
errorMatch = self.agentErrorRE.match(data)
if errorMatch:
raise AgentError("Agent Error processing command '%s'; err='%s'" %
(cmd['cmd'], errorMatch.group(1)), fatal=True)
if not commandFailed:
errorMatch = self.agentErrorRE.match(data)
if errorMatch:
# We still need to consume the prompt, so raise an error after
# draining the rest of the buffer.
commandFailed = True
for line in data.splitlines():
if promptre.match(line):
@ -254,6 +257,10 @@ class DeviceManagerSUT(DeviceManager):
if (temp == ''):
loopguard += 1
if commandFailed:
raise AgentError("Agent Error processing command '%s'; err='%s'" %
(cmd['cmd'], errorMatch.group(1)), fatal=True)
# Write any remaining data to outputfile
outputfile.write(data)

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

@ -11,15 +11,13 @@ import unittest
class BasicTest(unittest.TestCase):
def _serve_thread(self):
need_connection = True
conn, addr = self._sock.accept()
conn.send("$>\x00")
while self.commands:
(command, response) = self.commands.pop(0)
if need_connection:
conn, addr = self._sock.accept()
need_connection = False
conn.send("$>\x00")
data = conn.recv(1024).strip()
self.assertEqual(data, command)
# send response and prompt separately to test for bug 789496
conn.send("%s\n" % response)
conn.send("$>\x00")
@ -30,16 +28,36 @@ class BasicTest(unittest.TestCase):
return thread
def test_init(self):
"""Tests DeviceManager initialization."""
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.bind(("127.0.0.1", 0))
self._sock.listen(1)
thread = self._serve([("testroot", "/mnt/sdcard"),
("cd /mnt/sdcard/tests", ""),
("cwd", "/mnt/sdcard/tests")])
("cwd", "/mnt/sdcard/tests"),
("ver", "SUTAgentAndroid Version XX")])
port = self._sock.getsockname()[1]
mozdevice.DroidSUT.debug = 4
d = mozdevice.DroidSUT("127.0.0.1", port=port)
thread.join()
def test_err(self):
"""Tests error handling during initialization."""
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.bind(("127.0.0.1", 0))
self._sock.listen(1)
thread = self._serve([("testroot", "/mnt/sdcard"),
("cd /mnt/sdcard/tests", "##AGENT-WARNING## no such file or directory"),
("cd /mnt/sdcard/tests", "##AGENT-WARNING## no such file or directory"),
("mkdr /mnt/sdcard/tests", "/mnt/sdcard/tests successfully created"),
("ver", "SUTAgentAndroid Version XX")])
port = self._sock.getsockname()[1]
d = mozdevice.DroidSUT("127.0.0.1", port=port)
mozdevice.DroidSUT.debug = 4
dm = mozdevice.DroidSUT("127.0.0.1", port=port)
thread.join()
if __name__ == '__main__':