OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Tests for mb.py.""" | 6 """Tests for mb.py.""" |
7 | 7 |
8 import json | 8 import json |
9 import StringIO | 9 import StringIO |
10 import os | 10 import os |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 'common_dev_configs': ['gn_debug'], | 106 'common_dev_configs': ['gn_debug'], |
107 'configs': { | 107 'configs': { |
108 'gyp_rel_bot': ['gyp', 'rel', 'goma'], | 108 'gyp_rel_bot': ['gyp', 'rel', 'goma'], |
109 'gn_debug': ['gn', 'debug', 'goma'], | 109 'gn_debug': ['gn', 'debug', 'goma'], |
110 'gyp_debug': ['gyp', 'debug'], | 110 'gyp_debug': ['gyp', 'debug'], |
111 'gn_rel_bot': ['gn', 'rel', 'goma'], | 111 'gn_rel_bot': ['gn', 'rel', 'goma'], |
112 'private': ['gyp', 'rel', 'fake_feature1'], | 112 'private': ['gyp', 'rel', 'fake_feature1'], |
113 'unsupported': ['gn', 'fake_feature2'], | 113 'unsupported': ['gn', 'fake_feature2'], |
114 }, | 114 }, |
115 'masters': { | 115 'masters': { |
| 116 'chromium': {}, |
116 'fake_master': { | 117 'fake_master': { |
117 'fake_builder': 'gyp_rel_bot', | 118 'fake_builder': 'gyp_rel_bot', |
118 'fake_gn_builder': 'gn_rel_bot', | 119 'fake_gn_builder': 'gn_rel_bot', |
119 'fake_gyp_builder': 'gyp_debug', | 120 'fake_gyp_builder': 'gyp_debug', |
120 }, | 121 }, |
121 }, | 122 }, |
122 'mixins': { | 123 'mixins': { |
123 'fake_feature1': { | 124 'fake_feature1': { |
124 'gn_args': 'enable_doom_melon=true', | 125 'gn_args': 'enable_doom_melon=true', |
125 'gyp_crosscompile': True, | 126 'gyp_crosscompile': True, |
(...skipping 15 matching lines...) Expand all Loading... |
141 'debug': { | 142 'debug': { |
142 'gn_args': 'is_debug=true', | 143 'gn_args': 'is_debug=true', |
143 }, | 144 }, |
144 }, | 145 }, |
145 'private_configs': ['private'], | 146 'private_configs': ['private'], |
146 'unsupported_configs': ['unsupported'], | 147 'unsupported_configs': ['unsupported'], |
147 } | 148 } |
148 """ | 149 """ |
149 | 150 |
150 | 151 |
| 152 TEST_BAD_CONFIG = """\ |
| 153 { |
| 154 'common_dev_configs': ['gn_rel_bot_1'], |
| 155 'configs': { |
| 156 'gn_rel_bot_1': ['gn', 'rel', 'chrome_with_codecs'], |
| 157 'gn_rel_bot_2': ['gn', 'rel', 'bad_nested_config'], |
| 158 }, |
| 159 'masters': { |
| 160 'chromium': { |
| 161 'a': 'gn_rel_bot_1', |
| 162 'b': 'gn_rel_bot_2', |
| 163 }, |
| 164 }, |
| 165 'mixins': { |
| 166 'gn': {'type': 'gn'}, |
| 167 'chrome_with_codecs': { |
| 168 'gn_args': 'proprietary_codecs=true', |
| 169 }, |
| 170 'bad_nested_config': { |
| 171 'mixins': ['chrome_with_codecs'], |
| 172 }, |
| 173 'rel': { |
| 174 'gn_args': 'is_debug=false', |
| 175 }, |
| 176 }, |
| 177 'private_configs': ['private'], |
| 178 'unsupported_configs': ['unsupported'], |
| 179 } |
| 180 """ |
| 181 |
| 182 |
| 183 TEST_BAD_CONFIG_ERR = """\ |
| 184 mb config file /fake_src/tools/mb/mb_config.pyl has problems: |
| 185 Config "gn_rel_bot_1" used by a bot is also listed in "common_dev_configs". |
| 186 Unknown config "unsupported" referenced from "unsupported_configs". |
| 187 Unknown config "private" referenced from "private_configs". |
| 188 Public artifact builder "a" can not contain the "chrome_with_codecs" mixin. |
| 189 Public artifact builder "b" can not contain the "chrome_with_codecs" mixin.""" |
| 190 |
| 191 |
151 class UnitTest(unittest.TestCase): | 192 class UnitTest(unittest.TestCase): |
152 def fake_mbw(self, files=None, win32=False): | 193 def fake_mbw(self, files=None, win32=False): |
153 mbw = FakeMBW(win32=win32) | 194 mbw = FakeMBW(win32=win32) |
154 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) | 195 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) |
155 if files: | 196 if files: |
156 for path, contents in files.items(): | 197 for path, contents in files.items(): |
157 mbw.files[path] = contents | 198 mbw.files[path] = contents |
158 return mbw | 199 return mbw |
159 | 200 |
160 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): | 201 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None, |
| 202 exception=None): |
161 if not mbw: | 203 if not mbw: |
162 mbw = self.fake_mbw(files) | 204 mbw = self.fake_mbw(files) |
163 mbw.ParseArgs(args) | 205 mbw.ParseArgs(args) |
164 actual_ret = mbw.args.func() | 206 |
165 if ret is not None: | 207 actual_ret = None |
166 self.assertEqual(actual_ret, ret) | 208 if exception is not None: |
| 209 self.assertRaisesRegexp(Exception, exception, mbw.args.func) |
| 210 else: |
| 211 actual_ret = mbw.args.func() |
| 212 |
| 213 self.assertEqual(actual_ret, ret) |
167 if out is not None: | 214 if out is not None: |
168 self.assertEqual(mbw.out, out) | 215 self.assertEqual(mbw.out, out) |
169 if err is not None: | 216 if err is not None: |
170 self.assertEqual(mbw.err, err) | 217 self.assertEqual(mbw.err, err) |
171 return mbw | 218 return mbw |
172 | 219 |
173 def test_clobber(self): | 220 def test_clobber(self): |
174 files = { | 221 files = { |
175 '/fake_src/out/Debug': None, | 222 '/fake_src/out/Debug': None, |
176 '/fake_src/out/Debug/mb_type': None, | 223 '/fake_src/out/Debug/mb_type': None, |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 "goma_dir=\"/foo\"'\n" )) | 403 "goma_dir=\"/foo\"'\n" )) |
357 | 404 |
358 def test_gyp_analyze(self): | 405 def test_gyp_analyze(self): |
359 mbw = self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release', | 406 mbw = self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release', |
360 '/tmp/in.json', '/tmp/out.json'], | 407 '/tmp/in.json', '/tmp/out.json'], |
361 ret=0) | 408 ret=0) |
362 self.assertIn('analyzer', mbw.calls[0]) | 409 self.assertIn('analyzer', mbw.calls[0]) |
363 | 410 |
364 def test_gyp_crosscompile(self): | 411 def test_gyp_crosscompile(self): |
365 mbw = self.fake_mbw() | 412 mbw = self.fake_mbw() |
366 self.check(['gen', '-c', 'private', '//out/Release'], mbw=mbw) | 413 self.check(['gen', '-c', 'private', '//out/Release'], mbw=mbw, ret=0) |
367 self.assertTrue(mbw.cross_compile) | 414 self.assertTrue(mbw.cross_compile) |
368 | 415 |
369 def test_gyp_gen(self): | 416 def test_gyp_gen(self): |
370 self.check(['gen', '-c', 'gyp_rel_bot', '-g', '/goma', '//out/Release'], | 417 self.check(['gen', '-c', 'gyp_rel_bot', '-g', '/goma', '//out/Release'], |
371 ret=0, | 418 ret=0, |
372 out=("GYP_DEFINES='goma=1 gomadir=/goma'\n" | 419 out=("GYP_DEFINES='goma=1 gomadir=/goma'\n" |
373 "python build/gyp_chromium -G output_dir=out\n")) | 420 "python build/gyp_chromium -G output_dir=out\n")) |
374 | 421 |
375 mbw = self.fake_mbw(win32=True) | 422 mbw = self.fake_mbw(win32=True) |
376 self.check(['gen', '-c', 'gyp_rel_bot', '-g', 'c:\\goma', '//out/Release'], | 423 self.check(['gen', '-c', 'gyp_rel_bot', '-g', 'c:\\goma', '//out/Release'], |
(...skipping 14 matching lines...) Expand all Loading... |
391 def test_help(self): | 438 def test_help(self): |
392 orig_stdout = sys.stdout | 439 orig_stdout = sys.stdout |
393 try: | 440 try: |
394 sys.stdout = StringIO.StringIO() | 441 sys.stdout = StringIO.StringIO() |
395 self.assertRaises(SystemExit, self.check, ['-h']) | 442 self.assertRaises(SystemExit, self.check, ['-h']) |
396 self.assertRaises(SystemExit, self.check, ['help']) | 443 self.assertRaises(SystemExit, self.check, ['help']) |
397 self.assertRaises(SystemExit, self.check, ['help', 'gen']) | 444 self.assertRaises(SystemExit, self.check, ['help', 'gen']) |
398 finally: | 445 finally: |
399 sys.stdout = orig_stdout | 446 sys.stdout = orig_stdout |
400 | 447 |
401 | |
402 def test_validate(self): | 448 def test_validate(self): |
403 self.check(['validate'], ret=0) | 449 self.check(['validate'], ret=0) |
404 | 450 |
| 451 def test_bad_validate(self): |
| 452 mbw = self.fake_mbw() |
| 453 mbw.files[mbw.default_config] = TEST_BAD_CONFIG |
| 454 self.check(['validate'], mbw=mbw, exception=TEST_BAD_CONFIG_ERR) |
| 455 |
405 | 456 |
406 if __name__ == '__main__': | 457 if __name__ == '__main__': |
407 unittest.main() | 458 unittest.main() |
OLD | NEW |