summaryrefslogtreecommitdiff
path: root/src/cups/test-ppds.in
blob: 3664f4e8580bbdc933d7a9a5029389d4f1c14e64 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!@BASHREAL@

# Test PPD conformance
#
# Copyright 2006-2017 Robert Krawitz (rlk@alum.mit.edu)
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

################################################################
#                 TEST FOR PPD FILE COMPLIANCE
#
# Keeping this up to date with changing CUPS versions is a real headache.
# This test, however, is particularly important; PPD conformance failures
# are one of the most frequently observed problems, and a lot of apps
# (and CUPS itself) are very sensitive -- arguably overly so -- to
# violations of the spec.
#
# We can't skip the translated PPD files either; sometimes translations
# blow out token maximum lengths.

if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then
    redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log"
    if [[ -n $BUILD_VERBOSE ]] ; then
	exec > >(tee -a "$redir" >&3)
    else
	exec 1>>"$redir"
    fi
    exec 2>&1
fi

[[ -n "$STP_TEST_DEBUG" ]] && DEBUG=echo

[[ -z $STP_TEST_SUITE || -z $STP_TEST_PROFILE ]] && STP_TEST_PROFILE=full

PPD_DIR=ppdtest

PPD_PARALLEL=200

function test_full() {
    rm -rf "$PPD_DIR"
    echo "GENERATING PPD FILES (all):"
    set -e
    $DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS='-b -Z' ppd-clean ppd-global-a ppd-nls-a ppd-nonls-a
}

function test_fast() {
    rm -rf "$PPD_DIR"
    echo "GENERATING PPD FILES (fast):"
    set -e
    $DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS='-b -Z' ppd-clean ppd-nonls
    if [[ -n $STP_TEST_DIST ]] ; then
	echo "GENERATING PPD FILES (global):"
	set -e
	$DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS='-b -Z -S' ppd-global
    fi
    PPD_PARALLEL=20
}

function test_minimal() {
    rm -rf "$PPD_DIR"
    echo "GENERATING PPD FILES (minimal):"
    set -e
    $DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS='-b -Z -S' ppd-clean ppd-nonls
    PPD_PARALLEL=20
}

case "$STP_TEST_PROFILE" in
    full|fast|minimal)
	test_$STP_TEST_PROFILE
	;;
    *)
	exit 77
esac

if [[ -n "$STP_TEST_DEBUG" ]] ; then
    echo "Would run $0 $@"
    exit 0
fi

ppd_count=$(find "$PPD_DIR" -name '*.ppd' -print | wc -l)

# Setting a limit on the number of files per invocation improves
# performance by about a minute by reducing the tail at the end.
[[ -n $STP_PARALLEL ]] && PARALLEL="-P $STP_PARALLEL -L $PPD_PARALLEL"

# Most non-Macintosh systems won't have the Macintosh-specific profiles
# installed in Macintosh-specific locations.
#
# Also, a number of our media sizes aren't named correctly, but we'll
# accept those issues rather than cluttering the namespace further and/or
# changing tag names.
cupstestppdopts='-I profiles -W sizes -I filters'

# This lets us report progress
testcmd="echo -n . 1>&2; cupstestppd $cupstestppdopts "'"$@"'

echo -n "TESTING PPD FILES: "
failures="$(find $PPD_DIR -name '*.ppd*' -print | sort -t/ -k3 -k2 | xargs $PARALLEL sh -c "$testcmd" |grep 'FAIL$' | awk -F: '{print $1}')"

if [[ -z "$failures" ]] ; then
    echo "All $ppd_count PPD files pass"
    rm -rf $PPD_DIR
    exit 0
fi

# Use this with "normal" PPD files without translated numbers.
#echo $failures | xargs cupstestppd $cupstestppdopts 2>&1 | egrep -v 'Missing "[a-z][a-z](_[A-Z][A-Z])?" translation string for option Stp((Brightness|Contrast|Saturation), choice None|([a-zA-Z0-9]+, choice (-?[0-9]+)))!$' |egrep -v 'Missing cupsICCProfile file'

# Use this with PPD files with translated numbers (genppd -N)
# With normal globalized PPD files this will yield hundreds of megabytes
# of errors.
echo $failures | xargs cupstestppd -r $cupstestppdopts 2>&1

fail_count=`echo "$failures" | wc -l`
echo "$fail_count/$ppd_count fail"
exit 1