Esempio n. 1
0
def get_config(argv=None):
    argv = argv or sys.argv[1:]
    cli_opts = parse_args(argv=argv)
    if cli_opts.suite:
        # read the suite config, update the args
        try:
            suite_conf = suites_conf()[cli_opts.suite]
        except KeyError:
            raise ConfigurationError('No such suite: %r' % cli_opts.suite)
        argv += ['-a', ':'.join(suite_conf['tests'])]
        argv += suite_conf.get('talos_options', [])
        # args needs to be reparsed now
    elif not cli_opts.activeTests:
        raise ConfigurationError('--activeTests or --suite required!')

    cli_opts = parse_args(argv=argv)
    setup_logging("talos", cli_opts, {"tbpl": sys.stdout})
    config = copy.deepcopy(DEFAULTS)
    config.update(cli_opts.__dict__)
    for validate in CONF_VALIDATORS:
        validate(config)
    # remove None Values
    for k, v in config.items():
        if v is None:
            del config[k]
    return config
Esempio n. 2
0
 def _lint(self, files, linter, **lintargs):
     payload = linter["payload"]
     handler = LintHandler(linter)
     logger = linter.get("logger")
     if logger is None:
         logger = get_default_logger()
     if logger is None:
         logger = structuredlog.StructuredLogger(linter["name"])
         commandline.setup_logging(logger, {}, {"mach": sys.stdout})
     logger.add_handler(handler)
     try:
         payload(files, logger, **lintargs)
     except KeyboardInterrupt:
         pass
     return handler.results
Esempio n. 3
0
def main():
    if sys.version_info < (2, 7):
        print(
            "Error: You must use python version 2.7 or newer but less than 3.0",
            file=sys.stderr,
        )
        sys.exit(1)

    parser = parser_remote()
    options = parser.parse_args()

    options = verifyRemoteOptions(parser, options)
    log = commandline.setup_logging("Remote XPCShell", options, {"tbpl": sys.stdout})

    if options["interactive"] and not options["testPath"]:
        print(
            "Error: You must specify a test filename in interactive mode!",
            file=sys.stderr,
        )
        sys.exit(1)

    if options["xpcshell"] is None:
        options["xpcshell"] = "xpcshell"

    # The threadCount depends on the emulator rather than the host machine and
    # empirically 10 seems to yield the best performance.
    options["threadCount"] = min(options["threadCount"], 10)

    xpcsh = XPCShellRemote(options, log)

    if not xpcsh.runTests(
        options, testClass=RemoteXPCShellTestThread, mobileArgs=xpcsh.mobileArgs
    ):
        sys.exit(1)
def run_reftest(context, **kwargs):
    import mozinfo
    from mozlog.commandline import setup_logging

    if not kwargs.get("log"):
        kwargs["log"] = setup_logging("reftest", kwargs, {"mach": sys.stdout})
    global logger
    logger = kwargs["log"]

    args = Namespace(**kwargs)
    args.e10s = context.mozharness_config.get("e10s", args.e10s)

    if not args.tests:
        args.tests = [os.path.join("layout", "reftests", "reftest.list")]

    test_root = os.path.join(context.package_root, "reftest", "tests")
    normalize = partial(context.normalize_test_path, test_root)
    args.tests = map(normalize, args.tests)

    if kwargs.get("allow_software_gl_layers"):
        os.environ["MOZ_LAYERS_ALLOW_SOFTWARE_GL"] = "1"

    if mozinfo.info.get("buildapp") == "mobile/android":
        return run_reftest_android(context, args)
    return run_reftest_desktop(context, args)
Esempio n. 5
0
def main():
    parser = B2GOptions()
    commandline.add_logging_group(parser)
    options, args = parser.parse_args()
    log = commandline.setup_logging("Remote XPCShell", options,
                                    {"tbpl": sys.stdout})
    run_remote_xpcshell(parser, options, args, log)
Esempio n. 6
0
def run_mochitest(context, **kwargs):
    from mochitest_options import ALL_FLAVORS
    from mozlog.commandline import setup_logging

    if not kwargs.get('log'):
        kwargs['log'] = setup_logging('mochitest', kwargs,
                                      {'mach': sys.stdout})

    flavor = kwargs.get('flavor') or 'mochitest'
    if flavor not in ALL_FLAVORS:
        for fname, fobj in ALL_FLAVORS.iteritems():
            if flavor in fobj['aliases']:
                flavor = fname
                break
    fobj = ALL_FLAVORS[flavor]
    kwargs.update(fobj.get('extra_args', {}))

    args = Namespace(**kwargs)
    args.e10s = context.mozharness_config.get('e10s', args.e10s)
    args.certPath = context.certs_dir

    if args.test_paths:
        install_subdir = fobj.get('install_subdir', fobj['suite'])
        test_root = os.path.join(context.package_root, 'mochitest',
                                 install_subdir)
        normalize = partial(context.normalize_test_path, test_root)
        args.test_paths = map(normalize, args.test_paths)

    import mozinfo
    if mozinfo.info.get('buildapp') == 'mobile/android':
        return run_mochitest_android(context, args)
    return run_mochitest_desktop(context, args)
