mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 742513 - allow marionette to launch b2g desktop build, r=jgriffin
This commit is contained in:
parent
5715b2f053
commit
d98e91105f
43
testing/marionette/client/marionette/b2ginstance.py
Normal file
43
testing/marionette/client/marionette/b2ginstance.py
Normal file
@ -0,0 +1,43 @@
|
||||
import datetime
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
class B2GInstance(object):
|
||||
|
||||
def __init__(self, host, port, b2gbin):
|
||||
self.marionette_host = host
|
||||
self.marionette_port = port
|
||||
self.b2gbin = b2gbin
|
||||
self.proc = None
|
||||
|
||||
def start(self):
|
||||
if not os.getenv('GAIA'):
|
||||
raise Exception("GAIA environment variable must be set to your gaia directory")
|
||||
args = [self.b2gbin, '-profile', os.path.join(os.getenv('GAIA'), "profile")]
|
||||
self.proc = subprocess.Popen(args,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
|
||||
def close(self):
|
||||
self.proc.terminate()
|
||||
|
||||
def wait_for_port(self, timeout=300):
|
||||
assert(self.marionette_port)
|
||||
starttime = datetime.datetime.now()
|
||||
while datetime.datetime.now() - starttime < datetime.timedelta(seconds=timeout):
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect((self.marionette_host, self.marionette_port))
|
||||
data = sock.recv(16)
|
||||
sock.close()
|
||||
if '"from"' in data:
|
||||
return True
|
||||
except:
|
||||
import traceback
|
||||
print traceback.format_exc()
|
||||
time.sleep(1)
|
||||
return False
|
||||
|
@ -39,6 +39,7 @@ import socket
|
||||
from client import MarionetteClient
|
||||
from errors import *
|
||||
from emulator import Emulator
|
||||
from b2ginstance import B2GInstance
|
||||
|
||||
class HTMLElement(object):
|
||||
|
||||
@ -101,11 +102,12 @@ class Marionette(object):
|
||||
CONTEXT_CHROME = 'chrome'
|
||||
CONTEXT_CONTENT = 'content'
|
||||
|
||||
def __init__(self, host='localhost', port=2828, emulator=False,
|
||||
connectToRunningEmulator=False, homedir=None,
|
||||
baseurl=None, noWindow=False):
|
||||
def __init__(self, host='localhost', port=2828, b2gbin=False,
|
||||
emulator=False, connectToRunningEmulator=False,
|
||||
homedir=None, baseurl=None, noWindow=False):
|
||||
self.host = host
|
||||
self.port = self.local_port = port
|
||||
self.b2gbin = b2gbin
|
||||
self.session = None
|
||||
self.window = None
|
||||
self.emulator = None
|
||||
@ -113,6 +115,10 @@ class Marionette(object):
|
||||
self.baseurl = baseurl
|
||||
self.noWindow = noWindow
|
||||
|
||||
if b2gbin:
|
||||
self.b2ginstance = B2GInstance(host=self.host, port=self.port, b2gbin=self.b2gbin)
|
||||
self.b2ginstance.start()
|
||||
assert(self.b2ginstance.wait_for_port())
|
||||
if emulator:
|
||||
self.emulator = Emulator(homedir=homedir, noWindow=self.noWindow)
|
||||
self.emulator.start()
|
||||
@ -130,6 +136,8 @@ class Marionette(object):
|
||||
def __del__(self):
|
||||
if self.emulator:
|
||||
self.emulator.close()
|
||||
if self.b2gbin:
|
||||
self.b2ginstance.close()
|
||||
|
||||
def _send_message(self, command, response_key, **kwargs):
|
||||
if not self.session and command not in ('newSession', 'getStatus'):
|
||||
|
@ -131,12 +131,13 @@ class MarionetteTextTestRunner(unittest.TextTestRunner):
|
||||
class MarionetteTestRunner(object):
|
||||
|
||||
def __init__(self, address=None, emulator=False, homedir=None,
|
||||
autolog=False, revision=None, es_server=None,
|
||||
b2gbin=None, autolog=False, revision=None, es_server=None,
|
||||
rest_server=None, logger=None, testgroup="marionette",
|
||||
noWindow=False):
|
||||
self.address = address
|
||||
self.emulator = emulator
|
||||
self.homedir = homedir
|
||||
self.b2gbin = b2gbin
|
||||
self.autolog = autolog
|
||||
self.testgroup = testgroup
|
||||
self.revision = revision
|
||||
@ -183,6 +184,8 @@ class MarionetteTestRunner(object):
|
||||
connectToRunningEmulator=True,
|
||||
homedir=self.homedir,
|
||||
baseurl=self.baseurl)
|
||||
if self.b2gbin:
|
||||
self.marionette = Marionette(host=host, port=int(port), b2gbin=self.b2gbin, baseurl=self.baseurl)
|
||||
else:
|
||||
self.marionette = Marionette(host=host, port=int(port), baseurl=self.baseurl)
|
||||
elif self.emulator:
|
||||
@ -364,6 +367,8 @@ if __name__ == "__main__":
|
||||
"tests from .ini files.")
|
||||
parser.add_option('--homedir', dest='homedir', action='store',
|
||||
help='home directory of emulator files')
|
||||
parser.add_option('--b2gbin', dest='b2gbin', action='store',
|
||||
help='b2g executable')
|
||||
|
||||
options, tests = parser.parse_args()
|
||||
|
||||
@ -379,6 +384,7 @@ if __name__ == "__main__":
|
||||
runner = MarionetteTestRunner(address=options.address,
|
||||
emulator=options.emulator,
|
||||
homedir=options.homedir,
|
||||
b2gbin=options.b2gbin,
|
||||
noWindow=options.noWindow,
|
||||
revision=options.revision,
|
||||
testgroup=options.testgroup,
|
||||
|
@ -51,6 +51,7 @@ then
|
||||
cd marionette_venv
|
||||
. bin/activate
|
||||
else
|
||||
echo "Creating marionette_venv folder in `pwd`"
|
||||
curl https://raw.github.com/pypa/virtualenv/develop/virtualenv.py | ${PYTHON} - marionette_venv
|
||||
cd marionette_venv
|
||||
. bin/activate
|
||||
|
Loading…
Reference in New Issue
Block a user