blob: 83444a9eb0cf529a3b15593eb344961f31f3cc26 [file] [log] [blame]
plars4a120e82004-09-02 18:56:06 +00001#!/bin/sh
2################################################################################
3## ##
4## Copyright (c) International Business Machines Corp., 2001 ##
5## ##
6## This program is free software; you can redistribute it and#or modify ##
7## it under the terms of the GNU General Public License as published by ##
8## the Free Software Foundation; either version 2 of the License, or ##
9## (at your option) any later version. ##
10## ##
11## This program is distributed in the hope that it will be useful, but ##
12## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
14## for more details. ##
15## ##
16## You should have received a copy of the GNU General Public License ##
17## along with this program; if not, write to the Free Software ##
18## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
19## ##
20################################################################################
21# File: runltp
22#
23# Description: This script can be used to the tests in the LTP test suite
24#
25# Authors: Manoj Iyer - manjo@mail.utexas.edu
26# Robbe Williamson - robbiew@us.ibm.com
27#
28# History: Oct 07 2003 - Modified - Manoj Iyer
29# - use functions
30# - clean up on script exit
31# - error checking etc.
32#
33# Oct 08 2003 - Modified - Manoj Iyer
34# - fixed bug in creating results directory
subrata_modaka1fd64b2007-04-11 11:24:49 +000035# - all checks should be enlclosed in " " to avoid bash error
plars4a120e82004-09-02 18:56:06 +000036# - exit with error if pan is not found in pan directory
subrata_modakbc833d32007-07-25 10:12:02 +000037#
38# Jul 22 2007 - Modified - Ricardo Salveti de Araujo
39# - added support to put more then one file at CMDLINE (-f)
40# - added a new option, that the user can pass the address of
41# the command file, and it'll use wget to get it (-w)
42# - now -s does the grep at the selected command files (default,
43# -f or -w)
44#
45# Jul 23 2007 - Modified - Ricardo Salveti de Araujo
46# - added flag to get the command file that has all failed tests
subrata_modak6838ec32007-09-14 10:10:12 +000047#
48# Sep 11 2007 - Modified - Subrata Modak
49# - added option to create Failed File if it is not an absolute path
50# - added option to create Output File if it is not an absolute path
51# - added option to create Failed File compulsory, even if user has not mentioned it
52#
53#################################################################################
subrata_modakbc833d32007-07-25 10:12:02 +000054
plars4a120e82004-09-02 18:56:06 +000055
56
57setup()
58{
59 cd `dirname $0` || \
60 {
61 echo "FATAL: unable to change directory to $(dirname $0)"
62 exit 1
63 }
64 export LTPROOT=${PWD}
65 export TMPBASE="/tmp"
66 export TMP="${TMPBASE}/ltp-$$"
67 export PATH="${PATH}:${LTPROOT}/testcases/bin"
68
69 [ -d $LTPROOT/testcases/bin ] ||
70 {
71 echo "FATAL: Test suite not installed correctly"
72 echo "INFO: as root user type 'make ; make install'"
73 exit 1
74 }
75
76 [ -e $LTPROOT/pan/pan ] ||
77 {
78 echo "FATAL: Test suite driver 'pan' not found"
79 echo "INFO: as root user type 'make ; make install'"
80 exit 1
81 }
82}
83
mreed1091696422006-05-03 19:07:22 +000084version_of_ltp()
85{
subrata_modaka1fd64b2007-04-11 11:24:49 +000086 head -n 1 $LTPROOT/ChangeLog
87 exit 0
mreed1091696422006-05-03 19:07:22 +000088}
plars4a120e82004-09-02 18:56:06 +000089
90usage()
91{
92 cat <<-EOF >&2
93
subrata_modakbc833d32007-07-25 10:12:02 +000094 usage: ./${0##*/} -c [-C FAILCMDFILE ] [-d TMPDIR] [-f CMDFILES(,...) ]
95 [-i # (in Mb)] [ -l LOGFILE ] [ -o OUTPUTFILE ] [ -m # (in Mb)] -N -n -q
96 [ -r LTPROOT ] [ -s PATTERN ] [ -t DURATION ] -v [ -w CMDFILEADDR ]
97 [ -x INSTANCES ]
plars4a120e82004-09-02 18:56:06 +000098
subrata_modakbc833d32007-07-25 10:12:02 +000099 -C FAILCMDFILE Command file with all failed test cases.
plars4a120e82004-09-02 18:56:06 +0000100 -c NUM_PROCS Run LTP under additional background CPU load.
101 -d TMPDIR Directory where temporary files will be created.
mreed1091696422006-05-03 19:07:22 +0000102 -e Prints the date of the current LTP release
subrata_modakbc833d32007-07-25 10:12:02 +0000103 -f CMDFILES Execute user defined list of testcases (separate with ',')
plars4a120e82004-09-02 18:56:06 +0000104 -h Help. Prints all available options.
105 -i # (in Mb) Run LTP with a _min_ IO load of # Mb in background.
106 -l LOGFILE Log results of test in a logfile.
107 -m # (in Mb) Run LTP with a _min_ memory load of # Mb in background.
108 -N Run all the networking tests.
109 -n Run LTP with network traffic in background.
110 -o OUTPUTFILE Redirect test output to a file.
111 -p Human readable format logfiles.
112 -q Print less verbose output to screen.
113 -r LTPROOT Fully qualified path where testsuite is installed.
subrata_modaka1fd64b2007-04-11 11:24:49 +0000114 -s PATTERN Only run test cases which match PATTERN.
plars4a120e82004-09-02 18:56:06 +0000115 -t DURATION Execute the testsuite for given duration. Examples:
116 -t 60s = 60 seconds
117 -t 45m = 45 minutes
118 -t 24h = 24 hours
119 -t 2d = 2 days
robbiew7d43d772005-02-07 20:07:30 +0000120 -v Print more verbose output to screen.
subrata_modakbc833d32007-07-25 10:12:02 +0000121 -w CMDFILEADDR Uses wget to get the user's list of testcases.
plars4a120e82004-09-02 18:56:06 +0000122 -x INSTANCES Run multiple instances of this testsuite.
123
124 example: ./${0##*/} -i 1024 -m 128 -p -q -l /tmp/resultlog.$$ -d ${PWD}
125
plars4a120e82004-09-02 18:56:06 +0000126
127 EOF
128exit 0
129}
130
plars4a120e82004-09-02 18:56:06 +0000131main()
132{
subrata_modakbc833d32007-07-25 10:12:02 +0000133 local CMDFILES=""
plars4a120e82004-09-02 18:56:06 +0000134 local PRETTY_PRT=""
135 local ALT_DIR=0
136 local RUN_NETEST=0
137 local QUIET_MODE=""
robbiew7d43d772005-02-07 20:07:30 +0000138 local VERBOSE_MODE=""
plars4a120e82004-09-02 18:56:06 +0000139 local NETPIPE=0
140 local GENLOAD=0
141 local MEMSIZE=0
142 local DURATION=""
subrata_modakbc833d32007-07-25 10:12:02 +0000143 local CMDFILEADDR=""
plars4a120e82004-09-02 18:56:06 +0000144 local BYTESIZE=0
145 local LOGFILE=""
146 local SCENFILES=""
147 local PRETTY_PRT=""
robbiew7d43d772005-02-07 20:07:30 +0000148 local TAG_RESTRICT_STRING=""
149 local PAN_COMMAND=""
mreed1091696422006-05-03 19:07:22 +0000150 version_date=`head -n 1 $LTPROOT/ChangeLog`
plars4a120e82004-09-02 18:56:06 +0000151
subrata_modakbc833d32007-07-25 10:12:02 +0000152 while getopts c:C:d:f:ehi:l:m:Nno:pqr:s:t:vw:x: arg
plars4a120e82004-09-02 18:56:06 +0000153 do case $arg in
154 c)
155 NUM_PROCS=$(($OPTARG))
156 $LTPROOT/testcases/bin/genload --cpu $NUM_PROCS >/dev/null 2>&1 &
157 GENLOAD=1 ;;
subrata_modakbc833d32007-07-25 10:12:02 +0000158
subrata_modak6838ec32007-09-14 10:10:12 +0000159 C) echo "INFO: creating $LTPROOT/output directory"
160 [ ! -d $LTPROOT/output ] && \
161 {
162 mkdir -p $LTPROOT/output || \
163 {
164 echo "ERROR: failed to create $LTPROOT/output"
165 exit 1
166 }
167 }
168 case $OPTARG in
169 /*)
170 FAILCMDFILE="-C $OPTARG" ;;
171 *)
172 FAILCMDFILE="-C $LTPROOT/output/$OPTARG"
173 ALT_DIR=1 ;;
174 esac ;;
plars4a120e82004-09-02 18:56:06 +0000175
176 d) # append $$ to TMP, as it is recursively
177 # removed at end of script.
178 TMPBASE=$OPTARG
robbiew58247a52005-01-19 18:44:42 +0000179 TMP="${TMPBASE}/ltp-$$"
robbiew538bc1a2005-03-11 19:26:14 +0000180 export TMPDIR="$TMP";;
mreed1091696422006-05-03 19:07:22 +0000181 e) # Print out the version of LTP
182 version_of_ltp
183 ;;
plars4a120e82004-09-02 18:56:06 +0000184 f) # Execute user defined set of testcases.
subrata_modakbc833d32007-07-25 10:12:02 +0000185 # Can be more then one file, just separate it with ',', like:
186 # -f nfs,commands,/tmp/testfile
187 CMDFILES=$OPTARG;;
plars4a120e82004-09-02 18:56:06 +0000188
189 h) usage;;
190
191 i)
192 BYTESIZE=$(($OPTARG * 1024 * 1024))
193 $LTPROOT/testcases/bin/genload --io 1 >/dev/null 2>&1 &
mreed1056ecf392007-02-28 02:09:46 +0000194 $LTPROOT/testcases/bin/genload --hdd 1 --hdd-bytes $BYTESIZE \
plars4a120e82004-09-02 18:56:06 +0000195 >/dev/null 2>&1 &
196 GENLOAD=1 ;;
197
198 l)
subrata_modak6838ec32007-09-14 10:10:12 +0000199 LOGFILE_NAME="$OPTARG"
plars4a120e82004-09-02 18:56:06 +0000200 echo "INFO: creating $LTPROOT/results directory"
201 [ ! -d $LTPROOT/results ] && \
202 {
203 mkdir -p $LTPROOT/results || \
204 {
205 echo "ERROR: failed to create $LTPROOT/results"
206 exit 1
207 }
208 }
209 case $OPTARG in
210 /*)
211 LOGFILE="-l $OPTARG" ;;
212 *)
213 LOGFILE="-l $LTPROOT/results/$OPTARG"
214 ALT_DIR=1 ;;
215 esac ;;
216
217 m)
218 MEMSIZE=$(($OPTARG * 1024 * 1024))
219 $LTPROOT/testcases/bin/genload --vm 0 --vm-bytes $MEMSIZE \
220 >/dev/null 2>&1 &
221 GENLOAD=1;;
222
223 N) RUN_NETEST=1;;
224
225 n)
226 $LTPROOT/testcases/bin/netpipe.sh
227 NETPIPE=1;;
228
subrata_modak6838ec32007-09-14 10:10:12 +0000229 o) OUTPUTFILE_NAME="$OPTARG"
230 echo "INFO: creating $LTPROOT/output directory"
231 [ ! -d $LTPROOT/output ] && \
232 {
233 mkdir -p $LTPROOT/output || \
234 {
235 echo "ERROR: failed to create $LTPROOT/output"
236 exit 1
237 }
238 }
239 case $OPTARG in
240 /*)
241 OUTPUTFILE="-o $OPTARG";;
242 *)
243 OUTPUTFILE="-o $LTPROOT/output/$OPTARG"
244 ALT_DIR=1 ;;
245 esac ;;
plars4a120e82004-09-02 18:56:06 +0000246
247 p) PRETTY_PRT=" -p ";;
248
249 q) QUIET_MODE=" -q ";;
250
251 r) LTPROOT=$OPTARG;;
252
robbiew7d43d772005-02-07 20:07:30 +0000253 s) TAG_RESTRICT_STRING=$OPTARG;;
254
plars4a120e82004-09-02 18:56:06 +0000255 t) # In case you want to specify the time
256 # to run from the command line
257 # (2m = two minutes, 2h = two hours, etc)
258 DURATION="-t $OPTARG" ;;
259
robbiew7d43d772005-02-07 20:07:30 +0000260 v) VERBOSE_MODE=1;;
subrata_modakbc833d32007-07-25 10:12:02 +0000261
262 w) CMDFILEADDR=$OPTARG;;
robbiew7d43d772005-02-07 20:07:30 +0000263
plars4a120e82004-09-02 18:56:06 +0000264 x) # number of ltp's to run
265 cat <<-EOF >&1
266 WARNING: The use of -x can cause unpredictable failures, as a
267 result of concurrently running multiple tests designed
268 to be ran exclusively.
269 Pausing for 10 seconds..."
270 EOF
271 sleep 10
272 INSTANCES="-x $OPTARG -O ${TMP}";;
273
274 \?) usage;;
275 esac
276 done
subrata_modak6838ec32007-09-14 10:10:12 +0000277
278 ## It would be nice if a Failed File is compulsorily created (gives User better Idea of Tests that failed)
279
280 if [ ! "$FAILCMDFILE" ]; then ## User has not mentioned about Failed File name
281 echo Inside Failed File Name not Mentioned
282 [ ! -d $LTPROOT/output ] && \ ## Try Creating output Directory if it doesn exist in First Place
283 {
284 mkdir -p $LTPROOT/output || \
285 {
286 echo "ERROR: failed to create $LTPROOT/output" ## Chuk out if not possible due to weired reason(s)
287 exit 1
288 }
289 }
290 if [ ! "$OUTPUTFILE" ]; then ## User has not mentioned about Output File name either
291 if [ ! "$LOGFILE" ]; then ## User has not mentioned about Log File name either
292 FAILED_FILE_NAME=`date +"%Y_%b_%d-%Hh_%Mm_%Ss"`
293 FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
294 ALT_DIR=1
295 else ## User Fortunately wanted a log file,
296 FAILED_FILE_NAME=`basename $LOGFILE_NAME` ## Extract log file name and use it to construct Failed file name
297 FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
298 ALT_DIR=1
299 fi
300 else ## User Fortunately wanted a Output file
301 FAILED_FILE_NAME=`basename $OUTPUTFILE_NAME` ## Extract output file name and use it to construct Failed file name
302 FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
303 ALT_DIR=1
304 fi
305 fi
subrata_modaka1fd64b2007-04-11 11:24:49 +0000306
307 # Added -m 777 for tests that call tst_tmpdir() and try to
308 # write to it as user nobody
309 mkdir -m 777 -p $TMP || \
plars4a120e82004-09-02 18:56:06 +0000310 {
robbiew7d43d772005-02-07 20:07:30 +0000311 echo "FATAL: Unable to make temporary directory $TMP"
plars4a120e82004-09-02 18:56:06 +0000312 exit 1
313 }
314
315 cd $TMP || \
316 {
317 echo "could not cd ${TMP} ... exiting"
318 exit 1
319 }
320
321 [ "$RUN_NETEST" -eq 1 ] && \
322 {
323 [ -z "$RHOST" ] || [ -z "$PASSWD" ] && \
324 {
325 [ -z "$RHOST" ] && \
326 {
327 echo \
328 "INFO: Enter RHOST = 'name of the remote host machine'"
329 echo -n "-> "
330 read RHOST
331 }
332
333 [ -z "$PASSWD" ] && \
334 {
335 echo " "
336 echo \
337 "INFO: Enter PASSWD = 'root passwd of the remote host machine'"
338 echo -n "-> "
339 read PASSWD
340 }
341 export RHOST=$RHOST
342 export PASSWD=$PASSWD
343 echo "WARNING: security of $RHOST may be compromised"
344 }
345 }
346
347 # If user does not provide a command file select a default set of testcases
348 # to execute.
subrata_modakbc833d32007-07-25 10:12:02 +0000349 if [ -z "$CMDFILES" ] && [ -z "$CMDFILEADDR" ]
plars4a120e82004-09-02 18:56:06 +0000350 then
subrata_modakbc833d32007-07-25 10:12:02 +0000351 cat <<-EOF >&1
plars4a120e82004-09-02 18:56:06 +0000352
353 INFO: no command files were provided, using default,
354 system calls, memory management, IPC, scheduler
355 direct io, file system, math and pty tests will
356 now be executed
357
358 EOF
359
subrata_modakbc833d32007-07-25 10:12:02 +0000360 for SCENFILES in ${LTPROOT}/runtest/syscalls ${LTPROOT}/runtest/fs \
plars4a120e82004-09-02 18:56:06 +0000361 ${LTPROOT}/runtest/fsx ${LTPROOT}/runtest/dio \
362 ${LTPROOT}/runtest/mm ${LTPROOT}/runtest/ipc \
363 ${LTPROOT}/runtest/sched ${LTPROOT}/runtest/math \
subrata_modak0c5f9702007-04-26 11:02:47 +0000364 ${LTPROOT}/runtest/nptl ${LTPROOT}/runtest/pty \
365 ${LTPROOT}/runtest/containers
plars4a120e82004-09-02 18:56:06 +0000366 do
367 [ -a "$SCENFILES" ] || \
368 {
369 echo "FATAL: missing scenario file $SCENFILES"
370 exit 1
371 }
372
373 cat $SCENFILES >> ${TMP}/alltests || \
374 {
375 echo "FATAL: unable to create command file"
376 exit 1
377 }
378 done
subrata_modakbc833d32007-07-25 10:12:02 +0000379 fi
380
381 [ -n "$CMDFILES" ] && \
382 {
383 for SCENFILES in `echo "$CMDFILES" | sed 's/,/\n/g'`
384 do
385 [ -f "$SCENFILES" ] || SCENFILES="$LTPROOT/runtest/$SCENFILES"
386 cat "$SCENFILES" >> ${TMP}/alltests || \
387 {
388 echo "FATAL: unable to create command file"
389 exit 1
390 }
391 done
392 }
393
394 [ -n "$CMDFILEADDR" ] && \
395 {
396 wget -q "${CMDFILEADDR}" -O ${TMP}/wgetcmdfile
397 if [ $? -ne 0 ]; then
398 echo "FATAL: error while getting the command file with wget (address $CMDFILEADDR)"
399 exit 1
400 fi
401 cat "${TMP}/wgetcmdfile" >> ${TMP}/alltests || \
plars4a120e82004-09-02 18:56:06 +0000402 {
subrata_modakbc833d32007-07-25 10:12:02 +0000403 echo "FATAL: unable to create command file"
plars4a120e82004-09-02 18:56:06 +0000404 exit 1
405 }
subrata_modakbc833d32007-07-25 10:12:02 +0000406 }
407
plars4a120e82004-09-02 18:56:06 +0000408 [ "$RUN_NETEST" -eq 1 ] && \
409 {
410 for SCENFILES in ${LTPROOT}/runtest/tcp_cmds \
411 ${LTPROOT}/runtest/multicast \
412 ${LTPROOT}/runtest/rpc \
413 ${LTPROOT}/runtest/nfs
414 do
415 [ -a "$SCENFILES" ] || \
416 {
417 echo "FATAL: missing scenario file $SCENFILES"
418 exit 1
419 }
420
subrata_modakbc833d32007-07-25 10:12:02 +0000421 cat "$SCENFILES" >> ${TMP}/alltests || \
plars4a120e82004-09-02 18:56:06 +0000422 {
423 echo "FATAL: unable to create command file"
424 exit 1
425 }
426 done
427 }
subrata_modakbc833d32007-07-25 10:12:02 +0000428
plars4a120e82004-09-02 18:56:06 +0000429 # The fsx-linux tests use the SCRATCHDEV environment variable as a location
430 # that can be reformatted and run on. Set SCRATCHDEV if you want to run
431 # these tests. As a safeguard, this is disabled.
432 unset SCRATCHDEV
433 [ -n "$SCRATCHDEV" ] && \
434 {
435 cat ${LTPROOT}/runtest/fsx >> ${TMP}/alltests ||
436 {
437 echo "FATAL: unable to create fsx-linux tests command file"
438 exit 1
439 }
440 }
subrata_modakbc833d32007-07-25 10:12:02 +0000441
442 # If enabled, execute only test cases that match the PATTERN
443 if [ -n "$TAG_RESTRICT_STRING" ]
444 then
445 mv -f ${TMP}/alltests ${TMP}/alltests.orig
446 grep $TAG_RESTRICT_STRING ${TMP}/alltests.orig > ${TMP}/alltests #Not worth checking return codes for this case
447 fi
plars4a120e82004-09-02 18:56:06 +0000448
449 # check for required users and groups
450 ${LTPROOT}/IDcheck.sh &>/dev/null || \
451 {
452 echo "WARNING: required users and groups not present"
453 echo "WARNING: some test cases may fail"
454 }
robbiew7d43d772005-02-07 20:07:30 +0000455
plars4a120e82004-09-02 18:56:06 +0000456 # display versions of installed software
457 [ -z "$QUIET_MODE" ] && \
458 {
459 ${LTPROOT}/ver_linux || \
460 {
461 echo "WARNING: unable to display versions of software installed"
462 exit 1
463 }
464 }
465
466 [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test start time: $(date)" ; }
robbiew7d43d772005-02-07 20:07:30 +0000467 PAN_COMMAND="${LTPROOT}/pan/pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \
subrata_modakbc833d32007-07-25 10:12:02 +0000468 -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE"
robbiew7d43d772005-02-07 20:07:30 +0000469 if [ ! -z "$VERBOSE_MODE" ] ; then
470 echo "COMMAND: $PAN_COMMAND"
471 if [ ! -z "$TAG_RESTRICT_STRING" ] ; then
472 echo "INFO: Restricted to $TAG_RESTRICT_STRING"
473 fi
474 fi
475 #$PAN_COMMAND #Duplicated code here, because otherwise if we fail, only "PAN_COMMAND" gets output
plars4a120e82004-09-02 18:56:06 +0000476 ${LTPROOT}/pan/pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \
subrata_modakbc833d32007-07-25 10:12:02 +0000477 -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE
plars4a120e82004-09-02 18:56:06 +0000478
479 if [ $? -eq 0 ]; then
480 echo "INFO: pan reported all tests PASS"
481 VALUE=0
482 else
483 echo "INFO: pan reported some tests FAIL"
484 VALUE=1
485 fi
mreed1091696422006-05-03 19:07:22 +0000486 echo "LTP Version: $version_date"
487
plars4a120e82004-09-02 18:56:06 +0000488 [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test end time: $(date)" ; }
489
490 [ "$GENLOAD" -eq 1 ] && { killall -9 genload ; }
491 [ "$NETPIPE" -eq 1 ] && { killall -9 NPtcp ; }
492
493 [ "$ALT_DIR" -eq 1 ] && \
494 {
495 cat <<-EOF >&1
496
497 ###############################################################"
498
499 Done executing testcases."
subrata_modak6838ec32007-09-14 10:10:12 +0000500 log result(s) is in $LTPROOT/results directory"
501 output/failed result(s) in $LTPROOT/output directory [If you did not provide Absolute Path]
mreed1091696422006-05-03 19:07:22 +0000502 LTP Version: $version_date
plars4a120e82004-09-02 18:56:06 +0000503 ###############################################################"
504
505 EOF
506 }
507 exit $VALUE
508}
509
510cleanup()
511{
512 rm -rf ${TMP}
513}
514
515trap "cleanup" 0
516setup
517main "$@"