Esempio n. 7
0
    def run_junit(self, no_install, **kwargs):
        self._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(
            self,
            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(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 main():
    if sys.version_info < (2, 7):
        print("Error: You must use python version 2.7 or newer but less than 3.0", file=sys.stderr)
        sys.exit(1)

    parser = parser_remote()
    options = parser.parse_args()

    options = verifyRemoteOptions(parser, options)
    log = commandline.setup_logging("Remote XPCShell",
                                    options,
                                    {"tbpl": sys.stdout})

    if options['interactive'] and not options['testPath']:
        print("Error: You must specify a test filename in interactive mode!", file=sys.stderr)
        sys.exit(1)

    if options['xpcshell'] is None:
        options['xpcshell'] = "xpcshell"

    xpcsh = XPCShellRemote(options, log)

    # we don't run concurrent tests on mobile
    options['sequential'] = True

    if not xpcsh.runTests(options,
                          testClass=RemoteXPCShellTestThread,
                          mobileArgs=xpcsh.mobileArgs):
        sys.exit(1)
Esempio n. 9
0
 def test_setup_logging_optparse(self):
     parser = optparse.OptionParser()
     commandline.add_logging_group(parser)
     args, _ = parser.parse_args(["--log-raw=-"])
     logger = commandline.setup_logging("test_optparse", args, {})
     self.assertEqual(len(logger.handlers), 1)
     self.assertIsInstance(logger.handlers[0], handlers.StreamHandler)
def run_reftest(context, **kwargs):
    import mozinfo
    from mozlog.commandline import setup_logging

    if not kwargs.get('log'):
        kwargs['log'] = setup_logging('reftest', kwargs, {'mach': sys.stdout})
    global logger
    logger = kwargs['log']

    args = Namespace(**kwargs)
    args.e10s = context.mozharness_config.get('e10s', args.e10s)

    if not args.tests:
        args.tests = [os.path.join('layout', 'reftests', 'reftest.list')]

    test_root = os.path.join(context.package_root, 'reftest', 'tests')
    normalize = partial(context.normalize_test_path, test_root)
    args.tests = map(normalize, args.tests)

    if kwargs.get('allow_software_gl_layers'):
        os.environ['MOZ_LAYERS_ALLOW_SOFTWARE_GL'] = '1'

    if mozinfo.info.get('buildapp') == 'mobile/android':
        return run_reftest_android(context, args)
    return run_reftest_desktop(context, args)
Esempio n. 11
0
def main():
    parser = parser_b2g()
    options = parser.parse_args()
    log = commandline.setup_logging("Remote XPCShell",
                                    options,
                                    {"tbpl": sys.stdout})
    run_remote_xpcshell(parser, options, log)
 def test_setup_logging_optparse(self):
     parser = optparse.OptionParser()
     commandline.add_logging_group(parser)
     args, _ = parser.parse_args(["--log-raw=-"])
     logger = commandline.setup_logging("test_optparse", args, {})
     self.assertEqual(len(logger.handlers), 1)
     self.assertIsInstance(logger.handlers[0], handlers.StreamHandler)
Esempio n. 13
0
    def _lint(self, files, config, **lintargs):
        handler = LintHandler(config)
        logger = config.get("logger")
        if logger is None:
            logger = get_default_logger()
        if logger is None:
            logger = structuredlog.StructuredLogger(config["name"])
            commandline.setup_logging(logger, {}, {"mach": sys.stdout})
        logger.add_handler(handler)

        func = findobject(config["payload"])
        try:
            func(files, config, logger, **lintargs)
        except KeyboardInterrupt:
            pass
        return handler.results
Esempio n. 14
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)
Esempio n. 15
0
    def _lint(self, files, config, **lintargs):
        handler = LintHandler(config)
        logger = config.get("logger")
        if logger is None:
            logger = get_default_logger()
        if logger is None:
            logger = structuredlog.StructuredLogger(config["name"])
            commandline.setup_logging(logger, {}, {"mach": sys.stdout})
        logger.add_handler(handler)

        func = findobject(config["payload"])
        try:
            func(files, config, logger, **lintargs)
        except KeyboardInterrupt:
            pass
        return handler.results
Esempio n. 16
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
        )
