mb_test.py 21.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/python
# Copyright 2016 the V8 project authors. All rights reserved.
# Copyright 2015 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.py."""

import json
import StringIO
import os
import sys
import unittest

import mb


class FakeMBW(mb.MetaBuildWrapper):
18

19 20 21 22 23 24 25
  def __init__(self, win32=False):
    super(FakeMBW, self).__init__()

    # Override vars for test portability.
    if win32:
      self.chromium_src_dir = 'c:\\fake_src'
      self.default_config = 'c:\\fake_src\\tools\\mb\\mb_config.pyl'
26 27
      self.default_isolate_map = ('c:\\fake_src\\testing\\buildbot\\'
                                  'gn_isolate_map.pyl')
28 29 30 31 32 33
      self.platform = 'win32'
      self.executable = 'c:\\python\\python.exe'
      self.sep = '\\'
    else:
      self.chromium_src_dir = '/fake_src'
      self.default_config = '/fake_src/tools/mb/mb_config.pyl'
34
      self.default_isolate_map = '/fake_src/testing/buildbot/gn_isolate_map.pyl'
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
      self.executable = '/usr/bin/python'
      self.platform = 'linux2'
      self.sep = '/'

    self.files = {}
    self.calls = []
    self.cmds = []
    self.cross_compile = None
    self.out = ''
    self.err = ''
    self.rmdirs = []

  def ExpandUser(self, path):
    return '$HOME/%s' % path

  def Exists(self, path):
    return self.files.get(path) is not None

  def MaybeMakeDirectory(self, path):
    self.files[path] = True

  def PathJoin(self, *comps):
    return self.sep.join(comps)

  def ReadFile(self, path):
    return self.files[path]

  def WriteFile(self, path, contents, force_verbose=False):
    if self.args.dryrun or self.args.verbose or force_verbose:
      self.Print('\nWriting """\\\n%s""" to %s.\n' % (contents, path))
    self.files[path] = contents

  def Call(self, cmd, env=None, buffer_output=True):
    self.calls.append(cmd)
    if self.cmds:
      return self.cmds.pop(0)
    return 0, '', ''

  def Print(self, *args, **kwargs):
    sep = kwargs.get('sep', ' ')
    end = kwargs.get('end', '\n')
    f = kwargs.get('file', sys.stdout)
    if f == sys.stderr:
      self.err += sep.join(args) + end
    else:
      self.out += sep.join(args) + end

  def TempFile(self, mode='w'):
    return FakeFile(self.files)

  def RemoveFile(self, path):
    del self.files[path]

  def RemoveDirectory(self, path):
    self.rmdirs.append(path)
    files_to_delete = [f for f in self.files if f.startswith(path)]
    for f in files_to_delete:
      self.files[f] = None


class FakeFile(object):
96

97 98 99 100 101 102 103 104 105
  def __init__(self, files):
    self.name = '/tmp/file'
    self.buf = ''
    self.files = files

  def write(self, contents):
    self.buf += contents

  def close(self):
106
    self.files[self.name] = self.buf
107 108 109 110


TEST_CONFIG = """\
{
111
  'builder_groups': {
112
    'chromium': {},
113
    'fake_builder_group': {
114 115
      'fake_builder': 'rel_bot',
      'fake_debug_builder': 'debug_goma',
116
      'fake_args_bot': '//build/args/bots/fake_builder_group/fake_args_bot.gn',
117
      'fake_multi_phase': { 'phase_1': 'phase_1', 'phase_2': 'phase_2'},
118 119
      'fake_args_file': 'args_file_goma',
      'fake_args_file_twice': 'args_file_twice',
120 121 122
    },
  },
  'configs': {
123 124
    'args_file_goma': ['args_file', 'goma'],
    'args_file_twice': ['args_file', 'args_file'],
125 126 127 128
    'rel_bot': ['rel', 'goma', 'fake_feature1'],
    'debug_goma': ['debug', 'goma'],
    'phase_1': ['phase_1'],
    'phase_2': ['phase_2'],
129 130 131 132 133 134 135 136
  },
  'mixins': {
    'fake_feature1': {
      'gn_args': 'enable_doom_melon=true',
    },
    'goma': {
      'gn_args': 'use_goma=true',
    },
137 138 139
    'args_file': {
      'args_file': '//build/args/fake.gn',
    },
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    'phase_1': {
      'gn_args': 'phase=1',
    },
    'phase_2': {
      'gn_args': 'phase=2',
    },
    'rel': {
      'gn_args': 'is_debug=false',
    },
    'debug': {
      'gn_args': 'is_debug=true',
    },
  },
}
"""

