Bug 1171602 - Run mochitest using mach from a tests.zip, r=chmanchester
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 26 May 2015 10:12:51 -0400
changeset 249667 43e3ece52f5572b6a11b39d15d89eb4d6620a580
parent 249666 92faa039f31b16d6de95cc3355688d8f492e8bae
child 249668 13d883caaf74900fbe66a32a87bfc361daf3466a
push id28936
push userryanvm@gmail.com
push dateFri, 19 Jun 2015 20:34:42 +0000
treeherdermozilla-central@c319f262ce3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1171602
milestone41.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 1171602 - Run mochitest using mach from a tests.zip, r=chmanchester
testing/mochitest/mach_test_package_commands.py
testing/mochitest/mochitest_options.py
testing/mochitest/moz.build
testing/tools/mach_test_package_bootstrap.py
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/mach_test_package_commands.py
@@ -0,0 +1,41 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+
+from __future__ import unicode_literals
+
+from argparse import Namespace
+import os
+
+from mach.decorators import (
+    CommandProvider,
+    Command,
+)
+
+
+def run_mochitest(context, **kwargs):
+    args = Namespace(**kwargs)
+    args.certPath = context.certs_dir
+    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(args)
+
+
+def setup_argument_parser():
+    from mochitest_options import MochitestArgumentParser
+    return MochitestArgumentParser(app='generic')
+
+
+@CommandProvider
+class MochitestCommands(object):
+
+    def __init__(self, context):
+        self.context = context
+
+    @Command('mochitest', category='testing',
+             description='Run the mochitest harness.',
+             parser=setup_argument_parser)
+    def mochitest(self, **kwargs):
+        return run_mochitest(self.context, **kwargs)
--- a/testing/mochitest/mochitest_options.py
+++ b/testing/mochitest/mochitest_options.py
@@ -72,17 +72,17 @@ class MochitestArguments(ArgumentContain
           "help": "Always keep the browser open after tests complete.",
           }],
         [["--appname"],
          {"dest": "app",
           "default": None,
           "help": "Override the default binary used to run tests with the path provided, e.g "
                   "/usr/bin/firefox. If you have run ./mach package beforehand, you can "
                   "specify 'dist' to run tests against the distribution bundle's binary.",
-          "suppress": True,
+          "suppress": build_obj is not None,
           }],
         [["--utility-path"],
          {"dest": "utilityPath",
           "default": build_obj.bindir if build_obj is not None else None,
           "help": "absolute path to directory containing utility programs "
                   "(xpcshell, ssltunnel, certutil)",
           "suppress": True,
           }],
@@ -580,17 +580,19 @@ class MochitestArguments(ArgumentContain
             elif build_obj is not None:
                 # otherwise default to dist/bin
                 options.xrePath = build_obj.bindir
             else:
                 parser.error(
                     "could not find xre directory, --xre-path must be specified")
 
         # allow relative paths
-        options.xrePath = self.get_full_path(options.xrePath, parser.oldcwd)
+        if options.xrePath:
+            options.xrePath = self.get_full_path(options.xrePath, parser.oldcwd)
+
         if options.profilePath:
             options.profilePath = self.get_full_path(options.profilePath, parser.oldcwd)
 
         if options.dmdPath:
             options.dmdPath = self.get_full_path(options.dmdPath, parser.oldcwd)
 
         if options.dmd and not options.dmdPath:
             if build_obj:
@@ -1145,17 +1147,17 @@ container_map = {
     'generic': [MochitestArguments],
     'b2g': [MochitestArguments, B2GArguments],
     'android': [MochitestArguments, AndroidArguments],
 }
 
 
 class MochitestArgumentParser(ArgumentParser):
     """
-    Usage instructions for runtests.py.
+    Usage instructions for Mochitest.
 
     All arguments are optional.
     If --chrome is specified, chrome tests will be run instead of web content tests.
     If --browser-chrome is specified, browser-chrome tests will be run instead of web content tests.
     See <http://mochikit.com/doc/html/MochiKit/Logging.html> for details on the logging levels.
     """
 
     _containers = None
--- a/testing/mochitest/moz.build
+++ b/testing/mochitest/moz.build
@@ -53,16 +53,17 @@ TEST_HARNESS_FILES.testing.mochitest += 
     'chrome-harness.js',
     'chunkifyTests.js',
     'gen_template.pl',
     'harness.xul',
     'jetpack-addon-harness.js',
     'jetpack-addon-overlay.xul',
     'jetpack-package-harness.js',
     'jetpack-package-overlay.xul',
+    'mach_test_package_commands.py',
     'manifest.webapp',
     'manifestLibrary.js',
     'mochitest_options.py',
     'nested_setup.js',
     'pywebsocket_wrapper.py',
     'redirect.html',
     'runtests.py',
     'runtestsb2g.py',
--- a/testing/tools/mach_test_package_bootstrap.py
+++ b/testing/tools/mach_test_package_bootstrap.py
@@ -6,21 +6,38 @@ from __future__ import print_function, u
 
 import os
 import platform
 import sys
 import time
 
 
 SEARCH_PATHS = [
+    'mochitest',
+    'mozbase/mozcrash',
+    'mozbase/mozdebug',
+    'mozbase/mozdevice',
+    'mozbase/mozfile',
+    'mozbase/mozhttpd',
+    'mozbase/mozlog',
+    'mozbase/moznetwork',
+    'mozbase/mozprocess',
+    'mozbase/mozprofile',
+    'mozbase/mozrunner',
+    'mozbase/mozsystemmonitor',
+    'mozbase/mozinfo',
+    'mozbase/moztest',
+    'mozbase/mozversion',
+    'mozbase/manifestparser',
     'tools/mach',
 ]
 
 # Individual files providing mach commands.
 MACH_MODULES = [
+    'mochitest/mach_test_package_commands.py',
     'tools/mach/mach/commands/commandinfo.py',
 ]
 
 
 CATEGORIES = {
     'testing': {
         'short': 'Testing',
         'long': 'Run tests.',
@@ -55,16 +72,20 @@ def bootstrap(test_package_root):
 
     try:
         import mach.main
     except ImportError:
         sys.path[0:0] = [os.path.join(test_package_root, path) for path in SEARCH_PATHS]
         import mach.main
 
     def populate_context(context, key=None):
+        context.package_root = test_package_root
+        context.certs_dir = os.path.join(test_package_root, 'certs')
+        context.bin_dir = os.path.join(test_package_root, 'bin')
+        context.modules_dir = os.path.join(test_package_root, 'modules')
         return context
 
     mach = mach.main.Mach(os.getcwd())
     mach.populate_context_handler = populate_context
 
     for category, meta in CATEGORIES.items():
         mach.define_category(category, meta['short'], meta['long'],
             meta['priority'])