Esempio n. 17
0
    def run_cppunit_test(self, **params):
        import mozinfo
        from mozlog import commandline
        import runcppunittests as cppunittests

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

        if len(params['test_files']) == 0:
            testdir = os.path.join(self.distdir, 'cppunittests')
            manifest = os.path.join(self.topsrcdir, 'testing',
                                    'cppunittest.ini')
            tests = cppunittests.extract_unittests_from_args([testdir],
                                                             mozinfo.info,
                                                             manifest)
        else:
            tests = cppunittests.extract_unittests_from_args(
                params['test_files'], mozinfo.info, None)

        # 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

        tester = cppunittests.CPPUnitTests()
        try:
            result = tester.run_tests(tests,
                                      self.bindir,
                                      symbols_path,
                                      interactive=True)
        except Exception as e:
            log.error("Caught exception running cpp unit tests: %s" % str(e))
            result = False

        return 0 if result else 1
Esempio n. 18
0
    def run_cppunit_test(self, **params):
        import mozinfo
        from mozlog import commandline
        import runcppunittests as cppunittests

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

        if len(params['test_files']) == 0:
            testdir = os.path.join(self.distdir, 'cppunittests')
            manifest = os.path.join(self.topsrcdir, 'testing', 'cppunittest.ini')
            tests = cppunittests.extract_unittests_from_args([testdir], mozinfo.info, manifest)
        else:
            tests = cppunittests.extract_unittests_from_args(params['test_files'], mozinfo.info, None)

        # 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

        tester = cppunittests.CPPUnitTests()
        try:
            result = tester.run_tests(tests, self.bindir, symbols_path, interactive=True)
        except Exception as e:
            log.error("Caught exception running cpp unit tests: %s" % str(e))
            result = False

        return 0 if result else 1
Esempio n. 19
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 len(tests) == 0:
            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
            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,
                                     utility_path, log)
def run_mochitest(context, **kwargs):
    from mochitest_options import ALL_FLAVORS
    from mozlog.commandline import setup_logging

    if not kwargs.get('log'):
        kwargs['log'] = setup_logging('mochitest', kwargs, {'mach': sys.stdout})

    flavor = kwargs.get('flavor') or 'mochitest'
    if flavor not in ALL_FLAVORS:
        for fname, fobj in ALL_FLAVORS.iteritems():
            if flavor in fobj['aliases']:
                flavor = fname
                break
    fobj = ALL_FLAVORS[flavor]
    kwargs.update(fobj.get('extra_args', {}))

    args = Namespace(**kwargs)
    args.e10s = context.mozharness_config.get('e10s', args.e10s)
    args.certPath = context.certs_dir

    if args.test_paths:
        install_subdir = fobj.get('install_subdir', fobj['suite'])
        test_root = os.path.join(context.package_root, 'mochitest', install_subdir)
        normalize = partial(context.normalize_test_path, test_root)
        args.test_paths = map(normalize, args.test_paths)

    import mozinfo
    if mozinfo.info.get('buildapp') == 'mobile/android':
        return run_mochitest_android(context, args)
    return run_mochitest_desktop(context, args)
Esempio n. 21
0
def main():
    parser = B2GOptions()
    commandline.add_logging_group(parser)
    options, args = parser.parse_args()
    log = commandline.setup_logging("Remote XPCShell",
                                    options,
                                    {"tbpl": sys.stdout})
    run_remote_xpcshell(parser, options, args, log)
Esempio n. 22
0
def setup(args, defaults):
    logger = commandline.setup_logging("web-platform-tests", args, defaults)
    setup_stdlib_logger()

    for name in args.keys():
        if name.startswith("log_"):
            args.pop(name)

    return logger
Esempio n. 23
0
def setup(args, defaults):
    logger = commandline.setup_logging("web-platform-tests", args, defaults)
    setup_stdlib_logger()

    for name in args.keys():
        if name.startswith("log_"):
            args.pop(name)

    return logger
def main():

    if sys.version_info < (2,7):
        print >>sys.stderr, "Error: You must use python version 2.7 or newer but less than 3.0"
        sys.exit(1)

    parser = RemoteXPCShellOptions()
    commandline.add_logging_group(parser)
    options, args = parser.parse_args()
    if not options.localAPK:
        for file in os.listdir(os.path.join(options.objdir, "dist")):
            if (file.endswith(".apk") and file.startswith("fennec")):
                options.localAPK = os.path.join(options.objdir, "dist")
                options.localAPK = os.path.join(options.localAPK, file)
                print >>sys.stderr, "using APK: " + options.localAPK
                break
        else:
            print >>sys.stderr, "Error: please specify an APK"
            sys.exit(1)

    options = parser.verifyRemoteOptions(options)
    log = commandline.setup_logging("Remote XPCShell",
                                    options,
                                    {"tbpl": sys.stdout})

    if len(args) < 1 and options.manifest is None:
        print >>sys.stderr, """Usage: %s <test dirs>
             or: %s --manifest=test.manifest """ % (sys.argv[0], sys.argv[0])
        sys.exit(1)

    if options.dm_trans == "adb":
        if options.deviceIP:
            dm = mozdevice.DroidADB(options.deviceIP, options.devicePort, packageName=None, deviceRoot=options.remoteTestRoot)
        else:
            dm = mozdevice.DroidADB(packageName=None, deviceRoot=options.remoteTestRoot)
    else:
        if not options.deviceIP:
            print "Error: you must provide a device IP to connect to via the --device option"
            sys.exit(1)
        dm = mozdevice.DroidSUT(options.deviceIP, options.devicePort, deviceRoot=options.remoteTestRoot)

    if options.interactive and not options.testPath:
        print >>sys.stderr, "Error: You must specify a test filename in interactive mode!"
        sys.exit(1)

    xpcsh = XPCShellRemote(dm, options, args, log)

    # we don't run concurrent tests on mobile
    options.sequential = True

    if not xpcsh.runTests(xpcshell='xpcshell',
                          testClass=RemoteXPCShellTestThread,
                          testdirs=args[0:],
                          mobileArgs=xpcsh.mobileArgs,
                          **options.__dict__):
        sys.exit(1)
Esempio n. 25
0
File: reduce.py Progetto: sw811/wpt
def setup_logging(args, defaults):
    global logger
    logger = commandline.setup_logging("web-platform-tests-unstable", args, defaults)
    wptrunner.setup_stdlib_logger()

    for name in args.keys():
        if name.startswith("log_"):
            args.pop(name)

    return logger
Esempio n. 26
0
    def test_logging_defaultlevel(self):
        parser = argparse.ArgumentParser()
        commandline.add_logging_group(parser)

        args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name])
        logger = commandline.setup_logging("test_fmtopts", args, {})
        logger.info("INFO message")
        logger.debug("DEBUG message")
        logger.error("ERROR message")
        # The debug level is not logged by default.
        self.assertEqual([b"INFO message", b"ERROR message"], self.loglines)
Esempio n. 27
0
def update_expectations(_, **kwargs):
    from wptrunner import metadata, products, wptcommandline

    commandline.setup_logging("web-platform-tests",
                              kwargs, {"mach": sys.stdout},
                              formatter_defaults=None)

    if not kwargs["tests_root"]:
        kwargs["tests_root"] = wpt_root

    # This matches the manifest path we end up using in `wpt run`
    if not kwargs["manifest_path"]:
        kwargs["manifest_path"] = os.path.join(wpt_root, "MANIFEST.json")

    if "product" not in kwargs["extra_property"]:
        kwargs["extra_property"].append("product")

    use_wptrunner_update_props = kwargs.get("product") is not None

    kwargs = wptcommandline.check_args_metadata_update(kwargs)

    # By default update according to product.
    # If we passed in the name of a product, then use the configured update properties
    # for that product.
    if use_wptrunner_update_props:
        update_properties = products.load_product_update(
            kwargs["config"], kwargs["product"])
        if kwargs["extra_property"]:
            update_properties[0].extend(kwargs["extra_property"])
    else:
        update_properties = (kwargs["extra_property"], {})

    manifest_update(kwargs["test_paths"])
    metadata.update_expected(
        kwargs["test_paths"],
        kwargs["run_log"],
        update_properties=update_properties,
        full_update=False,
        disable_intermittent=kwargs["update_intermittent"],
        update_intermittent=kwargs["update_intermittent"],
        remove_intermittent=kwargs["update_intermittent"])
Esempio n. 28
0
    def test_logging_errorlevel(self):
        parser = argparse.ArgumentParser()
        commandline.add_logging_group(parser)
        args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=error"])
        logger = commandline.setup_logging("test_fmtopts", args, {})
        logger.info("INFO message")
        logger.debug("DEBUG message")
        logger.error("ERROR message")

        # Only the error level and above were requested.
        self.assertEqual(["ERROR message"],
                         self.loglines)
