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

Side by Side Diff: gm/gm_expectations.cpp

Issue 281303003: Generate gm/Android.mk, minus JSON. (Closed) Base URL: https://skia.googlesource.com/skia.git@baseline_gm
Patch Set: Created 6 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
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 * TODO(epoger): Combine this with tools/image_expectations.cpp, or eliminate on e of the two. 7 * TODO(epoger): Combine this with tools/image_expectations.cpp, or eliminate on e of the two.
8 */ 8 */
9 9
10 #include "gm_expectations.h" 10 #include "gm_expectations.h"
(...skipping 13 matching lines...) Expand all
24 const static char kJsonKey_ExpectedResults[] = "expected-results"; 24 const static char kJsonKey_ExpectedResults[] = "expected-results";
25 const static char kJsonKey_ExpectedResults_AllowedDigests[] = "allowed-digests"; 25 const static char kJsonKey_ExpectedResults_AllowedDigests[] = "allowed-digests";
26 const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure"; 26 const static char kJsonKey_ExpectedResults_IgnoreFailure[] = "ignore-failure";
27 27
28 // Types of result hashes we support in the JSON file. 28 // Types of result hashes we support in the JSON file.
29 const static char kJsonKey_Hashtype_Bitmap_64bitMD5[] = "bitmap-64bitMD5"; 29 const static char kJsonKey_Hashtype_Bitmap_64bitMD5[] = "bitmap-64bitMD5";
30 30
31 31
32 namespace skiagm { 32 namespace skiagm {
33 33
34 // FIXME (scroggo): JSON is disabled in Android framework until we solve
35 // skbug.com/2448
36 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
34 Json::Value CreateJsonTree(Json::Value expectedResults, 37 Json::Value CreateJsonTree(Json::Value expectedResults,
35 Json::Value actualResultsFailed, 38 Json::Value actualResultsFailed,
36 Json::Value actualResultsFailureIgnored, 39 Json::Value actualResultsFailureIgnored,
37 Json::Value actualResultsNoComparison, 40 Json::Value actualResultsNoComparison,
38 Json::Value actualResultsSucceeded) { 41 Json::Value actualResultsSucceeded) {
39 Json::Value actualResults; 42 Json::Value actualResults;
40 actualResults[kJsonKey_ActualResults_Failed] = actualResultsFailed; 43 actualResults[kJsonKey_ActualResults_Failed] = actualResultsFailed;
41 actualResults[kJsonKey_ActualResults_FailureIgnored] = actualResultsFail ureIgnored; 44 actualResults[kJsonKey_ActualResults_FailureIgnored] = actualResultsFail ureIgnored;
42 actualResults[kJsonKey_ActualResults_NoComparison] = actualResultsNoComp arison; 45 actualResults[kJsonKey_ActualResults_NoComparison] = actualResultsNoComp arison;
43 actualResults[kJsonKey_ActualResults_Succeeded] = actualResultsSucceeded ; 46 actualResults[kJsonKey_ActualResults_Succeeded] = actualResultsSucceeded ;
44 Json::Value root; 47 Json::Value root;
45 root[kJsonKey_ActualResults] = actualResults; 48 root[kJsonKey_ActualResults] = actualResults;
46 root[kJsonKey_ExpectedResults] = expectedResults; 49 root[kJsonKey_ExpectedResults] = expectedResults;
47 return root; 50 return root;
48 } 51 }
49 52 #endif
50 53
51 // GmResultDigest class... 54 // GmResultDigest class...
52 55
53 GmResultDigest::GmResultDigest(const SkBitmap &bitmap) { 56 GmResultDigest::GmResultDigest(const SkBitmap &bitmap) {
54 fIsValid = SkBitmapHasher::ComputeDigest(bitmap, &fHashDigest); 57 fIsValid = SkBitmapHasher::ComputeDigest(bitmap, &fHashDigest);
55 } 58 }
56 59
60 // FIXME (scroggo): JSON is disabled in Android framework until we solve
61 // skbug.com/2448
62 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
57 GmResultDigest::GmResultDigest(const Json::Value &jsonTypeValuePair) { 63 GmResultDigest::GmResultDigest(const Json::Value &jsonTypeValuePair) {
58 fIsValid = false; 64 fIsValid = false;
59 if (!jsonTypeValuePair.isArray()) { 65 if (!jsonTypeValuePair.isArray()) {
60 SkDebugf("found non-array json value when parsing GmResultDigest: %s \n", 66 SkDebugf("found non-array json value when parsing GmResultDigest: %s \n",
61 jsonTypeValuePair.toStyledString().c_str()); 67 jsonTypeValuePair.toStyledString().c_str());
62 DEBUGFAIL_SEE_STDERR; 68 DEBUGFAIL_SEE_STDERR;
63 } else if (2 != jsonTypeValuePair.size()) { 69 } else if (2 != jsonTypeValuePair.size()) {
64 SkDebugf("found json array with wrong size when parsing GmResultDige st: %s\n", 70 SkDebugf("found json array with wrong size when parsing GmResultDige st: %s\n",
65 jsonTypeValuePair.toStyledString().c_str()); 71 jsonTypeValuePair.toStyledString().c_str());
66 DEBUGFAIL_SEE_STDERR; 72 DEBUGFAIL_SEE_STDERR;
67 } else { 73 } else {
68 // TODO(epoger): The current implementation assumes that the 74 // TODO(epoger): The current implementation assumes that the
69 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5 75 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5
70 Json::Value jsonHashValue = jsonTypeValuePair[1]; 76 Json::Value jsonHashValue = jsonTypeValuePair[1];
71 if (!jsonHashValue.isIntegral()) { 77 if (!jsonHashValue.isIntegral()) {
72 SkDebugf("found non-integer jsonHashValue when parsing GmResultD igest: %s\n", 78 SkDebugf("found non-integer jsonHashValue when parsing GmResultD igest: %s\n",
73 jsonTypeValuePair.toStyledString().c_str()); 79 jsonTypeValuePair.toStyledString().c_str());
74 DEBUGFAIL_SEE_STDERR; 80 DEBUGFAIL_SEE_STDERR;
75 } else { 81 } else {
76 fHashDigest = jsonHashValue.asUInt64(); 82 fHashDigest = jsonHashValue.asUInt64();
77 fIsValid = true; 83 fIsValid = true;
78 } 84 }
79 } 85 }
80 } 86 }
87 #endif
81 88
82 bool GmResultDigest::isValid() const { 89 bool GmResultDigest::isValid() const {
83 return fIsValid; 90 return fIsValid;
84 } 91 }
85 92
86 bool GmResultDigest::equals(const GmResultDigest &other) const { 93 bool GmResultDigest::equals(const GmResultDigest &other) const {
87 // TODO(epoger): The current implementation assumes that this 94 // TODO(epoger): The current implementation assumes that this
88 // and other are always of type kJsonKey_Hashtype_Bitmap_64bitMD5 95 // and other are always of type kJsonKey_Hashtype_Bitmap_64bitMD5
89 return (this->fIsValid && other.fIsValid && (this->fHashDigest == other. fHashDigest)); 96 return (this->fIsValid && other.fIsValid && (this->fHashDigest == other. fHashDigest));
90 } 97 }
91 98
99 // FIXME (scroggo): JSON is disabled in Android framework until we solve
100 // skbug.com/2448
101 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
92 Json::Value GmResultDigest::asJsonTypeValuePair() const { 102 Json::Value GmResultDigest::asJsonTypeValuePair() const {
93 // TODO(epoger): The current implementation assumes that the 103 // TODO(epoger): The current implementation assumes that the
94 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5 104 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5
95 Json::Value jsonTypeValuePair; 105 Json::Value jsonTypeValuePair;
96 if (fIsValid) { 106 if (fIsValid) {
97 jsonTypeValuePair.append(Json::Value(kJsonKey_Hashtype_Bitmap_64bitM D5)); 107 jsonTypeValuePair.append(Json::Value(kJsonKey_Hashtype_Bitmap_64bitM D5));
98 jsonTypeValuePair.append(Json::UInt64(fHashDigest)); 108 jsonTypeValuePair.append(Json::UInt64(fHashDigest));
99 } else { 109 } else {
100 jsonTypeValuePair.append(Json::Value("INVALID")); 110 jsonTypeValuePair.append(Json::Value("INVALID"));
101 } 111 }
102 return jsonTypeValuePair; 112 return jsonTypeValuePair;
103 } 113 }
114 #endif
104 115
105 SkString GmResultDigest::getHashType() const { 116 SkString GmResultDigest::getHashType() const {
106 // TODO(epoger): The current implementation assumes that the 117 // TODO(epoger): The current implementation assumes that the
107 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5 118 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5
108 return SkString(kJsonKey_Hashtype_Bitmap_64bitMD5); 119 return SkString(kJsonKey_Hashtype_Bitmap_64bitMD5);
109 } 120 }
110 121
111 SkString GmResultDigest::getDigestValue() const { 122 SkString GmResultDigest::getDigestValue() const {
112 // TODO(epoger): The current implementation assumes that the 123 // TODO(epoger): The current implementation assumes that the
113 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5 124 // result digest is always of type kJsonKey_Hashtype_Bitmap_64bitMD5
(...skipping 14 matching lines...) Expand all
128 fIgnoreFailure = ignoreFailure; 139 fIgnoreFailure = ignoreFailure;
129 fAllowedResultDigests.push_back(GmResultDigest(bitmap)); 140 fAllowedResultDigests.push_back(GmResultDigest(bitmap));
130 } 141 }
131 142
132 Expectations::Expectations(const BitmapAndDigest& bitmapAndDigest) { 143 Expectations::Expectations(const BitmapAndDigest& bitmapAndDigest) {
133 fBitmap = bitmapAndDigest.fBitmap; 144 fBitmap = bitmapAndDigest.fBitmap;
134 fIgnoreFailure = false; 145 fIgnoreFailure = false;
135 fAllowedResultDigests.push_back(bitmapAndDigest.fDigest); 146 fAllowedResultDigests.push_back(bitmapAndDigest.fDigest);
136 } 147 }
137 148
149 // FIXME (scroggo): JSON is disabled in Android framework until we solve
150 // skbug.com/2448
151 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
138 Expectations::Expectations(Json::Value jsonElement) { 152 Expectations::Expectations(Json::Value jsonElement) {
139 if (jsonElement.empty()) { 153 if (jsonElement.empty()) {
140 fIgnoreFailure = kDefaultIgnoreFailure; 154 fIgnoreFailure = kDefaultIgnoreFailure;
141 } else { 155 } else {
142 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_Ign oreFailure]; 156 Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_Ign oreFailure];
143 if (ignoreFailure.isNull()) { 157 if (ignoreFailure.isNull()) {
144 fIgnoreFailure = kDefaultIgnoreFailure; 158 fIgnoreFailure = kDefaultIgnoreFailure;
145 } else if (!ignoreFailure.isBool()) { 159 } else if (!ignoreFailure.isBool()) {
146 SkDebugf("found non-boolean json value for key '%s' in element ' %s'\n", 160 SkDebugf("found non-boolean json value for key '%s' in element ' %s'\n",
147 kJsonKey_ExpectedResults_IgnoreFailure, 161 kJsonKey_ExpectedResults_IgnoreFailure,
(...skipping 12 matching lines...) Expand all
160 kJsonKey_ExpectedResults_AllowedDigests, 174 kJsonKey_ExpectedResults_AllowedDigests,
161 jsonElement.toStyledString().c_str()); 175 jsonElement.toStyledString().c_str());
162 DEBUGFAIL_SEE_STDERR; 176 DEBUGFAIL_SEE_STDERR;
163 } else { 177 } else {
164 for (Json::ArrayIndex i=0; i<allowedDigests.size(); i++) { 178 for (Json::ArrayIndex i=0; i<allowedDigests.size(); i++) {
165 fAllowedResultDigests.push_back(GmResultDigest(allowedDigest s[i])); 179 fAllowedResultDigests.push_back(GmResultDigest(allowedDigest s[i]));
166 } 180 }
167 } 181 }
168 } 182 }
169 } 183 }
184 #endif
170 185
171 bool Expectations::match(GmResultDigest actualGmResultDigest) const { 186 bool Expectations::match(GmResultDigest actualGmResultDigest) const {
172 for (int i=0; i < this->fAllowedResultDigests.count(); i++) { 187 for (int i=0; i < this->fAllowedResultDigests.count(); i++) {
173 GmResultDigest allowedResultDigest = this->fAllowedResultDigests[i]; 188 GmResultDigest allowedResultDigest = this->fAllowedResultDigests[i];
174 if (allowedResultDigest.equals(actualGmResultDigest)) { 189 if (allowedResultDigest.equals(actualGmResultDigest)) {
175 return true; 190 return true;
176 } 191 }
177 } 192 }
178 return false; 193 return false;
179 } 194 }
180 195
196 // FIXME (scroggo): JSON is disabled in Android framework until we solve
197 // skbug.com/2448
198 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
181 Json::Value Expectations::asJsonValue() const { 199 Json::Value Expectations::asJsonValue() const {
182 Json::Value allowedDigestArray; 200 Json::Value allowedDigestArray;
183 if (!this->fAllowedResultDigests.empty()) { 201 if (!this->fAllowedResultDigests.empty()) {
184 for (int i=0; i < this->fAllowedResultDigests.count(); i++) { 202 for (int i=0; i < this->fAllowedResultDigests.count(); i++) {
185 allowedDigestArray.append(this->fAllowedResultDigests[i].asJsonT ypeValuePair()); 203 allowedDigestArray.append(this->fAllowedResultDigests[i].asJsonT ypeValuePair());
186 } 204 }
187 } 205 }
188 206
189 Json::Value jsonExpectations; 207 Json::Value jsonExpectations;
190 jsonExpectations[kJsonKey_ExpectedResults_AllowedDigests] = allowedDiges tArray; 208 jsonExpectations[kJsonKey_ExpectedResults_AllowedDigests] = allowedDiges tArray;
191 jsonExpectations[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignore Failure(); 209 jsonExpectations[kJsonKey_ExpectedResults_IgnoreFailure] = this->ignore Failure();
192 return jsonExpectations; 210 return jsonExpectations;
193 } 211 }
194 212 #endif
195 213
196 // IndividualImageExpectationsSource class... 214 // IndividualImageExpectationsSource class...
197 215
198 Expectations IndividualImageExpectationsSource::get(const char *testName) co nst { 216 Expectations IndividualImageExpectationsSource::get(const char *testName) co nst {
199 SkString path = SkOSPath::SkPathJoin(fRootDir.c_str(), testName); 217 SkString path = SkOSPath::SkPathJoin(fRootDir.c_str(), testName);
200 SkBitmap referenceBitmap; 218 SkBitmap referenceBitmap;
201 bool decodedReferenceBitmap = 219 bool decodedReferenceBitmap =
202 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap, 220 SkImageDecoder::DecodeFile(path.c_str(), &referenceBitmap,
203 SkBitmap::kARGB_8888_Config, 221 SkBitmap::kARGB_8888_Config,
204 SkImageDecoder::kDecodePixels_Mode, 222 SkImageDecoder::kDecodePixels_Mode,
205 NULL); 223 NULL);
206 if (decodedReferenceBitmap) { 224 if (decodedReferenceBitmap) {
207 return Expectations(referenceBitmap); 225 return Expectations(referenceBitmap);
208 } else { 226 } else {
209 return Expectations(); 227 return Expectations();
210 } 228 }
211 } 229 }
212 230
213 231
232 // FIXME (scroggo): JSON is disabled in Android framework until we solve
233 // skbug.com/2448
234 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
214 // JsonExpectationsSource class... 235 // JsonExpectationsSource class...
215 236
216 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) { 237 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) {
217 Parse(jsonPath, &fJsonRoot); 238 Parse(jsonPath, &fJsonRoot);
218 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults]; 239 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults];
219 } 240 }
220 241
221 Expectations JsonExpectationsSource::get(const char *testName) const { 242 Expectations JsonExpectationsSource::get(const char *testName) const {
222 return Expectations(fJsonExpectedResults[testName]); 243 return Expectations(fJsonExpectedResults[testName]);
223 } 244 }
224 245
225 /*static*/ bool JsonExpectationsSource::Parse(const char *jsonPath, Json::Va lue *jsonRoot) { 246 /*static*/ bool JsonExpectationsSource::Parse(const char *jsonPath, Json::Va lue *jsonRoot) {
226 SkAutoDataUnref dataRef(SkData::NewFromFileName(jsonPath)); 247 SkAutoDataUnref dataRef(SkData::NewFromFileName(jsonPath));
227 if (NULL == dataRef.get()) { 248 if (NULL == dataRef.get()) {
228 SkDebugf("error reading JSON file %s\n", jsonPath); 249 SkDebugf("error reading JSON file %s\n", jsonPath);
229 DEBUGFAIL_SEE_STDERR; 250 DEBUGFAIL_SEE_STDERR;
230 return false; 251 return false;
231 } 252 }
232 253
233 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data() ); 254 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data() );
234 size_t size = dataRef.get()->size(); 255 size_t size = dataRef.get()->size();
235 Json::Reader reader; 256 Json::Reader reader;
236 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { 257 if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
237 SkDebugf("error parsing JSON file %s\n", jsonPath); 258 SkDebugf("error parsing JSON file %s\n", jsonPath);
238 DEBUGFAIL_SEE_STDERR; 259 DEBUGFAIL_SEE_STDERR;
239 return false; 260 return false;
240 } 261 }
241 return true; 262 return true;
242 } 263 }
243 264 #endif
244 } 265 }
OLDNEW
« Android.mk ('K') | « gm/gm_expectations.h ('k') | gm/gmmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698