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