2 # Copyright 2020 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 """Tests for mb_validate.py."""
12 sys.path.insert(0, os.path.join(
13 os.path.dirname(os.path.abspath(__file__)), '..'))
16 from mb import mb_unittest
17 from mb.lib import validation
19 TEST_UNREFERENCED_MIXIN_CONFIG = """\
21 'public_artifact_builders': {},
27 'fake_builder_group_a': {
28 'fake_builder_a': 'rel_bot_1',
29 'fake_builder_b': 'rel_bot_2',
33 'unreferenced_mixin': {
34 'gn_args': 'proprietary_codecs=true',
37 'gn_args': 'is_debug=false',
43 TEST_UNKNOWNMIXIN_CONFIG = """\
45 'public_artifact_builders': {},
48 'rel_bot_2': ['rel', 'unknown_mixin'],
51 'fake_builder_group_a': {
52 'fake_builder_a': 'rel_bot_1',
53 'fake_builder_b': 'rel_bot_2',
58 'gn_args': 'is_debug=false',
64 TEST_UNKNOWN_NESTED_MIXIN_CONFIG = """\
66 'public_artifact_builders': {},
68 'rel_bot_1': ['rel', 'nested_mixin'],
72 'fake_builder_group_a': {
73 'fake_builder_a': 'rel_bot_1',
74 'fake_builder_b': 'rel_bot_2',
81 'gn_args': 'proprietary_codecs=true',
86 'gn_args': 'is_debug=false',
92 TEST_CONFIG_UNSORTED_GROUPS = """\
106 TEST_CONFIG_UNSORTED_BUILDERNAMES = """\
121 TEST_CONFIG_UNSORTED_CONFIGS = """\
134 TEST_CONFIG_UNSORTED_MIXINS = """\
148 class UnitTest(unittest.TestCase):
149 def test_GetAllConfigs(self):
150 configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
151 all_configs = validation.GetAllConfigs(configs['builder_groups'])
152 self.assertEqual(all_configs['rel_bot'], 'fake_builder_group')
153 self.assertEqual(all_configs['debug_goma'], 'fake_builder_group')
155 def test_CheckAllConfigsAndMixinsReferenced_ok(self):
156 configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
158 all_configs = validation.GetAllConfigs(configs['builder_groups'])
159 config_configs = configs['configs']
160 mixins = configs['mixins']
162 validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
163 config_configs, mixins)
165 self.assertEqual(errs, [])
167 def test_CheckAllConfigsAndMixinsReferenced_unreferenced(self):
168 configs = ast.literal_eval(TEST_UNREFERENCED_MIXIN_CONFIG)
170 all_configs = validation.GetAllConfigs(configs['builder_groups'])
171 config_configs = configs['configs']
172 mixins = configs['mixins']
174 validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
175 config_configs, mixins)
177 self.assertIn('Unreferenced mixin "unreferenced_mixin".', errs)
179 def test_CheckAllConfigsAndMixinsReferenced_unknown(self):
180 configs = ast.literal_eval(TEST_UNKNOWNMIXIN_CONFIG)
182 all_configs = validation.GetAllConfigs(configs['builder_groups'])
183 config_configs = configs['configs']
184 mixins = configs['mixins']
186 validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
187 config_configs, mixins)
189 'Unknown mixin "unknown_mixin" '
190 'referenced by config "rel_bot_2".', errs)
192 def test_CheckAllConfigsAndMixinsReferenced_unknown_nested(self):
193 configs = ast.literal_eval(TEST_UNKNOWN_NESTED_MIXIN_CONFIG)
195 all_configs = validation.GetAllConfigs(configs['builder_groups'])
196 config_configs = configs['configs']
197 mixins = configs['mixins']
199 validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
200 config_configs, mixins)
203 'Unknown mixin "unknown_mixin" '
204 'referenced by mixin "nested_mixin".', errs)
206 def test_CheckAllConfigsAndMixinsReferenced_unused(self):
207 configs = ast.literal_eval(TEST_UNKNOWN_NESTED_MIXIN_CONFIG)
209 all_configs = validation.GetAllConfigs(configs['builder_groups'])
210 config_configs = configs['configs']
211 mixins = configs['mixins']
213 validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
214 config_configs, mixins)
217 'Unknown mixin "unknown_mixin" '
218 'referenced by mixin "nested_mixin".', errs)
220 def test_EnsureNoProprietaryMixins(self):
221 bad_configs = ast.literal_eval(mb_unittest.TEST_BAD_CONFIG)
223 builder_groups = bad_configs['builder_groups']
224 mixins = bad_configs['mixins']
225 config_configs = bad_configs['configs']
227 validation.EnsureNoProprietaryMixins(errs, builder_groups, config_configs,
231 'Public artifact builder "a" '
232 'can not contain the "chrome_with_codecs" mixin.', errs)
234 'Public artifact builder "b" '
235 'can not contain the "chrome_with_codecs" mixin.', errs)
236 self.assertEqual(len(errs), 2)
238 def test_CheckDuplicateConfigs_ok(self):
239 configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
240 config_configs = configs['configs']
241 mixins = configs['mixins']
242 grouping = configs['builder_groups']
245 validation.CheckDuplicateConfigs(errs, config_configs, mixins, grouping,
247 self.assertEqual(errs, [])
249 @unittest.skip('bla')
250 def test_CheckDuplicateConfigs_dups(self):
251 configs = ast.literal_eval(mb_unittest.TEST_DUP_CONFIG)
252 config_configs = configs['configs']
253 mixins = configs['mixins']
254 grouping = configs['builder_groups']
257 validation.CheckDuplicateConfigs(errs, config_configs, mixins, grouping,
260 'Duplicate configs detected. When evaluated fully, the '
261 'following configs are all equivalent: \'some_config\', '
262 '\'some_other_config\'. Please consolidate these configs '
263 'into only one unique name per configuration value.', errs)
265 def test_CheckKeyOrderingOK(self):
266 mb_config = ast.literal_eval(mb_unittest.TEST_CONFIG)
268 validation.CheckKeyOrdering(errs, mb_config['builder_groups'],
269 mb_config['configs'], mb_config['mixins'])
270 self.assertEqual(errs, [])
272 def test_CheckKeyOrderingBad(self):
273 mb_config = ast.literal_eval(TEST_CONFIG_UNSORTED_GROUPS)
275 validation.CheckKeyOrdering(errs, mb_config['builder_groups'],
276 mb_config['configs'], mb_config['mixins'])
277 self.assertIn('\nThe keys in "builder_groups" are not sorted:', errs)
279 mb_config = ast.literal_eval(TEST_CONFIG_UNSORTED_BUILDERNAMES)
281 validation.CheckKeyOrdering(errs, mb_config['builder_groups'],
282 mb_config['configs'], mb_config['mixins'])
283 self.assertIn('\nThe builders in group "group" are not sorted:', errs)
285 mb_config = ast.literal_eval(TEST_CONFIG_UNSORTED_CONFIGS)
287 validation.CheckKeyOrdering(errs, mb_config['builder_groups'],
288 mb_config['configs'], mb_config['mixins'])
289 self.assertIn('\nThe config names are not sorted:', errs)
291 mb_config = ast.literal_eval(TEST_CONFIG_UNSORTED_MIXINS)
293 validation.CheckKeyOrdering(errs, mb_config['builder_groups'],
294 mb_config['configs'], mb_config['mixins'])
295 self.assertIn('\nThe mixin names are not sorted:', errs)
298 if __name__ == '__main__':