#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/cups/Regression/bz1677440-pstops-doesn-t-clean-up-after-SIGPIPE-floods
# Description: Test for BZ#1677440 (pstops doesn't clean up after SIGPIPE -- floods)
# Author: Zdenek Dohnal <zdohnal@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="cups"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlServiceStart cups
rlPhaseEnd
rlPhaseStartTest
rlRun "lpadmin -p broken -m drv:///sample.drv/generic.ppd -v socket://broken/ -o printer-error-policy=retry-current-job -E" 0 "Create non-functional printer."
rlRun "lp -d broken -n 2 -o Collate /etc/fstab" 0 "Print /etc/fstab in two copies collated."
rlRun "sleep 10" 0 "Wait 10 seconds."
rlRun "cancel -a" 0 "Cancel all jobs."
# We have clean directory only on RHEL 6, CUPS on newer RHELs perserves
# job files for one day by default, so there will be several files
# in the directory.
rlAssertLesserOrEqual "There should be only a few files in /var/spool/cups/tmp" `ls -l /var/spool/cups/tmp | wc -l` 5
rlPhaseEnd
rlPhaseStartCleanup
rlRun "rm -f /var/spool/cups/tmp/*" 0 "Clean cups tmp dir."
rlServiceStop cups
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd