blob: e1b6ce77070c12796035ecd3572396e8fc918207 [file] [log] [blame]
epoger@google.coma413a532012-11-12 18:04:51 +00001#!/bin/bash
2
3# Self-tests for gm, based on tools/tests/run.sh
epoger@google.com454008a2012-11-13 20:46:50 +00004#
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.com3aa33582013-01-02 15:53:25 +00008# 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.com454008a2012-11-13 20:46:50 +000013# 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.coma413a532012-11-12 18:04:51 +000016
17# cd into .../trunk so all the paths will work
18cd $(dirname $0)/../..
19
20# TODO(epoger): make it look in Release and/or Debug
21GM_BINARY=out/Debug/gm
22
epoger@google.com407f8da2013-01-18 19:19:47 +000023OUTPUT_ACTUAL_SUBDIR=output-actual
24OUTPUT_EXPECTED_SUBDIR=output-expected
epoger@google.com4688de12013-01-31 15:06:36 +000025CONFIGS="--config 8888 --config 565"
epoger@google.com407f8da2013-01-18 19:19:47 +000026
epoger@google.coma413a532012-11-12 18:04:51 +000027# 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.
32function 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.com407f8da2013-01-18 19:19:47 +000046# - 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.coma413a532012-11-12 18:04:51 +000050function 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.com407f8da2013-01-18 19:19:47 +000056 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.coma413a532012-11-12 18:04:51 +000059
60 rm -rf $ACTUAL_OUTPUT_DIR
61 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com80d44782013-01-18 20:03:58 +000062 COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $JSON_SUMMARY_FILE"
epoger@google.coma413a532012-11-12 18:04:51 +000063 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
64 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
65 echo $? >$ACTUAL_OUTPUT_DIR/return_value
66
epoger@google.com80d44782013-01-18 20:03:58 +000067 # Only compare selected lines in the stdout, to ignore any spurious lines
epoger@google.com407f8da2013-01-18 19:19:47 +000068 # 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.com98204f92013-01-16 04:19:01 +000075 mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout
76
epoger@google.com80d44782013-01-18 20:03:58 +000077 # Replace particular checksums in json summary with a placeholder, so
epoger@google.com407f8da2013-01-18 19:19:47 +000078 # 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.coma413a532012-11-12 18:04:51 +000085 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
86}
87
epoger@google.come460a472013-02-06 18:41:04 +000088# Create input dir (at path $1) with expectations (both image and json)
89# that gm will match or mismatch as appropriate.
epoger@google.com407f8da2013-01-18 19:19:47 +000090#
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.
95function 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.come460a472013-02-06 18:41:04 +0000101 IMAGES_DIR=$INPUTS_DIR/images
102 JSON_DIR=$INPUTS_DIR/json
103 mkdir -p $IMAGES_DIR $JSON_DIR
epoger@google.com407f8da2013-01-18 19:19:47 +0000104
epoger@google.come460a472013-02-06 18:41:04 +0000105 mkdir -p $IMAGES_DIR/identical-bytes
106 # Run GM to write out the images actually generated.
epoger@google.com4688de12013-01-31 15:06:36 +0000107 $GM_BINARY --hierarchy --match dashing2 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000108 -w $IMAGES_DIR/identical-bytes
109 # Run GM again to read in those images and write them out as a JSON summary.
epoger@google.com4688de12013-01-31 15:06:36 +0000110 $GM_BINARY --hierarchy --match dashing2 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000111 -r $IMAGES_DIR/identical-bytes \
112 --writeJsonSummary $JSON_DIR/identical-bytes.json
epoger@google.com407f8da2013-01-18 19:19:47 +0000113
epoger@google.come460a472013-02-06 18:41:04 +0000114 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.com4688de12013-01-31 15:06:36 +0000126 $GM_BINARY --hierarchy --match dashing3 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000127 -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.com407f8da2013-01-18 19:19:47 +0000135
epoger@google.come460a472013-02-06 18:41:04 +0000136 mkdir -p $IMAGES_DIR/empty-dir
epoger@google.com407f8da2013-01-18 19:19:47 +0000137}
138
epoger@google.coma413a532012-11-12 18:04:51 +0000139GM_TESTDIR=gm/tests
140GM_INPUTS=$GM_TESTDIR/inputs
141GM_OUTPUTS=$GM_TESTDIR/outputs
epoger@google.com37269602013-01-19 04:21:27 +0000142GM_TEMPFILES=$GM_TESTDIR/tempfiles
epoger@google.coma413a532012-11-12 18:04:51 +0000143
epoger@google.com407f8da2013-01-18 19:19:47 +0000144create_inputs_dir $GM_INPUTS
145
epoger@google.com570aafe2012-11-28 20:08:32 +0000146# Compare generated image against an input image file with identical bytes.
epoger@google.come460a472013-02-06 18:41:04 +0000147gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes-images"
epoger@google.coma413a532012-11-12 18:04:51 +0000148
epoger@google.com570aafe2012-11-28 20:08:32 +0000149# Compare generated image against an input image file with identical pixels but different PNG encoding.
epoger@google.come460a472013-02-06 18:41:04 +0000150gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels-images"
epoger@google.com570aafe2012-11-28 20:08:32 +0000151
152# Compare generated image against an input image file with different pixels.
epoger@google.come460a472013-02-06 18:41:04 +0000153gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels-images"
epoger@google.coma413a532012-11-12 18:04:51 +0000154
epoger@google.comee8a8e32012-12-18 19:13:49 +0000155# Compare generated image against an empty "expected image" dir.
epoger@google.come460a472013-02-06 18:41:04 +0000156gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir"
epoger@google.comee8a8e32012-12-18 19:13:49 +0000157
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000158# 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.com4688de12013-01-31 15:06:36 +0000161gm_test "--hierarchy --match dashing2 $CONFIGS" "$GM_OUTPUTS/no-readpath"
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000162
epoger@google.com666c5cf2013-01-19 04:56:36 +0000163# Run a test which generates partially transparent images, write out those
164# images, and read them back in.
epoger@google.com37269602013-01-19 04:21:27 +0000165#
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').
169IMAGEDIR=$GM_TEMPFILES/aaclip-images
170rm -rf $IMAGEDIR
171mkdir -p $IMAGEDIR
epoger@google.com4688de12013-01-31 15:06:36 +0000172gm_test "--match simpleaaclip_path $CONFIGS -w $IMAGEDIR" "$GM_OUTPUTS/aaclip-write"
173gm_test "--match simpleaaclip_path $CONFIGS -r $IMAGEDIR" "$GM_OUTPUTS/aaclip-readback"
epoger@google.com37269602013-01-19 04:21:27 +0000174
epoger@google.coma413a532012-11-12 18:04:51 +0000175echo "All tests passed."