blob: 4482d391eaaf81011b7544247f3a0dc740219cd3 [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.com0b62b3d2013-03-20 17:59:28 +00008# To generate new baselines when gm behavior changes, run gm/tests/rebaseline.sh
9#
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +000010# TODO: because this is written as a shell script (instead of, say, Python)
11# it only runs on Linux and Mac.
epoger@google.com3aa33582013-01-02 15:53:25 +000012# See https://code.google.com/p/skia/issues/detail?id=677
13# ('make tools/tests/run.sh work cross-platform')
epoger@google.com454008a2012-11-13 20:46:50 +000014# 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.coma413a532012-11-12 18:04:51 +000017
18# cd into .../trunk so all the paths will work
19cd $(dirname $0)/../..
20
21# TODO(epoger): make it look in Release and/or Debug
22GM_BINARY=out/Debug/gm
23
epoger@google.com407f8da2013-01-18 19:19:47 +000024OUTPUT_ACTUAL_SUBDIR=output-actual
25OUTPUT_EXPECTED_SUBDIR=output-expected
scroggo@google.com09fd4d22013-03-20 14:20:18 +000026CONFIGS="--config 8888 565"
epoger@google.com407f8da2013-01-18 19:19:47 +000027
epoger@google.com0cc99cf2013-04-26 17:45:06 +000028ENCOUNTERED_ANY_ERRORS=0
29
epoger@google.coma413a532012-11-12 18:04:51 +000030# Compare contents of all files within directories $1 and $2,
31# EXCEPT for any dotfiles.
32# If there are any differences, a description is written to stdout and
33# we exit with a nonzero return value.
34# Otherwise, we write nothing to stdout and return.
35function compare_directories {
36 if [ $# != 2 ]; then
37 echo "compare_directories requires exactly 2 parameters, got $#"
38 exit 1
39 fi
40 diff -r --exclude=.* $1 $2
41 if [ $? != 0 ]; then
42 echo "failed in: compare_directories $1 $2"
epoger@google.com0cc99cf2013-04-26 17:45:06 +000043 ENCOUNTERED_ANY_ERRORS=1
epoger@google.coma413a532012-11-12 18:04:51 +000044 fi
45}
46
47# Run gm...
48# - with the arguments in $1
epoger@google.com407f8da2013-01-18 19:19:47 +000049# - writing stdout into $2/$OUTPUT_ACTUAL_SUBDIR/stdout
50# - writing json summary into $2/$OUTPUT_ACTUAL_SUBDIR/json-summary.txt
51# - writing return value into $2/$OUTPUT_ACTUAL_SUBDIR/return_value
52# Then compare all of those against $2/$OUTPUT_EXPECTED_SUBDIR .
epoger@google.coma413a532012-11-12 18:04:51 +000053function gm_test {
54 if [ $# != 2 ]; then
55 echo "gm_test requires exactly 2 parameters, got $#"
56 exit 1
57 fi
58 GM_ARGS="$1"
epoger@google.com407f8da2013-01-18 19:19:47 +000059 ACTUAL_OUTPUT_DIR="$2/$OUTPUT_ACTUAL_SUBDIR"
60 EXPECTED_OUTPUT_DIR="$2/$OUTPUT_EXPECTED_SUBDIR"
61 JSON_SUMMARY_FILE="$ACTUAL_OUTPUT_DIR/json-summary.txt"
epoger@google.coma413a532012-11-12 18:04:51 +000062
63 rm -rf $ACTUAL_OUTPUT_DIR
64 mkdir -p $ACTUAL_OUTPUT_DIR
scroggo@google.com09fd4d22013-03-20 14:20:18 +000065 COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummaryPath $JSON_SUMMARY_FILE"
epoger@google.coma413a532012-11-12 18:04:51 +000066 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
epoger@google.com5efdd0c2013-03-13 14:18:40 +000067 $COMMAND >$ACTUAL_OUTPUT_DIR/stdout 2>$ACTUAL_OUTPUT_DIR/stderr
epoger@google.coma413a532012-11-12 18:04:51 +000068 echo $? >$ACTUAL_OUTPUT_DIR/return_value
69
epoger@google.com80d44782013-01-18 20:03:58 +000070 # Only compare selected lines in the stdout, to ignore any spurious lines
epoger@google.com407f8da2013-01-18 19:19:47 +000071 # as noted in http://code.google.com/p/skia/issues/detail?id=1068 .
72 #
73 # TODO(epoger): This is still hacky... we need to rewrite this script in
74 # Python soon, and make stuff like this more maintainable.
epoger@google.com5efdd0c2013-03-13 14:18:40 +000075 grep ^GM: $ACTUAL_OUTPUT_DIR/stdout >$ACTUAL_OUTPUT_DIR/stdout-tmp
epoger@google.com98204f92013-01-16 04:19:01 +000076 mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout
epoger@google.com5efdd0c2013-03-13 14:18:40 +000077 grep ^GM: $ACTUAL_OUTPUT_DIR/stderr >$ACTUAL_OUTPUT_DIR/stderr-tmp
78 mv $ACTUAL_OUTPUT_DIR/stderr-tmp $ACTUAL_OUTPUT_DIR/stderr
epoger@google.com98204f92013-01-16 04:19:01 +000079
epoger@google.coma413a532012-11-12 18:04:51 +000080 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
81}
82
epoger@google.come460a472013-02-06 18:41:04 +000083# Create input dir (at path $1) with expectations (both image and json)
84# that gm will match or mismatch as appropriate.
epoger@google.com407f8da2013-01-18 19:19:47 +000085#
86# We used to check these files into SVN, but then we needed to rebasline them
87# when our drawing changed at all... so, as proposed in
88# http://code.google.com/p/skia/issues/detail?id=1068 , we generate them
89# new each time.
90function create_inputs_dir {
91 if [ $# != 1 ]; then
92 echo "create_inputs_dir requires exactly 1 parameter, got $#"
93 exit 1
94 fi
95 INPUTS_DIR="$1"
epoger@google.come460a472013-02-06 18:41:04 +000096 IMAGES_DIR=$INPUTS_DIR/images
97 JSON_DIR=$INPUTS_DIR/json
98 mkdir -p $IMAGES_DIR $JSON_DIR
epoger@google.com407f8da2013-01-18 19:19:47 +000099
epoger@google.come460a472013-02-06 18:41:04 +0000100 mkdir -p $IMAGES_DIR/identical-bytes
101 # Run GM to write out the images actually generated.
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +0000102 $GM_BINARY --hierarchy --match selftest1 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000103 -w $IMAGES_DIR/identical-bytes
104 # Run GM again to read in those images and write them out as a JSON summary.
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +0000105 $GM_BINARY --hierarchy --match selftest1 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000106 -r $IMAGES_DIR/identical-bytes \
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000107 --writeJsonSummaryPath $JSON_DIR/identical-bytes.json
epoger@google.com407f8da2013-01-18 19:19:47 +0000108
epoger@google.come460a472013-02-06 18:41:04 +0000109 mkdir -p $IMAGES_DIR/identical-pixels
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +0000110 $GM_BINARY --hierarchy --match selftest1 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000111 -w $IMAGES_DIR/identical-pixels
112 echo "more bytes that do not change the image pixels" \
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +0000113 >> $IMAGES_DIR/identical-pixels/8888/selftest1.png
epoger@google.come460a472013-02-06 18:41:04 +0000114 echo "more bytes that do not change the image pixels" \
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +0000115 >> $IMAGES_DIR/identical-pixels/565/selftest1.png
116 $GM_BINARY --hierarchy --match selftest1 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000117 -r $IMAGES_DIR/identical-pixels \
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000118 --writeJsonSummaryPath $JSON_DIR/identical-pixels.json
epoger@google.come460a472013-02-06 18:41:04 +0000119
120 mkdir -p $IMAGES_DIR/different-pixels
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +0000121 $GM_BINARY --hierarchy --match selftest2 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000122 -w $IMAGES_DIR/different-pixels
commit-bot@chromium.orgc61c3c32013-03-01 15:32:34 +0000123 mv $IMAGES_DIR/different-pixels/8888/selftest2.png \
124 $IMAGES_DIR/different-pixels/8888/selftest1.png
125 mv $IMAGES_DIR/different-pixels/565/selftest2.png \
126 $IMAGES_DIR/different-pixels/565/selftest1.png
127 $GM_BINARY --hierarchy --match selftest1 $CONFIGS \
epoger@google.come460a472013-02-06 18:41:04 +0000128 -r $IMAGES_DIR/different-pixels \
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000129 --writeJsonSummaryPath $JSON_DIR/different-pixels.json
epoger@google.com407f8da2013-01-18 19:19:47 +0000130
epoger@google.come460a472013-02-06 18:41:04 +0000131 mkdir -p $IMAGES_DIR/empty-dir
epoger@google.com407f8da2013-01-18 19:19:47 +0000132}
133
epoger@google.coma413a532012-11-12 18:04:51 +0000134GM_TESTDIR=gm/tests
135GM_INPUTS=$GM_TESTDIR/inputs
136GM_OUTPUTS=$GM_TESTDIR/outputs
epoger@google.com37269602013-01-19 04:21:27 +0000137GM_TEMPFILES=$GM_TESTDIR/tempfiles
epoger@google.coma413a532012-11-12 18:04:51 +0000138
epoger@google.com407f8da2013-01-18 19:19:47 +0000139create_inputs_dir $GM_INPUTS
140
epoger@google.com570aafe2012-11-28 20:08:32 +0000141# Compare generated image against an input image file with identical bytes.
epoger@google.com51dbabe2013-04-10 15:24:53 +0000142gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes-images"
143gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-bytes.json" "$GM_OUTPUTS/compared-against-identical-bytes-json"
epoger@google.coma413a532012-11-12 18:04:51 +0000144
epoger@google.com570aafe2012-11-28 20:08:32 +0000145# Compare generated image against an input image file with identical pixels but different PNG encoding.
epoger@google.com51dbabe2013-04-10 15:24:53 +0000146gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels-images"
147gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-pixels.json" "$GM_OUTPUTS/compared-against-identical-pixels-json"
epoger@google.com570aafe2012-11-28 20:08:32 +0000148
149# Compare generated image against an input image file with different pixels.
epoger@google.com51dbabe2013-04-10 15:24:53 +0000150gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels-images"
151gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels.json" "$GM_OUTPUTS/compared-against-different-pixels-json"
epoger@google.coma413a532012-11-12 18:04:51 +0000152
epoger@google.comee8a8e32012-12-18 19:13:49 +0000153# Compare generated image against an empty "expected image" dir.
epoger@google.com51dbabe2013-04-10 15:24:53 +0000154gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir"
155
epoger@google.com318a0592013-04-12 19:05:57 +0000156# Compare generated image against a nonexistent "expected image" dir.
157gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r ../path/to/nowhere" "$GM_OUTPUTS/compared-against-nonexistent-dir"
158
epoger@google.com51dbabe2013-04-10 15:24:53 +0000159# Compare generated image against an empty "expected image" dir, but NOT in verbose mode.
160gm_test "--hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/nonverbose"
epoger@google.comee8a8e32012-12-18 19:13:49 +0000161
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000162# If run without "-r", the JSON's "actual-results" section should contain
163# actual checksums marked as "failure-ignored", but the "expected-results"
164# section should be empty.
epoger@google.com51dbabe2013-04-10 15:24:53 +0000165gm_test "--verbose --hierarchy --match selftest1 $CONFIGS" "$GM_OUTPUTS/no-readpath"
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000166
epoger@google.comcaac3db2013-04-04 19:23:11 +0000167# Test what happens if a subset of the renderModes fail (e.g. pipe)
epoger@google.com51dbabe2013-04-10 15:24:53 +0000168gm_test "--simulatePipePlaybackFailure --verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-pixels.json" "$GM_OUTPUTS/pipe-playback-failure"
epoger@google.comcaac3db2013-04-04 19:23:11 +0000169
epoger@google.comc8263e72013-04-10 12:17:34 +0000170# Confirm that IntentionallySkipped tests are recorded as such.
epoger@google.com51dbabe2013-04-10 15:24:53 +0000171gm_test "--verbose --hierarchy --match selftest1 selftest2 $CONFIGS" "$GM_OUTPUTS/intentionally-skipped-tests"
epoger@google.comc8263e72013-04-10 12:17:34 +0000172
epoger@google.com5079d2c2013-04-12 14:11:21 +0000173# Ignore some error types (including ExpectationsMismatch)
174gm_test "--ignoreErrorTypes ExpectationsMismatch NoGpuContext --verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels.json" "$GM_OUTPUTS/ignore-expectations-mismatch"
175
epoger@google.com0cc99cf2013-04-26 17:45:06 +0000176if [ $ENCOUNTERED_ANY_ERRORS == 0 ]; then
177 echo "All tests passed."
178 exit 0
179else
180 exit 1
181fi