1#!@BASHREAL@ 2 3# Test PPD conformance 4# 5# Copyright 2006-2017 Robert Krawitz (rlk@alum.mit.edu) 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 32if [[ -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 40fi 41 42DEBUG=${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 48PPD_DIR=ppdtest 49 50PPD_PARALLEL=200 51 52echo '****************************************************************' 53 54rotor="-R ${STP_TEST_ROTOR_CIRCUMFERENCE:-1} -r ${STP_TEST_ROTOR:-0}" 55 56function test_full() { 57 rm -rf "$PPD_DIR" 58 echo "GENERATING PPD FILES (all):" 59 set -e 60 $DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z" ppd-clean ppd-global-a ppd-nls-a ppd-nonls-a 61} 62 63function test_fast() { 64 rm -rf "$PPD_DIR" 65 echo "GENERATING PPD FILES (fast):" 66 set -e 67 $DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z" ppd-clean ppd-nonls 68 if [[ -n $STP_TEST_DIST ]] ; then 69 echo "GENERATING PPD FILES (global):" 70 set -e 71 $DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z -S" ppd-global 72 fi 73 PPD_PARALLEL=20 74} 75 76function test_minimal() { 77 rm -rf "$PPD_DIR" 78 echo "GENERATING PPD FILES (minimal):" 79 set -e 80 $DEBUG make "PPD_DIR=$PPD_DIR" EXTRA_GENPPD_OPTS="$rotor -b -Z -S" ppd-clean ppd-nonls 81 PPD_PARALLEL=20 82} 83 84case "$STP_TEST_PROFILE" in 85 full|fast|minimal) 86 test_$STP_TEST_PROFILE 87 ;; 88 *) 89 exit 77 90esac 91 92if [[ -n "$STP_TEST_DEBUG" ]] ; then 93 echo "Would run $0 $*" 94 exit 0 95fi 96 97ppd_count=$(find "$PPD_DIR" -name '*.ppd' -print | wc -l) 98 99# Setting a limit on the number of files per invocation improves 100# performance by about a minute by reducing the tail at the end. 101[[ -n $STP_PARALLEL ]] && PARALLEL="-P $STP_PARALLEL -L $PPD_PARALLEL" 102 103# Most non-Macintosh systems won't have the Macintosh-specific profiles 104# installed in Macintosh-specific locations. 105# 106# Also, a number of our media sizes aren't named correctly, but we'll 107# accept those issues rather than cluttering the namespace further and/or 108# changing tag names. 109cupstestppdopts='-I profiles -W sizes -I filters' 110 111# This lets us report progress 112testcmd="echo -n . 1>&2; cupstestppd $cupstestppdopts "'"$@"' 113 114echo -n "TESTING PPD FILES: " 115failures="$(find $PPD_DIR -name '*.ppd*' -print | sort -t/ -k3 -k2 | xargs $PARALLEL sh -c "$testcmd" |grep 'FAIL$' | awk -F: '{print $1}')" 116 117if [[ -z "$failures" ]] ; then 118 echo "All $ppd_count PPD files pass" 119 rm -rf $PPD_DIR 120 exit 0 121fi 122 123# Use this with "normal" PPD files without translated numbers. 124#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' 125 126# Use this with PPD files with translated numbers (genppd -N) 127# With normal globalized PPD files this will yield hundreds of megabytes 128# of errors. 129echo "$failures" | xargs cupstestppd -r $cupstestppdopts 2>&1 130 131fail_count=`echo "$failures" | wc -l` 132echo "$fail_count/$ppd_count fail" 133exit 1 134