diff --git a/tests/lib.sh b/tests/lib.sh index df84145..cbf6496 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -3,6 +3,22 @@ . /usr/share/beakerlib/beakerlib.sh || exit 1 BU_TMPDIR_PARENT="${BU_TMPDIR_PARENT:-/tmp}" +BU_TEST_USER="${BU_TEST_USER:-buUser}" + + +function buEnterTestUser () { + username="${1:-$BU_TEST_USER}" + + rlRun "userdel -r $username" 0,6 + rlRun "useradd -m -d /home/$username $username" +} + + +function buExitTestUser () { + username="${1:-$BU_TEST_USER}" + + rlRun "userdel -r $username" +} function buTestHeader () { @@ -20,6 +36,7 @@ function buTestHeader () { rlLogInfo "LD=$_LD" rlLogInfo "GCC=$_GCC" rlLogInfo "BU_TMPDIR_PARENT=$BU_TMPDIR_PARENT" + rlLogInfo "BU_AS_TEST_USER=$BU_AS_TEST_USER" rlAssertRpm --all @@ -49,15 +66,31 @@ function buTestHeader () { function buEnterTmpDir () { rlRun "export TmpDir=$(mktemp -d -p $BU_TMPDIR_PARENT)" 0 "Creating tmp directory" + + if [ ! -z "$BU_AS_TEST_USER" ]; then + username="${1:-$BU_TEST_USER}" + + buEnterTestUser "$username" + + rlRun "chown -R $username $TmpDir" + fi + rlRun "pushd $TmpDir" } + function buExitTmpDir () { rlRun "popd" if [ -z "$PRESERVE_TMPDIR" ]; then rlRun "rm -r $TmpDir" 0 "Removing tmp directory" fi + + if [ ! -z "$BU_AS_TEST_USER" ]; then + username="${1:-$BU_TEST_USER}" + + buExitTestUser "$username" + fi } @@ -73,10 +106,16 @@ function buPrepareSRPM () { rlRun "export SPECDIR=`rpm --define=\"_topdir $TmpDir\" --eval=%_specdir`" rlRun "export SPECFILE=`find $SPECDIR/ -name '*.spec'`" - rlRun "yum-builddep -y $builddep_options $SPECFILE" + rlRun "yum-builddep -y --define=\"_topdir $TmpDir\" $builddep_options $SPECFILE" } function buBuildSRPM () { - rlRun "rpmbuild -bb --define='_topdir $TmpDir' $SPECFILE" + if [ ! -z "$BU_AS_TEST_USER" ]; then + username="${1:-$BU_TEST_USER}" + + rlRun "su - $username -c 'rpmbuild -bb --define=\"_topdir $TmpDir\" $SPECFILE'" + else + rlRun " rpmbuild -bb --define=\"_topdir $TmpDir\" $SPECFILE" + fi } diff --git a/tests/rebuild-coreutils/main.fmf b/tests/rebuild-coreutils/main.fmf new file mode 100644 index 0000000..3e424a2 --- /dev/null +++ b/tests/rebuild-coreutils/main.fmf @@ -0,0 +1,10 @@ +summary: Rebuild coreutils +description: '' +tag: + - gate-build +duration: 1h + +# Configurable fields +require+: + - coreutils + - rpm-build diff --git a/tests/rebuild-coreutils/test.sh b/tests/rebuild-coreutils/test.sh new file mode 100755 index 0000000..7d99439 --- /dev/null +++ b/tests/rebuild-coreutils/test.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Description: Rebuild coreutils +# +# Author: Milos Prchlik +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# 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/share/beakerlib/beakerlib.sh || exit 1 + +. "$TMT_TREE/tests/lib.sh" || exit 1 + +export BU_AS_TEST_USER=yes + +rlJournalStart + rlPhaseStartSetup + buTestHeader + + buEnterTmpDir + + buPrepareSRPM "coreutils" + rlPhaseEnd + + rlPhaseStartTest + # TODO: maybe this will be needed for RHEL7 + # rlRun "FORCE_UNSAFE_CONFIGURE=0" + # rlIsRHEL 7 && rlRun "FORCE_UNSAFE_CONFIGURE=1" + # rlRun "FORCE_UNSAFE_CONFIGURE=$FORCE_UNSAFE_CONFIGURE rpmbuild -bb --clean $SRPM_SPECDIR/coreutils.spec" + + buBuildSRPM + rlPhaseEnd + + rlPhaseStartCleanup + buExitTmpDir + rlPhaseEnd +rlJournalPrintText +rlJournalEnd