Example #1
0
    def run_xpcshell_test(self, test_objects=None, **params):
        from mozbuild.controller.building import BuildDriver

        if test_objects is not None:
            from manifestparser import TestManifest
            m = TestManifest()
            m.tests.extend(test_objects)
            params['manifest'] = m

        driver = self._spawn(BuildDriver)
        driver.install_tests(test_objects)

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        params['log'] = structured.commandline.setup_logging(
            "XPCShellTests", params, {"mach": sys.stdout}, {"verbose": True})

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #2
0
def setup_argument_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)

    build_path = os.path.join(build_obj.topobjdir, 'build')
    if build_path not in sys.path:
        sys.path.append(build_path)

    mochitest_dir = os.path.join(build_obj.topobjdir, '_tests', 'testing', 'mochitest')

    with warnings.catch_warnings():
        warnings.simplefilter('ignore')

        import imp
        path = os.path.join(build_obj.topobjdir, mochitest_dir, 'runtests.py')
        if not os.path.exists(path):
            path = os.path.join(here, "runtests.py")

        with open(path, 'r') as fh:
            imp.load_module('mochitest', fh, path,
                            ('.py', 'r', imp.PY_SOURCE))

        from mochitest_options import MochitestArgumentParser

    if conditions.is_android(build_obj):
        # On Android, check for a connected device (and offer to start an
        # emulator if appropriate) before running tests. This check must
        # be done in this admittedly awkward place because
        # MochitestArgumentParser initialization fails if no device is found.
        from mozrunner.devices.android_device import verify_android_device
        verify_android_device(build_obj, install=True, xre=True)

    global parser
    parser = MochitestArgumentParser()
    return parser
Example #3
0
    def run_xpcshell_test(self, **params):
        from mozbuild.controller.building import BuildDriver

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        driver = self._spawn(BuildDriver)
        driver.install_tests(remove=False)

        params['log'] = structured.commandline.setup_logging(
            "XPCShellTests", params, {"mach": sys.stdout}, {"verbose": True})

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        elif conditions.is_b2g(self):
            xpcshell = self._spawn(B2GXPCShellRunner)
            params['b2g_home'] = self.b2g_home
            params['device_name'] = self.device_name
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #4
0
def setup_junit_argument_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)

    build_path = os.path.join(build_obj.topobjdir, 'build')
    if build_path not in sys.path:
        sys.path.append(build_path)

    mochitest_dir = os.path.join(build_obj.topobjdir, '_tests', 'testing',
                                 'mochitest')

    with warnings.catch_warnings():
        warnings.simplefilter('ignore')

        # runtests.py contains MochitestDesktop, required by runjunit
        import imp
        path = os.path.join(build_obj.topobjdir, mochitest_dir, 'runtests.py')
        if not os.path.exists(path):
            path = os.path.join(here, "runtests.py")

        with open(path, 'r') as fh:
            imp.load_module('mochitest', fh, path, ('.py', 'r', imp.PY_SOURCE))

        import runjunit

        from mozrunner.devices.android_device import verify_android_device
        verify_android_device(build_obj, install=False, xre=True, network=True)

    global parser
    parser = runjunit.JunitArgumentParser()
    return parser
Example #5
0
    def kwargs_common(self, kwargs):
        tests_src_path = os.path.join(self._here, "tests")
        if kwargs["product"] == "fennec":
            # package_name may be non-fennec in the future
            package_name = kwargs["package_name"]
            if not package_name:
                package_name = self.substs["ANDROID_PACKAGE_NAME"]

            # Note that this import may fail in non-fennec trees
            from mozrunner.devices.android_device import verify_android_device, grant_runtime_permissions
            verify_android_device(self,
                                  install=True,
                                  verbose=False,
                                  xre=True,
                                  app=package_name)

            grant_runtime_permissions(self, package_name,
                                      kwargs["device_serial"])
            if kwargs["certutil_binary"] is None:
                kwargs["certutil_binary"] = os.path.join(
                    os.environ.get('MOZ_HOST_BIN'), "certutil")

            if kwargs["install_fonts"] is None:
                kwargs["install_fonts"] = True

        if kwargs["config"] is None:
            kwargs["config"] = os.path.join(self.topobjdir, '_tests',
                                            'web-platform',
                                            'wptrunner.local.ini')

        if kwargs["prefs_root"] is None:
            kwargs["prefs_root"] = os.path.join(self.topsrcdir, 'testing',
                                                'profiles')

        if kwargs["stackfix_dir"] is None:
            kwargs["stackfix_dir"] = self.bindir

        if kwargs["exclude"] is None and kwargs[
                "include"] is None and not sys.platform.startswith("linux"):
            kwargs["exclude"] = ["css"]

        if kwargs["ssl_type"] in (None, "pregenerated"):
            cert_root = os.path.join(tests_src_path, "tools", "certs")
            if kwargs["ca_cert_path"] is None:
                kwargs["ca_cert_path"] = os.path.join(cert_root, "cacert.pem")

            if kwargs["host_key_path"] is None:
                kwargs["host_key_path"] = os.path.join(
                    cert_root, "web-platform.test.key")

            if kwargs["host_cert_path"] is None:
                kwargs["host_cert_path"] = os.path.join(
                    cert_root, "web-platform.test.pem")

        if kwargs["log_mach_screenshot"] is None:
            kwargs["log_mach_screenshot"] = True

        kwargs["capture_stdio"] = True

        return kwargs
