forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mb_validation_unittest.py
executable file
·215 lines (183 loc) · 6.36 KB
/
mb_validation_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests for mb_validate.py."""
from __future__ import print_function
from __future__ import absolute_import
import sys
import ast
import os
import unittest
sys.path.insert(0, os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..'))
from mb import mb
from mb import mb_unittest
from mb.lib import validation
TEST_UNREFERENCED_MIXIN_CONFIG = """\
{
'public_artifact_builders': {},
'configs': {
'rel_bot_1': ['rel'],
'rel_bot_2': ['rel'],
},
'builder_groups': {
'fake_builder_group_a': {
'fake_builder_a': 'rel_bot_1',
'fake_builder_b': 'rel_bot_2',
},
},
'mixins': {
'unreferenced_mixin': {
'gn_args': 'proprietary_codecs=true',
},
'rel': {
'gn_args': 'is_debug=false',
},
},
}
"""
TEST_UNKNOWNMIXIN_CONFIG = """\
{
'public_artifact_builders': {},
'configs': {
'rel_bot_1': ['rel'],
'rel_bot_2': ['rel', 'unknown_mixin'],
},
'builder_groups': {
'fake_builder_group_a': {
'fake_builder_a': 'rel_bot_1',
'fake_builder_b': 'rel_bot_2',
},
},
'mixins': {
'rel': {
'gn_args': 'is_debug=false',
},
},
}
"""
TEST_UNKNOWN_NESTED_MIXIN_CONFIG = """\
{
'public_artifact_builders': {},
'configs': {
'rel_bot_1': ['rel', 'nested_mixin'],
'rel_bot_2': ['rel'],
},
'builder_groups': {
'fake_builder_group_a': {
'fake_builder_a': 'rel_bot_1',
'fake_builder_b': 'rel_bot_2',
},
},
'mixins': {
'nested_mixin': {
'mixins': {
'unknown_mixin': {
'gn_args': 'proprietary_codecs=true',
},
},
},
'rel': {
'gn_args': 'is_debug=false',
},
},
}
"""
class UnitTest(unittest.TestCase):
def test_GetAllConfigs(self):
configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
all_configs = validation.GetAllConfigs(configs['builder_groups'])
self.assertEqual(all_configs['rel_bot'], 'fake_builder_group')
self.assertEqual(all_configs['debug_goma'], 'fake_builder_group')
def test_CheckAllConfigsAndMixinsReferenced_ok(self):
configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
errs = []
all_configs = validation.GetAllConfigs(configs['builder_groups'])
config_configs = configs['configs']
mixins = configs['mixins']
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
config_configs, mixins)
self.assertEqual(errs, [])
def test_CheckAllConfigsAndMixinsReferenced_unreferenced(self):
configs = ast.literal_eval(TEST_UNREFERENCED_MIXIN_CONFIG)
errs = []
all_configs = validation.GetAllConfigs(configs['builder_groups'])
config_configs = configs['configs']
mixins = configs['mixins']
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
config_configs, mixins)
self.assertIn('Unreferenced mixin "unreferenced_mixin".', errs)
def test_CheckAllConfigsAndMixinsReferenced_unknown(self):
configs = ast.literal_eval(TEST_UNKNOWNMIXIN_CONFIG)
errs = []
all_configs = validation.GetAllConfigs(configs['builder_groups'])
config_configs = configs['configs']
mixins = configs['mixins']
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
config_configs, mixins)
self.assertIn(
'Unknown mixin "unknown_mixin" '
'referenced by config "rel_bot_2".', errs)
def test_CheckAllConfigsAndMixinsReferenced_unknown_nested(self):
configs = ast.literal_eval(TEST_UNKNOWN_NESTED_MIXIN_CONFIG)
errs = []
all_configs = validation.GetAllConfigs(configs['builder_groups'])
config_configs = configs['configs']
mixins = configs['mixins']
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
config_configs, mixins)
self.assertIn(
'Unknown mixin "unknown_mixin" '
'referenced by mixin "nested_mixin".', errs)
def test_CheckAllConfigsAndMixinsReferenced_unused(self):
configs = ast.literal_eval(TEST_UNKNOWN_NESTED_MIXIN_CONFIG)
errs = []
all_configs = validation.GetAllConfigs(configs['builder_groups'])
config_configs = configs['configs']
mixins = configs['mixins']
validation.CheckAllConfigsAndMixinsReferenced(errs, all_configs,
config_configs, mixins)
self.assertIn(
'Unknown mixin "unknown_mixin" '
'referenced by mixin "nested_mixin".', errs)
def test_EnsureNoProprietaryMixins(self):
bad_configs = ast.literal_eval(mb_unittest.TEST_BAD_CONFIG)
errs = []
builder_groups = bad_configs['builder_groups']
mixins = bad_configs['mixins']
config_configs = bad_configs['configs']
validation.EnsureNoProprietaryMixins(errs, builder_groups, config_configs,
mixins)
self.assertIn(
'Public artifact builder "a" '
'can not contain the "chrome_with_codecs" mixin.', errs)
self.assertIn(
'Public artifact builder "b" '
'can not contain the "chrome_with_codecs" mixin.', errs)
self.assertEqual(len(errs), 2)
def test_CheckDuplicateConfigs_ok(self):
configs = ast.literal_eval(mb_unittest.TEST_CONFIG)
config_configs = configs['configs']
mixins = configs['mixins']
grouping = configs['builder_groups']
errs = []
validation.CheckDuplicateConfigs(errs, config_configs, mixins, grouping,
mb.FlattenConfig)
self.assertEqual(errs, [])
@unittest.skip('bla')
def test_CheckDuplicateConfigs_dups(self):
configs = ast.literal_eval(mb_unittest.TEST_DUP_CONFIG)
config_configs = configs['configs']
mixins = configs['mixins']
grouping = configs['builder_groups']
errs = []
validation.CheckDuplicateConfigs(errs, config_configs, mixins, grouping,
mb.FlattenConfig)
self.assertIn(
'Duplicate configs detected. When evaluated fully, the '
'following configs are all equivalent: \'some_config\', '
'\'some_other_config\'. Please consolidate these configs '
'into only one unique name per configuration value.', errs)
if __name__ == '__main__':
unittest.main()