156 157
TRYSERVER_CONFIG = """\
{
158
  'builder_groups': {
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    'not_a_tryserver': {
      'fake_builder': 'fake_config',
    },
    'tryserver.chromium.linux': {
      'try_builder': 'fake_config',
    },
    'tryserver.chromium.mac': {
      'try_builder2': 'fake_config',
    },
  },
  'luci_tryservers': {
    'luci_tryserver1': ['luci_builder1'],
    'luci_tryserver2': ['luci_builder2'],
  },
  'configs': {},
  'mixins': {},
}
"""

178 179

class UnitTest(unittest.TestCase):
180

181 182 183
  def fake_mbw(self, files=None, win32=False):
    mbw = FakeMBW(win32=win32)
    mbw.files.setdefault(mbw.default_config, TEST_CONFIG)
184
    mbw.files.setdefault(
185
        mbw.ToAbsPath('//testing/buildbot/gn_isolate_map.pyl'), '''{
186 187 188 189 190 191
        "foo_unittests": {
          "label": "//foo:foo_unittests",
          "type": "console_test_launcher",
          "args": [],
        },
      }''')
192
    mbw.files.setdefault(
193
        mbw.ToAbsPath('//build/args/bots/fake_builder_group/fake_args_bot.gn'),
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
        'is_debug = false\n')
    if files:
      for path, contents in files.items():
        mbw.files[path] = contents
    return mbw

  def check(self, args, mbw=None, files=None, out=None, err=None, ret=None):
    if not mbw:
      mbw = self.fake_mbw(files)

    actual_ret = mbw.Main(args)

    self.assertEqual(actual_ret, ret)
    if out is not None:
      self.assertEqual(mbw.out, out)
    if err is not None:
      self.assertEqual(mbw.err, err)
    return mbw

213
  def test_analyze(self):
214 215 216
    files = {
        '/tmp/in.json':
            '''{\
217
               "files": ["foo/foo_unittest.cc"],
218 219 220
               "test_targets": ["foo_unittests"],
               "additional_compile_targets": ["all"]
             }''',
221 222
        '/tmp/out.json.gn':
            '''{\
223 224 225
               "status": "Found dependency",
               "compile_targets": ["//foo:foo_unittests"],
               "test_targets": ["//foo:foo_unittests"]
226 227
             }'''
    }
228 229

    mbw = self.fake_mbw(files)
230
    mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '')
231

232 233 234 235 236 237
    self.check([
        'analyze', '-c', 'debug_goma', '//out/Default', '/tmp/in.json',
        '/tmp/out.json'
    ],
               mbw=mbw,
               ret=0)
238
    out = json.loads(mbw.files['/tmp/out.json'])
239 240 241 242 243 244
    self.assertEqual(
        out, {
            'status': 'Found dependency',
            'compile_targets': ['foo:foo_unittests'],
            'test_targets': ['foo_unittests']
        })
245

246
  def test_analyze_optimizes_compile_for_all(self):
247 248 249
    files = {
        '/tmp/in.json':
            '''{\
250
               "files": ["foo/foo_unittest.cc"],
251 252 253
               "test_targets": ["foo_unittests"],
               "additional_compile_targets": ["all"]
             }''',
254 255
        '/tmp/out.json.gn':
            '''{\
256 257 258
               "status": "Found dependency",
               "compile_targets": ["//foo:foo_unittests", "all"],
               "test_targets": ["//foo:foo_unittests"]
259 260
             }'''
    }
261 262

    mbw = self.fake_mbw(files)
263
    mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '')
264

265 266 267 268 269 270
    self.check([
        'analyze', '-c', 'debug_goma', '//out/Default', '/tmp/in.json',
        '/tmp/out.json'
    ],
               mbw=mbw,
               ret=0)
271
    out = json.loads(mbw.files['/tmp/out.json'])
272

