Blame tests/bz672959-RFE-Integrate-valgrind-with-gdb-possibly-through/runtest.sh

Alexandra Hájková c043c4
#!/bin/bash
Alexandra Hájková c043c4
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
Alexandra Hájková c043c4
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alexandra Hájková c043c4
#
Alexandra Hájková c043c4
#   runtest.sh of /tools/valgrind/Sanity/bz672959-RFE-Integrate-valgrind-with-gdb-possibly-through
Alexandra Hájková c043c4
#   Description: Test for BZ#672959 ([RFE] Integrate valgrind with gdb possibly through)
Alexandra Hájková c043c4
#   Author: Miroslav Franc <mfranc@redhat.com>
Alexandra Hájková c043c4
#
Alexandra Hájková c043c4
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alexandra Hájková c043c4
#
Alexandra Hájková c043c4
#   Copyright (c) 2012 Red Hat, Inc. All rights reserved.
Alexandra Hájková c043c4
#
Alexandra Hájková c043c4
#   This copyrighted material is made available to anyone wishing
Alexandra Hájková c043c4
#   to use, modify, copy, or redistribute it subject to the terms
Alexandra Hájková c043c4
#   and conditions of the GNU General Public License version 2.
Alexandra Hájková c043c4
#
Alexandra Hájková c043c4
#   This program is distributed in the hope that it will be
Alexandra Hájková c043c4
#   useful, but WITHOUT ANY WARRANTY; without even the implied
Alexandra Hájková c043c4
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Alexandra Hájková c043c4
#   PURPOSE. See the GNU General Public License for more details.
Alexandra Hájková c043c4
#
Alexandra Hájková c043c4
#   You should have received a copy of the GNU General Public
Alexandra Hájková c043c4
#   License along with this program; if not, write to the Free
Alexandra Hájková c043c4
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Alexandra Hájková c043c4
#   Boston, MA 02110-1301, USA.
Alexandra Hájková c043c4
#
Alexandra Hájková c043c4
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alexandra Hájková c043c4
Alexandra Hájková c043c4
# Include Beaker environment
Alexandra Hájková c043c4
. /usr/share/beakerlib/beakerlib.sh
Alexandra Hájková c043c4
Alexandra Hájková c043c4
PACKAGE=$(rpm --qf "%{name}\n" -qf $(which valgrind) | head -1)
Alexandra Hájková c043c4
PACKAGES=(valgrind gcc gdb)
Alexandra Hájková c043c4
Alexandra Hájková c043c4
# Expect 1th argument as a path to binary to test with
Alexandra Hájková c043c4
_test_routine()
Alexandra Hájková c043c4
{
Alexandra Hájková c043c4
    local binary=$1
Alexandra Hájková c043c4
Alexandra Hájková c043c4
    rlPhaseStartTest "$binary error"
Alexandra Hájková c043c4
    rlAssertExists "$binary"
Alexandra Hájková c043c4
        rlLog "valgrind gdb server..."
Alexandra Hájková c043c4
        valgrind --vex-iropt-register-updates=allregs-at-mem-access --vgdb-error=0 ./$binary > vloge 2>&1 &
Alexandra Hájková c043c4
        vpid=$!
Alexandra Hájková c043c4
        sleep 5
Alexandra Hájková c043c4
        rlRun "gdb -x error.gdb ./$binary > gloge 2>&1"
Alexandra Hájková c043c4
        [[ -d /proc/$vpid ]] && { kill -9 $vpid; rlFail "oops: valgrind still running..."; }
Alexandra Hájková c043c4
        rlRun "wait $vpid"
Alexandra Hájková c043c4
        rlAssertGrep '19.*if(x)' gloge
Alexandra Hájková c043c4
        rlAssertGrep '$1 = 42' gloge
Alexandra Hájková c043c4
        # there should be exactly one error
Alexandra Hájková c043c4
        rlAssertGrep 'ERROR SUMMARY: 1 errors from 1 contexts' vloge
Alexandra Hájková c043c4
        rlLog "> gdb output <"
Alexandra Hájková c043c4
        rlLog "$(
Alexandra Hájková c043c4
        rlLog "> valgrind output <"
Alexandra Hájková c043c4
        rlLog "$(
Alexandra Hájková c043c4
    rlPhaseEnd
Alexandra Hájková c043c4
Alexandra Hájková c043c4
    rlPhaseStartTest "$binary noerror"
Alexandra Hájková c043c4
    rlAssertExists "$binary"
Alexandra Hájková c043c4
        rlLog "valgrind gdb server..."
Alexandra Hájková c043c4
        valgrind --vex-iropt-register-updates=allregs-at-mem-access --vgdb-error=0 ./$binary > vlogn 2>&1 &
Alexandra Hájková c043c4
        vpid=$!
Alexandra Hájková c043c4
        sleep 5
Alexandra Hájková c043c4
        rlRun "gdb -x noerror.gdb ./$binary > glogn 2>&1"
Alexandra Hájková c043c4
        [[ -d /proc/$vpid ]] && { kill -9 $vpid; rlFail "oops: valgrind still running..."; }
Alexandra Hájková c043c4
        rlRun "wait $vpid"
Alexandra Hájková c043c4
        rlAssertGrep '10.*f(a);' glogn
Alexandra Hájková c043c4
        # this time, no errors
Alexandra Hájková c043c4
        rlAssertGrep 'ERROR SUMMARY: 0 errors from 0 contexts' vlogn
Alexandra Hájková c043c4
        rlAssertGrep 'hello, world' vlogn
Alexandra Hájková c043c4
        rlLog "> gdb output <"
Alexandra Hájková c043c4
        rlLog "$(
Alexandra Hájková c043c4
        rlLog "> valgrind output <"
Alexandra Hájková c043c4
        rlLog "$(
Alexandra Hájková c043c4
    rlPhaseEnd
Alexandra Hájková c043c4
}
Alexandra Hájková c043c4
Alexandra Hájková c043c4
rlJournalStart
Alexandra Hájková c043c4
    rlPhaseStartSetup
