15e20ba
#!/bin/bash
15e20ba
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
15e20ba
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15e20ba
#
15e20ba
#   runtest.sh of /tools/libffi/Sanity/testsuite
15e20ba
#   Description: Runs upstream testsuite
15e20ba
#   Author: Michal Nowak <mnowak@redhat.com>
15e20ba
#
15e20ba
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15e20ba
#
15e20ba
#   Copyright (c) 2010 Red Hat, Inc. 
15e20ba
#
15e20ba
#   This program is free software: you can redistribute it and/or
15e20ba
#   modify it under the terms of the GNU General Public License as
15e20ba
#   published by the Free Software Foundation, either version 3 of
15e20ba
#   the License, or (at your option) any later version.
15e20ba
#
15e20ba
#   This program is distributed in the hope that it will be
15e20ba
#   useful, but WITHOUT ANY WARRANTY; without even the implied
15e20ba
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15e20ba
#   PURPOSE.  See the GNU General Public License for more details.
15e20ba
#
15e20ba
#   You should have received a copy of the GNU General Public License
15e20ba
#   along with this program. If not, see http://www.gnu.org/licenses/.
15e20ba
#
15e20ba
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15e20ba
15e20ba
# Include rhts environment
15e20ba
. /usr/lib/beakerlib/beakerlib.sh
15e20ba
15e20ba
PACKAGES=(libffi libffi-devel gcc dejagnu rpm-build gcc-c++)
15e20ba
15e20ba
rlJournalStart
15e20ba
    rlPhaseStartSetup
15e20ba
        for p in "${PACKAGES[@]}"; do
15e20ba
            if ! rlCheckRpm "$p"; then
15e20ba
                rlRun "yum -y install $p"
15e20ba
                rlAssertRpm "$p"
15e20ba
            fi
15e20ba
        done;
15e20ba
15e20ba
        rlRun "TmpDir=`mktemp -d`" 0 "Creating tmp directory"
15e20ba
        rlRun "cp *.patch $TmpDir/"
15e20ba
        rlRun "pushd $TmpDir"
15e20ba
        rlFetchSrcForInstalled libffi
15e20ba
        rlRun "rpm -ivh libffi*.src.rpm"
15e20ba
        rlRun "popd"
15e20ba
        rlRun "specfile=$(rpm --eval='%_specdir')/libffi.spec"
15e20ba
        rlRun "rpmbuild -bp $specfile"
15e20ba
        rlRun "builddir=$(rpm --eval='%_builddir')"
15e20ba
        rlRun "pushd $builddir/libffi-*/"
15e20ba
        rlRun "./configure"
15e20ba
        rlRUn "make"
15e20ba
    rlPhaseEnd
15e20ba
15e20ba
    rlPhaseStartTest "Run testsuite"
15e20ba
15e20ba
        # patching the testsuite to test the installed libraries instead of the built ones
15e20ba
        if [ -e /usr/lib64/libffi.so ]; then
15e20ba
            export LD_LIBRARY_PATH=/usr/lib64
15e20ba
            perl -i -pe 's/LIBRARY_DIR/lib64/' $TmpDir/dynamic_linking.patch
15e20ba
            perl -i -pe 's/LIBRARY_DIR/lib64/' $TmpDir/dynamic_linking-dg.patch
15e20ba
        else
15e20ba
            export LD_LIBRARY_PATH=/usr/lib
15e20ba
            perl -i -pe 's/LIBRARY_DIR/lib/' $TmpDir/dynamic_linking.patch
15e20ba
            perl -i -pe 's/LIBRARY_DIR/lib/' $TmpDir/dynamic_linking-dg.patch
15e20ba
        fi
15e20ba
        test -e testsuite/lib/libffi.exp && rlRun "patch testsuite/lib/libffi.exp < $TmpDir/dynamic_linking.patch"
15e20ba
        test -e testsuite/lib/libffi-dg.exp && rlRun "patch testsuite/lib/libffi-dg.exp < $TmpDir/dynamic_linking-dg.patch"
15e20ba
        rlLog "Checking whether we test really the installed libraries."
15e20ba
        strace -F -e open,openat,stat -o strace.log -- make check
15e20ba
        LIBFFI_SO_CALLS=`cat strace.log | grep libffi.so | grep -v ENOENT | grep -v 'usr/lib' | grep -v '\"\/lib' | grep -v 'unfinished' | wc -l`
15e20ba
        rlAssertGreater "The just built libraries should not be used, everything should be taken from /usr" 5 $LIBFFI_SO_CALLS
15e20ba
        rlRun "cat strace.log | grep libffi.so | grep usr"
15e20ba
        rlRun "cat strace.log | grep libffi.so | grep rpmbuild" 1
15e20ba
        rlRun "make check" 0 "RUNNING THE TESTSUITE"
15e20ba
        rlRun "popd"
15e20ba
    rlPhaseEnd
15e20ba
15e20ba
    rlPhaseStartCleanup
15e20ba
        rlRun "ls -al $TmpDir"
15e20ba
        rlBundleLogs logs $(find . -name 'libffi.sum') $(find . -name 'libffi.log')
15e20ba
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
15e20ba
    rlPhaseEnd
15e20ba
rlJournalPrintText
15e20ba
rlJournalEnd