blob: 717262ed5c31368710f860de74a0d38e57d2b8e0 [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.com407f8da2013-01-18 19:19:47 +000088# 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.
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"
101 mkdir -p $INPUTS_DIR
102
103 mkdir -p $INPUTS_DIR/identical-bytes
epoger@google.com4688de12013-01-31 15:06:36 +0000104 $GM_BINARY --hierarchy --match dashing2 $CONFIGS \
epoger@google.com407f8da2013-01-18 19:19:47 +0000105 -w $INPUTS_DIR/identical-bytes
106
107 mkdir -p $INPUTS_DIR/identical-pixels
epoger@google.com4688de12013-01-31 15:06:36 +0000108 $GM_BINARY --hierarchy --match dashing2 $CONFIGS \
epoger@google.com407f8da2013-01-18 19:19:47 +0000109 -w $INPUTS_DIR/identical-pixels
110 echo "more bytes that do not change the image pixels" \
111 >> $INPUTS_DIR/identical-pixels/8888/dashing2.png
epoger@google.com4688de12013-01-31 15:06:36 +0000112 echo "more bytes that do not change the image pixels" \
113 >> $INPUTS_DIR/identical-pixels/565/dashing2.png
epoger@google.com407f8da2013-01-18 19:19:47 +0000114
115 mkdir -p $INPUTS_DIR/different-pixels
epoger@google.com4688de12013-01-31 15:06:36 +0000116 $GM_BINARY --hierarchy --match dashing3 $CONFIGS \
epoger@google.com407f8da2013-01-18 19:19:47 +0000117 -w $INPUTS_DIR/different-pixels
118 mv $INPUTS_DIR/different-pixels/8888/dashing3.png \
119 $INPUTS_DIR/different-pixels/8888/dashing2.png
epoger@google.com4688de12013-01-31 15:06:36 +0000120 mv $INPUTS_DIR/different-pixels/565/dashing3.png \
121 $INPUTS_DIR/different-pixels/565/dashing2.png
epoger@google.com407f8da2013-01-18 19:19:47 +0000122
123 mkdir -p $INPUTS_DIR/empty-dir
124}
125
epoger@google.coma413a532012-11-12 18:04:51 +0000126GM_TESTDIR=gm/tests
127GM_INPUTS=$GM_TESTDIR/inputs
128GM_OUTPUTS=$GM_TESTDIR/outputs
epoger@google.com37269602013-01-19 04:21:27 +0000129GM_TEMPFILES=$GM_TESTDIR/tempfiles
epoger@google.coma413a532012-11-12 18:04:51 +0000130
epoger@google.com407f8da2013-01-18 19:19:47 +0000131create_inputs_dir $GM_INPUTS
132
epoger@google.com570aafe2012-11-28 20:08:32 +0000133# Compare generated image against an input image file with identical bytes.
epoger@google.com4688de12013-01-31 15:06:36 +0000134gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes"
epoger@google.coma413a532012-11-12 18:04:51 +0000135
epoger@google.com570aafe2012-11-28 20:08:32 +0000136# Compare generated image against an input image file with identical pixels but different PNG encoding.
epoger@google.com4688de12013-01-31 15:06:36 +0000137gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels"
epoger@google.com570aafe2012-11-28 20:08:32 +0000138
139# Compare generated image against an input image file with different pixels.
epoger@google.com4688de12013-01-31 15:06:36 +0000140gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels"
epoger@google.coma413a532012-11-12 18:04:51 +0000141
epoger@google.comee8a8e32012-12-18 19:13:49 +0000142# Compare generated image against an empty "expected image" dir.
epoger@google.com4688de12013-01-31 15:06:36 +0000143gm_test "--hierarchy --match dashing2 $CONFIGS -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir"
epoger@google.comee8a8e32012-12-18 19:13:49 +0000144
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000145# 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.
epoger@google.com4688de12013-01-31 15:06:36 +0000148gm_test "--hierarchy --match dashing2 $CONFIGS" "$GM_OUTPUTS/no-readpath"
epoger@google.com9c56a8d2012-12-20 18:34:29 +0000149
epoger@google.com666c5cf2013-01-19 04:56:36 +0000150# Run a test which generates partially transparent images, write out those
151# images, and read them back in.
epoger@google.com37269602013-01-19 04:21:27 +0000152#
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').
156IMAGEDIR=$GM_TEMPFILES/aaclip-images
157rm -rf $IMAGEDIR
158mkdir -p $IMAGEDIR
epoger@google.com4688de12013-01-31 15:06:36 +0000159gm_test "--match simpleaaclip_path $CONFIGS -w $IMAGEDIR" "$GM_OUTPUTS/aaclip-write"
160gm_test "--match simpleaaclip_path $CONFIGS -r $IMAGEDIR" "$GM_OUTPUTS/aaclip-readback"
epoger@google.com37269602013-01-19 04:21:27 +0000161
epoger@google.coma413a532012-11-12 18:04:51 +0000162echo "All tests passed."