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

Side by Side Diff: tools/skimage_main.cpp

Issue 22301006: Do not fail skimage on missing expectations. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 // Store the names of the filenames to report later which ones failed, succeeded , and were 91 // Store the names of the filenames to report later which ones failed, succeeded , and were
92 // invalid. 92 // invalid.
93 static SkTArray<SkString, false> gInvalidStreams; 93 static SkTArray<SkString, false> gInvalidStreams;
94 static SkTArray<SkString, false> gMissingCodecs; 94 static SkTArray<SkString, false> gMissingCodecs;
95 static SkTArray<SkString, false> gDecodeFailures; 95 static SkTArray<SkString, false> gDecodeFailures;
96 static SkTArray<SkString, false> gEncodeFailures; 96 static SkTArray<SkString, false> gEncodeFailures;
97 static SkTArray<SkString, false> gSuccessfulDecodes; 97 static SkTArray<SkString, false> gSuccessfulDecodes;
98 static SkTArray<SkString, false> gSuccessfulSubsetDecodes; 98 static SkTArray<SkString, false> gSuccessfulSubsetDecodes;
99 static SkTArray<SkString, false> gFailedSubsetDecodes; 99 static SkTArray<SkString, false> gFailedSubsetDecodes;
100 // Files/subsets that do not have expectations. Not reported as a failure of the test so
101 // the bots will not turn red with each new image test.
102 static SkTArray<SkString, false> gMissingExpectations;
103 static SkTArray<SkString, false> gMissingSubsetExpectations;
100 104
101 // Expections read from a file specified by readExpectationsPath. The expectatio ns must have been 105 // Expections read from a file specified by readExpectationsPath. The expectatio ns must have been
102 // previously written using createExpectationsPath. 106 // previously written using createExpectationsPath.
103 SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations; 107 SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations;
104 108
105 static bool write_bitmap(const char outName[], const SkBitmap& bm) { 109 static bool write_bitmap(const char outName[], const SkBitmap& bm) {
106 return SkImageEncoder::EncodeFile(outName, bm, SkImageEncoder::kPNG_Type, 10 0); 110 return SkImageEncoder::EncodeFile(outName, bm, SkImageEncoder::kPNG_Type, 10 0);
107 } 111 }
108 112
109 /** 113 /**
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return false; 176 return false;
173 } 177 }
174 skiagm::Expectations jsExpectations = gJsonExpectations->get(filename); 178 skiagm::Expectations jsExpectations = gJsonExpectations->get(filename);
175 return jsExpectations.ignoreFailure(); 179 return jsExpectations.ignoreFailure();
176 } 180 }
177 181
178 /** 182 /**
179 * Compare against an expectation for this filename, if there is one. 183 * Compare against an expectation for this filename, if there is one.
180 * @param bitmap SkBitmap to compare to the expected value. 184 * @param bitmap SkBitmap to compare to the expected value.
181 * @param filename String used to find the expected value. 185 * @param filename String used to find the expected value.
186 * @param failureArray Array to add a failure message to on failure.
187 * @param missingArray Array to add missing expectation to on failure.
182 * @return bool True in any of these cases: 188 * @return bool True in any of these cases:
183 * - the bitmap matches the expectation. 189 * - the bitmap matches the expectation.
184 * False in any of these cases: 190 * False in any of these cases:
185 * - there is no expectations file. 191 * - there is no expectations file.
186 * - there is an expectations file, but no expectation for this bitmap. 192 * - there is an expectations file, but no expectation for this bitmap.
187 * - there is an expectation for this bitmap, but it did not ma tch. 193 * - there is an expectation for this bitmap, but it did not ma tch.
188 * - expectation could not be computed from the bitmap. 194 * - expectation could not be computed from the bitmap.
189 */ 195 */
190 static bool compare_to_expectations_if_necessary(const SkBitmap& bitmap, const c har* filename, 196 static bool compare_to_expectations_if_necessary(const SkBitmap& bitmap, const c har* filename,
191 SkTArray<SkString, false>* fail ureArray) { 197 SkTArray<SkString, false>* fail ureArray,
198 SkTArray<SkString, false>* miss ingArray) {
192 skiagm::GmResultDigest resultDigest(bitmap); 199 skiagm::GmResultDigest resultDigest(bitmap);
193 if (!resultDigest.isValid()) { 200 if (!resultDigest.isValid()) {
194 if (failureArray != NULL) { 201 if (failureArray != NULL) {
195 failureArray->push_back().printf("decoded %s, but could not create a GmResultDigest.", 202 failureArray->push_back().printf("decoded %s, but could not create a GmResultDigest.",
196 filename); 203 filename);
197 } 204 }
198 return false; 205 return false;
199 } 206 }
200 207
201 if (NULL == gJsonExpectations.get()) { 208 if (NULL == gJsonExpectations.get()) {
202 return false; 209 return false;
203 } 210 }
204 211
205 skiagm::Expectations jsExpectation = gJsonExpectations->get(filename); 212 skiagm::Expectations jsExpectation = gJsonExpectations->get(filename);
206 if (jsExpectation.empty()) { 213 if (jsExpectation.empty()) {
207 if (failureArray != NULL) { 214 if (missingArray != NULL) {
208 failureArray->push_back().printf("decoded %s, but could not find exp ectation.", 215 missingArray->push_back().printf("decoded %s, but could not find exp ectation.",
209 filename); 216 filename);
210 } 217 }
211 return false; 218 return false;
212 } 219 }
213 220
214 if (jsExpectation.match(resultDigest)) { 221 if (jsExpectation.match(resultDigest)) {
215 return true; 222 return true;
216 } 223 }
217 224
218 if (failureArray != NULL) { 225 if (failureArray != NULL) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 gDecodeFailures.push_back() = failure; 343 gDecodeFailures.push_back() = failure;
337 } else { 344 } else {
338 // Now check that the bounds match: 345 // Now check that the bounds match:
339 if (dim.width() != bitmap.width() || dim.height() != bitmap.height() ) { 346 if (dim.width() != bitmap.width() || dim.height() != bitmap.height() ) {
340 SkString failure = SkStringPrintf("bounds do not match for %s", srcPath); 347 SkString failure = SkStringPrintf("bounds do not match for %s", srcPath);
341 gDecodeFailures.push_back() = failure; 348 gDecodeFailures.push_back() = failure;
342 } 349 }
343 } 350 }
344 } 351 }
345 352
346 if (compare_to_expectations_if_necessary(bitmap, filename, &gDecodeFailures) ) { 353 if (compare_to_expectations_if_necessary(bitmap, filename,
354 &gDecodeFailures,
355 &gMissingExpectations)) {
347 gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.widt h(), 356 gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.widt h(),
348 bitmap.height()); 357 bitmap.height());
349 } else if (!FLAGS_mismatchPath.isEmpty()) { 358 } else if (!FLAGS_mismatchPath.isEmpty()) {
350 SkString outPath; 359 SkString outPath;
351 make_outname(&outPath, FLAGS_mismatchPath[0], srcPath, ".png"); 360 make_outname(&outPath, FLAGS_mismatchPath[0], srcPath, ".png");
352 if (write_bitmap(outPath.c_str(), bitmap)) { 361 if (write_bitmap(outPath.c_str(), bitmap)) {
353 gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str() ); 362 gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str() );
354 } else { 363 } else {
355 gEncodeFailures.push_back().set(outPath); 364 gEncodeFailures.push_back().set(outPath);
356 } 365 }
(...skipping 24 matching lines...) Expand all
381 for (int i = 0; i < 5; i++) { 390 for (int i = 0; i < 5; i++) {
382 SkBitmap bitmapFromDecodeSubset; 391 SkBitmap bitmapFromDecodeSubset;
383 // FIXME: Come up with a more representative set of rectangles. 392 // FIXME: Come up with a more representative set of rectangles.
384 SkIRect rect = generate_random_rect(&rand, width, height); 393 SkIRect rect = generate_random_rect(&rand, width, height);
385 SkString subsetDim = SkStringPrintf("[%d,%d,%d,%d]", rect.fLeft, rect.fTop, 394 SkString subsetDim = SkStringPrintf("[%d,%d,%d,%d]", rect.fLeft, rect.fTop,
386 rect.fRight, rect.fBottom); 395 rect.fRight, rect.fBottom);
387 if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, SkBitmap: :kNo_Config)) { 396 if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, SkBitmap: :kNo_Config)) {
388 SkString subsetName = SkStringPrintf("%s_%s", filename, subs etDim.c_str()); 397 SkString subsetName = SkStringPrintf("%s_%s", filename, subs etDim.c_str());
389 if (compare_to_expectations_if_necessary(bitmapFromDecodeSub set, 398 if (compare_to_expectations_if_necessary(bitmapFromDecodeSub set,
390 subsetName.c_str(), 399 subsetName.c_str(),
391 &gFailedSubsetDecod es)) { 400 &gFailedSubsetDecod es,
401 &gMissingSubsetExpe ctations)) {
392 gSuccessfulSubsetDecodes.push_back().printf("Decoded sub set %s from %s", 402 gSuccessfulSubsetDecodes.push_back().printf("Decoded sub set %s from %s",
393 subsetDim.c_str(), srcPath); 403 subsetDim.c_str(), srcPath);
394 } else if (!FLAGS_mismatchPath.isEmpty()) { 404 } else if (!FLAGS_mismatchPath.isEmpty()) {
395 write_subset(FLAGS_mismatchPath[0], filename, subsetDim. c_str(), 405 write_subset(FLAGS_mismatchPath[0], filename, subsetDim. c_str(),
396 &bitmapFromDecodeSubset, rect, bitmap); 406 &bitmapFromDecodeSubset, rect, bitmap);
397 } 407 }
398 408
399 write_expectations(bitmapFromDecodeSubset, subsetName.c_str( )); 409 write_expectations(bitmapFromDecodeSubset, subsetName.c_str( ));
400 if (writePath != NULL) { 410 if (writePath != NULL) {
401 write_subset(writePath->c_str(), filename, subsetDim.c_s tr(), 411 write_subset(writePath->c_str(), filename, subsetDim.c_s tr(),
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 stream.write(jsonStdString.c_str(), jsonStdString.length()); 592 stream.write(jsonStdString.c_str(), jsonStdString.length());
583 } 593 }
584 // Add some space, since codecs may print warnings without newline. 594 // Add some space, since codecs may print warnings without newline.
585 SkDebugf("\n\n"); 595 SkDebugf("\n\n");
586 596
587 bool failed = print_strings("Invalid files", gInvalidStreams); 597 bool failed = print_strings("Invalid files", gInvalidStreams);
588 failed |= print_strings("Missing codec", gMissingCodecs); 598 failed |= print_strings("Missing codec", gMissingCodecs);
589 failed |= print_strings("Failed to decode", gDecodeFailures); 599 failed |= print_strings("Failed to decode", gDecodeFailures);
590 failed |= print_strings("Failed to encode", gEncodeFailures); 600 failed |= print_strings("Failed to encode", gEncodeFailures);
591 print_strings("Decoded", gSuccessfulDecodes); 601 print_strings("Decoded", gSuccessfulDecodes);
602 print_strings("Missing expectations", gMissingExpectations);
592 603
593 if (FLAGS_testSubsetDecoding) { 604 if (FLAGS_testSubsetDecoding) {
594 failed |= print_strings("Failed subset decodes", gFailedSubsetDecodes); 605 failed |= print_strings("Failed subset decodes", gFailedSubsetDecodes);
595 print_strings("Decoded subsets", gSuccessfulSubsetDecodes); 606 print_strings("Decoded subsets", gSuccessfulSubsetDecodes);
607 print_strings("Missing subset expectations", gMissingSubsetExpectations) ;
596 } 608 }
597 609
598 return failed ? -1 : 0; 610 return failed ? -1 : 0;
599 } 611 }
600 612
601 #if !defined SK_BUILD_FOR_IOS 613 #if !defined SK_BUILD_FOR_IOS
602 int main(int argc, char * const argv[]) { 614 int main(int argc, char * const argv[]) {
603 return tool_main(argc, (char**) argv); 615 return tool_main(argc, (char**) argv);
604 } 616 }
605 #endif 617 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698