blob: 1f7bf5e191d0cfa4e7de87a478ff5f0788c61cd9 [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.com3aa33582013-01-02 15:53:25 +00005# TODO: currently, this only passes on Linux (which is the platform that
6# the housekeeper bot runs on, e.g.
7# http://70.32.156.51:10117/builders/Skia_PerCommit_House_Keeping/builds/1415/steps/RunToolSelfTests/logs/stdio )
8# See https://code.google.com/p/skia/issues/detail?id=677
9# ('make tools/tests/run.sh work cross-platform')
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)/../..
epoger@google.coma2b793c2012-05-15 14:58:53 +000016
17# TODO: make it look in Release and/or Debug
18SKDIFF_BINARY=out/Debug/skdiff
19
epoger@google.coma4443522012-05-17 17:12:38 +000020# 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.
epoger@google.coma2b793c2012-05-15 14:58:53 +000025function compare_directories {
epoger@google.coma413a532012-11-12 18:04:51 +000026 if [ $# != 2 ]; then
27 echo "compare_directories requires exactly 2 parameters, got $#"
28 exit 1
29 fi
epoger@google.coma2b793c2012-05-15 14:58:53 +000030 diff --exclude=.* $1 $2
31 if [ $? != 0 ]; then
32 echo "failed in: compare_directories $1 $2"
33 exit 1
34 fi
35}
36
epoger@google.coma4443522012-05-17 17:12:38 +000037# Run skdiff with arguments in $1 (plus implicit final argument causing skdiff
38# to write its output, if any, to directory $2/output-actual).
39# Then compare its results against those in $2/output-expected.
40function skdiff_test {
epoger@google.coma413a532012-11-12 18:04:51 +000041 if [ $# != 2 ]; then
42 echo "skdiff_test requires exactly 2 parameters, got $#"
43 exit 1
44 fi
epoger@google.coma4443522012-05-17 17:12:38 +000045 SKDIFF_ARGS="$1"
46 ACTUAL_OUTPUT_DIR="$2/output-actual"
47 EXPECTED_OUTPUT_DIR="$2/output-expected"
epoger@google.coma2b793c2012-05-15 14:58:53 +000048
epoger@google.coma4443522012-05-17 17:12:38 +000049 rm -rf $ACTUAL_OUTPUT_DIR
50 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com90cb9b32012-05-18 18:25:26 +000051 COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR"
52 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
53 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
54 echo $? >$ACTUAL_OUTPUT_DIR/return_value
55
epoger@google.coma4443522012-05-17 17:12:38 +000056 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
57}
58
59SKDIFF_TESTDIR=tools/tests/skdiff
epoger@google.com8e4e51d2012-05-30 19:12:45 +000060
epoger@google.comdfbf24e2012-07-13 21:22:02 +000061# Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from
62# baseDir, etc.
epoger@google.coma4443522012-05-17 17:12:38 +000063skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000064
epoger@google.comdfbf24e2012-07-13 21:22:02 +000065# Run skdiff over the same set of files, but with arguments as used by our buildbots:
66# - return the number of mismatching file pairs (but ignore any files missing from either
67# baseDir or comparisonDir)
epoger@google.com46a45962012-07-12 18:16:02 +000068# - list filenames with each result type to stdout
69# - don't generate HTML output files
bungeman@google.come3c8ddf2012-12-05 20:13:12 +000070skdiff_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 +000071
epoger@google.comdfbf24e2012-07-13 21:22:02 +000072# Run skdiff over just the files that have identical bits.
73skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000074
epoger@google.comdfbf24e2012-07-13 21:22:02 +000075# Run skdiff over just the files that have identical bits or identical pixels.
76skdiff_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 +000077
epoger@google.comf4eeeab2013-02-14 15:10:24 +000078
79# Run bench_graph_svg.py across the data from platform $1,
80# writing its output to output-actual and comparing those results against
81# output-expected.
82function benchgraph_test {
83 if [ $# != 1 ]; then
84 echo "benchgraph_test requires exactly 1 parameter, got $#"
85 exit 1
86 fi
87 PLATFORM="$1"
88
89 PLATFORM_DIR="tools/tests/benchgraphs/$PLATFORM"
90 TARBALL_DIR="$PLATFORM_DIR/tarballs"
91 RAW_BENCH_DATA_DIR="$PLATFORM_DIR/raw-bench-data"
92 ACTUAL_OUTPUT_DIR="$PLATFORM_DIR/output-actual"
93 EXPECTED_OUTPUT_DIR="$PLATFORM_DIR/output-expected"
94
95 # First, unpack raw bench data from tarballs.
96 # (The raw bench data files are large, so this saves space in our SVN repo.)
97 rm -rf $RAW_BENCH_DATA_DIR
98 mkdir -p $RAW_BENCH_DATA_DIR
99 for TARBALL in $TARBALL_DIR/*.tgz ; do
100 tar --extract --gunzip --directory $RAW_BENCH_DATA_DIR --file $TARBALL
101 done
102
103 # Now that we have the input files we need, run bench_graph_svg.py .
104 rm -rf $ACTUAL_OUTPUT_DIR
105 mkdir -p $ACTUAL_OUTPUT_DIR
106 COMMAND="python bench/bench_graph_svg.py -d $RAW_BENCH_DATA_DIR -r -150 -f -150 -x 1024 -y 768 -l Title -m 25th -o $ACTUAL_OUTPUT_DIR/graph.xhtml"
107 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
108 START_TIMESTAMP=$(date +%s)
109 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
110 echo $? >$ACTUAL_OUTPUT_DIR/return_value
111 END_TIMESTAMP=$(date +%s)
112
113 SECONDS_RUN=$(expr $END_TIMESTAMP - $START_TIMESTAMP)
114 echo "bench_graph_svg.py for $PLATFORM took $SECONDS_RUN seconds to complete"
115
116 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
117}
118
epoger@google.com2459a392013-02-14 18:58:05 +0000119benchgraph_test Skia_Shuttle_Ubuntu12_ATI5770_Float_Bench_32
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000120
epoger@google.coma2b793c2012-05-15 14:58:53 +0000121echo "All tests passed."