Esempio n. 29
0
    def test_logging_errorlevel(self):
        parser = argparse.ArgumentParser()
        commandline.add_logging_group(parser)
        args = parser.parse_args(
            ["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=error"])
        logger = commandline.setup_logging("test_fmtopts", args, {})
        logger.info("INFO message")
        logger.debug("DEBUG message")
        logger.error("ERROR message")

        # Only the error level and above were requested.
        self.assertEqual([b"ERROR message"], self.loglines)
Esempio n. 30
0
 def test_logging_debuglevel(self):
     parser = argparse.ArgumentParser()
     commandline.add_logging_group(parser)
     args = parser.parse_args(
         ["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=debug"])
     logger = commandline.setup_logging("test_fmtopts", args, {})
     logger.info("INFO message")
     logger.debug("DEBUG message")
     logger.error("ERROR message")
     # Requesting a lower log level than default works as expected.
     self.assertEqual([b"INFO message", b"DEBUG message", b"ERROR message"],
                      self.loglines)
Esempio n. 31
0
def main():
    if sys.version_info < (2, 7):
        print(
            "Error: You must use python version 2.7 or newer but less than 3.0",
            file=sys.stderr)
        sys.exit(1)

    parser = parser_remote()
    options = parser.parse_args()
    if not options.localAPK:
        for file in os.listdir(os.path.join(options.objdir, "dist")):
            if (file.endswith(".apk") and file.startswith("fennec")):
                options.localAPK = os.path.join(options.objdir, "dist")
                options.localAPK = os.path.join(options.localAPK, file)
                print("using APK: " + options.localAPK, file=sys.stderr)
                break
        else:
            print("Error: please specify an APK", file=sys.stderr)
            sys.exit(1)

    options = verifyRemoteOptions(parser, options)
    log = commandline.setup_logging("Remote XPCShell", options,
                                    {"tbpl": sys.stdout})

    dm_args = {'deviceRoot': options['remoteTestRoot']}
    if options['deviceIP']:
        dm_args['host'] = options['deviceIP']
        dm_args['port'] = options['devicePort']
    if options['log_tbpl_level'] == 'debug' or options[
            'log_mach_level'] == 'debug':
        dm_args['logLevel'] = logging.DEBUG
    if options['adbPath']:
        dm_args['adbPath'] = options['adbPath']
    dm = mozdevice.DroidADB(**dm_args)

    if options['interactive'] and not options['testPath']:
        print("Error: You must specify a test filename in interactive mode!",
              file=sys.stderr)
        sys.exit(1)

    if options['xpcshell'] is None:
        options['xpcshell'] = "xpcshell"

    xpcsh = XPCShellRemote(dm, options, log)

    # we don't run concurrent tests on mobile
    options['sequential'] = True

    if not xpcsh.runTests(options,
                          testClass=RemoteXPCShellTestThread,
                          mobileArgs=xpcsh.mobileArgs):
        sys.exit(1)
Esempio n. 32
0
    def test_logging_defaultlevel(self):
        parser = argparse.ArgumentParser()
        commandline.add_logging_group(parser)

        args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name])
        logger = commandline.setup_logging("test_fmtopts", args, {})
        logger.info("INFO message")
        logger.debug("DEBUG message")
        logger.error("ERROR message")
        # The debug level is not logged by default.
        self.assertEqual(["INFO message",
                          "ERROR message"],
                         self.loglines)
Esempio n. 33
0
def main(args=sys.argv[1:]):
    args = parse_args()
    commandline.setup_logging('raptor', args, {'tbpl': sys.stdout})
    LOG = get_default_logger(component='raptor-main')

    LOG.info("raptor-start")
    LOG.info("received command line arguments: %s" % str(args))

    # if a test name specified on command line, and it exists, just run that one
    # otherwise run all available raptor tests that are found for this browser
    raptor_test_list = get_raptor_test_list(args, mozinfo.os)

    # ensure we have at least one valid test to run
    if len(raptor_test_list) == 0:
        LOG.critical("abort: no tests found")
        sys.exit(1)

    LOG.info("raptor tests scheduled to run:")
    for next_test in raptor_test_list:
        LOG.info(next_test['name'])

    raptor = Raptor(args.app, args.binary, args.run_local, args.obj_path)

    raptor.start_control_server()

    for next_test in raptor_test_list:
        if 'page_timeout' not in next_test.keys():
            next_test['page_timeout'] = 120000
        if 'page_cycles' not in next_test.keys():
            next_test['page_cycles'] = 1
        raptor.run_test(next_test, timeout=int(next_test['page_timeout']))

    success = raptor.process_results()
    raptor.clean_up()

    if not success:
        # didn't get test results; test timed out or crashed, etc. we want job to fail
        LOG.critical("error: no raptor test results were found")
        os.sys.exit(1)
