Blob Blame History Raw
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/postgresql/testsuite
#   Description: PostgreSQL testsuite wrapper
#   Author: Tom Lane <tgl@redhat.com>
#   Owner: Karel Volny <kvolny@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2010-2012 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 Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1

# TODO: This is temporary workaround till we have no /Library directory
# in this git repository.
PACKAGE=postgresql
PGDATA=/var/lib/pgsql/data
PGUSER=postgres

ORIG_AVC_ERROR=$AVC_ERROR

rlJournalStart
    rlPhaseStartSetup "General setup"
        PG_VER=$(postgres -V | cut -d " " -f3 | cut -d "." -f1);
        rlLogInfo "Using postgres version: $PG_VER";
        PACKAGES="postgresql postgresql-test postgresql-server"
        for PACKAGE in $PACKAGES; do
            rlAssertRpm $PACKAGE
        done
        # stop the system's service (if any)
        rlServiceStop postgresql
    rlPhaseEnd

    rlPhaseStartSetup
        TestingDir="$(rpm -ql "postgresql-test" | grep -E '/regress$' | head -n 1)";
        rlRun "test -d $TestingDir"
        rlLogInfo "postgresql-test directory: $TestingDir"
        rlRun "pushd $TestingDir"
        rlRun "rlFileBackup --clean $PGDATA"
        # switch to non-root to have additional protection against mistakes
        rlRun "su - $PGUSER -c 'rm -rf ${PGDATA-/var/lib/pgsql/data}'"
        rlRun "postgresql-setup --initdb"
        # start the testing server
        rlServiceStart postgresql
    rlPhaseEnd

    rlPhaseStartTest
        rlLogDebug "Running test from: $TestingDir";

        pg_command="cd $TestingDir && make installcheck-parallel"
        rlRun "su - $PGUSER -c '$pg_command' &> testsuite.out" 0 \
            "Running the testsuite"

        echo ":::::::::::::::::::::::::::::: TESTSUITE OUTPUT ::::::::::::::::::::::::::::::";
        cat testsuite.out
        rlRun "grep -E 'All [[:digit:]]+ tests passed.' testsuite.out" 0 "Checking if All tests passed."

        if [ -f regression.diffs ]; then
            rlFail "The test must have failed - 'regression.diffs' found"
            rlBundleLogs $PACKAGE regression.diffs
        fi
    rlPhaseEnd

    rlPhaseStartCleanup
        rlRun "rm -f regression.diffs testsuite.out" 0 "Cleaning up files"
        rlRun "make clean"
        # stop the testing server
        rlServiceStop postgresql
        # restore the system server, if any
        rlFileRestore
        rlServiceRestore postgresql
        rlRun "popd"
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd
AVC_ERROR=$ORIG_AVC_ERROR