#!/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 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"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "useradd $TESTUSER"
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "chmod -R 777 $TmpDir"
rlRun "pushd $TmpDir"
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`
rlRun "chmod -R 777 $TmpDir"
if [ -f "$RPM_NAME" ];then
# Get folders
HOME_DIR=$(awk -F: -v v="$TESTUSER" '{if ($1==v) print $6}' /etc/passwd)
rlRun "su $TESTUSER -c \"mkdir -p $HOME_DIR/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}\""
SPECDIR=$(su $TESTUSER -c "rpm --define '_topdir $HOME_DIR/rpmbuild' --eval %{_specdir}")
BUILDDIR=$(su $TESTUSER -c "rpm --define '_topdir $HOME_DIR/rpmbuild' --eval %{_builddir}")
# Print some info
rlLog "RPM name: $RPM_NAME"
rlLog "Version: $VERSION"
rlLog "Spec Dir: $SPECDIR"
rlLog "Build Dir: $BUILDDIR"
# Installing RPM
rlRun -s "su $TESTUSER -c \"rpm --define '_topdir $HOME_DIR/rpmbuild' -Uvh $TmpDir/$RPM_NAME\""
rlRun "mv $rlRun_LOG $TmpDir/rpm-install.log"
# Dependencies
REQ=""
for i in `yum deplist $RPM_NAME 2>/dev/null | grep "dependency:" | awk '/dependency:/ {print $2}'`; do REQ="$REQ $i"; done
if [ ! -z "$REQ" ]; then
yum -y install $REQ 2>&1 >> $TmpDir/yum-install.log
rlRun "rpm -q $REQ"
else
rlLog "Build dependencies satisfied."
fi
# Building
rlRun -s "su $TESTUSER -c \"rpmbuild --define '_topdir $HOME_DIR/rpmbuild' -ba $SPECDIR/tar.spec\""
rlRun "mv $rlRun_LOG $TmpDir/rpmbuild.log"
# Using system /bin/tar for testsuite
rlRun "cd $BUILDDIR/tar-$VERSION"
rlRun "rm -f src/tar"
# Starting testsuite on /bin/tar
rlLog "Starting testsuite!"
rlRun "su $TESTUSER -c \"ln -s /bin/tar src/tar\""
rlRun -s "su $TESTUSER -c \"cd $BUILDDIR/tar-$VERSION/tests && ./testsuite\""
rlRun "mv $rlRun_LOG $TmpDir/testsuite.log"
# Grep fails from logs
while read line
do
echo "$line" | grep "[0-9]\{0,\}:.*FAILED (" && rlFail "$line"
done < $TmpDir/testsuite.log
# Data from stderr
SKIPPED=`grep "[0-9]\{0,3\} tests were skipped" $TmpDir/testsuite.log`
if [ `echo $SKIPPED | wc -l` -eq 1 ];then
rlLog "$SKIPPED"
fi
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