OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 | |
3 """Starts bisect try jobs on multiple platforms using known-good configs. | |
4 | |
5 The purpose of this script is to serve as an integration test for the | |
6 auto-bisect project by starting try jobs for various config types and | |
7 various platforms. | |
8 | |
9 The known-good configs are in this same directory as this script. They | |
10 are expected to all end in ".cfg" and start with the name of the platform | |
11 followed by a dot. | |
12 | |
13 You can specify --full to try running each config on all applicable bots; | |
14 the default behavior is to try each config on only one bot. | |
15 """ | |
16 | |
17 import argparse | |
18 import logging | |
19 import os | |
20 import subprocess | |
21 import sys | |
22 | |
23 SCRIPT_DIR = os.path.dirname(__file__) | |
Sergiy Byelozyorov
2014/10/21 19:24:42
SCRIPT_DIR = os.path.abspath(os.path.dirname(__fil
qyearsley
2014/10/23 02:51:01
Ah, yes, right.
| |
24 BISECT_CONFIG = os.path.join(SCRIPT_DIR, os.path.pardir, 'bisect.cfg') | |
25 PERF_TEST_CONFIG = os.path.join( | |
26 SCRIPT_DIR, os.path.pardir, os.path.pardir, 'run-perf-test.cfg') | |
27 PLATFORM_BOT_MAP = { | |
28 'linux': ['linux_perf_bot'], | |
29 'mac': ['mac_perf_bisect', 'mac_10_9_perf_bisect'], | |
30 'win': ['win_perf_bisect', 'win_8_perf_bisect', 'win_xp_perf_bisect'], | |
31 'android': [ | |
32 'android_nexus4_perf_bisect', | |
33 'android_nexus5_perf_bisect', | |
34 'android_nexus7_perf_bisect', | |
35 'android_nexus10_perf_bisect', | |
36 ], | |
37 } | |
38 SVN_URL = 'svn://svn.chromium.org/chrome-try/try-perf' | |
39 AUTO_COMMIT_MESSAGE = 'Automatic commit for bisect try job.' | |
40 | |
41 | |
42 def main(argv): | |
43 parser = argparse.ArgumentParser(description=__doc__) | |
44 parser.add_argument('--full', action='store_true', | |
45 help='Run each config on all applicable bots.') | |
46 parser.add_argument('--filter', | |
47 help='Filter for config filenames to use. Only configs ' | |
48 'containing the given substring will be tried.') | |
49 parser.add_argument('--verbose', '-v', action='store_true') | |
50 args = parser.parse_args(argv[1:]) | |
51 _SetupLogging(args.verbose) | |
52 source_configs = _SourceConfigs(args.filter) | |
53 logging.debug('Source configs: %s', source_configs) | |
54 try: | |
55 _StartTryJobs(source_configs, args.full) | |
56 except subprocess.CalledProcessError as error: | |
57 print str(error) | |
58 print error.output | |
59 | |
60 | |
61 def _SetupLogging(verbose): | |
62 level = logging.INFO | |
63 if verbose: | |
64 level = logging.DEBUG | |
65 logging.basicConfig(level=level) | |
66 | |
67 | |
68 def _SourceConfigs(name_filter): | |
69 """Gets a list of paths to sample configs to try.""" | |
70 files = os.listdir(SCRIPT_DIR) | |
71 files = [os.path.join(SCRIPT_DIR, name) for name in files] | |
72 files = [name for name in files if name.endswith('.cfg')] | |
73 if name_filter: | |
74 files = [name for name in files if name_filter in name] | |
75 return files | |
76 | |
77 | |
78 def _StartTryJobs(source_configs, full_mode=False): | |
79 """Tries each of the given sample configs on one or more try bots.""" | |
80 for source_config in source_configs: | |
81 dest_config = _DestConfig(source_config) | |
82 bot_names = _BotNames(source_config, full_mode=full_mode) | |
83 _StartTry(source_config, dest_config, bot_names) | |
84 | |
85 | |
86 def _DestConfig(source_config): | |
87 """Returns the path that a sample config should be copied to.""" | |
88 if 'bisect' in source_config: | |
89 return BISECT_CONFIG | |
90 assert 'perf_test' in source_config, source_config | |
91 return PERF_TEST_CONFIG | |
92 | |
93 | |
94 def _BotNames(source_config, full_mode=False): | |
95 """Returns try bot names to use for the given config file name.""" | |
96 platform = os.path.basename(source_config).split('.')[0] | |
97 assert platform in PLATFORM_BOT_MAP | |
98 bot_names = PLATFORM_BOT_MAP[platform] | |
99 if full_mode: | |
100 return bot_names | |
101 return [bot_names[0]] | |
102 | |
103 | |
104 def _StartTry(source_config, dest_config, bot_names): | |
105 """Sends a try job with the given config to the given try bots. | |
106 | |
107 Args: | |
108 source_config: Path of the sample config to copy over. | |
109 dest_config: Destination path to copy sample to, e.g. "./bisect.cfg". | |
110 bot_names: List of try bot builder names. | |
111 """ | |
112 assert os.path.exists(source_config) | |
113 assert os.path.exists(dest_config) | |
114 assert _LastCommitMessage() != AUTO_COMMIT_MESSAGE | |
115 | |
116 # Copy the sample config over and commit it. | |
117 _Run(['cp', source_config, dest_config]) | |
118 _Run(['git', 'commit', '--all', '-m', AUTO_COMMIT_MESSAGE]) | |
119 | |
120 try: | |
121 # Start the try job. | |
122 job_name = 'Automatically-started job with sample config %s' % source_config | |
123 try_command = ['git', 'try', '--svn_repo', SVN_URL, '-n', job_name] | |
124 for bot_name in bot_names: | |
125 try_command.extend(['-b', bot_name]) | |
126 print _Run(try_command) | |
127 finally: | |
128 # Revert the immediately-previous commit which was made just above. | |
129 assert _LastCommitMessage() == AUTO_COMMIT_MESSAGE | |
130 _Run(['git', 'reset', '--hard', 'HEAD~1']) | |
131 | |
132 | |
133 def _LastCommitMessage(): | |
134 return _Run(['git', 'log', '--format=%s', '-1']).strip() | |
135 | |
136 | |
137 def _Run(command): | |
138 logging.debug('Running %s', command) | |
139 # Note: check_output will raise a subprocess.CalledProcessError when | |
140 # the return-code is non-zero. | |
141 return subprocess.check_output(command) | |
142 | |
143 | |
144 if __name__ == '__main__': | |
145 sys.exit(main(sys.argv)) | |
OLD | NEW |