blob: b36c1e2807cb44787d700dc5904be60e79337589 [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.com673816c2013-02-15 15:50:23 +000020# Suffixes of all the raw bench data files we want to process.
epoger@google.combd9669a2013-02-17 08:33:27 +000021BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES=\
epoger@google.comaa6470a2013-02-15 16:42:21 +000022"data_skp_device_bitmap_multi_2_mode_tile_256_256_timeIndividualTiles "\
23"data_skp_device_bitmap_multi_3_mode_tile_256_256_timeIndividualTiles "\
24"data_skp_device_bitmap_multi_4_mode_tile_256_256_timeIndividualTiles "\
25"data_skp_device_bitmap_mode_record_bbh_rtree"
epoger@google.combd9669a2013-02-17 08:33:27 +000026BENCHDATA_FILE_SUFFIXES_NO_INDIVIDUAL_TILES=\
27"data_skp_device_bitmap_multi_2_mode_tile_256_256 "\
28"data_skp_device_bitmap_multi_3_mode_tile_256_256 "\
29"data_skp_device_bitmap_multi_4_mode_tile_256_256 "\
30"data_skp_device_bitmap_mode_record_bbh_rtree"
epoger@google.com673816c2013-02-15 15:50:23 +000031
epoger@google.coma4443522012-05-17 17:12:38 +000032# Compare contents of all files within directories $1 and $2,
33# EXCEPT for any dotfiles.
34# If there are any differences, a description is written to stdout and
35# we exit with a nonzero return value.
36# Otherwise, we write nothing to stdout and return.
epoger@google.coma2b793c2012-05-15 14:58:53 +000037function compare_directories {
epoger@google.coma413a532012-11-12 18:04:51 +000038 if [ $# != 2 ]; then
39 echo "compare_directories requires exactly 2 parameters, got $#"
40 exit 1
41 fi
epoger@google.com34b73a22013-07-03 17:43:11 +000042 diff --recursive --exclude=.* $1 $2
epoger@google.coma2b793c2012-05-15 14:58:53 +000043 if [ $? != 0 ]; then
44 echo "failed in: compare_directories $1 $2"
45 exit 1
46 fi
47}
48
epoger@google.coma4443522012-05-17 17:12:38 +000049# Run skdiff with arguments in $1 (plus implicit final argument causing skdiff
50# to write its output, if any, to directory $2/output-actual).
51# Then compare its results against those in $2/output-expected.
52function skdiff_test {
epoger@google.coma413a532012-11-12 18:04:51 +000053 if [ $# != 2 ]; then
54 echo "skdiff_test requires exactly 2 parameters, got $#"
55 exit 1
56 fi
epoger@google.coma4443522012-05-17 17:12:38 +000057 SKDIFF_ARGS="$1"
58 ACTUAL_OUTPUT_DIR="$2/output-actual"
59 EXPECTED_OUTPUT_DIR="$2/output-expected"
epoger@google.coma2b793c2012-05-15 14:58:53 +000060
epoger@google.coma4443522012-05-17 17:12:38 +000061 rm -rf $ACTUAL_OUTPUT_DIR
62 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com90cb9b32012-05-18 18:25:26 +000063 COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR"
64 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
65 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
66 echo $? >$ACTUAL_OUTPUT_DIR/return_value
67
epoger@google.coma4443522012-05-17 17:12:38 +000068 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
69}
70
epoger@google.com673816c2013-02-15 15:50:23 +000071# Download a subset of the raw bench data for platform $1 at revision $2.
epoger@google.combd9669a2013-02-17 08:33:27 +000072# (For the subset, download all files matching any of the suffixes in
73# whitespace-separated list $3.)
epoger@google.com673816c2013-02-15 15:50:23 +000074# If any of those files already exist locally, we assume that they are
75# correct and up to date, and we don't download them again.
76function benchgraph_download_rawdata {
epoger@google.combd9669a2013-02-17 08:33:27 +000077 if [ $# != 3 ]; then
78 echo "benchgraph_download_rawdata requires exactly 3 parameters, got $#"
epoger@google.com673816c2013-02-15 15:50:23 +000079 exit 1
80 fi
81 PLATFORM="$1"
82 REV="$2"
epoger@google.combd9669a2013-02-17 08:33:27 +000083 FILE_SUFFIXES="$3"
epoger@google.com673816c2013-02-15 15:50:23 +000084
85 PLATFORM_DIR="tools/tests/benchgraphs/$PLATFORM"
86 RAW_BENCH_DATA_DIR="$PLATFORM_DIR/raw-bench-data"
87 mkdir -p $RAW_BENCH_DATA_DIR
88
epoger@google.combd9669a2013-02-17 08:33:27 +000089 for FILE_SUFFIX in $FILE_SUFFIXES; do
epoger@google.com673816c2013-02-15 15:50:23 +000090 FILE=bench_r${REV}_${FILE_SUFFIX}
91 DESTFILE=$RAW_BENCH_DATA_DIR/$FILE
92 if [ ! -f $DESTFILE ];
93 then
94 URL=http://chromium-skia-gm.commondatastorage.googleapis.com/playback/perfdata/${PLATFORM}/data/${FILE}
epoger@google.comaa6470a2013-02-15 16:42:21 +000095 echo Downloading $URL ...
epoger@google.com673816c2013-02-15 15:50:23 +000096 curl $URL --output $DESTFILE
97 fi
98 done
99}
100
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000101# Run bench_graph_svg.py across the data from platform $1,
102# writing its output to output-actual and comparing those results against
103# output-expected.
104function benchgraph_test {
105 if [ $# != 1 ]; then
106 echo "benchgraph_test requires exactly 1 parameter, got $#"
107 exit 1
108 fi
109 PLATFORM="$1"
110
111 PLATFORM_DIR="tools/tests/benchgraphs/$PLATFORM"
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000112 RAW_BENCH_DATA_DIR="$PLATFORM_DIR/raw-bench-data"
113 ACTUAL_OUTPUT_DIR="$PLATFORM_DIR/output-actual"
114 EXPECTED_OUTPUT_DIR="$PLATFORM_DIR/output-expected"
115
epoger@google.com673816c2013-02-15 15:50:23 +0000116 # Run bench_graph_svg.py .
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000117 rm -rf $ACTUAL_OUTPUT_DIR
118 mkdir -p $ACTUAL_OUTPUT_DIR
119 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"
120 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
121 START_TIMESTAMP=$(date +%s)
122 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
123 echo $? >$ACTUAL_OUTPUT_DIR/return_value
124 END_TIMESTAMP=$(date +%s)
125
126 SECONDS_RUN=$(expr $END_TIMESTAMP - $START_TIMESTAMP)
127 echo "bench_graph_svg.py for $PLATFORM took $SECONDS_RUN seconds to complete"
128
129 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
130}
131
epoger@google.com2a192a82013-08-02 20:54:46 +0000132# Test rebaseline.py's JSON-format expectations rebaselining capability.
epoger@google.com34b73a22013-07-03 17:43:11 +0000133#
134# Copy expected-result.json files from $1 into a dir where they can be modified.
135# Run rebaseline.py with arguments in $2, recording its output.
136# Then compare the output (and modified expected-result.json files) to the
137# content of $2/output-expected.
138function rebaseline_test {
139 if [ $# != 3 ]; then
140 echo "rebaseline_test requires exactly 3 parameters, got $#"
141 exit 1
142 fi
143 COPY_EXPECTATIONS_FROM_DIR="$1"
144 ARGS="$2"
145 ACTUAL_OUTPUT_DIR="$3/output-actual"
146 EXPECTED_OUTPUT_DIR="$3/output-expected"
147
148 rm -rf $ACTUAL_OUTPUT_DIR
149 mkdir -p $ACTUAL_OUTPUT_DIR
150 EXPECTATIONS_TO_MODIFY_DIR="$ACTUAL_OUTPUT_DIR/gm-expectations"
151 SUBDIRS=$(ls $COPY_EXPECTATIONS_FROM_DIR)
152 for SUBDIR in $SUBDIRS; do
153 mkdir -p $EXPECTATIONS_TO_MODIFY_DIR/$SUBDIR
154 cp $COPY_EXPECTATIONS_FROM_DIR/$SUBDIR/expected-results.json \
155 $EXPECTATIONS_TO_MODIFY_DIR/$SUBDIR
156 done
157 COMMAND="python tools/rebaseline.py --expectations-root $EXPECTATIONS_TO_MODIFY_DIR $ARGS"
158 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
159 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
160 echo $? >$ACTUAL_OUTPUT_DIR/return_value
161
162 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
163}
164
epoger@google.com53953b42013-07-02 20:22:27 +0000165# Run jsondiff.py with arguments in $1, recording its output.
166# Then compare that output to the content of $2/output-expected.
167function jsondiff_test {
168 if [ $# != 2 ]; then
169 echo "jsondiff_test requires exactly 2 parameters, got $#"
170 exit 1
171 fi
172 ARGS="$1"
173 ACTUAL_OUTPUT_DIR="$2/output-actual"
174 EXPECTED_OUTPUT_DIR="$2/output-expected"
175
176 rm -rf $ACTUAL_OUTPUT_DIR
177 mkdir -p $ACTUAL_OUTPUT_DIR
178 COMMAND="python tools/jsondiff.py $ARGS"
179 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
180 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
181 echo $? >$ACTUAL_OUTPUT_DIR/return_value
182
183 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
184}
185
epoger@google.comdb29a312013-06-04 14:58:47 +0000186
187
188#
189# Run skdiff tests...
190#
191
192SKDIFF_TESTDIR=tools/tests/skdiff
193
194# Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from
195# baseDir, etc.
196skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"
197
198# Run skdiff over the same set of files, but with arguments as used by our buildbots:
199# - return the number of mismatching file pairs (but ignore any files missing from either
200# baseDir or comparisonDir)
201# - list filenames with each result type to stdout
202# - don't generate HTML output files
203skdiff_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"
204
205# Run skdiff over just the files that have identical bits.
206skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"
207
208# Run skdiff over just the files that have identical bits or identical pixels.
209skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"
210
211#
212# Run benchgraph tests...
213#
214
epoger@google.comaa6470a2013-02-15 16:42:21 +0000215# Parse a collection of bench data leading up to
216# http://70.32.156.53:10117/builders/Skia_Shuttle_Ubuntu12_ATI5770_Float_Bench_32/builds/878/steps/GenerateWebpagePictureBenchGraphs/logs/stdio
217# (this was during the period when the bench data included a ton of per-tile,
218# per-iteration data)
219PLATFORM=Skia_Shuttle_Ubuntu12_ATI5770_Float_Bench_32
epoger@google.combd9669a2013-02-17 08:33:27 +0000220benchgraph_download_rawdata $PLATFORM 7618 "$BENCHDATA_FILE_SUFFIXES_NO_INDIVIDUAL_TILES"
221benchgraph_download_rawdata $PLATFORM 7671 "$BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES"
222benchgraph_download_rawdata $PLATFORM 7679 "$BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES"
223benchgraph_download_rawdata $PLATFORM 7686 "$BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES"
epoger@google.comaa6470a2013-02-15 16:42:21 +0000224benchgraph_test $PLATFORM
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000225
epoger@google.comdb29a312013-06-04 14:58:47 +0000226#
scroggo@google.come762dad2013-06-07 12:40:35 +0000227# Run self test for skimage ...
228#
229
230COMMAND="python tools/tests/skimage_self_test.py"
231echo "$COMMAND"
232$COMMAND
233ret=$?
234if [ $ret -ne 0 ]; then
235 echo "skimage self tests failed."
236 exit 1
237fi
238
239#
epoger@google.comdb29a312013-06-04 14:58:47 +0000240# Test rebaseline.py ...
241#
242
epoger@google.com19e80c12013-06-06 15:11:11 +0000243REBASELINE_INPUT=tools/tests/rebaseline/input
244REBASELINE_OUTPUT=tools/tests/rebaseline/output
epoger@google.coma783f2b2013-07-08 17:51:58 +0000245rebaseline_test "$REBASELINE_INPUT/json1" "--actuals-base-url $REBASELINE_INPUT/json1 --subdirs base-android-galaxy-nexus base-shuttle-win7-intel-float" "$REBASELINE_OUTPUT/using-json1-expectations"
epoger@google.comdb29a312013-06-04 14:58:47 +0000246
epoger@google.com53953b42013-07-02 20:22:27 +0000247#
248# Test jsondiff.py ...
249#
250
251JSONDIFF_INPUT=tools/tests/jsondiff/input
252JSONDIFF_OUTPUT=tools/tests/jsondiff/output
253jsondiff_test "$JSONDIFF_INPUT/old.json $JSONDIFF_INPUT/new.json" "$JSONDIFF_OUTPUT/old-vs-new"
254
255
epoger@google.coma2b793c2012-05-15 14:58:53 +0000256echo "All tests passed."