Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: build/android/buildbot/bb_run_bot.py

Issue 11666023: Move android buildbot test logic into python (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/buildbot/bb_perf_gn_tests.sh ('k') | build/android/buildbot/bb_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import collections
8 import json
9 import optparse
10 import os
11 import pipes
12 import subprocess
13 import sys
14
15 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
16 from pylib import buildbot_report
17
18 CHROME_SRC = os.path.abspath(
19 os.path.join(os.path.dirname(__file__), '..', '..', '..'))
20
21 GLOBAL_SLAVE_PROPS = {}
22
23 BotConfig = collections.namedtuple(
24 'BotConfig', ['bot_id', 'bash_funs', 'test_obj', 'slave_props'])
25 TestConfig = collections.namedtuple('Tests', ['tests', 'extra_args'])
26 Command = collections.namedtuple('Command', ['step_name', 'command'])
27
28
29 def GetCommands(options, bot_config):
30 """Get a formatted list of commands.
31
32 Args:
33 options: Options object.
34 bot_config: A BotConfig named tuple.
35 Returns:
36 list of Command objects.
37 """
38 slave_props = dict(GLOBAL_SLAVE_PROPS)
39 if bot_config.slave_props:
40 slave_props.update(bot_config.slave_props)
41
42 property_args = [
43 '--factory-properties=%s' % json.dumps(options.factory_properties),
44 '--build-properties=%s' % json.dumps(options.build_properties),
45 '--slave-properties=%s' % json.dumps(slave_props)]
46
47 commands = []
48 if bot_config.bash_funs:
49 bash_base = [
50 '. build/android/buildbot/buildbot_functions.sh',
51 "bb_baseline_setup %s '%s'" %
52 (CHROME_SRC, "' '".join(property_args))]
53 commands.append(Command(
54 None, ['bash', '-exc', ' && '.join(bash_base + bot_config.bash_funs)]))
55
56 test_obj = bot_config.test_obj
57 if test_obj:
58 run_test_cmd = ['build/android/buildbot/bb_tests.py'] + property_args
59 for test in test_obj.tests:
60 run_test_cmd.extend(['-f', test])
61 if test_obj.extra_args:
62 run_test_cmd.extend(test_obj.extra_args)
63 commands.append(Command('Run tests', run_test_cmd))
64
65 return commands
66
67
68 def GetBotStepMap():
69 std_build_steps = ['bb_compile', 'bb_zip_build']
70 std_test_steps = ['bb_extract_build', 'bb_reboot_phones']
71 std_tests = ['ui', 'unit']
72
73 B = BotConfig
74 def T(tests, extra_args=None):
75 return TestConfig(tests, extra_args)
76
77 bot_configs = [
78 # Main builders
79 B('main-builder-dbg',
80 ['bb_compile', 'bb_run_findbugs', 'bb_zip_build'], None, None),
81 B('main-builder-rel', std_build_steps, None, None),
82 B('main-clang-builder', ['bb_compile'], None, None),
83 B('main-clobber', ['bb_compile'], None, None),
84 B('main-tests-dbg', std_test_steps, T(std_tests), None),
85
86 # Other waterfalls
87 B('asan-builder', std_build_steps, None, None),
88 B('asan-tests', std_test_steps, T(std_tests, ['--asan']), None),
89 B('fyi-builder-dbg',
90 ['bb_check_webview_licenses', 'bb_compile', 'bb_compile_experimental',
91 'bb_run_findbugs', 'bb_zip_build'], None, None),
92 B('fyi-builder-rel',
93 ['bb_compile', 'bb_compile_experimental', 'bb_zip_build'], None, None),
94 B('fyi-tests', std_test_steps, T(std_tests, ['--experimental']), None),
95 B('perf-builder-rel', std_build_steps, None, None),
96 B('perf-tests-rel', std_test_steps, T([], ['--install=ContentShell']),
97 None),
98 B('webkit-latest-builder', std_build_steps, None, None),
99 B('webkit-latest-tests', std_test_steps, T(['unit']), None),
100 B('webkit-latest-webkit-tests', std_test_steps,
101 T(['webkit_layout', 'webkit']), None),
102 ]
103
104 bot_map = dict((config.bot_id, config) for config in bot_configs)
105
106 # These bots have identical configuration to ones defined earlier.
107 copy_map = [
108 ('try-builder-dbg', 'main-builder-dbg'),
109 ('try-tests-dbg', 'main-tests-dbg'),
110 ('try-clang-builder', 'main-clang-builder'),
111 ('try-fyi-builder-dbg', 'fyi-builder-dbg'),
112 ('try-fyi-tests', 'fyi-tests'),
113 ]
114 for to_id, from_id in copy_map:
115 assert to_id not in bot_map
116 # pylint: disable=W0212
117 bot_map[to_id] = bot_map[from_id]._replace(bot_id=to_id)
118
119 return bot_map
120
121
122 def main(argv):
123 parser = optparse.OptionParser()
124
125 def ConvertJson(option, _, value, parser):
126 setattr(parser.values, option.dest, json.loads(value))
127
128 parser.add_option('--build-properties', action='callback',
129 callback=ConvertJson, type='string', default={},
130 help='build properties in JSON format')
131 parser.add_option('--factory-properties', action='callback',
132 callback=ConvertJson, type='string', default={},
133 help='factory properties in JSON format')
134 parser.add_option('--bot-id', help='Specify bot id directly.')
135 parser.add_option('--TESTING', action='store_true',
136 help='For testing: print, but do not run commands')
137 options, args = parser.parse_args(argv[1:])
138 if args:
139 parser.error('Unused args: %s' % args)
140
141 bot_id = options.bot_id or options.factory_properties.get('bot_id')
142 if not bot_id:
143 parser.error('A bot id must be specified through option or factory_props.')
144
145 # Get a BotConfig object looking first for an exact bot-id match. If no exact
146 # match, look for a bot-id which is a substring of the specified id.
147 # This allows similar bots can have unique IDs, but to share config.
148 bot_map = GetBotStepMap()
149 bot_config = bot_map.get(bot_id)
150 if not bot_config:
151 for cur_id, cur_config in bot_map.iteritems():
152 if cur_id in bot_id:
153 print 'Using config from id="%s" (substring match).' % cur_id
154 bot_config = cur_config
155 break
156 if not bot_config:
157 print 'Error: config for id="%s" cannot be inferred.' % bot_id
158 return 1
159
160 print 'Using config:', bot_config
161
162 def CommandToString(command):
163 """Returns quoted command that can be run in bash shell."""
164 return ' '.join(map(pipes.quote, command))
165
166 command_objs = GetCommands(options, bot_config)
167 for command_obj in command_objs:
168 print 'Will run:', CommandToString(command_obj.command)
169
170 return_code = 0
171 for command_obj in command_objs:
172 if command_obj.step_name:
173 buildbot_report.PrintNamedStep(command_obj.step_name)
174 command = command_obj.command
175 print CommandToString(command)
176 sys.stdout.flush()
177 env = None
178 if options.TESTING:
179 # The bash command doesn't yet support the testing option.
180 if command[0] == 'bash':
181 continue
182 env = dict(os.environ)
183 env['BUILDBOT_TESTING'] = '1'
184
185 return_code |= subprocess.call(command, cwd=CHROME_SRC, env=env)
186 return return_code
187
188
189 if __name__ == '__main__':
190 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/android/buildbot/bb_perf_gn_tests.sh ('k') | build/android/buildbot/bb_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698