#!/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"
_KERNEL_DEVEL="kernel-devel-`uname -r`"
# for ruby on RHEL7 and in collections
PRINT="Kernel::printf"
_run_stap () {
local t="${1:-2}"
rlRun "( timeout $t stap -v ${_STAP_FILE} -o ${_LOG_FILE} 1>&2 2>${_STAP_OUT} & )" 0 "Running systemtap in background"
sleep 1
# wait for systemtap to start
rlWaitForCmd "grep 'starting run' ${_STAP_OUT}"
}
_log_file () {
sleep 1
echo -e "---${_LOG_FILE}--"
grep ' -e:1$' ${_LOG_FILE}
}
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}
if rlIsRHEL '>=8' || rlIsFedora; then
rlRun "rpm -q '$_KERNEL_DEVEL' || dnf install -y '$_KERNEL_DEVEL'" 0 'Installing corresponding kernel-devel: $_KERNEL_DEVEL'
fi
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"
# stap takes long time to start for the first time
_run_stap 60
rlRun "grep -q 'starting run' ${_STAP_OUT}" 0 "Checking stap output."
_log_file
if rlIsRHEL '<7' && [ -z "$COLLECTIONS" ]
then
_run_stap
rlRun "$RUBY -e '1.0 + 9.0'" 0 "Running ruby interpreter: Float test"
_log_file
rlRun "grep -q 'Float::+' ${_LOG_FILE}" 0 "Checking systemtap log: Float test"
# for ruby on RHEL6
PRINT="Object::printf"
fi
_run_stap
rlRun "$RUBY -e '[1, 2, 3].push(4)'" 0 "Running ruby interpreter: Array test"
_log_file
rlRun "grep -q 'Array::push -e:1$' ${_LOG_FILE}" 0 "Checking systemtap log: Array test"
_run_stap
rlRun "$RUBY -e '(1..10).step(1)'" 0 "Running ruby interpreter: Range test"
_log_file
rlRun "grep -q 'Range::step -e:1$' ${_LOG_FILE}" 0 "Checking systemtap log: Range test"
_run_stap
rlRun "$RUBY -e 'Hash.new()'" 0 "Running ruby interpreter: Hash test"
_log_file
rlRun "grep -q 'Hash::initialize -e:1$' ${_LOG_FILE}" 0 "Checking systemtap log: Hash test"
_run_stap
rlRun "$RUBY -e '\"abc\".slice!(\"c\")'" 0 "Running ruby interpreter: String test"
_log_file
rlRun "grep -q 'String::slice! -e:1$' ${_LOG_FILE}" 0 "Checking systemtap log: String test"
_run_stap
rlRun "$RUBY -e '5.times { printf \"Ruby!\n\" }'" 0 "Running ruby interpreter: Cycle and print test"
_log_file
rlRun "grep -q 'Integer::times -e:1$' ${_LOG_FILE}" 0 "Checking systemtap log: Cycle and print test - iteration number"
rlRun "grep -q '$PRINT -e:1$' ${_LOG_FILE}" 0 "Checking systemtap log: Cycle and print test - printf function"
rlRun "grep -q 'IO::write -e:1$' ${_LOG_FILE}" 0 "Checking systemtap log: Cycle and print test - IO write"
rlRun "pkill stapio" 0,1 "Attempt killing all leftover stapios"
echo -e "---ps-out--" && ps -e | grep stap # info
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd