cairo/test/check-refs.sh
Bryce W. Harrington 8d3c518e9d test: Use cmp to catch byte-by-byte identical files
cmp runs faster than perceptualdiff, and catches files that are exact
copies of the reference image.  We still use perceptualdiff for catching
files that aren't bytewise identical, but are still identical at the
pixel level.

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
2013-07-04 09:04:17 +01:00

64 lines
1.8 KiB
Bash
Executable file

#!/bin/bash
current_dir=$(pwd)
# Move to the reference directory as needed
if [ $(basename $current_dir) != 'test' ]; then
if [ -d test ]; then
cd test || exit 1
fi
fi
if [ $(basename $current_dir) != 'reference' ]; then
if [ -d reference ]; then
cd reference || exit 2
fi
fi
pdiff=../pdiff/perceptualdiff
if [ ! -e "${pdiff}" ]; then
echo "Error: requires ${pdiff} executable"
exit 3
fi
for file in *.ref.png; do
test=$(echo $file | cut -d'.' -f1)
target=$(echo $file | cut -d'.' -f2)
format=$(echo $file | cut -d'.' -f3)
notes=""
ref=""
result=""
if [ $target = 'base' ]; then
# Ignore the base images for this script's purposes
continue
elif [ $target = 'ref' ]; then
# This is actually the baseline reference image
continue
elif [ $format = 'ref' ]; then
# This is either a format-specific reference, or a target-specific/format-generic image
# In either case, compare it against the generic reference image
ref="$test.ref.png"
else
# Prefer the target-specific/format-generic reference image, if available
ref="$test.$target.ref.png"
if [ ! -e $ref ]; then
ref="$test.$format.ref.png"
fi
fi
if [ -e $ref ]; then
if cmp --silent "$ref" "$file" ; then
printf "redundant: %s and %s are byte-by-byte identical files\n" $file $ref
else
# Run perceptualdiff with minimum threshold
pdiff_output=$($pdiff $ref $file -threshold 1)
result=${pdiff_output%:*}
notes=$(echo "${pdiff_output#*: }" | tail -n 1)
if [ "$result" = "PASS" ] && [ "$notes" = "Images are binary identical" ]; then
printf "redundant: %s and %s are pixel equivalent images\n" $file $ref
notes=""
fi
fi
fi
done