Fix mb.py presubmit issues.

* Add a config file for python formatting (.style.yapf).
* Change the default indentation from 4 spaces to 2 spaces.
* Run 'git cl format --python' on a few python files.

Bug: webrtc:13413
Change-Id: Ia71135131276c2c499b00032d57ad16ee5200a5c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/238982
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Christoffer Jansson <jansson@google.com>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#35500}
This commit is contained in:
Jeremy Leconte 2021-12-07 19:49:48 +01:00 committed by WebRTC LUCI CQ
parent 035f0446c8
commit f22c78b01a
6 changed files with 1758 additions and 1697 deletions

4
.style.yapf Normal file
View file

@ -0,0 +1,4 @@
[style]
based_on_style = pep8
indent_width = 2
column_limit = 80

1
OWNERS
View file

@ -17,3 +17,4 @@ per-file pylintrc=mbonadei@webrtc.org
per-file WATCHLISTS=* per-file WATCHLISTS=*
per-file native-api.md=mbonadei@webrtc.org per-file native-api.md=mbonadei@webrtc.org
per-file ....lua=titovartem@webrtc.org per-file ....lua=titovartem@webrtc.org
per-file .style.yapf=jleconte@webrtc.org

View file

@ -31,108 +31,103 @@ NO_TOOLS_ERROR_MESSAGE = (
'To fix this run:\n' 'To fix this run:\n'
' python %s %s\n' ' python %s %s\n'
'\n' '\n'
'Note that these tools are Google-internal due to licensing, so in order to ' 'Note that these tools are Google-internal due to licensing, so in order '
'use them you will have to get your own license and manually put them in the ' 'to use them you will have to get your own license and manually put them '
'right location.\n' 'in the right location.\n'
'See https://cs.chromium.org/chromium/src/third_party/webrtc/tools_webrtc/' 'See https://cs.chromium.org/chromium/src/third_party/webrtc/tools_webrtc/'
'download_tools.py?rcl=bbceb76f540159e2dba0701ac03c514f01624130&l=13') 'download_tools.py?rcl=bbceb76f540159e2dba0701ac03c514f01624130&l=13')
def _LogCommand(command): def _LogCommand(command):
logging.info('Running %r', command) logging.info('Running %r', command)
return command return command
def _ParseArgs(): def _ParseArgs():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(description='Run low-bandwidth audio tests.')
description='Run low-bandwidth audio tests.') parser.add_argument('build_dir',
parser.add_argument('build_dir', help='Path to the build directory (e.g. out/Release).')
help='Path to the build directory (e.g. out/Release).') parser.add_argument('--remove',
parser.add_argument('--remove', action='store_true',
action='store_true', help='Remove output audio files after testing.')
help='Remove output audio files after testing.') parser.add_argument(
parser.add_argument( '--android',
'--android', action='store_true',
action='store_true', help='Perform the test on a connected Android device instead.')
help='Perform the test on a connected Android device instead.') parser.add_argument('--adb-path', help='Path to adb binary.', default='adb')
parser.add_argument('--adb-path', parser.add_argument('--num-retries',
help='Path to adb binary.', default='0',
default='adb') help='Number of times to retry the test on Android.')
parser.add_argument('--num-retries', parser.add_argument(
default='0', '--isolated-script-test-perf-output',
help='Number of times to retry the test on Android.') default=None,
parser.add_argument( help='Path to store perf results in histogram proto format.')
'--isolated-script-test-perf-output', parser.add_argument('--extra-test-args',
default=None, default=[],
help='Path to store perf results in histogram proto format.') action='append',
parser.add_argument('--extra-test-args', help='Extra args to path to the test binary.')
default=[],
action='append',
help='Extra args to path to the test binary.')
# Ignore Chromium-specific flags # Ignore Chromium-specific flags
parser.add_argument('--test-launcher-summary-output', parser.add_argument('--test-launcher-summary-output', type=str, default=None)
type=str, args = parser.parse_args()
default=None)
args = parser.parse_args()
return args return args
def _GetPlatform(): def _GetPlatform():
if sys.platform == 'win32': if sys.platform == 'win32':
return 'win' return 'win'
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
return 'mac' return 'mac'
elif sys.platform.startswith('linux'): elif sys.platform.startswith('linux'):
return 'linux' return 'linux'
raise AssertionError('Unknown platform %s' % sys.platform)
def _GetExtension(): def _GetExtension():
return '.exe' if sys.platform == 'win32' else '' return '.exe' if sys.platform == 'win32' else ''
def _GetPathToTools(): def _GetPathToTools():
tools_dir = os.path.join(SRC_DIR, 'tools_webrtc') tools_dir = os.path.join(SRC_DIR, 'tools_webrtc')
toolchain_dir = os.path.join(tools_dir, 'audio_quality') toolchain_dir = os.path.join(tools_dir, 'audio_quality')
platform = _GetPlatform() platform = _GetPlatform()
ext = _GetExtension() ext = _GetExtension()
pesq_path = os.path.join(toolchain_dir, platform, 'pesq' + ext) pesq_path = os.path.join(toolchain_dir, platform, 'pesq' + ext)
if not os.path.isfile(pesq_path): if not os.path.isfile(pesq_path):
pesq_path = None pesq_path = None
polqa_path = os.path.join(toolchain_dir, platform, 'PolqaOem64' + ext) polqa_path = os.path.join(toolchain_dir, platform, 'PolqaOem64' + ext)
if not os.path.isfile(polqa_path): if not os.path.isfile(polqa_path):
polqa_path = None polqa_path = None
if (platform != 'mac' and not polqa_path) or not pesq_path: if (platform != 'mac' and not polqa_path) or not pesq_path:
logging.error(NO_TOOLS_ERROR_MESSAGE, toolchain_dir, logging.error(NO_TOOLS_ERROR_MESSAGE, toolchain_dir,
os.path.join(tools_dir, 'download_tools.py'), os.path.join(tools_dir, 'download_tools.py'), toolchain_dir)
toolchain_dir)
return pesq_path, polqa_path return pesq_path, polqa_path
def ExtractTestRuns(lines, echo=False): def ExtractTestRuns(lines, echo=False):
"""Extracts information about tests from the output of a test runner. """Extracts information about tests from the output of a test runner.
Produces tuples Produces tuples
(android_device, test_name, reference_file, degraded_file, cur_perf_results). (android_device, test_name, reference_file, degraded_file, cur_perf_results).
""" """
for line in lines: for line in lines:
if echo: if echo:
sys.stdout.write(line) sys.stdout.write(line)
# Output from Android has a prefix with the device name. # Output from Android has a prefix with the device name.
android_prefix_re = r'(?:I\b.+\brun_tests_on_device\((.+?)\)\s*)?' android_prefix_re = r'(?:I\b.+\brun_tests_on_device\((.+?)\)\s*)?'
test_re = r'^' + android_prefix_re + (r'TEST (\w+) ([^ ]+?) ([^\s]+)' test_re = r'^' + android_prefix_re + (r'TEST (\w+) ([^ ]+?) ([^\s]+)'
r' ?([^\s]+)?\s*$') r' ?([^\s]+)?\s*$')
match = re.search(test_re, line) match = re.search(test_re, line)
if match: if match:
yield match.groups() yield match.groups()
def _GetFile(file_path, def _GetFile(file_path,
@ -140,97 +135,95 @@ def _GetFile(file_path,
move=False, move=False,
android=False, android=False,
adb_prefix=('adb', )): adb_prefix=('adb', )):
out_file_name = os.path.basename(file_path) out_file_name = os.path.basename(file_path)
out_file_path = os.path.join(out_dir, out_file_name) out_file_path = os.path.join(out_dir, out_file_name)
if android: if android:
# Pull the file from the connected Android device. # Pull the file from the connected Android device.
adb_command = adb_prefix + ('pull', file_path, out_dir) adb_command = adb_prefix + ('pull', file_path, out_dir)
subprocess.check_call(_LogCommand(adb_command)) subprocess.check_call(_LogCommand(adb_command))
if move: if move:
# Remove that file. # Remove that file.
adb_command = adb_prefix + ('shell', 'rm', file_path) adb_command = adb_prefix + ('shell', 'rm', file_path)
subprocess.check_call(_LogCommand(adb_command)) subprocess.check_call(_LogCommand(adb_command))
elif os.path.abspath(file_path) != os.path.abspath(out_file_path): elif os.path.abspath(file_path) != os.path.abspath(out_file_path):
if move: if move:
shutil.move(file_path, out_file_path) shutil.move(file_path, out_file_path)
else: else:
shutil.copy(file_path, out_file_path) shutil.copy(file_path, out_file_path)
return out_file_path return out_file_path
def _RunPesq(executable_path, def _RunPesq(executable_path,
reference_file, reference_file,
degraded_file, degraded_file,
sample_rate_hz=16000): sample_rate_hz=16000):
directory = os.path.dirname(reference_file) directory = os.path.dirname(reference_file)
assert os.path.dirname(degraded_file) == directory assert os.path.dirname(degraded_file) == directory
# Analyze audio. # Analyze audio.
command = [ command = [
executable_path, executable_path,
'+%d' % sample_rate_hz, '+%d' % sample_rate_hz,
os.path.basename(reference_file), os.path.basename(reference_file),
os.path.basename(degraded_file) os.path.basename(degraded_file)
] ]
# Need to provide paths in the current directory due to a bug in PESQ: # Need to provide paths in the current directory due to a bug in PESQ:
# On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than # On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than
# 'path/to', PESQ crashes. # 'path/to', PESQ crashes.
out = subprocess.check_output(_LogCommand(command), out = subprocess.check_output(_LogCommand(command),
cwd=directory, cwd=directory,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
# Find the scores in stdout of PESQ. # Find the scores in stdout of PESQ.
match = re.search( match = re.search(
r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', out) r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', out)
if match: if match:
raw_mos, _ = match.groups() raw_mos, _ = match.groups()
return {'pesq_mos': (raw_mos, 'unitless')}
return {'pesq_mos': (raw_mos, 'unitless')} logging.error('PESQ: %s', out.splitlines()[-1])
else: return {}
logging.error('PESQ: %s', out.splitlines()[-1])
return {}
def _RunPolqa(executable_path, reference_file, degraded_file): def _RunPolqa(executable_path, reference_file, degraded_file):
# Analyze audio. # Analyze audio.
command = [ command = [
executable_path, '-q', '-LC', 'NB', '-Ref', reference_file, '-Test', executable_path, '-q', '-LC', 'NB', '-Ref', reference_file, '-Test',
degraded_file degraded_file
] ]
process = subprocess.Popen(_LogCommand(command), process = subprocess.Popen(_LogCommand(command),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
out, err = process.communicate() out, err = process.communicate()
# Find the scores in stdout of POLQA. # Find the scores in stdout of POLQA.
match = re.search(r'\bMOS-LQO:\s+([\d.]+)', out) match = re.search(r'\bMOS-LQO:\s+([\d.]+)', out)
if process.returncode != 0 or not match: if process.returncode != 0 or not match:
if process.returncode == 2: if process.returncode == 2:
logging.warning('%s (2)', err.strip()) logging.warning('%s (2)', err.strip())
logging.warning('POLQA license error, skipping test.') logging.warning('POLQA license error, skipping test.')
else: else:
logging.error('%s (%d)', err.strip(), process.returncode) logging.error('%s (%d)', err.strip(), process.returncode)
return {} return {}
mos_lqo, = match.groups() mos_lqo, = match.groups()
return {'polqa_mos_lqo': (mos_lqo, 'unitless')} return {'polqa_mos_lqo': (mos_lqo, 'unitless')}
def _MergeInPerfResultsFromCcTests(histograms, run_perf_results_file): def _MergeInPerfResultsFromCcTests(histograms, run_perf_results_file):
from tracing.value import histogram_set from tracing.value import histogram_set
cc_histograms = histogram_set.HistogramSet() cc_histograms = histogram_set.HistogramSet()
with open(run_perf_results_file, 'rb') as f: with open(run_perf_results_file, 'rb') as f:
contents = f.read() contents = f.read()
if not contents: if not contents:
return return
cc_histograms.ImportProto(contents) cc_histograms.ImportProto(contents)
histograms.Merge(cc_histograms) histograms.Merge(cc_histograms)
Analyzer = collections.namedtuple( Analyzer = collections.namedtuple(
@ -238,136 +231,131 @@ Analyzer = collections.namedtuple(
def _ConfigurePythonPath(args): def _ConfigurePythonPath(args):
script_dir = os.path.dirname(os.path.realpath(__file__)) script_dir = os.path.dirname(os.path.realpath(__file__))
checkout_root = os.path.abspath( checkout_root = os.path.abspath(os.path.join(script_dir, os.pardir,
os.path.join(script_dir, os.pardir, os.pardir)) os.pardir))
# TODO(https://crbug.com/1029452): Use a copy rule and add these from the out # TODO(https://crbug.com/1029452): Use a copy rule and add these from the
# dir like for the third_party/protobuf code. # out dir like for the third_party/protobuf code.
sys.path.insert( sys.path.insert(
0, os.path.join(checkout_root, 'third_party', 'catapult', 'tracing')) 0, os.path.join(checkout_root, 'third_party', 'catapult', 'tracing'))
# The low_bandwidth_audio_perf_test gn rule will build the protobuf stub for # The low_bandwidth_audio_perf_test gn rule will build the protobuf stub
# python, so put it in the path for this script before we attempt to import # for python, so put it in the path for this script before we attempt to
# it. # import it.
histogram_proto_path = os.path.join(os.path.abspath(args.build_dir), histogram_proto_path = os.path.join(os.path.abspath(args.build_dir),
'pyproto', 'tracing', 'tracing', 'pyproto', 'tracing', 'tracing', 'proto')
'proto') sys.path.insert(0, histogram_proto_path)
sys.path.insert(0, histogram_proto_path) proto_stub_path = os.path.join(os.path.abspath(args.build_dir), 'pyproto')
proto_stub_path = os.path.join(os.path.abspath(args.build_dir), 'pyproto') sys.path.insert(0, proto_stub_path)
sys.path.insert(0, proto_stub_path)
# Fail early in case the proto hasn't been built. # Fail early in case the proto hasn't been built.
try: try:
import histogram_pb2 #pylint: disable=unused-variable
except ImportError as e: import histogram_pb2
logging.exception(e) except ImportError as e:
raise ImportError( logging.exception(e)
'Could not import histogram_pb2. You need to build the ' raise ImportError('Could not import histogram_pb2. You need to build the '
'low_bandwidth_audio_perf_test target before invoking ' 'low_bandwidth_audio_perf_test target before invoking '
'this script. Expected to find ' 'this script. Expected to find '
'histogram_pb2.py in %s.' % histogram_proto_path) 'histogram_pb2.py in %s.' % histogram_proto_path)
def main(): def main():
# pylint: disable=W0101 # pylint: disable=W0101
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
logging.info('Invoked with %s', str(sys.argv)) logging.info('Invoked with %s', str(sys.argv))
args = _ParseArgs() args = _ParseArgs()
_ConfigurePythonPath(args) _ConfigurePythonPath(args)
# Import catapult modules here after configuring the pythonpath. # Import catapult modules here after configuring the pythonpath.
from tracing.value import histogram_set from tracing.value import histogram_set
from tracing.value.diagnostics import reserved_infos from tracing.value.diagnostics import reserved_infos
from tracing.value.diagnostics import generic_set from tracing.value.diagnostics import generic_set
pesq_path, polqa_path = _GetPathToTools() pesq_path, polqa_path = _GetPathToTools()
if pesq_path is None: if pesq_path is None:
return 1 return 1
out_dir = os.path.join(args.build_dir, '..') out_dir = os.path.join(args.build_dir, '..')
if args.android: if args.android:
test_command = [ test_command = [
os.path.join(args.build_dir, 'bin', os.path.join(args.build_dir, 'bin', 'run_low_bandwidth_audio_test'),
'run_low_bandwidth_audio_test'), '-v', '-v', '--num-retries', args.num_retries
'--num-retries', args.num_retries ]
] else:
else: test_command = [os.path.join(args.build_dir, 'low_bandwidth_audio_test')]
test_command = [
os.path.join(args.build_dir, 'low_bandwidth_audio_test')
]
analyzers = [Analyzer('pesq', _RunPesq, pesq_path, 16000)] analyzers = [Analyzer('pesq', _RunPesq, pesq_path, 16000)]
# Check if POLQA can run at all, or skip the 48 kHz tests entirely. # Check if POLQA can run at all, or skip the 48 kHz tests entirely.
example_path = os.path.join(SRC_DIR, 'resources', 'voice_engine', example_path = os.path.join(SRC_DIR, 'resources', 'voice_engine',
'audio_tiny48.wav') 'audio_tiny48.wav')
if polqa_path and _RunPolqa(polqa_path, example_path, example_path): if polqa_path and _RunPolqa(polqa_path, example_path, example_path):
analyzers.append(Analyzer('polqa', _RunPolqa, polqa_path, 48000)) analyzers.append(Analyzer('polqa', _RunPolqa, polqa_path, 48000))
histograms = histogram_set.HistogramSet() histograms = histogram_set.HistogramSet()
for analyzer in analyzers: for analyzer in analyzers:
# Start the test executable that produces audio files. # Start the test executable that produces audio files.
test_process = subprocess.Popen(_LogCommand(test_command + [ test_process = subprocess.Popen(_LogCommand(test_command + [
'--sample_rate_hz=%d' % analyzer.sample_rate_hz, '--sample_rate_hz=%d' % analyzer.sample_rate_hz,
'--test_case_prefix=%s' % analyzer.name, '--test_case_prefix=%s' % analyzer.name,
] + args.extra_test_args), ] + args.extra_test_args),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
perf_results_file = None perf_results_file = None
try: try:
lines = iter(test_process.stdout.readline, '') lines = iter(test_process.stdout.readline, '')
for result in ExtractTestRuns(lines, echo=True): for result in ExtractTestRuns(lines, echo=True):
(android_device, test_name, reference_file, degraded_file, (android_device, test_name, reference_file, degraded_file,
perf_results_file) = result perf_results_file) = result
adb_prefix = (args.adb_path, ) adb_prefix = (args.adb_path, )
if android_device: if android_device:
adb_prefix += ('-s', android_device) adb_prefix += ('-s', android_device)
reference_file = _GetFile(reference_file, reference_file = _GetFile(reference_file,
out_dir, out_dir,
android=args.android, android=args.android,
adb_prefix=adb_prefix) adb_prefix=adb_prefix)
degraded_file = _GetFile(degraded_file, degraded_file = _GetFile(degraded_file,
out_dir, out_dir,
move=True, move=True,
android=args.android, android=args.android,
adb_prefix=adb_prefix) adb_prefix=adb_prefix)
analyzer_results = analyzer.func(analyzer.executable, analyzer_results = analyzer.func(analyzer.executable, reference_file,
reference_file, degraded_file) degraded_file)
for metric, (value, units) in analyzer_results.items(): for metric, (value, units) in analyzer_results.items():
hist = histograms.CreateHistogram(metric, units, [value]) hist = histograms.CreateHistogram(metric, units, [value])
user_story = generic_set.GenericSet([test_name]) user_story = generic_set.GenericSet([test_name])
hist.diagnostics[reserved_infos.STORIES.name] = user_story hist.diagnostics[reserved_infos.STORIES.name] = user_story
# Output human readable results. # Output human readable results.
print 'RESULT %s: %s= %s %s' % (metric, test_name, value, print 'RESULT %s: %s= %s %s' % (metric, test_name, value, units)
units)
if args.remove: if args.remove:
os.remove(reference_file) os.remove(reference_file)
os.remove(degraded_file) os.remove(degraded_file)
finally: finally:
test_process.terminate() test_process.terminate()
if perf_results_file: if perf_results_file:
perf_results_file = _GetFile(perf_results_file, perf_results_file = _GetFile(perf_results_file,
out_dir, out_dir,
move=True, move=True,
android=args.android, android=args.android,
adb_prefix=adb_prefix) adb_prefix=adb_prefix)
_MergeInPerfResultsFromCcTests(histograms, perf_results_file) _MergeInPerfResultsFromCcTests(histograms, perf_results_file)
if args.remove: if args.remove:
os.remove(perf_results_file) os.remove(perf_results_file)
if args.isolated_script_test_perf_output: if args.isolated_script_test_perf_output:
with open(args.isolated_script_test_perf_output, 'wb') as f: with open(args.isolated_script_test_perf_output, 'wb') as f:
f.write(histograms.AsProto().SerializeToString()) f.write(histograms.AsProto().SerializeToString())
return test_process.wait() return test_process.wait()
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())

View file

@ -97,6 +97,9 @@ max-line-length=80
# Maximum number of lines in a module # Maximum number of lines in a module
max-module-lines=1000 max-module-lines=1000
# We use two spaces for indents, instead of the usual four spaces or tab.
indent-string=' '
[BASIC] [BASIC]
@ -192,10 +195,6 @@ max-public-methods=20
[CLASSES] [CLASSES]
# List of interface methods to ignore, separated by a comma. This is used for
# instance to not check methods defines in Zope's Interface base class.
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
# List of method names used to declare (i.e. assign) instance attributes. # List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp defining-attr-methods=__init__,__new__,setUp

File diff suppressed because it is too large Load diff

View file

@ -12,9 +12,9 @@
import ast import ast
import json import json
try: try:
from StringIO import StringIO # for Python2 from StringIO import StringIO # for Python2
except ImportError: except ImportError:
from io import StringIO # for Python3 from io import StringIO # for Python3
import os import os
import re import re
import sys import sys
@ -61,7 +61,7 @@ class FakeMBW(mb.MetaBuildWrapper):
def Exists(self, path): def Exists(self, path):
abs_path = self._AbsPath(path) abs_path = self._AbsPath(path)
return (self.files.get(abs_path) is not None or abs_path in self.dirs) return self.files.get(abs_path) is not None or abs_path in self.dirs
def MaybeMakeDirectory(self, path): def MaybeMakeDirectory(self, path):
abpath = self._AbsPath(path) abpath = self._AbsPath(path)
@ -132,7 +132,7 @@ class FakeFile(object):
self.buf += contents self.buf += contents
def close(self): def close(self):
self.files[self.name] = self.buf self.files[self.name] = self.buf
TEST_CONFIG = """\ TEST_CONFIG = """\
@ -186,8 +186,7 @@ class UnitTest(unittest.TestCase):
mbw = FakeMBW(win32=win32) mbw = FakeMBW(win32=win32)
mbw.files.setdefault(mbw.default_config, TEST_CONFIG) mbw.files.setdefault(mbw.default_config, TEST_CONFIG)
mbw.files.setdefault( mbw.files.setdefault(
mbw.ToAbsPath('//testing/buildbot/gn_isolate_map.pyl'), mbw.ToAbsPath('//testing/buildbot/gn_isolate_map.pyl'), '''{
'''{
"foo_unittests": { "foo_unittests": {
"label": "//foo:foo_unittests", "label": "//foo:foo_unittests",
"type": "console_test_launcher", "type": "console_test_launcher",
@ -202,7 +201,13 @@ class UnitTest(unittest.TestCase):
mbw.files[path] = contents mbw.files[path] = contents
return mbw return mbw
def check(self, args, mbw=None, files=None, out=None, err=None, ret=None, def check(self,
args,
mbw=None,
files=None,
out=None,
err=None,
ret=None,
env=None): env=None):
if not mbw: if not mbw:
mbw = self.fake_mbw(files) mbw = self.fake_mbw(files)
@ -223,33 +228,43 @@ class UnitTest(unittest.TestCase):
return mbw return mbw
def test_analyze(self): def test_analyze(self):
files = {'/tmp/in.json': '''{\ files = {
'/tmp/in.json':
'''{\
"files": ["foo/foo_unittest.cc"], "files": ["foo/foo_unittest.cc"],
"test_targets": ["foo_unittests"], "test_targets": ["foo_unittests"],
"additional_compile_targets": ["all"] "additional_compile_targets": ["all"]
}''', }''',
'/tmp/out.json.gn': '''{\ '/tmp/out.json.gn':
'''{\
"status": "Found dependency", "status": "Found dependency",
"compile_targets": ["//foo:foo_unittests"], "compile_targets": ["//foo:foo_unittests"],
"test_targets": ["//foo:foo_unittests"] "test_targets": ["//foo:foo_unittests"]
}'''} }'''
}
mbw = self.fake_mbw(files) mbw = self.fake_mbw(files)
mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '') mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '')
self.check(['analyze', '-c', 'debug_goma', '//out/Default', self.check([
'/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) 'analyze', '-c', 'debug_goma', '//out/Default', '/tmp/in.json',
'/tmp/out.json'
],
mbw=mbw,
ret=0)
out = json.loads(mbw.files['/tmp/out.json']) out = json.loads(mbw.files['/tmp/out.json'])
self.assertEqual(out, { self.assertEqual(
'status': 'Found dependency', out, {
'compile_targets': ['foo:foo_unittests'], 'status': 'Found dependency',
'test_targets': ['foo_unittests'] 'compile_targets': ['foo:foo_unittests'],
}) 'test_targets': ['foo_unittests']
})
def test_gen(self): def test_gen(self):
mbw = self.fake_mbw() mbw = self.fake_mbw()
self.check(['gen', '-c', 'debug_goma', '//out/Default', '-g', '/goma'], self.check(['gen', '-c', 'debug_goma', '//out/Default', '-g', '/goma'],
mbw=mbw, ret=0) mbw=mbw,
ret=0)
self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'], self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'],
('goma_dir = "/goma"\n' ('goma_dir = "/goma"\n'
'is_debug = true\n' 'is_debug = true\n'
@ -262,23 +277,25 @@ class UnitTest(unittest.TestCase):
mbw = self.fake_mbw(win32=True) mbw = self.fake_mbw(win32=True)
self.check(['gen', '-c', 'debug_goma', '-g', 'c:\\goma', '//out/Debug'], self.check(['gen', '-c', 'debug_goma', '-g', 'c:\\goma', '//out/Debug'],
mbw=mbw, ret=0) mbw=mbw,
ret=0)
self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'], self.assertMultiLineEqual(mbw.files['c:\\fake_src\\out\\Debug\\args.gn'],
('goma_dir = "c:\\\\goma"\n' ('goma_dir = "c:\\\\goma"\n'
'is_debug = true\n' 'is_debug = true\n'
'use_goma = true\n')) 'use_goma = true\n'))
self.assertIn('c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug ' self.assertIn(
'--check\n', mbw.out) 'c:\\fake_src\\buildtools\\win\\gn.exe gen //out/Debug '
'--check\n', mbw.out)
mbw = self.fake_mbw() mbw = self.fake_mbw()
self.check(['gen', '-m', 'fake_group', '-b', 'fake_args_bot', self.check(
'//out/Debug'], ['gen', '-m', 'fake_group', '-b', 'fake_args_bot', '//out/Debug'],
mbw=mbw, ret=0) mbw=mbw,
ret=0)
self.assertEqual( self.assertEqual(
mbw.files['/fake_src/out/Debug/args.gn'], mbw.files['/fake_src/out/Debug/args.gn'],
'import("//build/args/bots/fake_group/fake_args_bot.gn")\n\n') 'import("//build/args/bots/fake_group/fake_args_bot.gn")\n\n')
def test_gen_fails(self): def test_gen_fails(self):
mbw = self.fake_mbw() mbw = self.fake_mbw()
mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '') mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '')
@ -286,46 +303,47 @@ class UnitTest(unittest.TestCase):
def test_gen_swarming(self): def test_gen_swarming(self):
files = { files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'raw'," " 'label': '//base:base_unittests',"
" 'args': []," " 'type': 'raw',"
"}}\n" " 'args': [],"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
mbw = self.fake_mbw(files) mbw = self.fake_mbw(files)
self.check(['gen', self.check([
'-c', 'debug_goma', 'gen', '-c', 'debug_goma', '--swarming-targets-file',
'--swarming-targets-file', '/tmp/swarming_targets', '/tmp/swarming_targets', '//out/Default'
'//out/Default'], mbw=mbw, ret=0) ],
self.assertIn('/fake_src/out/Default/base_unittests.isolate', mbw=mbw,
mbw.files) ret=0)
self.assertIn('/fake_src/out/Default/base_unittests.isolate', mbw.files)
self.assertIn('/fake_src/out/Default/base_unittests.isolated.gen.json', self.assertIn('/fake_src/out/Default/base_unittests.isolated.gen.json',
mbw.files) mbw.files)
def test_gen_swarming_android(self): def test_gen_swarming_android(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'additional_compile_target'," " 'label': '//base:base_unittests',"
"}}\n" " 'type': 'additional_compile_target',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
mbw = self.check(['gen', '-c', 'android_bot', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'android_bot', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -337,30 +355,34 @@ class UnitTest(unittest.TestCase):
self.assertEqual(command, [ self.assertEqual(command, [
'vpython', 'vpython',
'../../build/android/test_wrapper/logdog_wrapper.py', '../../build/android/test_wrapper/logdog_wrapper.py',
'--target', 'base_unittests', '--target',
'--logdog-bin-cmd', '../../bin/logdog_butler', 'base_unittests',
'--logcat-output-file', '${ISOLATED_OUTDIR}/logcats', '--logdog-bin-cmd',
'../../bin/logdog_butler',
'--logcat-output-file',
'${ISOLATED_OUTDIR}/logcats',
'--store-tombstones', '--store-tombstones',
]) ])
def test_gen_swarming_android_junit_test(self): def test_gen_swarming_android_junit_test(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'junit_test'," " 'label': '//base:base_unittests',"
"}}\n" " 'type': 'junit_test',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
mbw = self.check(['gen', '-c', 'android_bot', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'android_bot', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -372,31 +394,35 @@ class UnitTest(unittest.TestCase):
self.assertEqual(command, [ self.assertEqual(command, [
'vpython', 'vpython',
'../../build/android/test_wrapper/logdog_wrapper.py', '../../build/android/test_wrapper/logdog_wrapper.py',
'--target', 'base_unittests', '--target',
'--logdog-bin-cmd', '../../bin/logdog_butler', 'base_unittests',
'--logcat-output-file', '${ISOLATED_OUTDIR}/logcats', '--logdog-bin-cmd',
'../../bin/logdog_butler',
'--logcat-output-file',
'${ISOLATED_OUTDIR}/logcats',
'--store-tombstones', '--store-tombstones',
]) ])
def test_gen_timeout(self): def test_gen_timeout(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'non_parallel_console_test_launcher'," " 'label': '//base:base_unittests',"
" 'timeout': 500," " 'type': 'non_parallel_console_test_launcher',"
"}}\n" " 'timeout': 500,"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
mbw = self.check(['gen', '-c', 'debug_goma', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'debug_goma', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -430,24 +456,25 @@ class UnitTest(unittest.TestCase):
def test_gen_script(self): def test_gen_script(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests_script\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests_script\n',
"{'base_unittests_script': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests_script': {"
" 'type': 'script'," " 'label': '//base:base_unittests',"
" 'script': '//base/base_unittests_script.py'," " 'type': 'script',"
"}}\n" " 'script': '//base/base_unittests_script.py',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"
"base_unittests_script.py\n" "base_unittests_script.py\n"),
),
} }
mbw = self.check(['gen', '-c', 'debug_goma', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'debug_goma', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = ( isolate_file = (
mbw.files['/fake_src/out/Default/base_unittests_script.isolate']) mbw.files['/fake_src/out/Default/base_unittests_script.isolate'])
@ -466,22 +493,23 @@ class UnitTest(unittest.TestCase):
def test_gen_raw(self): def test_gen_raw(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'raw'," " 'label': '//base:base_unittests',"
"}}\n" " 'type': 'raw',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
mbw = self.check(['gen', '-c', 'debug_goma', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'debug_goma', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -508,22 +536,23 @@ class UnitTest(unittest.TestCase):
def test_gen_non_parallel_console_test_launcher(self): def test_gen_non_parallel_console_test_launcher(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'non_parallel_console_test_launcher'," " 'label': '//base:base_unittests',"
"}}\n" " 'type': 'non_parallel_console_test_launcher',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
mbw = self.check(['gen', '-c', 'debug_goma', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'debug_goma', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -557,23 +586,24 @@ class UnitTest(unittest.TestCase):
def test_isolate_windowed_test_launcher_linux(self): def test_isolate_windowed_test_launcher_linux(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'windowed_test_launcher'," " 'label': '//base:base_unittests',"
"}}\n" " 'type': 'windowed_test_launcher',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"
"some_resource_file\n" "some_resource_file\n"),
),
} }
mbw = self.check(['gen', '-c', 'debug_goma', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'debug_goma', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -608,26 +638,26 @@ class UnitTest(unittest.TestCase):
def test_gen_windowed_test_launcher_win(self): def test_gen_windowed_test_launcher_win(self):
files = { files = {
'c:\\fake_src\\out\\Default\\tmp\\swarming_targets': 'unittests\n', 'c:\\fake_src\\out\\Default\\tmp\\swarming_targets':
'c:\\fake_src\\testing\\buildbot\\gn_isolate_map.pyl': ( 'unittests\n',
"{'unittests': {" 'c:\\fake_src\\testing\\buildbot\\gn_isolate_map.pyl':
" 'label': '//somewhere:unittests'," ("{'unittests': {"
" 'type': 'windowed_test_launcher'," " 'label': '//somewhere:unittests',"
"}}\n" " 'type': 'windowed_test_launcher',"
), "}}\n"),
r'c:\fake_src\out\Default\unittests.exe.runtime_deps': ( r'c:\fake_src\out\Default\unittests.exe.runtime_deps':
"unittests.exe\n" ("unittests.exe\n"
"some_dependency\n" "some_dependency\n"),
),
} }
mbw = self.fake_mbw(files=files, win32=True) mbw = self.fake_mbw(files=files, win32=True)
self.check(['gen', self.check([
'-c', 'debug_goma', 'gen', '-c', 'debug_goma', '--swarming-targets-file',
'--swarming-targets-file', 'c:\\fake_src\\out\\Default\\tmp\\swarming_targets',
'c:\\fake_src\\out\\Default\\tmp\\swarming_targets', '--isolate-map-file',
'--isolate-map-file', 'c:\\fake_src\\testing\\buildbot\\gn_isolate_map.pyl', '//out/Default'
'c:\\fake_src\\testing\\buildbot\\gn_isolate_map.pyl', ],
'//out/Default'], mbw=mbw, ret=0) mbw=mbw,
ret=0)
isolate_file = mbw.files['c:\\fake_src\\out\\Default\\unittests.isolate'] isolate_file = mbw.files['c:\\fake_src\\out\\Default\\unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -661,22 +691,23 @@ class UnitTest(unittest.TestCase):
def test_gen_console_test_launcher(self): def test_gen_console_test_launcher(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'console_test_launcher'," " 'label': '//base:base_unittests',"
"}}\n" " 'type': 'console_test_launcher',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
mbw = self.check(['gen', '-c', 'debug_goma', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'debug_goma', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -709,24 +740,25 @@ class UnitTest(unittest.TestCase):
def test_isolate_test_launcher_with_webcam(self): def test_isolate_test_launcher_with_webcam(self):
test_files = { test_files = {
'/tmp/swarming_targets': 'base_unittests\n', '/tmp/swarming_targets':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( 'base_unittests\n',
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'console_test_launcher'," " 'label': '//base:base_unittests',"
" 'use_webcam': True," " 'type': 'console_test_launcher',"
"}}\n" " 'use_webcam': True,"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"
"some_resource_file\n" "some_resource_file\n"),
),
} }
mbw = self.check(['gen', '-c', 'debug_goma', '//out/Default', mbw = self.check([
'--swarming-targets-file', '/tmp/swarming_targets', 'gen', '-c', 'debug_goma', '//out/Default', '--swarming-targets-file',
'--isolate-map-file', '/tmp/swarming_targets', '--isolate-map-file',
'/fake_src/testing/buildbot/gn_isolate_map.pyl'], '/fake_src/testing/buildbot/gn_isolate_map.pyl'
files=test_files, ret=0) ],
files=test_files,
ret=0)
isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate'] isolate_file = mbw.files['/fake_src/out/Default/base_unittests.isolate']
isolate_file_contents = ast.literal_eval(isolate_file) isolate_file_contents = ast.literal_eval(isolate_file)
@ -763,42 +795,44 @@ class UnitTest(unittest.TestCase):
def test_isolate(self): def test_isolate(self):
files = { files = {
'/fake_src/out/Default/toolchain.ninja': "", '/fake_src/out/Default/toolchain.ninja':
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( "",
"{'base_unittests': {" '/fake_src/testing/buildbot/gn_isolate_map.pyl':
" 'label': '//base:base_unittests'," ("{'base_unittests': {"
" 'type': 'non_parallel_console_test_launcher'," " 'label': '//base:base_unittests',"
"}}\n" " 'type': 'non_parallel_console_test_launcher',"
), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': ( '/fake_src/out/Default/base_unittests.runtime_deps':
"base_unittests\n" ("base_unittests\n"),
),
} }
self.check(['isolate', '-c', 'debug_goma', '//out/Default', self.check(
'base_unittests'], files=files, ret=0) ['isolate', '-c', 'debug_goma', '//out/Default', 'base_unittests'],
files=files,
ret=0)
# test running isolate on an existing build_dir # test running isolate on an existing build_dir
files['/fake_src/out/Default/args.gn'] = 'is_debug = True\n' files['/fake_src/out/Default/args.gn'] = 'is_debug = True\n'
self.check(['isolate', '//out/Default', 'base_unittests'], self.check(['isolate', '//out/Default', 'base_unittests'],
files=files, ret=0) files=files,
ret=0)
files['/fake_src/out/Default/mb_type'] = 'gn\n' files['/fake_src/out/Default/mb_type'] = 'gn\n'
self.check(['isolate', '//out/Default', 'base_unittests'], self.check(['isolate', '//out/Default', 'base_unittests'],
files=files, ret=0) files=files,
ret=0)
def test_run(self): def test_run(self):
files = { files = {
'/fake_src/testing/buildbot/gn_isolate_map.pyl': ( '/fake_src/testing/buildbot/gn_isolate_map.pyl':
"{'base_unittests': {" ("{'base_unittests': {"
" 'label': '//base:base_unittests'," " 'label': '//base:base_unittests',"
" 'type': 'windowed_test_launcher'," " 'type': 'windowed_test_launcher',"
"}}\n" "}}\n"),
), '/fake_src/out/Default/base_unittests.runtime_deps':
'/fake_src/out/Default/base_unittests.runtime_deps': ( ("base_unittests\n"),
"base_unittests\n"
),
} }
self.check(['run', '-c', 'debug_goma', '//out/Default', self.check(['run', '-c', 'debug_goma', '//out/Default', 'base_unittests'],
'base_unittests'], files=files, ret=0) files=files,
ret=0)
def test_run_swarmed(self): def test_run_swarmed(self):
files = { files = {
@ -830,25 +864,33 @@ class UnitTest(unittest.TestCase):
mbw.ToSrcRelPath = to_src_rel_path_stub mbw.ToSrcRelPath = to_src_rel_path_stub
self.check(['run', '-s', '-c', 'debug_goma', '//out/Default', self.check(
'base_unittests'], mbw=mbw, ret=0) ['run', '-s', '-c', 'debug_goma', '//out/Default', 'base_unittests'],
mbw=mbw,
ret=0)
mbw = self.fake_mbw(files=files) mbw = self.fake_mbw(files=files)
mbw.files[mbw.PathJoin(mbw.TempDir(), 'task.json')] = task_json mbw.files[mbw.PathJoin(mbw.TempDir(), 'task.json')] = task_json
mbw.files[mbw.PathJoin(mbw.TempDir(), 'collect_output.json')] = collect_json mbw.files[mbw.PathJoin(mbw.TempDir(), 'collect_output.json')] = collect_json
mbw.ToSrcRelPath = to_src_rel_path_stub mbw.ToSrcRelPath = to_src_rel_path_stub
self.check(['run', '-s', '-c', 'debug_goma', '-d', 'os', 'Win7', self.check([
'//out/Default', 'base_unittests'], mbw=mbw, ret=0) 'run', '-s', '-c', 'debug_goma', '-d', 'os', 'Win7', '//out/Default',
'base_unittests'
],
mbw=mbw,
ret=0)
def test_lookup(self): def test_lookup(self):
self.check(['lookup', '-c', 'debug_goma'], ret=0) self.check(['lookup', '-c', 'debug_goma'], ret=0)
def test_quiet_lookup(self): def test_quiet_lookup(self):
self.check(['lookup', '-c', 'debug_goma', '--quiet'], ret=0, self.check(['lookup', '-c', 'debug_goma', '--quiet'],
ret=0,
out=('is_debug = true\n' out=('is_debug = true\n'
'use_goma = true\n')) 'use_goma = true\n'))
def test_lookup_goma_dir_expansion(self): def test_lookup_goma_dir_expansion(self):
self.check(['lookup', '-c', 'rel_bot', '-g', '/foo'], ret=0, self.check(['lookup', '-c', 'rel_bot', '-g', '/foo'],
ret=0,
out=('\n' out=('\n'
'Writing """\\\n' 'Writing """\\\n'
'enable_doom_melon = true\n' 'enable_doom_melon = true\n'
@ -875,22 +917,33 @@ class UnitTest(unittest.TestCase):
self.assertIn('Must specify a build --phase', mbw.out) self.assertIn('Must specify a build --phase', mbw.out)
# Check that passing a --phase to a single-phase builder fails. # Check that passing a --phase to a single-phase builder fails.
mbw = self.check(['lookup', '-m', 'fake_group', '-b', 'fake_builder', mbw = self.check([
'--phase', 'phase_1'], ret=1) 'lookup', '-m', 'fake_group', '-b', 'fake_builder', '--phase', 'phase_1'
],
ret=1)
self.assertIn('Must not specify a build --phase', mbw.out) self.assertIn('Must not specify a build --phase', mbw.out)
# Check that passing a wrong phase key to a multi-phase builder fails. # Check that passing a wrong phase key to a multi-phase builder fails.
mbw = self.check(['lookup', '-m', 'fake_group', '-b', 'fake_multi_phase', mbw = self.check([
'--phase', 'wrong_phase'], ret=1) 'lookup', '-m', 'fake_group', '-b', 'fake_multi_phase', '--phase',
'wrong_phase'
],
ret=1)
self.assertIn('Phase wrong_phase doesn\'t exist', mbw.out) self.assertIn('Phase wrong_phase doesn\'t exist', mbw.out)
# Check that passing a correct phase key to a multi-phase builder passes. # Check that passing a correct phase key to a multi-phase builder passes.
mbw = self.check(['lookup', '-m', 'fake_group', '-b', 'fake_multi_phase', mbw = self.check([
'--phase', 'phase_1'], ret=0) 'lookup', '-m', 'fake_group', '-b', 'fake_multi_phase', '--phase',
'phase_1'
],
ret=0)
self.assertIn('phase = 1', mbw.out) self.assertIn('phase = 1', mbw.out)
mbw = self.check(['lookup', '-m', 'fake_group', '-b', 'fake_multi_phase', mbw = self.check([
'--phase', 'phase_2'], ret=0) 'lookup', '-m', 'fake_group', '-b', 'fake_multi_phase', '--phase',
'phase_2'
],
ret=0)
self.assertIn('phase = 2', mbw.out) self.assertIn('phase = 2', mbw.out)
def test_validate(self): def test_validate(self):