Blob Blame History Raw
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/ruby/Regression/systemtap-static-probes-in-ruby
#   Description: It tests there are static probes in ruby package.
#   Author: Ales Marecek <amarecek@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2011 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 rhts environment
. /usr/share/beakerlib/beakerlib.sh

PACKAGES=${PACKAGES:-ruby ruby-libs rubypick}
# in RHEL7 and later the stap file is in ruby-doc package
if [ -z "$COLLECTIONS" ]; then
    if rlIsRHEL '>=7' || rlIsFedora; then
        PACKAGES=$PACKAGES" ruby-doc"
    fi
fi
REQUIRES=${REQUIRES:-}
RUBY=${RUBY:-ruby}
_STAP_FILE="`rpm -ql $PACKAGES | grep 'ruby-exercise.stp' 2>/dev/null`"
_LOG_FILE="ruby.log"
_STAP_OUT="stap-out.log"

# for ruby on RHEL7 and in collections
PRINT="Kernel::printf"

rlJournalStart
    rlPhaseStartSetup
        rlAssertRpm --all
        rlAssertBinaryOrigin $RUBY
        rlAssertExists "${_STAP_FILE}" || rlDie
        rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
        rlRun "pushd ${TmpDir}"
        _LOG_FILE="${TmpDir}/${_LOG_FILE}"
        touch ${_LOG_FILE}
    rlPhaseEnd

    rlPhaseStartTest
        # TODO: Systemtap - The test could be enlarged by other methods / functions / objects / ...
        rlRun "rpm -ql $PACKAGES | grep 'stp' | grep 'tapset'" 0 "Checking tapset file"
        rlRun "rpm -ql $PACKAGES | grep 'stp' | grep 'doc'" 0 "Checking doc file"

        rlRun "{ stap -v ${_STAP_FILE} -o ${_LOG_FILE} |& tee ${_STAP_OUT}; } &" 0 "Running systemtap in background"
        _STAP_PID=$!
        echo -e "--_STAP_PID--\n${_STAP_PID}" # info

        # wait for systemtap to start
        rlWaitForCmd "grep 'starting run' ${_STAP_OUT}"

        rlRun "$RUBY -e '1.0 + 9.0'" 0 "Running ruby interpreter: Float test"
        rlRun "$RUBY -e '[1, 2, 3].push(4)'" 0 "Running ruby interpreter: Array test"
        rlRun "$RUBY -e '(1..10).step(1)'" 0 "Running ruby interpreter: Range test"
        rlRun "$RUBY -e 'Hash.new()'" 0 "Running ruby interpreter: Hash test"
        rlRun "$RUBY -e '\"abc\".slice!(\"c\")'" 0 "Running ruby interpreter: String test"
        rlRun "$RUBY -e '5.times { printf \"Ruby!\n\" }'" 0 "Running ruby interpreter: Cycle and print test"

        # wait for all output
        rlRun "sleep 10" 0 "Waiting \"10\" seconds"

        rlRun "kill ${_STAP_PID}" 0 "Terminating stap"
        sleep 1 # No Operation

        echo -e "---ps-out--" && ps -e | grep stap      # info
        rlRun "kill -s SIGKILL ${_STAP_PID}" 0,1 "Attempt killing stap"
        rlRun "pkill stapio" 0,1 "Attempt killing all leftover stapios"
        echo -e "---ps-out--" && ps -e | grep stap      # info

        echo -e "---${_LOG_FILE}--" && cat ${_LOG_FILE} # info
        if rlIsRHEL '<7' && [ -z "$COLLECTIONS" ]
        then
            rlRun "grep -q 'Float::+' ${_LOG_FILE}" 0 "Checking systemtap log: Float test"
            # for ruby on RHEL6
            PRINT="Object::printf"
        fi
        rlRun "grep -q 'Array::push' ${_LOG_FILE}" 0 "Checking systemtap log: Array test" 
        rlRun "grep -q 'Range::step' ${_LOG_FILE}" 0 "Checking systemtap log: Range test"
        rlRun "grep -q 'Hash::initialize' ${_LOG_FILE}" 0 "Checking systemtap log: Hash test"
        rlRun "grep -q 'String::slice!' ${_LOG_FILE}" 0 "Checking systemtap log: String test"
        rlRun "grep -q 'Integer::times' ${_LOG_FILE}" 0 "Checking systemtap log: Cycle and print test - iteration number"
        rlRun "grep -q '$PRINT' ${_LOG_FILE}" 0 "Checking systemtap log: Cycle and print test - printf function"
        rlRun "grep -q 'IO::write' ${_LOG_FILE}" 0 "Checking systemtap log: Cycle and print test - IO write"
    rlPhaseEnd

    rlPhaseStartCleanup
        rlRun "popd"
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd