blob: d4036a418c8c5f89d818b15d1717dbd3a8f007c3 [file] [log] [blame]
halcanarydc09f132016-04-26 12:43:59 -07001#!/bin/sh
2
3# Copyright 2016 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8# This tool compares the PDF output of Skia's DM tool of two commits.
9
10CONTROL_COMMIT="$1"
11EXPERIMENT_COMMIT="$2"
12
13SOURCE="${3:-gm}" # could be 'skp'
14
15if ! [ "$1" ] || ! [ "$2" ]; then
16 echo "usage:" >&2
17 echo " $0 CONTROL_COMMIT EXPERIMENT_COMMIT [SOURCE]" >&2
18 exit 1
19fi
20
21BAD=''
22for CMD in 'python' 'ninja' 'pdfium_test' 'timeout' 'skdiff'; do
23 if ! command -v "$CMD" > /dev/null ; then
24 echo "could not find $CMD command in PATH." >&2
25 BAD=1
26 fi
27done
28if [ "$BAD" ]; then exit 1; fi
29
30cd "$(dirname "$0")/.."
31if [ "$(git diff --shortstat)" ]; then
32 echo "please stash your changes" >&2
33 exit 1
34fi
35
36DIR=$(mktemp -d "${TMPDIR:-/tmp}/skpdf.XXXXXXXXXX")
37EXP="${DIR}/exp"
38CON="${DIR}/con"
39
40set -e
41
42git checkout "$EXPERIMENT_COMMIT"
43python bin/sync-and-gyp && ninja -C out/Release dm
44out/Release/dm --src "$SOURCE" --config pdf -w "$EXP"
45
46git checkout "$CONTROL_COMMIT"
47python bin/sync-and-gyp && ninja -C out/Release dm
48out/Release/dm --src "$SOURCE" --config pdf -w "$CON"
49
50set +e
51
52EXP_DIR="${EXP}/pdf/${SOURCE}"
53CON_DIR="${CON}/pdf/${SOURCE}"
54
55DIFFS=''
56# remove byte-identical PDFs
57for con in "$CON_DIR"/*pdf; do
58 exp="$EXP_DIR/$(basename "$con")"
59 if diff "$con" "$exp" > /dev/null; then
60 rm "$con" "$exp" # no difference
61 else
62 echo "PDF differs: $(basename "$con")"
63 DIFFS=1
64 fi
65done
66if [ -z "$DIFFS" ]; then
67 echo 'All PDFs are byte-identical!'
68 rm -r "$DIR"
69 exit 0;
70fi
71
72# rasterize the remaining PDFs
73for pdf in "$CON_DIR"/*pdf "$EXP_DIR"/*pdf ; do
74 # timeout is from GNU coreutils
75 if timeout 10 pdfium_test --png "$pdf"; then
76 rm "$pdf"
77 else
78 echo "pdfium_test '$pdf' failed."
79 fi
80done
81
82DIFFS=''
83# remove byte-identical PNGs:
84for con in "$CON_DIR"/*.png; do
85 exp="$EXP_DIR/$(basename "$con")"
86 if diff "$con" "$exp"; then
87 rm "$exp" "$con"
88 else
89 echo "PNG differs: $(basename "$con")"
90 DIFFS=1
91 fi
92done
93if [ -z "$DIFFS" ]; then
94 echo 'All PNGs are byte-identical!'
95 rm -r "$DIR"
96 exit 0;
97fi
98
99# run remaining PNG files through skdiff:
100DIFF_DIR="${DIR}/skdiffout"
101skdiff "$CON_DIR" "$EXP_DIR" "$DIFF_DIR"
102echo "'$DIFF_DIR/index.html'"
103
104if [ $(uname) = 'Darwin' ] ; then
105 open "$DIFF_DIR/index.html" # look at diffs
106elif [ $(uname) = 'Linux' ] ; then
107 xdg-open "$DIFF_DIR/index.html" # look at diffs
108fi