From bd92c31a0f5bcd4c84ba815f092deece7617bb65 Mon Sep 17 00:00:00 2001 From: Malini Das Date: Thu, 24 May 2012 03:00:46 -0700 Subject: [PATCH] Bug 757174: Allow Firefox binary and profile to be passed in during tests. DONTBUILD because NPOTB r=jgriffin --- .../client/marionette/b2ginstance.py | 43 ---------------- .../client/marionette/geckoinstance.py | 49 +++++++++++++++++++ .../client/marionette/marionette.py | 20 ++++---- .../marionette/client/marionette/runtests.py | 39 +++++++++------ 4 files changed, 85 insertions(+), 66 deletions(-) create mode 100644 testing/marionette/client/marionette/geckoinstance.py diff --git a/testing/marionette/client/marionette/b2ginstance.py b/testing/marionette/client/marionette/b2ginstance.py index 4b171087401..5501cd4b330 100644 --- a/testing/marionette/client/marionette/b2ginstance.py +++ b/testing/marionette/client/marionette/b2ginstance.py @@ -2,46 +2,3 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -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/geckoinstance.py b/testing/marionette/client/marionette/geckoinstance.py new file mode 100644 index 00000000000..615707cbcfd --- /dev/null +++ b/testing/marionette/client/marionette/geckoinstance.py @@ -0,0 +1,49 @@ +import datetime +import socket +import time +from mozrunner import Runner + + +class GeckoInstance(object): + + def __init__(self, host, port, bin, profile): + self.marionette_host = host + self.marionette_port = port + self.bin = bin + self.profile = profile + self.runner = None + + def start(self): + profile = self.profile + if not profile: + prefs = {"dom.allow_XUL_XBL_for_file": True, + "marionette.defaultPrefs.enabled": True, + "marionette.defaultPrefs.port": 2828} + profile = {"preferences": prefs, "restore":False} + print "starting runner" + self.runner = Runner.create(binary=self.bin, profile_args=profile, cmdargs=['-no-remote']) + self.runner.start() + + def close(self): + self.runner.stop() + self.runner.cleanup() + + def wait_for_port(self, timeout=3000): + 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) + print "closing socket" + sock.close() + if '"from"' in data: + print "got data" + time.sleep(5) + 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 c103992239a..1bcfcc5808b 100644 --- a/testing/marionette/client/marionette/marionette.py +++ b/testing/marionette/client/marionette/marionette.py @@ -7,7 +7,7 @@ import socket from client import MarionetteClient from errors import * from emulator import Emulator -from b2ginstance import B2GInstance +from geckoinstance import GeckoInstance class HTMLElement(object): @@ -70,12 +70,13 @@ class Marionette(object): CONTEXT_CHROME = 'chrome' CONTEXT_CONTENT = 'content' - def __init__(self, host='localhost', port=2828, b2gbin=False, + def __init__(self, host='localhost', port=2828, bin=None, profile=None, emulator=None, emulatorBinary=None, connectToRunningEmulator=False, homedir=None, baseurl=None, noWindow=False, logcat_dir=None): self.host = host self.port = self.local_port = port - self.b2gbin = b2gbin + self.bin = bin + self.profile = profile self.session = None self.window = None self.emulator = None @@ -85,10 +86,11 @@ class Marionette(object): self.noWindow = noWindow self.logcat_dir = logcat_dir - if b2gbin: - self.b2ginstance = B2GInstance(host=self.host, port=self.port, b2gbin=self.b2gbin) - self.b2ginstance.start() - assert(self.b2ginstance.wait_for_port()) + if bin: + self.instance = GeckoInstance(host=self.host, port=self.port, + bin=self.bin, profile=self.profile) + self.instance.start() + assert(self.instance.wait_for_port()) if emulator: self.emulator = Emulator(homedir=homedir, noWindow=self.noWindow, @@ -110,8 +112,8 @@ class Marionette(object): def __del__(self): if self.emulator: self.emulator.close() - if self.b2gbin: - self.b2ginstance.close() + if self.bin: + self.instance.close() for qemu in self.extra_emulators: qemu.emulator.close() diff --git a/testing/marionette/client/marionette/runtests.py b/testing/marionette/client/marionette/runtests.py index 73ea5d3191f..4ecf0391cf8 100644 --- a/testing/marionette/client/marionette/runtests.py +++ b/testing/marionette/client/marionette/runtests.py @@ -135,14 +135,15 @@ class MarionetteTextTestRunner(unittest.TextTestRunner): class MarionetteTestRunner(object): def __init__(self, address=None, emulator=None, emulatorBinary=None, homedir=None, - b2gbin=None, autolog=False, revision=None, es_server=None, + bin=None, profile=None, autolog=False, revision=None, es_server=None, rest_server=None, logger=None, testgroup="marionette", noWindow=False, logcat_dir=None): self.address = address self.emulator = emulator self.emulatorBinary = emulatorBinary self.homedir = homedir - self.b2gbin = b2gbin + self.bin = bin + self.profile = profile self.autolog = autolog self.testgroup = testgroup self.revision = revision @@ -187,7 +188,16 @@ class MarionetteTestRunner(object): def start_marionette(self): assert(self.baseurl is not None) - if self.address: + if self.bin: + if self.address: + host, port = self.address.split(':') + else: + host = 'localhost' + port = 2828 + self.marionette = Marionette(host=host, port=int(port), + bin=self.bin, profile=self.profile, + baseurl=self.baseurl) + elif self.address: host, port = self.address.split(':') if self.emulator: self.marionette = Marionette(host=host, port=int(port), @@ -195,11 +205,6 @@ class MarionetteTestRunner(object): homedir=self.homedir, baseurl=self.baseurl, logcat_dir=self.logcat_dir) - 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), @@ -212,7 +217,7 @@ class MarionetteTestRunner(object): noWindow=self.noWindow, logcat_dir=self.logcat_dir) else: - raise Exception("must specify address or emulator") + raise Exception("must specify binary, address or emulator") def post_to_autolog(self, elapsedtime): self.logger.info('posting results to autolog') @@ -267,7 +272,9 @@ class MarionetteTestRunner(object): def run_test(self, test, testtype): if not self.httpd: + print "starting httpd" self.start_httpd() + if not self.marionette: self.start_marionette() @@ -390,8 +397,11 @@ 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') + parser.add_option('--binary', dest='bin', action='store', + help='gecko executable to launch before running the test') + parser.add_option('--profile', dest='profile', action='store', + help='profile to use when launching the gecko process. If not ' + 'passed, then a profile will be constructed and used.') options, tests = parser.parse_args() @@ -399,9 +409,9 @@ if __name__ == "__main__": parser.print_usage() parser.exit() - if not options.emulator and not options.address: + if not options.emulator and not options.address and not options.bin: parser.print_usage() - print "must specify --emulator or --address" + print "must specify --binary, --emulator or --address" parser.exit() # default to storing logcat output for emulator runs @@ -413,7 +423,8 @@ if __name__ == "__main__": emulatorBinary=options.emulatorBinary, homedir=options.homedir, logcat_dir=options.logcat_dir, - b2gbin=options.b2gbin, + bin=options.bin, + profile=options.profile, noWindow=options.noWindow, revision=options.revision, testgroup=options.testgroup,