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

Side by Side Diff: gm/gm_expectations.cpp

Issue 15883004: GM: create GmResultDigest that encapsulates digest type ("bitmap-64bitMD5") and value (12345) (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: create_GmResultDigest_class 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 // These constants must be kept in sync with the JSONKEY_ constants in 14 // These constants must be kept in sync with the JSONKEY_ constants in
15 // display_json_results.py ! 15 // display_json_results.py !
16 const static char kJsonKey_ActualResults[] = "actual-results"; 16 const static char kJsonKey_ActualResults[] = "actual-results";
17 const static char kJsonKey_ActualResults_Failed[] = "failed"; 17 const static char kJsonKey_ActualResults_Failed[] = "failed";
18 const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored"; 18 const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored";
19 const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison"; 19 const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison";
20 const static char kJsonKey_ActualResults_Succeeded[] = "succeeded"; 20 const static char kJsonKey_ActualResults_Succeeded[] = "succeeded";
21 const static char kJsonKey_ActualResults_AnyStatus_BitmapHash[] = "bitmap-64bit MD5";
22 21
23 const static char kJsonKey_ExpectedResults[] = "expected-results"; 22 const static char kJsonKey_ExpectedResults[] = "expected-results";
23 // TODO(epoger): Delete the following reference to "64bitMD5", and
24 // instead call GmResultDigest.asJsonTypeValuePair() to generate all
25 // instances of that string.
24 const static char kJsonKey_ExpectedResults_AllowedBitmapHashes[] = "allowed-bitm ap-64bitMD5s"; 26 const static char kJsonKey_ExpectedResults_AllowedBitmapHashes[] = "allowed-bitm ap-64bitMD5s";
25 const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-f ailure"; 27 const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failu re";
28
29 // Types of result hashes we support in the JSON file.
30 const static char kJsonKey_Hashtype_Bitmap_64bitMD5[] = "bitmap-64bitMD5";
31
26 32
27 namespace skiagm { 33 namespace skiagm {
28 34
29 void gm_fprintf(FILE *stream, const char format[], ...) { 35 void gm_fprintf(FILE *stream, const char format[], ...) {
30 va_list args; 36 va_list args;
31 va_start(args, format); 37 va_start(args, format);
32 fprintf(stream, "GM: "); 38 fprintf(stream, "GM: ");
33 vfprintf(stream, format, args); 39 vfprintf(stream, format, args);
34 va_end(args); 40 va_end(args);
35 } 41 }
36 42
37 SkString SkPathJoin(const char *rootPath, const char *relativePath) { 43 SkString SkPathJoin(const char *rootPath, const char *relativePath) {
38 SkString result(rootPath); 44 SkString result(rootPath);
39 if (!result.endsWith(SkPATH_SEPARATOR)) { 45 if (!result.endsWith(SkPATH_SEPARATOR)) {
40 result.appendUnichar(SkPATH_SEPARATOR); 46 result.appendUnichar(SkPATH_SEPARATOR);
41 } 47 }
42 result.append(relativePath); 48 result.append(relativePath);
43 return result; 49 return result;
44 } 50 }
45 51
46 // TODO(epoger): This currently assumes that the result SkHashDigest was
47 // generated as an SkHashDigest of an SkBitmap. We'll need to allow for oth er
48 // hash types to cover non-bitmaps.
49 Json::Value ActualResultAsJsonValue(const SkHashDigest& result) {
50 Json::Value jsonValue;
51 jsonValue[kJsonKey_ActualResults_AnyStatus_BitmapHash] = asJsonValue(res ult);
52 return jsonValue;
53 }
54
55 Json::Value CreateJsonTree(Json::Value expectedResults, 52 Json::Value CreateJsonTree(Json::Value expectedResults,
56 Json::Value actualResultsFailed, 53 Json::Value actualResultsFailed,
57 Json::Value actualResultsFailureIgnored, 54 Json::Value actualResultsFailureIgnored,
58 Json::Value actualResultsNoComparison, 55 Json::Value actualResultsNoComparison,
59 Json::Value actualResultsSucceeded) { 56 Json::Value actualResultsSucceeded) {
60 Json::Value actualResults; 57 Json::Value actualResults;
61 actualResults[kJsonKey_ActualResults_Failed] = actualResultsFailed; 58 actualResults[kJsonKey_ActualResults_Failed] = actualResultsFailed;
62 actualResults[kJsonKey_ActualResults_FailureIgnored] = actualResultsFail ureIgnored; 59 actualResults[kJsonKey_ActualResults_FailureIgnored] = actualResultsFail ureIgnored;
63 actualResults[kJsonKey_ActualResults_NoComparison] = actualResultsNoComp arison; 60 actualResults[kJsonKey_ActualResults_NoComparison] = actualResultsNoComp arison;
64 actualResults[kJsonKey_ActualResults_Succeeded] = actualResultsSucceeded ; 61 actualResults[kJsonKey_ActualResults_Succeeded] = actualResultsSucceeded ;
65 Json::Value root; 62 Json::Value root;
66 root[kJsonKey_ActualResults] = actualResults; 63 root[kJsonKey_ActualResults] = actualResults;
67 root[kJsonKey_ExpectedResults] = expectedResults; 64 root[kJsonKey_ExpectedResults] = expectedResults;
68 return root; 65 return root;
69 } 66 }
70 67
71 68
69 // GmResultDigest class...
70
71 GmResultDigest::GmResultDigest(const SkBitmap &bitmap) {
72 // TODO(epoger): Better handling for error returned by ComputeDigest()?
73 // For now, we just report a digest of 0 in error cases, like before.
74 if (!SkBitmapHasher::ComputeDigest(bitmap, &fHashDigest)) {
75 fHashDigest = 0;
76 }
77 }
78
79 GmResultDigest::GmResultDigest(uint64_t checksum) {
80 fHashDigest = checksum;
81 }
82
83 bool GmResultDigest::equals(const GmResultDigest &other) const {
84 // TODO(epoger): The current implementation assumes that this
85 // and other are always of type kJsonKey_Hashtype_Bitmap_64bitMD5
86 return (this->fHashDigest == other.fHashDigest);
87 }
88
89 Json::Value GmResultDigest::asJsonTypeValuePair() const {
90 // TODO(epoger): The current implementation assumes that the
91 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5
92 Json::Value jsonTypeValuePair;
93 jsonTypeValuePair[kJsonKey_Hashtype_Bitmap_64bitMD5] = Json::UInt64(fHas hDigest);
94 return jsonTypeValuePair;
95 }
96
97 Json::Value GmResultDigest::getValueAsJsonValue() const {
98 return Json::UInt64(fHashDigest);
99 }
100
101
72 // Expectations class... 102 // Expectations class...
73 103
74 Expectations::Expectations(bool ignoreFailure) { 104 Expectations::Expectations(bool ignoreFailure) {
75 fIgnoreFailure = ignoreFailure; 105 fIgnoreFailure = ignoreFailure;
76 } 106 }
77 107
78 Expectations::Expectations(const SkBitmap& bitmap, bool ignoreFailure) { 108 Expectations::Expectations(const SkBitmap& bitmap, bool ignoreFailure) {
79 fBitmap = bitmap; 109 fBitmap = bitmap;
80 fIgnoreFailure = ignoreFailure; 110 fIgnoreFailure = ignoreFailure;
81 SkHashDigest digest; 111 fAllowedResultDigests.push_back(GmResultDigest(bitmap));
82 // TODO(epoger): Better handling for error returned by ComputeDigest()?
83 // For now, we just report a digest of 0 in error cases, like before.
84 if (!SkBitmapHasher::ComputeDigest(bitmap, &digest)) {
85 digest = 0;
86 }
87 fAllowedBitmapChecksums.push_back() = digest;
88 } 112 }
89 113
90 Expectations::Expectations(Json::Value jsonElement) { 114 Expectations::Expectations(Json::Value jsonElement) {
91 if (jsonElement.empty()) { 115 if (jsonElement.empty()) {
92 fIgnoreFailure = kDefaultIgnoreFailure; 116 fIgnoreFailure = kDefaultIgnoreFailure;
93 } else { 117 } else {
94 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_Ign oreFailure]; 118 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_Ign oreFailure];
95 if (ignoreFailure.isNull()) { 119 if (ignoreFailure.isNull()) {
96 fIgnoreFailure = kDefaultIgnoreFailure; 120 fIgnoreFailure = kDefaultIgnoreFailure;
97 } else if (!ignoreFailure.isBool()) { 121 } else if (!ignoreFailure.isBool()) {
(...skipping 19 matching lines...) Expand all
117 DEBUGFAIL_SEE_STDERR; 141 DEBUGFAIL_SEE_STDERR;
118 } else { 142 } else {
119 for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) { 143 for (Json::ArrayIndex i=0; i<allowedChecksums.size(); i++) {
120 Json::Value checksumElement = allowedChecksums[i]; 144 Json::Value checksumElement = allowedChecksums[i];
121 if (!checksumElement.isIntegral()) { 145 if (!checksumElement.isIntegral()) {
122 gm_fprintf(stderr, "found non-integer checksum" 146 gm_fprintf(stderr, "found non-integer checksum"
123 " in json element '%s'\n", 147 " in json element '%s'\n",
124 jsonElement.toStyledString().c_str()); 148 jsonElement.toStyledString().c_str());
125 DEBUGFAIL_SEE_STDERR; 149 DEBUGFAIL_SEE_STDERR;
126 } else { 150 } else {
127 fAllowedBitmapChecksums.push_back() = asChecksum(checksu mElement); 151 fAllowedResultDigests.push_back(GmResultDigest(checksumE lement.asUInt64()));
128 } 152 }
129 } 153 }
130 } 154 }
131 } 155 }
132 } 156 }
133 157
134 bool Expectations::match(Checksum actualChecksum) const { 158 bool Expectations::match(GmResultDigest actualGmResultDigest) const {
135 for (int i=0; i < this->fAllowedBitmapChecksums.count(); i++) { 159 for (int i=0; i < this->fAllowedResultDigests.count(); i++) {
136 Checksum allowedChecksum = this->fAllowedBitmapChecksums[i]; 160 GmResultDigest allowedResultDigest = this->fAllowedResultDigests[i];
137 if (allowedChecksum == actualChecksum) { 161 if (allowedResultDigest.equals(actualGmResultDigest)) {
138 return true; 162 return true;
139 } 163 }
140 } 164 }
141 return false; 165 return false;
142 } 166 }
143 167
144 Json::Value Expectations::asJsonValue() const { 168 Json::Value Expectations::asJsonValue() const {
145 Json::Value allowedChecksumArray; 169 // TODO(epoger): This implementation assumes that all
epoger 2013/05/23 18:19:12 This comment describes the remaining work for this
146 if (!this->fAllowedBitmapChecksums.empty()) { 170 // allowedResultDigests are of type "bitmap-64bitMD5".
147 for (int i=0; i < this->fAllowedBitmapChecksums.count(); i++) { 171 // Instead, it should allow each allowedResultDigest to contribute
148 Checksum allowedChecksum = this->fAllowedBitmapChecksums[i]; 172 // its own JSON representation.
149 allowedChecksumArray.append(Json::UInt64(allowedChecksum)); 173 Json::Value allowed64bitMD5Array;
174 if (!this->fAllowedResultDigests.empty()) {
175 for (int i=0; i < this->fAllowedResultDigests.count(); i++) {
176 GmResultDigest allowedResultDigest = this->fAllowedResultDigests [i];
177 // TODO(epoger): If we delete this call to getValueAsJsonValue()
178 // will there be any other callers left? If not, delete that
179 // method's implementation.
180 allowed64bitMD5Array.append(allowedResultDigest.getValueAsJsonVa lue());
150 } 181 }
151 } 182 }
152 183
153 Json::Value jsonValue; 184 Json::Value jsonValue;
154 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowedChecksu mArray; 185 jsonValue[kJsonKey_ExpectedResults_AllowedBitmapHashes] = allowed64bitMD 5Array;
155 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure( ); 186 jsonValue[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignoreFailure( );
156 return jsonValue; 187 return jsonValue;
157 } 188 }
158 189
159 190
160 // IndividualImageExpectationsSource class... 191 // IndividualImageExpectationsSource class...
161 192
162 Expectations IndividualImageExpectationsSource::get(const char *testName) { 193 Expectations IndividualImageExpectationsSource::get(const char *testName) {
163 SkString path = SkPathJoin(fRootDir.c_str(), testName); 194 SkString path = SkPathJoin(fRootDir.c_str(), testName);
164 SkBitmap referenceBitmap; 195 SkBitmap referenceBitmap;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 Json::Reader reader; 255 Json::Reader reader;
225 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { 256 if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
226 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath); 257 gm_fprintf(stderr, "error parsing JSON file %s\n", jsonPath);
227 DEBUGFAIL_SEE_STDERR; 258 DEBUGFAIL_SEE_STDERR;
228 return false; 259 return false;
229 } 260 }
230 return true; 261 return true;
231 } 262 }
232 263
233 } 264 }
OLDNEW
« gm/gm_expectations.h ('K') | « gm/gm_expectations.h ('k') | gm/gmmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698