testing/marionette/mach_commands.py

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 from __future__ import unicode_literals
michael@0 6 import os
michael@0 7
michael@0 8 from mozbuild.base import (
michael@0 9 MachCommandBase,
michael@0 10 MachCommandConditions as conditions,
michael@0 11 )
michael@0 12
michael@0 13 from mach.decorators import (
michael@0 14 CommandArgument,
michael@0 15 CommandProvider,
michael@0 16 Command,
michael@0 17 )
michael@0 18
michael@0 19 MARIONETTE_DISABLED_B2G = '''
michael@0 20 The %s command requires a Marionette-enabled build.
michael@0 21
michael@0 22 Please create an engineering build, which has Marionette enabled. You can do
michael@0 23 this by ommitting the VARIANT variable when building, or using:
michael@0 24
michael@0 25 VARIANT=eng ./build.sh
michael@0 26 '''
michael@0 27
michael@0 28 def run_marionette(tests, b2g_path=None, emulator=None, testtype=None,
michael@0 29 address=None, bin=None, topsrcdir=None):
michael@0 30 from marionette.runtests import (
michael@0 31 MarionetteTestRunner,
michael@0 32 BaseMarionetteOptions,
michael@0 33 startTestRunner
michael@0 34 )
michael@0 35
michael@0 36 parser = BaseMarionetteOptions()
michael@0 37 options, args = parser.parse_args()
michael@0 38
michael@0 39 if not tests:
michael@0 40 tests = [os.path.join(topsrcdir,
michael@0 41 'testing/marionette/client/marionette/tests/unit-tests.ini')]
michael@0 42
michael@0 43 options.type = testtype
michael@0 44 if b2g_path:
michael@0 45 options.homedir = b2g_path
michael@0 46 if emulator:
michael@0 47 options.emulator = emulator
michael@0 48 else:
michael@0 49 options.bin = bin
michael@0 50 path, exe = os.path.split(options.bin)
michael@0 51
michael@0 52 options.address = address
michael@0 53
michael@0 54 parser.verify_usage(options, tests)
michael@0 55
michael@0 56 runner = startTestRunner(MarionetteTestRunner, options, tests)
michael@0 57 if runner.failed > 0:
michael@0 58 return 1
michael@0 59
michael@0 60 return 0
michael@0 61
michael@0 62 @CommandProvider
michael@0 63 class B2GCommands(MachCommandBase):
michael@0 64 def __init__(self, context):
michael@0 65 MachCommandBase.__init__(self, context)
michael@0 66
michael@0 67 for attr in ('b2g_home', 'device_name'):
michael@0 68 setattr(self, attr, getattr(context, attr, None))
michael@0 69 @Command('marionette-webapi', category='testing',
michael@0 70 description='Run a Marionette webapi test',
michael@0 71 conditions=[conditions.is_b2g])
michael@0 72 @CommandArgument('--emulator', choices=['x86', 'arm'],
michael@0 73 help='Run an emulator of the specified architecture.')
michael@0 74 @CommandArgument('--type', dest='testtype',
michael@0 75 help='Test type, usually one of: browser, b2g, b2g-qemu.',
michael@0 76 default='b2g')
michael@0 77 @CommandArgument('tests', nargs='*', metavar='TESTS',
michael@0 78 help='Path to test(s) to run.')
michael@0 79 def run_marionette_webapi(self, tests, emulator=None, testtype=None):
michael@0 80 if not emulator and self.device_name.find('emulator') == 0:
michael@0 81 emulator='arm'
michael@0 82
michael@0 83 if self.substs.get('ENABLE_MARIONETTE') != '1':
michael@0 84 print(MARIONETTE_DISABLED_B2G % 'marionette-webapi')
michael@0 85 return 1
michael@0 86
michael@0 87 return run_marionette(tests, b2g_path=self.b2g_home, emulator=emulator,
michael@0 88 testtype=testtype, topsrcdir=self.topsrcdir, address=None)
michael@0 89
michael@0 90
michael@0 91 @CommandProvider
michael@0 92 class MachCommands(MachCommandBase):
michael@0 93 @Command('marionette-test', category='testing',
michael@0 94 description='Run a Marionette test.',
michael@0 95 conditions=[conditions.is_firefox])
michael@0 96 @CommandArgument('--address',
michael@0 97 help='host:port of running Gecko instance to connect to.')
michael@0 98 @CommandArgument('--type', dest='testtype',
michael@0 99 help='Test type, usually one of: browser, b2g, b2g-qemu.',
michael@0 100 default='browser')
michael@0 101 @CommandArgument('tests', nargs='*', metavar='TESTS',
michael@0 102 help='Path to test(s) to run.')
michael@0 103 def run_marionette_test(self, tests, address=None, testtype=None):
michael@0 104 bin = self.get_binary_path('app')
michael@0 105 return run_marionette(tests, bin=bin, testtype=testtype,
michael@0 106 topsrcdir=self.topsrcdir, address=address)

mercurial