| 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 | 0b62b3d | 2013-03-20 17:59:28 +0000 | [diff] [blame] | 8 | # To generate new baselines when gm behavior changes, run gm/tests/rebaseline.sh |
| 9 | # |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 10 | # TODO: because this is written as a shell script (instead of, say, Python) |
| 11 | # it only runs on Linux and Mac. |
| epoger@google.com | 3aa3358 | 2013-01-02 15:53:25 +0000 | [diff] [blame] | 12 | # See https://code.google.com/p/skia/issues/detail?id=677 |
| 13 | # ('make tools/tests/run.sh work cross-platform') |
| epoger@google.com | 454008a | 2012-11-13 20:46:50 +0000 | [diff] [blame] | 14 | # Ideally, these tests should pass on all development platforms... |
| 15 | # otherwise, how can developers be expected to test them before committing a |
| 16 | # change? |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 17 | |
| 18 | # cd into .../trunk so all the paths will work |
| 19 | cd $(dirname $0)/../.. |
| 20 | |
| 21 | # TODO(epoger): make it look in Release and/or Debug |
| 22 | GM_BINARY=out/Debug/gm |
| 23 | |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 24 | OUTPUT_ACTUAL_SUBDIR=output-actual |
| 25 | OUTPUT_EXPECTED_SUBDIR=output-expected |
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 26 | CONFIGS="--config 8888 565" |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 27 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 28 | # Compare contents of all files within directories $1 and $2, |
| 29 | # EXCEPT for any dotfiles. |
| 30 | # If there are any differences, a description is written to stdout and |
| 31 | # we exit with a nonzero return value. |
| 32 | # Otherwise, we write nothing to stdout and return. |
| 33 | function compare_directories { |
| 34 | if [ $# != 2 ]; then |
| 35 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 36 | exit 1 |
| 37 | fi |
| 38 | diff -r --exclude=.* $1 $2 |
| 39 | if [ $? != 0 ]; then |
| 40 | echo "failed in: compare_directories $1 $2" |
| 41 | exit 1 |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | # Run gm... |
| 46 | # - with the arguments in $1 |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 47 | # - writing stdout into $2/$OUTPUT_ACTUAL_SUBDIR/stdout |
| 48 | # - writing json summary into $2/$OUTPUT_ACTUAL_SUBDIR/json-summary.txt |
| 49 | # - writing return value into $2/$OUTPUT_ACTUAL_SUBDIR/return_value |
| 50 | # Then compare all of those against $2/$OUTPUT_EXPECTED_SUBDIR . |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 51 | function gm_test { |
| 52 | if [ $# != 2 ]; then |
| 53 | echo "gm_test requires exactly 2 parameters, got $#" |
| 54 | exit 1 |
| 55 | fi |
| 56 | GM_ARGS="$1" |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 57 | ACTUAL_OUTPUT_DIR="$2/$OUTPUT_ACTUAL_SUBDIR" |
| 58 | EXPECTED_OUTPUT_DIR="$2/$OUTPUT_EXPECTED_SUBDIR" |
| 59 | JSON_SUMMARY_FILE="$ACTUAL_OUTPUT_DIR/json-summary.txt" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 60 | |
| 61 | rm -rf $ACTUAL_OUTPUT_DIR |
| 62 | mkdir -p $ACTUAL_OUTPUT_DIR |
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 63 | COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummaryPath $JSON_SUMMARY_FILE" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 64 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 65 | $COMMAND >$ACTUAL_OUTPUT_DIR/stdout 2>$ACTUAL_OUTPUT_DIR/stderr |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 66 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 67 | |
| epoger@google.com | 80d4478 | 2013-01-18 20:03:58 +0000 | [diff] [blame] | 68 | # Only compare selected lines in the stdout, to ignore any spurious lines |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 69 | # as noted in http://code.google.com/p/skia/issues/detail?id=1068 . |
| 70 | # |
| 71 | # TODO(epoger): This is still hacky... we need to rewrite this script in |
| 72 | # Python soon, and make stuff like this more maintainable. |
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 73 | grep ^GM: $ACTUAL_OUTPUT_DIR/stdout >$ACTUAL_OUTPUT_DIR/stdout-tmp |
| epoger@google.com | 98204f9 | 2013-01-16 04:19:01 +0000 | [diff] [blame] | 74 | mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout |
| epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 75 | grep ^GM: $ACTUAL_OUTPUT_DIR/stderr >$ACTUAL_OUTPUT_DIR/stderr-tmp |
| 76 | mv $ACTUAL_OUTPUT_DIR/stderr-tmp $ACTUAL_OUTPUT_DIR/stderr |
| epoger@google.com | 98204f9 | 2013-01-16 04:19:01 +0000 | [diff] [blame] | 77 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 78 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 79 | } |
| 80 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 81 | # Create input dir (at path $1) with expectations (both image and json) |
| 82 | # that gm will match or mismatch as appropriate. |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 83 | # |
| 84 | # We used to check these files into SVN, but then we needed to rebasline them |
| 85 | # when our drawing changed at all... so, as proposed in |
| 86 | # http://code.google.com/p/skia/issues/detail?id=1068 , we generate them |
| 87 | # new each time. |
| 88 | function create_inputs_dir { |
| 89 | if [ $# != 1 ]; then |
| 90 | echo "create_inputs_dir requires exactly 1 parameter, got $#" |
| 91 | exit 1 |
| 92 | fi |
| 93 | INPUTS_DIR="$1" |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 94 | IMAGES_DIR=$INPUTS_DIR/images |
| 95 | JSON_DIR=$INPUTS_DIR/json |
| 96 | mkdir -p $IMAGES_DIR $JSON_DIR |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 97 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 98 | mkdir -p $IMAGES_DIR/identical-bytes |
| 99 | # Run GM to write out the images actually generated. |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 100 | $GM_BINARY --hierarchy --match selftest1 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 101 | -w $IMAGES_DIR/identical-bytes |
| 102 | # Run GM again to read in those images and write them out as a JSON summary. |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 103 | $GM_BINARY --hierarchy --match selftest1 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 104 | -r $IMAGES_DIR/identical-bytes \ |
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 105 | --writeJsonSummaryPath $JSON_DIR/identical-bytes.json |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 106 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 107 | mkdir -p $IMAGES_DIR/identical-pixels |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 108 | $GM_BINARY --hierarchy --match selftest1 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 109 | -w $IMAGES_DIR/identical-pixels |
| 110 | echo "more bytes that do not change the image pixels" \ |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 111 | >> $IMAGES_DIR/identical-pixels/8888/selftest1.png |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 112 | echo "more bytes that do not change the image pixels" \ |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 113 | >> $IMAGES_DIR/identical-pixels/565/selftest1.png |
| 114 | $GM_BINARY --hierarchy --match selftest1 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 115 | -r $IMAGES_DIR/identical-pixels \ |
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 116 | --writeJsonSummaryPath $JSON_DIR/identical-pixels.json |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 117 | |
| 118 | mkdir -p $IMAGES_DIR/different-pixels |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 119 | $GM_BINARY --hierarchy --match selftest2 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 120 | -w $IMAGES_DIR/different-pixels |
| commit-bot@chromium.org | c61c3c3 | 2013-03-01 15:32:34 +0000 | [diff] [blame] | 121 | mv $IMAGES_DIR/different-pixels/8888/selftest2.png \ |
| 122 | $IMAGES_DIR/different-pixels/8888/selftest1.png |
| 123 | mv $IMAGES_DIR/different-pixels/565/selftest2.png \ |
| 124 | $IMAGES_DIR/different-pixels/565/selftest1.png |
| 125 | $GM_BINARY --hierarchy --match selftest1 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 126 | -r $IMAGES_DIR/different-pixels \ |
| scroggo@google.com | 09fd4d2 | 2013-03-20 14:20:18 +0000 | [diff] [blame] | 127 | --writeJsonSummaryPath $JSON_DIR/different-pixels.json |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 128 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame] | 129 | mkdir -p $IMAGES_DIR/empty-dir |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 132 | GM_TESTDIR=gm/tests |
| 133 | GM_INPUTS=$GM_TESTDIR/inputs |
| 134 | GM_OUTPUTS=$GM_TESTDIR/outputs |
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 135 | GM_TEMPFILES=$GM_TESTDIR/tempfiles |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 136 | |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 137 | create_inputs_dir $GM_INPUTS |
| 138 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 139 | # Compare generated image against an input image file with identical bytes. |
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame^] | 140 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes-images" |
| 141 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-bytes.json" "$GM_OUTPUTS/compared-against-identical-bytes-json" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 142 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 143 | # Compare generated image against an input image file with identical pixels but different PNG encoding. |
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame^] | 144 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels-images" |
| 145 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-pixels.json" "$GM_OUTPUTS/compared-against-identical-pixels-json" |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 146 | |
| 147 | # Compare generated image against an input image file with different pixels. |
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame^] | 148 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels-images" |
| 149 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels.json" "$GM_OUTPUTS/compared-against-different-pixels-json" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 150 | |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 151 | # Compare generated image against an empty "expected image" dir. |
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame^] | 152 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir" |
| 153 | |
| 154 | # Compare generated image against an empty "expected image" dir, but NOT in verbose mode. |
| 155 | gm_test "--hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/nonverbose" |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 156 | |
| epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 157 | # If run without "-r", the JSON's "actual-results" section should contain |
| 158 | # actual checksums marked as "failure-ignored", but the "expected-results" |
| 159 | # section should be empty. |
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame^] | 160 | gm_test "--verbose --hierarchy --match selftest1 $CONFIGS" "$GM_OUTPUTS/no-readpath" |
| epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 161 | |
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 162 | # Test what happens if a subset of the renderModes fail (e.g. pipe) |
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame^] | 163 | gm_test "--simulatePipePlaybackFailure --verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-pixels.json" "$GM_OUTPUTS/pipe-playback-failure" |
| epoger@google.com | caac3db | 2013-04-04 19:23:11 +0000 | [diff] [blame] | 164 | |
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 165 | # Confirm that IntentionallySkipped tests are recorded as such. |
| epoger@google.com | 51dbabe | 2013-04-10 15:24:53 +0000 | [diff] [blame^] | 166 | gm_test "--verbose --hierarchy --match selftest1 selftest2 $CONFIGS" "$GM_OUTPUTS/intentionally-skipped-tests" |
| epoger@google.com | c8263e7 | 2013-04-10 12:17:34 +0000 | [diff] [blame] | 167 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 168 | echo "All tests passed." |