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
545e2c
# Set those variables to n to skip tests on variants
277938
#DEFAULT_VARIANTS="normal pkcs11 sdb"
277938
DEFAULT_VARIANTS="normal"
545e2c
#TEST_VARIANTS="normal"
545e2c
0983c9
#
0983c9
# Runs test suite and checks known errors
0983c9
# Prepared to be repeated with another variants
0983c9
run_testsuite()
0983c9
{
0983c9
	local RESULT_TEXT="$TMPDIR/test${NAMED_VARIANT}.txt"
0983c9
	local FOUNDERROR=`mktemp found-XXXXXXXX.err`
545e2c
	local KNOWNERROR=/dev/null
0983c9
0983c9
	if [ -f "$ORIG/knownerror${NAMED_VARIANT}.$TAG" ]; then
0983c9
		KNOWNERROR=`readlink -f $ORIG/knownerror.$TAG`
0983c9
	elif [ -f "$ORIG/knownerror${NAMED_VARIANT}" ]; then
0983c9
		KNOWNERROR=`readlink -f $ORIG/knownerror`
0983c9
	fi
0983c9
0983c9
	# Sometime it can fail. Report just failures that are not known
0983c9
        rlRun "make test -j${CORES:-1} &> $RESULT_TEXT" 0-255 "Perform the test."
0983c9
        rlRun "grep -C 10 FAIL $RESULT_TEXT" 0-255 "Quickly show the test error (if any)."
0983c9
0983c9
	rlRun "$FILTER $RESULT_TEXT" 0 "Showing unsuccessful tests"
0983c9
	rlRun "$FILTER -s $RESULT_TEXT > $FOUNDERROR" 0
0983c9
	rlRun "ls $KNOWNERROR $FOUNDERROR $RESULT_TEXT" 0 'check if there is needed files'
0983c9
	rlLog "`cat $FOUNDERROR`"
0983c9
0983c9
	rlAssertLesserOrEqual "Checking number of found errors is in limits" "$(grep '^FAIL' $FOUNDERROR | wc -l)" "$(wc -l <$KNOWNERROR)"
0983c9
        cat $FOUNDERROR | while read STATUS TEST ; do
0983c9
		if [ "$STATUS" = FAIL ]; then
0983c9
			rlRun "grep '$TEST' $KNOWNERROR" 0 "Check $TEST failure is expected"
0983c9
		else
0983c9
			rlLog "$STATUS $TEST"
0983c9
		fi
0983c9
        done
0983c9
}
0983c9
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
	SETUP_SOFTHSM=`readlink -f setup-named-softhsm.sh`
8da017
	FILTER=`readlink -f bind-systest-filter.sh`
0983c9
	CORES=`grep 'processor\s*:' /proc/cpuinfo | wc -l`
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
        #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
5691e0
		rlRun "dnf --enablerepo='*-source' download --source bind" 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
545e2c
	if echo "${TEST_VARIANTS:-$DEFAULT_VARIANTS}" | grep -q normal; then
545e2c
		rlLog "Running normal variant"
545e2c
		export NAMED_VARIANT= DNSSEC_VARIANT=
545e2c
		run_testsuite
54fa84
		rlLog "Finished normal variant"
545e2c
	fi
8da017
545e2c
	if echo "${TEST_VARIANTS:-$DEFAULT_VARIANTS}" | grep -q sdb; then
545e2c
		rlLog "Running sdb variant"
545e2c
		export NAMED_VARIANT=-sdb DNSSEC_VARIANT=
545e2c
		run_testsuite
54fa84
		rlLog "Finished sdb variant"
545e2c
	fi
8da017
545e2c
	if echo "${TEST_VARIANTS:-$DEFAULT_VARIANTS}" | grep -q pkcs11; then
545e2c
		rlLog "Running pkcs11 variant"
545e2c
		# Unfortunately, PKCS11 variant uses shared key storage
545e2c
		# It cannot use more threads for that reason
545e2c
		export NAMED_VARIANT=-pkcs11 DNSSEC_VARIANT=-pkcs11
545e2c
		CORES=1 run_testsuite
54fa84
		rlLog "Finished pkcs11 variant"
545e2c
	fi
8da017
0983c9
        rlRun "popd"
0983c9
0983c9
        rlRun "./bin/tests/system/ifconfig.sh down" 0 "Remove fake network interfaces."
8da017
8da017
    rlPhaseEnd
8da017
8da017
    rlPhaseStartCleanup
0983c9
        rlBundleLogs "BUILD_LOGS" "$TMPDIR/install.txt" "$TMPDIR/builddeps.txt" "$TMPDIR/build.txt"
0983c9
        rlBundleLogs "TEST_LOGS" "$TMPDIR"/test*.txt
8da017
        rlRun "popd"
8da017
        rlRun "rm -r $TMPDIR" 0 "Removing tmp directory"
8da017
    rlPhaseEnd
8da017
rlJournalEnd