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_10_9_perf_bisect', 'mac_10_10_perf_bisect'],
33 'win': ['win_perf_bisect', 'win_8_perf_bisect', 'win_xp_perf_bisect'],
34 'winx64': ['win_x64_perf_bisect'],
36 'android_nexus4_perf_bisect',
37 'android_nexus5_perf_bisect',
38 'android_nexus7_perf_bisect',
41 SVN_URL
= 'svn://svn.chromium.org/chrome-try/try-perf'
42 AUTO_COMMIT_MESSAGE
= 'Automatic commit for bisect try job.'
46 parser
= argparse
.ArgumentParser(description
=__doc__
)
47 parser
.add_argument('--full', action
='store_true',
48 help='Run each config on all applicable bots.')
49 parser
.add_argument('configs', nargs
='+',
50 help='One or more sample config files.')
51 parser
.add_argument('--verbose', '-v', action
='store_true',
52 help='Output additional debugging information.')
53 parser
.add_argument('--dry-run', action
='store_true',
54 help='Don\'t execute "git try" while running.')
55 args
= parser
.parse_args(argv
[1:])
56 _SetupLogging(args
.verbose
)
57 logging
.debug('Source configs: %s', args
.configs
)
59 _StartTryJobs(args
.configs
, args
.full
, args
.dry_run
)
60 except subprocess
.CalledProcessError
as error
:
65 def _SetupLogging(verbose
):
69 logging
.basicConfig(level
=level
)
72 def _StartTryJobs(source_configs
, full_mode
=False, dry_run
=False):
73 """Tries each of the given sample configs on one or more try bots."""
74 for source_config
in source_configs
:
75 dest_config
= _DestConfig(source_config
)
76 bot_names
= _BotNames(source_config
, full_mode
=full_mode
)
77 _StartTry(source_config
, dest_config
, bot_names
, dry_run
=dry_run
)
80 def _DestConfig(source_config
):
81 """Returns the path that a sample config should be copied to."""
82 if 'bisect' in source_config
:
84 assert 'perf_test' in source_config
, source_config
85 return PERF_TEST_CONFIG
88 def _BotNames(source_config
, full_mode
=False):
89 """Returns try bot names to use for the given config file name."""
90 platform
= os
.path
.basename(source_config
).split('.')[0]
91 assert platform
in PLATFORM_BOT_MAP
92 bot_names
= PLATFORM_BOT_MAP
[platform
]
98 def _StartTry(source_config
, dest_config
, bot_names
, dry_run
=False):
99 """Sends a try job with the given config to the given try bots.
102 source_config: Path of the sample config to copy over.
103 dest_config: Destination path to copy sample to, e.g. "./bisect.cfg".
104 bot_names: List of try bot builder names.
106 assert os
.path
.exists(source_config
)
107 assert os
.path
.exists(dest_config
)
108 assert _LastCommitMessage() != AUTO_COMMIT_MESSAGE
110 # Copy the sample config over and commit it.
111 _Run(['cp', source_config
, dest_config
])
112 _Run(['git', 'commit', '--all', '-m', AUTO_COMMIT_MESSAGE
])
116 job_name
= 'Automatically-started (%s)' % os
.path
.basename(source_config
)
117 try_command
= ['git', 'try', '--svn_repo', SVN_URL
, '--name', job_name
]
118 for bot_name
in bot_names
:
119 try_command
.extend(['--bot', bot_name
])
120 print _Run(try_command
, dry_run
=dry_run
)
122 # Revert the immediately-previous commit which was made just above.
123 assert _LastCommitMessage() == AUTO_COMMIT_MESSAGE
124 _Run(['git', 'reset', '--hard', 'HEAD~1'])
127 def _LastCommitMessage():
128 return _Run(['git', 'log', '--format=%s', '-1']).strip()
131 def _Run(command
, dry_run
=False):
132 """Runs a command in a subprocess.
135 command: The command given as an args list.
138 The output of the command.
141 subprocess.CalledProcessError: The return-code was non-zero.
143 logging
.debug('Running %s', command
)
145 return 'Did not run command because this is a dry run.'
146 return subprocess
.check_output(command
)
149 if __name__
== '__main__':
150 sys
.exit(main(sys
.argv
))