81ef81b356bc8ef72ac351b075a8e0e5f85f89ba
[platform/core/graphics/cairo.git] / test / check-refs.sh
1 #!/bin/bash
2
3 cd $(dirname $0)/reference || exit
4
5 pdiff=$1
6 [ -n "$pdiff" ] || pdiff=../pdiff/perceptualdiff
7 if [ ! -e "${pdiff}" ]; then
8     echo "Error:  requires pdiff executable"
9     exit 128
10 fi
11
12 for file in *.ref.png; do
13     test=$(echo $file | cut -d'.' -f1)
14     target=$(echo $file | cut -d'.' -f2)
15     format=$(echo $file | cut -d'.' -f3)
16     notes=""
17     ref=""
18     result=""
19
20     if [ $target = 'base' ]; then
21         # Ignore the base images for this script's purposes
22         continue
23     elif [ $target = 'ref' ]; then
24         # This is actually the baseline reference image
25         continue
26     elif [ $format = 'ref' ]; then
27         # This is either a format-specific reference, or a target-specific/format-generic image
28         # In either case, compare it against the generic reference image
29         ref="$test.ref.png"
30     else
31         # Prefer the target-specific/format-generic reference image, if available
32         ref="$test.$target.ref.png"
33         if [ ! -e $ref ]; then
34             ref="$test.$format.ref.png"
35         fi
36     fi
37
38     # Special cases
39     if [ $test = "create-from-png" ]; then
40         # The create-from-png test utilizes multiple reference images directly
41         continue
42     elif [ $test = "fallback-resolution" ]; then
43         # The fallback-resolution test generates a set of reference images;
44         # These won't be redundant with one another, but just ignore them all.
45         continue
46     fi
47
48     if [ -e $ref ]; then
49         if cmp --silent "$ref" "$file" ; then
50             printf "redundant: %s and %s are byte-by-byte identical files\n" $file $ref
51         else
52             # Run perceptualdiff with minimum threshold
53             pdiff_output=$($pdiff $ref $file -threshold 1)
54             result=${pdiff_output%:*}
55             notes=$(echo "${pdiff_output#*: }" | tail -n 1)
56             if [ "$result" = "PASS" ] && [ "$notes" = "Images are binary identical" ]; then
57                 printf "redundant: %s and %s are pixel equivalent images\n" $file $ref
58                 notes=""
59             fi
60         fi
61     fi
62
63 done