273 274 275 276
    # check that 'foo_unittests' is not in the compile_targets
    self.assertEqual(['all'], out['compile_targets'])

  def test_analyze_handles_other_toolchains(self):
277 278 279
    files = {
        '/tmp/in.json':
            '''{\
280
               "files": ["foo/foo_unittest.cc"],
281
               "test_targets": ["foo_unittests"],
282
               "additional_compile_targets": ["all"]
283
             }''',
284 285
        '/tmp/out.json.gn':
            '''{\
286 287 288 289
               "status": "Found dependency",
               "compile_targets": ["//foo:foo_unittests",
                                   "//foo:foo_unittests(bar)"],
               "test_targets": ["//foo:foo_unittests"]
290 291
             }'''
    }
292

293
    mbw = self.fake_mbw(files)
294 295
    mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '')

296 297 298 299 300 301
    self.check([
        'analyze', '-c', 'debug_goma', '//out/Default', '/tmp/in.json',
        '/tmp/out.json'
    ],
               mbw=mbw,
               ret=0)
302 303
    out = json.loads(mbw.files['/tmp/out.json'])

304 305 306 307 308 309 310 311
    # crbug.com/736215: If GN returns a label containing a toolchain,
    # MB (and Ninja) don't know how to handle it; to work around this,
    # we give up and just build everything we were asked to build. The
    # output compile_targets should include all of the input test_targets and
    # additional_compile_targets.
    self.assertEqual(['all', 'foo_unittests'], out['compile_targets'])

  def test_analyze_handles_way_too_many_results(self):
312
    too_many_files = ', '.join(['"//foo:foo%d"' % i for i in range(4 * 1024)])
313 314 315
    files = {
        '/tmp/in.json':
            '''{\
316
               "files": ["foo/foo_unittest.cc"],
317 318 319
               "test_targets": ["foo_unittests"],
               "additional_compile_targets": ["all"]
             }''',
320 321
        '/tmp/out.json.gn':
            '''{\
322 323 324
               "status": "Found dependency",
               "compile_targets": [''' + too_many_files + '''],
               "test_targets": ["//foo:foo_unittests"]
325 326
             }'''
    }
327

328
    mbw = self.fake_mbw(files)
329
    mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '')
330

331 332 333 334 335 336
    self.check([
        'analyze', '-c', 'debug_goma', '//out/Default', '/tmp/in.json',
        '/tmp/out.json'
    ],
               mbw=mbw,
               ret=0)
337
    out = json.loads(mbw.files['/tmp/out.json'])
338 339 340 341 342 343

    # If GN returns so many compile targets that we might have command-line
    # issues, we should give up and just build everything we were asked to
    # build. The output compile_targets should include all of the input
    # test_targets and additional_compile_targets.
    self.assertEqual(['all', 'foo_unittests'], out['compile_targets'])
344

345
  def test_gen(self):
346
    mbw = self.fake_mbw()
347
    self.check(['gen', '-c', 'debug_goma', '//out/Default', '-g', '/goma'],
348 349
               mbw=mbw,
               ret=0)
350 351 352 353 354 355 356 357 358 359 360
    self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'],
                              ('goma_dir = "/goma"\n'
                               'is_debug = true\n'
                               'use_goma = true\n'))

    # Make sure we log both what is written to args.gn and the command line.
    self.assertIn('Writing """', mbw.out)
    self.assertIn('/fake_src/buildtools/linux64/gn gen //out/Default --check',
                  mbw.out)

    mbw = self.fake_mbw(win32=True)
361
    self.check(['gen', '-c', 'debug_goma', '-g', 'c:\\goma', '//out/Debug'],
362 363
               mbw=mbw,
               ret=0)
364 365 366 367
    self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'],
                              ('goma_dir = "c:\\\\goma"\n'
                               'is_debug = true\n'
                               'use_goma = true\n'))
368 369 370
    self.assertIn(
        'c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug '
        '--check\n', mbw.out)
371 372

    mbw = self.fake_mbw()
373 374 375 376 377
    self.check([
        'gen', '-m', 'fake_builder_group', '-b', 'fake_args_bot', '//out/Debug'
    ],
               mbw=mbw,
               ret=0)
378 379 380 381
    # TODO(almuthanna): disable test temporarily to
    #   solve this issue https://crbug.com/v8/11102
    # self.assertEqual(
    #     mbw.files['/fake_src/out/Debug/args.gn'],
