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

Side by Side Diff: testing/buildbot/manage.py

Issue 1048213003: Add manage.py --convert to convert a test to run on Swarming everywhere. (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2_count_down
Patch Set: Rebased Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Toolbox to manage all the json files in this directory. 6 """Toolbox to manage all the json files in this directory.
7 7
8 It can reformat them in their canonical format or ensures they are well 8 It can reformat them in their canonical format or ensures they are well
9 formatted. 9 formatted.
10 """ 10 """
(...skipping 26 matching lines...) Expand all
37 return test 37 return test
38 38
39 39
40 def main(): 40 def main():
41 colorama.init() 41 colorama.init()
42 parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__) 42 parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)
43 group = parser.add_mutually_exclusive_group(required=True) 43 group = parser.add_mutually_exclusive_group(required=True)
44 group.add_argument( 44 group.add_argument(
45 '-c', '--check', action='store_true', help='Only check the files') 45 '-c', '--check', action='store_true', help='Only check the files')
46 group.add_argument( 46 group.add_argument(
47 '--convert', action='store_true',
48 help='Convert a test to run on Swarming everywhere')
49 group.add_argument(
47 '--remaining', action='store_true', 50 '--remaining', action='store_true',
48 help='Count the number of tests not yet running on Swarming') 51 help='Count the number of tests not yet running on Swarming')
49 group.add_argument( 52 group.add_argument(
50 '-w', '--write', action='store_true', help='Rewrite the files') 53 '-w', '--write', action='store_true', help='Rewrite the files')
51 parser.add_argument( 54 parser.add_argument(
52 'test_name', nargs='?', 55 'test_name', nargs='?',
53 help='The test name to print which configs to update; only to be used ' 56 help='The test name to print which configs to update; only to be used '
54 'with --remaining') 57 'with --remaining')
55 args = parser.parse_args() 58 args = parser.parse_args()
56 59
60 if args.convert and not args.test_name:
61 parser.error('A test name is required with --convert')
62
57 # Stats when running in --remaining mode; 63 # Stats when running in --remaining mode;
58 tests_location = collections.defaultdict( 64 tests_location = collections.defaultdict(
59 lambda: { 65 lambda: {
60 'count_run_local': 0, 'count_run_on_swarming': 0, 'local_configs': {} 66 'count_run_local': 0, 'count_run_on_swarming': 0, 'local_configs': {}
61 }) 67 })
62 68
63 result = 0 69 result = 0
64 for filepath in glob.glob(os.path.join(THIS_DIR, '*.json')): 70 for filepath in glob.glob(os.path.join(THIS_DIR, '*.json')):
65 filename = os.path.basename(filepath) 71 filename = os.path.basename(filepath)
66 with open(filepath) as f: 72 with open(filepath) as f:
(...skipping 15 matching lines...) Expand all
82 88
83 if args.remaining: 89 if args.remaining:
84 for test in data['gtest_tests']: 90 for test in data['gtest_tests']:
85 name = test['test'] 91 name = test['test']
86 if test.get('swarming', {}).get('can_use_on_swarming_builders'): 92 if test.get('swarming', {}).get('can_use_on_swarming_builders'):
87 tests_location[name]['count_run_on_swarming'] += 1 93 tests_location[name]['count_run_on_swarming'] += 1
88 else: 94 else:
89 tests_location[name]['count_run_local'] += 1 95 tests_location[name]['count_run_local'] += 1
90 tests_location[name]['local_configs'].setdefault( 96 tests_location[name]['local_configs'].setdefault(
91 filename, []).append(builder) 97 filename, []).append(builder)
98 elif args.convert:
99 for test in data['gtest_tests']:
100 if test['test'] != args.test_name:
101 continue
102 test.setdefault('swarming', {})['can_use_on_swarming_builders'] = (
103 True)
92 104
93 expected = json.dumps( 105 expected = json.dumps(
94 config, sort_keys=True, indent=2, separators=(',', ': ')) + '\n' 106 config, sort_keys=True, indent=2, separators=(',', ': ')) + '\n'
95 if content != expected: 107 if content != expected:
96 result = 1 108 result = 1
97 if args.write: 109 if args.write or args.convert:
98 with open(filepath, 'wb') as f: 110 with open(filepath, 'wb') as f:
99 f.write(expected) 111 f.write(expected)
100 print('Updated %s' % filename) 112 print('Updated %s' % filename)
101 else: 113 else:
102 print('%s is not in canonical format' % filename) 114 print('%s is not in canonical format' % filename)
103 115
104 if args.remaining: 116 if args.remaining:
105 if args.test_name: 117 if args.test_name:
106 if args.test_name not in tests_location: 118 if args.test_name not in tests_location:
107 print('Unknown test %s' % args.test_name) 119 print('Unknown test %s' % args.test_name)
(...skipping 26 matching lines...) Expand all
134 p_swarming = 100. * total_swarming / total 146 p_swarming = 100. * total_swarming / total
135 print('%s%-*s %4d (%4.1f%%) %4d (%4.1f%%)' % 147 print('%s%-*s %4d (%4.1f%%) %4d (%4.1f%%)' %
136 (colorama.Fore.WHITE, l, 'Total:', total_local, p_local, 148 (colorama.Fore.WHITE, l, 'Total:', total_local, p_local,
137 total_swarming, p_swarming)) 149 total_swarming, p_swarming))
138 print('%-*s %4d' % (l, 'Total executions:', total)) 150 print('%-*s %4d' % (l, 'Total executions:', total))
139 return result 151 return result
140 152
141 153
142 if __name__ == "__main__": 154 if __name__ == "__main__":
143 sys.exit(main()) 155 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698