halcanary | dc09f13 | 2016-04-26 12:43:59 -0700 | [diff] [blame] | 1 | #!/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 | |
| 10 | CONTROL_COMMIT="$1" |
| 11 | EXPERIMENT_COMMIT="$2" |
| 12 | |
| 13 | SOURCE="${3:-gm}" # could be 'skp' |
| 14 | |
| 15 | if ! [ "$1" ] || ! [ "$2" ]; then |
| 16 | echo "usage:" >&2 |
| 17 | echo " $0 CONTROL_COMMIT EXPERIMENT_COMMIT [SOURCE]" >&2 |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | BAD='' |
halcanary | d155607 | 2016-04-27 07:44:03 -0700 | [diff] [blame] | 22 | for CMD in 'python' 'ninja' 'pdfium_test' 'skdiff'; do |
halcanary | dc09f13 | 2016-04-26 12:43:59 -0700 | [diff] [blame] | 23 | if ! command -v "$CMD" > /dev/null ; then |
| 24 | echo "could not find $CMD command in PATH." >&2 |
| 25 | BAD=1 |
| 26 | fi |
| 27 | done |
| 28 | if [ "$BAD" ]; then exit 1; fi |
| 29 | |
| 30 | cd "$(dirname "$0")/.." |
| 31 | if [ "$(git diff --shortstat)" ]; then |
| 32 | echo "please stash your changes" >&2 |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | DIR=$(mktemp -d "${TMPDIR:-/tmp}/skpdf.XXXXXXXXXX") |
| 37 | EXP="${DIR}/exp" |
| 38 | CON="${DIR}/con" |
| 39 | |
| 40 | set -e |
| 41 | |
| 42 | git checkout "$EXPERIMENT_COMMIT" |
| 43 | python bin/sync-and-gyp && ninja -C out/Release dm |
| 44 | out/Release/dm --src "$SOURCE" --config pdf -w "$EXP" |
| 45 | |
| 46 | git checkout "$CONTROL_COMMIT" |
| 47 | python bin/sync-and-gyp && ninja -C out/Release dm |
| 48 | out/Release/dm --src "$SOURCE" --config pdf -w "$CON" |
| 49 | |
| 50 | set +e |
| 51 | |
| 52 | EXP_DIR="${EXP}/pdf/${SOURCE}" |
| 53 | CON_DIR="${CON}/pdf/${SOURCE}" |
| 54 | |
| 55 | DIFFS='' |
| 56 | # remove byte-identical PDFs |
| 57 | for 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 |
| 65 | done |
| 66 | if [ -z "$DIFFS" ]; then |
| 67 | echo 'All PDFs are byte-identical!' |
| 68 | rm -r "$DIR" |
| 69 | exit 0; |
| 70 | fi |
| 71 | |
halcanary | d155607 | 2016-04-27 07:44:03 -0700 | [diff] [blame] | 72 | # Portable version of timeout from GNU coreutils. |
| 73 | timeout_py() { python -c "$(cat <<EOF |
| 74 | import sys, subprocess, threading |
| 75 | proc = subprocess.Popen(sys.argv[2:]) |
| 76 | timer = threading.Timer(float(sys.argv[1]), proc.terminate) |
| 77 | timer.start() |
| 78 | proc.wait() |
| 79 | timer.cancel() |
| 80 | exit(proc.returncode) |
| 81 | EOF |
| 82 | )" "$@"; } |
| 83 | |
halcanary | dc09f13 | 2016-04-26 12:43:59 -0700 | [diff] [blame] | 84 | # rasterize the remaining PDFs |
| 85 | for pdf in "$CON_DIR"/*pdf "$EXP_DIR"/*pdf ; do |
halcanary | d155607 | 2016-04-27 07:44:03 -0700 | [diff] [blame] | 86 | 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 |
halcanary | dc09f13 | 2016-04-26 12:43:59 -0700 | [diff] [blame] | 91 | rm "$pdf" |
| 92 | else |
| 93 | echo "pdfium_test '$pdf' failed." |
| 94 | fi |
| 95 | done |
| 96 | |
| 97 | DIFFS='' |
| 98 | # remove byte-identical PNGs: |
| 99 | for 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 |
| 107 | done |
| 108 | if [ -z "$DIFFS" ]; then |
| 109 | echo 'All PNGs are byte-identical!' |
| 110 | rm -r "$DIR" |
| 111 | exit 0; |
| 112 | fi |
| 113 | |
| 114 | # run remaining PNG files through skdiff: |
| 115 | DIFF_DIR="${DIR}/skdiffout" |
| 116 | skdiff "$CON_DIR" "$EXP_DIR" "$DIFF_DIR" |
| 117 | echo "'$DIFF_DIR/index.html'" |
| 118 | |
| 119 | if [ $(uname) = 'Darwin' ] ; then |
| 120 | open "$DIFF_DIR/index.html" # look at diffs |
| 121 | elif [ $(uname) = 'Linux' ] ; then |
| 122 | xdg-open "$DIFF_DIR/index.html" # look at diffs |
| 123 | fi |