blob: 2bcff4e1ef38b45f489462ef1cb4888ce24ce32d [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 resulting images into $2/$OUTPUT_ACTUAL_SUBDIR/images
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 .
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.com407f8da2013-01-18 19:19:47 +000062 COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $JSON_SUMMARY_FILE -w $ACTUAL_OUTPUT_DIR/images"
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.com407f8da2013-01-18 19:19:47 +000067 # Only compare selected lines in the output, 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
epoger@google.com98204f92013-01-16 04:19:01 +000075 mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout
76
epoger@google.com407f8da2013-01-18 19:19:47 +000077 # Replace particular checksums in json output 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
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
104 $GM_BINARY --hierarchy --match dashing2 --config 8888 \
105 -w $INPUTS_DIR/identical-bytes
106
107 mkdir -p $INPUTS_DIR/identical-pixels
108 $GM_BINARY --hierarchy --match dashing2 --config 8888 \
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
113 mkdir -p $INPUTS_DIR/different-pixels
114 $GM_BINARY --hierarchy --match dashing3 --config 8888 \
115 -w $INPUTS_DIR/different-pixels
116 mv $INPUTS_DIR/different-pixels/8888/dashing3.png \
117 $INPUTS_DIR/different-pixels/8888/dashing2.png
118
119 mkdir -p $INPUTS_DIR/empty-dir
120}
121
epoger@google.coma413a532012-11-12 18:04:51 +0000122GM_TESTDIR=gm/tests
123GM_INPUTS=$GM_TESTDIR/inputs
124GM_OUTPUTS=$GM_TESTDIR/outputs
125
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.coma413a532012-11-12 18:04:51 +0000145echo "All tests passed."