Bug 1300163 - Add support for Android mochitests to interactive loaners, r?armenzg draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 02 Sep 2016 14:43:53 -0400
changeset 410294 7e13c170bdaa7603d9cffe31760009699b75497f
parent 410293 5b894f120d5b0eb4277780fae4b163d550364b96
child 530559 20ae163b1ff25ef28f2083118ee51cfdfe633967
push id28715
push userahalberstadt@mozilla.com
push dateTue, 06 Sep 2016 16:35:28 +0000
reviewersarmenzg
bugs1300163
milestone51.0a1
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 {}