1 #!/bin/bash 2 3 # Self-tests for gm, based on tools/tests/run.sh 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: 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') 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? 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 OUTPUT_ACTUAL_SUBDIR=output-actual 24 OUTPUT_EXPECTED_SUBDIR=output-expected 25 CONFIGS="--config 8888 --config 565" 26 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 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 . 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" 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" 59 60 rm -rf $ACTUAL_OUTPUT_DIR 61 mkdir -p $ACTUAL_OUTPUT_DIR 62 COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $JSON_SUMMARY_FILE" 63 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line 64 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout 65 echo $? >$ACTUAL_OUTPUT_DIR/return_value 66 67 # Only compare selected lines in the stdout, 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 75 mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout 76 77 # Replace particular checksums in json summary 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 85 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR 86 } 87 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 $CONFIGS \ 105 -w $INPUTS_DIR/identical-bytes 106 107 mkdir -p $INPUTS_DIR/identical-pixels 108 $GM_BINARY --hierarchy --match dashing2 $CONFIGS \ 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 echo "more bytes that do not change the image pixels" \ 113 >> $INPUTS_DIR/identical-pixels/565/dashing2.png 114 115 mkdir -p $INPUTS_DIR/different-pixels 116 $GM_BINARY --hierarchy --match dashing3 $CONFIGS \ 117 -w $INPUTS_DIR/different-pixels 118 mv $INPUTS_DIR/different-pixels/8888/dashing3.png \ 119 $INPUTS_DIR/different-pixels/8888/dashing2.png 120 mv $INPUTS_DIR/different-pixels/565/dashing3.png \ 121 $INPUTS_DIR/different-pixels/565/dashing2.png 122 123 mkdir -p $INPUTS_DIR/empty-dir 124 } 125 126 GM_TESTDIR=gm/tests 127 GM_INPUTS=$GM_TESTDIR/inputs 128 GM_OUTPUTS=$GM_TESTDIR/outputs 129 GM_TEMPFILES=$GM_TESTDIR/tempfiles 130 131 create_inputs_dir $GM_INPUTS 132 133 # Compare generated image against an input image file with identical bytes. 134 gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes" 135 136 # Compare generated image against an input image file with identical pixels but different PNG encoding. 137 gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels" 138 139 # Compare generated image against an input image file with different pixels. 140 gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels" 141 142 # Compare generated image against an empty "expected image" dir. 143 gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir" 144 145 # If run without "-r", the JSON's "actual-results" section should contain 146 # actual checksums marked as "failure-ignored", but the "expected-results" 147 # section should be empty. 148 gm_test "--hierarchy --match dashing2 $CONFIGS" "$GM_OUTPUTS/no-readpath" 149 150 # Run a test which generates partially transparent images, write out those 151 # images, and read them back in. 152 # 153 # This test would have caught 154 # http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating 155 # spurious pixel_error messages as of r7258'). 156 IMAGEDIR=$GM_TEMPFILES/aaclip-images 157 rm -rf $IMAGEDIR 158 mkdir -p $IMAGEDIR 159 gm_test "--match simpleaaclip_path $CONFIGS -w $IMAGEDIR" "$GM_OUTPUTS/aaclip-write" 160 gm_test "--match simpleaaclip_path $CONFIGS -r $IMAGEDIR" "$GM_OUTPUTS/aaclip-readback" 161 162 echo "All tests passed." 163