#!/bin/bash # vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # runtest.sh of systemtap-static-probes-in-ruby # Description: It tests there are static probes in ruby package. # Author: Ales Marecek # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # 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 || exit 1 PACKAGES=${PACKAGES:-ruby ruby-libs rubypick ruby-doc} REQUIRES=${REQUIRES:-} RUBY=${RUBY:-ruby} _STAP_FILE="${_STAP_FILE:-/usr/share/doc/ruby-doc/ruby-exercise.stp}" _LOG_FILE="ruby.log" _STAP_OUT="stap-out.log" RUBY_OPTS="--disable-gems" STAP_OPTS="--suppress-handler-errors" # System Under Test UPDATE_SUT="${UPDATE_SUT:-1}" rlJournalStart rlPhaseStartSetup rlAssertRpm --all rlAssertBinaryOrigin $RUBY rlAssertExists "${_STAP_FILE}" || rlDie rlLog "Using STAP_FILE from $(rpm -qf ${_STAP_FILE})." if [[ $UPDATE_SUT == "1" ]]; then rlLog "Machine to be updated, disable by setting UPDATE_SUT to other value than 1" if [[ $TMT_REBOOT_COUNT == "0" ]]; then rlRun "dnf update --refresh -y" rlLog "Now reboot the system" tmt-reboot else rlLog "SUT updated and rebooted" fi else rlLog "Machine not to be updated" fi rlRun "stap-prep" 0 "Prepare system for systemtap use" 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 file with ruby systemtap probes" if ! $RUBY $RUBY_OPTS -e ''; then rlLog "Can't use $RUBY_OPTS as option for $RUBY, removing these options" RUBY_OPTS="" fi if rlTestVersion "$(rpm -qf $(command -v stap) --qf '%{version}-%{release}')" ">=" "4.7-1"; then rlLog "Changing stap buffer size" STAP_OPTS="$STAP_OPTS -s 100" fi rlRun "{ stap $STAP_OPTS -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 $RUBY_OPTS -e '1.0 + 9.0'" 0 "Running ruby interpreter: Float test" rlRun "$RUBY $RUBY_OPTS -e '[1, 2, 3].push(4)'" 0 "Running ruby interpreter: Array test" rlRun "$RUBY $RUBY_OPTS -e '(1..10).step(1)'" 0 "Running ruby interpreter: Range test" rlRun "$RUBY $RUBY_OPTS -e 'TracePoint.new{}.enable; Hash.new()'" 0 "Running ruby interpreter: Hash test" rlRun "$RUBY $RUBY_OPTS -e '\"abc\".slice!(\"c\")'" 0 "Running ruby interpreter: String test" rlRun "$RUBY $RUBY_OPTS -e 'TracePoint.new{}.enable; 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 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 'Kernel::printf' ${_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