| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Tests for our tools. |
| epoger@google.com | 3aa3358 | 2013-01-02 15:53:25 +0000 | [diff] [blame^] | 4 | # |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 5 | # TODO: for now, it only tests skdiff |
| epoger@google.com | 3aa3358 | 2013-01-02 15:53:25 +0000 | [diff] [blame^] | 6 | # |
| 7 | # TODO: currently, this only passes on Linux (which is the platform that |
| 8 | # the housekeeper bot runs on, e.g. |
| 9 | # http://70.32.156.51:10117/builders/Skia_PerCommit_House_Keeping/builds/1415/steps/RunToolSelfTests/logs/stdio ) |
| 10 | # See https://code.google.com/p/skia/issues/detail?id=677 |
| 11 | # ('make tools/tests/run.sh work cross-platform') |
| 12 | # Ideally, these tests should pass on all development platforms... |
| 13 | # otherwise, how can developers be expected to test them before committing a |
| 14 | # change? |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 15 | |
| 16 | # cd into .../trunk so all the paths will work |
| 17 | cd $(dirname $0)/../.. |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 18 | |
| 19 | # TODO: make it look in Release and/or Debug |
| 20 | SKDIFF_BINARY=out/Debug/skdiff |
| 21 | |
| epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 22 | # Compare contents of all files within directories $1 and $2, |
| 23 | # EXCEPT for any dotfiles. |
| 24 | # If there are any differences, a description is written to stdout and |
| 25 | # we exit with a nonzero return value. |
| 26 | # Otherwise, we write nothing to stdout and return. |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 27 | function compare_directories { |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 28 | if [ $# != 2 ]; then |
| 29 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 30 | exit 1 |
| 31 | fi |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 32 | diff --exclude=.* $1 $2 |
| 33 | if [ $? != 0 ]; then |
| 34 | echo "failed in: compare_directories $1 $2" |
| 35 | exit 1 |
| 36 | fi |
| 37 | } |
| 38 | |
| epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 39 | # Run skdiff with arguments in $1 (plus implicit final argument causing skdiff |
| 40 | # to write its output, if any, to directory $2/output-actual). |
| 41 | # Then compare its results against those in $2/output-expected. |
| 42 | function skdiff_test { |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 43 | if [ $# != 2 ]; then |
| 44 | echo "skdiff_test requires exactly 2 parameters, got $#" |
| 45 | exit 1 |
| 46 | fi |
| epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 47 | SKDIFF_ARGS="$1" |
| 48 | ACTUAL_OUTPUT_DIR="$2/output-actual" |
| 49 | EXPECTED_OUTPUT_DIR="$2/output-expected" |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 50 | |
| epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 51 | rm -rf $ACTUAL_OUTPUT_DIR |
| 52 | mkdir -p $ACTUAL_OUTPUT_DIR |
| epoger@google.com | 90cb9b3 | 2012-05-18 18:25:26 +0000 | [diff] [blame] | 53 | COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR" |
| 54 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| 55 | $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout |
| 56 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 57 | |
| epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 58 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 59 | } |
| 60 | |
| 61 | SKDIFF_TESTDIR=tools/tests/skdiff |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 62 | |
| epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 63 | # Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from |
| 64 | # baseDir, etc. |
| epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 65 | skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 66 | |
| epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 67 | # Run skdiff over the same set of files, but with arguments as used by our buildbots: |
| 68 | # - return the number of mismatching file pairs (but ignore any files missing from either |
| 69 | # baseDir or comparisonDir) |
| epoger@google.com | 46a4596 | 2012-07-12 18:16:02 +0000 | [diff] [blame] | 70 | # - list filenames with each result type to stdout |
| 71 | # - don't generate HTML output files |
| bungeman@google.com | e3c8ddf | 2012-12-05 20:13:12 +0000 | [diff] [blame] | 72 | skdiff_test "--failonresult DifferentPixels --failonresult DifferentSizes --failonresult Unknown --failonstatus CouldNotDecode,CouldNotRead any --failonstatus any CouldNotDecode,CouldNotRead --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 73 | |
| epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 74 | # Run skdiff over just the files that have identical bits. |
| 75 | skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 76 | |
| epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 77 | # Run skdiff over just the files that have identical bits or identical pixels. |
| 78 | skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 79 | |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 80 | echo "All tests passed." |