aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/tests/run.sh
blob: fd12711f49e85e6bfa2064f9fd7efb3747529a0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash

# Tests for our tools.
#
# TODO: currently, this only passes on Linux (which is the platform that
# the housekeeper bot runs on, e.g.
# http://70.32.156.51:10117/builders/Skia_PerCommit_House_Keeping/builds/1415/steps/RunToolSelfTests/logs/stdio )
# See https://code.google.com/p/skia/issues/detail?id=677
# ('make tools/tests/run.sh work cross-platform')
# Ideally, these tests should pass on all development platforms...
# otherwise, how can developers be expected to test them before committing a
# change?

# cd into .../trunk so all the paths will work
cd $(dirname $0)/../..

# TODO: make it look in Release and/or Debug
SKDIFF_BINARY=out/Debug/skdiff

# Suffixes of the raw bench data files we want to process.
BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES=\
"data_skp_scale_1.3061_config_8888_mode_tile_256_256_timeIndividualTiles_bbh_rtree "\
"data_skp_scale_1.3061_config_8888_mode_tile_256_256_timeIndividualTiles"
BENCHDATA_FILE_SUFFIXES_NO_INDIVIDUAL_TILES=\
"data_skp_multi_4_scale_1.3061_config_8888_mode_tile_256_256 "\
"data_skp_scale_1.3061_config_8888_mode_record"

