Blob Blame History Raw
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of tests/Run-internal-BIND-test-suite
#   Description: Run internal BIND test suite
#   Author: Martin Cermak <mcermak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2010 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 rhts environment
. /usr/bin/rhts-environment.sh
. /usr/lib/beakerlib/beakerlib.sh

PACKAGE="bind"

rlJournalStart
    rlPhaseStartSetup
        # package assertions
        rlAssertRpm $PACKAGE 
        rlAssertRpm rpm-build
        rlAssertRpm perl-Net-DNS-Nameserver

	#pwd
	ORIG=`pwd`
	FOUNDERROR=`mktemp`
	SETUP_SOFTHSM=`readlink -f setup-named-softhsm.sh`
	FILTER=`readlink -f bind-systest-filter.sh`

	TAG=generic
	if [ -f /etc/os-release ]; then
		# extract platform tag
		TAG=`(source /etc/os-release && echo ${PLATFORM_ID#platform:})`
	fi

	if [ -f "knownerror.$TAG" ]; then
		KNOWNERROR=`readlink -f knownerror.$TAG`
	elif [ -f "knownerror" ]; then
		KNOWNERROR=`readlink -f knownerror`
	fi

        #tempdir
        rlRun "TMPDIR=\`mktemp -d\`" 0 "Creating tmp directory"
        rlRun "pushd $TMPDIR"

        # topdir
	TOPDIR=`rpm -E '%{_topdir}'`

        # cleanup in topdir
        mkdir -p $TOPDIR/{BUILD,SOURCES,SPECS}
        rm -rf $TOPDIR/{BUILD,SOURCES,SPECS}/*

        # download src rpm
	if ! ls bind*.src.rpm; then
		rlRun "dnf --enablerepo='*-source' download --source bind" 0 "Fetch source from repository"
		rlRun "rpm -i bind*.src.rpm"
	fi
	
        rlRun "rpm --define '_topdir $TOPDIR' -Uvh *rpm &> $TMPDIR/install.txt"
        rlRun "cd $TOPDIR/SPECS" 

	rlRun "dnf -y builddep *.spec"

        # stop bind if it is running
        rlServiceStop named
    rlPhaseEnd

    rlPhaseStartTest
        # rebuild from source
        rlRun "rpmbuild -ba *.spec &> $TMPDIR/build.txt"

        # the test
        rlRun "cd $TOPDIR/BUILD/bind*"

        rlLogInfo "Test takes place in `pwd`"

        rlRun "chown -R root ."

	if [ -x "$SETUP_SOFTHSM" ]; then
		rlRun "eval \"$(bash $SETUP_SOFTHSM -A)\"" 0 "Preparing PKCS#11 token slot"
		rlRun "pkcs11-tokens" 0 "Testing token slot availability"
	else
		rlLog "PKCS#11 not initialized"
	fi

	if [ -d build ]; then
		BUILD=build
	else
		BUILD=.
	fi

        rlRun "./bin/tests/system/ifconfig.sh up" 0 "Setup fake network interfaces."

	# required by idna test 
	export LC_ALL=en_US.UTF-8

        rlRun "pushd $BUILD"
        rlRun "make test &> $TMPDIR/test.txt" 0-255 "Perform the test."
        rlRun "popd"

        rlRun "grep -C 10 FAIL $TMPDIR/test.txt" 0-255 "Quickly show the test error (if any)."

        rlRun "./bin/tests/system/ifconfig.sh down" 0 "Remove fake network interfaces."


	#list of failures:
	rlRun "$FILTER $TMPDIR/test.txt" 0 "Showing unsuccessful tests"
	rlRun "$FILTER -s $TMPDIR/test.txt > $FOUNDERROR" 0
	rlRun "ls $KNOWNERROR $FOUNDERROR $TMPDIR/test.txt" 0 'check if there is needed files'
	rlLog "`cat $FOUNDERROR`"

	rlAssertLesserOrEqual "Checking number of found errors is in limits" "$(grep '^FAIL' $FOUNDERROR | wc -l)" "$(wc -l <$KNOWNERROR)"
        cat $FOUNDERROR | while read STATUS TEST ; do
		if [ "$STATUS" = FAIL ]; then
			rlRun "grep '$TEST' $KNOWNERROR" 0 "Check $TEST failure is expected"
		else
			rlLog "$STATUS $TEST"
		fi
        done
    rlPhaseEnd

    rlPhaseStartCleanup
        rlBundleLogs "TEST_LOGS" "$TMPDIR/install.txt" "$TMPDIR/builddeps.txt" "$TMPDIR/build.txt" "$TMPDIR/test.txt"
        rlRun "popd"
        rlRun "rm -r $TMPDIR" 0 "Removing tmp directory"
	rlRun "rm -rf $FOUNDERROR"
    rlPhaseEnd
rlJournalEnd