def test_args_passed_to_runner_class(mach_parsed_kwargs, runner_class):
    arg_list = mach_parsed_kwargs.keys()
    arg_list.remove('tests')
    mach_parsed_kwargs.update([(a, getattr(sentinel, a)) for a in arg_list])
    harness = MarionetteHarness(runner_class, args=mach_parsed_kwargs)
    harness.process_args = Mock()
    harness.run()
    for arg in arg_list:
        assert harness._runner_class.call_args[1][arg] is getattr(sentinel, arg)
def test_harness_sets_up_default_test_handlers(mach_parsed_kwargs):
    """
    If the necessary TestCase is not in test_handlers,
    tests are omitted silently
    """
    harness = MarionetteHarness(args=mach_parsed_kwargs)
    mach_parsed_kwargs.pop('tests')
    runner = harness._runner_class(**mach_parsed_kwargs)
    assert marionette_test.MarionetteTestCase in runner.test_handlers
def test_harness_sets_up_default_test_handlers(mach_parsed_kwargs):
    """
    If the necessary TestCase is not in test_handlers,
    tests are omitted silently
    """
    harness = MarionetteHarness(args=mach_parsed_kwargs)
    mach_parsed_kwargs.pop('tests')
    runner = harness._runner_class(**mach_parsed_kwargs)
    assert marionette_test.MarionetteTestCase in runner.test_handlers
def test_args_passed_to_runner_class(mach_parsed_kwargs, runner_class):
    arg_list = mach_parsed_kwargs.keys()
    arg_list.remove('tests')
    mach_parsed_kwargs.update([(a, getattr(sentinel, a)) for a in arg_list])
    harness = MarionetteHarness(runner_class, args=mach_parsed_kwargs)
    harness.process_args = Mock()
    harness.run()
    for arg in arg_list:
        assert harness._runner_class.call_args[1][arg] is getattr(sentinel, arg)
Exemplo n.º 5
0
def run_marionette(tests, binary=None, topsrcdir=None, **kwargs):
    from mozlog.structured import commandline

    from marionette_harness.runtests import MarionetteTestRunner, MarionetteHarness

    parser = create_parser_tests()

    args = argparse.Namespace(tests=tests)

    args.binary = binary
    args.logger = kwargs.pop("log", None)

    for k, v in iteritems(kwargs):
        setattr(args, k, v)

    parser.verify_usage(args)

    if not args.logger:
        args.logger = commandline.setup_logging("Marionette Unit Tests", args,
                                                {"mach": sys.stdout})
    failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
    if failed > 0:
        return 1
    else:
        return 0
Exemplo n.º 6
0
def run_marionette(tests, binary=None, topsrcdir=None, **kwargs):
    from mozlog.structured import commandline

    from marionette_harness.runtests import (MarionetteTestRunner,
                                             MarionetteHarness)

    parser = create_parser_tests()

    if not tests:
        tests = [
            os.path.join(
                topsrcdir,
                "testing/marionette/harness/marionette_harness/tests/unit-tests.ini"
            )
        ]

    args = argparse.Namespace(tests=tests)

    args.binary = binary

    for k, v in kwargs.iteritems():
        setattr(args, k, v)

    parser.verify_usage(args)

    args.logger = commandline.setup_logging("Marionette Unit Tests", args,
                                            {"mach": sys.stdout})
    failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
    if failed > 0:
        return 1
    else:
        return 0
Exemplo n.º 7
0
def run_telemetry(tests, binary=None, topsrcdir=None, **kwargs):
    from mozlog.structured import commandline

    from telemetry_harness.runtests import TelemetryTestRunner

    from marionette_harness.runtests import MarionetteHarness

    parser = create_parser_tests()

    if not tests:
        tests = [
            os.path.join(
                topsrcdir,
                "toolkit/components/telemetry/tests/marionette/tests/manifest.ini",
            )
        ]

    args = argparse.Namespace(tests=tests)

    args.binary = binary
    args.logger = kwargs.pop("log", None)

    for k, v in kwargs.iteritems():
        setattr(args, k, v)

    parser.verify_usage(args)

    if not args.logger:
        args.logger = commandline.setup_logging("Telemetry Client Tests", args,
                                                {"mach": sys.stdout})
    failed = MarionetteHarness(TelemetryTestRunner, args=vars(args)).run()
    if failed > 0:
        return 1
    else:
        return 0