Example #6
0
 def _run_reftest(self, **kwargs):
     kwargs["topsrcdir"] = self.topsrcdir
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     # Unstructured logging must be enabled prior to calling
     # adb which uses an unstructured logger in its constructor.
     reftest.log_manager.enable_unstructured()
     if conditions.is_android(self):
         from mozrunner.devices.android_device import (
             verify_android_device, InstallIntent)
         install = InstallIntent.NO if kwargs.get(
             'no_install') else InstallIntent.YES
         verbose = False
         if kwargs.get('log_mach_verbose') or kwargs.get('log_tbpl_level') == 'debug' or \
            kwargs.get('log_mach_level') == 'debug' or kwargs.get('log_raw_level') == 'debug':
             verbose = True
         verify_android_device(self,
                               install=install,
                               xre=True,
                               network=True,
                               app=kwargs["app"],
                               device_serial=kwargs["deviceSerial"],
                               verbose=verbose)
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #7
0
    def kwargs_common(self, kwargs):
        tests_src_path = os.path.join(self._here, "tests")
        if kwargs["product"] == "firefox_android":
            # package_name may be different in the future
            package_name = kwargs["package_name"]
            if not package_name:
                kwargs[
                    "package_name"] = package_name = "org.mozilla.geckoview.test"

            # Note that this import may fail in non-firefox-for-android trees
            from mozrunner.devices.android_device import (
                verify_android_device, InstallIntent)
            verify_android_device(self,
                                  install=InstallIntent.PROMPT,
                                  verbose=False,
                                  xre=True,
                                  app=package_name)

            if kwargs["certutil_binary"] is None:
                kwargs["certutil_binary"] = os.path.join(
                    os.environ.get('MOZ_HOST_BIN'), "certutil")

            if kwargs["install_fonts"] is None:
                kwargs["install_fonts"] = True

        if kwargs["config"] is None:
            kwargs["config"] = os.path.join(self.topobjdir, '_tests',
                                            'web-platform',
                                            'wptrunner.local.ini')

        if kwargs["prefs_root"] is None:
            kwargs["prefs_root"] = os.path.join(self.topsrcdir, 'testing',
                                                'profiles')

        if kwargs["stackfix_dir"] is None:
            kwargs["stackfix_dir"] = self.bindir

        if kwargs["exclude"] is None and kwargs[
                "include"] is None and not sys.platform.startswith("linux"):
            kwargs["exclude"] = ["css"]

        if kwargs["ssl_type"] in (None, "pregenerated"):
            cert_root = os.path.join(tests_src_path, "tools", "certs")
            if kwargs["ca_cert_path"] is None:
                kwargs["ca_cert_path"] = os.path.join(cert_root, "cacert.pem")

            if kwargs["host_key_path"] is None:
                kwargs["host_key_path"] = os.path.join(
                    cert_root, "web-platform.test.key")

            if kwargs["host_cert_path"] is None:
                kwargs["host_cert_path"] = os.path.join(
                    cert_root, "web-platform.test.pem")

        if kwargs["reftest_screenshot"] is None:
            kwargs["reftest_screenshot"] = "fail"

        kwargs["capture_stdio"] = True

        return kwargs
Example #8
0
    def run_xpcshell_test(self, test_objects=None, **params):
        from mozbuild.controller.building import BuildDriver

        if test_objects is not None:
            from manifestparser import TestManifest
            m = TestManifest()
            m.tests.extend(test_objects)
            params['manifest'] = m

        driver = self._spawn(BuildDriver)
        driver.install_tests(test_objects)

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        params['log'] = structured.commandline.setup_logging("XPCShellTests",
                                                             params,
                                                             {"mach": sys.stdout},
                                                             {"verbose": True})

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #9
0
    def run_cppunit_test(self, **params):
        from mozlog import commandline

        log = params.get("log")
        if not log:
            log = commandline.setup_logging("cppunittest", {}, {"tbpl": sys.stdout})

        # See if we have crash symbols
        symbols_path = os.path.join(self.distdir, "crashreporter-symbols")
        if not os.path.isdir(symbols_path):
            symbols_path = None

        # If no tests specified, run all tests in main manifest
        tests = params["test_files"]
        if not tests:
            tests = [os.path.join(self.distdir, "cppunittests")]
            manifest_path = os.path.join(self.topsrcdir, "testing", "cppunittest.ini")
        else:
            manifest_path = None

        utility_path = self.bindir

        if conditions.is_android(self):
            from mozrunner.devices.android_device import (
                verify_android_device,
                InstallIntent,
            )

            verify_android_device(self, install=InstallIntent.NO)
            return self.run_android_test(tests, symbols_path, manifest_path, log)

        return self.run_desktop_test(
            tests, symbols_path, manifest_path, utility_path, log
        )
