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