Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: gm/gm_expectations.cpp

Issue 14758003: GM: now that we use MD5 instead of CityHash, the JSON should say so (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm_expectations.h" 8 #include "gm_expectations.h"
9 #include "SkBitmapHasher.h" 9 #include "SkBitmapHasher.h"
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
11 11
12 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") 12 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
13 13
14 const static char kJsonKey_ActualResults[] = "actual-results"; 14 const static char kJsonKey_ActualResults[] = "actual-results";
15 const static char kJsonKey_ActualResults_Failed[] = "failed"; 15 const static char kJsonKey_ActualResults_Failed[] = "failed";
16 const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored"; 16 const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored";
17 const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison"; 17 const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison";
18 const static char kJsonKey_ActualResults_Succeeded[] = "succeeded"; 18 const static char kJsonKey_ActualResults_Succeeded[] = "succeeded";
19 const static char kJsonKey_ActualResults_AnyStatus_BitmapCityhash[] = "bitmap-c ityhash"; 19 #ifdef BITMAPHASHER_USES_TRUNCATED_MD5
20 const static char kJsonKey_ActualResults_AnyStatus_BitmapHash[] = "bitmap-64bit MD5";
21 #else
22 const static char kJsonKey_ActualResults_AnyStatus_BitmapHash[] = "bitmap-cityh ash";
23 #endif
20 24
21 const static char kJsonKey_ExpectedResults[] = "expected-results"; 25 const static char kJsonKey_ExpectedResults[] = "expected-results";
22 const static char kJsonKey_ExpectedResults_AllowedBitmapCityhashes[] = "allowed- bitmap-cityhashes"; 26 #ifdef BITMAPHASHER_USES_TRUNCATED_MD5
27 const static char kJsonKey_ExpectedResults_AllowedBitmapHashes[] = "allowed-bitm ap-64bitMD5s";
28 #else
29 const static char kJsonKey_ExpectedResults_AllowedBitmapHashes[] = "allowed-bitm ap-cityhashes";
30 #endif
23 const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-f ailure"; 31 const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-f ailure";
24 32
25 namespace skiagm { 33 namespace skiagm {
26 34
27 // TODO(epoger): This currently assumes that the result SkHashDigest was 35 // TODO(epoger): This currently assumes that the result SkHashDigest was
28 // generated as a CityHash of an SkBitmap. We'll need to allow for other 36 // generated as an SkHashDigest of an SkBitmap. We'll need to allow for oth er
29 // hash types to cover non-bitmaps, MD5 instead of CityHash, etc. 37 // hash types to cover non-bitmaps.
30 Json::Value ActualResultAsJsonValue(const SkHashDigest& result) { 38 Json::Value ActualResultAsJsonValue(const SkHashDigest& result) {
31 Json::Value jsonValue; 39 Json::Value jsonValue;
32 jsonValue[kJsonKey_ActualResults_AnyStatus_BitmapCityhash] = asJsonValue (result); 40 jsonValue[kJsonKey_ActualResults_AnyStatus_BitmapHash] = asJsonValue(res ult);
33 return jsonValue; 41 return jsonValue;
34 } 42 }
35 43
36 Json::Value CreateJsonTree(Json::Value expectedResults, 44 Json::Value CreateJsonTree(Json::Value expectedResults,
37 Json::Value actualResultsFailed, 45 Json::Value actualResultsFailed,
38 Json::Value actualResultsFailureIgnored, 46 Json::Value actualResultsFailureIgnored,
39 Json::Value actualResultsNoComparison, 47 Json::Value actualResultsNoComparison,
40 Json::Value actualResultsSucceeded) { 48 Json::Value actualResultsSucceeded) {
41 Json::Value actualResults; 49 Json::Value actualResults;
42 actualResults[kJsonKey_ActualResults_Failed] = actualResultsFailed; 50 actualResults[kJsonKey_ActualResults_Failed] = actualResultsFailed;
(...skipping 15 matching lines...) Expand all
58 66
59 Expectations::Expectations(const SkBitmap& bitmap, bool ignoreFailure) { 67 Expectations::Expectations(const SkBitmap& bitmap, bool ignoreFailure) {
60 fBitmap = bitmap; 68 fBitmap = bitmap;
61 fIgnoreFailure = ignoreFailure; 69 fIgnoreFailure = ignoreFailure;
62 SkHashDigest digest; 70 SkHashDigest digest;
63 // TODO(epoger): Better handling for error returned by ComputeDigest()? 71 // TODO(epoger): Better handling for error returned by ComputeDigest()?
64 // For now, we just report a digest of 0 in error cases, like before. 72 // For now, we just report a digest of 0 in error cases, like before.
65 if (!SkBitmapHasher::ComputeDigest(bitmap, &digest)) { 73 if (!SkBitmapHasher::ComputeDigest(bitmap, &digest)) {
66 digest = 0; 74 digest = 0;
67 } 75 }
68 fAllowedBitmapCityhashes.push_back() = digest; 76 fAllowedBitmapChecksums.push_back() = digest;
69 } 77 }
70 78
71 Expectations::Expectations(Json::Value jsonElement) { 79 Expectations::Expectations(Json::Value jsonElement) {
72 if (jsonElement.empty()) { 80 if (jsonElement.empty()) {
73 fIgnoreFailure = kDefaultIgnoreFailure; 81 fIgnoreFailure = kDefaultIgnoreFailure;
74 } else { 82 } else {
75 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_Ign oreFailure]; 83 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_Ign oreFailure];
76 if (ignoreFailure.isNull()) { 84 if (ignoreFailure.isNull()) {
77 fIgnoreFailure = kDefaultIgnoreFailure; 85 fIgnoreFailure = kDefaultIgnoreFailure;
78 } else if (!ignoreFailure.isBool()) { 86 } else if (!ignoreFailure.isBool()) {
79 gm_fprintf(stderr, "found non-boolean json value" 87 gm_fprintf(stderr, "found non-boolean json value"
80 " for key '%s' in element '%s'\n", 88 " for key '%s' in element '%s'\n",
81 kJsonKey_ExpectedResults_IgnoreFailure, 89 kJsonKey_ExpectedResults_IgnoreFailure,
82 jsonElement.toStyledString().c_str()); 90 jsonElement.toStyledString().c_str());
83 DEBUGFAIL_SEE_STDERR; 91 DEBUGFAIL_SEE_STDERR;
84 fIgnoreFailure = kDefaultIgnoreFailure; 92 fIgnoreFailure = kDefaultIgnoreFailure;
85 } else { 93 } else {
86 fIgnoreFailure = ignoreFailure.asBool(); 94 fIgnoreFailure = ignoreFailure.asBool();
87 } 95 }
88 96
89 Json::Value allowedChecksums = 97 Json::Value allowedChecksums =
90 jsonElement[kJsonKey_ExpectedResults_AllowedBitmapCityhashes]; 98 jsonElement[kJsonKey_ExpectedResults_AllowedBitmapHashes];
91 if (allowedChecksums.isNull()) { 99 if (allowedChecksums.isNull()) {
92 // ok, we'll just assume there aren't any expected checksums to compare against 100 // ok, we'll just assume there aren't any expected checksums to compare against
93 } else if (!allowedChecksums.isArray()) { 101 } else if (!allowedChecksums.isArray()) {
94 gm_fprintf(stderr, "found non-array json value" 102 gm_fprintf(stderr, "found non-array json value"
95 " for key '%s' in element '%s'\n", 103 " for key '%s' in element '%s'\n",
96 kJsonKey_ExpectedResults_AllowedBitmapCityhashes, 104 kJsonKey_ExpectedResults_AllowedBitmapHashes,
97 jsonElement.toStyledString().c_str()); 105 jsonElement.toStyledString().c_str());
98 DEBUGFAIL_SEE_STDERR; 106 DEBUGFAIL_SEE_STDERR;
99 } else { 107 } else {
100 for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) { 108 for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) {
101 Json::Value checksumElement = allowedChecksums[i]; 109 Json::Value checksumElement = allowedChecksums[i];
102 if (!checksumElement.isIntegral()) { 110 if (!checksumElement.isIntegral()) {
103 gm_fprintf(stderr, "found non-integer checksum" 111 gm_fprintf(stderr, "found non-integer checksum"
104 " in json element '%s'\n", 112 " in json element '%s'\n",
105 jsonElement.toStyledString().c_str()); 113 jsonElement.toStyledString().c_str());
106 DEBUGFAIL_SEE_STDERR; 114 DEBUGFAIL_SEE_STDERR;
107 } else { 115 } else {
108 fAllowedBitmapCityhashes.push_back() = asChecksum(checks umElement); 116 fAllowedBitmapChecksums.push_back() = asChecksum(checksu mElement);
109 } 117 }
110 } 118 }
111 } 119 }
112 } 120 }
113 } 121 }
114 122
115 bool Expectations::match(Checksum actualChecksum) const { 123 bool Expectations::match(Checksum actualChecksum) const {
116 for (int i=0; i < this->fAllowedBitmapCityhashes.count(); i++) { 124 for (int i=0; i < this->fAllowedBitmapChecksums.count(); i++) {
117 Checksum allowedChecksum = this->fAllowedBitmapCityhashes[i]; 125 Checksum allowedChecksum = this->fAllowedBitmapChecksums[i];
118 if (allowedChecksum == actualChecksum) { 126 if (allowedChecksum == actualChecksum) {
119 return true; 127 return true;
120 } 128 }
121 } 129 }
122 return false; 130 return false;
123 } 131 }
124 132
125 Json::Value Expectations::asJsonValue() const { 133 Json::Value Expectations::asJsonValue() const {
126 Json::Value allowedChecksumArray; 134 Json::Value allowedChecksumArray;
127 if (!this->fAllowedBitmapCityhashes.empty()) { 135 if (!this->fAllowedBitmapChecksums.empty()) {
128 for (int i=0; i < this->fAllowedBitmapCityhashes.count(); i++) { 136 for (int i=0; i < this->fAllowedBitmapChecksums.count(); i++) {
129 Checksum allowedChecksum = this->fAllowedBitmapCityhashes[i]; 137 Checksum allowedChecksum = this->fAllowedBitmapChecksums[i];
130 allowedChecksumArray.append(Json::UInt64(allowedChecksum)); 138 allowedChecksumArray.append(Json::UInt64(allowedChecksum));
131 } 139 }
132 } 140 }
133 141
134 Json::Value jsonValue; 142 Json::Value jsonValue;
135 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapCityhashes] = allowedChe cksumArray; 143 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu mArray;
136 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure( ); 144 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure( );
137 return jsonValue; 145 return jsonValue;
138 } 146 }
139 147
140 148
141 // IndividualImageExpectationsSource class... 149 // IndividualImageExpectationsSource class...
142 150
143 Expectations IndividualImageExpectationsSource::get(const char *testName) { 151 Expectations IndividualImageExpectationsSource::get(const char *testName) {
144 SkString path = make_filename(fRootDir.c_str(), "", testName, 152 SkString path = make_filename(fRootDir.c_str(), "", testName,
145 "png"); 153 "png");
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 Json::Reader reader; 214 Json::Reader reader;
207 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { 215 if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
208 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); 216 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath);
209 DEBUGFAIL_SEE_STDERR; 217 DEBUGFAIL_SEE_STDERR;
210 return false; 218 return false;
211 } 219 }
212 return true; 220 return true;
213 } 221 }
214 222
215 } 223 }
OLDNEW
« no previous file with comments | « gm/gm_expectations.h ('k') | gm/tests/outputs/compared-against-different-pixels-images/output-expected/json-summary.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698