blob: 46c8929114c96038d519e422e292e6214d6302b7 [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#
8# TODO: Even though these tests are passing on the Skia_PerCommit_House_Keeping
9# bot (which runs on Linux), they fail when I run them on my Mac.
10# Ideally, these tests should pass on all development platforms...
11# otherwise, how can developers be expected to test them before committing a
12# change?
epoger@google.coma413a532012-11-12 18:04:51 +000013
14# cd into .../trunk so all the paths will work
15cd $(dirname $0)/../..
16
17# TODO(epoger): make it look in Release and/or Debug
18GM_BINARY=out/Debug/gm
19
20# Compare contents of all files within directories $1 and $2,
21# EXCEPT for any dotfiles.
22# If there are any differences, a description is written to stdout and
23# we exit with a nonzero return value.
24# Otherwise, we write nothing to stdout and return.
25function compare_directories {
26 if [ $# != 2 ]; then
27 echo "compare_directories requires exactly 2 parameters, got $#"
28 exit 1
29 fi
30 diff -r --exclude=.* $1 $2
31 if [ $? != 0 ]; then
32 echo "failed in: compare_directories $1 $2"
33 exit 1
34 fi
35}
36
37# Run gm...
38# - with the arguments in $1
39# - writing resulting images into $2/output-actual/images
40# - writing stdout into $2/output-actual/stdout
epoger@google.comee8a8e32012-12-18 19:13:49 +000041# - writing json summary into $2/output-actual/json-summary.txt
epoger@google.coma413a532012-11-12 18:04:51 +000042# - writing return value into $2/output-actual/return_value
43# Then compare all of those against $2/output-expected .
44function gm_test {
45 if [ $# != 2 ]; then
46 echo "gm_test requires exactly 2 parameters, got $#"
47 exit 1
48 fi
49 GM_ARGS="$1"
50 ACTUAL_OUTPUT_DIR="$2/output-actual"
51 EXPECTED_OUTPUT_DIR="$2/output-expected"
52
53 rm -rf $ACTUAL_OUTPUT_DIR
54 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.comee8a8e32012-12-18 19:13:49 +000055 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 +000056 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
57 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
58 echo $? >$ACTUAL_OUTPUT_DIR/return_value
59
60 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
61}
62
63GM_TESTDIR=gm/tests
64GM_INPUTS=$GM_TESTDIR/inputs
65GM_OUTPUTS=$GM_TESTDIR/outputs
66
epoger@google.com570aafe2012-11-28 20:08:32 +000067# Compare generated image against an input image file with identical bytes.
epoger@google.com8a6f13a2012-12-05 20:21:35 +000068gm_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 +000069
epoger@google.com570aafe2012-11-28 20:08:32 +000070# Compare generated image against an input image file with identical pixels but different PNG encoding.
epoger@google.com8a6f13a2012-12-05 20:21:35 +000071gm_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 +000072
73# Compare generated image against an input image file with different pixels.
epoger@google.com8a6f13a2012-12-05 20:21:35 +000074gm_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 +000075
epoger@google.comee8a8e32012-12-18 19:13:49 +000076# Compare generated image against an empty "expected image" dir.
77gm_test "--hierarchy --match dashing2 --config 8888 -r $GM_INPUTS/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir"
78
epoger@google.com9c56a8d2012-12-20 18:34:29 +000079# If run without "-r", the JSON's "actual-results" section should contain
80# actual checksums marked as "failure-ignored", but the "expected-results"
81# section should be empty.
82gm_test "--hierarchy --match dashing2 --config 8888" "$GM_OUTPUTS/no-readpath"
83
epoger@google.coma413a532012-11-12 18:04:51 +000084echo "All tests passed."