| 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 | |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 23 | OUTPUT_ACTUAL_SUBDIR=output-actual |
| 24 | OUTPUT_EXPECTED_SUBDIR=output-expected |
| epoger@google.com | 4688de1 | 2013-01-31 15:06:36 +0000 | [diff] [blame] | 25 | CONFIGS="--config 8888 --config 565" |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 26 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 27 | # Compare contents of all files within directories $1 and $2, |
| 28 | # EXCEPT for any dotfiles. |
| 29 | # If there are any differences, a description is written to stdout and |
| 30 | # we exit with a nonzero return value. |
| 31 | # Otherwise, we write nothing to stdout and return. |
| 32 | function compare_directories { |
| 33 | if [ $# != 2 ]; then |
| 34 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 35 | exit 1 |
| 36 | fi |
| 37 | diff -r --exclude=.* $1 $2 |
| 38 | if [ $? != 0 ]; then |
| 39 | echo "failed in: compare_directories $1 $2" |
| 40 | exit 1 |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | # Run gm... |
| 45 | # - with the arguments in $1 |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 46 | # - writing stdout into $2/$OUTPUT_ACTUAL_SUBDIR/stdout |
| 47 | # - writing json summary into $2/$OUTPUT_ACTUAL_SUBDIR/json-summary.txt |
| 48 | # - writing return value into $2/$OUTPUT_ACTUAL_SUBDIR/return_value |
| 49 | # Then compare all of those against $2/$OUTPUT_EXPECTED_SUBDIR . |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 50 | function gm_test { |
| 51 | if [ $# != 2 ]; then |
| 52 | echo "gm_test requires exactly 2 parameters, got $#" |
| 53 | exit 1 |
| 54 | fi |
| 55 | GM_ARGS="$1" |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 56 | ACTUAL_OUTPUT_DIR="$2/$OUTPUT_ACTUAL_SUBDIR" |
| 57 | EXPECTED_OUTPUT_DIR="$2/$OUTPUT_EXPECTED_SUBDIR" |
| 58 | JSON_SUMMARY_FILE="$ACTUAL_OUTPUT_DIR/json-summary.txt" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 59 | |
| 60 | rm -rf $ACTUAL_OUTPUT_DIR |
| 61 | mkdir -p $ACTUAL_OUTPUT_DIR |
| epoger@google.com | 80d4478 | 2013-01-18 20:03:58 +0000 | [diff] [blame] | 62 | COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $JSON_SUMMARY_FILE" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 63 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| 64 | $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout |
| 65 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 66 | |
| epoger@google.com | 80d4478 | 2013-01-18 20:03:58 +0000 | [diff] [blame] | 67 | # 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] | 68 | # as noted in http://code.google.com/p/skia/issues/detail?id=1068 . |
| 69 | # |
| 70 | # TODO(epoger): This is still hacky... we need to rewrite this script in |
| 71 | # Python soon, and make stuff like this more maintainable. |
| 72 | grep --regexp=^reading --regexp=^writing --regexp=^drawing \ |
| 73 | --regexp=^FAILED --regexp=^Ran $ACTUAL_OUTPUT_DIR/stdout \ |
| 74 | >$ACTUAL_OUTPUT_DIR/stdout-tmp |
| epoger@google.com | 98204f9 | 2013-01-16 04:19:01 +0000 | [diff] [blame] | 75 | mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout |
| 76 | |
| epoger@google.com | 80d4478 | 2013-01-18 20:03:58 +0000 | [diff] [blame] | 77 | # Replace particular checksums in json summary with a placeholder, so |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 78 | # we don't need to rebaseline these json files when our drawing routines |
| 79 | # change. |
| 80 | sed -e 's/"checksum" : [0-9]*/"checksum" : FAKE/g' \ |
| 81 | --in-place $JSON_SUMMARY_FILE |
| 82 | sed -e 's/"checksums" : \[ [0-9]* \]/"checksums" : [ FAKE ]/g' \ |
| 83 | --in-place $JSON_SUMMARY_FILE |
| 84 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 85 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 86 | } |
| 87 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 88 | # Create input dir (at path $1) with expectations (both image and json) |
| 89 | # that gm will match or mismatch as appropriate. |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 90 | # |
| 91 | # We used to check these files into SVN, but then we needed to rebasline them |
| 92 | # when our drawing changed at all... so, as proposed in |
| 93 | # http://code.google.com/p/skia/issues/detail?id=1068 , we generate them |
| 94 | # new each time. |
| 95 | function create_inputs_dir { |
| 96 | if [ $# != 1 ]; then |
| 97 | echo "create_inputs_dir requires exactly 1 parameter, got $#" |
| 98 | exit 1 |
| 99 | fi |
| 100 | INPUTS_DIR="$1" |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 101 | IMAGES_DIR=$INPUTS_DIR/images |
| 102 | JSON_DIR=$INPUTS_DIR/json |
| 103 | mkdir -p $IMAGES_DIR $JSON_DIR |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 104 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 105 | mkdir -p $IMAGES_DIR/identical-bytes |
| 106 | # Run GM to write out the images actually generated. |
| epoger@google.com | 4688de1 | 2013-01-31 15:06:36 +0000 | [diff] [blame] | 107 | $GM_BINARY --hierarchy --match dashing2 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 108 | -w $IMAGES_DIR/identical-bytes |
| 109 | # Run GM again to read in those images and write them out as a JSON summary. |
| epoger@google.com | 4688de1 | 2013-01-31 15:06:36 +0000 | [diff] [blame] | 110 | $GM_BINARY --hierarchy --match dashing2 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 111 | -r $IMAGES_DIR/identical-bytes \ |
| 112 | --writeJsonSummary $JSON_DIR/identical-bytes.json |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 113 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 114 | mkdir -p $IMAGES_DIR/identical-pixels |
| 115 | $GM_BINARY --hierarchy --match dashing2 $CONFIGS \ |
| 116 | -w $IMAGES_DIR/identical-pixels |
| 117 | echo "more bytes that do not change the image pixels" \ |
| 118 | >> $IMAGES_DIR/identical-pixels/8888/dashing2.png |
| 119 | echo "more bytes that do not change the image pixels" \ |
| 120 | >> $IMAGES_DIR/identical-pixels/565/dashing2.png |
| 121 | $GM_BINARY --hierarchy --match dashing2 $CONFIGS \ |
| 122 | -r $IMAGES_DIR/identical-pixels \ |
| 123 | --writeJsonSummary $JSON_DIR/identical-pixels.json |
| 124 | |
| 125 | mkdir -p $IMAGES_DIR/different-pixels |
| epoger@google.com | 4688de1 | 2013-01-31 15:06:36 +0000 | [diff] [blame] | 126 | $GM_BINARY --hierarchy --match dashing3 $CONFIGS \ |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 127 | -w $IMAGES_DIR/different-pixels |
| 128 | mv $IMAGES_DIR/different-pixels/8888/dashing3.png \ |
| 129 | $IMAGES_DIR/different-pixels/8888/dashing2.png |
| 130 | mv $IMAGES_DIR/different-pixels/565/dashing3.png \ |
| 131 | $IMAGES_DIR/different-pixels/565/dashing2.png |
| 132 | $GM_BINARY --hierarchy --match dashing2 $CONFIGS \ |
| 133 | -r $IMAGES_DIR/different-pixels \ |
| 134 | --writeJsonSummary $JSON_DIR/different-pixels.json |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 135 | |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 136 | mkdir -p $IMAGES_DIR/empty-dir |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 139 | GM_TESTDIR=gm/tests |
| 140 | GM_INPUTS=$GM_TESTDIR/inputs |
| 141 | GM_OUTPUTS=$GM_TESTDIR/outputs |
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 142 | GM_TEMPFILES=$GM_TESTDIR/tempfiles |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 143 | |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame] | 144 | create_inputs_dir $GM_INPUTS |
| 145 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 146 | # Compare generated image against an input image file with identical bytes. |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 147 | gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes-images" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 148 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 149 | # Compare generated image against an input image file with identical pixels but different PNG encoding. |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 150 | gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels-images" |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 151 | |
| 152 | # Compare generated image against an input image file with different pixels. |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 153 | gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels-images" |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 154 | |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 155 | # Compare generated image against an empty "expected image" dir. |
| epoger@google.com | e460a47 | 2013-02-06 18:41:04 +0000 | [diff] [blame^] | 156 | gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir" |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 157 | |
| epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 158 | # If run without "-r", the JSON's "actual-results" section should contain |
| 159 | # actual checksums marked as "failure-ignored", but the "expected-results" |
| 160 | # section should be empty. |
| epoger@google.com | 4688de1 | 2013-01-31 15:06:36 +0000 | [diff] [blame] | 161 | gm_test "--hierarchy --match dashing2 $CONFIGS" "$GM_OUTPUTS/no-readpath" |
| epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 162 | |
| epoger@google.com | 666c5cf | 2013-01-19 04:56:36 +0000 | [diff] [blame] | 163 | # Run a test which generates partially transparent images, write out those |
| 164 | # images, and read them back in. |
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 165 | # |
| 166 | # This test would have caught |
| 167 | # http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating |
| 168 | # spurious pixel_error messages as of r7258'). |
| 169 | IMAGEDIR=$GM_TEMPFILES/aaclip-images |
| 170 | rm -rf $IMAGEDIR |
| 171 | mkdir -p $IMAGEDIR |
| epoger@google.com | 4688de1 | 2013-01-31 15:06:36 +0000 | [diff] [blame] | 172 | gm_test "--match simpleaaclip_path $CONFIGS -w $IMAGEDIR" "$GM_OUTPUTS/aaclip-write" |
| 173 | gm_test "--match simpleaaclip_path $CONFIGS -r $IMAGEDIR" "$GM_OUTPUTS/aaclip-readback" |
| epoger@google.com | 3726960 | 2013-01-19 04:21:27 +0000 | [diff] [blame] | 174 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 175 | echo "All tests passed." |