Example #10
0
    def run_junit(self, **kwargs):
        self._ensure_state_subdir_exists('.')

        from mozrunner.devices.android_device import (
            grant_runtime_permissions, get_adb_path, verify_android_device)
        # verify installation
        app = kwargs.get('app')
        device_serial = kwargs.get('deviceSerial')
        verify_android_device(self,
                              install=True,
                              xre=False,
                              app=app,
                              device_serial=device_serial)
        grant_runtime_permissions(self, app, device_serial=device_serial)

        if not kwargs.get('adbPath'):
            kwargs['adbPath'] = get_adb_path(self)

        if not kwargs.get('log'):
            from mozlog.commandline import setup_logging
            format_args = {
                'level': self._mach_context.settings['test']['level']
            }
            default_format = self._mach_context.settings['test']['format']
            kwargs['log'] = setup_logging('mach-mochitest', kwargs,
                                          {default_format: sys.stdout},
                                          format_args)

        mochitest = self._spawn(MochitestRunner)
        return mochitest.run_geckoview_junit_test(self._mach_context, **kwargs)
Example #11
0
    def run_xpcshell_test(self, **params):
        from mozbuild.controller.building import BuildDriver

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        driver = self._spawn(BuildDriver)
        driver.install_tests(remove=False)

        params['log'] = structured.commandline.setup_logging("XPCShellTests",
                                                             params,
                                                             {"mach": sys.stdout},
                                                             {"verbose": True})

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        elif conditions.is_b2g(self):
            xpcshell = self._spawn(B2GXPCShellRunner)
            params['b2g_home'] = self.b2g_home
            params['device_name'] = self.device_name
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #12
0
    def run_cppunit_test(self, **params):
        import mozinfo
        from mozlog import commandline
        log = commandline.setup_logging("cppunittest",
                                        {},
                                        {"tbpl": sys.stdout})

        # See if we have crash symbols
        symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
        if not os.path.isdir(symbols_path):
            symbols_path = None

        # If no tests specified, run all tests in main manifest
        tests = params['test_files']
        if len(tests) == 0:
            tests = [os.path.join(self.distdir, 'cppunittests')]
            manifest_path = os.path.join(self.topsrcdir, 'testing', 'cppunittest.ini')
        else:
            manifest_path = None

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self, install=False)
            return self.run_android_test(tests, symbols_path, manifest_path, log)

        return self.run_desktop_test(tests, symbols_path, manifest_path, log)
Example #13
0
    def run_cppunit_test(self, **params):
        from mozlog import commandline
        log = commandline.setup_logging("cppunittest", {},
                                        {"tbpl": sys.stdout})

        # See if we have crash symbols
        symbols_path = os.path.join(self.distdir, 'crashreporter-symbols')
        if not os.path.isdir(symbols_path):
            symbols_path = None

        # If no tests specified, run all tests in main manifest
        tests = params['test_files']
        if len(tests) == 0:
            tests = [os.path.join(self.distdir, 'cppunittests')]
            manifest_path = os.path.join(self.topsrcdir, 'testing',
                                         'cppunittest.ini')
        else:
            manifest_path = None

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device
            verify_android_device(self, install=False)
            return self.run_android_test(tests, symbols_path, manifest_path,
                                         log)

        return self.run_desktop_test(tests, symbols_path, manifest_path, log)
Example #14
0
def setup_argument_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)

    build_path = os.path.join(build_obj.topobjdir, 'build')
    if build_path not in sys.path:
        sys.path.append(build_path)

    mochitest_dir = os.path.join(build_obj.topobjdir, '_tests', 'testing',
                                 'mochitest')

    with warnings.catch_warnings():
        warnings.simplefilter('ignore')

        import imp
        path = os.path.join(build_obj.topobjdir, mochitest_dir, 'runtests.py')
        if not os.path.exists(path):
            path = os.path.join(here, "runtests.py")

        with open(path, 'r') as fh:
            imp.load_module('mochitest', fh, path, ('.py', 'r', imp.PY_SOURCE))

        from mochitest_options import MochitestArgumentParser

    if conditions.is_android(build_obj):
        # On Android, check for a connected device (and offer to start an
        # emulator if appropriate) before running tests. This check must
        # be done in this admittedly awkward place because
        # MochitestArgumentParser initialization fails if no device is found.
        from mozrunner.devices.android_device import verify_android_device
        # verify device and xre
        verify_android_device(build_obj, install=False, xre=True)

    global parser
    parser = MochitestArgumentParser()
    return parser
Example #15
0
 def _run_reftest(self, **kwargs):
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True)
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #16
0
 def _run_reftest(self, **kwargs):
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True)
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #17
0
    def run_robocop(self, serve=False, **kwargs):
        if serve:
            kwargs['autorun'] = False

        if not kwargs.get('robocopIni'):
            kwargs['robocopIni'] = os.path.join(self.topobjdir, '_tests',
                                                'testing', 'mochitest',
                                                'robocop.ini')

        from mozbuild.controller.building import BuildDriver
        self._ensure_state_subdir_exists('.')

        test_paths = kwargs['test_paths']
        kwargs['test_paths'] = []

        from moztest.resolve import TestResolver
        resolver = self._spawn(TestResolver)
        tests = list(
            resolver.resolve_tests(paths=test_paths,
                                   cwd=self._mach_context.cwd,
                                   flavor='instrumentation',
                                   subsuite='robocop'))
        driver = self._spawn(BuildDriver)
        driver.install_tests(tests)

        if len(tests) < 1:
            print(
                ROBOCOP_TESTS_NOT_FOUND.format('\n'.join(
                    sorted(list(test_paths)))))
            return 1

        from mozrunner.devices.android_device import grant_runtime_permissions, get_adb_path
        from mozrunner.devices.android_device import verify_android_device
        # verify installation
        app = kwargs.get('app')
        if not app:
            kwargs['app'] = app = self.substs["ANDROID_PACKAGE_NAME"]
        device_serial = kwargs.get('deviceSerial')

        # setup adb logging so that grant_runtime_permissions can log
        from mozlog.commandline import setup_logging
        format_args = {'level': self._mach_context.settings['test']['level']}
        default_format = self._mach_context.settings['test']['format']
        setup_logging('adb', kwargs, {default_format: sys.stdout}, format_args)

        verify_android_device(self,
                              install=True,
                              xre=False,
                              network=True,
                              app=app,
                              device_serial=device_serial)
        grant_runtime_permissions(self, app, device_serial=device_serial)

        if not kwargs['adbPath']:
            kwargs['adbPath'] = get_adb_path(self)

        mochitest = self._spawn(MochitestRunner)
        return mochitest.run_robocop_test(self._mach_context, tests, **kwargs)
