#!/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"
if rlIsRHEL '>7'; then
DISABLE_TESTS="filerem01"
fi
testsuite_flags=
if test -n "$DISABLE_TESTS"; then
testsuite_flags="-k "
for the_test in $DISABLE_TESTS; do
testsuite_flags="$testsuite_flags!$the_test,"
done
fi
install_build_deps()
{
if rlIsFedora; then
rlRun "dnf -y builddep $*"
elif rlIsRHEL; then
packages="libacl-devel libselinux-devel"
if rlIsRHEL '>7'; then
# TODO: remove once 'texinfo' is in AppStream
packages+=" texinfo"
# TODO: rmove once we have CRB available
enable_repo="--enablerepo rhel-CRB"
if grep -rq beaker-CRB /etc/yum.repos.d/; then
enable_repo="--enablerepo beaker-CRB"
fi
fi
yum $enable_repo -y install $packages
fi
}
rlJournalStart
rlPhaseStartSetup
test -n "$testsuite_flags" && rlLog "using special testsuite flags: $testsuite_flags"
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 TESTSUITEFLAGS='$testsuite_flags'\""
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 $testsuite_flags"
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