Commit 8cb6aa78 authored by Dirk Pranke's avatar Dirk Pranke Committed by Commit Bot

Add initial support for `mb run --swarmed`.

This adds the initial support to MB to be able to build and run
a binary under swarming easily. It builds on the existing code
in MB for building and isolating targets, and just adds uploading
the isolate, triggering the task, waiting for and collecting the
results.
e
The end goal is that it should be this easy to reproduce a failure
in a bot config:

    $ fetch chromium && python src\tools\mb\mb.py run --swarmed \
        --master tryserver.chromium.win \
        --builder win-msvc-rel \
        out\Release base_unittests

Adding this gives us a starting framework that we can build on
for the bit.ly/chromium-test-runner-api cleanup work.

R=jbudorick@chromium.org, maruel@chromium.org
BUG=794783

Change-Id: I160706b1a563bceb36b8465857d32692a3ca004d
Reviewed-on: https://chromium-review.googlesource.com/825925
Commit-Queue: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarMarc-Antoine Ruel <maruel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524568}
parent 55fab54d
......@@ -132,6 +132,13 @@ incorporated into the appropriate flags for GN as needed.
Produces help output on the other subcommands
### `mb isolate`
Builds a given (ninja) target and produces an `.isolated` file suitable
for then running the command either locally in an isolated environment,
or remotely by uploading it to an isolate server and running it under
swarming. See below for more information on isolates and swarming.
### `mb lookup`
Prints what command will be run by `mb gen` (like `mb gen -n` but does
......@@ -141,6 +148,24 @@ The `-b/--builder`, `-c/--config`, `-f/--config-file`, `-m/--master`,
`--phase`, `-q/--quiet`, and `-v/--verbose` flags work as documented for
`mb gen`.
### `mb run`
Builds and runs a given (ninja) target. By default the target will
be run locally but isolated (i.e., outside of the source tree, just
as it would be run under swarming). If the `-s/--swarming` flag is
passed, the target will be built, run, uploaded to the isolate server,
and run under swarming.
By default, a set of dimensions appropriate for running the target in the
default pool for the build will be provided. You can specify additional
dimensions with the `-d/--dimension` flags, and you can skip the default
dimensions with the `--no-default-dimensions` flag (which can be useful
if you need to run on devices or in a different pool). See below for more
information on isolates and swarming.
In either case, any flags past `--` will be passed on to the command
to be run inside the isolate.
### `mb validate`
Does internal checking to make sure the config file is syntactically
......
......@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""MB - the Meta-Build wrapper around GN
"""MB - the Meta-Build wrapper around GN.
MB is a wrapper script for GN that can be used to generate build files
for sets of canned configurations and analyze them.
......@@ -17,6 +17,7 @@ import errno
import json
import os
import pipes
import platform
import pprint
import re
import shutil
......@@ -179,7 +180,6 @@ class MetaBuildWrapper(object):
' --test-launcher-retry-limit=0'
'\n'
)
AddCommonOptions(subp)
subp.add_argument('-j', '--jobs', dest='jobs', type=int,
help='Number of jobs to pass to ninja')
......@@ -191,6 +191,14 @@ class MetaBuildWrapper(object):
' This can be either a regular path or a '
'GN-style source-relative path like '
'//out/Default.'))
subp.add_argument('-s', '--swarmed', action='store_true',
help='Run under swarming with the default dimensions')
subp.add_argument('-d', '--dimension', default=[], action='append', nargs=2,
dest='dimensions', metavar='FOO bar',
help='dimension to filter on')
subp.add_argument('--no-default-dimensions', action='store_false',
dest='default_dimensions', default=True,
help='Do not automatically add dimensions to the task')
subp.add_argument('target', nargs=1,
help='ninja target to build and run')
subp.add_argument('extra_args', nargs='*',
......@@ -313,6 +321,49 @@ class MetaBuildWrapper(object):
if ret:
return ret
if self.args.swarmed:
return self._RunUnderSwarming(build_dir, target)
else:
return self._RunLocallyIsolated(build_dir, target)
def _RunUnderSwarming(self, build_dir, target):
# TODO(dpranke): Look up the information for the target in
# the //testing/buildbot.json file, if possible, so that we
# can determine the isolate target, command line, and additional
# swarming parameters, if possible.
#
# TODO(dpranke): Also, add support for sharding and merging results.
dimensions = []
for k, v in self._DefaultDimensions() + self.args.dimensions:
dimensions += ['-d', k, v]
cmd = [
self.executable,
self.PathJoin('tools', 'swarming_client', 'isolate.py'),
'archive',
'-s',
self.ToSrcRelPath('%s/%s.isolated' % (build_dir, target)),
'-I', 'isolateserver.appspot.com',
]
ret, out, _ = self.Run(cmd, force_verbose=False)
if ret:
return ret
isolated_hash = out.splitlines()[0].split()[0]
cmd = [
self.executable,
self.PathJoin('tools', 'swarming_client', 'swarming.py'),
'run',
'-s', isolated_hash,
'-I', 'isolateserver.appspot.com',
'-S', 'chromium-swarm.appspot.com',
] + dimensions
if self.args.extra_args:
cmd += ['--'] + self.args.extra_args
ret, _, _ = self.Run(cmd, force_verbose=True, buffer_output=False)
return ret
def _RunLocallyIsolated(self, build_dir, target):
cmd = [
self.executable,
self.PathJoin('tools', 'swarming_client', 'isolate.py'),
......@@ -322,10 +373,26 @@ class MetaBuildWrapper(object):
]
if self.args.extra_args:
cmd += ['--'] + self.args.extra_args
ret, _, _ = self.Run(cmd, force_verbose=True, buffer_output=False)
return ret
ret, _, _ = self.Run(cmd, force_verbose=False, buffer_output=False)
def _DefaultDimensions(self):
if not self.args.default_dimensions:
return []
return ret
# This code is naive and just picks reasonable defaults per platform.
if self.platform == 'darwin':
os_dim = ('os', 'Mac-10.12')
elif self.platform.startswith('linux'):
os_dim = ('os', 'Ubuntu-14.04')
elif self.platform == 'win32':
os_dim = ('os', 'Windows-10-14393')
else:
raise MBErr('unrecognized platform string "%s"' % self.platform)
return [('pool', 'Chrome'),
('cpu', 'x86-64'),
os_dim]
def CmdBuildbucket(self):
self.ReadConfigFile()
......
......@@ -478,6 +478,33 @@ class UnitTest(unittest.TestCase):
self.check(['run', '-c', 'debug_goma', '//out/Default',
'base_unittests'], files=files, ret=0)
def test_run_swarmed(self):
files = {
'/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"
),
}
def run_stub(cmd, **_kwargs):
if 'isolate.py' in cmd[1]:
return 0, 'fake_hash base_unittests', ''
else:
return 0, '', ''
mbw = self.fake_mbw(files=files)
mbw.Run = run_stub
self.check(['run', '-s', '-c', 'debug_goma', '//out/Default',
'base_unittests'], mbw=mbw, ret=0)
self.check(['run', '-s', '-c', 'debug_goma', '-d', 'os', 'Win7',
'//out/Default', 'base_unittests'], mbw=mbw, ret=0)
def test_lookup(self):
self.check(['lookup', '-c', 'debug_goma'], ret=0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment