aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/PdfViewer/scripts/test_all_pdfs.sh
blob: 924c531bca5d35dfbd3696dc206965c9df7c3c5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

# Copyright 2013 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if [ "${1}" == '-h' ] || [ "${1}" == '--help' ]
then
echo 'test_all_pdfs.sh
Usage: Run from the trunk directory of a Skia tree to convert a folder of PDFs into PNGs.
       Many threads will be run simultaneously using the "parallel" tool if that tool is
       installed. "parallel" can be installed on linux using "sudo apt-get install parallel."
       Requires that skdiff and pdfviewer have already been built.

Arguments:
    folder      Folder containing PDF files. The PNG results will be placed in "folder/new".
                If folder contains a folder named "old", the PNGs in "folder/new" will be
                compared to PNGs in "folder/old" with the same name, and the differences
                will be stored in a "folder/d".'
exit
fi

# Early exit if pdfviewer has not been built.
# TODO (scroggo): Use release version if debug is unavailable
if [ ! -f out/Debug/pdfviewer ]
then
    echo 'debug version of pdfviewer is required.'
    exit
fi

if [ -z $1 ]
then
    echo 'folder is a required argument.'
    exit
fi

if [ ! -d $1 ]
then
    echo 'folder must be a valid directory.'
    exit
fi

# Create the directory to contain the new results. If old new results exist, remove them.
if [ -d $1/new ]
then
    rm -rf $1/new
fi

mkdir $1/new/

# Run the script to read each PDF and convert it to a PNG.
if command -v parallel >/dev/null 2>&1
then
    echo 'Running in parallel'
    ls -1 $1/*.pdf | sed "s/^/experimental\/PdfViewer\/scripts\/vm_pdf_viewer_run_one_pdf.sh /" \
        | parallel
else
    echo 'Converting each file sequentially. Install "parallel" to convert in parallel.'
    echo '"parallel" can be installed on linux with "sudo apt-get install parallel".'
    ls -1 $1/*.pdf | xargs experimental/PdfViewer/scripts/vm_pdf_viewer_run_one_pdf.sh
fi

# Next, compare to the old results. Exit now if there is no folder with old results.
if [ ! -d $1/old ]
then
    exit
fi

# Check to make sure that skdiff has been built.
RELEASE_SKDIFF=out/Release/skdiff
DEBUG_SKDIFF=out/Debug/skdiff
if [ -f $RELEASE_SKDIFF ]
then
    SKDIFF=$RELEASE_SKDIFF
elif [ -f $DEBUG_SKDIFF ]
then
    SKDIFF=$DEBUG_SKDIFF
else
    echo 'Build skdiff in order to do comparisons.'
    exit
fi

# Create the diff folder, after deleting old diffs if necessary.
if [ -d $1/d ]
then
    rm -rf $1/d
fi

mkdir $1/d

$SKDIFF $1/old $1/new $1/d