blob: 2c37d6a35c51c40329e2a56b249661da62b10442 [file] [log] [blame]
epoger@google.com9d331542013-05-28 15:25:38 +00001#!/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
8This 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.org83aaf882013-12-18 15:28:24 +000015import io
epoger@google.com9d331542013-05-28 15:25:38 +000016import json
scroggo@google.comd23e6832013-10-10 21:09:24 +000017import os
epoger@google.com9d331542013-05-28 15:25:38 +000018
19
epoger@google.coma783f2b2013-07-08 17:51:58 +000020# Key strings used in GM results JSON files (both expected-results.json and
21# actual-results.json).
22#
epoger@google.com9d331542013-05-28 15:25:38 +000023# These constants must be kept in sync with the kJsonKey_ constants in
24# gm_expectations.cpp !
epoger@google.coma783f2b2013-07-08 17:51:58 +000025
epoger@google.com06e626d2013-09-03 17:32:15 +000026
epoger@google.com9d331542013-05-28 15:25:38 +000027JSONKEY_ACTUALRESULTS = 'actual-results'
epoger@google.com06e626d2013-09-03 17:32:15 +000028
epoger@google.coma783f2b2013-07-08 17:51:58 +000029# Tests whose results failed to match expectations.
epoger@google.com9d331542013-05-28 15:25:38 +000030JSONKEY_ACTUALRESULTS_FAILED = 'failed'
epoger@google.com06e626d2013-09-03 17:32:15 +000031
epoger@google.coma783f2b2013-07-08 17:51:58 +000032# Tests whose results failed to match expectations, but IGNOREFAILURE causes
33# us to take them less seriously.
epoger@google.com9d331542013-05-28 15:25:38 +000034JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored'
epoger@google.com06e626d2013-09-03 17:32:15 +000035
epoger@google.coma783f2b2013-07-08 17:51:58 +000036# 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.com9d331542013-05-28 15:25:38 +000041JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison'
epoger@google.com06e626d2013-09-03 17:32:15 +000042
epoger@google.coma783f2b2013-07-08 17:51:58 +000043# Tests whose results matched their expectations.
epoger@google.com9d331542013-05-28 15:25:38 +000044JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded'
45
epoger@google.com06e626d2013-09-03 17:32:15 +000046
epoger@google.com53953b42013-07-02 20:22:27 +000047JSONKEY_EXPECTEDRESULTS = 'expected-results'
epoger@google.com06e626d2013-09-03 17:32:15 +000048
epoger@google.coma783f2b2013-07-08 17:51:58 +000049# 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.com53953b42013-07-02 20:22:27 +000052JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests'
epoger@google.com06e626d2013-09-03 17:32:15 +000053
54# Optional: one or more integers listing Skia bugs (under
55# https://code.google.com/p/skia/issues/list ) that pertain to this expectation.
56JSONKEY_EXPECTEDRESULTS_BUGS = 'bugs'
57
epoger@google.coma783f2b2013-07-08 17:51:58 +000058# 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.com53953b42013-07-02 20:22:27 +000061JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure'
62
epoger@google.com06e626d2013-09-03 17:32:15 +000063# Optional: a free-form text string with human-readable information about
64# this expectation.
65JSONKEY_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.
74JSONKEY_EXPECTEDRESULTS_REVIEWED = 'reviewed-by-human'
75
76
epoger@google.coma783f2b2013-07-08 17:51:58 +000077# Allowed hash types for test expectations.
epoger@google.com53953b42013-07-02 20:22:27 +000078JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5'
79
epoger@google.com61822a22013-07-16 18:56:32 +000080# Root directory where the buildbots store their actually-generated images...
81# as a publicly readable HTTP URL:
82GM_ACTUALS_ROOT_HTTP_URL = (
83 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm')
84# as a GS URL that allows credential-protected write access:
85GM_ACTUALS_ROOT_GS_URL = 'gs://chromium-skia-gm/gm'
86
scroggo@google.comd23e6832013-10-10 21:09:24 +000087# Root directory where buildbots store skimage actual results json files.
88SKIMAGE_ACTUALS_BASE_URL = (
89 'http://chromium-skia-gm.commondatastorage.googleapis.com/skimage/actuals')
90# Root directory inside trunk where skimage expectations are stored.
91SKIMAGE_EXPECTATIONS_ROOT = os.path.join('expectations', 'skimage')
92
epoger@google.com61822a22013-07-16 18:56:32 +000093# Pattern used to assemble each image's filename
scroggo@google.comd048a3c2013-10-10 20:41:43 +000094IMAGE_FILENAME_PATTERN = '(\S+)_(\S+)\.png' # matches (testname, config)
epoger@google.com61822a22013-07-16 18:56:32 +000095
96def 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.com4075fd42013-06-04 17:50:36 +0000110def LoadFromString(file_contents):
epoger@google.com9d331542013-05-28 15:25:38 +0000111 """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.com4075fd42013-06-04 17:50:36 +0000114 # TODO(epoger): we should add a version number to the JSON file to ensure
epoger@google.com9d331542013-05-28 15:25:38 +0000115 # that the writer and reader agree on the schema (raising an exception
116 # otherwise).
epoger@google.com4075fd42013-06-04 17:50:36 +0000117 json_dict = json.loads(file_contents)
epoger@google.com9d331542013-05-28 15:25:38 +0000118 return json_dict
epoger@google.com4075fd42013-06-04 17:50:36 +0000119
120def 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.coma783f2b2013-07-08 17:51:58 +0000126
127def WriteToFile(json_dict, file_path):
commit-bot@chromium.org83aaf882013-12-18 15:28:24 +0000128 """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)))