blob: 103a71f81664acc9f71ef96fcafb862fecdf9866 [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
41# - writing return value into $2/output-actual/return_value
42# Then compare all of those against $2/output-expected .
43function gm_test {
44 if [ $# != 2 ]; then
45 echo "gm_test requires exactly 2 parameters, got $#"
46 exit 1
47 fi
48 GM_ARGS="$1"
49 ACTUAL_OUTPUT_DIR="$2/output-actual"
50 EXPECTED_OUTPUT_DIR="$2/output-expected"
51
52 rm -rf $ACTUAL_OUTPUT_DIR
53 mkdir -p $ACTUAL_OUTPUT_DIR
54 COMMAND="$GM_BINARY $GM_ARGS -w $ACTUAL_OUTPUT_DIR/images"
55 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
56 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
57 echo $? >$ACTUAL_OUTPUT_DIR/return_value
58
59 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
60}
61
62GM_TESTDIR=gm/tests
63GM_INPUTS=$GM_TESTDIR/inputs
64GM_OUTPUTS=$GM_TESTDIR/outputs
65
66gm_test "--hierarchy --match dashing --config 4444 -r $GM_INPUTS/dashing-correct-images" "$GM_OUTPUTS/dashing-compared-against-correct"
67
68# In this case, dashing.png has different pixels, but dashing2.png differs only in PNG encoding (identical pixels)
69gm_test "--hierarchy --match dashing --config 4444 -r $GM_INPUTS/dashing-incorrect-images" "$GM_OUTPUTS/dashing-compared-against-incorrect"
70
71echo "All tests passed."