Blob Blame History Raw
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/openscap/Sanity/smoke-test
#   Description: Test runs upstream test suite.
#   Author: Ondrej Moris <omoris@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2010 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.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

. /usr/lib/beakerlib/beakerlib.sh

PACKAGE="openscap"

rlJournalStart

    rlPhaseStartSetup
        rlImport --all || rlDie "Failed to import libraries"
        rlAssertRpm "$PACKAGE"

        RpmSnapshotCreate
        CleanupRegister "RpmSnapshotRevert"
        rlRun "TmpDir=\$(mktemp -d)" 0
        CleanupRegister "rlRun 'rm -r $TmpDir' 0 'Removing tmp directory'"
        rlRun "cp fix_hugepages_err7.patch fix_hugepages_err.patch $TmpDir"
        rlRun "pushd $TmpDir"
        CleanupRegister "rlRun 'popd'"
        rlServiceStart sendmail
        CleanupRegister "rlRun 'rlServiceRestore sendmail'"

        if rlIsRHEL 7; then
            rlLog "Build system is using the latest version of python, therefore"
            rlLog "python3 packages must not be present on the machine to make"
            rlLog "sure that the build system configures with python2."
            rlRun "yum remove -y python3*" 0 "python3 packages must not be installed"
        elif rlIsRHEL ">=8"; then
            rlFileBackup "/etc/yum.repos.d/"
            CleanupRegister "rlFileRestore"
            # we have to enable buildroot repo
            rlRun "dnf config-manager --set-enabled rhel-buildroot{,-debuginfo,-source}" 0-255
            # Some packages needed to build openscap moved from rhel-buildroot to rhel-CRB
            rlRun "dnf config-manager --set-enabled rhel-CRB{,-debuginfo,-source}" 0-255
            rlRun "dnf config-manager --set-enabled beaker-CRB{,-debuginfo,-source}" 0-255
            # AppStream source repo is not enabled by default
            rlRun "dnf config-manager --set-enabled beaker-AppStream-source" 0-255
        fi

        rlFetchSrcForInstalled $PACKAGE
        if rlIsFedora || rlIsRHEL ">=8"; then
            rlRun "dnf builddep -y $PACKAGE*"
        else
            rlRun "yum-builddep -y $PACKAGE*"
        fi
        TOPDIR=`rpm --eval %_topdir`
        rlRun "rm -rf ${TOPDIR}/BUILD/${PACKAGE}*" 0-255
        rlRun "rpm -ihv `ls *.rpm`" 0 "Install $PACKAGE source RPM"
    rlPhaseEnd

    rlPhaseStartSetup "Prepare upstream test suite (%prep and %build stages from the spec file)"
        rlRun "rpmbuild -v -bc ${TOPDIR}/SPECS/${PACKAGE}.spec"
        CleanupRegister "rlRun 'rm -rf ${TOPDIR}/BUILD/${PACKAGE}*'"
        CleanupRegister "rlRun 'rm -rf ${TOPDIR}/SPECS/${PACKAGE}*'"
        CleanupRegister "rlRun 'rm -rf ${TOPDIR}/SOURCES/*'"

        rlLogInfo "Waive the known issue with hugepages on ppc64/ppc64le"
        rlLogInfo "platforms which won't be fixed:"
        rlLogInfo "https://bugzilla.redhat.com/show_bug.cgi?id=1607382"
        TEST_CWD=$(pwd)
        TREE_CWD=$(readlink -f ${TOPDIR}/BUILD/${PACKAGE}*)
        if rlIsRHEL 7; then
            HUGEPAGES_PATCH="fix_hugepages_err7.patch"
        else
            HUGEPAGES_PATCH="fix_hugepages_err.patch"
        fi
        rlRun "cp $HUGEPAGES_PATCH $TREE_CWD"
        rlRun "cd $TREE_CWD"
        rlRun "patch -p1 < $HUGEPAGES_PATCH"
        rlRun "cd $TEST_CWD" 0 "Restore test default working directory"
    rlPhaseEnd

    rlPhaseStartTest "Run upstream test suite against installed $PACKAGE"
        rlRun "export OSCAP_FULL_VALIDATION=1"
        rlRun "export CUSTOM_OSCAP=$(which oscap)"
        BUILD_DIR="$(rpm --eval %{_vpath_builddir})"
        BUILD_DIR_PATH=$(readlink -f ${TOPDIR}/BUILD/${PACKAGE}*/${BUILD_DIR})
        if [ ! -d "$BUILD_DIR_PATH" ]; then
            BUILD_DIR_PATH=$(readlink -f ${TOPDIR}/BUILD/${PACKAGE}*/build)
        fi
        if rlIsFedora || rlIsRHEL ">=8"; then
            rlRun -s "cmake --build $BUILD_DIR_PATH --target test"
            rv=$?
            # cmake output does not contain enough information, submit verbose output log
            FILE="${BUILD_DIR_PATH}/Testing/Temporary/LastTest.log"
            rlFileSubmit $(readlink -f $FILE) test_verbose_output.log
        else
            rlRun -s "make -C $(readlink -f ${TOPDIR}/BUILD/${PACKAGE}*) check"
            rv=$?
        fi

        # if we got error, submit file with result of particular test for easier debugging
        if [ $rv -ne 0 ]; then
            if rlIsFedora || rlIsRHEL ">=8"; then
                FILE="${BUILD_DIR_PATH}/tests"
                rlBundleLogs test_outputs_all $(readlink -f $FILE)
            elif grep "See tests/" $rlRun_LOG; then
                RESULT=`grep "See tests/" $rlRun_LOG | sed -e "s/See tests\(.*\)/tests\1/"`
                FILE="${TOPDIR}/BUILD/${PACKAGE}*/${RESULT}"
                cat $(readlink -f $FILE)
                rlBundleLogs test_outputs $(dirname $FILE)
                if grep "See tests/" $FILE; then # we need to go deeper ...
                    RESULT=`grep "See tests/" $FILE | sed -e "s/See tests\(.*\)/tests\1/"`
                    FILE="${TOPDIR}/BUILD/${PACKAGE}*/${RESULT}"
                    cat $(readlink -f $FILE)
                    rlBundleLogs test_outputs_deep $(dirname $FILE)
                fi
            fi
        fi
    rlPhaseEnd

    rlPhaseStartCleanup
        CleanupDo
    rlPhaseEnd

rlJournalPrintText
rlJournalEnd