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 if 'delta' not in perf_data[key] or 'var' not in perf_data[key]: | 108 |
109 bad_keys.append(key) | 109 # First check if regress/improve is in the key's data. |
110 if (not isinstance(perf_data[key]['delta'], int) and | 110 if 'regress' in perf_data[key]: |
111 not isinstance(perf_data[key]['delta'], float)): | 111 if 'improve' not in perf_data[key]: |
112 bad_keys.append(key) | 112 bad_keys.append(key) |
113 if (not isinstance(perf_data[key]['var'], int) and | 113 if (not isinstance(perf_data[key]['regress'], int) and |
114 not isinstance(perf_data[key]['var'], float)): | 114 not isinstance(perf_data[key]['regress'], 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 |
116 if len(bad_keys) > 0: | 130 if len(bad_keys) > 0: |
117 msg = "perf expectations key values missing or invalid delta/var" | 131 msg = "perf expectations key values missing or invalid delta/var" |
118 raise Exception("%s: %s" % (msg, bad_keys)) | 132 raise Exception("%s: %s" % (msg, bad_keys)) |
119 | 133 |
120 # Test all keys have the correct format. | 134 # Test all keys have the correct format. |
121 for key in perf_data: | 135 for key in perf_data: |
122 if key == 'load': | 136 if key == 'load': |
123 continue | 137 continue |
124 # tools/buildbot/scripts/master/log_parser.py should have a matching | 138 # tools/buildbot/scripts/master/log_parser.py should have a matching |
125 # regular expression. | 139 # regular expression. |
126 if not re.match(r"^([\w\.-]+)/([\w\.-]+)/([\w\.-]+)/([\w\.-]+)$", key): | 140 if not re.match(r"^([\w\.-]+)/([\w\.-]+)/([\w\.-]+)/([\w\.-]+)$", key): |
127 bad_keys.append(key) | 141 bad_keys.append(key) |
128 if len(bad_keys) > 0: | 142 if len(bad_keys) > 0: |
129 msg = "perf expectations keys in bad format, expected a/b/c/d" | 143 msg = "perf expectations keys in bad format, expected a/b/c/d" |
130 raise Exception("%s: %s" % (msg, bad_keys)) | 144 raise Exception("%s: %s" % (msg, bad_keys)) |
131 | 145 |
132 if __name__ == '__main__': | 146 if __name__ == '__main__': |
133 unittest.main() | 147 unittest.main() |
OLD | NEW |