# Compare contents of all files within directories $1 and $2,
# EXCEPT for any dotfiles.
# If there are any differences, a description is written to stdout and
# we exit with a nonzero return value.
# Otherwise, we write nothing to stdout and return.
function compare_directories {
  if [ $# != 2 ]; then
    echo "compare_directories requires exactly 2 parameters, got $#"
    exit 1
  fi
  diff --recursive --exclude=.* $1 $2
  if [ $? != 0 ]; then
    echo "failed in: compare_directories $1 $2"
    exit 1
  fi
}

# Run skdiff with arguments in $1 (plus implicit final argument causing skdiff
# to write its output, if any, to directory $2/output-actual).
# Then compare its results against those in $2/output-expected.
function skdiff_test {
  if [ $# != 2 ]; then
    echo "skdiff_test requires exactly 2 parameters, got $#"
    exit 1
  fi
  SKDIFF_ARGS="$1"
  ACTUAL_OUTPUT_DIR="$2/output-actual"
  EXPECTED_OUTPUT_DIR="$2/output-expected"

  rm -rf $ACTUAL_OUTPUT_DIR
  mkdir -p $ACTUAL_OUTPUT_DIR
  COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR"
  echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
  $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
  echo $? >$ACTUAL_OUTPUT_DIR/return_value

  compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
}

# Download a subset of the raw bench data for platform $1 at revision $2.
# (For the subset, download all files matching any of the suffixes in
# whitespace-separated list $3.)
# If any of those files already exist locally, we assume that they are
# correct and up to date, and we don't download them again.
function download_bench_rawdata {
  if [ $# != 3 ]; then
    echo "download_bench_rawdata requires exactly 3 parameters, got $#"
    exit 1
  fi
  PLATFORM="$1"
  REV="$2"
  FILE_SUFFIXES="$3"

  PLATFORM_DIR="tools/tests/benchalerts/$PLATFORM"
  RAW_BENCH_DATA_DIR="$PLATFORM_DIR/raw-bench-data"
  mkdir -p $RAW_BENCH_DATA_DIR

  for FILE_SUFFIX in $FILE_SUFFIXES; do
    FILE=bench_${REV}_${FILE_SUFFIX}
    DESTFILE=$RAW_BENCH_DATA_DIR/$FILE
    if [ ! -f $DESTFILE ];
    then
      URL=http://chromium-skia-gm.commondatastorage.googleapis.com/perfdata/${PLATFORM}/${FILE}
      echo Downloading $URL ...
      curl $URL --output $DESTFILE
    fi
  done
}

# Run check_bench_regressions.py across the data from platform $1,
# writing its output to output-actual and comparing those results against
# output-expected.
function benchalert_test {
  if [ $# != 2 ]; then
    echo "benchalert_test requires exactly 2 parameter, got $#"
    exit 1
  fi
  PLATFORM="$1"
  REVISION="$2"

  PLATFORM_DIR="tools/tests/benchalerts/$PLATFORM"
  RAW_BENCH_DATA_DIR="$PLATFORM_DIR/raw-bench-data"
  ACTUAL_OUTPUT_DIR="$PLATFORM_DIR/output-actual"
  EXPECTED_OUTPUT_DIR="$PLATFORM_DIR/output-expected"

  # Run check_bench_regressions.py .
  rm -rf $ACTUAL_OUTPUT_DIR
  mkdir -p $ACTUAL_OUTPUT_DIR
  COMMAND="python bench/check_bench_regressions.py -a 25th -b $PLATFORM -d $RAW_BENCH_DATA_DIR -e $PLATFORM_DIR/expectations.txt -r $REVISION"
  echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
  START_TIMESTAMP=$(date +%s)
  $COMMAND 2>$ACTUAL_OUTPUT_DIR/stderr
  echo $? >$ACTUAL_OUTPUT_DIR/return_value
  END_TIMESTAMP=$(date +%s)

  SECONDS_RUN=$(expr $END_TIMESTAMP - $START_TIMESTAMP)
  echo "check_bench_regressions.py took $SECONDS_RUN seconds to complete"

  compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
}

# Run jsondiff.py with arguments in $1, recording its output.
# Then compare that output to the content of $2/output-expected.
function jsondiff_test {
  if [ $# != 2 ]; then
    echo "jsondiff_test requires exactly 2 parameters, got $#"
    exit 1
  fi
  ARGS="$1"
  ACTUAL_OUTPUT_DIR="$2/output-actual"
  EXPECTED_OUTPUT_DIR="$2/output-expected"

  rm -rf $ACTUAL_OUTPUT_DIR
  mkdir -p $ACTUAL_OUTPUT_DIR
  COMMAND="python tools/jsondiff.py $ARGS"
  echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
  $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout
  echo $? >$ACTUAL_OUTPUT_DIR/return_value

  compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
}



#
# Run skdiff tests...
#

SKDIFF_TESTDIR=tools/tests/skdiff

# Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from
# baseDir, etc.
skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"

# Run skdiff over the same set of files, but with arguments as used by our buildbots:
# - return the number of mismatching file pairs (but ignore any files missing from either
#   baseDir or comparisonDir)
# - list filenames with each result type to stdout
# - don't generate HTML output files
skdiff_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"

# Run skdiff over just the files that have identical bits.
skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"

# Run skdiff over just the files that have identical bits or identical pixels.
skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"

#
# Run bench alerts tests...
#

# Parse a collection of bench data
PLATFORM=Perf-Android-Nexus7-Tegra3-Arm7-Release
REVISION=69c9e1a7261a3c8361e2b2c109d6340862149e34
download_bench_rawdata $PLATFORM $REVISION "$BENCHDATA_FILE_SUFFIXES_NO_INDIVIDUAL_TILES"
download_bench_rawdata $PLATFORM $REVISION "$BENCHDATA_FILE_SUFFIXES_YES_INDIVIDUAL_TILES"
benchalert_test $PLATFORM $REVISION

#
# Test jsondiff.py ...
#

JSONDIFF_INPUT=tools/tests/jsondiff/input
JSONDIFF_OUTPUT=tools/tests/jsondiff/output
jsondiff_test "$JSONDIFF_INPUT/old.json $JSONDIFF_INPUT/new.json" "$JSONDIFF_OUTPUT/old-vs-new"


#
# Launch all the self-tests which have been written in Python.
#
# TODO: Over time, we should move all of our tests into Python, and delete
# the bash tests above.
# See https://code.google.com/p/skia/issues/detail?id=677
# ('make tools/tests/run.sh work cross-platform')
#

COMMAND="python tools/test_all.py"
echo "$COMMAND"
$COMMAND
ret=$?
if [ $ret -ne 0 ]; then
    echo "failure in Python self-tests; see stack trace above"
    exit 1
fi


echo "All tests passed."