Example #18
0
    def run_xpcshell_test(self, test_objects=None, **params):
        from mozbuild.controller.building import BuildDriver

        if test_objects is not None:
            from manifestparser import TestManifest

            m = TestManifest()
            m.tests.extend(test_objects)
            params["manifest"] = m

        driver = self._spawn(BuildDriver)
        driver.install_tests()

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists(".")

        if not params.get("log"):
            log_defaults = {
                self._mach_context.settings["test"]["format"]: sys.stdout
            }
            fmt_defaults = {
                "level": self._mach_context.settings["test"]["level"],
                "verbose": True,
            }
            params["log"] = structured.commandline.setup_logging(
                "XPCShellTests", params, log_defaults, fmt_defaults)

        if not params["threadCount"]:
            # pylint --py3k W1619
            params["threadCount"] = int((cpu_count() * 3) / 2)

        if conditions.is_android(self) or self.substs.get(
                "MOZ_BUILD_APP") == "b2g":
            from mozrunner.devices.android_device import (
                verify_android_device,
                get_adb_path,
            )

            device_serial = params.get("deviceSerial")
            verify_android_device(self,
                                  network=True,
                                  device_serial=device_serial)
            if not params["adbPath"]:
                params["adbPath"] = get_adb_path(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(str(e))
            return 1
Example #19
0
 def _run_reftest(self, **kwargs):
     kwargs["topsrcdir"] = self.topsrcdir
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True, app=kwargs["app"],
                               device_serial=kwargs["deviceSerial"])
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #20
0
    def install(self, verbose=False):
        from mozrunner.devices.android_device import verify_android_device
        verify_android_device(self, verbose=verbose)

        ret = self._run_make(directory='.',
                             target='install',
                             ensure_exit_code=False)
        if ret == 0:
            self.notify('Install complete')
        return ret
Example #21
0
    def run(self,
            url=None,
            no_install=None,
            no_wait=None,
            fail_if_running=None):
        from mozrunner.devices.android_device import verify_android_device, run_firefox_for_android

        verify_android_device(self, install=not no_install)
        return run_firefox_for_android(self, [],
                                       url=url,
                                       wait=not no_wait,
                                       fail_if_running=fail_if_running)
Example #22
0
 def _run_reftest(self, **kwargs):
     kwargs["topsrcdir"] = self.topsrcdir
     process_test_objects(kwargs)
     reftest = self._spawn(ReftestRunner)
     # Unstructured logging must be enabled prior to calling
     # adb which uses an unstructured logger in its constructor.
     reftest.log_manager.enable_unstructured()
     if conditions.is_android(self):
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(self, install=True, xre=True, network=True,
                               app=kwargs["app"], device_serial=kwargs["deviceSerial"])
         return reftest.run_android_test(**kwargs)
     return reftest.run_desktop_test(**kwargs)
Example #23
0
    def run_xpcshell_test(self, test_objects=None, **params):
        from mozbuild.controller.building import BuildDriver

        if test_objects is not None:
            from manifestparser import TestManifest
            m = TestManifest()
            m.tests.extend(test_objects)
            params['manifest'] = m

        driver = self._spawn(BuildDriver)
        driver.install_tests(test_objects)

        # We should probably have a utility function to ensure the tree is
        # ready to run tests. Until then, we just create the state dir (in
        # case the tree wasn't built with mach).
        self._ensure_state_subdir_exists('.')

        if not params.get('log'):
            log_defaults = {
                self._mach_context.settings['test']['format']: sys.stdout
            }
            fmt_defaults = {
                "level": self._mach_context.settings['test']['level'],
                "verbose": True
            }
            params['log'] = structured.commandline.setup_logging(
                "XPCShellTests", params, log_defaults, fmt_defaults)

        if not params['threadCount']:
            params['threadCount'] = int((cpu_count() * 3) / 2)

        if conditions.is_android(self):
            from mozrunner.devices.android_device import verify_android_device, get_adb_path
            device_serial = params.get('deviceSerial')
            verify_android_device(self,
                                  network=True,
                                  device_serial=device_serial)
            if not params['adbPath']:
                params['adbPath'] = get_adb_path(self)
            xpcshell = self._spawn(AndroidXPCShellRunner)
        else:
            xpcshell = self._spawn(XPCShellRunner)
        xpcshell.cwd = self._mach_context.cwd

        try:
            return xpcshell.run_test(**params)
        except InvalidTestPathError as e:
            print(e.message)
            return 1
