From d98e91105fdd519644ac3648b7ab4bf50bcc8e30 Mon Sep 17 00:00:00 2001 From: Malini Das Date: Wed, 4 Apr 2012 15:56:26 -0700 Subject: [PATCH] Bug 742513 - allow marionette to launch b2g desktop build, r=jgriffin --- .../client/marionette/b2ginstance.py | 43 +++++++++++++++++++ .../client/marionette/marionette.py | 14 ++++-- .../marionette/client/marionette/runtests.py | 8 +++- .../marionette/client/marionette/venv_test.sh | 1 + 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 testing/marionette/client/marionette/b2ginstance.py diff --git a/testing/marionette/client/marionette/b2ginstance.py b/testing/marionette/client/marionette/b2ginstance.py new file mode 100644 index 000000000000..ab424ece3ef6 --- /dev/null +++ b/testing/marionette/client/marionette/b2ginstance.py @@ -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 + diff --git a/testing/marionette/client/marionette/marionette.py b/testing/marionette/client/marionette/marionette.py index a0753d327e07..e63fcf00c1d4 100644 --- a/testing/marionette/client/marionette/marionette.py +++ b/testing/marionette/client/marionette/marionette.py @@ -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'): diff --git a/testing/marionette/client/marionette/runtests.py b/testing/marionette/client/marionette/runtests.py index 66d8a4e1b3b2..78d9d992e5c4 100644 --- a/testing/marionette/client/marionette/runtests.py +++ b/testing/marionette/client/marionette/runtests.py @@ -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, diff --git a/testing/marionette/client/marionette/venv_test.sh b/testing/marionette/client/marionette/venv_test.sh index f4f8aac5c8a4..693c9e2af1e4 100644 --- a/testing/marionette/client/marionette/venv_test.sh +++ b/testing/marionette/client/marionette/venv_test.sh @@ -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