epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Schema of the JSON summary file written out by the GM tool. |
| 7 | |
| 8 | This must be kept in sync with the kJsonKey_ constants in gm_expectations.cpp ! |
| 9 | """ |
| 10 | |
| 11 | __author__ = 'Elliot Poger' |
| 12 | |
| 13 | |
| 14 | # system-level imports |
| 15 | import json |
scroggo@google.com | d23e683 | 2013-10-10 21:09:24 +0000 | [diff] [blame] | 16 | import os |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 17 | |
| 18 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 19 | # Key strings used in GM results JSON files (both expected-results.json and |
| 20 | # actual-results.json). |
| 21 | # |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 22 | # These constants must be kept in sync with the kJsonKey_ constants in |
| 23 | # gm_expectations.cpp ! |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 24 | |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 25 | |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 26 | JSONKEY_ACTUALRESULTS = 'actual-results' |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 27 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 28 | # Tests whose results failed to match expectations. |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 29 | JSONKEY_ACTUALRESULTS_FAILED = 'failed' |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 30 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 31 | # Tests whose results failed to match expectations, but IGNOREFAILURE causes |
| 32 | # us to take them less seriously. |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 33 | JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored' |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 34 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 35 | # Tests for which we do not have any expectations. They may be new tests that |
| 36 | # we haven't had a chance to check in expectations for yet, or we may have |
| 37 | # consciously decided to leave them without expectations because we are unhappy |
| 38 | # with the results (although we should try to move away from that, and instead |
| 39 | # check in expectations with the IGNOREFAILURE flag set). |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 40 | JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison' |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 41 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 42 | # Tests whose results matched their expectations. |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 43 | JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded' |
| 44 | |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 45 | |
epoger@google.com | 53953b4 | 2013-07-02 20:22:27 +0000 | [diff] [blame] | 46 | JSONKEY_EXPECTEDRESULTS = 'expected-results' |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 47 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 48 | # One or more [HashType/DigestValue] pairs representing valid results for this |
| 49 | # test. Typically, there will just be one pair, but we allow for multiple |
| 50 | # expectations, and the test will pass if any one of them is matched. |
epoger@google.com | 53953b4 | 2013-07-02 20:22:27 +0000 | [diff] [blame] | 51 | JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests' |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 52 | |
| 53 | # Optional: one or more integers listing Skia bugs (under |
| 54 | # https://code.google.com/p/skia/issues/list ) that pertain to this expectation. |
| 55 | JSONKEY_EXPECTEDRESULTS_BUGS = 'bugs' |
| 56 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 57 | # If IGNOREFAILURE is set to True, a failure of this test will be reported |
| 58 | # within the FAILUREIGNORED section (thus NOT causing the buildbots to go red) |
| 59 | # rather than the FAILED section (which WOULD cause the buildbots to go red). |
epoger@google.com | 53953b4 | 2013-07-02 20:22:27 +0000 | [diff] [blame] | 60 | JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure' |
| 61 | |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 62 | # Optional: a free-form text string with human-readable information about |
| 63 | # this expectation. |
| 64 | JSONKEY_EXPECTEDRESULTS_NOTES = 'notes' |
| 65 | |
| 66 | # Optional: boolean indicating whether this expectation was reviewed/approved |
| 67 | # by a human being. |
| 68 | # If True: a human looked at this image and approved it. |
| 69 | # If False: this expectation was committed blind. (In such a case, please |
| 70 | # add notes indicating why!) |
| 71 | # If absent: this expectation was committed by a tool that didn't enforce human |
| 72 | # review of expectations. |
| 73 | JSONKEY_EXPECTEDRESULTS_REVIEWED = 'reviewed-by-human' |
| 74 | |
| 75 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 76 | # Allowed hash types for test expectations. |
epoger@google.com | 53953b4 | 2013-07-02 20:22:27 +0000 | [diff] [blame] | 77 | JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5' |
| 78 | |
epoger@google.com | 61822a2 | 2013-07-16 18:56:32 +0000 | [diff] [blame] | 79 | # Root directory where the buildbots store their actually-generated images... |
| 80 | # as a publicly readable HTTP URL: |
| 81 | GM_ACTUALS_ROOT_HTTP_URL = ( |
| 82 | 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm') |
| 83 | # as a GS URL that allows credential-protected write access: |
| 84 | GM_ACTUALS_ROOT_GS_URL = 'gs://chromium-skia-gm/gm' |
| 85 | |
scroggo@google.com | d23e683 | 2013-10-10 21:09:24 +0000 | [diff] [blame] | 86 | # Root directory where buildbots store skimage actual results json files. |
| 87 | SKIMAGE_ACTUALS_BASE_URL = ( |
| 88 | 'http://chromium-skia-gm.commondatastorage.googleapis.com/skimage/actuals') |
| 89 | # Root directory inside trunk where skimage expectations are stored. |
| 90 | SKIMAGE_EXPECTATIONS_ROOT = os.path.join('expectations', 'skimage') |
| 91 | |
epoger@google.com | 61822a2 | 2013-07-16 18:56:32 +0000 | [diff] [blame] | 92 | # Pattern used to assemble each image's filename |
scroggo@google.com | d048a3c | 2013-10-10 20:41:43 +0000 | [diff] [blame] | 93 | IMAGE_FILENAME_PATTERN = '(\S+)_(\S+)\.png' # matches (testname, config) |
epoger@google.com | 61822a2 | 2013-07-16 18:56:32 +0000 | [diff] [blame] | 94 | |
| 95 | def CreateGmActualUrl(test_name, hash_type, hash_digest, |
| 96 | gm_actuals_root_url=GM_ACTUALS_ROOT_HTTP_URL): |
| 97 | """Return the URL we can use to download a particular version of |
| 98 | the actually-generated image for this particular GM test. |
| 99 | |
| 100 | test_name: name of the test, e.g. 'perlinnoise' |
| 101 | hash_type: string indicating the hash type used to generate hash_digest, |
| 102 | e.g. JSONKEY_HASHTYPE_BITMAP_64BITMD5 |
| 103 | hash_digest: the hash digest of the image to retrieve |
| 104 | gm_actuals_root_url: root url where actual images are stored |
| 105 | """ |
| 106 | return '%s/%s/%s/%s.png' % (gm_actuals_root_url, hash_type, test_name, |
| 107 | hash_digest) |
| 108 | |
epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 109 | def LoadFromString(file_contents): |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 110 | """Loads the JSON summary written out by the GM tool. |
| 111 | Returns a dictionary keyed by the values listed as JSONKEY_ constants |
| 112 | above.""" |
epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 113 | # TODO(epoger): we should add a version number to the JSON file to ensure |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 114 | # that the writer and reader agree on the schema (raising an exception |
| 115 | # otherwise). |
epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 116 | json_dict = json.loads(file_contents) |
epoger@google.com | 9d33154 | 2013-05-28 15:25:38 +0000 | [diff] [blame] | 117 | return json_dict |
epoger@google.com | 4075fd4 | 2013-06-04 17:50:36 +0000 | [diff] [blame] | 118 | |
| 119 | def LoadFromFile(file_path): |
| 120 | """Loads the JSON summary written out by the GM tool. |
| 121 | Returns a dictionary keyed by the values listed as JSONKEY_ constants |
| 122 | above.""" |
| 123 | file_contents = open(file_path, 'r').read() |
| 124 | return LoadFromString(file_contents) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 125 | |
| 126 | def WriteToFile(json_dict, file_path): |
| 127 | """Writes the JSON summary in json_dict out to file_path.""" |
| 128 | with open(file_path, 'w') as outfile: |
| 129 | json.dump(json_dict, outfile, sort_keys=True, indent=2) |