Example #24
0
    def run_raptor(self, **kwargs):
        build_obj = self

        is_android = Conditions.is_android(build_obj) or \
            kwargs['app'] in FIREFOX_ANDROID_BROWSERS

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device, InstallIntent)
            from mozdevice import ADBAndroid
            install = InstallIntent.NO if kwargs.pop(
                'noinstall', False) else InstallIntent.PROMPT
            if not verify_android_device(
                    build_obj, install=install, app=kwargs['binary'],
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)
        device = None

        try:
            if kwargs['power_test'] and is_android:
                device = ADBAndroid(verbose=True)
                disable_charging(device)
            return raptor.run_test(sys.argv[2:], kwargs)
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            if kwargs['power_test'] and device:
                enable_charging(device)
    def run_robocop(self, serve=False, **kwargs):
        if serve:
            kwargs['autorun'] = False

        if not kwargs.get('robocopIni'):
            kwargs['robocopIni'] = os.path.join(self.topobjdir, '_tests',
                                                'testing', 'mochitest',
                                                'robocop.ini')

        from mozbuild.controller.building import BuildDriver
        self._ensure_state_subdir_exists('.')

        test_paths = kwargs['test_paths']
        kwargs['test_paths'] = []

        from moztest.resolve import TestResolver
        resolver = self._spawn(TestResolver)
        tests = list(
            resolver.resolve_tests(paths=test_paths,
                                   cwd=self._mach_context.cwd,
                                   flavor='instrumentation',
                                   subsuite='robocop'))
        driver = self._spawn(BuildDriver)
        driver.install_tests(tests)

        if len(tests) < 1:
            print(
                ROBOCOP_TESTS_NOT_FOUND.format('\n'.join(
                    sorted(list(test_paths)))))
            return 1

        from mozrunner.devices.android_device import grant_runtime_permissions, get_adb_path
        from mozrunner.devices.android_device import verify_android_device
        # verify installation
        app = kwargs.get('app')
        if not app:
            app = self.substs["ANDROID_PACKAGE_NAME"]
        verify_android_device(self, install=True, xre=False, app=app)
        grant_runtime_permissions(self, app)

        if not kwargs['adbPath']:
            kwargs['adbPath'] = get_adb_path(self)

        mochitest = self._spawn(MochitestRunner)
        return mochitest.run_robocop_test(self._mach_context, tests, 'robocop',
                                          **kwargs)
Example #26
0
    def run_raptor(self, **kwargs):
        # Defers this import so that a transitive dependency doesn't
        # stop |mach bootstrap| from running
        from raptor.power import enable_charging, disable_charging

        build_obj = self

        is_android = (Conditions.is_android(build_obj)
                      or kwargs["app"] in ANDROID_BROWSERS)

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device,
                InstallIntent,
            )
            from mozdevice import ADBDeviceFactory

            install = (InstallIntent.NO if kwargs.pop("noinstall", False) else
                       InstallIntent.YES)
            verbose = False
            if (kwargs.get("log_mach_verbose")
                    or kwargs.get("log_tbpl_level") == "debug"
                    or kwargs.get("log_mach_level") == "debug"
                    or kwargs.get("log_raw_level") == "debug"):
                verbose = True
            if not verify_android_device(
                    build_obj,
                    install=install,
                    app=kwargs["binary"],
                    verbose=verbose,
                    xre=True,
            ):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = "--debug-command"
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)
        device = None

        try:
            if kwargs["power_test"] and is_android:
                device = ADBDeviceFactory(verbose=True)
                disable_charging(device)
            return raptor.run_test(sys.argv[2:], kwargs)
        except BinaryNotFoundException as e:
            self.log(logging.ERROR, "raptor", {"error": str(e)},
                     "ERROR: {error}")
            self.log(logging.INFO, "raptor", {"help": e.help()}, "{help}")
            return 1
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            if kwargs["power_test"] and device:
                enable_charging(device)
Example #27
0
    def run_raptor_test(self, **kwargs):

        build_obj = MozbuildObject.from_environment(cwd=HERE)

        firefox_android_browsers = ["fennec", "geckoview", "refbrow", "fenix"]

        if conditions.is_android(
                build_obj) or kwargs['app'] in firefox_android_browsers:
            from mozrunner.devices.android_device import verify_android_device
            from mozdevice import ADBAndroid, ADBHost
            if not verify_android_device(
                    build_obj, install=True, app=kwargs['binary'],
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)

        try:
            if kwargs['app'] in firefox_android_browsers and kwargs[
                    'power_test']:
                device = ADBAndroid(verbose=True)
                adbhost = ADBHost(verbose=True)
                device_serial = "%s:5555" % device.get_ip_address()
                device.command_output(["tcpip", "5555"])
                raw_input(
                    "Please disconnect your device from USB then press Enter/return..."
                )
                adbhost.command_output(["connect", device_serial])
                while len(adbhost.devices()) > 1:
                    raw_input(
                        "You must disconnect your device from USB before continuing."
                    )
                # must reset the environment DEVICE_SERIAL which was set during
                # verify_android_device to match our new tcpip value.
                os.environ["DEVICE_SERIAL"] = device_serial
            return raptor.run_test(sys.argv[2:], kwargs)
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            try:
                if kwargs['app'] in firefox_android_browsers and kwargs[
                        'power_test']:
                    raw_input(
                        "Connect device via USB and press Enter/return...")
                    device = ADBAndroid(device=device_serial, verbose=True)
                    device.command_output(["usb"])
                    adbhost.command_output(["disconnect", device_serial])
            except Exception:
                adbhost.command_output(["kill-server"])
