blob: 3f9a6c9adb89339fea84bc54279f00291497d46c [file] [log] [blame]
kjellandera013a022016-11-14 05:54:22 -08001#!/usr/bin/python
2# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3#
4# Use of this source code is governed by a BSD-style license
5# that can be found in the LICENSE file in the root of the source
6# tree. An additional intellectual property rights grant can be found
7# in the file PATENTS. All contributing project authors may
8# be found in the AUTHORS file in the root of the source tree.
9
10"""Tests for mb.py."""
11
ehmaldonadoed8c8ed2016-11-23 12:58:35 -080012import ast
kjellandera013a022016-11-14 05:54:22 -080013import json
14import StringIO
15import os
16import sys
17import unittest
18
19import mb
20
21
22class FakeMBW(mb.MetaBuildWrapper):
23 def __init__(self, win32=False):
24 super(FakeMBW, self).__init__()
25
26 # Override vars for test portability.
27 if win32:
28 self.chromium_src_dir = 'c:\\fake_src'
Henrik Kjellanderb2d55772016-12-18 22:14:50 +010029 self.default_config = 'c:\\fake_src\\tools-webrtc\\mb\\mb_config.pyl'
kjellandera013a022016-11-14 05:54:22 -080030 self.default_isolate_map = ('c:\\fake_src\\testing\\buildbot\\'
31 'gn_isolate_map.pyl')
32 self.platform = 'win32'
33 self.executable = 'c:\\python\\python.exe'
34 self.sep = '\\'
35 else:
36 self.chromium_src_dir = '/fake_src'
Henrik Kjellanderb2d55772016-12-18 22:14:50 +010037 self.default_config = '/fake_src/tools-webrtc/mb/mb_config.pyl'
kjellandera013a022016-11-14 05:54:22 -080038 self.default_isolate_map = '/fake_src/testing/buildbot/gn_isolate_map.pyl'
39 self.executable = '/usr/bin/python'
40 self.platform = 'linux2'
41 self.sep = '/'
42
43 self.files = {}
44 self.calls = []
45 self.cmds = []
46 self.cross_compile = None
47 self.out = ''
48 self.err = ''
49 self.rmdirs = []
50
51 def ExpandUser(self, path):
52 return '$HOME/%s' % path
53
54 def Exists(self, path):
55 return self.files.get(path) is not None
56
57 def MaybeMakeDirectory(self, path):
58 self.files[path] = True
59
60 def PathJoin(self, *comps):
61 return self.sep.join(comps)
62
63 def ReadFile(self, path):
64 return self.files[path]
65
66 def WriteFile(self, path, contents, force_verbose=False):
67 if self.args.dryrun or self.args.verbose or force_verbose:
68 self.Print('\nWriting """\\\n%s""" to %s.\n' % (contents, path))
69 self.files[path] = contents
70
71 def Call(self, cmd, env=None, buffer_output=True):
72 if env:
73 self.cross_compile = env.get('GYP_CROSSCOMPILE')
74 self.calls.append(cmd)
75 if self.cmds:
76 return self.cmds.pop(0)
77 return 0, '', ''
78
79 def Print(self, *args, **kwargs):
80 sep = kwargs.get('sep', ' ')
81 end = kwargs.get('end', '\n')
82 f = kwargs.get('file', sys.stdout)
83 if f == sys.stderr:
84 self.err += sep.join(args) + end
85 else:
86 self.out += sep.join(args) + end
87
88 def TempFile(self, mode='w'):
89 return FakeFile(self.files)
90
91 def RemoveFile(self, path):
92 del self.files[path]
93
94 def RemoveDirectory(self, path):
95 self.rmdirs.append(path)
96 files_to_delete = [f for f in self.files if f.startswith(path)]
97 for f in files_to_delete:
98 self.files[f] = None
99
100
101class FakeFile(object):
102 def __init__(self, files):
103 self.name = '/tmp/file'
104 self.buf = ''
105 self.files = files
106
107 def write(self, contents):
108 self.buf += contents
109
110 def close(self):
111 self.files[self.name] = self.buf
112
113
114TEST_CONFIG = """\
115{
116 'masters': {
117 'chromium': {},
118 'fake_master': {
119 'fake_builder': 'gyp_rel_bot',
120 'fake_gn_builder': 'gn_rel_bot',
121 'fake_gyp_crosscompile_builder': 'gyp_crosscompile',
122 'fake_gn_debug_builder': 'gn_debug_goma',
123 'fake_gyp_builder': 'gyp_debug',
124 'fake_gn_args_bot': '//build/args/bots/fake_master/fake_gn_args_bot.gn',
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800125 'fake_memcheck_bot': 'gn_memcheck_bot',
kjellandera013a022016-11-14 05:54:22 -0800126 'fake_multi_phase': { 'phase_1': 'gn_phase_1', 'phase_2': 'gn_phase_2'},
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800127 'fake_android_bot': 'gn_android_bot',
kjellandera013a022016-11-14 05:54:22 -0800128 },
129 },
130 'configs': {
131 'gyp_rel_bot': ['gyp', 'rel', 'goma'],
132 'gn_debug_goma': ['gn', 'debug', 'goma'],
133 'gyp_debug': ['gyp', 'debug', 'fake_feature1'],
134 'gn_rel_bot': ['gn', 'rel', 'goma'],
135 'gyp_crosscompile': ['gyp', 'crosscompile'],
136 'gn_phase_1': ['gn', 'phase_1'],
137 'gn_phase_2': ['gn', 'phase_2'],
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800138 'gn_memcheck_bot': ['gn', 'memcheck'],
139 'gn_android_bot': ['gn', 'android'],
kjellandera013a022016-11-14 05:54:22 -0800140 },
141 'mixins': {
142 'crosscompile': {
143 'gyp_crosscompile': True,
144 },
145 'fake_feature1': {
146 'gn_args': 'enable_doom_melon=true',
147 'gyp_defines': 'doom_melon=1',
148 },
149 'gyp': {'type': 'gyp'},
150 'gn': {'type': 'gn'},
151 'goma': {
152 'gn_args': 'use_goma=true',
153 'gyp_defines': 'goma=1',
154 },
155 'phase_1': {
156 'gn_args': 'phase=1',
157 'gyp_args': 'phase=1',
158 },
159 'phase_2': {
160 'gn_args': 'phase=2',
161 'gyp_args': 'phase=2',
162 },
163 'rel': {
164 'gn_args': 'is_debug=false',
165 },
166 'debug': {
167 'gn_args': 'is_debug=true',
168 },
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800169 'memcheck': {
170 'gn_args': 'rtc_use_memcheck=true',
171 },
172 'android': {
173 'gn_args': 'target_os="android"',
174 }
kjellandera013a022016-11-14 05:54:22 -0800175 },
176}
177"""
178
kjellandera013a022016-11-14 05:54:22 -0800179GYP_HACKS_CONFIG = """\
180{
181 'masters': {
182 'chromium': {},
183 'fake_master': {
184 'fake_builder': 'fake_config',
185 },
186 },
187 'configs': {
188 'fake_config': ['fake_mixin'],
189 },
190 'mixins': {
191 'fake_mixin': {
192 'type': 'gyp',
193 'gn_args': '',
194 'gyp_defines':
195 ('foo=bar llvm_force_head_revision=1 '
196 'gyp_link_concurrency=1 baz=1'),
197 },
198 },
199}
200"""
201
202
203class UnitTest(unittest.TestCase):
204 def fake_mbw(self, files=None, win32=False):
205 mbw = FakeMBW(win32=win32)
206 mbw.files.setdefault(mbw.default_config, TEST_CONFIG)
207 mbw.files.setdefault(
208 mbw.ToAbsPath('//testing/buildbot/gn_isolate_map.pyl'),
209 '''{
210 "foo_unittests": {
211 "label": "//foo:foo_unittests",
212 "type": "console_test_launcher",
213 "args": [],
214 },
215 }''')
216 mbw.files.setdefault(
217 mbw.ToAbsPath('//build/args/bots/fake_master/fake_gn_args_bot.gn'),
218 'is_debug = false\n')
219 if files:
220 for path, contents in files.items():
221 mbw.files[path] = contents
222 return mbw
223
224 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None):
225 if not mbw:
226 mbw = self.fake_mbw(files)
227
228 actual_ret = mbw.Main(args)
229
230 self.assertEqual(actual_ret, ret)
231 if out is not None:
232 self.assertEqual(mbw.out, out)
233 if err is not None:
234 self.assertEqual(mbw.err, err)
235 return mbw
236
237 def test_clobber(self):
238 files = {
239 '/fake_src/out/Debug': None,
240 '/fake_src/out/Debug/mb_type': None,
241 }
242 mbw = self.fake_mbw(files)
243
244 # The first time we run this, the build dir doesn't exist, so no clobber.
245 self.check(['gen', '-c', 'gn_debug_goma', '//out/Debug'], mbw=mbw, ret=0)
246 self.assertEqual(mbw.rmdirs, [])
247 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gn')
248
249 # The second time we run this, the build dir exists and matches, so no
250 # clobber.
251 self.check(['gen', '-c', 'gn_debug_goma', '//out/Debug'], mbw=mbw, ret=0)
252 self.assertEqual(mbw.rmdirs, [])
253 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gn')
254
255 # Now we switch build types; this should result in a clobber.
256 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0)
257 self.assertEqual(mbw.rmdirs, ['/fake_src/out/Debug'])
258 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp')
259
260 # Now we delete mb_type; this checks the case where the build dir
261 # exists but wasn't populated by mb; this should also result in a clobber.
262 del mbw.files['/fake_src/out/Debug/mb_type']
263 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0)
264 self.assertEqual(mbw.rmdirs,
265 ['/fake_src/out/Debug', '/fake_src/out/Debug'])
266 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp')
267
268 def test_gn_analyze(self):
269 files = {'/tmp/in.json': '''{\
270 "files": ["foo/foo_unittest.cc"],
271 "test_targets": ["foo_unittests"],
272 "additional_compile_targets": ["all"]
273 }''',
274 '/tmp/out.json.gn': '''{\
275 "status": "Found dependency",
276 "compile_targets": ["//foo:foo_unittests"],
277 "test_targets": ["//foo:foo_unittests"]
278 }'''}
279
280 mbw = self.fake_mbw(files)
281 mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '')
282
283 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default',
284 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
285 out = json.loads(mbw.files['/tmp/out.json'])
286 self.assertEqual(out, {
287 'status': 'Found dependency',
288 'compile_targets': ['foo:foo_unittests'],
289 'test_targets': ['foo_unittests']
290 })
291
292 def test_gn_gen(self):
293 mbw = self.fake_mbw()
294 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default', '-g', '/goma'],
295 mbw=mbw, ret=0)
296 self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'],
297 ('goma_dir = "/goma"\n'
298 'is_debug = true\n'
299 'use_goma = true\n'))
300
301 # Make sure we log both what is written to args.gn and the command line.
302 self.assertIn('Writing """', mbw.out)
303 self.assertIn('/fake_src/buildtools/linux64/gn gen //out/Default --check',
304 mbw.out)
305
306 mbw = self.fake_mbw(win32=True)
307 self.check(['gen', '-c', 'gn_debug_goma', '-g', 'c:\\goma', '//out/Debug'],
308 mbw=mbw, ret=0)
309 self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'],
310 ('goma_dir = "c:\\\\goma"\n'
311 'is_debug = true\n'
312 'use_goma = true\n'))
313 self.assertIn('c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug '
314 '--check\n', mbw.out)
315
316 mbw = self.fake_mbw()
317 self.check(['gen', '-m', 'fake_master', '-b', 'fake_gn_args_bot',
318 '//out/Debug'],
319 mbw=mbw, ret=0)
320 self.assertEqual(
321 mbw.files['/fake_src/out/Debug/args.gn'],
322 'import("//build/args/bots/fake_master/fake_gn_args_bot.gn")\n')
323
324
325 def test_gn_gen_fails(self):
326 mbw = self.fake_mbw()
327 mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '')
328 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default'], mbw=mbw, ret=1)
329
330 def test_gn_gen_swarming(self):
331 files = {
kjellandera013a022016-11-14 05:54:22 -0800332 '/tmp/swarming_targets': 'cc_perftests\n',
333 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
334 "{'cc_perftests': {"
335 " 'label': '//cc:cc_perftests',"
ehmaldonadob2fcf6d2016-11-15 12:20:30 -0800336 " 'type': 'console_test_launcher',"
kjellandera013a022016-11-14 05:54:22 -0800337 "}}\n"
338 ),
339 'c:\\fake_src\out\Default\cc_perftests.exe.runtime_deps': (
340 "cc_perftests\n"
341 ),
342 }
343 mbw = self.fake_mbw(files=files, win32=True)
344 self.check(['gen',
345 '-c', 'gn_debug_goma',
346 '--swarming-targets-file', '/tmp/swarming_targets',
347 '--isolate-map-file',
348 '/fake_src/testing/buildbot/gn_isolate_map.pyl',
349 '//out/Default'], mbw=mbw, ret=0)
350 self.assertIn('c:\\fake_src\\out\\Default\\cc_perftests.isolate',
351 mbw.files)
352 self.assertIn('c:\\fake_src\\out\\Default\\cc_perftests.isolated.gen.json',
353 mbw.files)
354
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800355 def test_gn_gen_swarming_android(self):
356 test_files = {
357 '/tmp/swarming_targets': 'base_unittests\n',
358 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
359 "{'base_unittests': {"
360 " 'label': '//base:base_unittests',"
361 " 'type': 'additional_compile_target',"
362 "}}\n"
363 ),
364 '/fake_src/out/Default/base_unittests.runtime_deps': (
365 "base_unittests\n"
366 ),
367 }
368 mbw = self.check(['gen', '-c', 'gn_android_bot', '//out/Default',
369 '--swarming-targets-file', '/tmp/swarming_targets',
370 '--isolate-map-file',
371 '/fake_src/testing/buildbot/gn_isolate_map.pyl'],
372 files=test_files, ret=0)
373
374 isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
375 isolate_file_contents = ast.literal_eval(isolate_file)
376 files = isolate_file_contents['variables']['files']
377 command = isolate_file_contents['variables']['command']
378
379 self.assertEqual(files, ['base_unittests'])
380 self.assertEqual(command, [
381 './../../build/android/test_wrapper/logdog_wrapper.py',
382 '--logdog-bin-cmd', './../../bin/logdog_butler',
383 '--project', 'chromium',
384 '--service-account-json',
385 '/creds/service_accounts/service-account-luci-logdog-publisher.json',
386 '--prefix', 'android/swarming/logcats/${SWARMING_TASK_ID}',
387 '--source', '${ISOLATED_OUTDIR}/logcats',
388 '--name', 'unified_logcats',
389 'bin/run_base_unittests',
390 '--logcat-output-file', '${ISOLATED_OUTDIR}/logcats',
391 '--target-devices-file', '${SWARMING_BOT_FILE}',
392 '-v',
393 ])
394
395 def test_gn_gen_swarming_android_junit_test(self):
396 test_files = {
397 '/tmp/swarming_targets': 'base_unittests\n',
398 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
399 "{'base_unittests': {"
400 " 'label': '//base:base_unittests',"
401 " 'type': 'junit_test',"
402 "}}\n"
403 ),
404 '/fake_src/out/Default/base_unittests.runtime_deps': (
405 "base_unittests\n"
406 ),
407 }
408 mbw = self.check(['gen', '-c', 'gn_android_bot', '//out/Default',
409 '--swarming-targets-file', '/tmp/swarming_targets',
410 '--isolate-map-file',
411 '/fake_src/testing/buildbot/gn_isolate_map.pyl'],
412 files=test_files, ret=0)
413
414 isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
415 isolate_file_contents = ast.literal_eval(isolate_file)
416 files = isolate_file_contents['variables']['files']
417 command = isolate_file_contents['variables']['command']
418
419 self.assertEqual(files, ['base_unittests'])
420 self.assertEqual(command, [
421 './../../build/android/test_wrapper/logdog_wrapper.py',
422 '--logdog-bin-cmd', './../../bin/logdog_butler',
423 '--project', 'chromium',
424 '--service-account-json',
425 '/creds/service_accounts/service-account-luci-logdog-publisher.json',
426 '--prefix', 'android/swarming/logcats/${SWARMING_TASK_ID}',
427 '--source', '${ISOLATED_OUTDIR}/logcats',
428 '--name', 'unified_logcats',
429 'bin/run_base_unittests',
430 '--logcat-output-file', '${ISOLATED_OUTDIR}/logcats',
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800431 '-v',
432 ])
433
434 def test_gn_gen_non_parallel_console_test_launcher(self):
435 test_files = {
436 '/tmp/swarming_targets': 'base_unittests\n',
437 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
438 "{'base_unittests': {"
439 " 'label': '//base:base_unittests',"
440 " 'type': 'non_parallel_console_test_launcher',"
441 "}}\n"
442 ),
443 '/fake_src/out/Default/base_unittests.runtime_deps': (
444 "base_unittests\n"
445 ),
446 }
447 mbw = self.check(['gen', '-c', 'gn_debug_goma', '//out/Default',
448 '--swarming-targets-file', '/tmp/swarming_targets',
449 '--isolate-map-file',
450 '/fake_src/testing/buildbot/gn_isolate_map.pyl'],
451 files=test_files, ret=0)
452
453 isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
454 isolate_file_contents = ast.literal_eval(isolate_file)
455 files = isolate_file_contents['variables']['files']
456 command = isolate_file_contents['variables']['command']
457
458 self.assertEqual(files, [
459 '../../testing/test_env.py',
460 'base_unittests',
461 ])
462 self.assertEqual(command, [
463 '../../testing/test_env.py',
464 './base_unittests',
465 '--',
466 '--asan=0',
467 '--msan=0',
468 '--tsan=0',
469 ])
470
471 def test_gn_isolate_windowed_test_launcher_linux(self):
472 test_files = {
473 '/tmp/swarming_targets': 'base_unittests\n',
474 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
475 "{'base_unittests': {"
476 " 'label': '//base:base_unittests',"
477 " 'type': 'windowed_test_launcher',"
478 "}}\n"
479 ),
480 '/fake_src/out/Default/base_unittests.runtime_deps': (
481 "base_unittests\n"
482 "some_resource_file\n"
483 ),
484 }
485 mbw = self.check(['gen', '-c', 'gn_debug_goma', '//out/Default',
486 '--swarming-targets-file', '/tmp/swarming_targets',
487 '--isolate-map-file',
488 '/fake_src/testing/buildbot/gn_isolate_map.pyl'],
489 files=test_files, ret=0)
490
491 isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
492 isolate_file_contents = ast.literal_eval(isolate_file)
493 files = isolate_file_contents['variables']['files']
494 command = isolate_file_contents['variables']['command']
495
496 self.assertEqual(files, [
497 '../../testing/test_env.py',
498 '../../testing/xvfb.py',
499 '../../third_party/gtest-parallel/gtest-parallel',
500 '../../third_party/gtest-parallel/gtest-parallel-wrapper.py',
501 'base_unittests',
502 'some_resource_file',
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800503 ])
504 self.assertEqual(command, [
505 '../../testing/xvfb.py',
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800506 '../../third_party/gtest-parallel/gtest-parallel-wrapper.py',
507 './base_unittests',
508 '--',
509 '--asan=0',
510 '--msan=0',
511 '--tsan=0',
512 ])
513
514 def test_gn_gen_windowed_test_launcher_win(self):
515 files = {
516 '/tmp/swarming_targets': 'unittests\n',
517 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
518 "{'unittests': {"
519 " 'label': '//somewhere:unittests',"
520 " 'type': 'windowed_test_launcher',"
521 "}}\n"
522 ),
523 r'c:\fake_src\out\Default\unittests.exe.runtime_deps': (
524 "unittests.exe\n"
525 "some_dependency\n"
526 ),
527 }
528 mbw = self.fake_mbw(files=files, win32=True)
529 self.check(['gen',
530 '-c', 'gn_debug_goma',
531 '--swarming-targets-file', '/tmp/swarming_targets',
532 '--isolate-map-file',
533 '/fake_src/testing/buildbot/gn_isolate_map.pyl',
534 '//out/Default'], mbw=mbw, ret=0)
535
536 isolate_file = mbw.files['c:\\fake_src\\out\\Default\\unittests.isolate']
537 isolate_file_contents = ast.literal_eval(isolate_file)
538 files = isolate_file_contents['variables']['files']
539 command = isolate_file_contents['variables']['command']
540
541 self.assertEqual(files, [
542 '../../testing/test_env.py',
543 '../../third_party/gtest-parallel/gtest-parallel',
544 '../../third_party/gtest-parallel/gtest-parallel-wrapper.py',
545 'some_dependency',
546 'unittests.exe',
547 ])
548 self.assertEqual(command, [
549 '../../testing/test_env.py',
550 '../../third_party/gtest-parallel/gtest-parallel-wrapper.py',
551 r'.\unittests.exe',
552 '--',
553 '--asan=0',
554 '--msan=0',
555 '--tsan=0',
556 ])
557
558 def test_gn_gen_console_test_launcher(self):
559 test_files = {
560 '/tmp/swarming_targets': 'base_unittests\n',
561 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
562 "{'base_unittests': {"
563 " 'label': '//base:base_unittests',"
564 " 'type': 'console_test_launcher',"
565 "}}\n"
566 ),
567 '/fake_src/out/Default/base_unittests.runtime_deps': (
568 "base_unittests\n"
569 ),
570 }
571 mbw = self.check(['gen', '-c', 'gn_debug_goma', '//out/Default',
572 '--swarming-targets-file', '/tmp/swarming_targets',
573 '--isolate-map-file',
574 '/fake_src/testing/buildbot/gn_isolate_map.pyl'],
575 files=test_files, ret=0)
576
577 isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
578 isolate_file_contents = ast.literal_eval(isolate_file)
579 files = isolate_file_contents['variables']['files']
580 command = isolate_file_contents['variables']['command']
581
582 self.assertEqual(files, [
583 '../../testing/test_env.py',
584 '../../third_party/gtest-parallel/gtest-parallel',
585 '../../third_party/gtest-parallel/gtest-parallel-wrapper.py',
586 'base_unittests',
587 ])
588 self.assertEqual(command, [
589 '../../testing/test_env.py',
590 '../../third_party/gtest-parallel/gtest-parallel-wrapper.py',
591 './base_unittests',
592 '--',
593 '--asan=0',
594 '--msan=0',
595 '--tsan=0',
596 ])
597
598 def test_gn_isolate_console_test_launcher_memcheck(self):
599 test_files = {
600 '/tmp/swarming_targets': 'base_unittests\n',
601 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
602 "{'base_unittests': {"
603 " 'label': '//base:base_unittests',"
604 " 'type': 'console_test_launcher',"
605 "}}\n"
606 ),
607 '/fake_src/out/Release/base_unittests.runtime_deps': (
608 "base_unittests\n"
609 "lots_of_memcheck_dependencies\n"
kjellanderafd54942016-12-17 12:21:39 -0800610 "../../tools-webrtc/valgrind/webrtc_tests.sh\n"
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800611 ),
612 }
613 mbw = self.check(['gen', '-c', 'gn_memcheck_bot', '//out/Release',
614 '--swarming-targets-file', '/tmp/swarming_targets',
615 '--isolate-map-file',
616 '/fake_src/testing/buildbot/gn_isolate_map.pyl'],
617 files=test_files, ret=0)
618
619 isolate_file = mbw.files['/fake_src/out/Release/base_unittests.isolate']
620 isolate_file_contents = ast.literal_eval(isolate_file)
621 files = isolate_file_contents['variables']['files']
622 command = isolate_file_contents['variables']['command']
623
624 self.assertEqual(files, [
625 '../../testing/test_env.py',
kjellanderafd54942016-12-17 12:21:39 -0800626 '../../tools-webrtc/valgrind/webrtc_tests.sh',
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800627 'base_unittests',
628 'lots_of_memcheck_dependencies',
629 ])
630 self.assertEqual(command, [
631 '../../testing/test_env.py',
632 'bash',
kjellanderafd54942016-12-17 12:21:39 -0800633 '../../tools-webrtc/valgrind/webrtc_tests.sh',
ehmaldonadoed8c8ed2016-11-23 12:58:35 -0800634 '--tool',
635 'memcheck',
636 '--target',
637 'Release',
638 '--build-dir',
639 '..',
640 '--test',
641 './base_unittests',
642 '--',
643 '--asan=0',
644 '--msan=0',
645 '--tsan=0',
646 ])
kjellandera013a022016-11-14 05:54:22 -0800647
648 def test_gn_isolate(self):
649 files = {
650 '/fake_src/out/Default/toolchain.ninja': "",
651 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
652 "{'base_unittests': {"
653 " 'label': '//base:base_unittests',"
ehmaldonadob2fcf6d2016-11-15 12:20:30 -0800654 " 'type': 'non_parallel_console_test_launcher',"
kjellandera013a022016-11-14 05:54:22 -0800655 "}}\n"
656 ),
657 '/fake_src/out/Default/base_unittests.runtime_deps': (
658 "base_unittests\n"
659 ),
660 }
661 self.check(['isolate', '-c', 'gn_debug_goma', '//out/Default',
662 'base_unittests'], files=files, ret=0)
663
664 # test running isolate on an existing build_dir
665 files['/fake_src/out/Default/args.gn'] = 'is_debug = True\n'
666 self.check(['isolate', '//out/Default', 'base_unittests'],
667 files=files, ret=0)
kjellandera013a022016-11-14 05:54:22 -0800668 files['/fake_src/out/Default/mb_type'] = 'gn\n'
669 self.check(['isolate', '//out/Default', 'base_unittests'],
670 files=files, ret=0)
671
672 def test_gn_run(self):
673 files = {
674 '/fake_src/testing/buildbot/gn_isolate_map.pyl': (
675 "{'base_unittests': {"
676 " 'label': '//base:base_unittests',"
ehmaldonadob2fcf6d2016-11-15 12:20:30 -0800677 " 'type': 'windowed_test_launcher',"
kjellandera013a022016-11-14 05:54:22 -0800678 "}}\n"
679 ),
680 '/fake_src/out/Default/base_unittests.runtime_deps': (
681 "base_unittests\n"
682 ),
683 }
684 self.check(['run', '-c', 'gn_debug_goma', '//out/Default',
685 'base_unittests'], files=files, ret=0)
686
687 def test_gn_lookup(self):
688 self.check(['lookup', '-c', 'gn_debug_goma'], ret=0)
689
690 def test_gn_lookup_goma_dir_expansion(self):
691 self.check(['lookup', '-c', 'gn_rel_bot', '-g', '/foo'], ret=0,
692 out=('\n'
693 'Writing """\\\n'
694 'goma_dir = "/foo"\n'
695 'is_debug = false\n'
696 'use_goma = true\n'
697 '""" to _path_/args.gn.\n\n'
698 '/fake_src/buildtools/linux64/gn gen _path_\n'))
699
700 def test_gyp_analyze(self):
701 mbw = self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release',
702 '/tmp/in.json', '/tmp/out.json'], ret=0)
703 self.assertIn('analyzer', mbw.calls[0])
704
705 def test_gyp_crosscompile(self):
706 mbw = self.fake_mbw()
707 self.check(['gen', '-c', 'gyp_crosscompile', '//out/Release'],
708 mbw=mbw, ret=0)
709 self.assertTrue(mbw.cross_compile)
710
711 def test_gyp_gen(self):
712 self.check(['gen', '-c', 'gyp_rel_bot', '-g', '/goma', '//out/Release'],
713 ret=0,
714 out=("GYP_DEFINES='goma=1 gomadir=/goma'\n"
715 "python build/gyp_chromium -G output_dir=out\n"))
716
717 mbw = self.fake_mbw(win32=True)
718 self.check(['gen', '-c', 'gyp_rel_bot', '-g', 'c:\\goma', '//out/Release'],
719 mbw=mbw, ret=0,
720 out=("set GYP_DEFINES=goma=1 gomadir='c:\\goma'\n"
721 "python build\\gyp_chromium -G output_dir=out\n"))
722
723 def test_gyp_gen_fails(self):
724 mbw = self.fake_mbw()
725 mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '')
726 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], mbw=mbw, ret=1)
727
728 def test_gyp_lookup_goma_dir_expansion(self):
729 self.check(['lookup', '-c', 'gyp_rel_bot', '-g', '/foo'], ret=0,
730 out=("GYP_DEFINES='goma=1 gomadir=/foo'\n"
731 "python build/gyp_chromium -G output_dir=_path_\n"))
732
733 def test_help(self):
734 orig_stdout = sys.stdout
735 try:
736 sys.stdout = StringIO.StringIO()
737 self.assertRaises(SystemExit, self.check, ['-h'])
738 self.assertRaises(SystemExit, self.check, ['help'])
739 self.assertRaises(SystemExit, self.check, ['help', 'gen'])
740 finally:
741 sys.stdout = orig_stdout
742
743 def test_multiple_phases(self):
744 # Check that not passing a --phase to a multi-phase builder fails.
745 mbw = self.check(['lookup', '-m', 'fake_master', '-b', 'fake_multi_phase'],
746 ret=1)
747 self.assertIn('Must specify a build --phase', mbw.out)
748
749 # Check that passing a --phase to a single-phase builder fails.
750 mbw = self.check(['lookup', '-m', 'fake_master', '-b', 'fake_gn_builder',
751 '--phase', 'phase_1'], ret=1)
752 self.assertIn('Must not specify a build --phase', mbw.out)
753
754 # Check that passing a wrong phase key to a multi-phase builder fails.
755 mbw = self.check(['lookup', '-m', 'fake_master', '-b', 'fake_multi_phase',
756 '--phase', 'wrong_phase'], ret=1)
757 self.assertIn('Phase wrong_phase doesn\'t exist', mbw.out)
758
759 # Check that passing a correct phase key to a multi-phase builder passes.
760 mbw = self.check(['lookup', '-m', 'fake_master', '-b', 'fake_multi_phase',
761 '--phase', 'phase_1'], ret=0)
762 self.assertIn('phase = 1', mbw.out)
763
764 mbw = self.check(['lookup', '-m', 'fake_master', '-b', 'fake_multi_phase',
765 '--phase', 'phase_2'], ret=0)
766 self.assertIn('phase = 2', mbw.out)
767
768 def test_validate(self):
769 mbw = self.fake_mbw()
770 self.check(['validate'], mbw=mbw, ret=0)
771
kjellandera013a022016-11-14 05:54:22 -0800772 def test_gyp_env_hacks(self):
773 mbw = self.fake_mbw()
774 mbw.files[mbw.default_config] = GYP_HACKS_CONFIG
775 self.check(['lookup', '-c', 'fake_config'], mbw=mbw,
776 ret=0,
777 out=("GYP_DEFINES='foo=bar baz=1'\n"
778 "GYP_LINK_CONCURRENCY=1\n"
779 "LLVM_FORCE_HEAD_REVISION=1\n"
780 "python build/gyp_chromium -G output_dir=_path_\n"))
781
782
783if __name__ == '__main__':
784 unittest.main()