382
    #     'import("//build/args/bots/fake_builder_group/fake_args_bot.gn")\n')
383

384
  def test_gen_args_file_mixins(self):
385
    mbw = self.fake_mbw()
386 387 388 389 390
    self.check([
        'gen', '-m', 'fake_builder_group', '-b', 'fake_args_file', '//out/Debug'
    ],
               mbw=mbw,
               ret=0)
391

392 393 394
    self.assertEqual(mbw.files['/fake_src/out/Debug/args.gn'],
                     ('import("//build/args/fake.gn")\n'
                      'use_goma = true\n'))
395 396

    mbw = self.fake_mbw()
397 398 399 400 401 402
    self.check([
        'gen', '-m', 'fake_builder_group', '-b', 'fake_args_file_twice',
        '//out/Debug'
    ],
               mbw=mbw,
               ret=1)
403

404
  def test_gen_fails(self):
405 406
    mbw = self.fake_mbw()
    mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '')
407
    self.check(['gen', '-c', 'debug_goma', '//out/Default'], mbw=mbw, ret=1)
408

409
  def test_gen_swarming(self):
410
    files = {
411 412 413 414 415 416 417 418 419 420
        '/tmp/swarming_targets':
            'base_unittests\n',
        '/fake_src/testing/buildbot/gn_isolate_map.pyl':
            ("{'base_unittests': {"
             "  'label': '//base:base_unittests',"
             "  'type': 'raw',"
             "  'args': [],"
             "}}\n"),
        '/fake_src/out/Default/base_unittests.runtime_deps':
            ("base_unittests\n"),
421 422
    }
    mbw = self.fake_mbw(files)
423 424 425 426 427 428 429
    self.check([
        'gen', '-c', 'debug_goma', '--swarming-targets-file',
        '/tmp/swarming_targets', '//out/Default'
    ],
               mbw=mbw,
               ret=0)
    self.assertIn('/fake_src/out/Default/base_unittests.isolate', mbw.files)
430 431 432
    self.assertIn('/fake_src/out/Default/base_unittests.isolated.gen.json',
                  mbw.files)

433
  def test_gen_swarming_script(self):
434
    files = {
435 436 437 438 439 440 441 442 443 444 445
        '/tmp/swarming_targets':
            'cc_perftests\n',
        '/fake_src/testing/buildbot/gn_isolate_map.pyl':
            ("{'cc_perftests': {"
             "  'label': '//cc:cc_perftests',"
             "  'type': 'script',"
             "  'script': '/fake_src/out/Default/test_script.py',"
             "  'args': [],"
             "}}\n"),
        'c:\\fake_src\out\Default\cc_perftests.exe.runtime_deps':
            ("cc_perftests\n"),
446 447
    }
    mbw = self.fake_mbw(files=files, win32=True)
448 449 450 451 452 453 454 455
    self.check([
        'gen', '-c', 'debug_goma', '--swarming-targets-file',
        '/tmp/swarming_targets', '--isolate-map-file',
        '/fake_src/testing/buildbot/gn_isolate_map.pyl', '//out/Default'
    ],
               mbw=mbw,
               ret=0)
    self.assertIn('c:\\fake_src\\out\\Default\\cc_perftests.isolate', mbw.files)
456 457 458
    self.assertIn('c:\\fake_src\\out\\Default\\cc_perftests.isolated.gen.json',
                  mbw.files)

459 460
  def test_multiple_isolate_maps(self):
    files = {
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
        '/tmp/swarming_targets':
            'cc_perftests\n',
        '/fake_src/testing/buildbot/gn_isolate_map.pyl':
            ("{'cc_perftests': {"
             "  'label': '//cc:cc_perftests',"
             "  'type': 'raw',"
             "  'args': [],"
             "}}\n"),
        '/fake_src/testing/buildbot/gn_isolate_map2.pyl':
            ("{'cc_perftests2': {"
             "  'label': '//cc:cc_perftests',"
             "  'type': 'raw',"
             "  'args': [],"
             "}}\n"),
        'c:\\fake_src\out\Default\cc_perftests.exe.runtime_deps':
            ("cc_perftests\n"),
477 478
    }
    mbw = self.fake_mbw(files=files, win32=True)
