Blame tar-testsuite/runtest.sh

b417179
#!/bin/bash
b417179
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
b417179
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b417179
#
b417179
#   runtest.sh of /CoreOS/tar/Regression/tar-testsuite
b417179
#   Description: TAR testsuite
b417179
#   Author: Branislav Blaskovic <bblaskov@redhat.com>
b417179
#
b417179
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b417179
#
1d6439d
#   Copyright (c) 2012, 2019 Red Hat, Inc. All rights reserved.
b417179
#
b417179
#   This copyrighted material is made available to anyone wishing
b417179
#   to use, modify, copy, or redistribute it subject to the terms
b417179
#   and conditions of the GNU General Public License version 2.
b417179
#
b417179
#   This program is distributed in the hope that it will be
b417179
#   useful, but WITHOUT ANY WARRANTY; without even the implied
b417179
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
b417179
#   PURPOSE. See the GNU General Public License for more details.
b417179
#
b417179
#   You should have received a copy of the GNU General Public
b417179
#   License along with this program; if not, write to the Free
b417179
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
b417179
#   Boston, MA 02110-1301, USA.
b417179
#
b417179
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b417179
b417179
# Include Beaker environment
b417179
. /usr/bin/rhts-environment.sh
b417179
. /usr/lib/beakerlib/beakerlib.sh
b417179
b417179
PACKAGE="tar"
b417179
TESTUSER="tar-testsuite"
b417179
a348706
install_build_deps()
a348706
{
a348706
    if rlIsFedora || rlIsRHEL '>7'; then
a348706
        rlIsRHEL 8 && additional_repo='--enablerepo rhel-buildroot'
a348706
        rlRun "dnf -y $additional_repo builddep $*"
a348706
    else
a348706
        # WARNING: yum-builddep doesn't work on RHEL5 as we would expect from
a348706
        # modern RHEL/Fedora distributions.  Only "package names" are accepted,
a348706
        # not SRPMs or SPEC files.  On RHEL6 this seems to work fine with SRPMs
a348706
        # only.
a348706
        rlRun "yum-builddep -y $*"
a348706
    fi
a348706
}
a348706
b417179
rlJournalStart
b417179
    rlPhaseStartSetup
b417179
        rlAssertRpm $PACKAGE
b417179
        rlRun "useradd $TESTUSER"
b417179
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
b417179
        rlRun "chmod -R 777 $TmpDir"
b417179
        rlRun "pushd $TmpDir"
a348706
        if rlIsRHEL 5; then
a348706
            fix_rpm='echo %_topdir $HOME > $HOME/.rpmmacros'
a348706
            rlRun "su - $TESTUSER -c '$fix_rpm'"
a348706
            # on RHEL5, this isn't create automatically for some reason
a348706
            rlRun "su - $TESTUSER -c 'mkdir \$HOME/BUILD'"
a348706
        fi
b417179
    rlPhaseEnd
b417179
b417179
    rlPhaseStartTest
b417179
b417179
        # Getting archive
b417179
        rlFetchSrcForInstalled $PACKAGE
b417179
        VERSION=`ls -1 *.src.rpm | head -1 | sed 's/tar-\([0-9.]*\).*src.rpm/\1/'`
b417179
        RPM_NAME=`ls -1 *.src.rpm | head -1`
1d6439d
        RPM_FULL_NAME=`readlink -f $RPM_NAME`
a348706
        TOPDIR=$(su - "$TESTUSER" -c 'rpm --eval %_topdir')
a348706
        SPECFILE=$TOPDIR/SPECS/tar.spec
a348706
        BUILDDIR=$TOPDIR/BUILD/tar-$VERSION
b417179
b417179
        rlRun "chmod -R 777 $TmpDir"
b417179
b417179
        if [ -f "$RPM_NAME" ];then
1d6439d
            # Extract SRPM
1d6439d
            rlRun "su $TESTUSER -c \"rpm -i $RPM_FULL_NAME\""
b417179
b417179
            # Print some info
b417179
            rlLog "RPM name: $RPM_NAME"
b417179
            rlLog "Version: $VERSION"
b417179
b417179
            # Dependencies
a348706
            install_build_deps tar
b417179
b417179
            # Building
1d6439d
            rlRun -s "su $TESTUSER -c \"rpmbuild -bc $SPECFILE\""
b417179
            rlRun "mv $rlRun_LOG $TmpDir/rpmbuild.log"
b417179
b417179
            # Using system /bin/tar for testsuite
a348706
            wrapper='export PATH=/bin ; exec tar "$@"'
1d6439d
            wrapper=`printf "%q" "$wrapper"`
1d6439d
            rlRun "echo $wrapper > $BUILDDIR/src/tar"
b417179
1d6439d
            # Starting testsuite (as regular user)
b417179
            rlLog "Starting testsuite!"
1d6439d
            # we need 'make check' to build tools like 'genfile', etc.
1d6439d
            rlRun -s "su $TESTUSER -c \"cd $BUILDDIR && make check\""
b417179
            rlRun "mv $rlRun_LOG $TmpDir/testsuite.log"
b417179
1d6439d
            print_stats ()
1d6439d
            {
1d6439d
                # Grep fails from logs
1d6439d
                while read line
1d6439d
                do
1d6439d
                    echo "$line" | grep "[0-9]\{0,\}:.*FAILED (" && rlFail "$line"
1d6439d
                done < $1
1d6439d
1d6439d
                # Data from stderr
1d6439d
                SKIPPED=`grep "[0-9]\{0,3\} tests were skipped" $1`
1d6439d
                if [ `echo $SKIPPED | wc -l` -eq 1 ];then
1d6439d
                    rlLog "$SKIPPED"
1d6439d
                fi
1d6439d
            }
1d6439d
1d6439d
            print_stats "$TmpDir/testsuite.log"
1d6439d
1d6439d
            rlLog "Starting ROOT testsuite!"
1d6439d
            # make check is not needed anymore
1d6439d
            rlRun -s "cd $BUILDDIR/tests && ./testsuite"
1d6439d
            rlRun "mv $rlRun_LOG $TmpDir/testsuite_root.log"
1d6439d
1d6439d
            print_stats "$TmpDir/testsuite_root.log"
1d6439d
1d6439d
            lines=`wc -l $BUILDDIR/src/tar`
1d6439d
            rlAssertO "check that we did not remove the wrapper mistakenly" "$lines"
1d6439d
b417179
        else
b417179
b417179
            rlFail "No src RPM downloaded."
b417179
b417179
        fi
b417179
b417179
    rlPhaseEnd
b417179
b417179
    rlPhaseStartCleanup
b417179
        rlRun "cd $TmpDir"
b417179
        rlBundleLogs "tar-testsuite-logs" "testsuite.log" "rpm-install.log" "rpmbuild.log" "yum-install.log"
b417179
        rlRun "popd"
b417179
        rlRun "userdel -r $TESTUSER"
b417179
        rlRun "rm -rf $TmpDir" 0 "Removing tmp directory"
b417179
    rlPhaseEnd
b417179
rlJournalPrintText
b417179
rlJournalEnd