• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-2023 by OpenPrinting
7# Copyright © 2007-2021 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/cgi.types $BASE/share/mime
361ln -s $root/conf/mime.types $BASE/share/mime
362ln -s $root/conf/mime.convs $BASE/share/mime
363ln -s $root/data/*.h $BASE/share/ppdc
364ln -s $root/data/*.defs $BASE/share/ppdc
365ln -s $root/templates $BASE/share
366
367#
368# Local filters and configuration files...
369#
370
371instfilter() {
372	# instfilter src dst format
373	#
374	# See if the filter exists in a standard location; if so, make a
375	# symlink, otherwise create a dummy script for the specified format.
376	#
377	src="$1"
378	dst="$2"
379	format="$3"
380
381	for dir in /usr/local/libexec/cups/filter /usr/libexec/cups/filter /usr/lib/cups/filter; do
382		if test -x "$dir/$src"; then
383			ln -s "$dir/$src" "$BASE/bin/filter/$dst"
384			return
385		fi
386	done
387
388	# Source filter not present, create a dummy filter
389	case $format in
390		passthru)
391			ln -s gziptoany "$BASE/bin/filter/$dst"
392			;;
393		pdf)
394			cat >"$BASE/bin/filter/$dst" <<EOF
395#!/bin/sh
396trap "" TERM
397trap "" PIPE
398gziptoany "$1" "$2" "$3" "$4" "$5" \$6 >/dev/null
399case "\$5" in
400	*media=a4* | *media=iso_a4* | *PageSize=A4*)
401		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-a4.pdf"
402		;;
403	*)
404		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-letter.pdf"
405		;;
406esac
407EOF
408			chmod +x "$BASE/bin/filter/$dst"
409			;;
410		ps)
411			cat >"$BASE/bin/filter/$dst" <<EOF
412#!/bin/sh
413trap "" TERM
414trap "" PIPE
415gziptoany "$1" "$2" "$3" "$4" "$5" \$6 >/dev/null
416case "\$5" in
417	*media=a4* | *media=iso_a4* | *PageSize=A4*)
418		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-a4.ps"
419		;;
420	*)
421		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-letter.ps"
422		;;
423esac
424EOF
425			chmod +x "$BASE/bin/filter/$dst"
426			;;
427		raster)
428			cat >"$BASE/bin/filter/$dst" <<EOF
429#!/bin/sh
430trap "" TERM
431trap "" PIPE
432gziptoany "$1" "$2" "$3" "$4" "$5" \$6 >/dev/null
433case "\$5" in
434	*media=a4* | *media=iso_a4* | *PageSize=A4*)
435		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-a4-300-black-1.pwg"
436		;;
437	*)
438		gziptoany "$1" "$2" "$3" "$4" "$5" "$root/examples/onepage-letter-300-black-1.pwg"
439		;;
440esac
441EOF
442			chmod +x "$BASE/bin/filter/$dst"
443			;;
444	esac
445}
446
447ln -s $root/test/test.convs $BASE/share/mime
448
449if test `uname` = Darwin; then
450	instfilter cgimagetopdf imagetopdf pdf
451	instfilter cgpdftopdf pdftopdf passthru
452	instfilter cgpdftops pdftops ps
453	instfilter cgpdftoraster pdftoraster raster
454	instfilter cgtexttopdf texttopdf pdf
455	instfilter pstocupsraster pstoraster raster
456else
457	instfilter imagetopdf imagetopdf pdf
458	instfilter pdftopdf pdftopdf passthru
459	instfilter pdftops pdftops ps
460	instfilter pdftoraster pdftoraster raster
461	instfilter pstoraster pstoraster raster
462	instfilter texttopdf texttopdf pdf
463
464	if test -d /usr/share/cups/charsets; then
465		ln -s /usr/share/cups/charsets $BASE/share
466	fi
467fi
468
469#
470# Then create the necessary config files...
471#
472
473echo "Creating cupsd.conf for test..."
474
475if test $ssltype = 2; then
476	encryption="Encryption Required"
477else
478	encryption=""
479fi
480
481if test $testtype = 0; then
482	jobhistory="30m"
483	jobfiles="5m"
484else
485	jobhistory="30"
486	jobfiles="Off"
487fi
488
489cat >$BASE/cupsd.conf <<EOF
490StrictConformance Yes
491Browsing Off
492Listen localhost:$port
493Listen $BASE/sock
494MaxSubscriptions 3
495MaxLogSize 0
496AccessLogLevel actions
497LogLevel $loglevel
498LogTimeFormat usecs
499PreserveJobHistory $jobhistory
500PreserveJobFiles $jobfiles
501<Policy default>
502<Limit All>
503Order Allow,Deny
504$encryption
505</Limit>
506</Policy>
507EOF
508
509if test $testtype = 0; then
510	echo WebInterface yes >>$BASE/cupsd.conf
511fi
512
513cat >$BASE/cups-files.conf <<EOF
514FileDevice yes
515Printcap
516User $user
517ServerRoot $BASE
518StateDir $BASE
519ServerBin $BASE/bin
520CacheDir $BASE/share
521DataDir $BASE/share
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
703tries=0
704while test $tries -lt 30; do
705	running=`$runcups ../systemv/lpstat -r 2>/dev/null`
706	if test "x$running" = "xscheduler is running"; then
707		break
708	fi
709
710	echo "Waiting for scheduler to become ready..."
711	sleep 10
712
713	tries=`expr $tries + 1`
714done
715
716#
717# Create the test report source file...
718#
719
720date=`date "+%Y-%m-%d"`
721
722strfile=$BASE/cups-str-$date-$user.html
723
724rm -f $strfile
725cat str-header.html >$strfile
726
727#
728# Run the IPP tests...
729#
730
731echo ""
732echo "Running IPP compliance tests..."
733
734echo "    <h1><a name='IPP'>1 - IPP Compliance Tests</a></h1>" >>$strfile
735echo "    <p>This section provides the results to the IPP compliance tests" >>$strfile
736echo "    outlined in the CUPS Software Test Plan. These tests were run on" >>$strfile
737echo "    $date by $user on `hostname`." >>$strfile
738echo "    <pre>" >>$strfile
739
740fail=0
741for file in 4*.test ../examples/ipp-2.1.test; do
742	echo $ac_n "Performing `basename $file`: $ac_c"
743	echo "" >>$strfile
744        echo $ac_n "`date '+[%d/%b/%Y:%H:%M:%S %z]'` $ac_c" >>$strfile
745
746	if test $file = ../examples/ipp-2.1.test; then
747		uri="ipp://localhost:$port/printers/Test1"
748		options="-V 2.1 -d NOPRINT=1 -f testfile.ps"
749	else
750		uri="ipp://localhost:$port/printers"
751		options=""
752	fi
753	$runcups $VALGRIND ../tools/ipptool -tI $options $uri $file >> $strfile
754	status=$?
755
756	if test $status != 0; then
757		echo FAIL
758		fail=`expr $fail + 1`
759	else
760		echo PASS
761	fi
762done
763
764echo "    </pre>" >>$strfile
765
766#
767# Run the command tests...
768#
769
770echo ""
771echo "Running command tests..."
772
773echo "    <h1><a name='COMMAND'>2 - Command Tests</a></h1>" >>$strfile
774echo "    <p>This section provides the results to the command tests" >>$strfile
775echo "    outlined in the CUPS Software Test Plan. These tests were run on" >>$strfile
776echo "    $date by $user on `hostname`." >>$strfile
777echo "    <pre>" >>$strfile
778
779for file in 5*.sh; do
780	# Wait for jobs from the previous test to complete before running the
781	# next test...
782	if test $file != 5.1-lpadmin.sh; then
783		./waitjobs.sh 1800
784	fi
785
786	# Run the test...
787	echo $ac_n "Performing $file: $ac_c"
788	echo "" >>$strfile
789        echo "`date '+[%d/%b/%Y:%H:%M:%S %z]'` \"$file\":" >>$strfile
790
791	sh $file $pjobs $pprinters >> $strfile
792	status=$?
793
794	if test $status != 0; then
795		echo FAIL
796		fail=`expr $fail + 1`
797	else
798		echo PASS
799	fi
800done
801
802#
803# Restart the server...
804#
805
806echo $ac_n "Performing restart test: $ac_c"
807echo "" >>$strfile
808echo "`date '+[%d/%b/%Y:%H:%M:%S %z]'` \"5.10-restart\":" >>$strfile
809
810kill -HUP $cupsd
811
812while true; do
813	sleep 10
814
815	running=`$runcups ../systemv/lpstat -r 2>/dev/null`
816	if test "x$running" = "xscheduler is running"; then
817		break
818	fi
819done
820
821description="`$runcups ../systemv/lpstat -l -p Test1 | grep Description | sed -e '1,$s/^[^:]*: //g'`"
822if test "x$description" != "xTest Printer 1"; then
823	echo "Failed, printer-info for Test1 is '$description', expected 'Test Printer 1'." >>$strfile
824	echo "FAIL (got '$description', expected 'Test Printer 1')"
825	fail=`expr $fail + 1`
826else
827	echo "Passed." >>$strfile
828	echo PASS
829fi
830
831
832#
833# Perform job history test...
834#
835
836echo $ac_n "Starting history test: $ac_c"
837echo "" >>$strfile
838echo "`date '+[%d/%b/%Y:%H:%M:%S %z]'` \"5.11-history\":" >>$strfile
839
840echo "    lp -d Test1 testfile.jpg" >>$strfile
841
842$runcups ../systemv/lp -d Test1 ../examples/testfile.jpg 2>&1 >>$strfile
843if test $? != 0; then
844	echo "FAIL (unable to queue test job)"
845	echo "    FAILED" >>$strfile
846	fail=`expr $fail + 1`
847else
848	echo "PASS"
849	echo "    PASSED" >>$strfile
850
851	sleep 5
852	./waitjobs.sh >>$strfile
853
854        echo $ac_n "Verifying that history still exists: $ac_c"
855
856	echo "    ls -l $BASE/spool" >>$strfile
857	count=`ls -1 $BASE/spool | wc -l`
858	if test $count = 1; then
859		echo "FAIL (job control files not present)"
860		ls -l $BASE/spool
861		echo "    FAILED (job control files not present)" >>$strfile
862		ls -l $BASE/spool >>$strfile
863		fail=`expr $fail + 1`
864	else
865		echo "PASS"
866		echo "    PASSED" >>$strfile
867
868		echo $ac_n "Waiting for job history to expire: $ac_c"
869		echo "" >>$strfile
870		echo "    sleep 35" >>$strfile
871		sleep 35
872
873		echo "    lpstat" >>$strfile
874		$runcups ../systemv/lpstat 2>&1 >>$strfile
875
876		echo "    ls -l $BASE/spool" >>$strfile
877		count=`ls -1 $BASE/spool | wc -l`
878		if test $count != 1; then
879			echo "FAIL (job control files still present)"
880			ls -l $BASE/spool
881			echo "    FAILED (job control files still present)" >>$strfile
882			ls -l $BASE/spool >>$strfile
883			fail=`expr $fail + 1`
884		else
885			echo "PASS"
886			echo "    PASSED" >>$strfile
887		fi
888	fi
889fi
890
891
892#
893# Perform job history test with cupsd restart...
894#
895
896echo $ac_n "Starting history test with cupsd restart: $ac_c"
897echo "" >>$strfile
898echo "`date '+[%d/%b/%Y:%H:%M:%S %z]'` \"5.11-history-cupsd-restart\":" >>$strfile
899
900echo "    lp -d Test1 testfile.jpg" >>$strfile
901
902$runcups ../systemv/lp -d Test1 ../examples/testfile.jpg 2>&1 >>$strfile
903if test $? != 0; then
904	echo "FAIL (unable to queue test job)"
905	echo "    FAILED" >>$strfile
906	fail=`expr $fail + 1`
907else
908	echo "PASS"
909	echo "    PASSED" >>$strfile
910
911	sleep 5
912	./waitjobs.sh >>$strfile
913
914        echo $ac_n "Verifying that history still exists: $ac_c"
915
916	echo "    ls -l $BASE/spool" >>$strfile
917	count=`ls -1 $BASE/spool | wc -l`
918	if test $count = 1; then
919		echo "FAIL (job control files not present)"
920		ls -l $BASE/spool
921		echo "    FAILED (job control files not present)" >>$strfile
922		ls -l $BASE/spool >>$strfile
923		fail=`expr $fail + 1`
924	else
925		echo "PASS"
926		echo "    PASSED" >>$strfile
927
928		echo "Restarting cupsd:"
929		echo "" >>$strfile
930		kill $cupsd
931		wait $cupsd
932
933		echo "    $runcups $VALGRIND ../scheduler/cupsd -c $BASE/cupsd.conf -f >>$BASE/log/debug_log 2>&1 &"
934		echo ""
935
936		$runcups $VALGRIND ../scheduler/cupsd -c $BASE/cupsd.conf -f >>$BASE/log/debug_log 2>&1 &
937
938		cupsd=$!
939
940		echo $ac_n "Waiting for job history to expire: $ac_c"
941		echo "" >>$strfile
942		echo "    sleep 35" >>$strfile
943		sleep 35
944
945		echo "    ls -l $BASE/spool" >>$strfile
946		count=`ls -1 $BASE/spool | wc -l`
947		if test $count != 1; then
948			echo "FAIL (job control files still present)"
949			ls -l $BASE/spool
950			echo "    FAILED (job control files still present)" >>$strfile
951			ls -l $BASE/spool >>$strfile
952			fail=`expr $fail + 1`
953		else
954			echo "PASS"
955			echo "    PASSED" >>$strfile
956		fi
957	fi
958fi
959
960
961#
962# Stop the server...
963#
964
965echo "    </pre>" >>$strfile
966
967kill $cupsd
968wait $cupsd
969cupsdstatus=$?
970
971#
972# Verify counts...
973#
974
975echo "Test Summary"
976echo ""
977echo "    <h1><a name='SUMMARY'>3 - Test Summary</a></h1>" >>$strfile
978
979if test $cupsdstatus != 0; then
980	echo "FAIL: cupsd failed with exit status $cupsdstatus."
981	echo "    <p>FAIL: cupsd failed with exit status $cupsdstatus.</p>" >>$strfile
982	fail=`expr $fail + 1`
983else
984	echo "PASS: cupsd exited with no errors."
985	echo "    <p>PASS: cupsd exited with no errors.</p>" >>$strfile
986fi
987
988# Job control files
989count=`ls -1 $BASE/spool | wc -l`
990count=`expr $count - 1`
991if test $count != 0; then
992	echo "FAIL: $count job control files were not purged."
993	echo "    <p>FAIL: $count job control files were not purged.</p>" >>$strfile
994	fail=`expr $fail + 1`
995else
996	echo "PASS: All job control files purged."
997	echo "    <p>PASS: All job control files purged.</p>" >>$strfile
998fi
999
1000# Pages printed on Test1 (within 1 page for timing-dependent cancel issues)
1001count=`$GREP '^Test1 ' $BASE/log/page_log | awk 'BEGIN{count=0}{count=count+$7}END{print count}'`
1002# expected numbers of pages from page ranges tests:
1003# - 5 pages for the job with a lower limit undefined (-5)
1004# - 4 pages for the job with a upper limit undefined (5-)
1005expected=`expr $pjobs \* 2 + 34 + 5 + 4`
1006expected2=`expr $expected + 2`
1007if test $count -lt $expected -a $count -gt $expected2; then
1008	echo "FAIL: Printer 'Test1' produced $count page(s), expected $expected."
1009	echo "    <p>FAIL: Printer 'Test1' produced $count page(s), expected $expected.</p>" >>$strfile
1010	fail=`expr $fail + 1`
1011else
1012	echo "PASS: Printer 'Test1' correctly produced $count page(s)."
1013	echo "    <p>PASS: Printer 'Test1' correctly produced $count page(s).</p>" >>$strfile
1014fi
1015
1016# Paged printed on Test2
1017count=`$GREP '^Test2 ' $BASE/log/page_log | awk 'BEGIN{count=0}{count=count+$7}END{print count}'`
1018expected=`expr $pjobs \* 2 + 3`
1019if test $count != $expected; then
1020	echo "FAIL: Printer 'Test2' produced $count page(s), expected $expected."
1021	echo "    <p>FAIL: Printer 'Test2' produced $count page(s), expected $expected.</p>" >>$strfile
1022	fail=`expr $fail + 1`
1023else
1024	echo "PASS: Printer 'Test2' correctly produced $count page(s)."
1025	echo "    <p>PASS: Printer 'Test2' correctly produced $count page(s).</p>" >>$strfile
1026fi
1027
1028# Paged printed on Test3
1029count=`$GREP '^Test3 ' $BASE/log/page_log | awk 'BEGIN{count=0}{count=count+$7}END{print count}'`
1030expected=2
1031if test $count != $expected; then
1032	echo "FAIL: Printer 'Test3' produced $count page(s), expected $expected."
1033	echo "    <p>FAIL: Printer 'Test3' produced $count page(s), expected $expected.</p>" >>$strfile
1034	fail=`expr $fail + 1`
1035else
1036	echo "PASS: Printer 'Test3' correctly produced $count page(s)."
1037	echo "    <p>PASS: Printer 'Test3' correctly produced $count page(s).</p>" >>$strfile
1038fi
1039
1040# Number of requests from 5.1-lpadmin.sh: cupsSNMP/IPPSupplies tests - total 5 in 'expected':
1041# - 2 requests for creating a queue - CUPS-Get-PPD and CUPS-Add-Modify-Printer
1042# - 1 request for setting cupsSNMP/IPPSupplies to True - CUPS-Add-Modify-Printer
1043# - 1 request for setting cupsSNMP/IPPSupplies to False - CUPS-Add-Modify-Printer
1044# - 1 request for deleting the queue - CUPS-Delete-Printer
1045
1046# Number of requests related to undefined page range limits - total 4 in 'expected'
1047# 2 requests (Create-Job, Send-Document) * number of jobs (2 - one for undefined
1048# low limit, one for undefined upper limit)
1049
1050# Requests logged
1051count=`wc -l $BASE/log/access_log | awk '{print $1}'`
1052expected=`expr 35 + 18 + 30 + $pjobs \* 8 + $pprinters \* $pjobs \* 4 + 2 + 2 + 5 + 4`
1053if test $count != $expected; then
1054	echo "FAIL: $count requests logged, expected $expected."
1055	echo "    <p>FAIL: $count requests logged, expected $expected.</p>" >>$strfile
1056	fail=`expr $fail + 1`
1057else
1058	echo "PASS: $count requests logged."
1059	echo "    <p>PASS: $count requests logged.</p>" >>$strfile
1060fi
1061
1062# Did CUPS-Get-Default get logged?
1063if $GREP -q CUPS-Get-Default $BASE/log/access_log; then
1064	echo "FAIL: CUPS-Get-Default logged with 'AccessLogLevel actions'"
1065	echo "    <p>FAIL: CUPS-Get-Default logged with 'AccessLogLevel actions'</p>" >>$strfile
1066	echo "    <pre>" >>$strfile
1067	$GREP CUPS-Get-Default $BASE/log/access_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1068	echo "    </pre>" >>$strfile
1069	fail=`expr $fail + 1`
1070else
1071	echo "PASS: CUPS-Get-Default not logged."
1072	echo "    <p>PASS: CUPS-Get-Default not logged.</p>" >>$strfile
1073fi
1074
1075# Emergency log messages
1076count=`$GREP '^X ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1077if test $count != 0; then
1078	echo "FAIL: $count emergency messages, expected 0."
1079	$GREP '^X ' $BASE/log/error_log
1080	echo "    <p>FAIL: $count emergency messages, expected 0.</p>" >>$strfile
1081	echo "    <pre>" >>$strfile
1082	$GREP '^X ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1083	echo "    </pre>" >>$strfile
1084	fail=`expr $fail + 1`
1085else
1086	echo "PASS: $count emergency messages."
1087	echo "    <p>PASS: $count emergency messages.</p>" >>$strfile
1088fi
1089
1090# Alert log messages
1091count=`$GREP '^A ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1092if test $count != 0; then
1093	echo "FAIL: $count alert messages, expected 0."
1094	$GREP '^A ' $BASE/log/error_log
1095	echo "    <p>FAIL: $count alert messages, expected 0.</p>" >>$strfile
1096	echo "    <pre>" >>$strfile
1097	$GREP '^A ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1098	echo "    </pre>" >>$strfile
1099	fail=`expr $fail + 1`
1100else
1101	echo "PASS: $count alert messages."
1102	echo "    <p>PASS: $count alert messages.</p>" >>$strfile
1103fi
1104
1105# Critical log messages
1106count=`$GREP '^C ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1107if test $count != 0; then
1108	echo "FAIL: $count critical messages, expected 0."
1109	$GREP '^C ' $BASE/log/error_log
1110	echo "    <p>FAIL: $count critical messages, expected 0.</p>" >>$strfile
1111	echo "    <pre>" >>$strfile
1112	$GREP '^C ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1113	echo "    </pre>" >>$strfile
1114	fail=`expr $fail + 1`
1115else
1116	echo "PASS: $count critical messages."
1117	echo "    <p>PASS: $count critical messages.</p>" >>$strfile
1118fi
1119
1120# Error log messages
1121count=`$GREP '^E ' $BASE/log/error_log | $GREP -v 'Unknown default SystemGroup' | wc -l | awk '{print $1}'`
1122if test $count != 33; then
1123	echo "FAIL: $count error messages, expected 33."
1124	$GREP '^E ' $BASE/log/error_log
1125	echo "    <p>FAIL: $count error messages, expected 33.</p>" >>$strfile
1126	echo "    <pre>" >>$strfile
1127	$GREP '^E ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1128	echo "    </pre>" >>$strfile
1129	fail=`expr $fail + 1`
1130else
1131	echo "PASS: $count error messages."
1132	echo "    <p>PASS: $count error messages.</p>" >>$strfile
1133fi
1134
1135# Warning log messages
1136count=`$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}'`
1137if test $count != 14; then
1138	echo "FAIL: $count warning messages, expected 14."
1139	$GREP '^W ' $BASE/log/error_log
1140	echo "    <p>FAIL: $count warning messages, expected 14.</p>" >>$strfile
1141	echo "    <pre>" >>$strfile
1142	$GREP '^W ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1143	echo "    </pre>" >>$strfile
1144	fail=`expr $fail + 1`
1145else
1146	echo "PASS: $count warning messages."
1147	echo "    <p>PASS: $count warning messages.</p>" >>$strfile
1148fi
1149
1150# Notice log messages
1151count=`$GREP '^N ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1152if test $count != 0; then
1153	echo "FAIL: $count notice messages, expected 0."
1154	$GREP '^N ' $BASE/log/error_log
1155	echo "    <p>FAIL: $count notice messages, expected 0.</p>" >>$strfile
1156	echo "    <pre>" >>$strfile
1157	$GREP '^N ' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1158	echo "    </pre>" >>$strfile
1159	fail=`expr $fail + 1`
1160else
1161	echo "PASS: $count notice messages."
1162	echo "    <p>PASS: $count notice messages.</p>" >>$strfile
1163fi
1164
1165# Info log messages
1166count=`$GREP '^I ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1167if test $count = 0; then
1168	echo "FAIL: $count info messages, expected more than 0."
1169	echo "    <p>FAIL: $count info messages, expected more than 0.</p>" >>$strfile
1170	fail=`expr $fail + 1`
1171else
1172	echo "PASS: $count info messages."
1173	echo "    <p>PASS: $count info messages.</p>" >>$strfile
1174fi
1175
1176# Debug log messages
1177count=`$GREP '^D ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1178if test $count = 0; then
1179	echo "FAIL: $count debug messages, expected more than 0."
1180	echo "    <p>FAIL: $count debug messages, expected more than 0.</p>" >>$strfile
1181	fail=`expr $fail + 1`
1182else
1183	echo "PASS: $count debug messages."
1184	echo "    <p>PASS: $count debug messages.</p>" >>$strfile
1185fi
1186
1187# Debug2 log messages
1188count=`$GREP '^d ' $BASE/log/error_log | wc -l | awk '{print $1}'`
1189if test $count = 0 -a $loglevel = debug2; then
1190	echo "FAIL: $count debug2 messages, expected more than 0."
1191	echo "    <p>FAIL: $count debug2 messages, expected more than 0.</p>" >>$strfile
1192	fail=`expr $fail + 1`
1193elif test $count != 0 -a $loglevel = debug; then
1194	echo "FAIL: $count debug2 messages, expected 0."
1195	echo "    <p>FAIL: $count debug2 messages, expected 0.</p>" >>$strfile
1196	fail=`expr $fail + 1`
1197else
1198	echo "PASS: $count debug2 messages."
1199	echo "    <p>PASS: $count debug2 messages.</p>" >>$strfile
1200fi
1201
1202#
1203# Log files...
1204#
1205
1206echo "    <h1><a name='LOGS'>4 - Log Files</a></h1>" >>$strfile
1207
1208for file in $BASE/log/*_log; do
1209        baselog=`basename $file`
1210
1211        echo "    <h2><a name=\"$baselog\">$baselog</a></h2>" >>$strfile
1212        case $baselog in
1213                error_log)
1214                        echo "    <blockquote>Note: debug2 messages have been filtered out of the HTML report.</blockquote>" >>$strfile
1215                        echo "    <pre>" >>$strfile
1216                        $GREP -v '^d' $BASE/log/error_log | sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' >>$strfile
1217                        echo "    </pre>" >>$strfile
1218                        ;;
1219
1220                *)
1221                        echo "    <pre>" >>$strfile
1222                        sed -e '1,$s/&/&amp;/g' -e '1,$s/</&lt;/g' $file >>$strfile
1223                        echo "    </pre>" >>$strfile
1224                        ;;
1225        esac
1226done
1227
1228#
1229# Format the reports and tell the user where to find them...
1230#
1231
1232cat str-trailer.html >>$strfile
1233
1234echo ""
1235for file in $BASE/log/*_log; do
1236        baselog=`basename $file`
1237        cp $file $baselog-$date-$user
1238        echo "Copied log file \"$baselog-$date-$user\" to test directory."
1239done
1240cp $strfile .
1241echo "Copied report file \"cups-str-$date-$user.html\" to test directory."
1242
1243# Clean out old failure log files after 1 week...
1244find . -name \*_log-\*-$user -a -mtime +7 -print -exec rm -f '{}' \; | awk '{print "Removed old log file \"" substr($1,3) "\" from test directory."}'
1245find . -name cups-str-\*-$user.html -a -mtime +7 -print -exec rm -f '{}' \; | awk '{print "Removed old report file \"" $1 "\" from test directory."}'
1246
1247echo ""
1248
1249if test $fail != 0; then
1250	echo "$fail tests failed."
1251	exit 1
1252else
1253	echo "All tests were successful."
1254fi
1255