Alexandra Hájková c043c4
        which valgrind | grep "/devtoolset"
Alexandra Hájková c043c4
        if [ $? -eq 0 ]; then
Alexandra Hájková c043c4
            rpm_prefix="$(which valgrind | grep -o 'devtoolset[^/]*')-"
Alexandra Hájková c043c4
        fi
Alexandra Hájková c043c4
Alexandra Hájková c043c4
        for p in "${PACKAGES[@]}"; do
Alexandra Hájková c043c4
            rlAssertRpm "${rpm_prefix}${p}"
Alexandra Hájková c043c4
        done; unset p
Alexandra Hájková c043c4
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
Alexandra Hájková c043c4
        rlRun "cp something.c error.gdb noerror.gdb $TmpDir"
Alexandra Hájková c043c4
        rlRun "pushd $TmpDir"
Alexandra Hájková c043c4
        rlRun "gcc -g something.c -o basic.out"
Alexandra Hájková c043c4
Alexandra Hájková c043c4
        which dwz
Alexandra Hájková c043c4
        if [ $? -eq 0 ]; then
Alexandra Hájková c043c4
            rlRun "cp basic.out dwz.out"
Alexandra Hájková c043c4
            rlRun "dwz dwz.out"
Alexandra Hájková c043c4
            rlRun "dwz_binary_size=$(du -b dwz.out | awk '{ print $1}')"
Alexandra Hájková c043c4
            rlRun "basic_binary_size=$(du -b basic.out | awk '{ print $1}')"
Alexandra Hájková c043c4
            [ "$dwz_binary_size" = "$basic_binary_size" ] && rlFail "Size of dwz binary should differs"
Alexandra Hájková c043c4
            run_for=(basic.out dwz.out)
Alexandra Hájková c043c4
        else
Alexandra Hájková c043c4
            run_for=(basic.out)
Alexandra Hájková c043c4
        fi
Alexandra Hájková c043c4
    rlPhaseEnd
Alexandra Hájková c043c4
Alexandra Hájková c043c4
    for p in "${run_for[@]}"; do
Alexandra Hájková c043c4
        _test_routine "$p"
Alexandra Hájková c043c4
    done; unset p
Alexandra Hájková c043c4
Alexandra Hájková c043c4
    rlPhaseStartCleanup
Alexandra Hájková c043c4
        rlRun "popd"
Alexandra Hájková c043c4
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
Alexandra Hájková c043c4
    rlPhaseEnd
Alexandra Hájková c043c4
rlJournalPrintText
Alexandra Hájková c043c4
rlJournalEnd