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