def test_call_harness_with_no_args_yields_num_failures(runner_class):
    with patch(
        'marionette_harness.runtests.MarionetteHarness.parse_args',
        return_value={'tests': []}
    ) as parse_args:
        failed_or_crashed = MarionetteHarness(runner_class).run()
        assert parse_args.call_count == 1
    assert failed_or_crashed == 0
Exemplo n.º 9
0
def test_call_harness_with_parsed_args_yields_num_failures(
        mach_parsed_kwargs, runner_class, num_fails_crashed):
    with patch("marionette_harness.runtests.MarionetteHarness.parse_args"
               ) as parse_args:
        failed_or_crashed = MarionetteHarness(runner_class,
                                              args=mach_parsed_kwargs).run()
        parse_args.assert_not_called()
    assert failed_or_crashed == sum(num_fails_crashed)
Exemplo n.º 10
0
    def run_awsy(self, tests, binary=None, **kwargs):
        import json
        from mozlog.structured import commandline

        from marionette_harness.runtests import (MarionetteTestRunner,
                                                 MarionetteHarness)

        parser = setup_awsy_argument_parser()

        awsy_source_dir = os.path.join(self.topsrcdir, 'testing', 'awsy')
        if not tests:
            tests = [
                os.path.join(awsy_source_dir, 'awsy', 'test_memory_usage.py')
            ]

        args = argparse.Namespace(tests=tests)

        args.binary = binary

        if kwargs['quick']:
            kwargs['entities'] = 3
            kwargs['iterations'] = 1
            kwargs['perTabPause'] = 1
            kwargs['settleWaitTime'] = 1

        if 'single_stylo_traversal' in kwargs and kwargs[
                'single_stylo_traversal']:
            os.environ['STYLO_THREADS'] = '1'
        else:
            os.environ['STYLO_THREADS'] = '4'

        if 'enable_webrender' in kwargs and kwargs['enable_webrender']:
            os.environ['MOZ_WEBRENDER'] = '1'
            os.environ['MOZ_ACCELERATED'] = '1'

        runtime_testvars = {}
        for arg in ('webRootDir', 'pageManifest', 'resultsDir', 'entities',
                    'iterations', 'perTabPause', 'settleWaitTime', 'maxTabs',
                    'dmd'):
            if arg in kwargs and kwargs[arg] is not None:
                runtime_testvars[arg] = kwargs[arg]

        if 'webRootDir' not in runtime_testvars:
            awsy_tests_dir = os.path.join(self.topobjdir, '_tests', 'awsy')
            web_root_dir = os.path.join(awsy_tests_dir, 'html')
            runtime_testvars['webRootDir'] = web_root_dir
        else:
            web_root_dir = runtime_testvars['webRootDir']
            awsy_tests_dir = os.path.dirname(web_root_dir)

        if 'resultsDir' not in runtime_testvars:
            runtime_testvars['resultsDir'] = os.path.join(
                awsy_tests_dir, 'results')
        page_load_test_dir = os.path.join(web_root_dir, 'page_load_test')
        if not os.path.isdir(page_load_test_dir):
            os.makedirs(page_load_test_dir)

        if not os.path.isdir(runtime_testvars['resultsDir']):
            os.makedirs(runtime_testvars['resultsDir'])

        runtime_testvars_path = os.path.join(awsy_tests_dir,
                                             'runtime-testvars.json')
        if kwargs['testvars']:
            kwargs['testvars'].append(runtime_testvars_path)
        else:
            kwargs['testvars'] = [runtime_testvars_path]

        runtime_testvars_file = open(runtime_testvars_path, 'wb')
        runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
        runtime_testvars_file.close()

        manifest_file = os.path.join(awsy_source_dir, 'tp5n-pageset.manifest')
        tooltool_args = {
            'args': [
                sys.executable,
                os.path.join(self.topsrcdir, 'mach'),
                'artifact',
                'toolchain',
                '-v',
                '--tooltool-manifest=%s' % manifest_file,
                '--cache-dir=%s' %
                os.path.join(self.topsrcdir, 'tooltool-cache'),
            ]
        }
        self.run_process(cwd=page_load_test_dir, **tooltool_args)
        tp5nzip = os.path.join(page_load_test_dir, 'tp5n.zip')
        tp5nmanifest = os.path.join(page_load_test_dir, 'tp5n',
                                    'tp5n.manifest')
        if not os.path.exists(tp5nmanifest):
            unzip_args = {
                'args':
                ['unzip', '-q', '-o', tp5nzip, '-d', page_load_test_dir]
            }
            self.run_process(**unzip_args)

        # If '--preferences' was not specified supply our default set.
        if not kwargs['prefs_files']:
            kwargs['prefs_files'] = [
                os.path.join(awsy_source_dir, 'conf', 'prefs.json')
            ]

        # Setup DMD env vars if necessary.
        if kwargs['dmd']:
            bin_dir = os.path.dirname(binary)

            if 'DMD' not in os.environ:
                os.environ['DMD'] = '1'

            # Also add the bin dir to the python path so we can use dmd.py
            if bin_dir not in sys.path:
                sys.path.append(bin_dir)

        for k, v in kwargs.iteritems():
            setattr(args, k, v)

        parser.verify_usage(args)

        args.logger = commandline.setup_logging('Are We Slim Yet Tests', args,
                                                {'mach': sys.stdout})
        failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
        if failed > 0:
            return 1
        else:
            return 0
