aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/pdf-comparison.sh
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-04-26 12:43:59 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-26 12:43:59 -0700
commitdc09f131d404481da0f64ca1684aff666baf0fdb (patch)
treec6adfde467c9590285f21f71f27131b2067a7a2e /tools/pdf-comparison.sh
parente6e2e5403692c3f2e5411f1e2dbcd9b309869fc3 (diff)
pdf comparison tool
Diffstat (limited to 'tools/pdf-comparison.sh')
-rwxr-xr-xtools/pdf-comparison.sh108
1 files changed, 108 insertions, 0 deletions
diff --git a/tools/pdf-comparison.sh b/tools/pdf-comparison.sh
new file mode 100755
index 0000000000..d4036a418c
--- /dev/null
+++ b/tools/pdf-comparison.sh
@@ -0,0 +1,108 @@
+#!/bin/sh
+
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This tool compares the PDF output of Skia's DM tool of two commits.
+
+CONTROL_COMMIT="$1"
+EXPERIMENT_COMMIT="$2"
+
+SOURCE="${3:-gm}" # could be 'skp'
+
+if ! [ "$1" ] || ! [ "$2" ]; then
+ echo "usage:" >&2
+ echo " $0 CONTROL_COMMIT EXPERIMENT_COMMIT [SOURCE]" >&2
+ exit 1
+fi
+
+BAD=''
+for CMD in 'python' 'ninja' 'pdfium_test' 'timeout' 'skdiff'; do
+ if ! command -v "$CMD" > /dev/null ; then
+ echo "could not find $CMD command in PATH." >&2
+ BAD=1
+ fi
+done
+if [ "$BAD" ]; then exit 1; fi
+
+cd "$(dirname "$0")/.."
+if [ "$(git diff --shortstat)" ]; then
+ echo "please stash your changes" >&2
+ exit 1
+fi
+
+DIR=$(mktemp -d "${TMPDIR:-/tmp}/skpdf.XXXXXXXXXX")
+EXP="${DIR}/exp"
+CON="${DIR}/con"
+
+set -e
+
+git checkout "$EXPERIMENT_COMMIT"
+python bin/sync-and-gyp && ninja -C out/Release dm
+out/Release/dm --src "$SOURCE" --config pdf -w "$EXP"
+
+git checkout "$CONTROL_COMMIT"
+python bin/sync-and-gyp && ninja -C out/Release dm
+out/Release/dm --src "$SOURCE" --config pdf -w "$CON"
+
+set +e
+
+EXP_DIR="${EXP}/pdf/${SOURCE}"
+CON_DIR="${CON}/pdf/${SOURCE}"
+
+DIFFS=''
+# remove byte-identical PDFs
+for con in "$CON_DIR"/*pdf; do
+ exp="$EXP_DIR/$(basename "$con")"
+ if diff "$con" "$exp" > /dev/null; then
+ rm "$con" "$exp" # no difference
+ else
+ echo "PDF differs: $(basename "$con")"
+ DIFFS=1
+ fi
+done
+if [ -z "$DIFFS" ]; then
+ echo 'All PDFs are byte-identical!'
+ rm -r "$DIR"
+ exit 0;
+fi
+
+# rasterize the remaining PDFs
+for pdf in "$CON_DIR"/*pdf "$EXP_DIR"/*pdf ; do
+ # timeout is from GNU coreutils
+ if timeout 10 pdfium_test --png "$pdf"; then
+ rm "$pdf"
+ else
+ echo "pdfium_test '$pdf' failed."
+ fi
+done
+
+DIFFS=''
+# remove byte-identical PNGs:
+for con in "$CON_DIR"/*.png; do
+ exp="$EXP_DIR/$(basename "$con")"
+ if diff "$con" "$exp"; then
+ rm "$exp" "$con"
+ else
+ echo "PNG differs: $(basename "$con")"
+ DIFFS=1
+ fi
+done
+if [ -z "$DIFFS" ]; then
+ echo 'All PNGs are byte-identical!'
+ rm -r "$DIR"
+ exit 0;
+fi
+
+# run remaining PNG files through skdiff:
+DIFF_DIR="${DIR}/skdiffout"
+skdiff "$CON_DIR" "$EXP_DIR" "$DIFF_DIR"
+echo "'$DIFF_DIR/index.html'"
+
+if [ $(uname) = 'Darwin' ] ; then
+ open "$DIFF_DIR/index.html" # look at diffs
+elif [ $(uname) = 'Linux' ] ; then
+ xdg-open "$DIFF_DIR/index.html" # look at diffs
+fi