Bug 1278890 - Add reftest support to test package mach environment, r?armenzg draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 13 Jul 2016 10:57:22 -0400
changeset 387193 ae93713c26d514f3517cbf224af79e7e1799c543
parent 387192 70ce608bf14d7d8e829f1aa6c7f10b4d36fe55fc
child 525304 9e43dd3a66bd7a821c38330299234b61c3fd0585
push id22912
push userahalberstadt@mozilla.com
push dateWed, 13 Jul 2016 15:23:47 +0000
reviewersarmenzg
bugs1278890
milestone50.0a1
Bug 1278890 - Add reftest support to test package mach environment, r?armenzg This adds reftest support to the test package mach environment. It will allow developers to easily run reftests after checking out an interactive worker. MozReview-Commit-ID: fBAbfuG5XQ
layout/tools/reftest/mach_test_package_commands.py
layout/tools/reftest/moz.build
layout/tools/reftest/reftestcommandline.py
layout/tools/reftest/runreftest.py
testing/tools/mach_test_package_bootstrap.py
new file mode 100644
--- /dev/null
+++ b/layout/tools/reftest/mach_test_package_commands.py
@@ -0,0 +1,53 @@
+# 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
+
+import os
+from functools import partial
+
+from mach.decorators import (
+    CommandProvider,
+    Command,
+)
+
+
+def run_reftest(context, **kwargs):
+    kwargs['certPath'] = context.certs_dir
+    kwargs['utilityPath'] = context.bin_dir
+    kwargs['extraProfileFiles'].append(os.path.join(context.bin_dir, 'plugins'))
+
+    if not kwargs['app']:
+        # This could still return None in which case --appname must be used
+        # to specify the firefox binary.
+        kwargs['app'] = context.find_firefox()
+
+    if not kwargs['tests']:
+        kwargs['tests'] = [os.path.join('layout', 'reftests', 'reftest.list')]
+
+    test_root = os.path.join(context.package_root, 'reftest', 'tests')
+    normalize = partial(context.normalize_test_path, test_root)
+    kwargs['tests'] = map(normalize, kwargs['tests'])
+
+    from runreftest import run as run_test_harness
+    return run_test_harness(**kwargs)
+
+
+def setup_argument_parser():
+    from reftestcommandline import DesktopArgumentsParser
+    return DesktopArgumentsParser()
+
+
+@CommandProvider
+class ReftestCommands(object):
+
+    def __init__(self, context):
+        self.context = context
+
+    @Command('reftest', category='testing',
+             description='Run the reftest harness.',
+             parser=setup_argument_parser)
+    def reftest(self, **kwargs):
+        kwargs['suite'] = 'reftest'
+        return run_reftest(self.context, **kwargs)
--- a/layout/tools/reftest/moz.build
+++ b/layout/tools/reftest/moz.build
@@ -17,16 +17,17 @@ GENERATED_FILES += ['automation.py']
 TEST_HARNESS_FILES.reftest += [
     '!automation.py',
     '/build/mobile/b2gautomation.py',
     '/build/mobile/remoteautomation.py',
     '/build/pgo/server-locations.txt',
     '/testing/mochitest/server.js',
     'b2g_start_script.js',
     'gaia_lock_screen.js',
+    'mach_test_package_commands.py',
     'output.py',
     'reftest-preferences.js',
     'reftestcommandline.py',
     'remotereftest.py',
     'runreftest.py',
     'runreftestb2g.py',
     'runreftestmulet.py',
 ]
--- a/layout/tools/reftest/reftestcommandline.py
+++ b/layout/tools/reftest/reftestcommandline.py
@@ -367,28 +367,16 @@ class DesktopArgumentsParser(ReftestArgu
         if options.app is None:
             bin_dir = (self.build_obj.get_binary_path() if
                        self.build_obj and self.build_obj.substs[
                            'MOZ_BUILD_APP'] != 'mobile/android'
                        else None)
 
             if bin_dir:
                 options.app = bin_dir
-            else:
-                self.error(
-                    "could not find the application path, --appname must be specified")
-
-        options.app = reftest.getFullPath(options.app)
-        if not os.path.exists(options.app):
-            self.error("""Error: Path %(app)s doesn't exist.
-            Are you executing $objdir/_tests/reftest/runreftest.py?"""
-                       % {"app": options.app})
-
-        if options.xrePath is None:
-            options.xrePath = os.path.dirname(options.app)
 
         if options.symbolsPath and len(urlparse(options.symbolsPath).scheme) < 2:
             options.symbolsPath = reftest.getFullPath(options.symbolsPath)
 
         options.utilityPath = reftest.getFullPath(options.utilityPath)
 
 
 class B2GArgumentParser(ReftestArgumentsParser):
--- a/layout/tools/reftest/runreftest.py
+++ b/layout/tools/reftest/runreftest.py
@@ -32,18 +32,21 @@ import mozprocess
 import mozprofile
 import mozrunner
 from mozrunner.utils import get_stack_fixer_function, test_environment
 from mozscreenshot import printstatus, dump_screen
 
 try:
     from marionette import Marionette
     from marionette_driver.addons import Addons
-except ImportError:
-    Marionette=None
+except ImportError, e:
+    # Defer ImportError until attempt to use Marionette
+    def reraise(*args, **kwargs):
+        raise(e)
+    Marionette = reraise
 
 from output import OutputHandler, ReftestFormatter
 import reftestcommandline
 
 here = os.path.abspath(os.path.dirname(__file__))
 
 try:
     from mozbuild.base import MozbuildObject
@@ -720,13 +723,27 @@ def run(**kwargs):
     if 'tests' in kwargs:
         options = parser.parse_args(kwargs["tests"])
     else:
         options = parser.parse_args()
 
     reftest = RefTest()
     parser.validate(options, reftest)
 
+    # We have to validate options.app here for the case when the mach
+    # command is able to find it after argument parsing. This can happen
+    # when running from a tests.zip.
+    if not options.app:
+        parser.error("could not find the application path, --appname must be specified")
+
+    options.app = reftest.getFullPath(options.app)
+    if not os.path.exists(options.app):
+        parser.error("Error: Path %(app)s doesn't exist. Are you executing "
+                     "$objdir/_tests/reftest/runreftest.py?" % {"app": options.app})
+
+    if options.xrePath is None:
+        options.xrePath = os.path.dirname(options.app)
+
     return reftest.runTests(options.tests, options)
 
 
 if __name__ == "__main__":
     sys.exit(run())
--- a/testing/tools/mach_test_package_bootstrap.py
+++ b/testing/tools/mach_test_package_bootstrap.py
@@ -29,24 +29,26 @@ SEARCH_PATHS = [
     'mozbase/moznetwork',
     'mozbase/mozprocess',
     'mozbase/mozprofile',
     'mozbase/mozrunner',
     'mozbase/mozscreenshot',
     'mozbase/mozsystemmonitor',
     'mozbase/moztest',
     'mozbase/mozversion',
+    'reftest',
     'tools/mach',
     'tools/wptserve',
     'xpcshell',
 ]
 
 # Individual files providing mach commands.
 MACH_MODULES = [
     'mochitest/mach_test_package_commands.py',
+    'reftest/mach_test_package_commands.py',
     'tools/mach/mach/commands/commandinfo.py',
     'xpcshell/mach_test_package_commands.py',
 ]
 
 
 CATEGORIES = {
     'testing': {
         'short': 'Testing',