From 313f16d96e64370de7ecd9d9b9538e0e22ffb9eb Mon Sep 17 00:00:00 2001 From: Marshall Culpepper Date: Wed, 16 May 2012 12:42:59 -0700 Subject: [PATCH] Bug 755427: Use the darwin-x86 host directory for the emulator in OSX. Added a new --emulator-binary argument to runtests.py to allow overriding of the emulator used by Marionette. r=mdas --- .../marionette/client/marionette/emulator.py | 20 ++++++++++++++----- .../client/marionette/marionette.py | 5 +++-- .../client/marionette/marionette_test.py | 1 + .../marionette/client/marionette/runtests.py | 10 +++++++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/testing/marionette/client/marionette/emulator.py b/testing/marionette/client/marionette/emulator.py index a8ef0915b1e..4d5f008a08e 100644 --- a/testing/marionette/client/marionette/emulator.py +++ b/testing/marionette/client/marionette/emulator.py @@ -3,6 +3,7 @@ from mozprocess import ProcessHandlerMixin import multiprocessing import os import re +import platform import shutil import socket import subprocess @@ -32,7 +33,7 @@ class Emulator(object): deviceRe = re.compile(r"^emulator-(\d+)(\s*)(.*)$") - def __init__(self, homedir=None, noWindow=False, logcat_dir=None, arch="x86"): + def __init__(self, homedir=None, noWindow=False, logcat_dir=None, arch="x86", emulatorBinary=None): self.port = None self._emulator_launched = False self.proc = None @@ -43,6 +44,7 @@ class Emulator(object): self.logcat_dir = logcat_dir self.logcat_proc = None self.arch = arch + self.binary = emulatorBinary self.battery = EmulatorBattery(self) self.homedir = homedir self.noWindow = noWindow @@ -64,22 +66,30 @@ class Emulator(object): raise Exception("Emulator architecture must be one of x86, arm, got: %s" % self.arch) + host_dir = "linux-x86" + if platform.system() == "Darwin": + host_dir = "darwin-x86" + + host_bin_dir = os.path.join("out/host", host_dir, "bin") + if self.arch == "x86": - binary = "out/host/linux-x86/bin/emulator-x86" + binary = os.path.join(host_bin_dir, "emulator-x86") kernel = "prebuilts/qemu-kernel/x86/kernel-qemu" sysdir = "out/target/product/generic_x86" self.tail_args = [] else: - binary = "out/host/linux-x86/bin/emulator" + binary = os.path.join(host_bin_dir, "emulator") kernel = "prebuilts/qemu-kernel/arm/kernel-qemu-armv7" sysdir = "out/target/product/generic" self.tail_args = ["-cpu", "cortex-a8"] - self.adb = os.path.join(self.homedir, 'out/host/linux-x86/bin/adb') + self.adb = os.path.join(self.homedir, host_bin_dir, "adb") if not os.access(self.adb, os.F_OK): self.adb = os.path.join(self.homedir, 'bin/adb') - self.binary = os.path.join(self.homedir, binary) + if not self.binary: + self.binary = os.path.join(self.homedir, binary) + self._check_file(self.binary) self.kernelImg = os.path.join(self.homedir, kernel) diff --git a/testing/marionette/client/marionette/marionette.py b/testing/marionette/client/marionette/marionette.py index e705083b74e..b99ef7f17c6 100644 --- a/testing/marionette/client/marionette/marionette.py +++ b/testing/marionette/client/marionette/marionette.py @@ -103,7 +103,7 @@ class Marionette(object): CONTEXT_CONTENT = 'content' def __init__(self, host='localhost', port=2828, b2gbin=False, - emulator=None, connectToRunningEmulator=False, + emulator=None, emulatorBinary=None, connectToRunningEmulator=False, homedir=None, baseurl=None, noWindow=False, logcat_dir=None): self.host = host self.port = self.local_port = port @@ -125,7 +125,8 @@ class Marionette(object): self.emulator = Emulator(homedir=homedir, noWindow=self.noWindow, logcat_dir=self.logcat_dir, - arch=emulator) + arch=emulator, + emulatorBinary=emulatorBinary) self.emulator.start() self.port = self.emulator.setup_port_forwarding(self.port) assert(self.emulator.wait_for_port()) diff --git a/testing/marionette/client/marionette/marionette_test.py b/testing/marionette/client/marionette/marionette_test.py index 6906a471b3c..e23a533022a 100644 --- a/testing/marionette/client/marionette/marionette_test.py +++ b/testing/marionette/client/marionette/marionette_test.py @@ -103,6 +103,7 @@ class MarionetteTestCase(CommonTestCase): self.extra_emulator_index += 1 if len(self.marionette.extra_emulators) == self.extra_emulator_index: qemu = Marionette(emulator=self.marionette.emulator.arch, + emulatorBinary=self.marionette.emulator.binary, homedir=self.marionette.homedir, baseurl=self.marionette.baseurl, noWindow=self.marionette.noWindow) diff --git a/testing/marionette/client/marionette/runtests.py b/testing/marionette/client/marionette/runtests.py index adb004a31b9..a12215734ba 100644 --- a/testing/marionette/client/marionette/runtests.py +++ b/testing/marionette/client/marionette/runtests.py @@ -130,12 +130,13 @@ class MarionetteTextTestRunner(unittest.TextTestRunner): class MarionetteTestRunner(object): - def __init__(self, address=None, emulator=None, homedir=None, + def __init__(self, address=None, emulator=None, emulatorBinary=None, homedir=None, b2gbin=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.autolog = autolog @@ -201,6 +202,7 @@ class MarionetteTestRunner(object): baseurl=self.baseurl) elif self.emulator: self.marionette = Marionette(emulator=self.emulator, + emulatorBinary=self.emulatorBinary, homedir=self.homedir, baseurl=self.baseurl, noWindow=self.noWindow, @@ -358,6 +360,11 @@ if __name__ == "__main__": default = None, choices = ["x86", "arm"], help = "Launch a B2G emulator on which to run tests. " "You need to specify which architecture to emulate.") + parser.add_option("--emulator-binary", + action = "store", dest = "emulatorBinary", + default = None, + help = "Launch a specific emulator binary rather than " + "launching from the B2G built emulator") parser.add_option("--no-window", action = "store_true", dest = "noWindow", default = False, @@ -399,6 +406,7 @@ if __name__ == "__main__": runner = MarionetteTestRunner(address=options.address, emulator=options.emulator, + emulatorBinary=options.emulatorBinary, homedir=options.homedir, logcat_dir=options.logcat_dir, b2gbin=options.b2gbin,