Example #28
0
    def run_raptor(self, **kwargs):
        build_obj = self

        is_android = Conditions.is_android(build_obj) or \
            kwargs['app'] in FIREFOX_ANDROID_BROWSERS

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device, InstallIntent)
            from mozdevice import ADBAndroid, ADBHost
            install = InstallIntent.NO if kwargs.pop(
                'noinstall', False) else InstallIntent.PROMPT
            if not verify_android_device(
                    build_obj, install=install, app=kwargs['binary'],
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)

        try:
            if is_android and kwargs['power_test']:
                device = ADBAndroid(verbose=True)
                adbhost = ADBHost(verbose=True)
                device_serial = "{}:5555".format(device.get_ip_address())
                device.command_output(["tcpip", "5555"])
                six.input(
                    "Please disconnect your device from USB then press Enter/return..."
                )
                adbhost.command_output(["connect", device_serial])
                while len(adbhost.devices()) > 1:
                    six.input(
                        "You must disconnect your device from USB before continuing."
                    )
                # must reset the environment DEVICE_SERIAL which was set during
                # verify_android_device to match our new tcpip value.
                os.environ["DEVICE_SERIAL"] = device_serial
            return raptor.run_test(sys.argv[2:], kwargs)
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            try:
                if is_android and kwargs['power_test']:
                    six.input(
                        "Connect device via USB and press Enter/return...")
                    device = ADBAndroid(device=device_serial, verbose=True)
                    device.command_output(["usb"])
                    adbhost.command_output(["disconnect", device_serial])
            except Exception:
                adbhost.command_output(["kill-server"])
    def run_raptor(self, **kwargs):
        # Defers this import so that a transitive dependency doesn't
        # stop |mach bootstrap| from running
        from raptor.power import enable_charging, disable_charging

        build_obj = self

        is_android = Conditions.is_android(build_obj) or \
            kwargs['app'] in ANDROID_BROWSERS

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device, InstallIntent)
            from mozdevice import ADBAndroid
            install = InstallIntent.NO if kwargs.pop(
                'noinstall', False) else InstallIntent.YES
            verbose = False
            if kwargs.get('log_mach_verbose') or kwargs.get('log_tbpl_level') == 'debug' or \
               kwargs.get('log_mach_level') == 'debug' or kwargs.get('log_raw_level') == 'debug':
                verbose = True
            if not verify_android_device(
                    build_obj,
                    install=install,
                    app=kwargs['binary'],
                    verbose=verbose,
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)
        device = None

        try:
            if kwargs['power_test'] and is_android:
                device = ADBAndroid(verbose=True)
                disable_charging(device)
            return raptor.run_test(sys.argv[2:], kwargs)
        except BinaryNotFoundException as e:
            self.log(logging.ERROR, 'raptor', {'error': str(e)},
                     'ERROR: {error}')
            self.log(logging.INFO, 'raptor', {'help': e.help()}, '{help}')
            return 1
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            if kwargs['power_test'] and device:
                enable_charging(device)
Example #30
0
def setup_junit_argument_parser():
    build_obj = MozbuildObject.from_environment(cwd=here)

    build_path = os.path.join(build_obj.topobjdir, "build")
    if build_path not in sys.path:
        sys.path.append(build_path)

    mochitest_dir = os.path.join(build_obj.topobjdir, "_tests", "testing",
                                 "mochitest")

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")

        # runtests.py contains MochitestDesktop, required by runjunit
        import imp

        path = os.path.join(build_obj.topobjdir, mochitest_dir, "runtests.py")
        if not os.path.exists(path):
            path = os.path.join(here, "runtests.py")

        with open(path, "r") as fh:
            imp.load_module("mochitest", fh, path, (".py", "r", imp.PY_SOURCE))

        import runjunit

        from mozrunner.devices.android_device import (
            verify_android_device,
            InstallIntent,
        )

        verify_android_device(build_obj,
                              install=InstallIntent.NO,
                              xre=True,
                              network=True)

    global parser
    parser = runjunit.JunitArgumentParser()
    return parser
Example #31
0
def run_junit(command_context, no_install, **kwargs):
    command_context._ensure_state_subdir_exists(".")

    from mozrunner.devices.android_device import (
        get_adb_path,
        verify_android_device,
        InstallIntent,
    )

    # verify installation
    app = kwargs.get("app")
    device_serial = kwargs.get("deviceSerial")
    verify_android_device(
        command_context,
        install=InstallIntent.NO if no_install else InstallIntent.YES,
        xre=False,
        app=app,
        device_serial=device_serial,
    )

    if not kwargs.get("adbPath"):
        kwargs["adbPath"] = get_adb_path(command_context)

    if not kwargs.get("log"):
        from mozlog.commandline import setup_logging

        format_args = {
            "level": command_context._mach_context.settings["test"]["level"]
        }
        default_format = command_context._mach_context.settings["test"][
            "format"]
        kwargs["log"] = setup_logging("mach-mochitest", kwargs,
                                      {default_format: sys.stdout},
                                      format_args)

    mochitest = command_context._spawn(MochitestRunner)
    return mochitest.run_geckoview_junit_test(command_context._mach_context,
                                              **kwargs)