Exemplo n.º 11
0
    def run_awsy(self, tests, binary=None, **kwargs):
        import json
        from mozlog.structured import commandline

        from marionette_harness.runtests import (MarionetteTestRunner,
                                                 MarionetteHarness)

        parser = setup_awsy_argument_parser()

        if not tests:
            tests = [
                os.path.join(self.topsrcdir,
                             'testing/awsy/awsy/test_memory_usage.py')
            ]

        args = argparse.Namespace(tests=tests)

        args.binary = binary

        if kwargs['quick']:
            kwargs['entities'] = 3
            kwargs['iterations'] = 1
            kwargs['perTabPause'] = 1
            kwargs['settleWaitTime'] = 1

        runtime_testvars = {}
        for arg in ('webRootDir', 'pageManifest', 'resultsDir', 'entities',
                    'iterations', 'perTabPause', 'settleWaitTime', 'maxTabs'):
            if kwargs[arg]:
                runtime_testvars[arg] = kwargs[arg]

        if 'webRootDir' not in runtime_testvars:
            awsy_tests_dir = os.path.join(self.topobjdir, '_tests', 'awsy')
            web_root_dir = os.path.join(awsy_tests_dir, 'html')
            runtime_testvars['webRootDir'] = web_root_dir
        else:
            web_root_dir = runtime_testvars['webRootDir']
            awsy_tests_dir = os.path.dirname(web_root_dir)

        if 'resultsDir' not in runtime_testvars:
            runtime_testvars['resultsDir'] = os.path.join(
                awsy_tests_dir, 'results')
        page_load_test_dir = os.path.join(web_root_dir, 'page_load_test')
        if not os.path.isdir(page_load_test_dir):
            os.makedirs(page_load_test_dir)

        if not os.path.isdir(runtime_testvars["resultsDir"]):
            os.makedirs(runtime_testvars["resultsDir"])

        runtime_testvars_path = os.path.join(awsy_tests_dir,
                                             'runtime-testvars.json')
        if kwargs['testvars']:
            kwargs['testvars'].append(runtime_testvars_path)
        else:
            kwargs['testvars'] = [runtime_testvars_path]

        runtime_testvars_file = open(runtime_testvars_path, 'wb')
        runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
        runtime_testvars_file.close()

        if not kwargs['webRootDir']:
            # Populate the Awsy webroot if not specified by the user.
            manifest_file = os.path.join(self.topsrcdir, 'testing', 'awsy',
                                         'tp5n-pageset.manifest')
            tooltool_args = {
                "args": [
                    os.path.join(
                        self.topsrcdir,
                        "python/mozbuild/mozbuild/action/tooltool.py"),
                    "--manifest=%s" % manifest_file, "--unpack",
                    "--cache-folder=%s" %
                    os.path.join(self.topsrcdir, "tooltool-cache"), "fetch"
                ]
            }

            self.run_process(cwd=page_load_test_dir, **tooltool_args)
            tp5nzip = os.path.join(page_load_test_dir, 'tp5n.zip')
            tp5nmanifest = os.path.join(page_load_test_dir, 'tp5n',
                                        'tp5n.manifest')
            if not os.path.exists(tp5nmanifest):
                files = mozfile.extract_zip(tp5nzip, page_load_test_dir)

        for k, v in kwargs.iteritems():
            setattr(args, k, v)

        parser.verify_usage(args)

        args.logger = commandline.setup_logging("Are We Slim Yet Tests", args,
                                                {"mach": sys.stdout})
        failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
        if failed > 0:
            return 1
        else:
            return 0
Exemplo n.º 12
0
 def parse_args(self, *args, **kwargs):
     return MarionetteHarness.parse_args(self, {'mach': sys.stdout})
Exemplo n.º 13
0
 def parse_args(self, *args, **kwargs):
     return MarionetteHarness.parse_args(self, {'mach': sys.stdout})
Exemplo n.º 14
0
    def run_awsy(self, tests, binary=None, **kwargs):
        import json
        from mozlog.structured import commandline

        from marionette_harness.runtests import (MarionetteTestRunner,
                                                 MarionetteHarness)

        parser = setup_awsy_argument_parser()

        awsy_source_dir = os.path.join(self.topsrcdir, 'testing', 'awsy')
        if not tests:
            tests = [
                os.path.join(awsy_source_dir, 'awsy', 'test_memory_usage.py')
            ]

        args = argparse.Namespace(tests=tests)

        args.binary = binary

        if kwargs['quick']:
            kwargs['entities'] = 3
            kwargs['iterations'] = 1
            kwargs['perTabPause'] = 1
            kwargs['settleWaitTime'] = 1

        if 'single_stylo_traversal' in kwargs and kwargs[
                'single_stylo_traversal']:
            os.environ['STYLO_THREADS'] = '1'
        else:
            os.environ['STYLO_THREADS'] = '4'

        runtime_testvars = {}
        for arg in ('webRootDir', 'pageManifest', 'resultsDir', 'entities',
                    'iterations', 'perTabPause', 'settleWaitTime', 'maxTabs',
                    'dmd', 'tp6'):
            if arg in kwargs and kwargs[arg] is not None:
                runtime_testvars[arg] = kwargs[arg]

        if 'webRootDir' not in runtime_testvars:
            awsy_tests_dir = os.path.join(self.topobjdir, '_tests', 'awsy')
            web_root_dir = os.path.join(awsy_tests_dir, 'html')
            runtime_testvars['webRootDir'] = web_root_dir
        else:
            web_root_dir = runtime_testvars['webRootDir']
            awsy_tests_dir = os.path.dirname(web_root_dir)

        if 'resultsDir' not in runtime_testvars:
            runtime_testvars['resultsDir'] = os.path.join(
                awsy_tests_dir, 'results')

        runtime_testvars['bin'] = binary
        runtime_testvars['run_local'] = True

        page_load_test_dir = os.path.join(web_root_dir, 'page_load_test')
        if not os.path.isdir(page_load_test_dir):
            os.makedirs(page_load_test_dir)

        if not os.path.isdir(runtime_testvars['resultsDir']):
            os.makedirs(runtime_testvars['resultsDir'])

        runtime_testvars_path = os.path.join(awsy_tests_dir,
                                             'runtime-testvars.json')
        if kwargs['testvars']:
            kwargs['testvars'].append(runtime_testvars_path)
        else:
            kwargs['testvars'] = [runtime_testvars_path]

        runtime_testvars_file = open(runtime_testvars_path, 'wb')
        runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
        runtime_testvars_file.close()

        manifest_file = os.path.join(awsy_source_dir, 'tp5n-pageset.manifest')
        tooltool_args = {
            'args': [
                sys.executable,
                os.path.join(self.topsrcdir, 'mach'),
                'artifact',
                'toolchain',
                '-v',
                '--tooltool-manifest=%s' % manifest_file,
                '--cache-dir=%s' %
                os.path.join(self.topsrcdir, 'tooltool-cache'),
            ]
        }
        self.run_process(cwd=page_load_test_dir, **tooltool_args)
        tp5nzip = os.path.join(page_load_test_dir, 'tp5n.zip')
        tp5nmanifest = os.path.join(page_load_test_dir, 'tp5n',
                                    'tp5n.manifest')
        if not os.path.exists(tp5nmanifest):
            unzip_args = {
                'args':
                ['unzip', '-q', '-o', tp5nzip, '-d', page_load_test_dir]
            }
            try:
                self.run_process(**unzip_args)
            except Exception as exc:
                troubleshoot = ''
                if mozinfo.os == 'win':
                    troubleshoot = ' Try using --web-root to specify a ' \
                                   'directory closer to the drive root.'

                self.log(
                    logging.ERROR, 'awsy', {
                        'directory': page_load_test_dir,
                        'exception': exc
                    }, 'Failed to unzip `tp5n.zip` into '
                    '`{directory}` with `{exception}`.' + troubleshoot)
                raise exc

        # If '--preferences' was not specified supply our default set.
        if not kwargs['prefs_files']:
            kwargs['prefs_files'] = [
                os.path.join(awsy_source_dir, 'conf', 'prefs.json')
            ]

        # Setup DMD env vars if necessary.
        if kwargs['dmd']:
            bin_dir = os.path.dirname(binary)

            if 'DMD' not in os.environ:
                os.environ['DMD'] = '1'

            # Work around a startup crash with DMD on windows
            if mozinfo.os == 'win':
                kwargs['pref'] = 'security.sandbox.content.level:0'
                self.log(
                    logging.WARNING, 'awsy', {},
                    'Forcing \'security.sandbox.content.level\' = 0 because DMD is enabled.'
                )
            elif mozinfo.os == 'mac':
                # On mac binary is in MacOS and dmd.py is in Resources, ie:
                #   Name.app/Contents/MacOS/libdmd.dylib
                #   Name.app/Contents/Resources/dmd.py
                bin_dir = os.path.join(bin_dir, "../Resources/")

            # Also add the bin dir to the python path so we can use dmd.py
            if bin_dir not in sys.path:
                sys.path.append(bin_dir)

        for k, v in kwargs.iteritems():
            setattr(args, k, v)

        parser.verify_usage(args)

        args.logger = commandline.setup_logging('Are We Slim Yet Tests', args,
                                                {'mach': sys.stdout})
        failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
        if failed > 0:
            return 1
        else:
            return 0
Exemplo n.º 15
0
    def run_awsy(self, tests, binary=None, **kwargs):
        import json
        from mozlog.structured import commandline

        from marionette_harness.runtests import (MarionetteTestRunner,
                                                 MarionetteHarness)

        parser = setup_awsy_argument_parser()

        awsy_source_dir = os.path.join(self.topsrcdir, 'testing', 'awsy')
        if not tests:
            tests = [
                os.path.join(awsy_source_dir, 'awsy', 'test_memory_usage.py')
            ]

        args = argparse.Namespace(tests=tests)

        args.binary = binary

        if kwargs['quick']:
            kwargs['entities'] = 3
            kwargs['iterations'] = 1
            kwargs['perTabPause'] = 1
            kwargs['settleWaitTime'] = 1

        runtime_testvars = {}
        for arg in ('webRootDir', 'pageManifest', 'resultsDir', 'entities',
                    'iterations', 'perTabPause', 'settleWaitTime', 'maxTabs'):
            if kwargs[arg]:
                runtime_testvars[arg] = kwargs[arg]

        if 'webRootDir' not in runtime_testvars:
            awsy_tests_dir = os.path.join(self.topobjdir, '_tests', 'awsy')
            web_root_dir = os.path.join(awsy_tests_dir, 'html')
            runtime_testvars['webRootDir'] = web_root_dir
        else:
            web_root_dir = runtime_testvars['webRootDir']
            awsy_tests_dir = os.path.dirname(web_root_dir)

        if 'resultsDir' not in runtime_testvars:
            runtime_testvars['resultsDir'] = os.path.join(
                awsy_tests_dir, 'results')
        page_load_test_dir = os.path.join(web_root_dir, 'page_load_test')
        if not os.path.isdir(page_load_test_dir):
            os.makedirs(page_load_test_dir)

        if not os.path.isdir(runtime_testvars['resultsDir']):
            os.makedirs(runtime_testvars['resultsDir'])

        runtime_testvars_path = os.path.join(awsy_tests_dir,
                                             'runtime-testvars.json')
        if kwargs['testvars']:
            kwargs['testvars'].append(runtime_testvars_path)
        else:
            kwargs['testvars'] = [runtime_testvars_path]

        runtime_testvars_file = open(runtime_testvars_path, 'wb')
        runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
        runtime_testvars_file.close()

        manifest_file = os.path.join(awsy_source_dir, 'tp5n-pageset.manifest')
        tooltool_args = {
            'args': [
                sys.executable,
                os.path.join(self.topsrcdir, 'taskcluster', 'docker',
                             'recipes', 'tooltool.py'),
                '--manifest=%s' % manifest_file,
                '--cache-folder=%s' %
                os.path.join(self.topsrcdir, 'tooltool-cache'), 'fetch'
            ]
        }
        self.run_process(cwd=page_load_test_dir, **tooltool_args)
        tp5nzip = os.path.join(page_load_test_dir, 'tp5n.zip')
        tp5nmanifest = os.path.join(page_load_test_dir, 'tp5n',
                                    'tp5n.manifest')
        if not os.path.exists(tp5nmanifest):
            unzip_args = {
                'args':
                ['unzip', '-q', '-o', tp5nzip, '-d', page_load_test_dir]
            }
            self.run_process(**unzip_args)

        for k, v in kwargs.iteritems():
            setattr(args, k, v)

        parser.verify_usage(args)

        args.logger = commandline.setup_logging('Are We Slim Yet Tests', args,
                                                {'mach': sys.stdout})
        failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
        if failed > 0:
            return 1
        else:
            return 0
