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

Side by Side Diff: tools/skdiff_main.cpp

Issue 302443012: add a verbose flag to skdiff that shows the progress and status of (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address ben comments Created 6 years, 6 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
« 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 #include "skdiff.h" 7 #include "skdiff.h"
8 #include "skdiff_html.h" 8 #include "skdiff_html.h"
9 #include "skdiff_utils.h" 9 #include "skdiff_utils.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 get_bitmap(fileBits, resource, SkImageDecoder::kDecodeBounds_Mode); 304 get_bitmap(fileBits, resource, SkImageDecoder::kDecodeBounds_Mode);
305 } 305 }
306 } 306 }
307 } 307 }
308 308
309 static void get_bounds(DiffRecord& drp) { 309 static void get_bounds(DiffRecord& drp) {
310 get_bounds(drp.fBase, "base"); 310 get_bounds(drp.fBase, "base");
311 get_bounds(drp.fComparison, "comparison"); 311 get_bounds(drp.fComparison, "comparison");
312 } 312 }
313 313
314 #ifdef SK_OS_WIN
315 #define ANSI_COLOR_RED ""
316 #define ANSI_COLOR_GREEN ""
317 #define ANSI_COLOR_YELLOW ""
318 #define ANSI_COLOR_RESET ""
319 #else
320 #define ANSI_COLOR_RED "\x1b[31m"
321 #define ANSI_COLOR_GREEN "\x1b[32m"
322 #define ANSI_COLOR_YELLOW "\x1b[33m"
323 #define ANSI_COLOR_RESET "\x1b[0m"
324 #endif
325
326 #define VERBOSE_STATUS(status,color,filename) if (verbose) printf( "[ " color " %10s " ANSI_COLOR_RESET " ] %s\n", status, filename->c_str())
327
314 /// Creates difference images, returns the number that have a 0 metric. 328 /// Creates difference images, returns the number that have a 0 metric.
315 /// If outputDir.isEmpty(), don't write out diff files. 329 /// If outputDir.isEmpty(), don't write out diff files.
316 static void create_diff_images (DiffMetricProc dmp, 330 static void create_diff_images (DiffMetricProc dmp,
317 const int colorThreshold, 331 const int colorThreshold,
318 RecordArray* differences, 332 RecordArray* differences,
319 const SkString& baseDir, 333 const SkString& baseDir,
320 const SkString& comparisonDir, 334 const SkString& comparisonDir,
321 const SkString& outputDir, 335 const SkString& outputDir,
322 const StringArray& matchSubstrings, 336 const StringArray& matchSubstrings,
323 const StringArray& nomatchSubstrings, 337 const StringArray& nomatchSubstrings,
324 bool recurseIntoSubdirs, 338 bool recurseIntoSubdirs,
325 bool getBounds, 339 bool getBounds,
340 bool verbose,
326 DiffSummary* summary) { 341 DiffSummary* summary) {
327 SkASSERT(!baseDir.isEmpty()); 342 SkASSERT(!baseDir.isEmpty());
328 SkASSERT(!comparisonDir.isEmpty()); 343 SkASSERT(!comparisonDir.isEmpty());
329 344
330 FileArray baseFiles; 345 FileArray baseFiles;
331 FileArray comparisonFiles; 346 FileArray comparisonFiles;
332 347
333 get_file_list(baseDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdir s, &baseFiles); 348 get_file_list(baseDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdir s, &baseFiles);
334 get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings, recurseInto Subdirs, 349 get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings, recurseInto Subdirs,
335 &comparisonFiles); 350 &comparisonFiles);
(...skipping 27 matching lines...) Expand all
363 comparisonPath.append(*baseFiles[i]); 378 comparisonPath.append(*baseFiles[i]);
364 379
365 drp->fBase.fFilename = *baseFiles[i]; 380 drp->fBase.fFilename = *baseFiles[i];
366 drp->fBase.fFullPath = basePath; 381 drp->fBase.fFullPath = basePath;
367 drp->fBase.fStatus = DiffResource::kExists_Status; 382 drp->fBase.fStatus = DiffResource::kExists_Status;
368 383
369 drp->fComparison.fFilename = *baseFiles[i]; 384 drp->fComparison.fFilename = *baseFiles[i];
370 drp->fComparison.fFullPath = comparisonPath; 385 drp->fComparison.fFullPath = comparisonPath;
371 drp->fComparison.fStatus = DiffResource::kDoesNotExist_Status; 386 drp->fComparison.fStatus = DiffResource::kDoesNotExist_Status;
372 387
388 VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, baseFiles[i]);
389
373 ++i; 390 ++i;
374 } else if (v > 0) { 391 } else if (v > 0) {
375 // in comparisonDir, but not in baseDir 392 // in comparisonDir, but not in baseDir
376 drp->fResult = DiffRecord::kCouldNotCompare_Result; 393 drp->fResult = DiffRecord::kCouldNotCompare_Result;
377 394
378 basePath.append(*comparisonFiles[j]); 395 basePath.append(*comparisonFiles[j]);
379 comparisonPath.append(*comparisonFiles[j]); 396 comparisonPath.append(*comparisonFiles[j]);
380 397
381 drp->fBase.fFilename = *comparisonFiles[j]; 398 drp->fBase.fFilename = *comparisonFiles[j];
382 drp->fBase.fFullPath = basePath; 399 drp->fBase.fFullPath = basePath;
383 drp->fBase.fStatus = DiffResource::kDoesNotExist_Status; 400 drp->fBase.fStatus = DiffResource::kDoesNotExist_Status;
384 401
385 drp->fComparison.fFilename = *comparisonFiles[j]; 402 drp->fComparison.fFilename = *comparisonFiles[j];
386 drp->fComparison.fFullPath = comparisonPath; 403 drp->fComparison.fFullPath = comparisonPath;
387 drp->fComparison.fStatus = DiffResource::kExists_Status; 404 drp->fComparison.fStatus = DiffResource::kExists_Status;
388 405
406 VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, comparisonFiles[j]);
407
389 ++j; 408 ++j;
390 } else { 409 } else {
391 // Found the same filename in both baseDir and comparisonDir. 410 // Found the same filename in both baseDir and comparisonDir.
392 SkASSERT(DiffRecord::kUnknown_Result == drp->fResult); 411 SkASSERT(DiffRecord::kUnknown_Result == drp->fResult);
393 412
394 basePath.append(*baseFiles[i]); 413 basePath.append(*baseFiles[i]);
395 comparisonPath.append(*comparisonFiles[j]); 414 comparisonPath.append(*comparisonFiles[j]);
396 415
397 drp->fBase.fFilename = *baseFiles[i]; 416 drp->fBase.fFilename = *baseFiles[i];
398 drp->fBase.fFullPath = basePath; 417 drp->fBase.fFullPath = basePath;
399 drp->fBase.fStatus = DiffResource::kExists_Status; 418 drp->fBase.fStatus = DiffResource::kExists_Status;
400 419
401 drp->fComparison.fFilename = *comparisonFiles[j]; 420 drp->fComparison.fFilename = *comparisonFiles[j];
402 drp->fComparison.fFullPath = comparisonPath; 421 drp->fComparison.fFullPath = comparisonPath;
403 drp->fComparison.fStatus = DiffResource::kExists_Status; 422 drp->fComparison.fStatus = DiffResource::kExists_Status;
404 423
405 SkAutoDataUnref baseFileBits(read_file(drp->fBase.fFullPath.c_str()) ); 424 SkAutoDataUnref baseFileBits(read_file(drp->fBase.fFullPath.c_str()) );
406 if (NULL != baseFileBits) { 425 if (NULL != baseFileBits) {
407 drp->fBase.fStatus = DiffResource::kRead_Status; 426 drp->fBase.fStatus = DiffResource::kRead_Status;
408 } 427 }
409 SkAutoDataUnref comparisonFileBits(read_file(drp->fComparison.fFullP ath.c_str())); 428 SkAutoDataUnref comparisonFileBits(read_file(drp->fComparison.fFullP ath.c_str()));
410 if (NULL != comparisonFileBits) { 429 if (NULL != comparisonFileBits) {
411 drp->fComparison.fStatus = DiffResource::kRead_Status; 430 drp->fComparison.fStatus = DiffResource::kRead_Status;
412 } 431 }
413 if (NULL == baseFileBits || NULL == comparisonFileBits) { 432 if (NULL == baseFileBits || NULL == comparisonFileBits) {
414 if (NULL == baseFileBits) { 433 if (NULL == baseFileBits) {
415 drp->fBase.fStatus = DiffResource::kCouldNotRead_Status; 434 drp->fBase.fStatus = DiffResource::kCouldNotRead_Status;
435 VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, baseFiles[i]);
416 } 436 }
417 if (NULL == comparisonFileBits) { 437 if (NULL == comparisonFileBits) {
418 drp->fComparison.fStatus = DiffResource::kCouldNotRead_Statu s; 438 drp->fComparison.fStatus = DiffResource::kCouldNotRead_Statu s;
439 VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, comparisonFiles[ j]);
419 } 440 }
420 drp->fResult = DiffRecord::kCouldNotCompare_Result; 441 drp->fResult = DiffRecord::kCouldNotCompare_Result;
421 442
422 } else if (are_buffers_equal(baseFileBits, comparisonFileBits)) { 443 } else if (are_buffers_equal(baseFileBits, comparisonFileBits)) {
423 drp->fResult = DiffRecord::kEqualBits_Result; 444 drp->fResult = DiffRecord::kEqualBits_Result;
424 445 VERBOSE_STATUS("MATCH", ANSI_COLOR_GREEN, baseFiles[i]);
425 } else { 446 } else {
426 AutoReleasePixels arp(drp); 447 AutoReleasePixels arp(drp);
427 get_bitmap(baseFileBits, drp->fBase, SkImageDecoder::kDecodePixe ls_Mode); 448 get_bitmap(baseFileBits, drp->fBase, SkImageDecoder::kDecodePixe ls_Mode);
428 get_bitmap(comparisonFileBits, drp->fComparison, 449 get_bitmap(comparisonFileBits, drp->fComparison,
429 SkImageDecoder::kDecodePixels_Mode); 450 SkImageDecoder::kDecodePixels_Mode);
451 VERBOSE_STATUS("DIFFERENT", ANSI_COLOR_RED, baseFiles[i]);
430 if (DiffResource::kDecoded_Status == drp->fBase.fStatus && 452 if (DiffResource::kDecoded_Status == drp->fBase.fStatus &&
431 DiffResource::kDecoded_Status == drp->fComparison.fStatus) { 453 DiffResource::kDecoded_Status == drp->fComparison.fStatus) {
432 create_and_write_diff_image(drp, dmp, colorThreshold, 454 create_and_write_diff_image(drp, dmp, colorThreshold,
433 outputDir, drp->fBase.fFilename) ; 455 outputDir, drp->fBase.fFilename) ;
434 } else { 456 } else {
435 drp->fResult = DiffRecord::kCouldNotCompare_Result; 457 drp->fResult = DiffRecord::kCouldNotCompare_Result;
436 } 458 }
437 } 459 }
438 460
439 ++i; 461 ++i;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 SkString comparisonDir; 573 SkString comparisonDir;
552 SkString outputDir; 574 SkString outputDir;
553 575
554 StringArray matchSubstrings; 576 StringArray matchSubstrings;
555 StringArray nomatchSubstrings; 577 StringArray nomatchSubstrings;
556 578
557 bool generateDiffs = true; 579 bool generateDiffs = true;
558 bool listFilenames = false; 580 bool listFilenames = false;
559 bool printDirNames = true; 581 bool printDirNames = true;
560 bool recurseIntoSubdirs = true; 582 bool recurseIntoSubdirs = true;
583 bool verbose = false;
561 584
562 RecordArray differences; 585 RecordArray differences;
563 DiffSummary summary; 586 DiffSummary summary;
564 587
565 bool failOnResultType[DiffRecord::kResultCount]; 588 bool failOnResultType[DiffRecord::kResultCount];
566 for (int i = 0; i < DiffRecord::kResultCount; i++) { 589 for (int i = 0; i < DiffRecord::kResultCount; i++) {
567 failOnResultType[i] = false; 590 failOnResultType[i] = false;
568 } 591 }
569 592
570 bool failOnStatusType[DiffResource::kStatusCount][DiffResource::kStatusCount ]; 593 bool failOnStatusType[DiffResource::kStatusCount][DiffResource::kStatusCount ];
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 continue; 641 continue;
619 } 642 }
620 if (!strcmp(argv[i], "--help")) { 643 if (!strcmp(argv[i], "--help")) {
621 usage(argv[0]); 644 usage(argv[0]);
622 return kNoError; 645 return kNoError;
623 } 646 }
624 if (!strcmp(argv[i], "--listfilenames")) { 647 if (!strcmp(argv[i], "--listfilenames")) {
625 listFilenames = true; 648 listFilenames = true;
626 continue; 649 continue;
627 } 650 }
651 if (!strcmp(argv[i], "--verbose")) {
652 verbose = true;
653 continue;
654 }
628 if (!strcmp(argv[i], "--match")) { 655 if (!strcmp(argv[i], "--match")) {
629 matchSubstrings.push(new SkString(argv[++i])); 656 matchSubstrings.push(new SkString(argv[++i]));
630 continue; 657 continue;
631 } 658 }
632 if (!strcmp(argv[i], "--nodiffs")) { 659 if (!strcmp(argv[i], "--nodiffs")) {
633 generateDiffs = false; 660 generateDiffs = false;
634 continue; 661 continue;
635 } 662 }
636 if (!strcmp(argv[i], "--nomatch")) { 663 if (!strcmp(argv[i], "--nomatch")) {
637 nomatchSubstrings.push(new SkString(argv[++i])); 664 nomatchSubstrings.push(new SkString(argv[++i]));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 748
722 // If no matchSubstrings were specified, match ALL strings 749 // If no matchSubstrings were specified, match ALL strings
723 // (except for whatever nomatchSubstrings were specified, if any). 750 // (except for whatever nomatchSubstrings were specified, if any).
724 if (matchSubstrings.isEmpty()) { 751 if (matchSubstrings.isEmpty()) {
725 matchSubstrings.push(new SkString("")); 752 matchSubstrings.push(new SkString(""));
726 } 753 }
727 754
728 create_diff_images(diffProc, colorThreshold, &differences, 755 create_diff_images(diffProc, colorThreshold, &differences,
729 baseDir, comparisonDir, outputDir, 756 baseDir, comparisonDir, outputDir,
730 matchSubstrings, nomatchSubstrings, recurseIntoSubdirs, g enerateDiffs, 757 matchSubstrings, nomatchSubstrings, recurseIntoSubdirs, g enerateDiffs,
731 &summary); 758 verbose, &summary);
732 summary.print(listFilenames, failOnResultType, failOnStatusType); 759 summary.print(listFilenames, failOnResultType, failOnStatusType);
733 760
734 if (differences.count()) { 761 if (differences.count()) {
735 qsort(differences.begin(), differences.count(), 762 qsort(differences.begin(), differences.count(),
736 sizeof(DiffRecord*), sortProc); 763 sizeof(DiffRecord*), sortProc);
737 } 764 }
738 765
739 if (generateDiffs) { 766 if (generateDiffs) {
740 print_diff_page(summary.fNumMatches, colorThreshold, differences, 767 print_diff_page(summary.fNumMatches, colorThreshold, differences,
741 baseDir, comparisonDir, outputDir); 768 baseDir, comparisonDir, outputDir);
(...skipping 25 matching lines...) Expand all
767 // range [0...255] are wrapped (mod 256). Do the conversion ourselves, to 794 // range [0...255] are wrapped (mod 256). Do the conversion ourselves, to
768 // make sure that we only return 0 when there were no failures. 795 // make sure that we only return 0 when there were no failures.
769 return (num_failing_results > 255) ? 255 : num_failing_results; 796 return (num_failing_results > 255) ? 255 : num_failing_results;
770 } 797 }
771 798
772 #if !defined SK_BUILD_FOR_IOS 799 #if !defined SK_BUILD_FOR_IOS
773 int main(int argc, char * const argv[]) { 800 int main(int argc, char * const argv[]) {
774 return tool_main(argc, (char**) argv); 801 return tool_main(argc, (char**) argv);
775 } 802 }
776 #endif 803 #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