Blob Blame History Raw
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/memcached/Sanity/upstream-testsuite
#   Description: Runs upstream testsuite built into src.rpm
#   Author: Ondrej Mejzlik <omejzlik@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2019 Red Hat, Inc.
#
#   This program is free software: you can redistribute it and/or
#   modify it under the terms of the GNU General Public License as
#   published by the Free Software Foundation, either version 2 of
#   the License, or (at your option) any later version.
#
#   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, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1

PACKAGE=${PACKAGE:-memcached}

# NOTE: if you want to test scratch build in 1minutetip then enable repo containing
# src.rpm and use $ declare -x BEAKERLIB_RPM_DOWNLOAD_METHODS="yum direct"
# so that rlFetchSrcForInstalled downloads src rpm from your repository

#how many times to repeat?
REPEAT=2

#how many pass is OK 
OK=1
run_and_verify_tests() {
   MAKETEST=0
   for r in `seq 1 $REPEAT`;do
	rlLog "================================================================"
	rlLog "================  running $r / $REPEAT  ========================"
        rlRun "sleep 10" 0 "Wait to calm down CPU"
	make test &> test.log.$r
	if [ "$?" = "0" ]; then
		rlLog "make test PASSed"
		let "MAKETEST=MAKETEST+1"
	else
		rlLog "make test FAILed"
		#rlFail "make test fail"
		wall TEST_FAIL_EXPECTED
	fi
	rlLog "`echo;grep 'All tests successful' test.log.$r`"
	rlLog "`echo;grep 'Result: PASS' test.log.$r`"
	#a=`mktemp --suffix UpTest$r`
	#cat test.log.$r &> $a
	echo "----------------------  test.log.$r -------------"
	cat test.log.$r
	echo "-------------------------------------------------"
   done
	if  [ "$MAKETEST" -ge "$OK" ]; then
		rlPass "RUNS=$REPEAT ; make test passes $MAKETEST x => PASS"
	else
		rlFail "RUNS=$REPEAT ; make test passes $MAKETEST x => FAIL"
	fi

	expected=$OK
	if [ "$RUN_SASL_TESTS" = "1" ]; then
#SASL test has two phases, twice more PASS in one log
		let "expected=OK*2"
	fi
	rlLog "$expected expected PASS is sufficient for this test"
	rlAssertGreaterOrEqual "risk analyze a.$r" `grep 'All tests successful' test.log.*|wc -l` $expected
	ls test.log.*
        rlAssertGreaterOrEqual "risk analyze b.$r" `grep 'Result: PASS' test.log.*|wc -l` $expected
	rlRun "rm test.log.*" 0 "Remove the test logs"
}

rlJournalStart
    rlPhaseStartSetup
        rlAssertRpm $PACKAGE || rlDie "Package $PACKAGE not installed"
        rlLog "PC name: $(hostname) User: $(whoami)"
        TESTDIR=$(pwd)
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
	rlRun "cp ./*.patch $TmpDir" 0 "Copy patches required for valid testing"
        rlRun "pushd $TmpDir" 0 "Going into tmp directory $TmpDir"
        rlRun "rlFetchSrcForInstalled $PACKAGE" 0 "Get src.rpm for $PACKAGE"
        rlRun "rpm --define '_topdir $TmpDir' -i *src.rpm" 0 "Install src rpm"
        rlRun "mkdir BUILD" 0 "Create BUILD directory"
        rlRun "rpmbuild --define '_topdir $TmpDir' -bc $TmpDir/SPECS/*spec" 0 "Prepare sources"
        rlRun "pushd ./BUILD/" 0 "Cd into the source directory"
    rlPhaseEnd

    rlGetTestState && {
    rlPhaseStartTest
        rlRun "cd memcached-[0-9]*" 0 "Cd into memcached dir"
	if rlIsRHEL ">=8" || rlIsFedora ">=33"; then
		rlLog "RHEL >=8 or Fedora >=33 release detected running tests with more features"
		rlRun "mv $TmpDir/*.patch ./" 0 "Move patches to source folder"
		rlRun "patch -p1<certs.patch" 0 "patch testing certificates"
		rlRun "patch -p1<no-abort.patch" 0 "remove test that forces abort"
		rlRun "patch -p1<wait-times.patch" 0 "adjust wait times in tests"
		rlRun "export RUN_SASL_TESTS=1" 0 "export env var so sasl tests are executed"
		run_and_verify_tests
		rlRun "unset RUN_SASL_TESTS" 0 "Unsetting env var for SASL tests"
		rlRun "export SSL_TEST=1" 0 "export env var so ssl tests are executed"
		run_and_verify_tests
	else
		rlLog "RHEL <8 or fedora <33 release detected"
		run_and_verify_tests
	fi
        rlRun "cd .." 0 "Cd back up"
    rlPhaseEnd
    }

    rlPhaseStartCleanup
        rlRun "popd; popd" 0 "Get out of all the directories"
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd