コード例 #1
0
 def test_cycle_in_dependency(self):
     # Cycle: 'c' => 'd' => 'e' => 'c'
     graph = {'a': ['b'], 'b': [], 'c': ['a', 'd'], 'd': ['e'], 'e': ['c']}
     with self.assertRaises(AssertionError):
         util.origin_trials([{
             'name': name,
             'depends_on': deps
         } for name, deps in graph.items()])
コード例 #2
0
    def test_in_origin_trials_flag(self):
        features = [
            {
                'name': NameStyleConverter('a'),
                'depends_on': [],
                'origin_trial_feature_name': None
            },
            {
                'name': NameStyleConverter('b'),
                'depends_on': ['a'],
                'origin_trial_feature_name': 'OriginTrials'
            },
            {
                'name': NameStyleConverter('c'),
                'depends_on': ['b'],
                'origin_trial_feature_name': None
            },
            {
                'name': NameStyleConverter('d'),
                'depends_on': ['b'],
                'origin_trial_feature_name': None
            },
            {
                'name': NameStyleConverter('e'),
                'depends_on': ['d'],
                'origin_trial_feature_name': None
            },
        ]
        self.assertSetEqual(util.origin_trials(features), {'b', 'c', 'd', 'e'})

        features = [{
            'name': 'a',
            'depends_on': ['x'],
            'origin_trial_feature_name': None
        }, {
            'name': 'b',
            'depends_on': ['x', 'y'],
            'origin_trial_feature_name': None
        }, {
            'name': 'c',
            'depends_on': ['y', 'z'],
            'origin_trial_feature_name': None
        }, {
            'name': 'x',
            'depends_on': [],
            'origin_trial_feature_name': None
        }, {
            'name': 'y',
            'depends_on': ['x'],
            'origin_trial_feature_name': 'y'
        }, {
            'name': 'z',
            'depends_on': ['y'],
            'origin_trial_feature_name': None
        }]

        self.assertSetEqual(util.origin_trials(features), {'b', 'c', 'y', 'z'})
コード例 #3
0
 def test_both_dependency_and_implication(self):
     with self.assertRaisesRegexp(
             AssertionError,
             'c: Only one of implied_by and depends_on is allowed'):
         util.origin_trials([
             _feature('a'),
             _feature('b'),
             _feature('c', depends_on=['a'], implied_by=['b'])
         ])
コード例 #4
0
 def test_cycle(self):
     # Cycle: 'c' => 'd' => 'e' => 'c'
     with self.assertRaisesRegexp(
             AssertionError, 'Cycle found in depends_on/implied_by graph'):
         util.origin_trials([
             _feature('a', depends_on=['b']),
             _feature('b'),
             _feature('c', implied_by=['a', 'd']),
             _feature('d', depends_on=['e']),
             _feature('e', implied_by=['c'])
         ])
コード例 #5
0
 def test_bad_implication(self):
     with self.assertRaisesRegexp(AssertionError,
                                  'a: Implied by non-existent-feature: x'):
         util.origin_trials([_feature('a', implied_by=['x'])])
     with self.assertRaisesRegexp(
             AssertionError,
             'a: A feature must be in origin trial if implied by an origin trial feature: b'
     ):
         util.origin_trials([
             _feature('a', implied_by=['b']),
             _feature('b', origin_trial_feature_name='b')
         ])
コード例 #6
0
    def __init__(self, json5_file_path, output_dir):
        super(BaseRuntimeFeatureWriter, self).__init__(json5_file_path, output_dir)
        # Subclasses should add generated output files and their contents to this dict.
        self._outputs = {}
        assert self.file_basename

        self._features = self.json5_file.name_dictionaries
        origin_trial_set = util.origin_trials(self._features)

        # Make sure the resulting dictionaries have all the keys we expect.
        for feature in self._features:
            feature['in_origin_trial'] = str(feature['name']) in origin_trial_set
            feature['data_member_name'] = self._data_member_name(feature['name'])
            # Most features just check their is_foo_enabled_ bool
            # but some depend on or are implied by other bools.
            enabled_condition = feature['data_member_name']
            assert not feature['implied_by'] or not feature['depends_on'], 'Only one of implied_by and depends_on is allowed'
            for implied_by_name in feature['implied_by']:
                enabled_condition += ' || ' + self._data_member_name(implied_by_name)
            for dependant_name in feature['depends_on']:
                enabled_condition += ' && ' + self._data_member_name(dependant_name)
            feature['enabled_condition'] = enabled_condition
            # If 'status' is a dict, add the values for all the not-mentioned platforms too.
            if isinstance(feature['status'], dict):
                feature['status'] = self._status_with_all_platforms(feature['status'])
            # Specify the type of status
            feature['status_type'] = "dict" if isinstance(feature['status'], dict) else "str"

        self._standard_features = [feature for feature in self._features if not feature['custom']]
        self._origin_trial_features = [feature for feature in self._features if feature['in_origin_trial']]
        self._header_guard = self.make_header_guard(self._relative_output_dir + self.file_basename + '.h')
コード例 #7
0
    def __init__(self, json5_file_path, output_dir):
        super(BaseRuntimeFeatureWriter, self).__init__(json5_file_path,
                                                       output_dir)
        # Subclasses should add generated output files and their contents to this dict.
        self._outputs = {}
        assert self.file_basename

        self._features = self.json5_file.name_dictionaries
        origin_trial_set = util.origin_trials(self._features)

        # Make sure the resulting dictionaries have all the keys we expect.
        for feature in self._features:
            feature['in_origin_trial'] = str(
                feature['name']) in origin_trial_set
            feature['data_member_name'] = self._data_member_name(
                feature['name'])
            # If 'status' is a dict, add the values for all the not-mentioned platforms too.
            if isinstance(feature['status'], dict):
                feature['status'] = self._status_with_all_platforms(
                    feature['status'])
            # Specify the type of status
            feature['status_type'] = "dict" if isinstance(
                feature['status'], dict) else "str"

        self._origin_trial_features = [
            feature for feature in self._features if feature['in_origin_trial']
        ]
        self._header_guard = self.make_header_guard(self._relative_output_dir +
                                                    self.file_basename + '.h')
コード例 #8
0
    def __init__(self, json5_file_path, output_dir):
        super(FeaturePolicyFeatureWriter,
              self).__init__(json5_file_path, output_dir)
        runtime_features = []
        feature_policy_features = []
        # Note: there can be feature with same 'name' attribute in document_policy_features
        # and in feature_policy_features. They are supposed to have the same 'depends_on' attribute.
        # However, their feature_policy_name and document_policy_name might be different.
        document_policy_features = []

        for feature in self.json5_file.name_dictionaries:
            if feature['feature_policy_name']:
                feature_policy_features.append(feature)
            elif feature['document_policy_name']:
                document_policy_features.append(feature)
            else:
                runtime_features.append(feature)

        origin_trials_set = origin_trials(runtime_features)
        origin_trial_dependency_map = defaultdict(list)
        runtime_to_feature_policy_map = defaultdict(list)
        runtime_to_document_policy_map = defaultdict(list)
        for feature in feature_policy_features + document_policy_features:
            for dependency in feature['depends_on']:
                if str(dependency) in origin_trials_set:
                    deps = origin_trial_dependency_map[feature['name']]
                    if dependency not in deps:
                        deps.append(dependency)
                else:
                    if feature['feature_policy_name']:
                        runtime_to_feature_policy_map[dependency].append(
                            feature['name'])
                    else:
                        runtime_to_document_policy_map[dependency].append(
                            feature['name'])

        self._outputs = {
            self.file_basename + '.cc':
            template_expander.use_jinja(
                'templates/' + self.file_basename + '.cc.tmpl')(lambda: {
                    'header_guard':
                    self.make_header_guard(self._relative_output_dir + self.
                                           file_basename + '.h'),
                    'input_files':
                    self._input_files,
                    'feature_policy_features':
                    feature_policy_features,
                    'document_policy_features':
                    document_policy_features,
                    'origin_trial_dependency_map':
                    origin_trial_dependency_map,
                    'runtime_to_feature_policy_map':
                    runtime_to_feature_policy_map,
                    'runtime_to_document_policy_map':
                    runtime_to_document_policy_map
                }),
        }
コード例 #9
0
    def test_origin_trials(self):
        features = [
            _feature(NameStyleConverter('a')),
            _feature(NameStyleConverter('b'),
                     depends_on=['a'],
                     origin_trial_feature_name='b'),
            _feature(NameStyleConverter('c'), depends_on=['b']),
            _feature(NameStyleConverter('d'), depends_on=['b']),
            _feature(NameStyleConverter('e'), depends_on=['d'])
        ]
        self.assertSetEqual(util.origin_trials(features), {'b', 'c', 'd', 'e'})

        features = [
            _feature('a'),
            _feature('b', depends_on=['x', 'y']),
            _feature('c', depends_on=['y', 'z']),
            _feature('x', depends_on=['a']),
            _feature('y', depends_on=['x'], origin_trial_feature_name='y'),
            _feature('z', depends_on=['y'])
        ]
        self.assertSetEqual(util.origin_trials(features), {'b', 'c', 'y', 'z'})
コード例 #10
0
    def __init__(self, json5_file_path, output_dir):
        super(FeaturePolicyFeatureWriter,
              self).__init__(json5_file_path, output_dir)
        runtime_features = []
        feature_policy_features = []
        # Note: there can be feature with same 'name' attribute in
        # document_policy_features and in feature_policy_features.
        # They are supposed to have the same 'depends_on' attribute.
        # However, their feature_policy_name and document_policy_name
        # might be different.
        document_policy_features = []

        def to_devtools_enum_format(feature_policy_name):
            """ Convert '-' separated feature_policy_name to cammel case devtool enum name """
            return ''.join(
                [name.capitalize() for name in feature_policy_name.split('-')])

        for feature in self.json5_file.name_dictionaries:
            if feature['feature_policy_name']:
                feature['devtools_enum_name'] = to_devtools_enum_format(
                    feature['feature_policy_name'])
                feature_policy_features.append(feature)
            elif feature['document_policy_name']:
                document_policy_features.append(feature)
            else:
                runtime_features.append(feature)

        origin_trials_set = origin_trials(runtime_features)
        fp_origin_trial_dependency_map = defaultdict(list)
        dp_origin_trial_dependency_map = defaultdict(list)
        runtime_to_feature_policy_map = defaultdict(list)
        runtime_to_document_policy_map = defaultdict(list)
        for feature in feature_policy_features + document_policy_features:
            for dependency in feature['depends_on']:
                if str(dependency) in origin_trials_set:
                    if feature['feature_policy_name']:
                        fp_origin_trial_dependency_map[feature['name']].append(
                            dependency)
                    else:
                        dp_origin_trial_dependency_map[feature['name']].append(
                            dependency)
                else:
                    if feature['feature_policy_name']:
                        runtime_to_feature_policy_map[dependency].append(
                            feature['name'])
                    else:
                        runtime_to_document_policy_map[dependency].append(
                            feature['name'])

        self._outputs = {
            self.file_basename + '.cc':
            template_expander.use_jinja(
                'templates/' + self.file_basename + '.cc.tmpl')(lambda: {
                    'header_guard':
                    self.make_header_guard(self._relative_output_dir + self.
                                           file_basename + '.h'),
                    'input_files':
                    self._input_files,
                    'feature_policy_features':
                    feature_policy_features,
                    'document_policy_features':
                    document_policy_features,
                    'fp_origin_trial_dependency_map':
                    fp_origin_trial_dependency_map,
                    'dp_origin_trial_dependency_map':
                    dp_origin_trial_dependency_map,
                    'runtime_to_feature_policy_map':
                    runtime_to_feature_policy_map,
                    'runtime_to_document_policy_map':
                    runtime_to_document_policy_map
                }),
        }
コード例 #11
0
 def test_bad_dependency(self):
     with self.assertRaises(AssertionError):
         util.origin_trials([{'name': 'a', 'depends_on': 'x'}])
コード例 #12
0
 def test_bad_dependency(self):
     with self.assertRaisesRegexp(AssertionError,
                                  'a: Depends on non-existent-feature: x'):
         util.origin_trials([_feature('a', depends_on=['x'])])