| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 }, | 209 }, |
| 210 } | 210 } |
| 211 """ | 211 """ |
| 212 | 212 |
| 213 | 213 |
| 214 class UnitTest(unittest.TestCase): | 214 class UnitTest(unittest.TestCase): |
| 215 def fake_mbw(self, files=None, win32=False): | 215 def fake_mbw(self, files=None, win32=False): |
| 216 mbw = FakeMBW(win32=win32) | 216 mbw = FakeMBW(win32=win32) |
| 217 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) | 217 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) |
| 218 mbw.files.setdefault( | 218 mbw.files.setdefault( |
| 219 mbw.ToAbsPath('//testing/buildbot/gn_isolate_map.pyl'), | |
| 220 '''{ | |
| 221 "foo_unittests": { | |
| 222 "label": "//foo:foo_unittests", | |
| 223 "type": "console_test_launcher", | |
| 224 "args": [], | |
| 225 }, | |
| 226 }''') | |
| 227 mbw.files.setdefault( | |
| 228 mbw.ToAbsPath('//build/args/bots/fake_master/fake_gn_args_bot.gn'), | 219 mbw.ToAbsPath('//build/args/bots/fake_master/fake_gn_args_bot.gn'), |
| 229 'is_debug = false\n') | 220 'is_debug = false\n') |
| 230 if files: | 221 if files: |
| 231 for path, contents in files.items(): | 222 for path, contents in files.items(): |
| 232 mbw.files[path] = contents | 223 mbw.files[path] = contents |
| 233 return mbw | 224 return mbw |
| 234 | 225 |
| 235 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): | 226 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): |
| 236 if not mbw: | 227 if not mbw: |
| 237 mbw = self.fake_mbw(files) | 228 mbw = self.fake_mbw(files) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 261 |
| 271 # Now we delete mb_type; this checks the case where the build dir | 262 # Now we delete mb_type; this checks the case where the build dir |
| 272 # exists but wasn't populated by mb; this should also result in a clobber. | 263 # exists but wasn't populated by mb; this should also result in a clobber. |
| 273 del mbw.files['/fake_src/out/Debug/mb_type'] | 264 del mbw.files['/fake_src/out/Debug/mb_type'] |
| 274 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0) | 265 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0) |
| 275 self.assertEqual(mbw.rmdirs, | 266 self.assertEqual(mbw.rmdirs, |
| 276 ['/fake_src/out/Debug', '/fake_src/out/Debug']) | 267 ['/fake_src/out/Debug', '/fake_src/out/Debug']) |
| 277 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp') | 268 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp') |
| 278 | 269 |
| 279 def test_gn_analyze(self): | 270 def test_gn_analyze(self): |
| 280 files = {'/tmp/in.json': '''{\ | 271 files = {'/tmp/in.json': """{\ |
| 281 "files": ["foo/foo_unittest.cc"], | 272 "files": ["foo/foo_unittest.cc"], |
| 282 "test_targets": ["foo_unittests"], | 273 "test_targets": ["foo_unittests", "bar_unittests"], |
| 283 "additional_compile_targets": ["all"] | 274 "additional_compile_targets": [] |
| 284 }''', | 275 }"""} |
| 285 '/tmp/out.json.gn': '''{\ | |
| 286 "status": "Found dependency", | |
| 287 "compile_targets": ["//foo:foo_unittests"], | |
| 288 "test_targets": ["//foo:foo_unittests"] | |
| 289 }'''} | |
| 290 | 276 |
| 291 mbw = self.fake_mbw(files) | 277 mbw = self.fake_mbw(files) |
| 292 mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '') | 278 mbw.Call = lambda cmd, env=None, buffer_output=True: ( |
| 279 0, 'out/Default/foo_unittests\n', '') |
| 293 | 280 |
| 294 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default', | 281 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default', |
| 295 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) | 282 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) |
| 296 out = json.loads(mbw.files['/tmp/out.json']) | 283 out = json.loads(mbw.files['/tmp/out.json']) |
| 297 self.assertEqual(out, { | 284 self.assertEqual(out, { |
| 298 'status': 'Found dependency', | 285 'status': 'Found dependency', |
| 299 'compile_targets': ['foo:foo_unittests'], | 286 'compile_targets': ['foo_unittests'], |
| 300 'test_targets': ['foo_unittests'] | 287 'test_targets': ['foo_unittests'] |
| 301 }) | 288 }) |
| 302 | 289 |
| 290 def test_gn_analyze_fails(self): |
| 291 files = {'/tmp/in.json': """{\ |
| 292 "files": ["foo/foo_unittest.cc"], |
| 293 "test_targets": ["foo_unittests", "bar_unittests"], |
| 294 "additional_compile_targets": [] |
| 295 }"""} |
| 296 |
| 297 mbw = self.fake_mbw(files) |
| 298 mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '') |
| 299 |
| 300 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default', |
| 301 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=1) |
| 302 |
| 303 def test_gn_analyze_all(self): |
| 304 files = {'/tmp/in.json': """{\ |
| 305 "files": ["foo/foo_unittest.cc"], |
| 306 "test_targets": ["bar_unittests"], |
| 307 "additional_compile_targets": ["all"] |
| 308 }"""} |
| 309 mbw = self.fake_mbw(files) |
| 310 mbw.Call = lambda cmd, env=None, buffer_output=True: ( |
| 311 0, 'out/Default/foo_unittests\n', '') |
| 312 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default', |
| 313 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) |
| 314 out = json.loads(mbw.files['/tmp/out.json']) |
| 315 self.assertEqual(out, { |
| 316 'status': 'Found dependency (all)', |
| 317 'compile_targets': ['all', 'bar_unittests'], |
| 318 'test_targets': ['bar_unittests'], |
| 319 }) |
| 320 |
| 321 def test_gn_analyze_missing_file(self): |
| 322 files = {'/tmp/in.json': """{\ |
| 323 "files": ["foo/foo_unittest.cc"], |
| 324 "test_targets": ["bar_unittests"], |
| 325 "additional_compile_targets": [] |
| 326 }"""} |
| 327 mbw = self.fake_mbw(files) |
| 328 mbw.cmds = [ |
| 329 (0, '', ''), |
| 330 (1, 'The input matches no targets, configs, or files\n', ''), |
| 331 (1, 'The input matches no targets, configs, or files\n', ''), |
| 332 ] |
| 333 |
| 334 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default', |
| 335 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) |
| 336 out = json.loads(mbw.files['/tmp/out.json']) |
| 337 self.assertEqual(out, { |
| 338 'status': 'No dependency', |
| 339 'compile_targets': [], |
| 340 'test_targets': [], |
| 341 }) |
| 342 |
| 303 def test_gn_gen(self): | 343 def test_gn_gen(self): |
| 304 mbw = self.fake_mbw() | 344 mbw = self.fake_mbw() |
| 305 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default', '-g', '/goma'], | 345 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default', '-g', '/goma'], |
| 306 mbw=mbw, ret=0) | 346 mbw=mbw, ret=0) |
| 307 self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'], | 347 self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'], |
| 308 ('goma_dir = "/goma"\n' | 348 ('goma_dir = "/goma"\n' |
| 309 'is_debug = true\n' | 349 'is_debug = true\n' |
| 310 'use_goma = true\n')) | 350 'use_goma = true\n')) |
| 311 | 351 |
| 312 # Make sure we log both what is written to args.gn and the command line. | 352 # Make sure we log both what is written to args.gn and the command line. |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 self.check(['lookup', '-c', 'fake_config'], mbw=mbw, | 567 self.check(['lookup', '-c', 'fake_config'], mbw=mbw, |
| 528 ret=0, | 568 ret=0, |
| 529 out=("GYP_DEFINES='foo=bar baz=1'\n" | 569 out=("GYP_DEFINES='foo=bar baz=1'\n" |
| 530 "GYP_LINK_CONCURRENCY=1\n" | 570 "GYP_LINK_CONCURRENCY=1\n" |
| 531 "LLVM_FORCE_HEAD_REVISION=1\n" | 571 "LLVM_FORCE_HEAD_REVISION=1\n" |
| 532 "python build/gyp_chromium -G output_dir=_path_\n")) | 572 "python build/gyp_chromium -G output_dir=_path_\n")) |
| 533 | 573 |
| 534 | 574 |
| 535 if __name__ == '__main__': | 575 if __name__ == '__main__': |
| 536 unittest.main() | 576 unittest.main() |
| OLD | NEW |