479 480 481 482 483 484 485 486 487
    self.check([
        'gen', '-c', 'debug_goma', '--swarming-targets-file',
        '/tmp/swarming_targets', '--isolate-map-file',
        '/fake_src/testing/buildbot/gn_isolate_map.pyl', '--isolate-map-file',
        '/fake_src/testing/buildbot/gn_isolate_map2.pyl', '//out/Default'
    ],
               mbw=mbw,
               ret=0)
    self.assertIn('c:\\fake_src\\out\\Default\\cc_perftests.isolate', mbw.files)
488 489 490 491 492
    self.assertIn('c:\\fake_src\\out\\Default\\cc_perftests.isolated.gen.json',
                  mbw.files)

  def test_duplicate_isolate_maps(self):
    files = {
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
        '/tmp/swarming_targets':
            'cc_perftests\n',
        '/fake_src/testing/buildbot/gn_isolate_map.pyl':
            ("{'cc_perftests': {"
             "  'label': '//cc:cc_perftests',"
             "  'type': 'raw',"
             "  'args': [],"
             "}}\n"),
        '/fake_src/testing/buildbot/gn_isolate_map2.pyl':
            ("{'cc_perftests': {"
             "  'label': '//cc:cc_perftests',"
             "  'type': 'raw',"
             "  'args': [],"
             "}}\n"),
        'c:\\fake_src\out\Default\cc_perftests.exe.runtime_deps':
            ("cc_perftests\n"),
509 510 511
    }
    mbw = self.fake_mbw(files=files, win32=True)
    # Check that passing duplicate targets into mb fails.
512 513 514 515 516 517 518 519
    self.check([
        'gen', '-c', 'debug_goma', '--swarming-targets-file',
        '/tmp/swarming_targets', '--isolate-map-file',
        '/fake_src/testing/buildbot/gn_isolate_map.pyl', '--isolate-map-file',
        '/fake_src/testing/buildbot/gn_isolate_map2.pyl', '//out/Default'
    ],
               mbw=mbw,
               ret=1)
520 521

  def test_isolate(self):
522
    files = {
523 524 525 526 527 528 529 530 531 532
        '/fake_src/out/Default/toolchain.ninja':
            "",
        '/fake_src/testing/buildbot/gn_isolate_map.pyl':
            ("{'base_unittests': {"
             "  'label': '//base:base_unittests',"
             "  'type': 'raw',"
             "  'args': [],"
             "}}\n"),
        '/fake_src/out/Default/base_unittests.runtime_deps':
            ("base_unittests\n"),
533
    }
534 535 536 537
    self.check(
        ['isolate', '-c', 'debug_goma', '//out/Default', 'base_unittests'],
        files=files,
        ret=0)
538 539 540 541

    # test running isolate on an existing build_dir
    files['/fake_src/out/Default/args.gn'] = 'is_debug = True\n'
    self.check(['isolate', '//out/Default', 'base_unittests'],
542 543
               files=files,
               ret=0)
544 545

    self.check(['isolate', '//out/Default', 'base_unittests'],
546 547
               files=files,
               ret=0)
548

549
  def test_run(self):
550
    files = {
551 552 553 554 555 556 557 558
        '/fake_src/testing/buildbot/gn_isolate_map.pyl':
            ("{'base_unittests': {"
             "  'label': '//base:base_unittests',"
             "  'type': 'raw',"
             "  'args': [],"
             "}}\n"),
        '/fake_src/out/Default/base_unittests.runtime_deps':
            ("base_unittests\n"),
559
    }
560 561 562
    self.check(['run', '-c', 'debug_goma', '//out/Default', 'base_unittests'],
               files=files,
               ret=0)
563

564
  def test_lookup(self):
565 566
    self.check(['lookup', '-c', 'debug_goma'],
               ret=0,
567 568 569 570 571 572 573 574
               out=('\n'
                    'Writing """\\\n'
                    'is_debug = true\n'
                    'use_goma = true\n'
                    '""" to _path_/args.gn.\n\n'
                    '/fake_src/buildtools/linux64/gn gen _path_\n'))

  def test_quiet_lookup(self):
575 576
    self.check(['lookup', '-c', 'debug_goma', '--quiet'],
               ret=0,
577 578
               out=('is_debug = true\n'
                    'use_goma = true\n'))
