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)
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 mozbuild.testing 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 grant_runtime_permissions(self) mochitest = self._spawn(MochitestRunner) return mochitest.run_robocop_test(self._mach_context, tests, 'robocop', **kwargs)
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
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)
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)
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') if not kwargs.get('robocopApk'): kwargs['robocopApk'] = os.path.join(self.topobjdir, 'mobile', 'android', 'tests', 'browser', 'robocop', 'robocop-debug.apk') from mozbuild.controller.building import BuildDriver self._ensure_state_subdir_exists('.') driver = self._spawn(BuildDriver) driver.install_tests(remove=False) test_paths = kwargs['test_paths'] kwargs['test_paths'] = [] from mozbuild.testing import TestResolver resolver = self._spawn(TestResolver) tests = list( resolver.resolve_tests(paths=test_paths, cwd=self._mach_context.cwd, flavor='instrumentation', subsuite='robocop')) 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 grant_runtime_permissions(self, kwargs['app']) mochitest = self._spawn(MochitestRunner) return mochitest.run_robocop_test(self._mach_context, tests, 'robocop', **kwargs)
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") if not kwargs.get("robocopApk"): kwargs["robocopApk"] = os.path.join( self.topobjdir, "mobile", "android", "tests", "browser", "robocop", "robocop-debug.apk" ) from mozbuild.controller.building import BuildDriver self._ensure_state_subdir_exists(".") test_paths = kwargs["test_paths"] kwargs["test_paths"] = [] from mozbuild.testing 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 grant_runtime_permissions(self, kwargs["app"]) mochitest = self._spawn(MochitestRunner) return mochitest.run_robocop_test(self._mach_context, tests, "robocop", **kwargs)
def run_mochitest_general(self, flavor=None, test_objects=None, resolve_tests=True, **kwargs): from mochitest_options import ALL_FLAVORS 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) 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 grant_runtime_permissions(self) run_mochitest = mochitest.run_android_test else: run_mochitest = mochitest.run_desktop_test overall = None for (flavor, subsuite), tests in sorted(suites.items()): fobj = ALL_FLAVORS[flavor] msg = fobj['aliases'][0] if subsuite: msg = '{} with subsuite {}'.format(msg, subsuite) print(NOW_RUNNING.format(msg)) harness_args = kwargs.copy() harness_args['subsuite'] = subsuite harness_args.update(fobj.get('extra_args', {})) result = run_mochitest( self._mach_context, tests=tests, suite=fobj['suite'], **harness_args) if result: overall = result # TODO consolidate summaries from all suites return overall
def run_android_test(self, **kwargs): """Runs a reftest, in Firefox for Android.""" args = Namespace(**kwargs) if args.suite not in ('reftest', 'crashtest', 'jstestbrowser'): raise Exception('None or unrecognized reftest suite type.') self._setup_objdir(args) import remotereftest default_manifest = { "reftest": (self.topsrcdir, "layout", "reftests", "reftest.list"), "crashtest": (self.topsrcdir, "testing", "crashtest", "crashtests.list"), "jstestbrowser": ("jsreftest", "tests", "jstests.list") } if not args.tests: args.tests = [os.path.join(*default_manifest[args.suite])] args.extraProfileFiles.append( os.path.join(self.topsrcdir, "mobile", "android", "fonts")) hyphenation_path = os.path.join(self.topsrcdir, "intl", "locales") for (dirpath, dirnames, filenames) in os.walk(hyphenation_path): for filename in filenames: if filename.endswith('.dic'): args.extraProfileFiles.append( os.path.join(dirpath, filename)) if not args.httpdPath: args.httpdPath = os.path.join(self.tests_dir, "modules") if not args.symbolsPath: args.symbolsPath = os.path.join(self.topobjdir, "crashreporter-symbols") if not args.xrePath: args.xrePath = os.environ.get("MOZ_HOST_BIN") if not args.app: args.app = self.substs["ANDROID_PACKAGE_NAME"] if not args.utilityPath: args.utilityPath = args.xrePath args.ignoreWindowSize = True args.printDeviceInfo = False from mozrunner.devices.android_device import grant_runtime_permissions, get_adb_path grant_runtime_permissions(self, args.app, device_serial=args.deviceSerial) if not args.adb_path: args.adb_path = get_adb_path(self) # A symlink and some path manipulations are required so that test # manifests can be found both locally and remotely (via a url) # using the same relative path. if args.suite == "jstestbrowser": staged_js_dir = os.path.join(self.topobjdir, "dist", "test-stage", "jsreftest") tests = os.path.join(self.reftest_dir, 'jsreftest') if not os.path.isdir(tests): os.symlink(staged_js_dir, tests) args.extraProfileFiles.append( os.path.join(staged_js_dir, "tests", "user.js")) else: tests = os.path.join(self.reftest_dir, "tests") if not os.path.isdir(tests): os.symlink(self.topsrcdir, tests) for i, path in enumerate(args.tests): # Non-absolute paths are relative to the packaged directory, which # has an extra tests/ at the start if os.path.exists(os.path.abspath(path)): path = os.path.relpath(path, os.path.join(self.topsrcdir)) args.tests[i] = os.path.join('tests', path) self.log_manager.enable_unstructured() try: rv = remotereftest.run_test_harness(parser, args) finally: self.log_manager.disable_unstructured() return rv
def run_mochitest_general(self, flavor=None, test_objects=None, resolve_tests=True, **kwargs): 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('.') driver = self._spawn(BuildDriver) driver.install_tests(remove=False) test_paths = kwargs['test_paths'] kwargs['test_paths'] = [] if test_paths and buildapp == 'b2g': # In B2G there is often a 'gecko' directory, though topsrcdir is actually # elsewhere. This little hack makes test paths like 'gecko/dom' work, even if # GECKO_PATH is set in the .userconfig gecko_path = mozpath.abspath(mozpath.join(kwargs['b2gPath'], 'gecko')) if gecko_path != self.topsrcdir: new_paths = [] for tp in test_paths: if mozpath.abspath(tp).startswith(gecko_path): new_paths.append(mozpath.relpath(tp, gecko_path)) else: new_paths.append(tp) test_paths = new_paths mochitest = self._spawn(MochitestRunner) tests = [] if resolve_tests: tests = mochitest.resolve_tests(test_paths, test_objects, cwd=self._mach_context.cwd) 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['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['subsuite']: unsupported.add(key) continue elif subsuite and test['subsuite'] != subsuite: unsupported.add(key) continue suites[key].append(test) # 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 in ('b2g',): run_mochitest = mochitest.run_b2g_test elif buildapp == 'android': from mozrunner.devices.android_device import grant_runtime_permissions grant_runtime_permissions(self, kwargs['app']) run_mochitest = mochitest.run_android_test else: run_mochitest = mochitest.run_desktop_test overall = None for (flavor, subsuite), tests in sorted(suites.items()): fobj = ALL_FLAVORS[flavor] msg = fobj['aliases'][0] if subsuite: msg = '{} with subsuite {}'.format(msg, subsuite) print(NOW_RUNNING.format(msg)) harness_args = kwargs.copy() harness_args['subsuite'] = subsuite harness_args.update(fobj.get('extra_args', {})) result = run_mochitest( self._mach_context, tests=tests, suite=fobj['suite'], **harness_args) if result: overall = result # TODO consolidate summaries from all suites return overall
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
def run_android_test(self, **kwargs): """Runs a reftest, in Firefox for Android.""" import runreftest if kwargs["suite"] not in ('reftest', 'crashtest', 'jstestbrowser'): raise Exception('None or unrecognized reftest suite type.') if "ipc" in kwargs.keys(): raise Exception('IPC tests not supported on Android.') default_manifest = { "reftest": (self.topsrcdir, "layout", "reftests", "reftest.list"), "crashtest": (self.topsrcdir, "testing", "crashtest", "crashtests.list"), "jstestbrowser": ("jsreftest", "tests", "jstests.list") } if not kwargs["tests"]: kwargs["tests"] = [ os.path.join(*default_manifest[kwargs["suite"]]) ] kwargs["extraProfileFiles"].append( os.path.join(self.topsrcdir, "mobile", "android", "fonts")) if not kwargs["httpdPath"]: kwargs["httpdPath"] = os.path.join(self.tests_dir, "modules") if not kwargs["symbolsPath"]: kwargs["symbolsPath"] = os.path.join(self.topobjdir, "crashreporter-symbols") if not kwargs["xrePath"]: kwargs["xrePath"] = os.environ.get("MOZ_HOST_BIN") if not kwargs["app"]: kwargs["app"] = self.substs["ANDROID_PACKAGE_NAME"] if not kwargs["utilityPath"]: kwargs["utilityPath"] = kwargs["xrePath"] kwargs["dm_trans"] = "adb" kwargs["ignoreWindowSize"] = True kwargs["printDeviceInfo"] = False from mozrunner.devices.android_device import grant_runtime_permissions grant_runtime_permissions(self, kwargs['app']) # A symlink and some path manipulations are required so that test # manifests can be found both locally and remotely (via a url) # using the same relative path. if kwargs["suite"] == "jstestbrowser": staged_js_dir = os.path.join(self.topobjdir, "dist", "test-stage", "jsreftest") tests = os.path.join(self.reftest_dir, 'jsreftest') if not os.path.isdir(tests): os.symlink(staged_js_dir, tests) kwargs["extraProfileFiles"].append( os.path.join(staged_js_dir, "tests", "user.js")) else: tests = os.path.join(self.reftest_dir, "tests") if not os.path.isdir(tests): os.symlink(self.topsrcdir, tests) for i, path in enumerate(kwargs["tests"]): # Non-absolute paths are relative to the packaged directory, which # has an extra tests/ at the start if os.path.exists(os.path.abspath(path)): path = os.path.relpath(path, os.path.join(self.topsrcdir)) kwargs["tests"][i] = os.path.join('tests', path) # Need to chdir to reftest_dir otherwise imports fail below. os.chdir(self.reftest_dir) # The imp module can spew warnings if the modules below have # already been imported, ignore them. with warnings.catch_warnings(): warnings.simplefilter('ignore') import imp path = os.path.join(self.reftest_dir, 'remotereftest.py') with open(path, 'r') as fh: imp.load_module('reftest', fh, path, ('.py', 'r', imp.PY_SOURCE)) import reftest self.log_manager.enable_unstructured() try: rv = reftest.run(**kwargs) finally: self.log_manager.disable_unstructured() return rv
def run_android_test(self, **kwargs): """Runs a reftest, in Firefox for Android.""" import runreftest if kwargs["suite"] not in ('reftest', 'crashtest', 'jstestbrowser'): raise Exception('None or unrecognized reftest suite type.') if "ipc" in kwargs.keys(): raise Exception('IPC tests not supported on Android.') default_manifest = { "reftest": (self.topsrcdir, "layout", "reftests", "reftest.list"), "crashtest": (self.topsrcdir, "testing", "crashtest", "crashtests.list"), "jstestbrowser": ("jsreftest", "tests", "jstests.list") } if not kwargs["tests"]: kwargs["tests"] = [os.path.join(*default_manifest[kwargs["suite"]])] kwargs["extraProfileFiles"].append( os.path.join(self.topsrcdir, "mobile", "android", "fonts")) if not kwargs["httpdPath"]: kwargs["httpdPath"] = os.path.join(self.tests_dir, "modules") if not kwargs["symbolsPath"]: kwargs["symbolsPath"] = os.path.join(self.topobjdir, "crashreporter-symbols") if not kwargs["xrePath"]: kwargs["xrePath"] = os.environ.get("MOZ_HOST_BIN") if not kwargs["app"]: kwargs["app"] = self.substs["ANDROID_PACKAGE_NAME"] kwargs["dm_trans"] = "adb" kwargs["ignoreWindowSize"] = True kwargs["printDeviceInfo"] = False from mozrunner.devices.android_device import grant_runtime_permissions grant_runtime_permissions(self, kwargs['app']) # A symlink and some path manipulations are required so that test # manifests can be found both locally and remotely (via a url) # using the same relative path. if kwargs["suite"] == "jstestbrowser": staged_js_dir = os.path.join(self.topobjdir, "dist", "test-stage", "jsreftest") tests = os.path.join(self.reftest_dir, 'jsreftest') if not os.path.isdir(tests): os.symlink(staged_js_dir, tests) kwargs["extraProfileFiles"].append(os.path.join(staged_js_dir, "tests", "user.js")) else: tests = os.path.join(self.reftest_dir, "tests") if not os.path.isdir(tests): os.symlink(self.topsrcdir, tests) for i, path in enumerate(kwargs["tests"]): # Non-absolute paths are relative to the packaged directory, which # has an extra tests/ at the start if os.path.exists(os.path.abspath(path)): path = os.path.relpath(path, os.path.join(self.topsrcdir)) kwargs["tests"][i] = os.path.join('tests', path) # Need to chdir to reftest_dir otherwise imports fail below. os.chdir(self.reftest_dir) # The imp module can spew warnings if the modules below have # already been imported, ignore them. with warnings.catch_warnings(): warnings.simplefilter('ignore') import imp path = os.path.join(self.reftest_dir, 'remotereftest.py') with open(path, 'r') as fh: imp.load_module('reftest', fh, path, ('.py', 'r', imp.PY_SOURCE)) import reftest self.log_manager.enable_unstructured() try: rv = reftest.run(**kwargs) finally: self.log_manager.disable_unstructured() return rv
def run_mochitest_general(self, flavor=None, test_objects=None, resolve_tests=True, **kwargs): 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) 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) # 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 grant_runtime_permissions(self) run_mochitest = mochitest.run_android_test else: run_mochitest = mochitest.run_desktop_test overall = None for (flavor, subsuite), tests in sorted(suites.items()): fobj = ALL_FLAVORS[flavor] msg = fobj['aliases'][0] if subsuite: msg = '{} with subsuite {}'.format(msg, subsuite) print(NOW_RUNNING.format(msg)) harness_args = kwargs.copy() harness_args['subsuite'] = subsuite harness_args.update(fobj.get('extra_args', {})) result = run_mochitest(self._mach_context, tests=tests, suite=fobj['suite'], **harness_args) if result: overall = result # TODO consolidate summaries from all suites return overall
def run_android_test(self, **kwargs): """Runs a reftest, in Firefox for Android.""" args = Namespace(**kwargs) if args.suite not in ("reftest", "crashtest", "jstestbrowser"): raise Exception("None or unrecognized reftest suite type.") self._setup_objdir(args) import remotereftest default_manifest = { "reftest": (self.topsrcdir, "layout", "reftests", "reftest.list"), "crashtest": (self.topsrcdir, "testing", "crashtest", "crashtests.list"), "jstestbrowser": ("jsreftest", "tests", "jstests.list"), } if not args.tests: args.tests = [os.path.join(*default_manifest[args.suite])] args.extraProfileFiles.append(os.path.join(self.topsrcdir, "mobile", "android", "fonts")) hyphenation_path = os.path.join(self.topsrcdir, "intl", "locales") for (dirpath, dirnames, filenames) in os.walk(hyphenation_path): for filename in filenames: if filename.endswith(".dic"): args.extraProfileFiles.append(os.path.join(dirpath, filename)) if not args.httpdPath: args.httpdPath = os.path.join(self.tests_dir, "modules") if not args.symbolsPath: args.symbolsPath = os.path.join(self.topobjdir, "crashreporter-symbols") if not args.xrePath: args.xrePath = os.environ.get("MOZ_HOST_BIN") if not args.app: args.app = self.substs["ANDROID_PACKAGE_NAME"] if not args.utilityPath: args.utilityPath = args.xrePath args.dm_trans = "adb" args.ignoreWindowSize = True args.printDeviceInfo = False from mozrunner.devices.android_device import grant_runtime_permissions grant_runtime_permissions(self) # A symlink and some path manipulations are required so that test # manifests can be found both locally and remotely (via a url) # using the same relative path. if args.suite == "jstestbrowser": staged_js_dir = os.path.join(self.topobjdir, "dist", "test-stage", "jsreftest") tests = os.path.join(self.reftest_dir, "jsreftest") if not os.path.isdir(tests): os.symlink(staged_js_dir, tests) args.extraProfileFiles.append(os.path.join(staged_js_dir, "tests", "user.js")) else: tests = os.path.join(self.reftest_dir, "tests") if not os.path.isdir(tests): os.symlink(self.topsrcdir, tests) for i, path in enumerate(args.tests): # Non-absolute paths are relative to the packaged directory, which # has an extra tests/ at the start if os.path.exists(os.path.abspath(path)): path = os.path.relpath(path, os.path.join(self.topsrcdir)) args.tests[i] = os.path.join("tests", path) self.log_manager.enable_unstructured() try: rv = remotereftest.run_test_harness(parser, args) finally: self.log_manager.disable_unstructured() return rv