blob: 1d8da9f12799af8621bb72c1642e94b4695faa01 [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
15import json
scroggo@google.comd23e6832013-10-10 21:09:24 +000016import os
epoger@google.com9d331542013-05-28 15:25:38 +000017
18
epoger@google.coma783f2b2013-07-08 17:51:58 +000019# Key strings used in GM results JSON files (both expected-results.json and
20# actual-results.json).
21#
epoger@google.com9d331542013-05-28 15:25:38 +000022# These constants must be kept in sync with the kJsonKey_ constants in
23# gm_expectations.cpp !
epoger@google.coma783f2b2013-07-08 17:51:58 +000024
epoger@google.com06e626d2013-09-03 17:32:15 +000025
epoger@google.com9d331542013-05-28 15:25:38 +000026JSONKEY_ACTUALRESULTS = 'actual-results'
epoger@google.com06e626d2013-09-03 17:32:15 +000027
epoger@google.coma783f2b2013-07-08 17:51:58 +000028# Tests whose results failed to match expectations.
epoger@google.com9d331542013-05-28 15:25:38 +000029JSONKEY_ACTUALRESULTS_FAILED = 'failed'
epoger@google.com06e626d2013-09-03 17:32:15 +000030
epoger@google.coma783f2b2013-07-08 17:51:58 +000031# Tests whose results failed to match expectations, but IGNOREFAILURE causes
32# us to take them less seriously.
epoger@google.com9d331542013-05-28 15:25:38 +000033JSONKEY_ACTUALRESULTS_FAILUREIGNORED = 'failure-ignored'
epoger@google.com06e626d2013-09-03 17:32:15 +000034
epoger@google.coma783f2b2013-07-08 17:51:58 +000035# 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.com9d331542013-05-28 15:25:38 +000040JSONKEY_ACTUALRESULTS_NOCOMPARISON = 'no-comparison'
epoger@google.com06e626d2013-09-03 17:32:15 +000041
epoger@google.coma783f2b2013-07-08 17:51:58 +000042# Tests whose results matched their expectations.
epoger@google.com9d331542013-05-28 15:25:38 +000043JSONKEY_ACTUALRESULTS_SUCCEEDED = 'succeeded'
44
epoger@google.com06e626d2013-09-03 17:32:15 +000045
epoger@google.com53953b42013-07-02 20:22:27 +000046JSONKEY_EXPECTEDRESULTS = 'expected-results'
epoger@google.com06e626d2013-09-03 17:32:15 +000047
epoger@google.coma783f2b2013-07-08 17:51:58 +000048# 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.com53953b42013-07-02 20:22:27 +000051JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS = 'allowed-digests'
epoger@google.com06e626d2013-09-03 17:32:15 +000052
53# Optional: one or more integers listing Skia bugs (under
54# https://code.google.com/p/skia/issues/list ) that pertain to this expectation.
55JSONKEY_EXPECTEDRESULTS_BUGS = 'bugs'
56
epoger@google.coma783f2b2013-07-08 17:51:58 +000057# 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.com53953b42013-07-02 20:22:27 +000060JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE = 'ignore-failure'
61
epoger@google.com06e626d2013-09-03 17:32:15 +000062# Optional: a free-form text string with human-readable information about
63# this expectation.
64JSONKEY_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.
73JSONKEY_EXPECTEDRESULTS_REVIEWED = 'reviewed-by-human'
74
75
epoger@google.coma783f2b2013-07-08 17:51:58 +000076# Allowed hash types for test expectations.
epoger@google.com53953b42013-07-02 20:22:27 +000077JSONKEY_HASHTYPE_BITMAP_64BITMD5 = 'bitmap-64bitMD5'
78
epoger@google.com61822a22013-07-16 18:56:32 +000079# Root directory where the buildbots store their actually-generated images...
80# as a publicly readable HTTP URL:
81GM_ACTUALS_ROOT_HTTP_URL = (
82 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm')
83# as a GS URL that allows credential-protected write access:
84GM_ACTUALS_ROOT_GS_URL = 'gs://chromium-skia-gm/gm'
85
scroggo@google.comd23e6832013-10-10 21:09:24 +000086# Root directory where buildbots store skimage actual results json files.
87SKIMAGE_ACTUALS_BASE_URL = (
88 'http://chromium-skia-gm.commondatastorage.googleapis.com/skimage/actuals')
89# Root directory inside trunk where skimage expectations are stored.
90SKIMAGE_EXPECTATIONS_ROOT = os.path.join('expectations', 'skimage')
91
epoger@google.com61822a22013-07-16 18:56:32 +000092# Pattern used to assemble each image's filename
scroggo@google.comd048a3c2013-10-10 20:41:43 +000093IMAGE_FILENAME_PATTERN = '(\S+)_(\S+)\.png' # matches (testname, config)
epoger@google.com61822a22013-07-16 18:56:32 +000094
95def 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.com4075fd42013-06-04 17:50:36 +0000109def LoadFromString(file_contents):
epoger@google.com9d331542013-05-28 15:25:38 +0000110 """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.com4075fd42013-06-04 17:50:36 +0000113 # TODO(epoger): we should add a version number to the JSON file to ensure
epoger@google.com9d331542013-05-28 15:25:38 +0000114 # that the writer and reader agree on the schema (raising an exception
115 # otherwise).
epoger@google.com4075fd42013-06-04 17:50:36 +0000116 json_dict = json.loads(file_contents)
epoger@google.com9d331542013-05-28 15:25:38 +0000117 return json_dict
epoger@google.com4075fd42013-06-04 17:50:36 +0000118
119def 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.coma783f2b2013-07-08 17:51:58 +0000125
126def 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)