2012-11-12 18:04:51 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Self-tests for gm, based on tools/tests/run.sh
|
2012-11-13 20:46:50 +00:00
|
|
|
#
|
|
|
|
# These tests are run by the Skia_PerCommit_House_Keeping bot at every commit,
|
|
|
|
# so make sure that they still pass when you make changes to gm!
|
|
|
|
#
|
2013-03-20 17:59:28 +00:00
|
|
|
# To generate new baselines when gm behavior changes, run gm/tests/rebaseline.sh
|
|
|
|
#
|
2013-03-01 15:32:34 +00:00
|
|
|
# TODO: because this is written as a shell script (instead of, say, Python)
|
|
|
|
# it only runs on Linux and Mac.
|
2013-01-02 15:53:25 +00:00
|
|
|
# See https://code.google.com/p/skia/issues/detail?id=677
|
|
|
|
# ('make tools/tests/run.sh work cross-platform')
|
2012-11-13 20:46:50 +00:00
|
|
|
# Ideally, these tests should pass on all development platforms...
|
|
|
|
# otherwise, how can developers be expected to test them before committing a
|
|
|
|
# change?
|
2012-11-12 18:04:51 +00:00
|
|
|
|
|
|
|
# cd into .../trunk so all the paths will work
|
|
|
|
cd $(dirname $0)/../..
|
|
|
|
|
|
|
|
# TODO(epoger): make it look in Release and/or Debug
|
|
|
|
GM_BINARY=out/Debug/gm
|
|
|
|
|
2013-01-18 19:19:47 +00:00
|
|
|
OUTPUT_ACTUAL_SUBDIR=output-actual
|
|
|
|
OUTPUT_EXPECTED_SUBDIR=output-expected
|
2013-03-20 14:20:18 +00:00
|
|
|
CONFIGS="--config 8888 565"
|
2013-01-18 19:19:47 +00:00
|
|
|
|
2013-04-26 17:45:06 +00:00
|
|
|
ENCOUNTERED_ANY_ERRORS=0
|
|
|
|
|
2012-11-12 18:04:51 +00:00
|
|
|
# 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 -r --exclude=.* $1 $2
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "failed in: compare_directories $1 $2"
|
2013-04-26 17:45:06 +00:00
|
|
|
ENCOUNTERED_ANY_ERRORS=1
|
2012-11-12 18:04:51 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-05-14 18:58:12 +00:00
|
|
|
# Run a command, and validate that it succeeds (returns 0).
|
|
|
|
function assert_passes {
|
|
|
|
COMMAND="$1"
|
|
|
|
OUTPUT=$($COMMAND 2>&1)
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "This command was supposed to pass, but failed: [$COMMAND]"
|
|
|
|
echo $OUTPUT
|
|
|
|
ENCOUNTERED_ANY_ERRORS=1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run a command, and validate that it fails (returns nonzero).
|
|
|
|
function assert_fails {
|
|
|
|
COMMAND="$1"
|
|
|
|
OUTPUT=$($COMMAND 2>&1)
|
|
|
|
if [ $? == 0 ]; then
|
|
|
|
echo "This command was supposed to fail, but passed: [$COMMAND]"
|
|
|
|
echo $OUTPUT
|
|
|
|
ENCOUNTERED_ANY_ERRORS=1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-11-12 18:04:51 +00:00
|
|
|
# Run gm...
|
|
|
|
# - with the arguments in $1
|
2013-01-18 19:19:47 +00:00
|
|
|
# - writing stdout into $2/$OUTPUT_ACTUAL_SUBDIR/stdout
|
|
|
|
# - writing json summary into $2/$OUTPUT_ACTUAL_SUBDIR/json-summary.txt
|
|
|
|
# - writing return value into $2/$OUTPUT_ACTUAL_SUBDIR/return_value
|
|
|
|
# Then compare all of those against $2/$OUTPUT_EXPECTED_SUBDIR .
|
2012-11-12 18:04:51 +00:00
|
|
|
function gm_test {
|
|
|
|
if [ $# != 2 ]; then
|
|
|
|
echo "gm_test requires exactly 2 parameters, got $#"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
GM_ARGS="$1"
|
2013-01-18 19:19:47 +00:00
|
|
|
ACTUAL_OUTPUT_DIR="$2/$OUTPUT_ACTUAL_SUBDIR"
|
|
|
|
EXPECTED_OUTPUT_DIR="$2/$OUTPUT_EXPECTED_SUBDIR"
|
|
|
|
JSON_SUMMARY_FILE="$ACTUAL_OUTPUT_DIR/json-summary.txt"
|
2012-11-12 18:04:51 +00:00
|
|
|
|
|
|
|
rm -rf $ACTUAL_OUTPUT_DIR
|
|
|
|
mkdir -p $ACTUAL_OUTPUT_DIR
|
2013-05-08 14:10:28 +00:00
|
|
|
|
2013-06-21 18:16:47 +00:00
|
|
|
COMMAND="$GM_BINARY $GM_ARGS --writeJsonSummaryPath $JSON_SUMMARY_FILE --writePath $ACTUAL_OUTPUT_DIR/writePath --mismatchPath $ACTUAL_OUTPUT_DIR/mismatchPath --missingExpectationsPath $ACTUAL_OUTPUT_DIR/missingExpectationsPath"
|
2013-05-08 14:10:28 +00:00
|
|
|
|
2012-11-12 18:04:51 +00:00
|
|
|
echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line
|
2013-03-13 14:18:40 +00:00
|
|
|
$COMMAND >$ACTUAL_OUTPUT_DIR/stdout 2>$ACTUAL_OUTPUT_DIR/stderr
|
2012-11-12 18:04:51 +00:00
|
|
|
echo $? >$ACTUAL_OUTPUT_DIR/return_value
|
|
|
|
|
2013-01-18 20:03:58 +00:00
|
|
|
# Only compare selected lines in the stdout, to ignore any spurious lines
|
2013-01-18 19:19:47 +00:00
|
|
|
# as noted in http://code.google.com/p/skia/issues/detail?id=1068 .
|
|
|
|
#
|
|
|
|
# TODO(epoger): This is still hacky... we need to rewrite this script in
|
|
|
|
# Python soon, and make stuff like this more maintainable.
|
2013-03-13 14:18:40 +00:00
|
|
|
grep ^GM: $ACTUAL_OUTPUT_DIR/stdout >$ACTUAL_OUTPUT_DIR/stdout-tmp
|
2013-01-16 04:19:01 +00:00
|
|
|
mv $ACTUAL_OUTPUT_DIR/stdout-tmp $ACTUAL_OUTPUT_DIR/stdout
|
2013-03-13 14:18:40 +00:00
|
|
|
grep ^GM: $ACTUAL_OUTPUT_DIR/stderr >$ACTUAL_OUTPUT_DIR/stderr-tmp
|
|
|
|
mv $ACTUAL_OUTPUT_DIR/stderr-tmp $ACTUAL_OUTPUT_DIR/stderr
|
2013-01-16 04:19:01 +00:00
|
|
|
|
2013-05-09 18:09:06 +00:00
|
|
|
# Replace image file contents with just the filename, for two reasons:
|
|
|
|
# 1. Image file encoding may vary by platform
|
|
|
|
# 2. https://code.google.com/p/chromium/issues/detail?id=169600
|
|
|
|
# ('gcl/upload.py fail to upload binary files to rietveld')
|
2013-05-21 15:41:35 +00:00
|
|
|
for IMAGEFILE in $(find $ACTUAL_OUTPUT_DIR -name *.png); do
|
2013-05-09 18:09:06 +00:00
|
|
|
echo "[contents of $IMAGEFILE]" >$IMAGEFILE
|
|
|
|
done
|
2013-07-08 19:13:33 +00:00
|
|
|
for IMAGEFILE in $(find $ACTUAL_OUTPUT_DIR -name *.pdf); do
|
|
|
|
echo "[contents of $IMAGEFILE]" >$IMAGEFILE
|
|
|
|
done
|
2013-06-21 18:16:47 +00:00
|
|
|
|
|
|
|
# Add a file to any empty subdirectories.
|
|
|
|
for DIR in $(find $ACTUAL_OUTPUT_DIR -mindepth 1 -type d); do
|
|
|
|
echo "Created additional file to make sure directory isn't empty, because self-test cannot handle empty directories." >$DIR/bogusfile
|
|
|
|
done
|
2013-05-08 14:10:28 +00:00
|
|
|
|
2012-11-12 18:04:51 +00:00
|
|
|
compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
|
|
|
|
}
|
|
|
|
|
2013-02-06 18:41:04 +00:00
|
|
|
# Create input dir (at path $1) with expectations (both image and json)
|
|
|
|
# that gm will match or mismatch as appropriate.
|
2013-01-18 19:19:47 +00:00
|
|
|
#
|
2013-05-21 15:41:35 +00:00
|
|
|
# We used to check these files into SVN, but then we needed to rebaseline them
|
2013-01-18 19:19:47 +00:00
|
|
|
# when our drawing changed at all... so, as proposed in
|
|
|
|
# http://code.google.com/p/skia/issues/detail?id=1068 , we generate them
|
|
|
|
# new each time.
|
|
|
|
function create_inputs_dir {
|
|
|
|
if [ $# != 1 ]; then
|
|
|
|
echo "create_inputs_dir requires exactly 1 parameter, got $#"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
INPUTS_DIR="$1"
|
2013-02-06 18:41:04 +00:00
|
|
|
IMAGES_DIR=$INPUTS_DIR/images
|
|
|
|
JSON_DIR=$INPUTS_DIR/json
|
|
|
|
mkdir -p $IMAGES_DIR $JSON_DIR
|
2013-01-18 19:19:47 +00:00
|
|
|
|
2013-05-21 15:41:35 +00:00
|
|
|
THIS_IMAGE_DIR=$IMAGES_DIR/identical-bytes
|
|
|
|
mkdir -p $THIS_IMAGE_DIR
|
2013-02-06 18:41:04 +00:00
|
|
|
# Run GM to write out the images actually generated.
|
2013-05-21 15:41:35 +00:00
|
|
|
$GM_BINARY --hierarchy --match selftest1 $CONFIGS -w $THIS_IMAGE_DIR
|
2013-02-06 18:41:04 +00:00
|
|
|
# Run GM again to read in those images and write them out as a JSON summary.
|
2013-05-21 15:41:35 +00:00
|
|
|
$GM_BINARY --hierarchy --match selftest1 $CONFIGS -r $THIS_IMAGE_DIR \
|
2013-03-20 14:20:18 +00:00
|
|
|
--writeJsonSummaryPath $JSON_DIR/identical-bytes.json
|
2013-01-18 19:19:47 +00:00
|
|
|
|
2013-05-21 15:41:35 +00:00
|
|
|
THIS_IMAGE_DIR=$IMAGES_DIR/identical-pixels
|
|
|
|
mkdir -p $THIS_IMAGE_DIR
|
|
|
|
$GM_BINARY --hierarchy --match selftest1 $CONFIGS -w $THIS_IMAGE_DIR
|
2013-01-18 19:19:47 +00:00
|
|
|
echo "more bytes that do not change the image pixels" \
|
2013-05-21 15:41:35 +00:00
|
|
|
>> $THIS_IMAGE_DIR/8888/selftest1.png
|
2013-01-31 15:06:36 +00:00
|
|
|
echo "more bytes that do not change the image pixels" \
|
2013-05-21 15:41:35 +00:00
|
|
|
>> $THIS_IMAGE_DIR/565/selftest1.png
|
|
|
|
$GM_BINARY --hierarchy --match selftest1 $CONFIGS -r $THIS_IMAGE_DIR \
|
2013-03-20 14:20:18 +00:00
|
|
|
--writeJsonSummaryPath $JSON_DIR/identical-pixels.json
|
2013-01-18 19:19:47 +00:00
|
|
|
|
2013-05-21 15:41:35 +00:00
|
|
|
THIS_IMAGE_DIR=$IMAGES_DIR/different-pixels
|
|
|
|
mkdir -p $THIS_IMAGE_DIR
|
|
|
|
$GM_BINARY --hierarchy --match selftest2 $CONFIGS -w $THIS_IMAGE_DIR
|
|
|
|
mv $THIS_IMAGE_DIR/8888/selftest2.png $THIS_IMAGE_DIR/8888/selftest1.png
|
|
|
|
mv $THIS_IMAGE_DIR/565/selftest2.png $THIS_IMAGE_DIR/565/selftest1.png
|
|
|
|
$GM_BINARY --hierarchy --match selftest1 $CONFIGS -r $THIS_IMAGE_DIR \
|
2013-03-20 14:20:18 +00:00
|
|
|
--writeJsonSummaryPath $JSON_DIR/different-pixels.json
|
2013-01-18 19:19:47 +00:00
|
|
|
|
2013-08-30 20:19:25 +00:00
|
|
|
# Create another JSON expectations file which is identical to
|
|
|
|
# different-pixels.json, but in which the *first* ignore-failure is changed
|
|
|
|
# from false to true.
|
|
|
|
OLD='"ignore-failure" : false'
|
|
|
|
NEW='"ignore-failure" : true'
|
|
|
|
sed -e "0,/$OLD/{s/$OLD/$NEW/}" $JSON_DIR/different-pixels.json \
|
|
|
|
>$JSON_DIR/different-pixels-ignore-some-failures.json
|
|
|
|
|
2013-05-21 15:41:35 +00:00
|
|
|
THIS_IMAGE_DIR=$IMAGES_DIR/different-pixels-no-hierarchy
|
|
|
|
mkdir -p $THIS_IMAGE_DIR
|
|
|
|
$GM_BINARY --match selftest2 $CONFIGS -w $THIS_IMAGE_DIR
|
|
|
|
mv $THIS_IMAGE_DIR/selftest2_8888.png $THIS_IMAGE_DIR/selftest1_8888.png
|
|
|
|
mv $THIS_IMAGE_DIR/selftest2_565.png $THIS_IMAGE_DIR/selftest1_565.png
|
|
|
|
$GM_BINARY --match selftest1 $CONFIGS -r $THIS_IMAGE_DIR \
|
|
|
|
--writeJsonSummaryPath $JSON_DIR/different-pixels-no-hierarchy.json
|
|
|
|
|
2013-02-06 18:41:04 +00:00
|
|
|
mkdir -p $IMAGES_DIR/empty-dir
|
2013-01-18 19:19:47 +00:00
|
|
|
}
|
|
|
|
|
2012-11-12 18:04:51 +00:00
|
|
|
GM_TESTDIR=gm/tests
|
|
|
|
GM_INPUTS=$GM_TESTDIR/inputs
|
|
|
|
GM_OUTPUTS=$GM_TESTDIR/outputs
|
2013-01-19 04:21:27 +00:00
|
|
|
GM_TEMPFILES=$GM_TESTDIR/tempfiles
|
2012-11-12 18:04:51 +00:00
|
|
|
|
2013-01-18 19:19:47 +00:00
|
|
|
create_inputs_dir $GM_INPUTS
|
|
|
|
|
2012-11-28 20:08:32 +00:00
|
|
|
# Compare generated image against an input image file with identical bytes.
|
2013-04-10 15:24:53 +00:00
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/identical-bytes" "$GM_OUTPUTS/compared-against-identical-bytes-images"
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-bytes.json" "$GM_OUTPUTS/compared-against-identical-bytes-json"
|
2012-11-12 18:04:51 +00:00
|
|
|
|
2012-11-28 20:08:32 +00:00
|
|
|
# Compare generated image against an input image file with identical pixels but different PNG encoding.
|
2013-04-10 15:24:53 +00:00
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/identical-pixels" "$GM_OUTPUTS/compared-against-identical-pixels-images"
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-pixels.json" "$GM_OUTPUTS/compared-against-identical-pixels-json"
|
2012-11-28 20:08:32 +00:00
|
|
|
|
|
|
|
# Compare generated image against an input image file with different pixels.
|
2013-04-10 15:24:53 +00:00
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/different-pixels" "$GM_OUTPUTS/compared-against-different-pixels-images"
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels.json" "$GM_OUTPUTS/compared-against-different-pixels-json"
|
2012-11-12 18:04:51 +00:00
|
|
|
|
2013-10-18 14:55:47 +00:00
|
|
|
# Exercise --ignoreFailuresFile flag.
|
|
|
|
FAILURES_FILE="$GM_INPUTS/ignoreFailureFile"
|
|
|
|
echo "# Comment line" >$FAILURES_FILE
|
|
|
|
echo "" >>$FAILURES_FILE
|
|
|
|
echo "8888/selfte" >>$FAILURES_FILE
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 --ignoreFailuresFile $FAILURES_FILE $CONFIGS -r $GM_INPUTS/json/different-pixels.json" "$GM_OUTPUTS/ignoring-one-test"
|
2013-09-19 06:18:27 +00:00
|
|
|
|
2013-08-30 20:19:25 +00:00
|
|
|
# Compare different pixels, but with a SUBSET of the expectations marked as
|
|
|
|
# ignore-failure.
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels-ignore-some-failures.json" "$GM_OUTPUTS/ignoring-some-failures"
|
|
|
|
|
2012-12-18 19:13:49 +00:00
|
|
|
# Compare generated image against an empty "expected image" dir.
|
2013-10-10 17:24:20 +00:00
|
|
|
# Even the tests that have been marked as ignore-failure should show up as
|
|
|
|
# no-comparison.
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 --ignoreTests 8888 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/compared-against-empty-dir"
|
2013-04-10 15:24:53 +00:00
|
|
|
|
2013-04-12 19:05:57 +00:00
|
|
|
# Compare generated image against a nonexistent "expected image" dir.
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS -r ../path/to/nowhere" "$GM_OUTPUTS/compared-against-nonexistent-dir"
|
|
|
|
|
2013-04-10 15:24:53 +00:00
|
|
|
# Compare generated image against an empty "expected image" dir, but NOT in verbose mode.
|
|
|
|
gm_test "--hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/images/empty-dir" "$GM_OUTPUTS/nonverbose"
|
2012-12-18 19:13:49 +00:00
|
|
|
|
2013-07-08 19:13:33 +00:00
|
|
|
# Add pdf to the list of configs.
|
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS pdf -r $GM_INPUTS/json/identical-bytes.json" "$GM_OUTPUTS/add-config-pdf"
|
|
|
|
|
2013-08-30 20:19:25 +00:00
|
|
|
# Test what happens if run without -r (no expected-results.json to compare
|
|
|
|
# against).
|
2013-04-10 15:24:53 +00:00
|
|
|
gm_test "--verbose --hierarchy --match selftest1 $CONFIGS" "$GM_OUTPUTS/no-readpath"
|
2012-12-20 18:34:29 +00:00
|
|
|
|
2013-04-04 19:23:11 +00:00
|
|
|
# Test what happens if a subset of the renderModes fail (e.g. pipe)
|
2013-09-30 07:01:55 +00:00
|
|
|
gm_test "--pipe --simulatePipePlaybackFailure --verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/identical-pixels.json" "$GM_OUTPUTS/pipe-playback-failure"
|
2013-04-04 19:23:11 +00:00
|
|
|
|
2013-04-10 12:17:34 +00:00
|
|
|
# Confirm that IntentionallySkipped tests are recorded as such.
|
2013-04-10 15:24:53 +00:00
|
|
|
gm_test "--verbose --hierarchy --match selftest1 selftest2 $CONFIGS" "$GM_OUTPUTS/intentionally-skipped-tests"
|
2013-04-10 12:17:34 +00:00
|
|
|
|
2013-04-12 14:11:21 +00:00
|
|
|
# Ignore some error types (including ExpectationsMismatch)
|
|
|
|
gm_test "--ignoreErrorTypes ExpectationsMismatch NoGpuContext --verbose --hierarchy --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels.json" "$GM_OUTPUTS/ignore-expectations-mismatch"
|
|
|
|
|
2013-05-21 15:41:35 +00:00
|
|
|
# Test non-hierarchical mode.
|
|
|
|
gm_test "--verbose --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels-no-hierarchy.json" "$GM_OUTPUTS/no-hierarchy"
|
|
|
|
|
2013-06-19 18:28:31 +00:00
|
|
|
# Try writing out actual images using checksum-based filenames, like we do when
|
|
|
|
# uploading to Google Storage.
|
|
|
|
gm_test "--verbose --writeChecksumBasedFilenames --match selftest1 $CONFIGS -r $GM_INPUTS/json/different-pixels-no-hierarchy.json" "$GM_OUTPUTS/checksum-based-filenames"
|
|
|
|
|
2013-05-21 16:06:40 +00:00
|
|
|
# Exercise display_json_results.py
|
2013-05-14 18:58:12 +00:00
|
|
|
PASSING_CASES="compared-against-identical-bytes-json compared-against-identical-pixels-json"
|
|
|
|
FAILING_CASES="compared-against-different-pixels-json"
|
|
|
|
for CASE in $PASSING_CASES; do
|
2013-05-21 16:06:40 +00:00
|
|
|
assert_passes "python gm/display_json_results.py $GM_OUTPUTS/$CASE/$OUTPUT_EXPECTED_SUBDIR/json-summary.txt"
|
2013-05-14 18:58:12 +00:00
|
|
|
done
|
|
|
|
for CASE in $FAILING_CASES; do
|
2013-05-21 16:06:40 +00:00
|
|
|
assert_fails "python gm/display_json_results.py $GM_OUTPUTS/$CASE/$OUTPUT_EXPECTED_SUBDIR/json-summary.txt"
|
2013-05-14 18:58:12 +00:00
|
|
|
done
|
|
|
|
|
2013-04-26 17:45:06 +00:00
|
|
|
if [ $ENCOUNTERED_ANY_ERRORS == 0 ]; then
|
|
|
|
echo "All tests passed."
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|