| 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 |
| 25 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 26 | # Compare contents of all files within directories $1 and $2, |
| 27 | # EXCEPT for any dotfiles. |
| 28 | # If there are any differences, a description is written to stdout and |
| 29 | # we exit with a nonzero return value. |
| 30 | # Otherwise, we write nothing to stdout and return. |
| 31 | function compare_directories { |
| 32 | if [ $# != 2 ]; then |
| 33 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 34 | exit 1 |
| 35 | fi |
| 36 | diff -r --exclude=.* $1 $2 |
| 37 | if [ $? != 0 ]; then |
| 38 | echo "failed in: compare_directories $1 $2" |
| 39 | exit 1 |
| 40 | fi |
| 41 | } |
| 42 | |
| 43 | # Run gm... |
| 44 | # - with the arguments in $1 |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame^] | 45 | # - writing resulting images into $2/$OUTPUT_ACTUAL_SUBDIR/images |
| 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 | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame^] | 62 | COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $JSON_SUMMARY_FILE -w $ACTUAL_OUTPUT_DIR/images" |
| 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 | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame^] | 67 | # Only compare selected lines in the output, to ignore any spurious lines |
| 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 | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame^] | 77 | # Replace particular checksums in json output with a placeholder, so |
| 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 | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame^] | 88 | # Create input dir (at path $1) with images that match or mismatch |
| 89 | # as appropriate. |
| 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" |
| 101 | mkdir -p $INPUTS_DIR |
| 102 | |
| 103 | mkdir -p $INPUTS_DIR/identical-bytes |
| 104 | $GM_BINARY --hierarchy --match dashing2 --config 8888 \ |
| 105 | -w $INPUTS_DIR/identical-bytes |
| 106 | |
| 107 | mkdir -p $INPUTS_DIR/identical-pixels |
| 108 | $GM_BINARY --hierarchy --match dashing2 --config 8888 \ |
| 109 | -w $INPUTS_DIR/identical-pixels |
| 110 | echo "more bytes that do not change the image pixels" \ |
| 111 | >> $INPUTS_DIR/identical-pixels/8888/dashing2.png |
| 112 | |
| 113 | mkdir -p $INPUTS_DIR/different-pixels |
| 114 | $GM_BINARY --hierarchy --match dashing3 --config 8888 \ |
| 115 | -w $INPUTS_DIR/different-pixels |
| 116 | mv $INPUTS_DIR/different-pixels/8888/dashing3.png \ |
| 117 | $INPUTS_DIR/different-pixels/8888/dashing2.png |
| 118 | |
| 119 | mkdir -p $INPUTS_DIR/empty-dir |
| 120 | } |
| 121 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 122 | GM_TESTDIR=gm/tests |
| 123 | GM_INPUTS=$GM_TESTDIR/inputs |
| 124 | GM_OUTPUTS=$GM_TESTDIR/outputs |
| 125 | |
| epoger@google.com | 407f8da | 2013-01-18 19:19:47 +0000 | [diff] [blame^] | 126 | create_inputs_dir $GM_INPUTS |
| 127 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 128 | # Compare generated image against an input image file with identical bytes. |
| epoger@google.com | 8a6f13a | 2012-12-05 20:21:35 +0000 | [diff] [blame] | 129 | 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] | 130 | |
| epoger@google.com | 570aafe | 2012-11-28 20:08:32 +0000 | [diff] [blame] | 131 | # 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] | 132 | 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] | 133 | |
| 134 | # Compare generated image against an input image file with different pixels. |
| epoger@google.com | 8a6f13a | 2012-12-05 20:21:35 +0000 | [diff] [blame] | 135 | 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] | 136 | |
| epoger@google.com | ee8a8e3 | 2012-12-18 19:13:49 +0000 | [diff] [blame] | 137 | # Compare generated image against an empty "expected image" dir. |
| 138 | gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir" |
| 139 | |
| epoger@google.com | 9c56a8d | 2012-12-20 18:34:29 +0000 | [diff] [blame] | 140 | # If run without "-r", the JSON's "actual-results" section should contain |
| 141 | # actual checksums marked as "failure-ignored", but the "expected-results" |
| 142 | # section should be empty. |
| 143 | gm_test "--hierarchy --match dashing2 --config 8888" "$GM_OUTPUTS/no-readpath" |
| 144 | |
| epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 145 | echo "All tests passed." |