skdiff: replace --failonmismatches with repeatable --failonresult option
authorepoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 13 Jul 2012 21:22:02 +0000 (21:22 +0000)
committerepoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 13 Jul 2012 21:22:02 +0000 (21:22 +0000)
Review URL: https://codereview.appspot.com/6392064

git-svn-id: http://skia.googlecode.com/svn/trunk@4611 2bbb7eff-a529-9590-31e7-b0007b416f81

tools/skdiff_main.cpp
tools/tests/run.sh
tools/tests/skdiff/identical-bits-or-pixels/output-expected/command_line
tools/tests/skdiff/identical-bits/output-expected/command_line
tools/tests/skdiff/test2/output-expected/command_line
tools/tests/skdiff/test2/output-expected/return_value

index d70027aaf55c7202e55d1052450443e0df1eedba..f20475aedb0565cd83452090446ee76ed53f3e3e 100644 (file)
@@ -54,6 +54,37 @@ enum Result {
     kNumResultTypes  // NOT A VALID VALUE--used to set up arrays. Must be last.
 };
 
+// Returns the Result with this name.
+// If there is no Result with this name, returns kNumResultTypes.
+// TODO: Is there a better return value for the fall-through case?
+Result getResultByName(const char *name) {
+    if (0 == strcmp("EqualBits", name)) {
+        return kEqualBits;
+    }
+    if (0 == strcmp("EqualPixels", name)) {
+        return kEqualPixels;
+    }
+    if (0 == strcmp("DifferentPixels", name)) {
+        return kDifferentPixels;
+    }
+    if (0 == strcmp("DifferentSizes", name)) {
+        return kDifferentSizes;
+    }
+    if (0 == strcmp("DifferentOther", name)) {
+        return kDifferentOther;
+    }
+    if (0 == strcmp("ComparisonMissing", name)) {
+        return kComparisonMissing;
+    }
+    if (0 == strcmp("BaseMissing", name)) {
+        return kBaseMissing;
+    }
+    if (0 == strcmp("Unknown", name)) {
+        return kUnknown;
+    }
+    return kNumResultTypes;
+}
+
 // Returns a text description of the given Result type.
 const char *getResultDescription(Result result) {
     switch (result) {
@@ -1079,19 +1110,22 @@ static void usage (char * argv0) {
 , argv0, argv0);
     SkDebugf(
 "\nArguments:"
+"\n    --failonresult <result>: After comparing all file pairs, exit with nonzero"
+"\n                             return code (number of file pairs yielding this"
+"\n                             result) if any file pairs yielded this result."
+"\n                             This flag may be repeated, in which case the"
+"\n                             return code will be the number of fail pairs"
+"\n                             yielding ANY of these results."
 "\n    --help: display this info"
-"\n    --failonmismatches: exit with nonzero return code (number of mismatching"
-"\n                        image pairs) if any pairs differ by more than threshold;"
-"\n                        otherwise, only return nonzero if the tool itself fails"
 "\n    --listfilenames: list all filenames for each result type in stdout"
-"\n    --match: compare files whose filenames contain this substring; if"
-"\n             unspecified, compare ALL files."
-"\n             this flag may be repeated to add more matching substrings."
+"\n    --match <substring>: compare files whose filenames contain this substring;"
+"\n                         if unspecified, compare ALL files."
+"\n                         this flag may be repeated."
 "\n    --nodiffs: don't write out image diffs or index.html, just generate"
 "\n               report on stdout"
-"\n    --nomatch: regardless of --match, DO NOT compare files whose filenames"
-"\n               contain this substring."
-"\n               this flag may be repeated to add more forbidden substrings."
+"\n    --nomatch <substring>: regardless of --match, DO NOT compare files whose"
+"\n                           filenames contain this substring."
+"\n                           this flag may be repeated."
 "\n    --noprintdirs: do not print the directories used."
 "\n    --sortbymaxmismatch: sort by worst color channel mismatch;"
 "\n                         break ties with -sortbymismatch"
@@ -1121,10 +1155,11 @@ int main (int argc, char ** argv) {
     SkString baseDir;
     SkString comparisonDir;
     SkString outputDir;
+
     StringArray matchSubstrings;
     StringArray nomatchSubstrings;
+    SkTDArray<Result> failOnTheseResultTypes;
 
-    bool failOnMismatches = false;
     bool generateDiffs = true;
     bool listFilenames = false;
     bool printDirs = true;
@@ -1135,8 +1170,11 @@ int main (int argc, char ** argv) {
     int i;
     int numUnflaggedArguments = 0;
     for (i = 1; i < argc; i++) {
-        if (!strcmp(argv[i], "--failonmismatches")) {
-            failOnMismatches = true;
+        if (!strcmp(argv[i], "--failonresult")) {
+            Result type = getResultByName(argv[++i]);
+            if (!failOnTheseResultTypes.contains(type)) {
+                failOnTheseResultTypes.push(type);
+            }
             continue;
         }
         if (!strcmp(argv[i], "--help")) {
@@ -1264,9 +1302,10 @@ int main (int argc, char ** argv) {
     matchSubstrings.deleteAll();
     nomatchSubstrings.deleteAll();
 
-    if (failOnMismatches) {
-        return summary.fNumMismatches;
-    } else {
-        return kNoError;
+    int num_failing_results = 0;
+    for (int i = 0; i < failOnTheseResultTypes.count(); i++) {
+        Result type = failOnTheseResultTypes[i];
+        num_failing_results += summary.fResultsOfType[type].count();
     }
+    return num_failing_results;
 }
index 25baf1987a780c0d574a7484c3f8261a49dd8b75..7f00ced8dccc03088e74973283d6dd17f322f016 100755 (executable)
@@ -40,22 +40,21 @@ function skdiff_test {
 
 SKDIFF_TESTDIR=tools/tests/skdiff
 
-# Run skdiff over a variety of file pair types: identical bits, identical
-# pixels, missing from baseDir, etc.
+# Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from
+# baseDir, etc.
 skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"
 
-# Same as above, except:
-# - return the number of mismatching file pairs
+# Run skdiff over the same set of files, but with arguments as used by our buildbots:
+# - return the number of mismatching file pairs (but ignore any files missing from either
+#   baseDir or comparisonDir)
 # - list filenames with each result type to stdout
 # - don't generate HTML output files
-skdiff_test "--failonmismatches --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2"
+skdiff_test "--failonresult DifferentPixels --failonresult DifferentSizes --failonresult DifferentOther --failonresult Unknown --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2"
 
-# Run skdiff over just the files that have identical bits, to validate any
-# behavior/return value differences in this case.
-skdiff_test "--failonmismatches --nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"
+# Run skdiff over just the files that have identical bits.
+skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"
 
-# Run skdiff over just the files that have identical bits or identical pixels,
-# to validate any behavior/return value differences in this case.
-skdiff_test "--failonmismatches --nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"
+# Run skdiff over just the files that have identical bits or identical pixels.
+skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"
 
 echo "All tests passed."
index eed0759ac59506c4212ef1bc71c6f22ae64db010..8a20667901a6967d381b0f6c888cb73b084be4e0 100644 (file)
@@ -1 +1 @@
-out/Debug/skdiff --failonmismatches --nodiffs --match identical-bits --match identical-pixels tools/tests/skdiff/baseDir tools/tests/skdiff/comparisonDir tools/tests/skdiff/identical-bits-or-pixels/output-actual
+out/Debug/skdiff --nodiffs --match identical-bits --match identical-pixels tools/tests/skdiff/baseDir tools/tests/skdiff/comparisonDir tools/tests/skdiff/identical-bits-or-pixels/output-actual
index 5c8c27bbb61eb088a125f40b1c4964772da80bac..49f9ad5e7402085eca5025d004b0562d7c90469d 100644 (file)
@@ -1 +1 @@
-out/Debug/skdiff --failonmismatches --nodiffs --match identical-bits tools/tests/skdiff/baseDir tools/tests/skdiff/comparisonDir tools/tests/skdiff/identical-bits/output-actual
+out/Debug/skdiff --nodiffs --match identical-bits tools/tests/skdiff/baseDir tools/tests/skdiff/comparisonDir tools/tests/skdiff/identical-bits/output-actual
index 22dcf74a7697d5a96ea8f3d03de5dfdc0c7c6ef1..97724dfbd68f90768039d8767da8245087e5d80c 100644 (file)
@@ -1 +1 @@
-out/Debug/skdiff --failonmismatches --listfilenames --nodiffs tools/tests/skdiff/baseDir tools/tests/skdiff/comparisonDir tools/tests/skdiff/test2/output-actual
+out/Debug/skdiff --failonresult DifferentPixels --failonresult DifferentSizes --failonresult DifferentOther --failonresult Unknown --listfilenames --nodiffs tools/tests/skdiff/baseDir tools/tests/skdiff/comparisonDir tools/tests/skdiff/test2/output-actual