Bug 799308 - Mach command for running Marionette, r=gps
authorGregory Szorc <gps@mozilla.com>
Fri, 19 Apr 2013 05:19:54 -0700
changeset 131057 6c1668dfaaed2b95603a560eb6545b91d4150c12
parent 131056 350afae381eb05d34bb8d6f6342a776430767f18
child 131058 a104963ba21da302ce826c03fcd8c3c2e7652355
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs799308
milestone23.0a1
Bug 799308 - Mach command for running Marionette, r=gps
build/mach_bootstrap.py
testing/marionette/client/marionette/runtests.py
testing/marionette/mach_commands.py
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -17,32 +17,40 @@ SEARCH_PATHS = [
     'python/psutil',
     'python/which',
     'build/pymake',
     'config',
     'other-licenses/ply',
     'xpcom/idl-parser',
     'testing',
     'testing/xpcshell',
+    'testing/marionette/client',
+    'testing/marionette/client/marionette',
     'testing/mozbase/mozcrash',
+    'testing/mozbase/mozdevice',
+    'testing/mozbase/mozfile',
+    'testing/mozbase/mozhttpd',
     'testing/mozbase/mozlog',
+    'testing/mozbase/moznetwork',
     'testing/mozbase/mozprocess',
-    'testing/mozbase/mozfile',
+    'testing/mozbase/mozprofile',
+    'testing/mozbase/mozrunner',
     'testing/mozbase/mozinfo',
 ]
 
 # Individual files providing mach commands.
 MACH_MODULES = [
     'addon-sdk/mach_commands.py',
     'layout/tools/reftest/mach_commands.py',
     'python/mach/mach/commands/commandinfo.py',
     'python/mozboot/mozboot/mach_commands.py',
     'python/mozbuild/mozbuild/config.py',
     'python/mozbuild/mozbuild/mach_commands.py',
     'python/mozbuild/mozbuild/frontend/mach_commands.py',
+    'testing/marionette/mach_commands.py',
     'testing/mochitest/mach_commands.py',
     'testing/xpcshell/mach_commands.py',
     'tools/mach_commands.py',
 ]
 
 def bootstrap(topsrcdir, mozilla_dir=None):
     if mozilla_dir is None:
         mozilla_dir = topsrcdir
--- a/testing/marionette/client/marionette/runtests.py
+++ b/testing/marionette/client/marionette/runtests.py
@@ -632,19 +632,17 @@ class MarionetteTestOptions(OptionParser
                         action='store',
                         default='b2g',
                         help='the tree that the revision parameter refers to')
         self.add_option('--symbols-path',
                         dest='symbols_path',
                         action='store',
                         help='absolute path to directory containing breakpad symbols, or the url of a zip file containing symbols')
 
-    def verify_usage(self):
-        options, tests = self.parse_args()
-
+    def verify_usage(self, options, tests):
         if not tests:
             print 'must specify one or more test files, manifests, or directories'
             sys.exit(1)
 
         if not options.emulator and not options.address and not options.bin:
             print 'must specify --binary, --emulator or --address'
             sys.exit(1)
 
@@ -659,25 +657,27 @@ class MarionetteTestOptions(OptionParser
                 assert len(dims) == 2
                 width = str(int(dims[0]))
                 height = str(int(dims[1]))
                 options.emulator_res = 'x'.join([width, height])
         except:
             raise ValueError('Invalid emulator resolution format. '
                              'Should be like "480x800".')
 
+        return (options, tests)
+
 
 def startTestRunner(runner_class, options, tests):
     runner = runner_class(**vars(options))
     runner.run_tests(tests)
     return runner
 
 def cli(runner_class=MarionetteTestRunner, parser_class=MarionetteTestOptions):
     parser = parser_class(usage='%prog [options] test_file_or_dir <test_file_or_dir> ...')
-    parser.verify_usage()
     options, tests = parser.parse_args()
+    parser.verify_usage(options, tests)
 
     runner = startTestRunner(runner_class, options, tests)
     if runner.failed > 0:
         sys.exit(10)
 
 if __name__ == "__main__":
     cli()
new file mode 100644
--- /dev/null
+++ b/testing/marionette/mach_commands.py
@@ -0,0 +1,80 @@
+# 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 mozbuild.base import MachCommandBase
+
+from mach.decorators import (
+    CommandArgument,
+    CommandProvider,
+    Command,
+)
+
+
+@CommandProvider
+class MachCommands(MachCommandBase):
+    @Command('marionette-test', help='Run a Marionette test.')
+    @CommandArgument('--homedir', dest='b2g_path',
+        help='For B2G testing, the path to the B2G repo.')
+    @CommandArgument('--emulator', choices=['x86', 'arm'],
+        help='Run an emulator of the specified architecture.')
+    @CommandArgument('--address',
+        help='host:port of running Gecko instance to connect to.')
+    @CommandArgument('--type', dest='testtype',
+        help='Test type, usually one of: browser, b2g, b2g-qemu.')
+    @CommandArgument('tests', nargs='*', metavar='TESTS',
+        help='Path to test(s) to run.')
+    def run_marionette(self, tests, emulator=None, address=None, b2g_path=None,
+            testtype=None):
+        from marionette.runtests import (
+            MarionetteTestRunner,
+            MarionetteTestOptions,
+            startTestRunner
+        )
+
+        parser = MarionetteTestOptions()
+        options, args = parser.parse_args()
+
+        if not tests:
+            tests = ['testing/marionette/client/marionette/tests/unit-tests.ini']
+
+        options.type = testtype
+        if emulator:
+            if b2g_path:
+                options.homedir = b2g_path
+            if not testtype:
+                options.type = "b2g"
+        else:
+            if not testtype:
+                options.type = "browser"
+            try:
+                bin = self.get_binary_path('app')
+                options.bin = bin
+            except Exception as e:
+                print("It looks like your program isn't built.",
+                      "You can run |mach build| to build it.")
+                print(e)
+                return 1
+            path, exe = os.path.split(options.bin)
+            if 'b2g' in exe:
+                options.app = 'b2gdesktop'
+
+        if not emulator:
+            if self.substs.get('ENABLE_MARIONETTE') != '1':
+                print("Marionette doesn't appear to be enabled; please "
+                      "add ENABLE_MARIONETTE=1 to your mozconfig and "
+                      "perform a clobber build.")
+                return 1
+
+        options.address = address
+
+        parser.verify_usage(options, tests)
+
+        runner = startTestRunner(MarionetteTestRunner, options, tests)
+        if runner.failed > 0:
+            return 1
+
+        return 0