blob: ff4ed6755716ce156fbbb300372b016b753314c8 [file] [log] [blame]
#!/bin/sh
################################################################################
## ##
## Copyright (c) International Business Machines Corp., 2001 ##
## ##
## This program is free software; you can redistribute it and#or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or ##
## (at your option) any later version. ##
## ##
## 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
## ##
################################################################################
# File: runltp
#
# Description: This script can be used to the tests in the LTP test suite
#
# Authors: Manoj Iyer - manjo@mail.utexas.edu
# Robbe Williamson - robbiew@us.ibm.com
#
# History: Oct 07 2003 - Modified - Manoj Iyer
# - use functions
# - clean up on script exit
# - error checking etc.
#
# Oct 08 2003 - Modified - Manoj Iyer
# - fixed bug in creating results directory
# - all checks should be enlclosed in " " to avoid bash error
# - exit with error if pan is not found in pan directory
#
# Jul 22 2007 - Modified - Ricardo Salveti de Araujo
# - added support to put more then one file at CMDLINE (-f)
# - added a new option, that the user can pass the address of
# the command file, and it'll use wget to get it (-w)
# - now -s does the grep at the selected command files (default,
# -f or -w)
#
# Jul 23 2007 - Modified - Ricardo Salveti de Araujo
# - added flag to get the command file that has all failed tests
#
# Sep 11 2007 - Modified - Subrata Modak
# - added option to create Failed File if it is not an absolute path
# - added option to create Output File if it is not an absolute path
# - added option to create Failed File compulsory, even if user has not mentioned it
#
# Sep 14 2007 - Modified - Ricardo Salveti de Araujo
# - cleaning and removing duplicated code
#
#################################################################################
setup()
{
cd `dirname $0` || \
{
echo "FATAL: unable to change directory to $(dirname $0)"
exit 1
}
export LTPROOT=${PWD}
export TMPBASE="/tmp"
export TMP="${TMPBASE}/ltp-$$"
export TMPDIR="${TMP}"
export PATH="${PATH}:${LTPROOT}/testcases/bin"
[ -d $LTPROOT/testcases/bin ] ||
{
echo "FATAL: Test suite not installed correctly"
echo "INFO: as root user type 'make ; make install'"
exit 1
}
[ -e $LTPROOT/pan/pan ] ||
{
echo "FATAL: Test suite driver 'pan' not found"
echo "INFO: as root user type 'make ; make install'"
exit 1
}
}
version_of_ltp()
{
head -n 1 $LTPROOT/ChangeLog
exit 0
}
usage()
{
cat <<-EOF >&2
usage: ./${0##*/} -c [-C FAILCMDFILE ] [-d TMPDIR] [-f CMDFILES(,...) ]
[-i # (in Mb)] [ -l LOGFILE ] [ -o OUTPUTFILE ] [ -m # (in Mb)] -N -n -q
[ -r LTPROOT ] [ -s PATTERN ] [ -t DURATION ] -v [ -w CMDFILEADDR ]
[ -x INSTANCES ]
-C FAILCMDFILE Command file with all failed test cases.
-c NUM_PROCS Run LTP under additional background CPU load.
-d TMPDIR Directory where temporary files will be created.
-e Prints the date of the current LTP release
-f CMDFILES Execute user defined list of testcases (separate with ',')
-h Help. Prints all available options.
-i # (in Mb) Run LTP with a _min_ IO load of # Mb in background.
-l LOGFILE Log results of test in a logfile.
-m # (in Mb) Run LTP with a _min_ memory load of # Mb in background.
-N Run all the networking tests.
-n Run LTP with network traffic in background.
-o OUTPUTFILE Redirect test output to a file.
-p Human readable format logfiles.
-q Print less verbose output to screen.
-r LTPROOT Fully qualified path where testsuite is installed.
-s PATTERN Only run test cases which match PATTERN.
-t DURATION Execute the testsuite for given duration. Examples:
-t 60s = 60 seconds
-t 45m = 45 minutes
-t 24h = 24 hours
-t 2d = 2 days
-v Print more verbose output to screen.
-w CMDFILEADDR Uses wget to get the user's list of testcases.
-x INSTANCES Run multiple instances of this testsuite.
example: ./${0##*/} -i 1024 -m 128 -p -q -l /tmp/resultlog.$$ -d ${PWD}
EOF
exit 0
}
main()
{
local CMDFILES=""
local PRETTY_PRT=""
local ALT_DIR_OUT=0
local ALT_DIR_RES=0
local RUN_NETEST=0
local QUIET_MODE=""
local VERBOSE_MODE=""
local NETPIPE=0
local GENLOAD=0
local MEMSIZE=0
local DURATION=""
local CMDFILEADDR=""
local BYTESIZE=0
local LOGFILE=""
local SCENFILES=""
local PRETTY_PRT=""
local TAG_RESTRICT_STRING=""
local PAN_COMMAND=""
version_date=`head -n 1 $LTPROOT/ChangeLog`
while getopts c:C:d:f:ehi:l:m:Nno:pqr:s:t:vw:x: arg
do case $arg in
c)
NUM_PROCS=$(($OPTARG))
$LTPROOT/testcases/bin/genload --cpu $NUM_PROCS >/dev/null 2>&1 &
GENLOAD=1 ;;
C)
case $OPTARG in
/*)
FAILCMDFILE="-C $OPTARG" ;;
*)
FAILCMDFILE="-C $LTPROOT/output/$OPTARG"
ALT_DIR_OUT=1 ;;
esac ;;
d) # append $$ to TMP, as it is recursively
# removed at end of script.
export TMPBASE=$OPTARG
export TMP="${TMPBASE}/ltp-$$"
export TMPDIR="$TMP";;
e) # Print out the version of LTP
version_of_ltp
;;
f) # Execute user defined set of testcases.
# Can be more then one file, just separate it with ',', like:
# -f nfs,commands,/tmp/testfile
CMDFILES=$OPTARG;;
h) usage;;
i)
BYTESIZE=$(($OPTARG * 1024 * 1024))
$LTPROOT/testcases/bin/genload --io 1 >/dev/null 2>&1 &
$LTPROOT/testcases/bin/genload --hdd 1 --hdd-bytes $BYTESIZE \
>/dev/null 2>&1 &
GENLOAD=1 ;;
l)
LOGFILE_NAME="$OPTARG"
case $OPTARG in
/*)
LOGFILE="-l $OPTARG" ;;
*)
LOGFILE="-l $LTPROOT/results/$OPTARG"
ALT_DIR_RES=1 ;;
esac ;;
m)
MEMSIZE=$(($OPTARG * 1024 * 1024))
$LTPROOT/testcases/bin/genload --vm 0 --vm-bytes $MEMSIZE \
>/dev/null 2>&1 &
GENLOAD=1;;
N) RUN_NETEST=1;;
n)
$LTPROOT/testcases/bin/netpipe.sh
NETPIPE=1;;
o) OUTPUTFILE_NAME="$OPTARG"
case $OPTARG in
/*)
OUTPUTFILE="-o $OPTARG";;
*)
OUTPUTFILE="-o $LTPROOT/output/$OPTARG"
ALT_DIR_OUT=1 ;;
esac ;;
p) PRETTY_PRT=" -p ";;
q) QUIET_MODE=" -q ";;
r) LTPROOT=$OPTARG;;
s) TAG_RESTRICT_STRING=$OPTARG;;
t) # In case you want to specify the time
# to run from the command line
# (2m = two minutes, 2h = two hours, etc)
DURATION="-t $OPTARG" ;;
v) VERBOSE_MODE=1;;
w) CMDFILEADDR=$OPTARG;;
x) # number of ltp's to run
cat <<-EOF >&1
WARNING: The use of -x can cause unpredictable failures, as a
result of concurrently running multiple tests designed
to be ran exclusively.
Pausing for 10 seconds..."
EOF
sleep 10
INSTANCES="-x $OPTARG -O ${TMP}";;
\?) usage;;
esac
done
## It would be nice if a Failed File is compulsorily created (gives User better Idea of Tests that failed)
if [ ! "$FAILCMDFILE" ]; then ## User has not mentioned about Failed File name
echo Inside Failed File Name not Mentioned
ALT_DIR_OUT=1
if [ ! "$OUTPUTFILE" ]; then ## User has not mentioned about Output File name either
if [ ! "$LOGFILE" ]; then ## User has not mentioned about Log File name either
FAILED_FILE_NAME=`date +"%Y_%b_%d-%Hh_%Mm_%Ss"`
FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
else ## User Fortunately wanted a log file,
FAILED_FILE_NAME=`basename $LOGFILE_NAME` ## Extract log file name and use it to construct Failed file name
FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
fi
else ## User Fortunately wanted a Output file
FAILED_FILE_NAME=`basename $OUTPUTFILE_NAME` ## Extract output file name and use it to construct Failed file name
FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
fi
fi
# If we need, create the output directory
[ "$ALT_DIR_OUT" -eq 1 ] && \
{
echo "INFO: creating $LTPROOT/output directory"
[ ! -d $LTPROOT/output ] && \
{
mkdir -p $LTPROOT/output || \
{
echo "ERROR: failed to create $LTPROOT/output"
exit 1
}
}
}
# If we need, create the results directory
[ "$ALT_DIR_RES" -eq 1 ] && \
{
echo "INFO: creating $LTPROOT/results directory"
[ ! -d $LTPROOT/results ] && \
{
mkdir -p $LTPROOT/results || \
{
echo "ERROR: failed to create $LTPROOT/results"
exit 1
}
}
}
# Added -m 777 for tests that call tst_tmpdir() and try to
# write to it as user nobody
mkdir -m 777 -p $TMP || \
{
echo "FATAL: Unable to make temporary directory $TMP"
exit 1
}
cd $TMP || \
{
echo "could not cd ${TMP} ... exiting"
exit 1
}
[ "$RUN_NETEST" -eq 1 ] && \
{
[ -z "$RHOST" ] || [ -z "$PASSWD" ] && \
{
[ -z "$RHOST" ] && \
{
echo \
"INFO: Enter RHOST = 'name of the remote host machine'"
echo -n "-> "
read RHOST
}
[ -z "$PASSWD" ] && \
{
echo " "
echo \
"INFO: Enter PASSWD = 'root passwd of the remote host machine'"
echo -n "-> "
read PASSWD
}
export RHOST=$RHOST
export PASSWD=$PASSWD
echo "WARNING: security of $RHOST may be compromised"
}
}
# If user does not provide a command file select a default set of testcases
# to execute.
if [ -z "$CMDFILES" ] && [ -z "$CMDFILEADDR" ]
then
cat <<-EOF >&1
INFO: no command files were provided, using default,
system calls, memory management, IPC, scheduler
direct io, file system, math and pty tests will
now be executed
EOF
for SCENFILES in ${LTPROOT}/runtest/syscalls ${LTPROOT}/runtest/fs \
${LTPROOT}/runtest/fsx ${LTPROOT}/runtest/dio \
${LTPROOT}/runtest/mm ${LTPROOT}/runtest/ipc \
${LTPROOT}/runtest/sched ${LTPROOT}/runtest/math \
${LTPROOT}/runtest/nptl ${LTPROOT}/runtest/pty \
${LTPROOT}/runtest/containers
do
[ -a "$SCENFILES" ] || \
{
echo "FATAL: missing scenario file $SCENFILES"
exit 1
}
cat $SCENFILES >> ${TMP}/alltests || \
{
echo "FATAL: unable to create command file"
exit 1
}
done
fi
[ -n "$CMDFILES" ] && \
{
for SCENFILES in `echo "$CMDFILES" | sed 's/,/\n/g'`
do
[ -f "$SCENFILES" ] || SCENFILES="$LTPROOT/runtest/$SCENFILES"
cat "$SCENFILES" >> ${TMP}/alltests || \
{
echo "FATAL: unable to create command file"
exit 1
}
done
}
[ -n "$CMDFILEADDR" ] && \
{
wget -q "${CMDFILEADDR}" -O ${TMP}/wgetcmdfile
if [ $? -ne 0 ]; then
echo "FATAL: error while getting the command file with wget (address $CMDFILEADDR)"
exit 1
fi
cat "${TMP}/wgetcmdfile" >> ${TMP}/alltests || \
{
echo "FATAL: unable to create command file"
exit 1
}
}
[ "$RUN_NETEST" -eq 1 ] && \
{
for SCENFILES in ${LTPROOT}/runtest/tcp_cmds \
${LTPROOT}/runtest/multicast \
${LTPROOT}/runtest/rpc \
${LTPROOT}/runtest/nfs
do
[ -a "$SCENFILES" ] || \
{
echo "FATAL: missing scenario file $SCENFILES"
exit 1
}
cat "$SCENFILES" >> ${TMP}/alltests || \
{
echo "FATAL: unable to create command file"
exit 1
}
done
}
# The fsx-linux tests use the SCRATCHDEV environment variable as a location
# that can be reformatted and run on. Set SCRATCHDEV if you want to run
# these tests. As a safeguard, this is disabled.
unset SCRATCHDEV
[ -n "$SCRATCHDEV" ] && \
{
cat ${LTPROOT}/runtest/fsx >> ${TMP}/alltests ||
{
echo "FATAL: unable to create fsx-linux tests command file"
exit 1
}
}
# If enabled, execute only test cases that match the PATTERN
if [ -n "$TAG_RESTRICT_STRING" ]
then
mv -f ${TMP}/alltests ${TMP}/alltests.orig
grep $TAG_RESTRICT_STRING ${TMP}/alltests.orig > ${TMP}/alltests #Not worth checking return codes for this case
fi
# check for required users and groups
${LTPROOT}/IDcheck.sh &>/dev/null || \
{
echo "WARNING: required users and groups not present"
echo "WARNING: some test cases may fail"
}
# display versions of installed software
[ -z "$QUIET_MODE" ] && \
{
${LTPROOT}/ver_linux || \
{
echo "WARNING: unable to display versions of software installed"
exit 1
}
}
[ ! -z "$QUIET_MODE" ] && { echo "INFO: Test start time: $(date)" ; }
PAN_COMMAND="${LTPROOT}/pan/pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \
-n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE"
if [ ! -z "$VERBOSE_MODE" ] ; then
echo "COMMAND: $PAN_COMMAND"
if [ ! -z "$TAG_RESTRICT_STRING" ] ; then
echo "INFO: Restricted to $TAG_RESTRICT_STRING"
fi
fi
#$PAN_COMMAND #Duplicated code here, because otherwise if we fail, only "PAN_COMMAND" gets output
${LTPROOT}/pan/pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \
-n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE
if [ $? -eq 0 ]; then
echo "INFO: pan reported all tests PASS"
VALUE=0
else
echo "INFO: pan reported some tests FAIL"
VALUE=1
fi
echo "LTP Version: $version_date"
[ ! -z "$QUIET_MODE" ] && { echo "INFO: Test end time: $(date)" ; }
[ "$GENLOAD" -eq 1 ] && { killall -9 genload ; }
[ "$NETPIPE" -eq 1 ] && { killall -9 NPtcp ; }
[ "$ALT_DIR_OUT" -eq 1 ] || [ "$ALT_DIR_RES" -eq 1 ] && \
{
cat <<-EOF >&1
###############################################################"
Done executing testcases."
log result(s) is in $LTPROOT/results directory"
output/failed result(s) in $LTPROOT/output directory [If you did not provide Absolute Path]
LTP Version: $version_date
###############################################################"
EOF
}
exit $VALUE
}
cleanup()
{
rm -rf ${TMP}
}
trap "cleanup" 0
setup
main "$@"