| 1 |
#!@BASHREAL@ |
| 2 |
|
| 3 |
# Test PPD conformance |
| 4 |
# |
| 5 |
# Copyright 2006-2017 Robert Krawitz ([email protected]) |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by the Free |
| 9 |
# Software Foundation; either version 2 of the License, or (at your option) |
| 10 |
# any later version. |
| 11 |
# |
| 12 |
# This program is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
# for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
################################################################ |
| 21 |
# TEST FOR PPD FILE COMPLIANCE |
| 22 |
# |
| 23 |
# Keeping this up to date with changing CUPS versions is a real headache. |
| 24 |
# This test, however, is particularly important; PPD conformance failures |
| 25 |
# are one of the most frequently observed problems, and a lot of apps |
| 26 |
# (and CUPS itself) are very sensitive -- arguably overly so -- to |
| 27 |
# violations of the spec. |
| 28 |
# |
| 29 |
# We can't skip the translated PPD files either; sometimes translations |
| 30 |
# blow out token maximum lengths. |
| 31 |
|
| 32 |
if [[ -n "$STP_TEST_LOG_PREFIX" ]] ; then |
| 33 |
redir="${STP_TEST_LOG_PREFIX}${0##*/}_$$.log" |
| 34 |
if [[ -n $BUILD_VERBOSE ]] ; then |
| 35 |
exec > >(tee -a "$redir" >&3) |
| 36 |
else |
| 37 |
exec 1>>"$redir" |
| 38 |
fi |
| 39 |
exec 2>&1 |
| 40 |
fi |
| 41 |
|
| 42 |
DEBUG=${STP_TEST_DEBUG:+echo} |
| 43 |
|
| 44 |
[[ -z $STP_TEST_SUITE || -z $STP_TEST_PROFILE ]] && STP_TEST_PROFILE=full |
| 45 |
|
| 46 |
[[ -n $STP_TEST_COMPONENTS && $STP_TEST_COMPONENTS != '*CUPS*' && $STP_TEST_COMPONENTS != '*test-ppds*' ]] && exit 77 |
| 47 |
|
| 48 |
PPD_DIR=ppdtest |
| 49 |
|
| 50 |
PPD_PARALLEL=200 |
| 51 |
|
| 52 |
echo '****************************************************************' |
| 53 |
|
| 54 |
rotor="-R ${STP_TEST_ROTOR_CIRCUMFERENCE:-1} -r ${STP_TEST_ROTOR:-0}" |
| 55 |
|
| 56 |
function test_full() { |
| 57 |
rm -rf "$PPD_DIR" |
| 58 |
echo "GENERATING PPD FILES (all):" |
| 59 |
$DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z" ppd-clean ppd-global-a ppd-nls-a ppd-nonls-a |
| 60 |
} |
| 61 |
|
| 62 |
function test_fast() { |
| 63 |
rm -rf "$PPD_DIR" |
| 64 |
echo "GENERATING PPD FILES (fast):" |
| 65 |
$DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z" ppd-clean ppd-nonls |
| 66 |
if [[ -n $STP_TEST_DIST ]] ; then |
| 67 |
echo "GENERATING PPD FILES (global):" |
| 68 |
$DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z -S" ppd-global |
| 69 |
fi |
| 70 |
PPD_PARALLEL=20 |
| 71 |
} |
| 72 |
|
| 73 |
function test_minimal() { |
| 74 |
rm -rf "$PPD_DIR" |
| 75 |
echo "GENERATING PPD FILES (minimal):" |
| 76 |
$DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z -S" ppd-clean ppd-nonls |
| 77 |
PPD_PARALLEL=20 |
| 78 |
} |
| 79 |
|
| 80 |
case "$STP_TEST_PROFILE" in |
| 81 |
full|fast|minimal) |
| 82 |
test_$STP_TEST_PROFILE |
| 83 |
;; |
| 84 |
*) |
| 85 |
exit 77 |
| 86 |
esac |
| 87 |
|
| 88 |
if [[ -n "$STP_TEST_DEBUG" ]] ; then |
| 89 |
echo "Would run $0 $*" |
| 90 |
exit 0 |
| 91 |
fi |
| 92 |
|
| 93 |
ppd_count=$(find "$PPD_DIR" -name '*.ppd' -print | wc -l) |
| 94 |
|
| 95 |
# Setting a limit on the number of files per invocation improves |
| 96 |
# performance by about a minute by reducing the tail at the end. |
| 97 |
[[ -n $STP_PARALLEL ]] && PARALLEL="-P $STP_PARALLEL -L $PPD_PARALLEL" |
| 98 |
|
| 99 |
# Most non-Macintosh systems won't have the Macintosh-specific profiles |
| 100 |
# installed in Macintosh-specific locations. |
| 101 |
# |
| 102 |
# Also, a number of our media sizes aren't named correctly, but we'll |
| 103 |
# accept those issues rather than cluttering the namespace further and/or |
| 104 |
# changing tag names. |
| 105 |
cupstestppdopts='-r -I profiles -W sizes -I filters' |
| 106 |
|
| 107 |
# This lets us report progress |
| 108 |
testcmd="echo -n . 1>&2; cupstestppd $cupstestppdopts"' "$@" |grep '"'FAIL$' | awk -F: '{print \$1}'" |
| 109 |
|
| 110 |
echo -n "TESTING PPD FILES: " |
| 111 |
failures="$(find $PPD_DIR -name '*.ppd*' -print | sort -t/ -k3 -k2 | xargs $PARALLEL sh -c "$testcmd")" |
| 112 |
echo 1>&2 |
| 113 |
|
| 114 |
if [[ -z "$failures" ]] ; then |
| 115 |
echo "All $ppd_count PPD files pass" |
| 116 |
rm -rf $PPD_DIR |
| 117 |
exit 0 |
| 118 |
fi |
| 119 |
|
| 120 |
# Use this with "normal" PPD files without translated numbers. |
| 121 |
#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' |
| 122 |
|
| 123 |
# Use this with PPD files with translated numbers (genppd -N) |
| 124 |
# With normal globalized PPD files this will yield hundreds of megabytes |
| 125 |
# of errors. |
| 126 |
echo "$failures" | xargs -P $STP_PARALLEL -L 10 sh -c "cupstestppd -r $cupstestppdopts "'"$@"'" 2>&1 | egrep -v '(WARN.*(Size \".*\" should be \"|has unexpected dimensions|should be the Adobe standard name)|REF: Page.*|^$)'" |
| 127 |
|
| 128 |
fail_count=$(wc -l <<< "$failures") |
| 129 |
echo "$fail_count/$ppd_count fail" |
| 130 |
exit 1 |