Example #32
0
    def run_raptor_test(self, **kwargs):

        from mozrunner.devices.android_device import verify_android_device

        build_obj = MozbuildObject.from_environment(cwd=HERE)
        if not verify_android_device(build_obj, install=True, app=kwargs['binary']):
            return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)

        try:
            return raptor.run_test(sys.argv[2:], app=kwargs['app'])
        except Exception as e:
            print(str(e))
            return 1
Example #33
0
    def run_raptor(self, **kwargs):
        build_obj = self

        is_android = Conditions.is_android(build_obj) or \
            kwargs['app'] in ANDROID_BROWSERS

        if is_android:
            from mozrunner.devices.android_device import (
                verify_android_device, InstallIntent)
            from mozdevice import ADBAndroid
            install = InstallIntent.NO if kwargs.pop(
                'noinstall', False) else InstallIntent.YES
            if not verify_android_device(
                    build_obj, install=install, app=kwargs['binary'],
                    xre=True):  # Equivalent to 'run_local' = True.
                return 1

        debug_command = '--debug-command'
        if debug_command in sys.argv:
            sys.argv.remove(debug_command)

        raptor = self._spawn(RaptorRunner)
        device = None

        try:
            if kwargs['power_test'] and is_android:
                device = ADBAndroid(verbose=True)
                disable_charging(device)
            return raptor.run_test(sys.argv[2:], kwargs)
        except BinaryNotFoundException as e:
            self.log(logging.ERROR, 'raptor', {'error': str(e)},
                     'ERROR: {error}')
            self.log(logging.INFO, 'raptor', {'help': e.help()}, '{help}')
            return 1
        except Exception as e:
            print(repr(e))
            return 1
        finally:
            if kwargs['power_test'] and device:
                enable_charging(device)
Example #34
0
    def run_mochitest_general(self,
                              flavor=None,
                              test_objects=None,
                              resolve_tests=True,
                              **kwargs):
        from mochitest_options import ALL_FLAVORS
        from mozlog.commandline import setup_logging
        from mozlog.handlers import StreamHandler
        from moztest.resolve import get_suite_definition

        buildapp = None
        for app in SUPPORTED_APPS:
            if is_buildapp_in(app)(self):
                buildapp = app
                break

        flavors = None
        if flavor:
            for fname, fobj in ALL_FLAVORS.iteritems():
                if flavor in fobj['aliases']:
                    if buildapp not in fobj['enabled_apps']:
                        continue
                    flavors = [fname]
                    break
        else:
            flavors = [
                f for f, v in ALL_FLAVORS.iteritems()
                if buildapp in v['enabled_apps']
            ]

        from mozbuild.controller.building import BuildDriver
        self._ensure_state_subdir_exists('.')

        test_paths = kwargs['test_paths']
        kwargs['test_paths'] = []

        mochitest = self._spawn(MochitestRunner)
        tests = []
        if resolve_tests:
            tests = mochitest.resolve_tests(test_paths,
                                            test_objects,
                                            cwd=self._mach_context.cwd)

        if not kwargs.get('log'):
            # Create shared logger
            format_args = {
                'level': self._mach_context.settings['test']['level']
            }
            if len(tests) == 1:
                format_args['verbose'] = True
                format_args['compact'] = False

            default_format = self._mach_context.settings['test']['format']
            kwargs['log'] = setup_logging('mach-mochitest', kwargs,
                                          {default_format: sys.stdout},
                                          format_args)
            for handler in kwargs['log'].handlers:
                if isinstance(handler, StreamHandler):
                    handler.formatter.inner.summary_on_shutdown = True

        driver = self._spawn(BuildDriver)
        driver.install_tests(tests)

        subsuite = kwargs.get('subsuite')
        if subsuite == 'default':
            kwargs['subsuite'] = None

        suites = defaultdict(list)
        unsupported = set()
        for test in tests:
            # Filter out non-mochitests and unsupported flavors.
            if test['flavor'] not in ALL_FLAVORS:
                continue

            key = (test['flavor'], test.get('subsuite', ''))
            if test['flavor'] not in flavors:
                unsupported.add(key)
                continue

            if subsuite == 'default':
                # "--subsuite default" means only run tests that don't have a subsuite
                if test.get('subsuite'):
                    unsupported.add(key)
                    continue
            elif subsuite and test.get('subsuite', '') != subsuite:
                unsupported.add(key)
                continue

            suites[key].append(test)

        if ('mochitest', 'media') in suites:
            req = os.path.join('testing', 'tools', 'websocketprocessbridge',
                               'websocketprocessbridge_requirements.txt')
            self.virtualenv_manager.activate()
            self.virtualenv_manager.install_pip_requirements(
                req, require_hashes=False)

            # sys.executable is used to start the websocketprocessbridge, though for some
            # reason it doesn't get set when calling `activate_this.py` in the virtualenv.
            sys.executable = self.virtualenv_manager.python_path

        # This is a hack to introduce an option in mach to not send
        # filtered tests to the mochitest harness. Mochitest harness will read
        # the master manifest in that case.
        if not resolve_tests:
            for flavor in flavors:
                key = (flavor, kwargs.get('subsuite'))
                suites[key] = []

        if not suites:
            # Make it very clear why no tests were found
            if not unsupported:
                print(
                    TESTS_NOT_FOUND.format('\n'.join(
                        sorted(list(test_paths or test_objects)))))
                return 1

            msg = []
            for f, s in unsupported:
                fobj = ALL_FLAVORS[f]
                apps = fobj['enabled_apps']
                name = fobj['aliases'][0]
                if s:
                    name = '{} --subsuite {}'.format(name, s)

                if buildapp not in apps:
                    reason = 'requires {}'.format(' or '.join(apps))
                else:
                    reason = 'excluded by the command line'
                msg.append('    mochitest -f {} ({})'.format(name, reason))
            print(
                SUPPORTED_TESTS_NOT_FOUND.format(buildapp,
                                                 '\n'.join(sorted(msg))))
            return 1

        if buildapp == 'android':
            from mozrunner.devices.android_device import grant_runtime_permissions
            from mozrunner.devices.android_device import verify_android_device
            app = kwargs.get('app')
            if not app:
                app = self.substs["ANDROID_PACKAGE_NAME"]
            device_serial = kwargs.get('deviceSerial')

            # verify installation
            verify_android_device(self,
                                  install=True,
                                  xre=False,
                                  network=True,
                                  app=app,
                                  device_serial=device_serial)
            grant_runtime_permissions(self, app, device_serial=device_serial)
            run_mochitest = mochitest.run_android_test
        else:
            run_mochitest = mochitest.run_desktop_test

        overall = None
        for (flavor, subsuite), tests in sorted(suites.items()):
            _, suite = get_suite_definition(flavor, subsuite)
            if 'test_paths' in suite['kwargs']:
                del suite['kwargs']['test_paths']

            harness_args = kwargs.copy()
            harness_args.update(suite['kwargs'])

            result = run_mochitest(self._mach_context,
                                   tests=tests,
                                   **harness_args)

            if result:
                overall = result

            # Halt tests on keyboard interrupt
            if result == -1:
                break

        # Only shutdown the logger if we created it
        if kwargs['log'].name == 'mach-mochitest':
            kwargs['log'].shutdown()

        return overall
