epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Self-tests for gm, based on tools/tests/run.sh |
epoger@google.com | 454008a | 2012-11-13 20:46:50 +0000 | [diff] [blame] | 4 | # |
| 5 | # These tests are run by the Skia_PerCommit_House_Keeping bot at every commit, |
| 6 | # so make sure that they still pass when you make changes to gm! |
| 7 | # |
| 8 | # TODO: Even though these tests are passing on the Skia_PerCommit_House_Keeping |
| 9 | # bot (which runs on Linux), they fail when I run them on my Mac. |
| 10 | # Ideally, these tests should pass on all development platforms... |
| 11 | # otherwise, how can developers be expected to test them before committing a |
| 12 | # change? |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 13 | |
| 14 | # cd into .../trunk so all the paths will work |
| 15 | cd $(dirname $0)/../.. |
| 16 | |
| 17 | # TODO(epoger): make it look in Release and/or Debug |
| 18 | GM_BINARY=out/Debug/gm |
| 19 | |
| 20 | # Compare contents of all files within directories $1 and $2, |
| 21 | # EXCEPT for any dotfiles. |
| 22 | # If there are any differences, a description is written to stdout and |
| 23 | # we exit with a nonzero return value. |
| 24 | # Otherwise, we write nothing to stdout and return. |
| 25 | function compare_directories { |
| 26 | if [ $# != 2 ]; then |
| 27 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 28 | exit 1 |
| 29 | fi |
| 30 | diff -r --exclude=.* $1 $2 |
| 31 | if [ $? != 0 ]; then |
| 32 | echo "failed in: compare_directories $1 $2" |
| 33 | exit 1 |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | # Run gm... |
| 38 | # - with the arguments in $1 |
| 39 | # - writing resulting images into $2/output-actual/images |
| 40 | # - writing stdout into $2/output-actual/stdout |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 41 | # - writing json summary into $2/output-actual/json-summary.txt |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 42 | # - writing return value into $2/output-actual/return_value |
| 43 | # Then compare all of those against $2/output-expected . |
| 44 | function gm_test { |
| 45 | if [ $# != 2 ]; then |
| 46 | echo "gm_test requires exactly 2 parameters, got $#" |
| 47 | exit 1 |
| 48 | fi |
| 49 | GM_ARGS="$1" |
| 50 | ACTUAL_OUTPUT_DIR="$2/output-actual" |
| 51 | EXPECTED_OUTPUT_DIR="$2/output-expected" |
| 52 | |
| 53 | rm -rf $ACTUAL_OUTPUT_DIR |
| 54 | mkdir -p $ACTUAL_OUTPUT_DIR |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 55 | COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $ACTUAL_OUTPUT_DIR/json-summary.txt -w $ACTUAL_OUTPUT_DIR/images" |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 56 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| 57 | $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout |
| 58 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 59 | |
| 60 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 61 | } |
| 62 | |
| 63 | GM_TESTDIR=gm/tests |
| 64 | GM_INPUTS=$GM_TESTDIR/inputs |
| 65 | GM_OUTPUTS=$GM_TESTDIR/outputs |
| 66 | |
epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 67 | # Compare generated image against an input image file with identical bytes. |
epoger@google.com | 8a6f13a | 2012-12-05 20:21:35 +0000 | [diff] [blame] | 68 | gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes" |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 69 | |
epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 70 | # Compare generated image against an input image file with identical pixels but different PNG encoding. |
epoger@google.com | 8a6f13a | 2012-12-05 20:21:35 +0000 | [diff] [blame] | 71 | gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels" |
epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 72 | |
| 73 | # Compare generated image against an input image file with different pixels. |
epoger@google.com | 8a6f13a | 2012-12-05 20:21:35 +0000 | [diff] [blame] | 74 | gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels" |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 75 | |
epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 76 | # Compare generated image against an empty "expected image" dir. |
| 77 | gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir" |
| 78 | |
epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame^] | 79 | # If run without "-r", the JSON's "actual-results" section should contain |
| 80 | # actual checksums marked as "failure-ignored", but the "expected-results" |
| 81 | # section should be empty. |
| 82 | gm_test "--hierarchy --match dashing2 --config 8888" "$GM_OUTPUTS/no-readpath" |
| 83 | |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 84 | echo "All tests passed." |