Blame Sanity/upstream-testsuite/runtest.sh

75dc730
#!/bin/bash
75dc730
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
75dc730
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75dc730
#
75dc730
#   runtest.sh of /CoreOS/memcached/Sanity/upstream-testsuite
75dc730
#   Description: Runs upstream testsuite built into src.rpm
75dc730
#   Author: Ondrej Mejzlik <omejzlik@redhat.com>
75dc730
#
75dc730
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75dc730
#
75dc730
#   Copyright (c) 2019 Red Hat, Inc.
75dc730
#
75dc730
#   This program is free software: you can redistribute it and/or
75dc730
#   modify it under the terms of the GNU General Public License as
75dc730
#   published by the Free Software Foundation, either version 2 of
75dc730
#   the License, or (at your option) any later version.
75dc730
#
75dc730
#   This program is distributed in the hope that it will be
75dc730
#   useful, but WITHOUT ANY WARRANTY; without even the implied
75dc730
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
75dc730
#   PURPOSE.  See the GNU General Public License for more details.
75dc730
#
75dc730
#   You should have received a copy of the GNU General Public License
75dc730
#   along with this program. If not, see http://www.gnu.org/licenses/.
75dc730
#
75dc730
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75dc730
75dc730
# Include Beaker environment
75dc730
. /usr/bin/rhts-environment.sh || exit 1
75dc730
. /usr/share/beakerlib/beakerlib.sh || exit 1
75dc730
75dc730
PACKAGE=${PACKAGE:-memcached}
75dc730
75dc730
# NOTE: if you want to test scratch build in 1minutetip then enable repo containing
75dc730
# src.rpm and use $ declare -x BEAKERLIB_RPM_DOWNLOAD_METHODS="yum direct"
75dc730
# so that rlFetchSrcForInstalled downloads src rpm from your repository
75dc730
75dc730
#how many times to repeat?
75dc730
REPEAT=2
75dc730
75dc730
#how many pass is OK 
75dc730
OK=1
75dc730
run_and_verify_tests() {
75dc730
   MAKETEST=0
75dc730
   for r in `seq 1 $REPEAT`;do
75dc730
	rlLog "================================================================"
75dc730
	rlLog "================  running $r / $REPEAT  ========================"
75dc730
        rlRun "sleep 10" 0 "Wait to calm down CPU"
75dc730
	make test &> test.log.$r
75dc730
	if [ "$?" = "0" ]; then
75dc730
		rlLog "make test PASSed"
75dc730
		let "MAKETEST=MAKETEST+1"
75dc730
	else
75dc730
		rlLog "make test FAILed"
75dc730
		#rlFail "make test fail"
75dc730
		wall TEST_FAIL_EXPECTED
75dc730
	fi
75dc730
	rlLog "`echo;grep 'All tests successful' test.log.$r`"
75dc730
	rlLog "`echo;grep 'Result: PASS' test.log.$r`"
75dc730
	#a=`mktemp --suffix UpTest$r`
75dc730
	#cat test.log.$r &> $a
75dc730
	echo "----------------------  test.log.$r -------------"
75dc730
	cat test.log.$r
75dc730
	echo "-------------------------------------------------"
75dc730
   done
75dc730
	if  [ "$MAKETEST" -ge "$OK" ]; then
75dc730
		rlPass "RUNS=$REPEAT ; make test passes $MAKETEST x => PASS"
75dc730
	else
75dc730
		rlFail "RUNS=$REPEAT ; make test passes $MAKETEST x => FAIL"
75dc730
	fi
75dc730
75dc730
	expected=$OK
75dc730
	if [ "$RUN_SASL_TESTS" = "1" ]; then
75dc730
#SASL test has two phases, twice more PASS in one log
75dc730
		let "expected=OK*2"
75dc730
	fi
75dc730
	rlLog "$expected expected PASS is sufficient for this test"
75dc730
	rlAssertGreaterOrEqual "risk analyze a.$r" `grep 'All tests successful' test.log.*|wc -l` $expected
75dc730
	ls test.log.*
75dc730
        rlAssertGreaterOrEqual "risk analyze b.$r" `grep 'Result: PASS' test.log.*|wc -l` $expected
75dc730
	rlRun "rm test.log.*" 0 "Remove the test logs"
75dc730
}
75dc730
75dc730
rlJournalStart
75dc730
    rlPhaseStartSetup
75dc730
        rlAssertRpm $PACKAGE || rlDie "Package $PACKAGE not installed"
75dc730
        rlLog "PC name: $(hostname) User: $(whoami)"
75dc730
        TESTDIR=$(pwd)
75dc730
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
75dc730
	rlRun "cp ./*.patch $TmpDir" 0 "Copy patches required for valid testing"
75dc730
        rlRun "pushd $TmpDir" 0 "Going into tmp directory $TmpDir"
75dc730
        rlRun "rlFetchSrcForInstalled $PACKAGE" 0 "Get src.rpm for $PACKAGE"
75dc730
        rlRun "rpm --define '_topdir $TmpDir' -i *src.rpm" 0 "Install src rpm"
75dc730
        rlRun "mkdir BUILD" 0 "Create BUILD directory"
75dc730
        rlRun "rpmbuild --define '_topdir $TmpDir' -bc $TmpDir/SPECS/*spec" 0 "Prepare sources"
75dc730
        rlRun "pushd ./BUILD/" 0 "Cd into the source directory"
75dc730
    rlPhaseEnd
75dc730
75dc730
    rlGetTestState && {
75dc730
    rlPhaseStartTest
75dc730
        rlRun "cd memcached-[0-9]*" 0 "Cd into memcached dir"
75dc730
	if rlIsRHEL ">=8" || rlIsFedora ">=33"; then
75dc730
		rlLog "RHEL >=8 or Fedora >=33 release detected running tests with more features"
75dc730
		rlRun "mv $TmpDir/*.patch ./" 0 "Move patches to source folder"
75dc730
		rlRun "patch -p1
75dc730
		rlRun "patch -p1
75dc730
		rlRun "patch -p1
75dc730
		rlRun "export RUN_SASL_TESTS=1" 0 "export env var so sasl tests are executed"
75dc730
		run_and_verify_tests
75dc730
		rlRun "unset RUN_SASL_TESTS" 0 "Unsetting env var for SASL tests"
75dc730
		rlRun "export SSL_TEST=1" 0 "export env var so ssl tests are executed"
75dc730
		run_and_verify_tests
75dc730
	else
75dc730
		rlLog "RHEL <8 or fedora <33 release detected"
75dc730
		run_and_verify_tests
75dc730
	fi
75dc730
        rlRun "cd .." 0 "Cd back up"
75dc730
    rlPhaseEnd
75dc730
    }
75dc730
75dc730
    rlPhaseStartCleanup
75dc730
        rlRun "popd; popd" 0 "Get out of all the directories"
75dc730
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
75dc730
    rlPhaseEnd
75dc730
rlJournalPrintText
75dc730
rlJournalEnd