blob: 69f96c980f92ebde47d57d382c713e2eedcb84cc [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=''
halcanaryd1556072016-04-27 07:44:03 -070022for CMD in 'python' 'ninja' 'pdfium_test' 'skdiff'; do
halcanarydc09f132016-04-26 12:43:59 -070023 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
halcanaryd1556072016-04-27 07:44:03 -070072# Portable version of timeout from GNU coreutils.
73timeout_py() { python -c "$(cat <<EOF
74import sys, subprocess, threading
75proc = subprocess.Popen(sys.argv[2:])
76timer = threading.Timer(float(sys.argv[1]), proc.terminate)
77timer.start()
78proc.wait()
79timer.cancel()
80exit(proc.returncode)
81EOF
82)" "$@"; }
83
halcanarydc09f132016-04-26 12:43:59 -070084# rasterize the remaining PDFs
85for pdf in "$CON_DIR"/*pdf "$EXP_DIR"/*pdf ; do
halcanaryd1556072016-04-27 07:44:03 -070086 if timeout_py 10 pdfium_test --png "$pdf"; then
87 if ! [ -f "$pdf".*.png ] ; then
88 echo "Missing pdfium_test output: '$pdf.*.png'" >&2
89 exit 1
90 fi
halcanarydc09f132016-04-26 12:43:59 -070091 rm "$pdf"
92 else
93 echo "pdfium_test '$pdf' failed."
94 fi
95done
96
97DIFFS=''
98# remove byte-identical PNGs:
99for con in "$CON_DIR"/*.png; do
100 exp="$EXP_DIR/$(basename "$con")"
101 if diff "$con" "$exp"; then
102 rm "$exp" "$con"
103 else
104 echo "PNG differs: $(basename "$con")"
105 DIFFS=1
106 fi
107done
108if [ -z "$DIFFS" ]; then
109 echo 'All PNGs are byte-identical!'
110 rm -r "$DIR"
111 exit 0;
112fi
113
114# run remaining PNG files through skdiff:
115DIFF_DIR="${DIR}/skdiffout"
116skdiff "$CON_DIR" "$EXP_DIR" "$DIFF_DIR"
117echo "'$DIFF_DIR/index.html'"
118
119if [ $(uname) = 'Darwin' ] ; then
120 open "$DIFF_DIR/index.html" # look at diffs
121elif [ $(uname) = 'Linux' ] ; then
122 xdg-open "$DIFF_DIR/index.html" # look at diffs
123fi