blob: eb003c860436fb23800f3f02bda67d8eabd6a5af [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
bensong@google.com4a28f592013-10-24 18:08:45 +000020# Suffixes of the raw bench data files we want to process.
epoger@google.combd9669a2013-02-17 08:33:27 +000021BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES=\
bensong@google.com4a28f592013-10-24 18:08:45 +000022"data_skp_scale_1.3061_config_8888_mode_tile_256_256_timeIndividualTiles_bbh_rtree "\
23"data_skp_scale_1.3061_config_8888_mode_tile_256_256_timeIndividualTiles"
epoger@google.combd9669a2013-02-17 08:33:27 +000024BENCHDATA_FILE_SUFFIXES_NO_INDIVIDUAL_TILES=\
bensong@google.com4a28f592013-10-24 18:08:45 +000025"data_skp_multi_4_scale_1.3061_config_8888_mode_tile_256_256 "\
26"data_skp_scale_1.3061_config_8888_mode_record"
epoger@google.com673816c2013-02-15 15:50:23 +000027
epoger@google.coma4443522012-05-17 17:12:38 +000028# Compare contents of all files within directories $1 and $2,
29# EXCEPT for any dotfiles.
30# If there are any differences, a description is written to stdout and
31# we exit with a nonzero return value.
32# Otherwise, we write nothing to stdout and return.
epoger@google.coma2b793c2012-05-15 14:58:53 +000033function compare_directories {
epoger@google.coma413a532012-11-12 18:04:51 +000034 if [ $# != 2 ]; then
35 echo "compare_directories requires exactly 2 parameters, got $#"
36 exit 1
37 fi
epoger@google.com34b73a22013-07-03 17:43:11 +000038 diff --recursive --exclude=.* $1 $2
epoger@google.coma2b793c2012-05-15 14:58:53 +000039 if [ $? != 0 ]; then
40 echo "failed in: compare_directories $1 $2"
41 exit 1
42 fi
43}
44
epoger@google.coma4443522012-05-17 17:12:38 +000045# Run skdiff with arguments in $1 (plus implicit final argument causing skdiff
46# to write its output, if any, to directory $2/output-actual).
47# Then compare its results against those in $2/output-expected.
48function skdiff_test {
epoger@google.coma413a532012-11-12 18:04:51 +000049 if [ $# != 2 ]; then
50 echo "skdiff_test requires exactly 2 parameters, got $#"
51 exit 1
52 fi
epoger@google.coma4443522012-05-17 17:12:38 +000053 SKDIFF_ARGS="$1"
54 ACTUAL_OUTPUT_DIR="$2/output-actual"
55 EXPECTED_OUTPUT_DIR="$2/output-expected"
epoger@google.coma2b793c2012-05-15 14:58:53 +000056
epoger@google.coma4443522012-05-17 17:12:38 +000057 rm -rf $ACTUAL_OUTPUT_DIR
58 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com90cb9b32012-05-18 18:25:26 +000059 COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR"
60 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
61 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
62 echo $? >$ACTUAL_OUTPUT_DIR/return_value
63
epoger@google.coma4443522012-05-17 17:12:38 +000064 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
65}
66
epoger@google.com673816c2013-02-15 15:50:23 +000067# Download a subset of the raw bench data for platform $1 at revision $2.
epoger@google.combd9669a2013-02-17 08:33:27 +000068# (For the subset, download all files matching any of the suffixes in
69# whitespace-separated list $3.)
epoger@google.com673816c2013-02-15 15:50:23 +000070# If any of those files already exist locally, we assume that they are
71# correct and up to date, and we don't download them again.
bensong@google.com4a28f592013-10-24 18:08:45 +000072function download_bench_rawdata {
epoger@google.combd9669a2013-02-17 08:33:27 +000073 if [ $# != 3 ]; then
bensong@google.com4a28f592013-10-24 18:08:45 +000074 echo "download_bench_rawdata requires exactly 3 parameters, got $#"
epoger@google.com673816c2013-02-15 15:50:23 +000075 exit 1
76 fi
77 PLATFORM="$1"
78 REV="$2"
epoger@google.combd9669a2013-02-17 08:33:27 +000079 FILE_SUFFIXES="$3"
epoger@google.com673816c2013-02-15 15:50:23 +000080
bensong@google.com4a28f592013-10-24 18:08:45 +000081 PLATFORM_DIR="tools/tests/benchalerts/$PLATFORM"
epoger@google.com673816c2013-02-15 15:50:23 +000082 RAW_BENCH_DATA_DIR="$PLATFORM_DIR/raw-bench-data"
83 mkdir -p $RAW_BENCH_DATA_DIR
84
epoger@google.combd9669a2013-02-17 08:33:27 +000085 for FILE_SUFFIX in $FILE_SUFFIXES; do
bensong@google.com4a28f592013-10-24 18:08:45 +000086 FILE=bench_${REV}_${FILE_SUFFIX}
epoger@google.com673816c2013-02-15 15:50:23 +000087 DESTFILE=$RAW_BENCH_DATA_DIR/$FILE
88 if [ ! -f $DESTFILE ];
89 then
bensong@google.com4a28f592013-10-24 18:08:45 +000090 URL=http://chromium-skia-gm.commondatastorage.googleapis.com/perfdata/${PLATFORM}/${FILE}
epoger@google.comaa6470a2013-02-15 16:42:21 +000091 echo Downloading $URL ...
epoger@google.com673816c2013-02-15 15:50:23 +000092 curl $URL --output $DESTFILE
93 fi
94 done
95}
96
bensong@google.com4a28f592013-10-24 18:08:45 +000097# Run check_bench_regressions.py across the data from platform $1,
epoger@google.comf4eeeab2013-02-14 15:10:24 +000098# writing its output to output-actual and comparing those results against
99# output-expected.
bensong@google.com4a28f592013-10-24 18:08:45 +0000100function benchalert_test {
101 if [ $# != 2 ]; then
102 echo "benchalert_test requires exactly 2 parameter, got $#"
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000103 exit 1
104 fi
105 PLATFORM="$1"
bensong@google.com4a28f592013-10-24 18:08:45 +0000106 REVISION="$2"
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000107
bensong@google.com4a28f592013-10-24 18:08:45 +0000108 PLATFORM_DIR="tools/tests/benchalerts/$PLATFORM"
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000109 RAW_BENCH_DATA_DIR="$PLATFORM_DIR/raw-bench-data"
110 ACTUAL_OUTPUT_DIR="$PLATFORM_DIR/output-actual"
111 EXPECTED_OUTPUT_DIR="$PLATFORM_DIR/output-expected"
112
bensong@google.com4a28f592013-10-24 18:08:45 +0000113 # Run check_bench_regressions.py .
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000114 rm -rf $ACTUAL_OUTPUT_DIR
115 mkdir -p $ACTUAL_OUTPUT_DIR
bensong@google.com4a28f592013-10-24 18:08:45 +0000116 COMMAND="python bench/check_bench_regressions.py -a 25th -b $PLATFORM -d $RAW_BENCH_DATA_DIR -e $PLATFORM_DIR/expectations.txt -r $REVISION"
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000117 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
118 START_TIMESTAMP=$(date +%s)
bensong@google.com4a28f592013-10-24 18:08:45 +0000119 $COMMAND 2>$ACTUAL_OUTPUT_DIR/stderr
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000120 echo $? >$ACTUAL_OUTPUT_DIR/return_value
121 END_TIMESTAMP=$(date +%s)
122
123 SECONDS_RUN=$(expr $END_TIMESTAMP - $START_TIMESTAMP)
bensong@google.com4a28f592013-10-24 18:08:45 +0000124 echo "check_bench_regressions.py took $SECONDS_RUN seconds to complete"
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000125
126 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
127}
128
epoger@google.com2a192a82013-08-02 20:54:46 +0000129# Test rebaseline.py's JSON-format expectations rebaselining capability.
epoger@google.com34b73a22013-07-03 17:43:11 +0000130#
epoger@google.comfd040112013-08-20 16:21:55 +0000131# Copy expected-results.json files from $1 into a dir where they can be modified.
epoger@google.com34b73a22013-07-03 17:43:11 +0000132# Run rebaseline.py with arguments in $2, recording its output.
epoger@google.comfd040112013-08-20 16:21:55 +0000133# Then compare the output (and modified expected-results.json files) to the
epoger@google.com34b73a22013-07-03 17:43:11 +0000134# content of $2/output-expected.
135function rebaseline_test {
136 if [ $# != 3 ]; then
137 echo "rebaseline_test requires exactly 3 parameters, got $#"
138 exit 1
139 fi
140 COPY_EXPECTATIONS_FROM_DIR="$1"
141 ARGS="$2"
142 ACTUAL_OUTPUT_DIR="$3/output-actual"
143 EXPECTED_OUTPUT_DIR="$3/output-expected"
144
145 rm -rf $ACTUAL_OUTPUT_DIR
146 mkdir -p $ACTUAL_OUTPUT_DIR
147 EXPECTATIONS_TO_MODIFY_DIR="$ACTUAL_OUTPUT_DIR/gm-expectations"
epoger@google.com3f0a1082013-08-28 19:04:05 +0000148 BUILDERS=$(ls $COPY_EXPECTATIONS_FROM_DIR)
epoger@google.comfd040112013-08-20 16:21:55 +0000149 for BUILDER in $BUILDERS; do
150 mkdir -p $EXPECTATIONS_TO_MODIFY_DIR/$BUILDER
151 cp $COPY_EXPECTATIONS_FROM_DIR/$BUILDER/expected-results.json \
152 $EXPECTATIONS_TO_MODIFY_DIR/$BUILDER
epoger@google.com34b73a22013-07-03 17:43:11 +0000153 done
154 COMMAND="python tools/rebaseline.py --expectations-root $EXPECTATIONS_TO_MODIFY_DIR $ARGS"
155 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
156 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
157 echo $? >$ACTUAL_OUTPUT_DIR/return_value
158
epoger@google.com3f0a1082013-08-28 19:04:05 +0000159 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
epoger@google.com34b73a22013-07-03 17:43:11 +0000160}
161
epoger@google.com53953b42013-07-02 20:22:27 +0000162# Run jsondiff.py with arguments in $1, recording its output.
163# Then compare that output to the content of $2/output-expected.
164function jsondiff_test {
165 if [ $# != 2 ]; then
166 echo "jsondiff_test requires exactly 2 parameters, got $#"
167 exit 1
168 fi
169 ARGS="$1"
170 ACTUAL_OUTPUT_DIR="$2/output-actual"
171 EXPECTED_OUTPUT_DIR="$2/output-expected"
172
173 rm -rf $ACTUAL_OUTPUT_DIR
174 mkdir -p $ACTUAL_OUTPUT_DIR
175 COMMAND="python tools/jsondiff.py $ARGS"
176 echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
177 $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
178 echo $? >$ACTUAL_OUTPUT_DIR/return_value
179
180 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
181}
182
epoger@google.comdb29a312013-06-04 14:58:47 +0000183
184
185#
186# Run skdiff tests...
187#
188
189SKDIFF_TESTDIR=tools/tests/skdiff
190
191# Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from
192# baseDir, etc.
193skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"
194
195# Run skdiff over the same set of files, but with arguments as used by our buildbots:
196# - return the number of mismatching file pairs (but ignore any files missing from either
197# baseDir or comparisonDir)
198# - list filenames with each result type to stdout
199# - don't generate HTML output files
200skdiff_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"
201
202# Run skdiff over just the files that have identical bits.
203skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"
204
205# Run skdiff over just the files that have identical bits or identical pixels.
206skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"
207
208#
bensong@google.com4a28f592013-10-24 18:08:45 +0000209# Run bench alerts tests...
epoger@google.comdb29a312013-06-04 14:58:47 +0000210#
211
bensong@google.com4a28f592013-10-24 18:08:45 +0000212# Parse a collection of bench data
213PLATFORM=Perf-Android-Nexus7-Tegra3-Arm7-Release
214REVISION=69c9e1a7261a3c8361e2b2c109d6340862149e34
215download_bench_rawdata $PLATFORM $REVISION "$BENCHDATA_FILE_SUFFIXES_NO_INDIVIDUAL_TILES"
216download_bench_rawdata $PLATFORM $REVISION "$BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES"
217benchalert_test $PLATFORM $REVISION
epoger@google.comf4eeeab2013-02-14 15:10:24 +0000218
epoger@google.comdb29a312013-06-04 14:58:47 +0000219#
scroggo@google.come762dad2013-06-07 12:40:35 +0000220# Run self test for skimage ...
221#
222
223COMMAND="python tools/tests/skimage_self_test.py"
224echo "$COMMAND"
225$COMMAND
226ret=$?
227if [ $ret -ne 0 ]; then
228 echo "skimage self tests failed."
229 exit 1
230fi
231
232#
epoger@google.comdb29a312013-06-04 14:58:47 +0000233# Test rebaseline.py ...
234#
235
epoger@google.com19e80c12013-06-06 15:11:11 +0000236REBASELINE_INPUT=tools/tests/rebaseline/input
237REBASELINE_OUTPUT=tools/tests/rebaseline/output
epoger@google.comfd040112013-08-20 16:21:55 +0000238rebaseline_test "$REBASELINE_INPUT/json1" "--actuals-base-url $REBASELINE_INPUT/json1 --builders Test-Android-GalaxyNexus-SGX540-Arm7-Debug Test-Win7-ShuttleA-HD2000-x86-Release" "$REBASELINE_OUTPUT/using-json1-expectations"
epoger@google.com06e626d2013-09-03 17:32:15 +0000239rebaseline_test "$REBASELINE_INPUT/json1" "--actuals-base-url $REBASELINE_INPUT/json1 --bugs 1234 5678 --builders Test-Android-GalaxyNexus-SGX540-Arm7-Debug Test-Win7-ShuttleA-HD2000-x86-Release --notes notes_content --unreviewed" "$REBASELINE_OUTPUT/marked-unreviewed"
epoger@google.com93acfd22013-09-03 18:27:19 +0000240rebaseline_test "$REBASELINE_INPUT/json1" "--actuals-base-url $REBASELINE_INPUT/json1 --add-new --builders Test-Android-GalaxyNexus-SGX540-Arm7-Debug Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release Test-Win7-ShuttleA-HD2000-x86-Release" "$REBASELINE_OUTPUT/add-new"
epoger@google.comdb29a312013-06-04 14:58:47 +0000241
epoger@google.com53953b42013-07-02 20:22:27 +0000242#
243# Test jsondiff.py ...
244#
245
246JSONDIFF_INPUT=tools/tests/jsondiff/input
247JSONDIFF_OUTPUT=tools/tests/jsondiff/output
248jsondiff_test "$JSONDIFF_INPUT/old.json $JSONDIFF_INPUT/new.json" "$JSONDIFF_OUTPUT/old-vs-new"
249
250
epoger@google.coma2b793c2012-05-15 14:58:53 +0000251echo "All tests passed."