1#!/bin/sh
2#
3# Perform the complete set of IPP compliance tests specified in the
4# CUPS Software Test Plan.
5#
6# Copyright © 2020 by Michael R Sweet
7# Copyright © 2007-2019 by Apple Inc.
8# Copyright © 1997-2007 by Easy Software Products, all rights reserved.
9#
10# Licensed under Apache License v2.0.  See the file "LICENSE" for more
11# information.
12#
13
14argcount=$#
15
16#
17# Don't allow "make check" or "make test" to be run by root...
18#
19
20if test "x`id -u`" = x0; then
21	echo Please run this as a normal user. Not supported when run as root.
22	exit 1
23fi
24
25#
26# Force the permissions of the files we create...
27#
28
29umask 022
30
31#
32# Make the IPP test program...
33#
34
35make
36
37#
38# Solaris has a non-POSIX grep in /bin...
39#
40
41if test -x /usr/xpg4/bin/grep; then
42	GREP=/usr/xpg4/bin/grep
43else
44	GREP=grep
45fi
46
47#
48# Figure out the proper echo options...
49#
50
51if (echo "testing\c"; echo 1,2,3) | $GREP c >/dev/null; then
52        ac_n=-n
53        ac_c=
54else
55        ac_n=
56        ac_c='\c'
57fi
58
59#
60# Greet the tester...
61#
62
63echo "Welcome to the CUPS Automated Test Script."
64echo ""
65echo "Before we begin, it is important that you understand that the larger"
66echo "tests require significant amounts of RAM and disk space.  If you"
67echo "attempt to run one of the big tests on a system that lacks sufficient"
68echo "disk and virtual memory, the UNIX kernel might decide to kill one or"
69echo "more system processes that you've grown attached to, like the X"
70echo "server.  The question you may want to ask yourself before running a"
71echo "large test is: Do you feel lucky?"
72echo ""
73echo "OK, now that we have the Dirty Harry quote out of the way, please"
74echo "choose the type of test you wish to perform:"
75echo ""
76echo "0 - No testing, keep the scheduler running for me (all systems)"
77echo "1 - Basic conformance test, no load testing (all systems)"
78echo "2 - Basic conformance test, some load testing (minimum 256MB VM, 50MB disk)"
79echo "3 - Basic conformance test, extreme load testing (minimum 1GB VM, 500MB disk)"
80echo "4 - Basic conformance test, torture load testing (minimum 2GB VM, 1GB disk)"
81echo ""
82echo $ac_n "Enter the number of the test you wish to perform: [1] $ac_c"
83
84if test $# -gt 0; then
85	testtype=$1
86	shift
87else
88	read testtype
89fi
90echo ""
91
92case "$testtype" in
93	0)
94		echo "Running in test mode (0)"
95		nprinters=0
96		pjobs=0
97		pprinters=0
98		loglevel="debug2"
99		;;
100	2)
101		echo "Running the medium tests (2)"
102		nprinters=20
103		pjobs=20
104		pprinters=10
105		loglevel="debug"
106		;;
107	3)
108		echo "Running the extreme tests (3)"
109		nprinters=1000
110		pjobs=100
111		pprinters=50
112		loglevel="debug"
113		;;
114	4)
115		echo "Running the torture tests (4)"
116		nprinters=20000
117		pjobs=200
118		pprinters=100
119		loglevel="debug"
120		;;
121	*)
122		echo "Running the timid tests (1)"
123		nprinters=0
124		pjobs=10
125		pprinters=0
126		loglevel="debug2"
127		testtype="1"
128		;;
129esac
130
131#
132# See if we want to do SSL testing...
133#
134
135echo ""
136echo "Now you can choose whether to create a SSL/TLS encryption key and"
137echo "certificate for testing:"
138echo ""
139echo "0 - Do not do SSL/TLS encryption tests"
140echo "1 - Test but do not require encryption"
141echo "2 - Test and require encryption"
142echo ""
143echo $ac_n "Enter the number of the SSL/TLS tests to perform: [0] $ac_c"
144
145if test $# -gt 0; then
146	ssltype=$1
147	shift
148else
149	read ssltype
150fi
151echo ""
152
153case "$ssltype" in
154	1)
155		echo "Will test but not require encryption (1)"
156		;;
157	2)
158		echo "Will test and require encryption (2)"
159		;;
160	*)
161		echo "Not using SSL/TLS (0)"
162		ssltype=0
163		;;
164esac
165
166#
167# Information for the server/tests...
168#
169
170user="$USER"
171if test -z "$user"; then
172	if test -x /usr/ucb/whoami; then
173		user=`/usr/ucb/whoami`
174	else
175		user=`whoami`
176	fi
177
178	if test -z "$user"; then
179		user="unknown"
180	fi
181fi
182
183port="${CUPS_TESTPORT:=8631}"
184cwd=`pwd`
185root=`dirname $cwd`
186CUPS_TESTROOT="$root"; export CUPS_TESTROOT
187
188BASE="${CUPS_TESTBASE:=}"
189if test -z "$BASE"; then
190	if test -d /private/tmp; then
191		BASE=/private/tmp/cups-$user
192	else
193		BASE=/tmp/cups-$user
194	fi
195fi
196export BASE
197
198#
199# Make sure that the LPDEST and PRINTER environment variables are
200# not included in the environment that is passed to the tests.  These
201# will usually cause tests to fail erroneously...
202#
203
204unset LPDEST
205unset PRINTER
206
207#
208# See if we want to use valgrind...
209#
210
211echo ""
212echo "This test script can use the Valgrind software from:"
213echo ""
214echo "    http://developer.kde.org/~sewardj/"
215echo ""
216echo $ac_n "Enter Y to use Valgrind or N to not use Valgrind: [N] $ac_c"
217
218if test $# -gt 0; then
219	usevalgrind=$1
220	shift
221else
222	read usevalgrind
223fi
224echo ""
225
226case "$usevalgrind" in
227	Y* | y*)
228		VALGRIND="valgrind --tool=memcheck --log-file=$BASE/log/valgrind.%p --error-limit=no --leak-check=yes --trace-children=yes"
229		if test `uname` = Darwin; then
230			VALGRIND="$VALGRIND --dsymutil=yes"
231		fi
232		export VALGRIND
233		echo "Using Valgrind; log files can be found in $BASE/log..."
234		;;
235
236	*)
237		VALGRIND=""
238		export VALGRIND
239		;;
240esac
241
242#
243# See if we want to do debug logging of the libraries...
244#
245
246echo ""
247echo "If CUPS was built with the --enable-debug-printfs configure option, you"
248echo "can enable debug logging of the libraries."
249echo ""
250echo $ac_n "Enter Y or a number from 0 to 9 to enable debug logging or N to not: [N] $ac_c"
251
252if test $# -gt 0; then
253	usedebugprintfs=$1
254	shift
255else
256	read usedebugprintfs
257fi
258echo ""
259
260case "$usedebugprintfs" in
261	Y* | y*)
262		echo "Enabling debug printfs (level 5); log files can be found in $BASE/log..."
263		CUPS_DEBUG_LOG="$BASE/log/debug_printfs.%d"; export CUPS_DEBUG_LOG
264		CUPS_DEBUG_LEVEL=5; export CUPS_DEBUG_LEVEL
265		CUPS_DEBUG_FILTER='^(http|_http|ipp|_ipp|cups.*Request|cupsGetResponse|cupsSend).*$'; export CUPS_DEBUG_FILTER
266		;;
267
268	0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)
269		echo "Enabling debug printfs (level $usedebugprintfs); log files can be found in $BASE/log..."
270		CUPS_DEBUG_LOG="$BASE/log/debug_printfs.%d"; export CUPS_DEBUG_LOG
271		CUPS_DEBUG_LEVEL="$usedebugprintfs"; export CUPS_DEBUG_LEVEL
272		CUPS_DEBUG_FILTER='^(http|_http|ipp|_ipp|cups.*Request|cupsGetResponse|cupsSend).*$'; export CUPS_DEBUG_FILTER
273		;;
274
275	*)
276		;;
277esac
278
279#
280# Start by creating temporary directories for the tests...
281#
282
283echo "Creating directories for test..."
284
285rm -rf $BASE
286mkdir $BASE
287mkdir $BASE/bin
288mkdir $BASE/bin/backend
289mkdir $BASE/bin/driver
290mkdir $BASE/bin/filter
291mkdir $BASE/certs
292mkdir $BASE/share
293mkdir $BASE/share/banners
294mkdir $BASE/share/drv
295mkdir $BASE/share/locale
296for file in ../locale/cups_*.po; do
297	loc=`basename $file .po | cut -c 6-`
298	mkdir $BASE/share/locale/$loc
299	ln -s $root/locale/cups_$loc.po $BASE/share/locale/$loc
300done
301mkdir $BASE/share/locale/en
302ln -s $root/locale/cups.pot $BASE/share/locale/en/cups_en.po
303mkdir $BASE/share/mime
304mkdir $BASE/share/model
305mkdir $BASE/share/ppdc
306mkdir $BASE/interfaces
307mkdir $BASE/log
308mkdir $BASE/ppd
309mkdir $BASE/spool
310mkdir $BASE/spool/temp
311mkdir $BASE/ssl
312
313ln -s $root/backend/dnssd $BASE/bin/backend
314ln -s $root/backend/http $BASE/bin/backend
315ln -s $root/backend/ipp $BASE/bin/backend
316ln -s ipp $BASE/bin/backend/ipps
317ln -s $root/backend/lpd $BASE/bin/backend
318ln -s $root/backend/mdns $BASE/bin/backend
319ln -s $root/backend/pseudo $BASE/bin/backend
320ln -s $root/backend/snmp $BASE/bin/backend
321ln -s $root/backend/socket $BASE/bin/backend
322ln -s $root/backend/usb $BASE/bin/backend
323ln -s $root/cgi-bin $BASE/bin
324ln -s $root/monitor $BASE/bin
325ln -s $root/notifier $BASE/bin
326ln -s $root/scheduler $BASE/bin/daemon
327ln -s $root/filter/commandtops $BASE/bin/filter
328ln -s $root/filter/gziptoany $BASE/bin/filter
329ln -s $root/filter/pstops $BASE/bin/filter
330ln -s $root/filter/rastertoepson $BASE/bin/filter
331ln -s $root/filter/rastertohp $BASE/bin/filter
332ln -s $root/filter/rastertolabel $BASE/bin/filter
333ln -s $root/filter/rastertopwg $BASE/bin/filter
334cat >$BASE/share/banners/standard <<EOF
335           ==== Cover Page ====
336
337
338      Job: {?printer-name}-{?job-id}
339    Owner: {?job-originating-user-name}
340     Name: {?job-name}
341    Pages: {?job-impressions}
342
343
344           ==== Cover Page ====
345EOF
346cat >$BASE/share/banners/classified <<EOF
347           ==== Classified - Do Not Disclose ====
348
349
350      Job: {?printer-name}-{?job-id}
351    Owner: {?job-originating-user-name}
352     Name: {?job-name}
353    Pages: {?job-impressions}
354
355
356           ==== Classified - Do Not Disclose ====
357EOF
358ln -s $root/data $BASE/share
359ln -s $root/ppdc/sample.drv $BASE/share/drv
360ln -s $root/conf/mime.types $BASE/share/mime
361ln -s $root/conf/mime.convs $BASE/share/mime
362ln -s $root/data/*.h $BASE/share/ppdc
363ln -s $root/data/*.defs $BASE/share/ppdc
364ln -s $root/templates $BASE/share
365
366#
367# Local filters and configuration files...
368#
369
370instfilter() {
371	# instfilter src dst format
372	#
373	# See if the filter exists in a standard location; if so, make a
374	# symlink, otherwise create a dummy script for the specified format.
375	#
376	src="$1"
377	dst="$2"
378	format="$3"
379
380	for dir in /usr/local/libexec/cups/filter /usr/libexec/cups/filter /usr/lib/cups/filter; do
381		if test -x "$dir/$src"; then
382			ln -s "$dir/$src" "$BASE/bin/filter/$dst"
383			return
384		fi
385	done
386
387	# Source filter not present, create a dummy filter
388	case $format in
389		passthru)
390			ln -s gziptoany "$BASE/bin/filter/$dst"
391			;;
392		pdf)
393			cat >"$BASE/bin/filter/$dst" <<EOF
394#!/bin/sh
395trap "" TERM
396trap "" PIPE
397gziptoany "$1" "$2" "$3" "$4" "$5" \$6 >/dev/null
398case "\$5" in
399	*media=a4* | *media=iso_a4* | *PageSize=A4*)
400		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-a4.pdf"
401		;;
402	*)
403		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-letter.pdf"
404		;;
405esac
406EOF
407			chmod +x "$BASE/bin/filter/$dst"
408			;;
409		ps)
410			cat >"$BASE/bin/filter/$dst" <<EOF
411#!/bin/sh
412trap "" TERM
413trap "" PIPE
414gziptoany "$1" "$2" "$3" "$4" "$5" \$6 >/dev/null
415case "\$5" in
416	*media=a4* | *media=iso_a4* | *PageSize=A4*)
417		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-a4.ps"
418		;;
419	*)
420		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-letter.ps"
421		;;
422esac
423EOF
424			chmod +x "$BASE/bin/filter/$dst"
425			;;
426		raster)
427			cat >"$BASE/bin/filter/$dst" <<EOF
428#!/bin/sh
429trap "" TERM
430trap "" PIPE
431gziptoany "$1" "$2" "$3" "$4" "$5" \$6 >/dev/null
432case "\$5" in
433	*media=a4* | *media=iso_a4* | *PageSize=A4*)
434		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-a4-300-black-1.pwg"
435		;;
436	*)
437		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-letter-300-black-1.pwg"
438		;;
439esac
440EOF
441			chmod +x "$BASE/bin/filter/$dst"
442			;;
443	esac
444}
445
446ln -s $root/test/test.convs $BASE/share/mime
447
448if test `uname` = Darwin; then
449	instfilter cgimagetopdf imagetopdf pdf
450	instfilter cgpdftopdf pdftopdf passthru
451	instfilter cgpdftops pdftops ps
452	instfilter cgpdftoraster pdftoraster raster
453	instfilter cgtexttopdf texttopdf pdf
454	instfilter pstocupsraster pstoraster raster
455else
456	instfilter imagetopdf imagetopdf pdf
457	instfilter pdftopdf pdftopdf passthru
458	instfilter pdftops pdftops ps
459	instfilter pdftoraster pdftoraster raster
460	instfilter pstoraster pstoraster raster
461	instfilter texttopdf texttopdf pdf
462
463	if test -d /usr/share/cups/charsets; then
464		ln -s /usr/share/cups/charsets $BASE/share
465	fi
466fi
467
468#
469# Then create the necessary config files...
470#
471
472echo "Creating cupsd.conf for test..."
473
474if test $ssltype = 2; then
475	encryption="Encryption Required"
476else
477	encryption=""
478fi
479
480if test $testtype = 0; then
481	jobhistory="30m"
482	jobfiles="5m"
483else
484	jobhistory="30"
485	jobfiles="Off"
486fi
487
488cat >$BASE/cupsd.conf <<EOF
489StrictConformance Yes
490Browsing Off
491Listen localhost:$port
492Listen $BASE/sock
493MaxSubscriptions 3
494MaxLogSize 0
495AccessLogLevel actions
496LogLevel $loglevel
497LogTimeFormat usecs
498PreserveJobHistory $jobhistory
499PreserveJobFiles $jobfiles
500<Policy default>
501<Limit All>
502Order Allow,Deny
503$encryption
504</Limit>
505</Policy>
506EOF
507
508if test $testtype = 0; then
509	echo WebInterface yes >>$BASE/cupsd.conf
510fi
511
512cat >$BASE/cups-files.conf <<EOF
513FileDevice yes
514Printcap
515User $user
516ServerRoot $BASE
517StateDir $BASE
518ServerBin $BASE/bin
519CacheDir $BASE/share
520DataDir $BASE/share
521FontPath $BASE/share/fonts
522DocumentRoot $root/doc
523RequestRoot $BASE/spool
524TempDir $BASE/spool/temp
525AccessLog $BASE/log/access_log
526ErrorLog $BASE/log/error_log
527PageLog $BASE/log/page_log
528
529PassEnv DYLD_INSERT_LIBRARIES
530PassEnv DYLD_LIBRARY_PATH
531PassEnv LD_LIBRARY_PATH
532PassEnv LD_PRELOAD
533PassEnv LOCALEDIR
534PassEnv ASAN_OPTIONS
535
536Sandboxing Off
537EOF
538
539if test $ssltype != 0 -a `uname` = Darwin; then
540	echo "ServerKeychain $HOME/Library/Keychains/login.keychain" >> $BASE/cups-files.conf
541fi
542
543#
544# Setup lots of test queues with PPD files...
545#
546
547echo "Creating printers.conf for test..."
548
549i=1
550while test $i -le $nprinters; do
551	cat >>$BASE/printers.conf <<EOF
552<Printer test-$i>
553Accepting Yes
554DeviceURI file:/dev/null
555Info Test PS printer $i
556JobSheets none none
557Location CUPS test suite
558State Idle
559StateMessage Printer $1 is idle.
560</Printer>
561EOF
562
563	cp testps.ppd $BASE/ppd/test-$i.ppd
564
565	i=`expr $i + 1`
566done
567
568if test -f $BASE/printers.conf; then
569	cp $BASE/printers.conf $BASE/printers.conf.orig
570else
571	touch $BASE/printers.conf.orig
572fi
573
574#
575# Create a helper script to run programs with...
576#
577
578echo "Setting up environment variables for test..."
579
580if test "x$ASAN_OPTIONS" = x; then
581	# AddressSanitizer on Linux reports memory leaks from the main function
582	# which is basically useless - in general, programs do not need to free
583	# every object before exit since the OS will recover the process's
584	# memory.
585	ASAN_OPTIONS="detect_leaks=false"
586	export ASAN_OPTIONS
587fi
588
589if test -f "$root/cups/libcups.so.2"; then
590	if test "x$LD_LIBRARY_PATH" = x; then
591		LD_LIBRARY_PATH="$root/cups"
592	else
593		LD_LIBRARY_PATH="$root/cups:$LD_LIBRARY_PATH"
594	fi
595
596	LD_PRELOAD="$root/cups/libcups.so.2:$root/cups/libcupsimage.so.2"
597	if test `uname` = SunOS -a -r /usr/lib/libCrun.so.1; then
598		LD_PRELOAD="/usr/lib/libCrun.so.1:$LD_PRELOAD"
599	fi
600fi
601
602if test -f "$root/cups/libcups.2.dylib"; then
603	if test "x$DYLD_INSERT_LIBRARIES" = x; then
604		DYLD_INSERT_LIBRARIES="$root/cups/libcups.2.dylib:$root/cups/libcupsimage.2.dylib"
605	else
606		DYLD_INSERT_LIBRARIES="$root/cups/libcups.2.dylib:$root/cups/libcupsimage.2.dylib:$DYLD_INSERT_LIBRARIES"
607	fi
608
609	if test "x$DYLD_LIBRARY_PATH" = x; then
610		DYLD_LIBRARY_PATH="$root/cups"
611	else
612		DYLD_LIBRARY_PATH="$root/cups:$DYLD_LIBRARY_PATH"
613	fi
614fi
615
616# These get exported because they don't have side-effects...
617CUPS_DISABLE_APPLE_DEFAULT=yes; export CUPS_DISABLE_APPLE_DEFAULT
618CUPS_SERVER=localhost:$port; export CUPS_SERVER
619CUPS_SERVERROOT=$BASE; export CUPS_SERVERROOT
620CUPS_STATEDIR=$BASE; export CUPS_STATEDIR
621CUPS_DATADIR=$BASE/share; export CUPS_DATADIR
622IPP_PORT=$port; export IPP_PORT
623LOCALEDIR=$BASE/share/locale; export LOCALEDIR
624
625echo "Creating wrapper script..."
626
627runcups="$BASE/runcups"; export runcups
628
629echo "#!/bin/sh" >$runcups
630echo "# Helper script for running CUPS test instance." >>$runcups
631echo "" >>$runcups
632echo "# Set required environment variables..." >>$runcups
633echo "CUPS_DATADIR=\"$CUPS_DATADIR\"; export CUPS_DATADIR" >>$runcups
634echo "CUPS_SERVER=\"$CUPS_SERVER\"; export CUPS_SERVER" >>$runcups
635echo "CUPS_SERVERROOT=\"$CUPS_SERVERROOT\"; export CUPS_SERVERROOT" >>$runcups
636echo "CUPS_STATEDIR=\"$CUPS_STATEDIR\"; export CUPS_STATEDIR" >>$runcups
637echo "DYLD_INSERT_LIBRARIES=\"$DYLD_INSERT_LIBRARIES\"; export DYLD_INSERT_LIBRARIES" >>$runcups
638echo "DYLD_LIBRARY_PATH=\"$DYLD_LIBRARY_PATH\"; export DYLD_LIBRARY_PATH" >>$runcups
639# IPP_PORT=$port; export IPP_PORT
640echo "LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\"; export LD_LIBRARY_PATH" >>$runcups
641echo "LD_PRELOAD=\"$LD_PRELOAD\"; export LD_PRELOAD" >>$runcups
642echo "LOCALEDIR=\"$LOCALEDIR\"; export LOCALEDIR" >>$runcups
643if test "x$CUPS_DEBUG_LEVEL" != x; then
644	echo "CUPS_DEBUG_FILTER='$CUPS_DEBUG_FILTER'; export CUPS_DEBUG_FILTER" >>$runcups
645	echo "CUPS_DEBUG_LEVEL=$CUPS_DEBUG_LEVEL; export CUPS_DEBUG_LEVEL" >>$runcups
646	echo "CUPS_DEBUG_LOG='$CUPS_DEBUG_LOG'; export CUPS_DEBUG_LOG" >>$runcups
647fi
648echo "" >>$runcups
649echo "# Run command..." >>$runcups
650echo "exec \"\$@\"" >>$runcups
651
652chmod +x $runcups
653
654#
655# Set a new home directory to avoid getting user options mixed in...
656#
657
658HOME=$BASE
659export HOME
660
661#
662# Force POSIX locale for tests...
663#
664
665LANG=C
666export LANG
667
668LC_MESSAGES=C
669export LC_MESSAGES
670
671#
672# Start the server; run as foreground daemon in the background...
673#
674
675echo "Starting scheduler:"
676echo "    $runcups $VALGRIND ../scheduler/cupsd -c $BASE/cupsd.conf -f >$BASE/log/debug_log 2>&1 &"
677echo ""
678
679$runcups $VALGRIND ../scheduler/cupsd -c $BASE/cupsd.conf -f >$BASE/log/debug_log 2>&1 &
680
681cupsd=$!
682
683if test "x$testtype" = x0; then
684	# Not running tests...
685	echo "Scheduler is PID $cupsd and is listening on port $port."
686	echo ""
687
688	echo "The $runcups helper script can be used to test programs"
689	echo "with the server."
690	exit 0
691fi
692
693if test $argcount -eq 0; then
694	echo "Scheduler is PID $cupsd; run debugger now if you need to."
695	echo ""
696	echo $ac_n "Press ENTER to continue... $ac_c"
697	read junk
698else
699	echo "Scheduler is PID $cupsd."
700	sleep 2
701fi
702
703while true; do
704	running=`$runcups ../systemv/lpstat -r 2>/dev/null`
705	if test "x$running" = "xscheduler is running"; then
706		break
707	fi
708
709	echo "Waiting for scheduler to become ready..."
710	sleep 10
711done
712
713#
714# Create the test report source file...
715#
716
717date=`date "+%Y-%m-%d"`
718
719strfile=$BASE/cups-str-$date-$user.html
720
721rm -f $strfile
722cat str-header.html >$strfile
723
724#
725# Run the IPP tests...
726#
727
728echo ""
729echo "Running IPP compliance tests..."
730
731echo "    <h1><a name='IPP'>1 - IPP Compliance Tests</a></h1>" >>$strfile
732echo "    <p>This section provides the results to the IPP compliance tests" >>$strfile
733echo "    outlined in the CUPS Software Test Plan. These tests were run on" >>$strfile
734echo "    $date by $user on `hostname`." >>$strfile
735echo "    <pre>" >>$strfile
736
737fail=0
738for file in 4*.test ../examples/ipp-2.1.test; do
739	echo $ac_n "Performing `basename $file`: $ac_c"
740	echo "" >>$strfile
741        echo $ac_n "`date '+[%d/%b/%Y:%H:%M:%S %z]'` $ac_c" >>$strfile
742
743	if test $file = ../examples/ipp-2.1.test; then
744		uri="ipp://localhost:$port/printers/Test1"
745		options="-V 2.1 -d NOPRINT=1 -f testfile.ps"
746	else
747		uri="ipp://localhost:$port/printers"
748		options=""
749	fi
750	$runcups $VALGRIND ../tools/ipptool -tI $options $uri $file >> $strfile
751	status=$?
752
753	if test $status != 0; then
754		echo FAIL
755		fail=`expr $fail + 1`
756	else
757		echo PASS
758	fi
759done
760
761echo "    </pre>" >>$strfile
762
763#
764# Run the command tests...
765#
766
767echo ""
768echo "Running command tests..."
769
770echo "    <h1><a name='COMMAND'>2 - Command Tests</a></h1>" >>$strfile
771echo "    <p>This section provides the results to the command tests" >>$strfile
772echo "    outlined in the CUPS Software Test Plan. These tests were run on" >>$strfile
773echo "    $date by $user on `hostname`." >>$strfile
774echo "    <pre>" >>$strfile
775
776for file in 5*.sh; do
777	# Wait for jobs from the previous test to complete before running the
778	# next test...
779	if test $file != 5.1-lpadmin.sh; then
780		./waitjobs.sh 1800
781	fi
782
783	# Run the test...
784	echo $ac_n "Performing $file: $ac_c"
785	echo "" >>$strfile
786        echo "`date '+[%d/%b/%Y:%H:%M:%S %z]'` \"$file\":" >>$strfile
787
788	sh $file $pjobs $pprinters >> $strfile
789	status=$?
790
791	if test $status != 0; then
792		echo FAIL
793		fail=`expr $fail + 1`
794	else
795		echo PASS
796	fi
797done
798
799#
800# Restart the server...
801#
802
803echo $ac_n "Performing restart test: $ac_c"
804echo "" >>$strfile
805echo "`date '+[%d/%b/%Y:%H:%M:%S %z]'` \"5.10-restart\":" >>$strfile
806
807kill -HUP $cupsd
808
809while true; do
810	sleep 10
811
812	running=`$runcups ../systemv/lpstat -r 2>/dev/null`
813	if test "x$running" = "xscheduler is running"; then
814		break
815	fi
816done
817
818description="`$runcups ../systemv/lpstat -l -p Test1 | grep Description | sed -e '1,$s/^[^:]*: //g'`"
819if test "x$description" != "xTest Printer 1"; then
820	echo "Failed, printer-info for Test1 is '$description', expected 'Test Printer 1'." >>$strfile
821	echo "FAIL (got '$description', expected 'Test Printer 1')"
822	fail=`expr $fail + 1`
823else
824	echo "Passed." >>$strfile
825	echo PASS
826fi
827
828
829#
830# Perform job history test...
831#
832
833echo $ac_n "Starting history test: $ac_c"
834echo "" >>$strfile
835echo "`date '+[%d/%b/%Y:%H:%M:%S %z]'` \"5.11-history\":" >>$strfile
836
837echo "    lp -d Test1 testfile.jpg" >>$strfile
838
839$runcups ../systemv/lp -d Test1 ../examples/testfile.jpg 2>&1 >>$strfile
840if test $? != 0; then
841	echo "FAIL (unable to queue test job)"
842	echo "    FAILED" >>$strfile
843	fail=`expr $fail + 1`
844else
845	echo "PASS"
846	echo "    PASSED" >>$strfile
847
848	sleep 5
849	./waitjobs.sh >>$strfile
850
851        echo $ac_n "Verifying that history still exists: $ac_c"
852
853	echo "    ls -l $BASE/spool" >>$strfile
854	count=`ls -1 $BASE/spool | wc -l`
855	if test $count = 1; then
856		echo "FAIL (job control files not present)"
857		ls -l $BASE/spool
858		echo "    FAILED (job control files not present)" >>$strfile
859		ls -l $BASE/spool >>$strfile
860		fail=`expr $fail + 1`
861	else
862		echo "PASS"
863		echo "    PASSED" >>$strfile
864
865		echo $ac_n "Waiting for job history to expire: $ac_c"
866		echo "" >>$strfile
867		echo "    sleep 35" >>$strfile
868		sleep 35
869
870		echo "    lpstat" >>$strfile
871		$runcups ../systemv/lpstat 2>&1 >>$strfile
872
873		echo "    ls -l $BASE/spool" >>$strfile
874		count=`ls -1 $BASE/spool | wc -l`
875		if test $count != 1; then
876			echo "FAIL (job control files still present)"
877			ls -l $BASE/spool
878			echo "    FAILED (job control files still present)" >>$strfile
879			ls -l $BASE/spool >>$strfile
880			fail=`expr $fail + 1`
881		else
882			echo "PASS"
883			echo "    PASSED" >>$strfile
884		fi
885	fi
886fi
887
888
889#
890# Stop the server...
891#
892
893echo "    </pre>" >>$strfile
894
895kill $cupsd
896wait $cupsd
897cupsdstatus=$?
898
899#
900# Verify counts...
901#
902
903echo "Test Summary"
904echo ""
905echo "    <h1><a name='SUMMARY'>3 - Test Summary</a></h1>" >>$strfile
906
907if test $cupsdstatus != 0; then
908	echo "FAIL: cupsd failed with exit status $cupsdstatus."
909	echo "    <p>FAIL: cupsd failed with exit status $cupsdstatus.</p>" >>$strfile
910	fail=`expr $fail + 1`
911else
912	echo "PASS: cupsd exited with no errors."
913	echo "    <p>PASS: cupsd exited with no errors.</p>" >>$strfile
914fi
915
916# Job control files
917count=`ls -1 $BASE/spool | wc -l`
918count=`expr $count - 1`
919if test $count != 0; then
920	echo "FAIL: $count job control files were not purged."
921	echo "    <p>FAIL: $count job control files were not purged.</p>" >>$strfile
922	fail=`expr $fail + 1`
923else
924	echo "PASS: All job control files purged."
925	echo "    <p>PASS: All job control files purged.</p>" >>$strfile
926fi
927
928# Pages printed on Test1 (within 1 page for timing-dependent cancel issues)
929count=`$GREP '^Test1 ' $BASE/log/page_log | awk 'BEGIN{count=0}{count=count+$7}END{print count}'`
930expected=`expr $pjobs \* 2 + 34`
931expected2=`expr $expected + 2`
932if test $count -lt $expected -a $count -gt $expected2; then
933	echo "FAIL: Printer 'Test1' produced $count page(s), expected $expected."
934	echo "    <p>FAIL: Printer 'Test1' produced $count page(s), expected $expected.</p>" >>$strfile
935	fail=`expr $fail + 1`
936else
937	echo "PASS: Printer 'Test1' correctly produced $count page(s)."
938	echo "    <p>PASS: Printer 'Test1' correctly produced $count page(s).</p>" >>$strfile
939fi
940
941# Paged printed on Test2
942count=`$GREP '^Test2 ' $BASE/log/page_log | awk 'BEGIN{count=0}{count=count+$7}END{print count}'`
943expected=`expr $pjobs \* 2 + 3`
944if test $count != $expected; then
945	echo "FAIL: Printer 'Test2' produced $count page(s), expected $expected."
946	echo "    <p>FAIL: Printer 'Test2' produced $count page(s), expected $expected.</p>" >>$strfile
947	fail=`expr $fail + 1`
948else
949	echo "PASS: Printer 'Test2' correctly produced $count page(s)."
950	echo "    <p>PASS: Printer 'Test2' correctly produced $count page(s).</p>" >>$strfile
951fi
952
953# Paged printed on Test3
954count=`$GREP '^Test3 ' $BASE/log/page_log | awk 'BEGIN{count=0}{count=count+$7}END{print count}'`
955expected=2
956if test $count != $expected; then
957	echo "FAIL: Printer 'Test3' produced $count page(s), expected $expected."
958	echo "    <p>FAIL: Printer 'Test3' produced $count page(s), expected $expected.</p>" >>$strfile
959	fail=`expr $fail + 1`
960else
961	echo "PASS: Printer 'Test3' correctly produced $count page(s)."
962	echo "    <p>PASS: Printer 'Test3' correctly produced $count page(s).</p>" >>$strfile
963fi
964
965# Requests logged
966count=`wc -l $BASE/log/access_log | awk '{print $1}'`
967expected=`expr 35 + 18 + 30 + $pjobs \* 8 + $pprinters \* $pjobs \* 4 + 2`
968if test $count != $expected; then
969	echo "FAIL: $count requests logged, expected $expected."
970	echo "    <p>FAIL: $count requests logged, expected $expected.</p>" >>$strfile
971	fail=`expr $fail + 1`
972else
973	echo "PASS: $count requests logged."
974	echo "    <p>PASS: $count requests logged.</p>" >>$strfile
975fi
976
977# Did CUPS-Get-Default get logged?
978if $GREP -q CUPS-Get-Default $BASE/log/access_log; then
979	echo "FAIL: CUPS-Get-Default logged with 'AccessLogLevel actions'"
980	echo "    <p>FAIL: CUPS-Get-Default logged with 'AccessLogLevel actions'</p>" >>$strfile
981	echo "    <pre>" >>$strfile
982	$GREP CUPS-Get-Default $BASE/log/access_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
983	echo "    </pre>" >>$strfile
984	fail=`expr $fail + 1`
985else
986	echo "PASS: CUPS-Get-Default not logged."
987	echo "    <p>PASS: CUPS-Get-Default not logged.</p>" >>$strfile
988fi
989
990# Emergency log messages
991count=`$GREP '^X ' $BASE/log/error_log | wc -l | awk '{print $1}'`
992if test $count != 0; then
993	echo "FAIL: $count emergency messages, expected 0."
994	$GREP '^X ' $BASE/log/error_log
995	echo "    <p>FAIL: $count emergency messages, expected 0.</p>" >>$strfile
996	echo "    <pre>" >>$strfile
997	$GREP '^X ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
998	echo "    </pre>" >>$strfile
999	fail=`expr $fail + 1`
1000else
1001	echo "PASS: $count emergency messages."
1002	echo "    <p>PASS: $count emergency messages.</p>" >>$strfile
1003fi
1004
1005# Alert log messages
1006count=`$GREP '^A ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1007if test $count != 0; then
1008	echo "FAIL: $count alert messages, expected 0."
1009	$GREP '^A ' $BASE/log/error_log
1010	echo "    <p>FAIL: $count alert messages, expected 0.</p>" >>$strfile
1011	echo "    <pre>" >>$strfile
1012	$GREP '^A ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1013	echo "    </pre>" >>$strfile
1014	fail=`expr $fail + 1`
1015else
1016	echo "PASS: $count alert messages."
1017	echo "    <p>PASS: $count alert messages.</p>" >>$strfile
1018fi
1019
1020# Critical log messages
1021count=`$GREP '^C ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1022if test $count != 0; then
1023	echo "FAIL: $count critical messages, expected 0."
1024	$GREP '^C ' $BASE/log/error_log
1025	echo "    <p>FAIL: $count critical messages, expected 0.</p>" >>$strfile
1026	echo "    <pre>" >>$strfile
1027	$GREP '^C ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1028	echo "    </pre>" >>$strfile
1029	fail=`expr $fail + 1`
1030else
1031	echo "PASS: $count critical messages."
1032	echo "    <p>PASS: $count critical messages.</p>" >>$strfile
1033fi
1034
1035# Error log messages
1036count=`$GREP '^E ' $BASE/log/error_log | $GREP -v 'Unknown default SystemGroup' | wc -l | awk '{print $1}'`
1037if test $count != 33; then
1038	echo "FAIL: $count error messages, expected 33."
1039	$GREP '^E ' $BASE/log/error_log
1040	echo "    <p>FAIL: $count error messages, expected 33.</p>" >>$strfile
1041	echo "    <pre>" >>$strfile
1042	$GREP '^E ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1043	echo "    </pre>" >>$strfile
1044	fail=`expr $fail + 1`
1045else
1046	echo "PASS: $count error messages."
1047	echo "    <p>PASS: $count error messages.</p>" >>$strfile
1048fi
1049
1050# Warning log messages
1051count=`$GREP '^W ' $BASE/log/error_log | $GREP -v CreateProfile | $GREP -v 'libusb error' | $GREP -v ColorManager | $GREP -v 'Avahi client failed' | wc -l | awk '{print $1}'`
1052if test $count != 8; then
1053	echo "FAIL: $count warning messages, expected 8."
1054	$GREP '^W ' $BASE/log/error_log
1055	echo "    <p>FAIL: $count warning messages, expected 8.</p>" >>$strfile
1056	echo "    <pre>" >>$strfile
1057	$GREP '^W ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1058	echo "    </pre>" >>$strfile
1059	fail=`expr $fail + 1`
1060else
1061	echo "PASS: $count warning messages."
1062	echo "    <p>PASS: $count warning messages.</p>" >>$strfile
1063fi
1064
1065# Notice log messages
1066count=`$GREP '^N ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1067if test $count != 0; then
1068	echo "FAIL: $count notice messages, expected 0."
1069	$GREP '^N ' $BASE/log/error_log
1070	echo "    <p>FAIL: $count notice messages, expected 0.</p>" >>$strfile
1071	echo "    <pre>" >>$strfile
1072	$GREP '^N ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1073	echo "    </pre>" >>$strfile
1074	fail=`expr $fail + 1`
1075else
1076	echo "PASS: $count notice messages."
1077	echo "    <p>PASS: $count notice messages.</p>" >>$strfile
1078fi
1079
1080# Info log messages
1081count=`$GREP '^I ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1082if test $count = 0; then
1083	echo "FAIL: $count info messages, expected more than 0."
1084	echo "    <p>FAIL: $count info messages, expected more than 0.</p>" >>$strfile
1085	fail=`expr $fail + 1`
1086else
1087	echo "PASS: $count info messages."
1088	echo "    <p>PASS: $count info messages.</p>" >>$strfile
1089fi
1090
1091# Debug log messages
1092count=`$GREP '^D ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1093if test $count = 0; then
1094	echo "FAIL: $count debug messages, expected more than 0."
1095	echo "    <p>FAIL: $count debug messages, expected more than 0.</p>" >>$strfile
1096	fail=`expr $fail + 1`
1097else
1098	echo "PASS: $count debug messages."
1099	echo "    <p>PASS: $count debug messages.</p>" >>$strfile
1100fi
1101
1102# Debug2 log messages
1103count=`$GREP '^d ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1104if test $count = 0 -a $loglevel = debug2; then
1105	echo "FAIL: $count debug2 messages, expected more than 0."
1106	echo "    <p>FAIL: $count debug2 messages, expected more than 0.</p>" >>$strfile
1107	fail=`expr $fail + 1`
1108elif test $count != 0 -a $loglevel = debug; then
1109	echo "FAIL: $count debug2 messages, expected 0."
1110	echo "    <p>FAIL: $count debug2 messages, expected 0.</p>" >>$strfile
1111	fail=`expr $fail + 1`
1112else
1113	echo "PASS: $count debug2 messages."
1114	echo "    <p>PASS: $count debug2 messages.</p>" >>$strfile
1115fi
1116
1117#
1118# Log files...
1119#
1120
1121echo "    <h1><a name='LOGS'>4 - Log Files</a></h1>" >>$strfile
1122
1123for file in $BASE/log/*_log; do
1124        baselog=`basename $file`
1125
1126        echo "    <h2><a name=\"$baselog\">$baselog</a></h2>" >>$strfile
1127        case $baselog in
1128                error_log)
1129                        echo "    <blockquote>Note: debug2 messages have been filtered out of the HTML report.</blockquote>" >>$strfile
1130                        echo "    <pre>" >>$strfile
1131                        $GREP -v '^d' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1132                        echo "    </pre>" >>$strfile
1133                        ;;
1134
1135                *)
1136                        echo "    <pre>" >>$strfile
1137                        sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' $file >>$strfile
1138                        echo "    </pre>" >>$strfile
1139                        ;;
1140        esac
1141done
1142
1143#
1144# Format the reports and tell the user where to find them...
1145#
1146
1147cat str-trailer.html >>$strfile
1148
1149echo ""
1150for file in $BASE/log/*_log; do
1151        baselog=`basename $file`
1152        cp $file $baselog-$date-$user
1153        echo "Copied log file \"$baselog-$date-$user\" to test directory."
1154done
1155cp $strfile .
1156echo "Copied report file \"cups-str-$date-$user.html\" to test directory."
1157
1158# Clean out old failure log files after 1 week...
1159find . -name \*_log-\*-$user -a -mtime +7 -print -exec rm -f '{}' \; | awk '{print "Removed old log file \"" substr($1,3) "\" from test directory."}'
1160find . -name cups-str-\*-$user.html -a -mtime +7 -print -exec rm -f '{}' \; | awk '{print "Removed old report file \"" $1 "\" from test directory."}'
1161
1162echo ""
1163
1164if test $fail != 0; then
1165	echo "$fail tests failed."
1166	exit 1
1167else
1168	echo "All tests were successful."
1169fi
1170