579 580

  def test_lookup_goma_dir_expansion(self):
581 582
    self.check(['lookup', '-c', 'rel_bot', '-g', '/foo'],
               ret=0,
583 584
               out=('\n'
                    'Writing """\\\n'
585
                    'enable_doom_melon = true\n'
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
                    'goma_dir = "/foo"\n'
                    'is_debug = false\n'
                    'use_goma = true\n'
                    '""" to _path_/args.gn.\n\n'
                    '/fake_src/buildtools/linux64/gn gen _path_\n'))

  def test_help(self):
    orig_stdout = sys.stdout
    try:
      sys.stdout = StringIO.StringIO()
      self.assertRaises(SystemExit, self.check, ['-h'])
      self.assertRaises(SystemExit, self.check, ['help'])
      self.assertRaises(SystemExit, self.check, ['help', 'gen'])
    finally:
      sys.stdout = orig_stdout

  def test_multiple_phases(self):
    # Check that not passing a --phase to a multi-phase builder fails.
604 605
    mbw = self.check(
        ['lookup', '-m', 'fake_builder_group', '-b', 'fake_multi_phase'], ret=1)
606 607 608
    self.assertIn('Must specify a build --phase', mbw.out)

    # Check that passing a --phase to a single-phase builder fails.
609 610 611 612 613
    mbw = self.check([
        'lookup', '-m', 'fake_builder_group', '-b', 'fake_builder', '--phase',
        'phase_1'
    ],
                     ret=1)
614 615
    self.assertIn('Must not specify a build --phase', mbw.out)

616
    # Check that passing a wrong phase key to a multi-phase builder fails.
617 618 619 620 621
    mbw = self.check([
        'lookup', '-m', 'fake_builder_group', '-b', 'fake_multi_phase',
        '--phase', 'wrong_phase'
    ],
                     ret=1)
622
    self.assertIn('Phase wrong_phase doesn\'t exist', mbw.out)
623

624
    # Check that passing a correct phase key to a multi-phase builder passes.
625 626 627 628 629
    mbw = self.check([
        'lookup', '-m', 'fake_builder_group', '-b', 'fake_multi_phase',
        '--phase', 'phase_1'
    ],
                     ret=0)
630 631
    self.assertIn('phase = 1', mbw.out)

632 633 634 635 636
    mbw = self.check([
        'lookup', '-m', 'fake_builder_group', '-b', 'fake_multi_phase',
        '--phase', 'phase_2'
    ],
                     ret=0)
637 638
    self.assertIn('phase = 2', mbw.out)

639 640
  def test_recursive_lookup(self):
    files = {
641 642
        '/fake_src/build/args/fake.gn': ('enable_doom_melon = true\n'
                                         'enable_antidoom_banana = true\n')
643
    }
644 645 646 647 648 649
    self.check([
        'lookup', '-m', 'fake_builder_group', '-b', 'fake_args_file',
        '--recursive'
    ],
               files=files,
               ret=0,
650 651 652 653
               out=('enable_antidoom_banana = true\n'
                    'enable_doom_melon = true\n'
                    'use_goma = true\n'))

654 655 656 657
  def test_validate(self):
    mbw = self.fake_mbw()
    self.check(['validate'], mbw=mbw, ret=0)

658
  def test_buildbucket(self):
659
    mbw = self.fake_mbw()
660
    mbw.files[mbw.default_config] = TRYSERVER_CONFIG
661 662
    self.check(['gerrit-buildbucket-config'],
               mbw=mbw,
663
               ret=0,
664 665 666 667 668 669
               out=('# This file was generated using '
                    '"tools/mb/mb.py gerrit-buildbucket-config".\n'
                    '[bucket "luci.luci_tryserver1"]\n'
                    '\tbuilder = luci_builder1\n'
                    '[bucket "luci.luci_tryserver2"]\n'
                    '\tbuilder = luci_builder2\n'
670
                    '[bucket "builder_group.tryserver.chromium.linux"]\n'
671
                    '\tbuilder = try_builder\n'
672
                    '[bucket "builder_group.tryserver.chromium.mac"]\n'
673
                    '\tbuilder = try_builder2\n'))
674 675 676 677


if __name__ == '__main__':
  unittest.main()