Example #35
0
    def run(self,
            app='org.mozilla.geckoview_example',
            intent=None,
            env=[],
            profile=None,
            url=None,
            no_install=None,
            no_wait=None,
            fail_if_running=None,
            restart=None):
        from mozrunner.devices.android_device import verify_android_device, _get_device
        from six.moves import shlex_quote

        if app == 'org.mozilla.geckoview_example':
            activity_name = 'org.mozilla.geckoview_example.GeckoViewActivity'
        elif app == 'org.mozilla.geckoview.test':
            activity_name = 'org.mozilla.geckoview.test.TestRunnerActivity'
        elif 'fennec' in app or 'firefox' in app:
            activity_name = 'org.mozilla.gecko.BrowserApp'
        else:
            raise RuntimeError('Application not recognized: {}'.format(app))

        # `verify_android_device` respects `DEVICE_SERIAL` if it is set and sets it otherwise.
        verify_android_device(self, app=app, install=not no_install)
        device_serial = os.environ.get('DEVICE_SERIAL')
        if not device_serial:
            print('No ADB devices connected.')
            return 1

        device = _get_device(self.substs, device_serial=device_serial)

        args = []
        if profile:
            if os.path.isdir(profile):
                host_profile = profile
                # Always /data/local/tmp, rather than `device.test_root`, because GeckoView only
                # takes its configuration file from /data/local/tmp, and we want to follow suit.
                target_profile = '/data/local/tmp/{}-profile'.format(app)
                device.rm(target_profile, recursive=True, force=True)
                device.push(host_profile, target_profile)
                self.log(
                    logging.INFO, "run", {
                        'host_profile': host_profile,
                        'target_profile': target_profile
                    },
                    'Pushed profile from host "{host_profile}" to target "{target_profile}"'
                )
            else:
                target_profile = profile
                self.log(logging.INFO, "run",
                         {'target_profile': target_profile},
                         'Using profile from target "{target_profile}"')

            args = ['--profile', shlex_quote(target_profile)]

        extras = {}
        for i, e in enumerate(env):
            extras['env{}'.format(i)] = e
        if args:
            extras['args'] = " ".join(args)
        extras[
            'use_multiprocess'] = True  # Only GVE and TRA process this extra.

        if env or args:
            restart = True

        if restart:
            fail_if_running = False
            self.log(logging.INFO, "run", {'app': app},
                     'Stopping {app} to ensure clean restart.')
            device.stop_application(app)

        # We'd prefer to log the actual `am start ...` command, but it's not trivial to wire the
        # device's logger to mach's logger.
        self.log(logging.INFO, "run", {
            'app': app,
            'activity_name': activity_name
        }, 'Starting {app}/{activity_name}.')

        device.launch_application(app_name=app,
                                  activity_name=activity_name,
                                  intent=intent,
                                  extras=extras,
                                  url=url,
                                  wait=not no_wait,
                                  fail_if_running=fail_if_running)

        return 0