Bug 1300163 - Add support for Android mochitests to interactive loaners, r=armenzg
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 02 Sep 2016 14:43:53 -0400
changeset 312856 dd6f0732c26084b026b8fc99b2da9f801baa9107
parent 312855 e786511a99e16ae8b861ef0ef12c94c63306fa80
child 312857 3a87bca22135bb6e0faa06b4fef2715ec4d92886
push id30663
push usercbook@mozilla.com
push dateWed, 07 Sep 2016 15:12:31 +0000
treeherdermozilla-central@3d0b41fdd93b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarmenzg
bugs1300163
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1300163 - Add support for Android mochitests to interactive loaners, r=armenzg This will allow developers to request a loaner for an Android mochitest job and then use |mach mochitest| to run tests. MozReview-Commit-ID: 4lsKGpizfH7
testing/mochitest/mach_test_package_commands.py
testing/tools/mach_test_package_bootstrap.py
--- a/testing/mochitest/mach_test_package_commands.py
+++ b/testing/mochitest/mach_test_package_commands.py
@@ -8,45 +8,72 @@ import os
 from argparse import Namespace
 from functools import partial
 
 from mach.decorators import (
     CommandProvider,
     Command,
 )
 
+here = os.path.abspath(os.path.dirname(__file__))
 parser = None
 
 
 def run_mochitest(context, **kwargs):
     args = Namespace(**kwargs)
     args.e10s = context.mozharness_config.get('e10s', args.e10s)
     args.certPath = context.certs_dir
 
     if args.test_paths:
         test_root = os.path.join(context.package_root, 'mochitest', 'tests')
         normalize = partial(context.normalize_test_path, test_root)
         args.test_paths = map(normalize, args.test_paths)
 
+    import mozinfo
+    if mozinfo.info['buildapp'] == 'mobile/android':
+        return run_mochitest_android(context, args)
     return run_mochitest_desktop(context, args)
 
 
 def run_mochitest_desktop(context, args):
     args.app = args.app or context.firefox_bin
     args.utilityPath = context.bin_dir
     args.extraProfileFiles.append(os.path.join(context.bin_dir, 'plugins'))
 
     from runtests import run_test_harness
     return run_test_harness(parser, args)
 
 
+def run_mochitest_android(context, args):
+    args.app = args.app or 'org.mozilla.fennec'
+    args.extraProfileFiles.append(os.path.join(context.package_root, 'mochitest', 'fonts'))
+    args.utilityPath = context.hostutils
+    args.xrePath = context.hostutils
+
+    config = context.mozharness_config
+    if config:
+        args.remoteWebServer = config['remote_webserver']
+        args.httpPort = config['emulator']['http_port']
+        args.sslPort = config['emulator']['ssl_port']
+        args.adbPath = config['exes']['adb'] % {'abs_work_dir': context.mozharness_workdir}
+
+    from runtestsremote import run_test_harness
+    return run_test_harness(parser, args)
+
+
 def setup_argument_parser():
+    import mozinfo
+    mozinfo.find_and_update_from_json(os.path.dirname(here))
+    app = 'generic'
+    if mozinfo.info.get('buildapp') == 'mobile/android':
+        app = 'android'
+
     from mochitest_options import MochitestArgumentParser
     global parser
-    parser = MochitestArgumentParser(app='generic')
+    parser = MochitestArgumentParser(app=app)
     return parser
 
 
 @CommandProvider
 class MochitestCommands(object):
 
     def __init__(self, context):
         self.context = context
--- a/testing/tools/mach_test_package_bootstrap.py
+++ b/testing/tools/mach_test_package_bootstrap.py
@@ -107,16 +107,25 @@ def find_firefox(context):
 
     for path in search_paths:
         try:
             return mozinstall.get_binary(path, 'firefox')
         except mozinstall.InvalidBinary:
             continue
 
 
+def find_hostutils(context):
+    workdir = context.mozharness_workdir
+    hostutils = os.path.join(workdir, 'hostutils')
+    for fname in os.listdir(hostutils):
+        fpath = os.path.join(hostutils, fname)
+        if os.path.isdir(fpath) and fname.startswith('host-utils'):
+            return fpath
+
+
 def normalize_test_path(test_root, path):
     if os.path.isabs(path) or os.path.exists(path):
         return os.path.normpath(os.path.abspath(path))
 
     for parent in ancestors(test_root):
         test_path = os.path.join(parent, path)
         if os.path.exists(test_path):
             return os.path.normpath(os.path.abspath(test_path))
@@ -146,16 +155,18 @@ def bootstrap(test_package_root):
             context.normalize_test_path = normalize_test_path
             return
 
         # The values for the following 'key's will be set lazily, and cached
         # after first being invoked.
         if key == 'firefox_bin':
             return find_firefox(context)
 
+        if key == 'hostutils':
+            return find_hostutils(context)
 
         if key == 'mozharness_config':
             for dir_path in ancestors(context.package_root):
                 mozharness_config = os.path.join(dir_path, 'logs', 'localconfig.json')
                 if os.path.isfile(mozharness_config):
                     with open(mozharness_config, 'rb') as f:
                         return json.load(f)
             return {}