blob: 773180509a102668c93f18c8ccd22b1d8f4e2569 [file] [log] [blame]
epoger@google.coma2b793c2012-05-15 14:58:53 +00001#!/bin/bash
2
3# Tests for our tools.
epoger@google.com3aa33582013-01-02 15:53:25 +00004#
epoger@google.coma2b793c2012-05-15 14:58:53 +00005# TODO: for now, it only tests skdiff
epoger@google.com3aa33582013-01-02 15:53:25 +00006#
7# TODO: currently, this only passes on Linux (which is the platform that
8# the housekeeper bot runs on, e.g.
9# http://70.32.156.51:10117/builders/Skia_PerCommit_House_Keeping/builds/1415/steps/RunToolSelfTests/logs/stdio )
10# See https://code.google.com/p/skia/issues/detail?id=677
11# ('make tools/tests/run.sh work cross-platform')
12# Ideally, these tests should pass on all development platforms...
13# otherwise, how can developers be expected to test them before committing a
14# change?
epoger@google.coma413a532012-11-12 18:04:51 +000015
16# cd into .../trunk so all the paths will work
17cd $(dirname $0)/../..
epoger@google.coma2b793c2012-05-15 14:58:53 +000018
19# TODO: make it look in Release and/or Debug
20SKDIFF_BINARY=out/Debug/skdiff
21
epoger@google.coma4443522012-05-17 17:12:38 +000022# Compare contents of all files within directories $1 and $2,
23# EXCEPT for any dotfiles.
24# If there are any differences, a description is written to stdout and
25# we exit with a nonzero return value.
26# Otherwise, we write nothing to stdout and return.
epoger@google.coma2b793c2012-05-15 14:58:53 +000027function compare_directories {
epoger@google.coma413a532012-11-12 18:04:51 +000028 if [ $# != 2 ]; then
29 echo "compare_directories requires exactly 2 parameters, got $#"
30 exit 1
31 fi
epoger@google.coma2b793c2012-05-15 14:58:53 +000032 diff --exclude=.* $1 $2
33 if [ $? != 0 ]; then
34 echo "failed in: compare_directories $1 $2"
35 exit 1
36 fi
37}
38
epoger@google.coma4443522012-05-17 17:12:38 +000039# Run skdiff with arguments in $1 (plus implicit final argument causing skdiff
40# to write its output, if any, to directory $2/output-actual).
41# Then compare its results against those in $2/output-expected.
42function skdiff_test {
epoger@google.coma413a532012-11-12 18:04:51 +000043 if [ $# != 2 ]; then
44 echo "skdiff_test requires exactly 2 parameters, got $#"
45 exit 1
46 fi
epoger@google.coma4443522012-05-17 17:12:38 +000047 SKDIFF_ARGS="$1"
48 ACTUAL_OUTPUT_DIR="$2/output-actual"
49 EXPECTED_OUTPUT_DIR="$2/output-expected"
epoger@google.coma2b793c2012-05-15 14:58:53 +000050
epoger@google.coma4443522012-05-17 17:12:38 +000051 rm -rf $ACTUAL_OUTPUT_DIR
52 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com90cb9b32012-05-18 18:25:26 +000053 COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR"
54 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
55 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
56 echo $? >$ACTUAL_OUTPUT_DIR/return_value
57
epoger@google.coma4443522012-05-17 17:12:38 +000058 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
59}
60
61SKDIFF_TESTDIR=tools/tests/skdiff
epoger@google.com8e4e51d2012-05-30 19:12:45 +000062
epoger@google.comdfbf24e2012-07-13 21:22:02 +000063# Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from
64# baseDir, etc.
epoger@google.coma4443522012-05-17 17:12:38 +000065skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000066
epoger@google.comdfbf24e2012-07-13 21:22:02 +000067# Run skdiff over the same set of files, but with arguments as used by our buildbots:
68# - return the number of mismatching file pairs (but ignore any files missing from either
69# baseDir or comparisonDir)
epoger@google.com46a45962012-07-12 18:16:02 +000070# - list filenames with each result type to stdout
71# - don't generate HTML output files
bungeman@google.come3c8ddf2012-12-05 20:13:12 +000072skdiff_test "--failonresult DifferentPixels --failonresult DifferentSizes --failonresult Unknown --failonstatus CouldNotDecode,CouldNotRead any --failonstatus any CouldNotDecode,CouldNotRead --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000073
epoger@google.comdfbf24e2012-07-13 21:22:02 +000074# Run skdiff over just the files that have identical bits.
75skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000076
epoger@google.comdfbf24e2012-07-13 21:22:02 +000077# Run skdiff over just the files that have identical bits or identical pixels.
78skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000079
epoger@google.coma2b793c2012-05-15 14:58:53 +000080echo "All tests passed."