Blame tests/Run-internal-BIND-test-suite/runtest.sh

8da017
#!/bin/bash
8da017
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
8da017
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8da017
#
8da017
#   runtest.sh of tests/Run-internal-BIND-test-suite
8da017
#   Description: Run internal BIND test suite
8da017
#   Author: Martin Cermak <mcermak@redhat.com>
8da017
#
8da017
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8da017
#
8da017
#   Copyright (c) 2010 Red Hat, Inc. All rights reserved.
8da017
#
8da017
#   This copyrighted material is made available to anyone wishing
8da017
#   to use, modify, copy, or redistribute it subject to the terms
8da017
#   and conditions of the GNU General Public License version 2.
8da017
#
8da017
#   This program is distributed in the hope that it will be
8da017
#   useful, but WITHOUT ANY WARRANTY; without even the implied
8da017
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8da017
#   PURPOSE. See the GNU General Public License for more details.
8da017
#
8da017
#   You should have received a copy of the GNU General Public
8da017
#   License along with this program; if not, write to the Free
8da017
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
8da017
#   Boston, MA 02110-1301, USA.
8da017
#
8da017
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8da017
8da017
# Include rhts environment
8da017
. /usr/bin/rhts-environment.sh
8da017
. /usr/lib/beakerlib/beakerlib.sh
8da017
8da017
PACKAGE="bind"
8da017
8da017
rlJournalStart
8da017
    rlPhaseStartSetup
8da017
        # package assertions
8da017
        rlAssertRpm $PACKAGE 
8da017
        rlAssertRpm rpm-build
8da017
        rlAssertRpm perl-Net-DNS-Nameserver
8da017
8da017
	#pwd
8da017
	ORIG=`pwd`
8da017
	FOUNDERROR=`mktemp`
8da017
	SETUP_SOFTHSM=`readlink -f setup-named-softhsm.sh`
8da017
	FILTER=`readlink -f bind-systest-filter.sh`
8da017
8da017
	TAG=generic
8da017
	if [ -f /etc/os-release ]; then
8da017
		# extract platform tag
8da017
		TAG=`(source /etc/os-release && echo ${PLATFORM_ID#platform:})`
8da017
	fi
8da017
8da017
	if [ -f "knownerror.$TAG" ]; then
8da017
		KNOWNERROR=`readlink -f knownerror.$TAG`
8da017
	elif [ -f "knownerror" ]; then
8da017
		KNOWNERROR=`readlink -f knownerror`
8da017
	fi
8da017
8da017
        #tempdir
8da017
        rlRun "TMPDIR=\`mktemp -d\`" 0 "Creating tmp directory"
8da017
        rlRun "pushd $TMPDIR"
8da017
8da017
        # topdir
8da017
	TOPDIR=`rpm -E '%{_topdir}'`
8da017
8da017
        # cleanup in topdir
8da017
        mkdir -p $TOPDIR/{BUILD,SOURCES,SPECS}
8da017
        rm -rf $TOPDIR/{BUILD,SOURCES,SPECS}/*
8da017
8da017
        # download src rpm
8da017
	if ! ls bind*.src.rpm; then
8da017
		rlRun "dnf --enablerepo='*-source' download bind.src" 0 "Fetch source from repository"
8da017
		rlRun "rpm -i bind*.src.rpm"
8da017
	fi
8da017
	
8da017
        rlRun "rpm --define '_topdir $TOPDIR' -Uvh *rpm &> $TMPDIR/install.txt"
8da017
        rlRun "cd $TOPDIR/SPECS" 
8da017
8da017
	rlRun "dnf -y builddep *.spec"
8da017
8da017
        # stop bind if it is running
8da017
        rlServiceStop named
8da017
    rlPhaseEnd
8da017
8da017
    rlPhaseStartTest
8da017
        # rebuild from source
8da017
        rlRun "rpmbuild -ba *.spec &> $TMPDIR/build.txt"
8da017
8da017
        # the test
8da017
        rlRun "cd $TOPDIR/BUILD/bind*"
8da017
8da017
        rlLogInfo "Test takes place in `pwd`"
8da017
8da017
        rlRun "chown -R root ."
8da017
8da017
	if [ -x "$SETUP_SOFTHSM" ]; then
8da017
		rlRun "eval \"$(bash $SETUP_SOFTHSM -A)\"" 0 "Preparing PKCS#11 token slot"
8da017
		rlRun "pkcs11-tokens" 0 "Testing token slot availability"
8da017
	else
8da017
		rlLog "PKCS#11 not initialized"
8da017
	fi
8da017
8da017
	if [ -d build ]; then
8da017
		BUILD=build
8da017
	else
8da017
		BUILD=.
8da017
	fi
8da017
8da017
        rlRun "./bin/tests/system/ifconfig.sh up" 0 "Setup fake network interfaces."
8da017
8da017
	# required by idna test 
8da017
	export LC_ALL=en_US.UTF-8
8da017
8da017
        rlRun "pushd $BUILD"
8da017
        rlRun "make test &> $TMPDIR/test.txt" 0-255 "Perform the test."
8da017
        rlRun "popd"
8da017
8da017
        rlRun "grep -C 10 FAIL $TMPDIR/test.txt" 0-255 "Quickly show the test error (if any)."
8da017
8da017
        rlRun "./bin/tests/system/ifconfig.sh down" 0 "Remove fake network interfaces."
8da017
8da017
8da017
	#list of failures:
8da017
	rlRun "$FILTER $TMPDIR/test.txt" 0 "Showing unsuccessful tests"
8da017
	rlRun "$FILTER -s $TMPDIR/test.txt > $FOUNDERROR" 0
8da017
	rlRun "ls $KNOWNERROR $FOUNDERROR $TMPDIR/test.txt" 0 'check if there is needed files'
8da017
	rlLog "`cat $FOUNDERROR`"
8da017
8da017
	rlAssertLesserOrEqual "Checking number of found errors is in limits" "$(grep '^FAIL' $FOUNDERROR | wc -l)" "$(wc -l <$KNOWNERROR)"
8da017
        cat $FOUNDERROR | while read STATUS TEST ; do
8da017
		if [ "$STATUS" = FAIL ]; then
8da017
			rlRun "grep '$TEST' $KNOWNERROR" 0 "Check $TEST failure is expected"
8da017
		else
8da017
			rlLog "$STATUS $TEST"
8da017
		fi
8da017
        done
8da017
    rlPhaseEnd
8da017
8da017
    rlPhaseStartCleanup
8da017
        rlBundleLogs "TEST_LOGS" "$TMPDIR/install.txt" "$TMPDIR/builddeps.txt" "$TMPDIR/build.txt" "$TMPDIR/test.txt"
8da017
        rlRun "popd"
8da017
        rlRun "rm -r $TMPDIR" 0 "Removing tmp directory"
8da017
	rlRun "rm -rf $FOUNDERROR"
8da017
    rlPhaseEnd
8da017
rlJournalEnd