зеркало из https://github.com/mozilla/gecko-dev.git
Bug 886882 - Mirror mozdevice 0.27;r=jhammel
This commit is contained in:
Родитель
228b79b0ec
Коммит
d4ff842ffa
|
@ -180,9 +180,13 @@ class DeviceManager(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def pullFile(self, remoteFilename):
|
def pullFile(self, remoteFilename, offset=None, length=None):
|
||||||
"""
|
"""
|
||||||
Returns contents of remoteFile using the "pull" command.
|
Returns contents of remoteFile using the "pull" command.
|
||||||
|
|
||||||
|
:param remoteFilename: Path to file to pull from remote device.
|
||||||
|
:param offset: Offset in bytes from which to begin reading (optional)
|
||||||
|
:param length: Number of bytes to read (optional)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
|
@ -386,13 +386,24 @@ class DeviceManagerADB(DeviceManager):
|
||||||
except (OSError, ValueError):
|
except (OSError, ValueError):
|
||||||
raise DMError("Error pulling remote file '%s' to '%s'" % (remoteFile, localFile))
|
raise DMError("Error pulling remote file '%s' to '%s'" % (remoteFile, localFile))
|
||||||
|
|
||||||
def pullFile(self, remoteFile):
|
def pullFile(self, remoteFile, offset=None, length=None):
|
||||||
# TODO: add debug flags and allow for printing stdout
|
# TODO: add debug flags and allow for printing stdout
|
||||||
localFile = tempfile.mkstemp()[1]
|
localFile = tempfile.mkstemp()[1]
|
||||||
self._runPull(remoteFile, localFile)
|
self._runPull(remoteFile, localFile)
|
||||||
|
|
||||||
f = open(localFile, 'r')
|
f = open(localFile, 'r')
|
||||||
ret = f.read()
|
|
||||||
|
# ADB pull does not support offset and length, but we can instead
|
||||||
|
# read only the requested portion of the local file
|
||||||
|
if offset is not None and length is not None:
|
||||||
|
f.seek(offset)
|
||||||
|
ret = f.read(length)
|
||||||
|
elif offset is not None:
|
||||||
|
f.seek(offset)
|
||||||
|
ret = f.read()
|
||||||
|
else:
|
||||||
|
ret = f.read()
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
os.remove(localFile)
|
os.remove(localFile)
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -542,7 +542,7 @@ class DeviceManagerSUT(DeviceManager):
|
||||||
def getTempDir(self):
|
def getTempDir(self):
|
||||||
return self._runCmds([{ 'cmd': 'tmpd' }]).strip()
|
return self._runCmds([{ 'cmd': 'tmpd' }]).strip()
|
||||||
|
|
||||||
def pullFile(self, remoteFile):
|
def pullFile(self, remoteFile, offset=None, length=None):
|
||||||
# The "pull" command is different from other commands in that DeviceManager
|
# The "pull" command is different from other commands in that DeviceManager
|
||||||
# has to read a certain number of bytes instead of just reading to the
|
# has to read a certain number of bytes instead of just reading to the
|
||||||
# next prompt. This is more robust than the "cat" command, which will be
|
# next prompt. This is more robust than the "cat" command, which will be
|
||||||
|
@ -604,7 +604,14 @@ class DeviceManagerSUT(DeviceManager):
|
||||||
# <filename>,-1\n<error message>
|
# <filename>,-1\n<error message>
|
||||||
|
|
||||||
# just send the command first, we read the response inline below
|
# just send the command first, we read the response inline below
|
||||||
self._runCmds([{ 'cmd': 'pull ' + remoteFile }])
|
if offset is not None and length is not None:
|
||||||
|
cmd = 'pull %s %d %d' % (remoteFile, offset, length)
|
||||||
|
elif offset is not None:
|
||||||
|
cmd = 'pull %s %d' % (remoteFile, offset)
|
||||||
|
else:
|
||||||
|
cmd = 'pull %s' % remoteFile
|
||||||
|
|
||||||
|
self._runCmds([{ 'cmd': cmd }])
|
||||||
|
|
||||||
# read metadata; buffer the rest
|
# read metadata; buffer the rest
|
||||||
metadata, sep, buf = read_until_char('\n', buf, 'could not find metadata')
|
metadata, sep, buf = read_until_char('\n', buf, 'could not find metadata')
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
PACKAGE_VERSION = '0.26'
|
PACKAGE_VERSION = '0.27'
|
||||||
|
|
||||||
setup(name='mozdevice',
|
setup(name='mozdevice',
|
||||||
version=PACKAGE_VERSION,
|
version=PACKAGE_VERSION,
|
||||||
|
|
|
@ -3,11 +3,17 @@
|
||||||
# Any copyright is dedicated to the Public Domain.
|
# Any copyright is dedicated to the Public Domain.
|
||||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
|
||||||
|
import datetime
|
||||||
import socket
|
import socket
|
||||||
from threading import Thread
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
class MockAgent(object):
|
class MockAgent(object):
|
||||||
|
|
||||||
|
MAX_WAIT_TIME_SECONDS = 10
|
||||||
|
SOCKET_TIMEOUT_SECONDS = 5
|
||||||
|
|
||||||
def __init__(self, tester, start_commands = None, commands = []):
|
def __init__(self, tester, start_commands = None, commands = []):
|
||||||
if start_commands:
|
if start_commands:
|
||||||
self.commands = start_commands
|
self.commands = start_commands
|
||||||
|
@ -37,10 +43,22 @@ class MockAgent(object):
|
||||||
while self.commands:
|
while self.commands:
|
||||||
if not conn:
|
if not conn:
|
||||||
conn, addr = self._sock.accept()
|
conn, addr = self._sock.accept()
|
||||||
|
conn.settimeout(self.SOCKET_TIMEOUT_SECONDS)
|
||||||
conn.send("$>\x00")
|
conn.send("$>\x00")
|
||||||
(command, response) = self.commands.pop(0)
|
(command, response) = self.commands.pop(0)
|
||||||
data = conn.recv(1024).strip()
|
data = ''
|
||||||
self.tester.assertEqual(data, command)
|
timeout = datetime.datetime.now() + datetime.timedelta(
|
||||||
|
seconds=self.MAX_WAIT_TIME_SECONDS)
|
||||||
|
# The data might come in chunks, particularly if we are expecting
|
||||||
|
# multiple lines, as with push commands.
|
||||||
|
while (len(data) < len(command) and
|
||||||
|
datetime.datetime.now() < timeout):
|
||||||
|
try:
|
||||||
|
data += conn.recv(1024)
|
||||||
|
except socket.timeout:
|
||||||
|
# We handle timeouts in the main loop.
|
||||||
|
pass
|
||||||
|
self.tester.assertEqual(data.strip(), command)
|
||||||
# send response and prompt separately to test for bug 789496
|
# send response and prompt separately to test for bug 789496
|
||||||
# FIXME: Improve the mock agent, since overloading the meaning
|
# FIXME: Improve the mock agent, since overloading the meaning
|
||||||
# of 'response' is getting confusing.
|
# of 'response' is getting confusing.
|
||||||
|
|
|
@ -16,7 +16,7 @@ class PushTest(unittest.TestCase):
|
||||||
|
|
||||||
# (good response, no exception), (bad response, exception)
|
# (good response, no exception), (bad response, exception)
|
||||||
for response in [ (expectedResponse, False), ("BADHASH", True) ]:
|
for response in [ (expectedResponse, False), ("BADHASH", True) ]:
|
||||||
cmd = "push /mnt/sdcard/foobar %s" % len(pushfile)
|
cmd = "push /mnt/sdcard/foobar %s\r\n%s" % (len(pushfile), pushfile)
|
||||||
a = MockAgent(self, commands = [("isdir /mnt/sdcard", "TRUE"),
|
a = MockAgent(self, commands = [("isdir /mnt/sdcard", "TRUE"),
|
||||||
(cmd, response[0])])
|
(cmd, response[0])])
|
||||||
exceptionThrown = False
|
exceptionThrown = False
|
||||||
|
@ -46,14 +46,16 @@ class PushTest(unittest.TestCase):
|
||||||
|
|
||||||
subTests = [ { 'cmds': [ ("isdir /mnt/sdcard//baz", "TRUE"),
|
subTests = [ { 'cmds': [ ("isdir /mnt/sdcard//baz", "TRUE"),
|
||||||
("isdir /mnt/sdcard//baz", "TRUE"),
|
("isdir /mnt/sdcard//baz", "TRUE"),
|
||||||
("push /mnt/sdcard//baz/%s %s" %
|
("push /mnt/sdcard//baz/%s %s\r\n%s" %
|
||||||
(os.path.basename(f.name), len(pushfile)),
|
(os.path.basename(f.name), len(pushfile),
|
||||||
|
pushfile),
|
||||||
expectedFileResponse) ],
|
expectedFileResponse) ],
|
||||||
'expectException': False },
|
'expectException': False },
|
||||||
{ 'cmds': [ ("isdir /mnt/sdcard//baz", "TRUE"),
|
{ 'cmds': [ ("isdir /mnt/sdcard//baz", "TRUE"),
|
||||||
("isdir /mnt/sdcard//baz", "TRUE"),
|
("isdir /mnt/sdcard//baz", "TRUE"),
|
||||||
("push /mnt/sdcard//baz/%s %s" %
|
("push /mnt/sdcard//baz/%s %s\r\n%s" %
|
||||||
(os.path.basename(f.name), len(pushfile)),
|
(os.path.basename(f.name), len(pushfile),
|
||||||
|
pushfile),
|
||||||
"BADHASH") ],
|
"BADHASH") ],
|
||||||
'expectException': True },
|
'expectException': True },
|
||||||
{ 'cmds': [ ("isdir /mnt/sdcard//baz", "FALSE"),
|
{ 'cmds': [ ("isdir /mnt/sdcard//baz", "FALSE"),
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
[include:manifestdestiny/tests/manifest.ini]
|
[include:manifestdestiny/tests/manifest.ini]
|
||||||
[include:mozcrash/tests/manifest.ini]
|
[include:mozcrash/tests/manifest.ini]
|
||||||
# [include:mozdevice/tests/manifest.ini] bug 885784
|
[include:mozdevice/tests/manifest.ini]
|
||||||
[include:mozfile/tests/manifest.ini]
|
[include:mozfile/tests/manifest.ini]
|
||||||
[include:mozhttpd/tests/manifest.ini]
|
[include:mozhttpd/tests/manifest.ini]
|
||||||
[include:mozprocess/tests/manifest.ini]
|
[include:mozprocess/tests/manifest.ini]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче