Skip to content

Commit

Permalink
port tracepoint operational test
Browse files Browse the repository at this point in the history
  • Loading branch information
ftjahjad authored and veruu committed Jun 4, 2019
1 parent 57e5967 commit c0b3331
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tracepoints/operational/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# The name of the package under test
PACKAGE_NAME=kernel

# The toplevel namespace within which the test lives.
TOPLEVEL_NAMESPACE=/$(PACKAGE_NAME)

# The version of the test rpm that gets
# created / submitted
export TESTVERSION=1.0

# The path of the test below the package
RELATIVE_PATH=tracepoints/operational

# The relative path name to the test
export TEST=$(TOPLEVEL_NAMESPACE)/$(RELATIVE_PATH)

# All files you want bundled into your rpm
FILES= $(METADATA) \
runtest.sh \
Makefile

clean:
$(RM) *~ $(METADATA)
$(RM) rh-tests-kernel*.rpm

run: $(METADATA)
@echo "No Build required"
chmod +x ./runtest.sh
./runtest.sh

# Include a global make rules file
include /usr/share/rhts/lib/rhts-make.include

showmeta: $(METADATA)
@cat $(METADATA)
@rhts-lint $(METADATA)

$(METADATA):
touch $(METADATA)
@echo "Name: $(TEST)" > $(METADATA)
@echo "Description: Ensure tracepoints are working" >> $(METADATA)
@echo "Path: $(TEST_DIR)" >> $(METADATA)
@echo "TestTime: 150m" >> $(METADATA)
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
@echo "Releases: RHELServer5 RHEL6 Fedora16 RHEL7 RedHatEnterpriseLinux7 RedHatEnterpriseLinuxPegas7 RedHatEnterpriseLinuxAlternateArchitectures7 RedHatEnterpriseLinux8" >> $(METADATA)
@echo "#Architectures: All" >> $(METADATA)
@echo "Destructive: no" >> $(METADATA)
@echo "Confidential: no" >> $(METADATA)
@echo "Priority: Normal" >> $(METADATA)
@echo "Type: KernelTier1" >> $(METADATA)
@echo "Requires: kernel-devel" >> $(METADATA)
@echo "Requires: kernel-rt-devel" >> $(METADATA)
@echo "Requires: systemtap" >> $(METADATA)
@echo "Requires: python3-lxml" >> $(METADATA)
@echo "RunFor: kernel" >> $(METADATA)
@echo "RunFor: kernel-devel" >> $(METADATA)
@echo "RunFor: systemtap" >> $(METADATA)
@echo "License: GPLv2" >> $(METADATA)
@echo "Owner: Kernel General Test Team <[email protected]>" >> $(METADATA)
4 changes: 4 additions & 0 deletions tracepoints/operational/PURPOSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SystemTap tracepoint operational tests.
SystemTap is a tracing and probing tool that allows users to study and monitor the activities of the operating system (particularly, the kernel) in fine detail.
It provides information similar to the output of tools like netstat, ps, top, and iostat;
SystemTap is designed to provide more filtering and analysis options for collected information.
13 changes: 13 additions & 0 deletions tracepoints/operational/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SystemTap tracepoint operational tests.
Tracepoint operational tests system tracing and probing with SystemTap tool. \
Test Maintainer: [Jeff Bastian](mailto:[email protected])

## How to run it

### Dependencies
Please refer to the top-leve README.md for common dependencies. Test-specific dependencies will automatically be installed when executing 'make run'.

### Execute the test
```bash
$ make run
```
233 changes: 233 additions & 0 deletions tracepoints/operational/runtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#!/bin/bash

# Source the common test script helpers
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1



STAP_VERBOSE_FLAG="-v"
if [ x"${STP_VERBOSE}" = x"y" ]; then
STAP_VERBOSE_FLAG="-vvvv"
fi

# Helper functions
function resultFail()
{
echo "***** End of runtest.sh *****" | tee -a $OUTPUTFILE
report_result $1 FAIL $2
echo "" | tee -a $OUTPUTFILE
}

function resultPass ()
{
echo "***** End of runtest.sh *****" | tee -a $OUTPUTFILE
report_result $1 PASS $2
echo "" | tee -a $OUTPUTFILE
}

function submitLog ()
{
LOG=$1
if [ -z "$TESTPATH" ]; then
echo "Running in developer mode"
else
rhts_submit_log -S $RESULT_SERVER -T $TESTID -l $LOG
fi
}

function testHeader ()
{
echo "***** Starting the runtest.sh script *****" | tee $OUTPUTFILE
echo "***** Current Running Kernel Package = "$kernbase" *****" | tee -a $OUTPUTFILE
echo "***** Installed systemtap version = "$stapbase" *****" | tee -a $OUTPUTFILE
echo "***** Current Running Distro = "$installeddistro" *****" | tee -a $OUTPUTFILE
}

function timeCalc ()
{
# end & test time
ETIME=`date +%s`
TTIME=`expr $ETIME - $STIME`
}

function isCpuFamilyModel ()
{
local CPU=$1
local FAMILY=$2
local MODEL=$3

cat /proc/cpuinfo | awk "BEGIN {CPU=\"NO\"; FAMILY=\"NO\"; MODEL=\"NO\"; MATCH=1} /^vendor_id/ { CPU = \$3 }; /^cpu family/ { FAMILY=\$4}; /^model\t/ { MODEL=\$3}; (CPU == \"$CPU\") && (FAMILY == \"$FAMILY\") && (MODEL == \"$MODEL\") { MATCH=0}; END {exit MATCH}"
return $?
}

function testList ()
{
local TESTLIST="$1"
local GROUP_SIZE="$2"
local COUNT=0
local PROBE_COUNT=`echo $TESTLIST | wc -w`
local PROBES_FILE=`mktemp -p /tmp -t group.XXXXXX`
local PROBES_NAME_FILE=`mktemp -p /tmp -t group_probe_names.XXXXXX`
for i in $TESTLIST; do

# Create unique log for verbose tracepoint logging
COUNT=`expr $COUNT + 1`
STIME=`date +%s`

echo "$i" | grep -q "hcall_"
if [ $? -eq 0 ]; then
echo "Skipping probe $i due to Bug 1143870" | tee -a $OUTPUTFILE
echo "Bug 1143870 - ppc64le kernel hangs while running systemtap with hcall_entry/hcall_exit probes" | tee -a $OUTPUTFILE
continue
fi

echo "$i" | tr -d '\"' >> $PROBES_NAME_FILE
echo 'probe kernel.trace('$i') { if (pid() == 0) printf("probe hit\n"); }' >> $PROBES_FILE

if [ $((COUNT % GROUP_SIZE)) == 0 -o $COUNT == $PROBE_COUNT ]; then

testHeader
echo "------------------------------------------------------------" | tee -a $OUTPUTFILE
echo " Start of SystemTap Kernel Tracepoint Test " | tee -a $OUTPUTFILE
echo " $STIME " | tee -a $OUTPUTFILE
echo " Testing: " | tee -a $OUTPUTFILE
cat $PROBES_FILE | tee -a $OUTPUTFILE
echo "------------------------------------------------------------" | tee -a $OUTPUTFILE

cat $PROBES_FILE > group.stap

local firstp=`head -1 $PROBES_NAME_FILE`
local lastp=`tail -1 $PROBES_NAME_FILE`
local VAR="$firstp"
if [ ! "$firstp" == "$lastp" ]; then
local VAR="${firstp}__to__${lastp}"
fi
local VERBOSETRACELOG=`mktemp -p /mnt/testarea -t $VAR-TraceLog.XXXXXX`

stap -DSTP_NO_OVERLOAD $XTRA -t -c "sleep 0.25" ${STAP_VERBOSE_FLAG} group.stap > $VERBOSETRACELOG 2>&1
local rc=$?
timeCalc
if [ $rc -eq 0 ] ; then
echo " Result testing : Test Passed " | tee -a $OUTPUTFILE
echo " Test run time : $TTIME seconds " | tee -a $OUTPUTFILE
echo "------------------------------------------------------------" | tee -a $OUTPUTFILE
resultPass $VAR $COUNT
else
echo " Result testing : Test Failed " | tee -a $OUTPUTFILE
echo " Test run time : $TTIME seconds " | tee -a $OUTPUTFILE
echo "------------------------------------------------------------" | tee -a $OUTPUTFILE
submitLog $VERBOSETRACELOG
resultFail $VAR $COUNT
fi
rm -f $PROBES_FILE
rm -f $PROBES_NAME_FILE
fi
done
}

function runTest ()
{
local TESTLIST=`/usr/bin/stap -L 'kernel.trace("*")' | grep -o "\".*\""`
if [ -z "$TESTLIST" ] ; then
resultFail TESTLIST_EMPTY 99
exit 0
fi

# Bug 1541287 - WARNING: CPU: 3 PID: 10291 at kernel/jump_label.c:188 __jump_label_update+0x95/0xa0
if grep -q "release 7.5" /etc/redhat-release; then
TESTLIST=$(echo "$TESTLIST" | sed '/xen:xen_cpu_write_gdt_entry/d')
TESTLIST=$(echo "$TESTLIST" | sed '/xen:xen_cpu_write_idt_entry/d')
fi

# Additional argumewnt to stap if Family is RHEL5 and CPU/Family/Model match
[ "$FAMILY" == "RedHatEnterpriseLinuxServer5" ] && isCpuFamilyModel AuthenticAMD 21 2
if [ "$?" == 0 ]; then
XTRA="-DTRYLOCKDELAY=300"
fi
stap --clean-cache
testList "$TESTLIST" 32
}

# Setup some variables
if [ -e /etc/redhat-release ] ; then
installeddistro=`cat /etc/redhat-release`
else
installeddistro=unknown
fi

# select tool to manage package, which could be "yum" or "dnf"
function select_yum_tool() {
if [ -x /usr/bin/dnf ]; then
echo "/usr/bin/dnf"
elif [ -x /usr/bin/yum ]; then
echo "/usr/bin/yum"
else
return 1
fi

return 0
}

# return 0 when running kernel rt
is_kernel_rt()
{
local kernel_name=$(uname -r)
if [[ "$kernel_name" =~ "rt" ]]; then
echo 0
else
echo 1
fi
}


yum=$(select_yum_tool)

kernel=$(uname -r)
kernbase=$(rpm -q --queryformat '%{name}-%{version}-%{release}.%{arch}\n' -qf /boot/config-$(uname -r))
stapbase=$(rpm -q --queryformat '%{name}-%{version}-%{release}.%{arch}\n' -qf /usr/bin/stap)

# Checking if running kernel-rt
if [ $(is_kernel_rt) -eq 0 ]; then
${yum} -y install kernel-rt-devel-${kernel}
else
${yum} -y install kernel-devel-${kernel}
fi
res=$?
if [ $res -ne 0 ] ; then
echo "WARN: failed to install kernel devel-${kernel}" | tee -a $OUTPUTFILE
report_result $TEST WARN/ABORTED
rhts-abort -t recipe
exit
fi

# Skip test if we are in FIPS mode, unsigned modules will cause kernel panic
grep "1" /proc/sys/crypto/fips_enabled > /dev/null
if [ $? -eq 0 ]; then
echo "***** Running in FIPS mode, stap modules would cause kernel panic ****" | tee -a $OUTPUTFILE
rhts-report-result $TEST SKIP $OUTPUTFILE
exit 0
fi

# Skip test if we are running an earlier distro (Supported in RHEL5.4)
OSREL=`grep -o 'release [[:digit:]]\+' /etc/redhat-release | awk '{print $2}'`
KERNVER=`/bin/uname -r | /bin/awk -F- {'print $2'} | /bin/awk -F. {'print $1'}`

# ensure KERNVER contains only digits
[[ "$KERNVER" =~ ^[[:digit:]]+$ ]] || KERVER=0

grep -q "Fedora" /etc/redhat-release
if [ $? -eq 0 ] ; then # Check if upstream-Fedora
runTest
elif [[ "$OSREL" = "5" ]] && [[ "$KERNVER" -ge "156" ]] ; then
runTest
elif [[ "$OSREL" =~ [678] ]] ; then
runTest
else
echo "***** tracepoint not enabled in this kernel *****" | tee -a $OUTPUTFILE
echo "***** End of runtest.sh *****" | tee -a $OUTPUTFILE
echo"" | tee -a $OUTPUTFILE
rhts-report-result $TEST SKIP $OUTPUTFILE
exit 0

fi

0 comments on commit c0b3331

Please sign in to comment.