Exemplo n.º 16
0
    def run_awsy(self, tests, binary=None, **kwargs):
        import json
        from mozlog.structured import commandline

        from marionette_harness.runtests import MarionetteTestRunner, MarionetteHarness

        parser = setup_awsy_argument_parser()

        awsy_source_dir = os.path.join(self.topsrcdir, "testing", "awsy")
        if not tests:
            tests = [
                os.path.join(awsy_source_dir, "awsy", "test_memory_usage.py")
            ]

        args = argparse.Namespace(tests=tests)

        args.binary = binary

        if kwargs["quick"]:
            kwargs["entities"] = 3
            kwargs["iterations"] = 1
            kwargs["perTabPause"] = 1
            kwargs["settleWaitTime"] = 1

        if "single_stylo_traversal" in kwargs and kwargs[
                "single_stylo_traversal"]:
            os.environ["STYLO_THREADS"] = "1"
        else:
            os.environ["STYLO_THREADS"] = "4"

        runtime_testvars = {}
        for arg in (
                "webRootDir",
                "pageManifest",
                "resultsDir",
                "entities",
                "iterations",
                "perTabPause",
                "settleWaitTime",
                "maxTabs",
                "dmd",
                "tp6",
        ):
            if arg in kwargs and kwargs[arg] is not None:
                runtime_testvars[arg] = kwargs[arg]

        if "webRootDir" not in runtime_testvars:
            awsy_tests_dir = os.path.join(self.topobjdir, "_tests", "awsy")
            web_root_dir = os.path.join(awsy_tests_dir, "html")
            runtime_testvars["webRootDir"] = web_root_dir
        else:
            web_root_dir = runtime_testvars["webRootDir"]
            awsy_tests_dir = os.path.dirname(web_root_dir)

        if "resultsDir" not in runtime_testvars:
            runtime_testvars["resultsDir"] = os.path.join(
                awsy_tests_dir, "results")

        runtime_testvars["bin"] = binary
        runtime_testvars["run_local"] = True

        page_load_test_dir = os.path.join(web_root_dir, "page_load_test")
        if not os.path.isdir(page_load_test_dir):
            os.makedirs(page_load_test_dir)

        if not os.path.isdir(runtime_testvars["resultsDir"]):
            os.makedirs(runtime_testvars["resultsDir"])

        runtime_testvars_path = os.path.join(awsy_tests_dir,
                                             "runtime-testvars.json")
        if kwargs["testvars"]:
            kwargs["testvars"].append(runtime_testvars_path)
        else:
            kwargs["testvars"] = [runtime_testvars_path]

        runtime_testvars_file = open(runtime_testvars_path, "wb")
        runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
        runtime_testvars_file.close()

        manifest_file = os.path.join(awsy_source_dir, "tp5n-pageset.manifest")
        tooltool_args = {
            "args": [
                sys.executable,
                os.path.join(self.topsrcdir, "mach"),
                "artifact",
                "toolchain",
                "-v",
                "--tooltool-manifest=%s" % manifest_file,
                "--cache-dir=%s" %
                os.path.join(self.topsrcdir, "tooltool-cache"),
            ]
        }
        self.run_process(cwd=page_load_test_dir, **tooltool_args)
        tp5nzip = os.path.join(page_load_test_dir, "tp5n.zip")
        tp5nmanifest = os.path.join(page_load_test_dir, "tp5n",
                                    "tp5n.manifest")
        if not os.path.exists(tp5nmanifest):
            unzip_args = {
                "args":
                ["unzip", "-q", "-o", tp5nzip, "-d", page_load_test_dir]
            }
            try:
                self.run_process(**unzip_args)
            except Exception as exc:
                troubleshoot = ""
                if mozinfo.os == "win":
                    troubleshoot = (" Try using --web-root to specify a "
                                    "directory closer to the drive root.")

                self.log(
                    logging.ERROR,
                    "awsy",
                    {
                        "directory": page_load_test_dir,
                        "exception": exc
                    },
                    "Failed to unzip `tp5n.zip` into "
                    "`{directory}` with `{exception}`." + troubleshoot,
                )
                raise exc

        # If '--preferences' was not specified supply our default set.
        if not kwargs["prefs_files"]:
            kwargs["prefs_files"] = [
                os.path.join(awsy_source_dir, "conf", "prefs.json")
            ]

        # Setup DMD env vars if necessary.
        if kwargs["dmd"]:
            bin_dir = os.path.dirname(binary)

            if "DMD" not in os.environ:
                os.environ["DMD"] = "1"

            # Work around a startup crash with DMD on windows
            if mozinfo.os == "win":
                kwargs["pref"] = "security.sandbox.content.level:0"
                self.log(
                    logging.WARNING,
                    "awsy",
                    {},
                    "Forcing 'security.sandbox.content.level' = 0 because DMD is enabled.",
                )
            elif mozinfo.os == "mac":
                # On mac binary is in MacOS and dmd.py is in Resources, ie:
                #   Name.app/Contents/MacOS/libdmd.dylib
                #   Name.app/Contents/Resources/dmd.py
                bin_dir = os.path.join(bin_dir, "../Resources/")

            # Also add the bin dir to the python path so we can use dmd.py
            if bin_dir not in sys.path:
                sys.path.append(bin_dir)

        for k, v in kwargs.iteritems():
            setattr(args, k, v)

        parser.verify_usage(args)

        args.logger = commandline.setup_logging("Are We Slim Yet Tests", args,
                                                {"mach": sys.stdout})
        failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
        if failed > 0:
            return 1
        else:
            return 0
