blob: 9d1461e7452e32bf59e0e375f00c66004c8f8065 [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
25
epoger@google.coma413a532012-11-12 18:04:51 +000026# 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.
31function 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.com407f8da2013-01-18 19:19:47 +000045# - writing stdout into $2/$OUTPUT_ACTUAL_SUBDIR/stdout
46# - writing json summary into $2/$OUTPUT_ACTUAL_SUBDIR/json-summary.txt
47# - writing return value into $2/$OUTPUT_ACTUAL_SUBDIR/return_value
48# Then compare all of those against $2/$OUTPUT_EXPECTED_SUBDIR .
epoger@google.coma413a532012-11-12 18:04:51 +000049function gm_test {
50 if [ $# != 2 ]; then
51 echo "gm_test requires exactly 2 parameters, got $#"
52 exit 1
53 fi
54 GM_ARGS="$1"
epoger@google.com407f8da2013-01-18 19:19:47 +000055 ACTUAL_OUTPUT_DIR="$2/$OUTPUT_ACTUAL_SUBDIR"
56 EXPECTED_OUTPUT_DIR="$2/$OUTPUT_EXPECTED_SUBDIR"
57 JSON_SUMMARY_FILE="$ACTUAL_OUTPUT_DIR/json-summary.txt"
epoger@google.coma413a532012-11-12 18:04:51 +000058
59 rm -rf $ACTUAL_OUTPUT_DIR
60 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com80d44782013-01-18 20:03:58 +000061 COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $JSON_SUMMARY_FILE"
epoger@google.coma413a532012-11-12 18:04:51 +000062 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
63 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
64 echo $? >$ACTUAL_OUTPUT_DIR/return_value
65
epoger@google.com80d44782013-01-18 20:03:58 +000066 # Only compare selected lines in the stdout, to ignore any spurious lines
epoger@google.com407f8da2013-01-18 19:19:47 +000067 # as noted in http://code.google.com/p/skia/issues/detail?id=1068 .
68 #
69 # TODO(epoger): This is still hacky... we need to rewrite this script in
70 # Python soon, and make stuff like this more maintainable.
71 grep --regexp=^reading --regexp=^writing --regexp=^drawing \
72 --regexp=^FAILED --regexp=^Ran $ACTUAL_OUTPUT_DIR/stdout \
73 >$ACTUAL_OUTPUT_DIR/stdout-tmp
epoger@google.com98204f92013-01-16 04:19:01 +000074 mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout
75
epoger@google.com80d44782013-01-18 20:03:58 +000076 # Replace particular checksums in json summary with a placeholder, so
epoger@google.com407f8da2013-01-18 19:19:47 +000077 # we don't need to rebaseline these json files when our drawing routines
78 # change.
79 sed -e 's/"checksum" : [0-9]*/"checksum" : FAKE/g' \
80 --in-place $JSON_SUMMARY_FILE
81 sed -e 's/"checksums" : \[ [0-9]* \]/"checksums" : [ FAKE ]/g' \
82 --in-place $JSON_SUMMARY_FILE
83
epoger@google.coma413a532012-11-12 18:04:51 +000084 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
85}
86
epoger@google.com407f8da2013-01-18 19:19:47 +000087# Create input dir (at path $1) with images that match or mismatch
88# as appropriate.
89#
90# We used to check these files into SVN, but then we needed to rebasline them
91# when our drawing changed at all... so, as proposed in
92# http://code.google.com/p/skia/issues/detail?id=1068 , we generate them
93# new each time.
94function create_inputs_dir {
95 if [ $# != 1 ]; then
96 echo "create_inputs_dir requires exactly 1 parameter, got $#"
97 exit 1
98 fi
99 INPUTS_DIR="$1"
100 mkdir -p $INPUTS_DIR
101
102 mkdir -p $INPUTS_DIR/identical-bytes
103 $GM_BINARY --hierarchy --match dashing2 --config 8888 \
104 -w $INPUTS_DIR/identical-bytes
105
106 mkdir -p $INPUTS_DIR/identical-pixels
107 $GM_BINARY --hierarchy --match dashing2 --config 8888 \
108 -w $INPUTS_DIR/identical-pixels
109 echo "more bytes that do not change the image pixels" \
110 >> $INPUTS_DIR/identical-pixels/8888/dashing2.png
111
112 mkdir -p $INPUTS_DIR/different-pixels
113 $GM_BINARY --hierarchy --match dashing3 --config 8888 \
114 -w $INPUTS_DIR/different-pixels
115 mv $INPUTS_DIR/different-pixels/8888/dashing3.png \
116 $INPUTS_DIR/different-pixels/8888/dashing2.png
117
118 mkdir -p $INPUTS_DIR/empty-dir
119}
120
epoger@google.coma413a532012-11-12 18:04:51 +0000121GM_TESTDIR=gm/tests
122GM_INPUTS=$GM_TESTDIR/inputs
123GM_OUTPUTS=$GM_TESTDIR/outputs
epoger@google.com37269602013-01-19 04:21:27 +0000124GM_TEMPFILES=$GM_TESTDIR/tempfiles
epoger@google.coma413a532012-11-12 18:04:51 +0000125
epoger@google.com407f8da2013-01-18 19:19:47 +0000126create_inputs_dir $GM_INPUTS
127
epoger@google.com570aafe2012-11-28 20:08:32 +0000128# Compare generated image against an input image file with identical bytes.
epoger@google.com8a6f13a2012-12-05 20:21:35 +0000129gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes"
epoger@google.coma413a532012-11-12 18:04:51 +0000130
epoger@google.com570aafe2012-11-28 20:08:32 +0000131# Compare generated image against an input image file with identical pixels but different PNG encoding.
epoger@google.com8a6f13a2012-12-05 20:21:35 +0000132gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels"
epoger@google.com570aafe2012-11-28 20:08:32 +0000133
134# Compare generated image against an input image file with different pixels.
epoger@google.com8a6f13a2012-12-05 20:21:35 +0000135gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels"
epoger@google.coma413a532012-11-12 18:04:51 +0000136
epoger@google.comee8a8e32012-12-18 19:13:49 +0000137# Compare generated image against an empty "expected image" dir.
138gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir"
139
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000140# 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.
143gm_test "--hierarchy --match dashing2 --config 8888" "$GM_OUTPUTS/no-readpath"
144
epoger@google.com37269602013-01-19 04:21:27 +0000145# Write out a handful of test images and read them back in.
146#
147# This test would have caught
148# http://code.google.com/p/skia/issues/detail?id=1079 ('gm generating
149# spurious pixel_error messages as of r7258').
150IMAGEDIR=$GM_TEMPFILES/aaclip-images
151rm -rf $IMAGEDIR
152mkdir -p $IMAGEDIR
153gm_test "--match aaclip --config 8888 -w $IMAGEDIR" "$GM_OUTPUTS/aaclip-write"
154gm_test "--match aaclip --config 8888 -r $IMAGEDIR" "$GM_OUTPUTS/aaclip-readback"
155
epoger@google.coma413a532012-11-12 18:04:51 +0000156echo "All tests passed."