blob: 2c9b719050c522187003b836dd1dbceb2415e136 [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
23# Compare contents of all files within directories $1 and $2,
24# EXCEPT for any dotfiles.
25# If there are any differences, a description is written to stdout and
26# we exit with a nonzero return value.
27# Otherwise, we write nothing to stdout and return.
28function compare_directories {
29 if [ $# != 2 ]; then
30 echo "compare_directories requires exactly 2 parameters, got $#"
31 exit 1
32 fi
33 diff -r --exclude=.* $1 $2
34 if [ $? != 0 ]; then
35 echo "failed in: compare_directories $1 $2"
36 exit 1
37 fi
38}
39
40# Run gm...
41# - with the arguments in $1
42# - writing resulting images into $2/output-actual/images
43# - writing stdout into $2/output-actual/stdout
epoger@google.comee8a8e32012-12-18 19:13:49 +000044# - writing json summary into $2/output-actual/json-summary.txt
epoger@google.coma413a532012-11-12 18:04:51 +000045# - writing return value into $2/output-actual/return_value
46# Then compare all of those against $2/output-expected .
47function gm_test {
48 if [ $# != 2 ]; then
49 echo "gm_test requires exactly 2 parameters, got $#"
50 exit 1
51 fi
52 GM_ARGS="$1"
53 ACTUAL_OUTPUT_DIR="$2/output-actual"
54 EXPECTED_OUTPUT_DIR="$2/output-expected"
55
56 rm -rf $ACTUAL_OUTPUT_DIR
57 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.comee8a8e32012-12-18 19:13:49 +000058 COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummary $ACTUAL_OUTPUT_DIR/json-summary.txt -w $ACTUAL_OUTPUT_DIR/images"
epoger@google.coma413a532012-11-12 18:04:51 +000059 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
60 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
61 echo $? >$ACTUAL_OUTPUT_DIR/return_value
62
epoger@google.com98204f92013-01-16 04:19:01 +000063 # Temporary hack to alleviate
64 # http://code.google.com/p/skia/issues/detail?id=1068 ('GM self-test failures')
65 # (Remove instance-counting lines from the Debug output)
66 grep -v Leaked $ACTUAL_OUTPUT_DIR/stdout >$ACTUAL_OUTPUT_DIR/stdout-tmp
67 mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout
68
epoger@google.coma413a532012-11-12 18:04:51 +000069 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
70}
71
72GM_TESTDIR=gm/tests
73GM_INPUTS=$GM_TESTDIR/inputs
74GM_OUTPUTS=$GM_TESTDIR/outputs
75
epoger@google.com570aafe2012-11-28 20:08:32 +000076# Compare generated image against an input image file with identical bytes.
epoger@google.com8a6f13a2012-12-05 20:21:35 +000077gm_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 +000078
epoger@google.com570aafe2012-11-28 20:08:32 +000079# Compare generated image against an input image file with identical pixels but different PNG encoding.
epoger@google.com8a6f13a2012-12-05 20:21:35 +000080gm_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 +000081
82# Compare generated image against an input image file with different pixels.
epoger@google.com8a6f13a2012-12-05 20:21:35 +000083gm_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 +000084
epoger@google.comee8a8e32012-12-18 19:13:49 +000085# Compare generated image against an empty "expected image" dir.
86gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir"
87
epoger@google.com9c56a8d2012-12-20 18:34:29 +000088# If run without "-r", the JSON's "actual-results" section should contain
89# actual checksums marked as "failure-ignored", but the "expected-results"
90# section should be empty.
91gm_test "--hierarchy --match dashing2 --config 8888" "$GM_OUTPUTS/no-readpath"
92
epoger@google.coma413a532012-11-12 18:04:51 +000093echo "All tests passed."