2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Starts bisect try jobs on multiple platforms using known-good configs.
8 The purpose of this script is to serve as an integration test for the
9 auto-bisect project by starting try jobs for various config types and
12 The known-good configs are in this same directory as this script. They
13 are expected to all end in ".cfg" and start with the name of the platform
16 You can specify --full to try running each config on all applicable bots;
17 the default behavior is to try each config on only one bot.
26 SCRIPT_DIR
= os
.path
.abspath(os
.path
.dirname(__file__
))
27 BISECT_CONFIG
= os
.path
.join(SCRIPT_DIR
, os
.path
.pardir
, 'bisect.cfg')
28 PERF_TEST_CONFIG
= os
.path
.join(
29 SCRIPT_DIR
, os
.path
.pardir
, os
.path
.pardir
, 'run-perf-test.cfg')
31 'linux': ['linux_perf_bisect'],
32 'mac': ['mac_perf_bisect', 'mac_10_9_perf_bisect'],
33 'win': ['win_perf_bisect', 'win_8_perf_bisect', 'win_xp_perf_bisect'],
34 'winx64': ['win_x64_perf_bisect'],
36 'android_gn_perf_bisect',
37 'android_nexus4_perf_bisect',
38 'android_nexus5_perf_bisect',
39 'android_nexus7_perf_bisect',
40 'android_nexus10_perf_bisect',
43 SVN_URL
= 'svn://svn.chromium.org/chrome-try/try-perf'
44 AUTO_COMMIT_MESSAGE
= 'Automatic commit for bisect try job.'
48 parser
= argparse
.ArgumentParser(description
=__doc__
)
49 parser
.add_argument('--full', action
='store_true',
50 help='Run each config on all applicable bots.')
51 parser
.add_argument('configs', nargs
='+',
52 help='One or more sample config files.')
53 parser
.add_argument('--verbose', '-v', action
='store_true',
54 help='Output additional debugging information.')
55 parser
.add_argument('--dry-run', action
='store_true',
56 help='Don\'t execute "git try" while running.')
57 args
= parser
.parse_args(argv
[1:])
58 _SetupLogging(args
.verbose
)
59 logging
.debug('Source configs: %s', args
.configs
)
61 _StartTryJobs(args
.configs
, args
.full
, args
.dry_run
)
62 except subprocess
.CalledProcessError
as error
:
67 def _SetupLogging(verbose
):
71 logging
.basicConfig(level
=level
)
74 def _StartTryJobs(source_configs
, full_mode
=False, dry_run
=False):
75 """Tries each of the given sample configs on one or more try bots."""
76 for source_config
in source_configs
:
77 dest_config
= _DestConfig(source_config
)
78 bot_names
= _BotNames(source_config
, full_mode
=full_mode
)
79 _StartTry(source_config
, dest_config
, bot_names
, dry_run
=dry_run
)
82 def _DestConfig(source_config
):
83 """Returns the path that a sample config should be copied to."""
84 if 'bisect' in source_config
:
86 assert 'perf_test' in source_config
, source_config
87 return PERF_TEST_CONFIG
90 def _BotNames(source_config
, full_mode
=False):
91 """Returns try bot names to use for the given config file name."""
92 platform
= os
.path
.basename(source_config
).split('.')[0]
93 assert platform
in PLATFORM_BOT_MAP
94 bot_names
= PLATFORM_BOT_MAP
[platform
]
100 def _StartTry(source_config
, dest_config
, bot_names
, dry_run
=False):
101 """Sends a try job with the given config to the given try bots.
104 source_config: Path of the sample config to copy over.
105 dest_config: Destination path to copy sample to, e.g. "./bisect.cfg".
106 bot_names: List of try bot builder names.
108 assert os
.path
.exists(source_config
)
109 assert os
.path
.exists(dest_config
)
110 assert _LastCommitMessage() != AUTO_COMMIT_MESSAGE
112 # Copy the sample config over and commit it.
113 _Run(['cp', source_config
, dest_config
])
114 _Run(['git', 'commit', '--all', '-m', AUTO_COMMIT_MESSAGE
])
118 job_name
= 'Automatically-started (%s)' % os
.path
.basename(source_config
)
119 try_command
= ['git', 'try', '--svn_repo', SVN_URL
, '--name', job_name
]
120 for bot_name
in bot_names
:
121 try_command
.extend(['--bot', bot_name
])
122 print _Run(try_command
, dry_run
=dry_run
)
124 # Revert the immediately-previous commit which was made just above.
125 assert _LastCommitMessage() == AUTO_COMMIT_MESSAGE
126 _Run(['git', 'reset', '--hard', 'HEAD~1'])
129 def _LastCommitMessage():
130 return _Run(['git', 'log', '--format=%s', '-1']).strip()
133 def _Run(command
, dry_run
=False):
134 """Runs a command in a subprocess.
137 command: The command given as an args list.
140 The output of the command.
143 subprocess.CalledProcessError: The return-code was non-zero.
145 logging
.debug('Running %s', command
)
147 return 'Did not run command because this is a dry run.'
148 return subprocess
.check_output(command
)
151 if __name__
== '__main__':
152 sys
.exit(main(sys
.argv
))