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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 'gyp_crosscompile': ['gyp', 'crosscompile'], | 111 'gyp_crosscompile': ['gyp', 'crosscompile'], |
112 }, | 112 }, |
113 'masters': { | 113 'masters': { |
114 'chromium': {}, | 114 'chromium': {}, |
115 'fake_master': { | 115 'fake_master': { |
116 'fake_builder': 'gyp_rel_bot', | 116 'fake_builder': 'gyp_rel_bot', |
117 'fake_gn_builder': 'gn_rel_bot', | 117 'fake_gn_builder': 'gn_rel_bot', |
118 'fake_gyp_crosscompile_builder': 'gyp_crosscompile', | 118 'fake_gyp_crosscompile_builder': 'gyp_crosscompile', |
119 'fake_gn_debug_builder': 'gn_debug_goma', | 119 'fake_gn_debug_builder': 'gn_debug_goma', |
120 'fake_gyp_builder': 'gyp_debug', | 120 'fake_gyp_builder': 'gyp_debug', |
| 121 'fake_gn_args_bot': '//build/args/bots/fake_master/fake_gn_args_bot.gn', |
121 }, | 122 }, |
122 }, | 123 }, |
123 'mixins': { | 124 'mixins': { |
124 'crosscompile': { | 125 'crosscompile': { |
125 'gyp_crosscompile': True, | 126 'gyp_crosscompile': True, |
126 }, | 127 }, |
127 'fake_feature1': { | 128 'fake_feature1': { |
128 'gn_args': 'enable_doom_melon=true', | 129 'gn_args': 'enable_doom_melon=true', |
129 'gyp_defines': 'doom_melon=1', | 130 'gyp_defines': 'doom_melon=1', |
130 }, | 131 }, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 'gn_args': 'is_debug=false', | 170 'gn_args': 'is_debug=false', |
170 }, | 171 }, |
171 }, | 172 }, |
172 } | 173 } |
173 """ | 174 """ |
174 | 175 |
175 class UnitTest(unittest.TestCase): | 176 class UnitTest(unittest.TestCase): |
176 def fake_mbw(self, files=None, win32=False): | 177 def fake_mbw(self, files=None, win32=False): |
177 mbw = FakeMBW(win32=win32) | 178 mbw = FakeMBW(win32=win32) |
178 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) | 179 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) |
| 180 mbw.files.setdefault( |
| 181 mbw.ToAbsPath('//build/args/bots/fake_master/fake_gn_args_bot.gn'), |
| 182 'is_debug = false\n') |
179 if files: | 183 if files: |
180 for path, contents in files.items(): | 184 for path, contents in files.items(): |
181 mbw.files[path] = contents | 185 mbw.files[path] = contents |
182 return mbw | 186 return mbw |
183 | 187 |
184 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): | 188 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): |
185 if not mbw: | 189 if not mbw: |
186 mbw = self.fake_mbw(files) | 190 mbw = self.fake_mbw(files) |
187 | 191 |
188 actual_ret = mbw.Main(args) | 192 actual_ret = mbw.Main(args) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 mbw = self.fake_mbw(win32=True) | 316 mbw = self.fake_mbw(win32=True) |
313 self.check(['gen', '-c', 'gn_debug_goma', '-g', 'c:\\goma', '//out/Debug'], | 317 self.check(['gen', '-c', 'gn_debug_goma', '-g', 'c:\\goma', '//out/Debug'], |
314 mbw=mbw, ret=0, | 318 mbw=mbw, ret=0, |
315 out=('c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug ' | 319 out=('c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug ' |
316 '--check\n')) | 320 '--check\n')) |
317 self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'], | 321 self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'], |
318 ('goma_dir = "c:\\\\goma"\n' | 322 ('goma_dir = "c:\\\\goma"\n' |
319 'is_debug = true\n' | 323 'is_debug = true\n' |
320 'use_goma = true\n')) | 324 'use_goma = true\n')) |
321 | 325 |
| 326 mbw = self.fake_mbw() |
| 327 self.check(['gen', '-m', 'fake_master', '-b', 'fake_gn_args_bot', |
| 328 '//out/Debug'], |
| 329 mbw=mbw, ret=0) |
| 330 self.assertEqual( |
| 331 mbw.files['/fake_src/out/Debug/args.gn'], |
| 332 'import("//build/args/bots/fake_master/fake_gn_args_bot.gn")\n') |
| 333 |
322 | 334 |
323 def test_gn_gen_fails(self): | 335 def test_gn_gen_fails(self): |
324 mbw = self.fake_mbw() | 336 mbw = self.fake_mbw() |
325 mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '') | 337 mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '') |
326 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default'], mbw=mbw, ret=1) | 338 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default'], mbw=mbw, ret=1) |
327 | 339 |
328 def test_gn_gen_swarming(self): | 340 def test_gn_gen_swarming(self): |
329 files = { | 341 files = { |
330 '/tmp/swarming_targets': 'base_unittests\n', | 342 '/tmp/swarming_targets': 'base_unittests\n', |
331 '/fake_src/testing/buildbot/gn_isolate_map.pyl': ( | 343 '/fake_src/testing/buildbot/gn_isolate_map.pyl': ( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 try: | 453 try: |
442 sys.stdout = StringIO.StringIO() | 454 sys.stdout = StringIO.StringIO() |
443 self.assertRaises(SystemExit, self.check, ['-h']) | 455 self.assertRaises(SystemExit, self.check, ['-h']) |
444 self.assertRaises(SystemExit, self.check, ['help']) | 456 self.assertRaises(SystemExit, self.check, ['help']) |
445 self.assertRaises(SystemExit, self.check, ['help', 'gen']) | 457 self.assertRaises(SystemExit, self.check, ['help', 'gen']) |
446 finally: | 458 finally: |
447 sys.stdout = orig_stdout | 459 sys.stdout = orig_stdout |
448 | 460 |
449 def test_validate(self): | 461 def test_validate(self): |
450 mbw = self.fake_mbw() | 462 mbw = self.fake_mbw() |
451 mbw.files[mbw.default_config] = TEST_CONFIG | |
452 self.check(['validate'], mbw=mbw, ret=0) | 463 self.check(['validate'], mbw=mbw, ret=0) |
453 | 464 |
454 def test_bad_validate(self): | 465 def test_bad_validate(self): |
455 mbw = self.fake_mbw() | 466 mbw = self.fake_mbw() |
456 mbw.files[mbw.default_config] = TEST_BAD_CONFIG | 467 mbw.files[mbw.default_config] = TEST_BAD_CONFIG |
457 self.check(['validate'], mbw=mbw, ret=1) | 468 self.check(['validate'], mbw=mbw, ret=1) |
458 | 469 |
459 | 470 |
460 if __name__ == '__main__': | 471 if __name__ == '__main__': |
461 unittest.main() | 472 unittest.main() |
OLD | NEW |