OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """Schema of the JSON summary file written out by the GM tool. | 6 """Schema of the JSON summary file written out by the GM tool. |
7 | 7 |
8 This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp ! | 8 This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp ! |
9 """ | 9 """ |
10 | 10 |
11 __author__ = 'Elliot Poger' | 11 __author__ = 'Elliot Poger' |
12 | 12 |
13 | 13 |
14 # system-level imports | 14 # system-level imports |
15 import json | 15 import json |
16 | 16 |
17 | 17 |
| 18 # Key strings used in GM results JSON files (both expected-results.json and |
| 19 # actual-results.json). |
| 20 # |
18 # These constants must be kept in sync with the kJsonKey_ constants in | 21 # These constants must be kept in sync with the kJsonKey_ constants in |
19 # gm_expectations.cpp ! | 22 # gm_expectations.cpp ! |
| 23 |
20 JSONKEY_ACTUALRESULTS = 'actual-results' | 24 JSONKEY_ACTUALRESULTS = 'actual-results' |
| 25 # Tests whose results failed to match expectations. |
21 JSONKEY_ACTUALRESULTS_FAILED = 'failed' | 26 JSONKEY_ACTUALRESULTS_FAILED = 'failed' |
| 27 # Tests whose results failed to match expectations, but IGNOREFAILURE causes |
| 28 # us to take them less seriously. |
22 JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored' | 29 JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored' |
| 30 # Tests for which we do not have any expectations. They may be new tests that |
| 31 # we haven't had a chance to check in expectations for yet, or we may have |
| 32 # consciously decided to leave them without expectations because we are unhappy |
| 33 # with the results (although we should try to move away from that, and instead |
| 34 # check in expectations with the IGNOREFAILURE flag set). |
23 JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison' | 35 JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison' |
| 36 # Tests whose results matched their expectations. |
24 JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded' | 37 JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded' |
25 | 38 |
26 JSONKEY_EXPECTEDRESULTS = 'expected-results' | 39 JSONKEY_EXPECTEDRESULTS = 'expected-results' |
| 40 # One or more [HashType/DigestValue] pairs representing valid results for this |
| 41 # test. Typically, there will just be one pair, but we allow for multiple |
| 42 # expectations, and the test will pass if any one of them is matched. |
27 JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests' | 43 JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests' |
| 44 # If IGNOREFAILURE is set to True, a failure of this test will be reported |
| 45 # within the FAILUREIGNORED section (thus NOT causing the buildbots to go red) |
| 46 # rather than the FAILED section (which WOULD cause the buildbots to go red). |
28 JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure' | 47 JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure' |
29 | 48 |
| 49 # Allowed hash types for test expectations. |
30 JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5' | 50 JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5' |
31 | 51 |
32 def LoadFromString(file_contents): | 52 def LoadFromString(file_contents): |
33 """Loads the JSON summary written out by the GM tool. | 53 """Loads the JSON summary written out by the GM tool. |
34 Returns a dictionary keyed by the values listed as JSONKEY_ constants | 54 Returns a dictionary keyed by the values listed as JSONKEY_ constants |
35 above.""" | 55 above.""" |
36 # TODO(epoger): we should add a version number to the JSON file to ensure | 56 # TODO(epoger): we should add a version number to the JSON file to ensure |
37 # that the writer and reader agree on the schema (raising an exception | 57 # that the writer and reader agree on the schema (raising an exception |
38 # otherwise). | 58 # otherwise). |
39 json_dict = json.loads(file_contents) | 59 json_dict = json.loads(file_contents) |
40 return json_dict | 60 return json_dict |
41 | 61 |
42 def LoadFromFile(file_path): | 62 def LoadFromFile(file_path): |
43 """Loads the JSON summary written out by the GM tool. | 63 """Loads the JSON summary written out by the GM tool. |
44 Returns a dictionary keyed by the values listed as JSONKEY_ constants | 64 Returns a dictionary keyed by the values listed as JSONKEY_ constants |
45 above.""" | 65 above.""" |
46 file_contents = open(file_path, 'r').read() | 66 file_contents = open(file_path, 'r').read() |
47 return LoadFromString(file_contents) | 67 return LoadFromString(file_contents) |
| 68 |
| 69 def WriteToFile(json_dict, file_path): |
| 70 """Writes the JSON summary in json_dict out to file_path.""" |
| 71 with open(file_path, 'w') as outfile: |
| 72 json.dump(json_dict, outfile, sort_keys=True, indent=2) |
OLD | NEW |