| 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 | # |
| epoger@google.com | 3aa3358 | 2013-01-02 15:53:25 +0000 | [diff] [blame] | 8 | # TODO: currently, this only passes on Linux (which is the platform that |
| 9 | # the housekeeper bot runs on, e.g. |
| 10 | # http://70.32.156.51:10117/builders/Skia_PerCommit_House_Keeping/builds/1417/steps/RunGmSelfTests/logs/stdio ) |
| 11 | # See https://code.google.com/p/skia/issues/detail?id=677 |
| 12 | # ('make tools/tests/run.sh work cross-platform') |
| epoger@google.com | 454008a | 2012-11-13 20:46:50 +0000 | [diff] [blame] | 13 | # Ideally, these tests should pass on all development platforms... |
| 14 | # otherwise, how can developers be expected to test them before committing a |
| 15 | # change? |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 16 | |
| 17 | # cd into .../trunk so all the paths will work |
| 18 | cd $(dirname $0)/../.. |
| 19 | |
| 20 | # TODO(epoger): make it look in Release and/or Debug |
| 21 | GM_BINARY=out/Debug/gm |
| 22 | |
| 23 | # Compare contents of all files within directories $1 and $2, |
| 24 | # EXCEPT for any dotfiles. |
| 25 | # If there are any differences, a description is written to stdout and |
| 26 | # we exit with a nonzero return value. |
| 27 | # Otherwise, we write nothing to stdout and return. |
| 28 | function compare_directories { |
| 29 | if [ $# != 2 ]; then |
| 30 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 31 | exit 1 |
| 32 | fi |
| 33 | diff -r --exclude=.* $1 $2 |
| 34 | if [ $? != 0 ]; then |
| 35 | echo "failed in: compare_directories $1 $2" |
| 36 | exit 1 |
| 37 | fi |
| 38 | } |
| 39 | |
| 40 | # Run gm... |
| 41 | # - with the arguments in $1 |
| 42 | # - writing resulting images into $2/output-actual/images |
| 43 | # - writing stdout into $2/output-actual/stdout |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 44 | # - writing json summary into $2/output-actual/json-summary.txt |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 45 | # - writing return value into $2/output-actual/return_value |
| 46 | # Then compare all of those against $2/output-expected . |
| 47 | function gm_test { |
| 48 | if [ $# != 2 ]; then |
| 49 | echo "gm_test requires exactly 2 parameters, got $#" |
| 50 | exit 1 |
| 51 | fi |
| 52 | GM_ARGS="$1" |
| 53 | ACTUAL_OUTPUT_DIR="$2/output-actual" |
| 54 | EXPECTED_OUTPUT_DIR="$2/output-expected" |
| 55 | |
| 56 | rm -rf $ACTUAL_OUTPUT_DIR |
| 57 | mkdir -p $ACTUAL_OUTPUT_DIR |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 58 | 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] | 59 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| 60 | $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout |
| 61 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 62 | |
| epoger@google.com | 98204f9 | 2013-01-16 04:19:01 +0000 | [diff] [blame^] | 63 | # Temporary hack to alleviate |
| 64 | # http://code.google.com/p/skia/issues/detail?id=1068 ('GM self-test failures') |
| 65 | # (Remove instance-counting lines from the Debug output) |
| 66 | grep -v Leaked $ACTUAL_OUTPUT_DIR/stdout >$ACTUAL_OUTPUT_DIR/stdout-tmp |
| 67 | mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout |
| 68 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 69 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 70 | } |
| 71 | |
| 72 | GM_TESTDIR=gm/tests |
| 73 | GM_INPUTS=$GM_TESTDIR/inputs |
| 74 | GM_OUTPUTS=$GM_TESTDIR/outputs |
| 75 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 76 | # Compare generated image against an input image file with identical bytes. |
| epoger@google.com | 8a6f13a | 2012-12-05 20:21:35 +0000 | [diff] [blame] | 77 | 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] | 78 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 79 | # 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] | 80 | 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] | 81 | |
| 82 | # Compare generated image against an input image file with different pixels. |
| epoger@google.com | 8a6f13a | 2012-12-05 20:21:35 +0000 | [diff] [blame] | 83 | 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] | 84 | |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 85 | # Compare generated image against an empty "expected image" dir. |
| 86 | gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir" |
| 87 | |
| epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 88 | # If run without "-r", the JSON's "actual-results" section should contain |
| 89 | # actual checksums marked as "failure-ignored", but the "expected-results" |
| 90 | # section should be empty. |
| 91 | gm_test "--hierarchy --match dashing2 --config 8888" "$GM_OUTPUTS/no-readpath" |
| 92 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 93 | echo "All tests passed." |