OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Verify perf_expectations.json can be loaded using simplejson. | 7 """Verify perf_expectations.json can be loaded using simplejson. |
8 | 8 |
9 perf_expectations.json is a JSON-formatted file. This script verifies | 9 perf_expectations.json is a JSON-formatted file. This script verifies |
10 that simplejson can load it correctly. It should catch most common | 10 that simplejson can load it correctly. It should catch most common |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if not isinstance(perf_data[key], dict): | 98 if not isinstance(perf_data[key], dict): |
99 bad_keys.append(key) | 99 bad_keys.append(key) |
100 if len(bad_keys) > 0: | 100 if len(bad_keys) > 0: |
101 msg = "perf expectations keys have non-dict values" | 101 msg = "perf expectations keys have non-dict values" |
102 raise Exception("%s: %s" % (msg, bad_keys)) | 102 raise Exception("%s: %s" % (msg, bad_keys)) |
103 | 103 |
104 # Test all key values have delta and var keys. | 104 # Test all key values have delta and var keys. |
105 for key in perf_data: | 105 for key in perf_data: |
106 if key == 'load': | 106 if key == 'load': |
107 continue | 107 continue |
108 | 108 if 'delta' not in perf_data[key] or 'var' not in perf_data[key]: |
109 # First check if regress/improve is in the key's data. | 109 bad_keys.append(key) |
110 if 'regress' in perf_data[key]: | 110 if (not isinstance(perf_data[key]['delta'], int) and |
111 if 'improve' not in perf_data[key]: | 111 not isinstance(perf_data[key]['delta'], float)): |
112 bad_keys.append(key) | 112 bad_keys.append(key) |
113 if (not isinstance(perf_data[key]['regress'], int) and | 113 if (not isinstance(perf_data[key]['var'], int) and |
114 not isinstance(perf_data[key]['regress'], float)): | 114 not isinstance(perf_data[key]['var'], float)): |
115 bad_keys.append(key) | 115 bad_keys.append(key) |
116 if (not isinstance(perf_data[key]['improve'], int) and | |
117 not isinstance(perf_data[key]['improve'], float)): | |
118 bad_keys.append(key) | |
119 else: | |
120 # Otherwise check if delta/var is in the key's data. | |
121 if 'delta' not in perf_data[key] or 'var' not in perf_data[key]: | |
122 bad_keys.append(key) | |
123 if (not isinstance(perf_data[key]['delta'], int) and | |
124 not isinstance(perf_data[key]['delta'], float)): | |
125 bad_keys.append(key) | |
126 if (not isinstance(perf_data[key]['var'], int) and | |
127 not isinstance(perf_data[key]['var'], float)): | |
128 bad_keys.append(key) | |
129 | |
130 if len(bad_keys) > 0: | 116 if len(bad_keys) > 0: |
131 msg = "perf expectations key values missing or invalid delta/var" | 117 msg = "perf expectations key values missing or invalid delta/var" |
132 raise Exception("%s: %s" % (msg, bad_keys)) | 118 raise Exception("%s: %s" % (msg, bad_keys)) |
133 | 119 |
134 # Test all keys have the correct format. | 120 # Test all keys have the correct format. |
135 for key in perf_data: | 121 for key in perf_data: |
136 if key == 'load': | 122 if key == 'load': |
137 continue | 123 continue |
138 # tools/buildbot/scripts/master/log_parser.py should have a matching | 124 # tools/buildbot/scripts/master/log_parser.py should have a matching |
139 # regular expression. | 125 # regular expression. |
140 if not re.match(r"^([\w\.-]+)/([\w\.-]+)/([\w\.-]+)/([\w\.-]+)$", key): | 126 if not re.match(r"^([\w\.-]+)/([\w\.-]+)/([\w\.-]+)/([\w\.-]+)$", key): |
141 bad_keys.append(key) | 127 bad_keys.append(key) |
142 if len(bad_keys) > 0: | 128 if len(bad_keys) > 0: |
143 msg = "perf expectations keys in bad format, expected a/b/c/d" | 129 msg = "perf expectations keys in bad format, expected a/b/c/d" |
144 raise Exception("%s: %s" % (msg, bad_keys)) | 130 raise Exception("%s: %s" % (msg, bad_keys)) |
145 | 131 |
146 if __name__ == '__main__': | 132 if __name__ == '__main__': |
147 unittest.main() | 133 unittest.main() |
OLD | NEW |