Esempio n. 34
0
 def test_logging_debuglevel(self):
     parser = argparse.ArgumentParser()
     commandline.add_logging_group(parser)
     args = parser.parse_args(["--log-tbpl=%s" % self.logfile.name, "--log-tbpl-level=debug"])
     logger = commandline.setup_logging("test_fmtopts", args, {})
     logger.info("INFO message")
     logger.debug("DEBUG message")
     logger.error("ERROR message")
     # Requesting a lower log level than default works as expected.
     self.assertEqual(["INFO message",
                       "DEBUG message",
                       "ERROR message"],
                      self.loglines)
def main():
    parser = get_parser()
    commandline.add_logging_group(parser)

    args = parser.parse_args()

    logger = commandline.setup_logging("structured-example", args, {"raw": sys.stdout})

    runner = TestRunner()
    try:
        runner.run()
    except Exception:
        logger.critical("Error during test run:\n%s" % traceback.format_exc())
Esempio n. 36
0
def main():
    parser = get_parser()
    commandline.add_logging_group(parser)

    args = parser.parse_args()

    logger = commandline.setup_logging("structured-example", args, {"raw": sys.stdout})

    runner = TestRunner()
    try:
        runner.run()
    except Exception:
        logger.critical("Error during test run:\n%s" % traceback.format_exc())
Esempio n. 37
0
def setup(args, defaults):
    logger = args.pop('log', None)
    if logger:
        set_default_logger(logger)
        StructuredLogger._logger_states["web-platform-tests"] = logger._state
    else:
        logger = commandline.setup_logging("web-platform-tests", args, defaults)
    setup_stdlib_logger()

    for name in args.keys():
        if name.startswith("log_"):
            args.pop(name)

    return logger
Esempio n. 38
0
def run_gtest(context, **kwargs):
    from mozlog.commandline import setup_logging

    if not kwargs.get('log'):
        kwargs['log'] = setup_logging('gtest', kwargs, {'mach': sys.stdout})
    global logger
    logger = kwargs['log']

    args = Namespace(**kwargs)

    import mozinfo
    if mozinfo.info.get('buildapp') == 'mobile/android':
        return run_gtest_android(context, args)
    return run_gtest_desktop(context, args)
def main():
    parser = get_parser()
    commandline.add_logging_group(parser)

    args = parser.parse_args()

    logger = commandline.setup_logging("check-sync-dirs", args,
                                       {"tbpl": sys.stdout})

    result = False
    logger.suite_start(tests=[])
    result |= test_build(logger)
    result |= test_tooltool(logger)
    logger.suite_end()
    return result
Esempio n. 40
0
 def test_limit_formatters(self):
     parser = argparse.ArgumentParser()
     commandline.add_logging_group(parser, include_formatters=['raw'])
     other_formatters = [fmt for fmt in commandline.log_formatters
                         if fmt != 'raw']
     # check that every formatter except raw is not present
     for fmt in other_formatters:
         with self.assertRaises(SystemExit):
             parser.parse_args(["--log-%s=-" % fmt])
         with self.assertRaises(SystemExit):
             parser.parse_args(["--log-%s-level=error" % fmt])
     # raw is still ok
     args = parser.parse_args(["--log-raw=-"])
     logger = commandline.setup_logging("test_setup_logging2", args, {})
     self.assertEqual(len(logger.handlers), 1)
Esempio n. 41
0
 def test_limit_formatters(self):
     parser = argparse.ArgumentParser()
     commandline.add_logging_group(parser, include_formatters=['raw'])
     other_formatters = [fmt for fmt in commandline.log_formatters
                         if fmt != 'raw']
     # check that every formatter except raw is not present
     for fmt in other_formatters:
         with self.assertRaises(SystemExit):
             parser.parse_args(["--log-%s=-" % fmt])
         with self.assertRaises(SystemExit):
             parser.parse_args(["--log-%s-level=error" % fmt])
     # raw is still ok
     args = parser.parse_args(["--log-raw=-"])
     logger = commandline.setup_logging("test_setup_logging2", args, {})
     self.assertEqual(len(logger.handlers), 1)
Esempio n. 42
0
def run_gtest(context, **kwargs):
    from mozlog.commandline import setup_logging

    if not kwargs.get("log"):
        kwargs["log"] = setup_logging("gtest", kwargs, {"mach": sys.stdout})
    global logger
    logger = kwargs["log"]

    args = Namespace(**kwargs)

    import mozinfo

    if mozinfo.info.get("buildapp") == "mobile/android":
        return run_gtest_android(context, args)
    return run_gtest_desktop(context, args)
def main():
    if sys.version_info < (2,7):
        print >>sys.stderr, "Error: You must use python version 2.7 or newer but less than 3.0"
        sys.exit(1)

    parser = parser_remote()
    options = parser.parse_args()
    if not options.localAPK:
        for file in os.listdir(os.path.join(options.objdir, "dist")):
            if (file.endswith(".apk") and file.startswith("fennec")):
                options.localAPK = os.path.join(options.objdir, "dist")
                options.localAPK = os.path.join(options.localAPK, file)
                print >>sys.stderr, "using APK: " + options.localAPK
                break
        else:
            print >>sys.stderr, "Error: please specify an APK"
            sys.exit(1)

    options = verifyRemoteOptions(parser, options)
    log = commandline.setup_logging("Remote XPCShell",
                                    options,
                                    {"tbpl": sys.stdout})

    dm_args = {'deviceRoot': options.remoteTestRoot}
    if options.deviceIP:
        dm_args['host'] = options.deviceIP
        dm_args['port'] = options.devicePort
    if options.log_tbpl_level == 'debug' or options.log_mach_level == 'debug':
        dm_args['logLevel'] = logging.DEBUG
    dm = mozdevice.DroidADB(**dm_args)

    if options.interactive and not options.testPath:
        print >>sys.stderr, "Error: You must specify a test filename in interactive mode!"
        sys.exit(1)

    if options.xpcshell is None:
        options.xpcshell = "xpcshell"

    xpcsh = XPCShellRemote(dm, options, log)

    # we don't run concurrent tests on mobile
    options.sequential = True

    if not xpcsh.runTests(testClass=RemoteXPCShellTestThread,
                          mobileArgs=xpcsh.mobileArgs,
                          **vars(options)):
        sys.exit(1)
Esempio n. 44
0
def main():
    if sys.version_info < (2, 7):
        print >> sys.stderr, "Error: You must use python version 2.7 or newer but less than 3.0"
        sys.exit(1)

    parser = parser_remote()
    options = parser.parse_args()
    if not options.localAPK:
        for file in os.listdir(os.path.join(options.objdir, "dist")):
            if (file.endswith(".apk") and file.startswith("fennec")):
                options.localAPK = os.path.join(options.objdir, "dist")
                options.localAPK = os.path.join(options.localAPK, file)
                print >> sys.stderr, "using APK: " + options.localAPK
                break
        else:
            print >> sys.stderr, "Error: please specify an APK"
            sys.exit(1)

    options = verifyRemoteOptions(parser, options)
    log = commandline.setup_logging("Remote XPCShell", options,
                                    {"tbpl": sys.stdout})

    if options.deviceIP:
        dm = mozdevice.DroidADB(options.deviceIP,
                                options.devicePort,
                                packageName=None,
                                deviceRoot=options.remoteTestRoot)
    else:
        dm = mozdevice.DroidADB(packageName=None,
                                deviceRoot=options.remoteTestRoot)

    if options.interactive and not options.testPath:
        print >> sys.stderr, "Error: You must specify a test filename in interactive mode!"
        sys.exit(1)

    if options.xpcshell is None:
        options.xpcshell = "xpcshell"

    xpcsh = XPCShellRemote(dm, options, log)

    # we don't run concurrent tests on mobile
    options.sequential = True

    if not xpcsh.runTests(testClass=RemoteXPCShellTestThread,
                          mobileArgs=xpcsh.mobileArgs,
                          **vars(options)):
        sys.exit(1)
Esempio n. 45
0
    def python_safety(self, python=None, **kwargs):
        self.logger = commandline.setup_logging(
            "python-safety", {"raw": sys.stdout})

        self.activate_pipenv(pipfile=os.path.join(here, 'Pipfile'), python=python, populate=True)

        pattern = '**/*requirements*.txt'
        path = mozpath.normsep(os.path.dirname(os.path.dirname(here)))
        finder = FileFinder(path)
        files = [os.path.join(path, p) for p, f in finder.find(pattern)]

        return_code = 0

        self.logger.suite_start(tests=files)
        for filepath in files:
            self._run_python_safety(filepath)

        self.logger.suite_end()
        return return_code
