testing/mochitest/mach_test_package_commands.py
author Alessio Placitelli <alessio.placitelli@gmail.com>
Fri, 07 Oct 2016 03:35:00 -0400
changeset 317024 464f24871b18d468555c25e2df9421e2de79df34
parent 312863 dd6f0732c26084b026b8fc99b2da9f801baa9107
child 319004 85832226cbd70af940e2f093a28ebc9ec018fb48
permissions -rw-r--r--
Bug 1308415 - Update about:telemetry to show keyed scalars. r=gfritzsche

# 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 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=app)
    return parser


@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)