Exemplo n.º 17
0
    def run_awsy(self, tests, binary=None, **kwargs):
        import json
        from mozlog.structured import commandline

        from marionette_harness.runtests import (
            MarionetteTestRunner,
            MarionetteHarness
        )

        parser = setup_awsy_argument_parser()

        awsy_source_dir = os.path.join(self.topsrcdir, 'testing', 'awsy')
        if not tests:
            tests = [os.path.join(awsy_source_dir,
                                  'awsy',
                                  'test_memory_usage.py')]

        args = argparse.Namespace(tests=tests)

        args.binary = binary

        if kwargs['quick']:
            kwargs['entities'] = 3
            kwargs['iterations'] = 1
            kwargs['perTabPause'] = 1
            kwargs['settleWaitTime'] = 1

        if 'disable_stylo' in kwargs and kwargs['disable_stylo']:
            if 'single_stylo_traversal' in kwargs and kwargs['single_stylo_traversal']:
                print("--disable-stylo conflicts with --single-stylo-traversal")
                return 1
            if 'enable_stylo' in kwargs and kwargs['enable_stylo']:
                print("--disable-stylo conflicts with --enable-stylo")
                return 1

        if 'single_stylo_traversal' in kwargs and kwargs['single_stylo_traversal']:
            os.environ['STYLO_THREADS'] = '1'
        else:
            os.environ['STYLO_THREADS'] = '4'

        if 'enable_stylo' in kwargs and kwargs['enable_stylo']:
            os.environ['STYLO_FORCE_ENABLED'] = '1'
        if 'disable_stylo' in kwargs and kwargs['disable_stylo']:
            os.environ['STYLO_FORCE_DISABLED'] = '1'

        runtime_testvars = {}
        for arg in ('webRootDir', 'pageManifest', 'resultsDir', 'entities', 'iterations',
                    'perTabPause', 'settleWaitTime', 'maxTabs', 'dmd'):
            if kwargs[arg]:
                runtime_testvars[arg] = kwargs[arg]

        if 'webRootDir' not in runtime_testvars:
            awsy_tests_dir = os.path.join(self.topobjdir, '_tests', 'awsy')
            web_root_dir = os.path.join(awsy_tests_dir, 'html')
            runtime_testvars['webRootDir'] = web_root_dir
        else:
            web_root_dir = runtime_testvars['webRootDir']
            awsy_tests_dir = os.path.dirname(web_root_dir)

        if 'resultsDir' not in runtime_testvars:
            runtime_testvars['resultsDir'] = os.path.join(awsy_tests_dir,
                                                          'results')
        page_load_test_dir = os.path.join(web_root_dir, 'page_load_test')
        if not os.path.isdir(page_load_test_dir):
            os.makedirs(page_load_test_dir)

        if not os.path.isdir(runtime_testvars['resultsDir']):
            os.makedirs(runtime_testvars['resultsDir'])

        runtime_testvars_path = os.path.join(awsy_tests_dir, 'runtime-testvars.json')
        if kwargs['testvars']:
            kwargs['testvars'].append(runtime_testvars_path)
        else:
            kwargs['testvars'] = [runtime_testvars_path]

        runtime_testvars_file = open(runtime_testvars_path, 'wb')
        runtime_testvars_file.write(json.dumps(runtime_testvars, indent=2))
        runtime_testvars_file.close()

        manifest_file = os.path.join(awsy_source_dir,
                                     'tp5n-pageset.manifest')
        tooltool_args = {'args': [
            sys.executable,
            os.path.join(self.topsrcdir, 'mach'),
            'artifact', 'toolchain', '-v',
            '--tooltool-manifest=%s' % manifest_file,
            '--cache-dir=%s' % os.path.join(self.topsrcdir, 'tooltool-cache'),
        ]}
        self.run_process(cwd=page_load_test_dir, **tooltool_args)
        tp5nzip = os.path.join(page_load_test_dir, 'tp5n.zip')
        tp5nmanifest = os.path.join(page_load_test_dir, 'tp5n', 'tp5n.manifest')
        if not os.path.exists(tp5nmanifest):
            unzip_args = {'args': [
                'unzip',
                '-q',
                '-o',
                tp5nzip,
                '-d',
                page_load_test_dir]}
            self.run_process(**unzip_args)

        # If '--preferences' was not specified supply our default set.
        if not kwargs['prefs_files']:
            kwargs['prefs_files'] = [os.path.join(awsy_source_dir, 'conf', 'prefs.json')]

        # Setup DMD env vars if necessary.
        if kwargs['dmd']:
            dmd_params = []

            bin_dir = os.path.dirname(binary)
            lib_name = self.substs['DLL_PREFIX'] + 'dmd' + self.substs['DLL_SUFFIX']
            dmd_lib = os.path.join(bin_dir, lib_name)
            if not os.path.exists(dmd_lib):
                print("Please build with |--enable-dmd| to use DMD.")
                return 1

            env_vars = {
                "Darwin": {
                    "DYLD_INSERT_LIBRARIES": dmd_lib,
                    "LD_LIBRARY_PATH": bin_dir,
                },
                "Linux": {
                    "LD_PRELOAD": dmd_lib,
                    "LD_LIBRARY_PATH": bin_dir,
                },
                "WINNT": {
                    "MOZ_REPLACE_MALLOC_LIB": dmd_lib,
                },
            }

            arch = self.substs['OS_ARCH']
            for k, v in env_vars[arch].iteritems():
                os.environ[k] = v

            # Also add the bin dir to the python path so we can use dmd.py
            if bin_dir not in sys.path:
                sys.path.append(bin_dir)

        for k, v in kwargs.iteritems():
            setattr(args, k, v)

        parser.verify_usage(args)

        args.logger = commandline.setup_logging('Are We Slim Yet Tests',
                                                args,
                                                {'mach': sys.stdout})
        failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
        if failed > 0:
            return 1
        else:
            return 0