Esempio n. 46
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)
Esempio n. 47
0
    def test(self, what, extra_args, **log_args):
        """Run tests from names or paths.

        mach test accepts arguments specifying which tests to run. Each argument
        can be:

        * The path to a test file
        * A directory containing tests
        * A test suite name
        * An alias to a test suite name (codes used on TreeHerder)

        If no input is provided, tests will be run based on files changed in
        the local tree. Relevant tests, tags, or flavors are determined by
        IMPACTED_TESTS annotations in moz.build files relevant to the
        changed files.

        When paths or directories are given, they are first resolved to test
        files known to the build system.

        If resolved tests belong to more than one test type/flavor/harness,
        the harness for each relevant type/flavor will be invoked. e.g. if
        you specify a directory with xpcshell and browser chrome mochitests,
        both harnesses will be invoked.
        """
        from mozlog.commandline import setup_logging
        from moztest.resolve import TestResolver, TEST_FLAVORS, TEST_SUITES

        resolver = self._spawn(TestResolver)
        run_suites, run_tests = resolver.resolve_metadata(what)

        if not run_suites and not run_tests:
            print(UNKNOWN_TEST)
            return 1

        # Create shared logger
        default_format = self._mach_context.settings['test']['format']
        default_level = self._mach_context.settings['test']['level']
        log = setup_logging('mach-test', log_args, {default_format: sys.stdout},
                            {'level': default_level})
        log.handlers[0].formatter.inner.summary_on_shutdown = True

        status = None
        for suite_name in run_suites:
            suite = TEST_SUITES[suite_name]
            kwargs = suite['kwargs']
            kwargs['log'] = log

            if 'mach_command' in suite:
                res = self._mach_context.commands.dispatch(
                    suite['mach_command'], self._mach_context,
                    argv=extra_args, **kwargs)
                if res:
                    status = res

        buckets = {}
        for test in run_tests:
            key = (test['flavor'], test.get('subsuite', ''))
            buckets.setdefault(key, []).append(test)

        for (flavor, subsuite), tests in sorted(buckets.items()):
            if flavor not in TEST_FLAVORS:
                print(UNKNOWN_FLAVOR % flavor)
                status = 1
                continue

            m = TEST_FLAVORS[flavor]
            if 'mach_command' not in m:
                print(UNKNOWN_FLAVOR % flavor)
                status = 1
                continue

            kwargs = dict(m['kwargs'])
            kwargs['log'] = log
            kwargs['subsuite'] = subsuite

            res = self._mach_context.commands.dispatch(
                m['mach_command'], self._mach_context,
                argv=extra_args, test_objects=tests, **kwargs)
            if res:
                status = res

        log.shutdown()
        return status
Esempio n. 48
0
 def test_setup_logging(self):
     parser = argparse.ArgumentParser()
     commandline.add_logging_group(parser)
     args = parser.parse_args(["--log-raw=-"])
     logger = commandline.setup_logging("test_setup_logging", args, {})
     self.assertEqual(len(logger.handlers), 1)
Esempio n. 49
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

        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']]

        if not kwargs.get('log'):
            # Create shared logger
            default_format = self._mach_context.settings['test']['format']
            default_level = self._mach_context.settings['test']['level']
            kwargs['log'] = setup_logging('mach-mochitest', kwargs, {default_format: sys.stdout},
                                          {'level': default_level})
            kwargs['log'].handlers[0].formatter.inner.summary_on_shutdown = True

        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]

            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

            # 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
                    'title': 'artifact uploaded'})
        j.artifacts.append(('Results', 'json', results))
        # TODO - fix this fake log parsing
        if log_files:
            failures = []
            if results.get('total failed'):
                failures = ['Total failed: %s' % results['total failed']]
            j.parsed_logs[log_files[0]] = failures
    if job1.build['repo'] == job2.build['repo']:
        treeherder.submit_complete([job1, job2])
    else:
        # Jobs that belong to different repos cannot be submitted in one
        # collection
        treeherder.submit_complete([job1])
        treeherder.submit_complete([job2])
    return result_string


if __name__ == '__main__':
    logger = commandline.setup_logging("example-submission", None,
                                       {"mach": sys.stdout},
                                       {"level": "debug"})
    result_string = main(sys.argv[1:])
    if result_string == 'busted':
        raise Exception('Something went wrong in the test harness.')
    elif result_string != 'success':
        sys.exit(1)
    else:
        sys.exit(0)