1#!/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 35# - all checks should be enlclosed in " " to avoid bash error 36# - exit with error if ltp-pan is not found in pan directory 37# 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 47# 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# Sep 14 2007 - Modified - Ricardo Salveti de Araujo 54# - cleaning and removing duplicated code 55# 56# Oct 27 2007 - Modified - Ricardo Salveti de Araujo and Subrata Modak 57# - better ways to integrate "ltp/tools/genload/stress" with "ltp/runltp" 58# Nov 24 2007 - Modified - Subrata Modak 59# - Added a new option to generate output in HTML format also. Also retaining 60# the original test format 61# Nov 28 2007 - Modified - Subrata Modak 62# - Added a new option to mail back LTP reports 63# May 19 2008 - Modified - Subrata Modak 64# - Added capability for default Log file generation 65# Aug 17 2009 - Modified - Subrata Modak 66# - Added Fault Injection generation Capability through -F Option 67# 68################################################################################# 69 70 71deprecated() 72{ 73 echo "-------------------------------------------" >&2 74 echo "INFO: runltp script is deprecated, try kirk" >&2 75 echo "https://github.com/linux-test-project/kirk" >&2 76 echo "-------------------------------------------" >&2 77} 78 79 80setup() 81{ 82 deprecated 83 84 cd `dirname $0` || \ 85 { 86 echo "FATAL: unable to change directory to $(dirname $0)" 87 exit 1 88 } 89 export LTPROOT=${PWD} 90 export TMPBASE="/tmp" 91 export PATH="${PATH}:${LTPROOT}/testcases/bin:${LTPROOT}/bin" 92 93 export LTP_DEV_FS_TYPE="ext2" 94 95 [ -d "$LTPROOT/testcases/bin" ] || 96 { 97 echo "FATAL: LTP not installed correctly" 98 echo "INFO: Follow directions in INSTALL!" 99 exit 1 100 } 101 102 [ -e "$LTPROOT/bin/ltp-pan" ] || 103 { 104 echo "FATAL: Test suite driver 'ltp-pan' not found" 105 echo "INFO: Follow directions in INSTALL!" 106 exit 1 107 } 108} 109 110version_of_ltp() 111{ 112 cat "$LTPROOT/Version" 113 exit 0 114} 115 116usage() 117{ 118 cat <<-EOF >&2 119 120 usage: ${0##*/} [ -a EMAIL_TO ] [ -c NUM_PROCS ] [ -C FAILCMDFILE ] [ -T TCONFCMDFILE ] 121 [ -d TMPDIR ] [ -D NUM_PROCS,NUM_FILES,NUM_BYTES,CLEAN_FLAG ] -e [ -f CMDFILES(,...) ] 122 [ -g HTMLFILE] [ -i NUM_PROCS ] [ -l LOGFILE ] [ -m NUM_PROCS,CHUNKS,BYTES,HANGUP_FLAG ] 123 -N -n [ -o OUTPUTFILE ] -p -q -Q [ -r LTPROOT ] [ -s PATTERN ] [ -t DURATION ] 124 -v [ -w CMDFILEADDR ] [ -x INSTANCES ] [ -b DEVICE ] [-B LTP_DEV_FS_TYPE] 125 [ -F LOOPS,PERCENTAGE ] [ -z BIG_DEVICE ] [-Z LTP_BIG_DEV_FS_TYPE] 126 127 -a EMAIL_TO EMAIL all your Reports to this E-mail Address 128 -c NUM_PROCS Run LTP under additional background CPU load 129 [NUM_PROCS = no. of processes creating the CPU Load by spinning over sqrt() 130 (Defaults to 1 when value)] 131 -C FAILCMDFILE Command file with all failed test cases. 132 -T TCONFCMDFILE Command file with all test cases that are not fully tested. 133 -d TMPDIR Directory where temporary files will be created. 134 -D NUM_PROCS,NUM_FILES,NUM_BYTES,CLEAN_FLAG 135 Run LTP under additional background Load on Secondary Storage (separated by comma) 136 [NUM_PROCS = no. of processes creating Storage Load by spinning over write()] 137 [NUM_FILES = Write() to these many files (Defaults to 1 when value 0 or undefined)] 138 [NUM_BYTES = write these many bytes (defaults to 1GB, when value 0 or undefined)] 139 [CLEAN_FLAG = unlink file to which random data written, when value 1] 140 -e Prints the date of the current LTP release 141 -f CMDFILES Execute user defined list of testcases (separate with ',') 142 -F LOOPS,PERCENTAGE Induce PERCENTAGE Fault in the Kernel Subsystems, and, run each test for LOOPS loop 143 -g HTMLFILE Create an additional HTML output format 144 -h Help. Prints all available options. 145 -i NUM_PROCS Run LTP under additional background Load on IO Bus 146 [NUM_PROCS = no. of processes creating IO Bus Load by spinning over sync()] 147 -K DMESG_LOG_DIR 148 Log Kernel messages generated for each test cases inside this directory 149 -l LOGFILE Log results of test in a logfile. 150 -m NUM_PROCS,CHUNKS,BYTES,HANGUP_FLAG 151 Run LTP under additional background Load on Main memory (separated by comma) 152 [NUM_PROCS = no. of processes creating main Memory Load by spinning over malloc()] 153 [CHUNKS = malloc these many chunks (default is 1 when value 0 or undefined)] 154 [BYTES = malloc CHUNKS of BYTES bytes (default is 256MB when value 0 or undefined) ] 155 [HANGUP_FLAG = hang in a sleep loop after memory allocated, when value 1] 156 -M CHECK_TYPE 157 [CHECK_TYPE=1 => Full Memory Leak Check tracing children as well] 158 [CHECK_TYPE=2 => Thread Concurrency Check tracing children as well] 159 [CHECK_TYPE=3 => Full Memory Leak & Thread Concurrency Check tracing children as well] 160 -N Run all the networking tests. 161 -o OUTPUTFILE Redirect test output to a file. 162 -p Human readable format logfiles. 163 -q Print less verbose output to screen. This implies 164 not logging start of the test in kernel log. 165 -Q Don't log start of test in kernel log. 166 -r LTPROOT Fully qualified path where testsuite is installed. 167 -R Randomize test order. 168 -s PATTERN Only run test cases which match PATTERN. 169 -S SKIPFILE Skip tests specified in SKIPFILE 170 -t DURATION Execute the testsuite for given duration. Examples: 171 -t 60s = 60 seconds 172 -t 45m = 45 minutes 173 -t 24h = 24 hours 174 -t 2d = 2 days 175 -I ITERATIONS Execute the testsuite ITERATIONS times. 176 -w CMDFILEADDR Uses wget to get the user's list of testcases. 177 -x INSTANCES Run multiple instances of this testsuite. 178 -b DEVICE Some tests require an unmounted block device 179 to run correctly. 180 -B LTP_DEV_FS_TYPE The file system of test block devices. 181 -z BIG_DEVICE Some tests require a big unmounted block device 182 to run correctly. 183 -Z LTP_BIG_DEV_FS_TYPE The file system of the big device 184 -W ZOOFILE Specify the zoo file used to record current test tags (default PID of this script) 185 186 187 188 example: ${0##*/} -c 2 -i 2 -m 2,4,10240,1 -D 2,10,10240,1 -p -q -l /tmp/result-log.$$ -o /tmp/result-output.$$ -C /tmp/result-failed.$$ -d ${PWD} 189 190 191 EOF 192exit 0 193} 194 195main() 196{ 197 local CMDFILES= 198 local PRETTY_PRT= 199 local ALT_DIR_OUT=0 200 local ALT_DIR_RES=0 201 local ALT_HTML_OUT=0 202 local ALT_EMAIL_OUT=0 203 local ALT_DMESG_OUT=0 204 local RUN_NETEST=0 205 local RUN_REPEATED=0 206 local QUIET_MODE= 207 local NO_KMSG= 208 local NETPIPE=0 209 local GENLOAD=0 210 local MEMSIZE=0 211 local DURATION= 212 local CMDFILEADDR= 213 local FAILCMDFILE= 214 local TCONFCMDFILE= 215 local INJECT_KERNEL_FAULT= 216 local INJECT_KERNEL_FAULT_PERCENTAGE= 217 local INJECT_FAULT_LOOPS_PER_TEST= 218 local VALGRIND_CHECK= 219 local VALGRIND_CHECK_TYPE= 220 local LOGFILE_NAME= 221 local LOGFILE= 222 local OUTPUTFILE_NAME= 223 local OUTPUTFILE= 224 local HTMLFILE_NAME= 225 local HTMLFILE= 226 local DMESG_DIR= 227 local EMAIL_TO= 228 local TAG_RESTRICT_STRING= 229 local PAN_COMMAND= 230 local RANDOMRUN=0 231 local DEFAULT_FILE_NAME_GENERATION_TIME=`date +"%Y_%m_%d-%Hh_%Mm_%Ss"` 232 local scenfile= 233 local ZOOFILE=$$ 234 235 version_date=$(cat "$LTPROOT/Version") 236 237 while getopts a:b:B:c:C:T:d:D:ef:F:g:hi:I:K:l:m:M:No:pqQr:Rs:S:t:T:w:x:z:Z:W: arg 238 do case $arg in 239 a) EMAIL_TO=$OPTARG 240 ALT_EMAIL_OUT=1;; 241 c) 242 NUM_PROCS=$(($OPTARG)) 243 if [ "$NUM_PROCS" -eq 0 ]; then 244 # User Did not Define the Value ,or, User Defined Zero, 245 # hence, prevent from creating infinite processes 246 NUM_PROCS=1 247 fi 248 $LTPROOT/testcases/bin/genload --cpu $NUM_PROCS >/dev/null 2>&1 & 249 GENLOAD=1 ;; 250 251 C) 252 case $OPTARG in 253 /*) 254 FAILCMDFILE="-C $OPTARG" ;; 255 *) 256 FAILCMDFILE="-C $LTPROOT/output/$OPTARG" 257 ALT_DIR_OUT=1 ;; 258 esac ;; 259 260 T) 261 case $OPTARG in 262 /*) 263 TCONFCMDFILE="-T $OPTARG" ;; 264 *) 265 TCONFCMDFILE="-T $LTPROOT/output/$OPTARG" 266 ALT_DIR_OUT=1 ;; 267 esac ;; 268 269 d) # convert the user path to absolute path. 270 export TMPBASE=$(readlink -f ${OPTARG}) ;; 271 272 D) NUM_PROCS=1; NUM_FILES=1; NUM_BYTES=$((1024 * 1024 * 1024)); CLEAN_FLAG=0 273 ARGUMENT_LIST=$OPTARG 274 TOTAL_ARGUMENTS=1 275 for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '` 276 do 277 case $TOTAL_ARGUMENTS in 278 1) NUM_PROCS="$ARGUMENT" ;; 279 2) NUM_FILES="$ARGUMENT" ;; 280 3) NUM_BYTES="$ARGUMENT" ;; 281 4) CLEAN_FLAG="$ARGUMENT" ;; 282 esac 283 TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1` 284 done 285 # just to get the default values if the user passed 0 286 if [ "$NUM_PROCS" -eq 0 ]; then 287 NUM_PROCS=1 288 fi 289 if [ "$NUM_FILES" -eq 0 ]; then 290 NUM_FILES=1 291 fi 292 if [ "$NUM_BYTES" -eq 0 ]; then 293 NUM_BYTES=$((1024 * 1024 * 1024)) 294 fi 295 if [ "$CLEAN_FLAG" -ne 1 ]; then 296 CLEAN_FLAG=0 297 fi 298 if [ "$CLEAN_FLAG" -eq 1 ]; then 299 # Do not unlink file in this case 300 $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \ 301 $NUM_FILES --hdd-bytes $NUM_BYTES >/dev/null 2>&1 & 302 else 303 # Cleanup otherwise 304 $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \ 305 $NUM_FILES --hdd-bytes $NUM_BYTES --hdd-noclean >/dev/null 2>&1 & 306 fi 307 GENLOAD=1;; 308 309 e) # Print out the version of LTP 310 version_of_ltp 311 ;; 312 f) # Execute user defined set of testcases. 313 # Can be more than one file, just separate it with ',', like: 314 # -f nfs,commands,/tmp/testfile 315 CMDFILES=$OPTARG;; 316 F) INJECT_KERNEL_FAULT=1 317 # Separate out the NO_OF_LOOPS & FAULT_PERCENTAGE 318 INJECT_FAULT_LOOPS_PER_TEST=`echo $OPTARG |cut -d',' -f1 | tr -d '\n' | tr -d ' '` 319 INJECT_KERNEL_FAULT_PERCENTAGE=`echo $OPTARG |cut -d',' -f2 | tr -d '\n' | tr -d ' '` 320 if [ ! $INJECT_FAULT_LOOPS_PER_TEST ]; then 321 echo "Loops not properly defined. Resorting to default 5..." 322 export INJECT_FAULT_LOOPS_PER_TEST=5 323 fi 324 if [ ! $INJECT_KERNEL_FAULT_PERCENTAGE ]; then 325 echo "Fault Persentage not properly defined. Resorting to default 10..." 326 export INJECT_KERNEL_FAULT_PERCENTAGE=10 327 fi;; 328 g) HTMLFILE_NAME="$OPTARG" 329 case $OPTARG in 330 /*) 331 HTMLFILE="$OPTARG";; 332 *) 333 HTMLFILE="$LTPROOT/output/$OPTARG" 334 ALT_DIR_OUT=1;; 335 esac 336 ALT_HTML_OUT=1;; 337 h) usage;; 338 339 i) 340 NUM_PROCS=$(($OPTARG)) 341 if [ "$NUM_PROCS" -eq 0 ]; then 342 # User Did not Define the Value ,or, User Defined Zero, 343 # hence, prevent from creating infinite processes 344 NUM_PROCS=1 345 fi 346 $LTPROOT/testcases/bin/genload --io $NUM_PROCS >/dev/null 2>&1 & 347 GENLOAD=1 ;; 348 349 K) 350 case $OPTARG in 351 /*) 352 DMESG_DIR="$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";; 353 *) 354 DMESG_DIR="$LTPROOT/output/$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";; 355 esac 356 mkdir -p $DMESG_DIR 357 ALT_DMESG_OUT=1;; 358 l) 359 LOGFILE_NAME="$OPTARG" 360 case $OPTARG in 361 /*) 362 LOGFILE="-l $OPTARG" ;; 363 *) 364 LOGFILE="-l $LTPROOT/results/$OPTARG" 365 ALT_DIR_RES=1 ;; 366 esac ;; 367 368 m) NUM_PROCS=1; CHUNKS=1; BYTES=$((256 * 1024 * 1024)); HANGUP_FLAG=0 369 ARGUMENT_LIST=$OPTARG 370 TOTAL_ARGUMENTS=1 371 for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '` 372 do 373 case $TOTAL_ARGUMENTS in 374 1) NUM_PROCS="$ARGUMENT" ;; 375 2) CHUNKS="$ARGUMENT" ;; 376 3) BYTES="$ARGUMENT" ;; 377 4) HANGUP_FLAG="$ARGUMENT" ;; 378 esac 379 TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1` 380 done 381 # just to get the default values if the user passed 0 382 if [ "$NUM_PROCS" -eq 0 ]; then 383 NUM_PROCS=1 384 fi 385 if [ "$CHUNKS" -eq 0 ]; then 386 CHUNKS=1 387 fi 388 if [ "$BYTES" -eq 0 ]; then 389 BYTES=$((256 * 1024 * 1024)) 390 fi 391 if [ "$HANGUP_FLAG" -ne 1 ]; then 392 HANGUP_FLAG=0 393 fi 394 if [ "$HANGUP_FLAG" -eq 1 ]; then 395 # Hang in a Sleep loop after memory allocated 396 $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \ 397 $CHUNKS --vm-bytes $BYTES --vm-hang >/dev/null 2>&1 & 398 else 399 # Otherwise Do not Hangup 400 $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \ 401 $CHUNKS --vm-bytes $BYTES >/dev/null 2>&1 & 402 fi 403 GENLOAD=1;; 404 M) 405 VALGRIND_CHECK=1 406 VALGRIND_CHECK_TYPE="$OPTARG";; 407 408 N) RUN_NETEST=1;; 409 410 o) OUTPUTFILE_NAME="$OPTARG" 411 case $OPTARG in 412 /*) 413 OUTPUTFILE="-o $OPTARG";; 414 *) 415 OUTPUTFILE="-o $LTPROOT/output/$OPTARG" 416 ALT_DIR_OUT=1 ;; 417 esac ;; 418 419 p) PRETTY_PRT="-p";; 420 421 q) QUIET_MODE="-q";; 422 423 Q) NO_KMSG="-Q";; 424 425 r) LTPROOT=$OPTARG;; 426 427 R) RANDOMRUN=1;; 428 429 s) TAG_RESTRICT_STRING=$OPTARG;; 430 431 S) case $OPTARG in 432 /*) 433 SKIPFILE=$OPTARG;; 434 *) 435 SKIPFILE="$LTPROOT/$OPTARG";; 436 esac ;; 437 438 t) # In case you want to specify the time 439 # to run from the command line 440 # (2m = two minutes, 2h = two hours, etc) 441 DURATION="-t $OPTARG" ;; 442 443 I) # In case you want the testcases to runsequentially RUN_REPEATED times 444 RUN_REPEATED=$OPTARG;; 445 446 w) CMDFILEADDR=$OPTARG;; 447 448 x) # number of ltp's to run 449 cat <<-EOF >&1 450 WARNING: The use of -x can cause unpredictable failures, as a 451 result of concurrently running multiple tests designed 452 to be ran exclusively. 453 Pausing for 10 seconds..." 454 EOF 455 sleep 10 456 INSTANCES="-x $OPTARG";; 457 b) DEVICE=$OPTARG;; 458 B) LTP_DEV_FS_TYPE=$OPTARG;; 459 z) BIG_DEVICE=$OPTARG;; 460 Z) BIG_DEVICE_FS_TYPE=$OPTARG;; 461 W) ZOOFILE=$OPTARG;; 462 \?) usage;; 463 esac 464 done 465 466 ## It would be nice to create a default log file even if the user has not mentioned 467 if [ ! "$LOGFILE" ]; then ## User has not mentioned about Log File name 468 LOGFILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME" 469 LOGFILE="-l $LTPROOT/results/LTP_RUN_ON-$LOGFILE_NAME.log" 470 ALT_DIR_RES=1 471 PRETTY_PRT="-p" 472 fi 473 474 ## It would be nice if a Failed File is compulsorily created (gives User better Idea of Tests that failed) 475 476 if [ ! "$FAILCMDFILE" ]; then ## User has not mentioned about Failed File name 477 ALT_DIR_OUT=1 478 if [ ! "$OUTPUTFILE" ]; then ## User has not mentioned about Output File name either 479 if [ ! "$LOGFILE" ]; then ## User has not mentioned about Log File name either 480 FAILED_FILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME" 481 FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed" 482 else ## User Fortunately wanted a log file, 483 FAILED_FILE_NAME=`basename $LOGFILE_NAME` ## Extract log file name and use it to construct Failed file name 484 FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed" 485 fi 486 else ## User Fortunately wanted a Output file 487 FAILED_FILE_NAME=`basename $OUTPUTFILE_NAME` ## Extract output file name and use it to construct Failed file name 488 FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed" 489 fi 490 fi 491 492 if [ ! "$TCONFCMDFILE" ]; then 493 ALT_DIR_OUT=1 494 if [ ! "$OUTPUTFILE" ]; then 495 if [ ! "$LOGFILE" ]; then 496 TCONF_FILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME" 497 TCONFCMDFILE="-T $LTPROOT/output/LTP_RUN_ON-${TCONF_FILE_NAME}.tconf" 498 else 499 TCONF_FILE_NAME=`basename $LOGFILE_NAME` 500 TCONFCMDFILE="-T $LTPROOT/output/LTP_RUN_ON-${TCONF_FILE_NAME}.tconf" 501 fi 502 else 503 TCONF_FILE_NAME=`basename $OUTPUTFILE_NAME` 504 TCONFCMDFILE="-T $LTPROOT/output/LTP_RUN_ON-${TCONF_FILE_NAME}.tconf" 505 fi 506 fi 507 508 if [ "$ALT_HTML_OUT" -eq 1 ] ; then ## User wants the HTML version of the output 509 QUIET_MODE="" ## Suppressing this guy as it will prevent generation of proper output 510 ## which the HTML parser will require 511 if [ ! "$OUTPUTFILE" ]; then ## User has not mentioned about the Outputfile name, then we need to definitely generate one 512 OUTPUTFILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME" 513 OUTPUTFILE="-o $LTPROOT/output/LTP_RUN_ON-$OUTPUTFILE_NAME.output" 514 ALT_DIR_OUT=1 515 fi 516 fi 517 518 # If we need, create the output directory 519 [ "$ALT_DIR_OUT" -eq 1 ] && \ 520 { 521 [ ! -d $LTPROOT/output ] && \ 522 { 523 echo "INFO: creating $LTPROOT/output directory" 524 mkdir -p $LTPROOT/output || \ 525 { 526 echo "ERROR: failed to create $LTPROOT/output" 527 exit 1 528 } 529 } 530 } 531 532 # If we need, create the results directory 533 [ "$ALT_DIR_RES" -eq 1 ] && \ 534 { 535 [ ! -d $LTPROOT/results ] && \ 536 { 537 echo "INFO: creating $LTPROOT/results directory" 538 mkdir -p $LTPROOT/results || \ 539 { 540 echo "ERROR: failed to create $LTPROOT/results" 541 exit 1 542 } 543 } 544 } 545 546 # Added -m 777 for tests that call tst_tmpdir() and try to 547 # write to it as user nobody 548 mkdir -m 777 -p $TMPBASE || \ 549 { 550 echo "FATAL: Unable to make temporary directory $TMPBASE" 551 exit 1 552 } 553 # use mktemp to create "safe" temporary directories 554 export TMPTEMPLATE="${TMPBASE}/ltp-XXXXXXXXXX" 555 TMP=`mktemp -d $TMPTEMPLATE` || \ 556 { 557 echo "FATAL: Unable to make temporary directory: $TMP" 558 exit 1 559 } 560 export TMP 561 # To be invoked by tst_tmpdir() 562 # write to it as user nobody 563 export TMPDIR=$TMP 564 565 trap "cleanup" 0 566 567 chmod 777 $TMP || \ 568 { 569 echo "unable to chmod 777 $TMP ... aborting" 570 exit 1 571 } 572 573 cd $TMP || \ 574 { 575 echo "could not cd ${TMP} ... exiting" 576 exit 1 577 } 578 579 [ -n "$INSTANCES" ] && \ 580 { 581 INSTANCES="$INSTANCES -O ${TMP}" 582 } 583 584 # If user does not provide a command file select a default set of testcases 585 # to execute. 586 if [ -z "$CMDFILES" ] && [ -z "$CMDFILEADDR" ]; then 587 588 SCENARIO_LISTS="$LTPROOT/scenario_groups/default" 589 if [ "$RUN_NETEST" -eq 1 ]; then 590 SCENARIO_LISTS="$LTPROOT/scenario_groups/network" 591 fi 592 593 cat <<-EOF >&1 594INFO: no command files were provided. Executing following runtest scenario files: 595`cat $SCENARIO_LISTS | tr '\012' ' '` 596 597EOF 598 cat_ok_sentinel=$TMP/cat_ok.$$ 599 touch "$cat_ok_sentinel" 600 cat $SCENARIO_LISTS | while read scenfile; do 601 scenfile=${LTPROOT}/runtest/$scenfile 602 [ -f "$scenfile" ] || continue 603 604 cat $scenfile >> "$TMP/alltests" || { 605 echo "FATAL: unable to append to command file" 606 rm -Rf "$TMP" 607 rm -f "$cat_ok_sentinel" 608 exit 1 609 } 610 done 611 rm -f "$cat_ok_sentinel" 612 fi 613 614 [ -n "$CMDFILES" ] && \ 615 { 616 for scenfile in `echo "$CMDFILES" | tr ',' ' '` 617 do 618 [ -f "$scenfile" ] || scenfile="$LTPROOT/runtest/$scenfile" 619 cat "$scenfile" >> ${TMP}/alltests || \ 620 { 621 echo "FATAL: unable to create command file" 622 rm -Rf "$TMP" 623 exit 1 624 } 625 done 626 } 627 628 [ -n "$CMDFILEADDR" ] && \ 629 { 630 wget -q "${CMDFILEADDR}" -O ${TMP}/wgetcmdfile 631 if [ $? -ne 0 ]; then 632 echo "FATAL: error while getting the command file with wget (address $CMDFILEADDR)" 633 exit 1 634 fi 635 cat "${TMP}/wgetcmdfile" >> ${TMP}/alltests || \ 636 { 637 echo "FATAL: unable to create command file" 638 exit 1 639 } 640 } 641 642 # If enabled, execute only test cases that match the PATTERN 643 if [ -n "$TAG_RESTRICT_STRING" ] 644 then 645 mv -f ${TMP}/alltests ${TMP}/alltests.orig 646 grep $TAG_RESTRICT_STRING ${TMP}/alltests.orig > ${TMP}/alltests #Not worth checking return codes for this case 647 fi 648 649 # Blacklist or skip tests if a SKIPFILE was specified with -S 650 if [ -n "${SKIPFILE}" ]; then 651 for test_name in $(awk '{print $1}' "${SKIPFILE}"); do 652 case "${test_name}" in \#*) continue;; esac 653 sed -i "/\<${test_name}\>/c\\${test_name} exit 32;" alltests 654 done 655 fi 656 657 # check for required users and groups 658 ${LTPROOT}/IDcheck.sh || \ 659 { 660 echo "WARNING: required users and groups not present" 661 echo "WARNING: some test cases may fail" 662 } 663 664 # display versions of installed software 665 [ -z "$QUIET_MODE" ] && \ 666 { 667 ${LTPROOT}/ver_linux || \ 668 { 669 echo "WARNING: unable to display versions of software installed" 670 exit 1 671 } 672 } 673 674 set_block_device 675 676 # here even if the user don't specify a big block device, we 677 # also don't create the big block device. 678 if [ -z "$BIG_DEVICE" ]; then 679 echo "no big block device was specified on commandline." 680 echo "Tests which require a big block device are disabled." 681 echo "You can specify it with option -z" 682 else 683 export LTP_BIG_DEV=$BIG_DEVICE 684 if [ -z "$BIG_DEVICE_FS_TYPE" ]; then 685 export LTP_BIG_DEV_FS_TYPE="ext2" 686 else 687 export LTP_BIG_DEV_FS_TYPE=$BIG_DEVICE_FS_TYPE 688 fi 689 fi 690 691 if [ $RUN_REPEATED -gt 1 ]; then # You need to specify at least more than 1 sequential run, else it runs default 692 echo "PAN will run these test cases $RUN_REPEATED times....." 693 echo "Test Tags will be Prepended with ITERATION NO.s....." 694 inc=1 695 sed -e '/^$/ d' -e 's/^[ ,\t]*//' -e '/^#/ d' < ${TMP}/alltests > ${TMP}/alltests.temp ##This removes all newlines, leading spaces, tabs, # 696 sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp > ${TMP}/alltests ## .temp is kept as Base file 697 while [ $inc -lt $RUN_REPEATED ] ; do 698 inc=`expr $inc + 1` 699 sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp >> ${TMP}/alltests #Keep appending with Iteration No.s 700 done 701 fi 702 703 if [ "$RANDOMRUN" != "0" ]; then 704 sort -R ${TMP}/alltests -o ${TMP}/alltests 705 fi 706 707 [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test start time: $(date)" ; } 708 PAN_COMMAND="${LTPROOT}/bin/ltp-pan $QUIET_MODE $NO_KMSG -e -S $INSTANCES $DURATION -a ${ZOOFILE} \ 709 -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE $TCONFCMDFILE" 710 echo "COMMAND: $PAN_COMMAND" 711 if [ ! -z "$TAG_RESTRICT_STRING" ] ; then 712 echo "INFO: Restricted to $TAG_RESTRICT_STRING" 713 fi 714 #$PAN_COMMAND #Duplicated code here, because otherwise if we fail, only "PAN_COMMAND" gets output 715 716 ## Display the Output/Log/Failed/HTML file names here 717 printf "LOG File: " 718 echo $LOGFILE | cut -b4- 719 720 if [ "$OUTPUTFILE" ]; then 721 printf "OUTPUT File: " 722 echo $OUTPUTFILE | cut -b4- 723 fi 724 725 printf "FAILED COMMAND File: " 726 echo $FAILCMDFILE | cut -b4- 727 728 printf "TCONF COMMAND File: " 729 echo $TCONFCMDFILE | cut -b4- 730 731 if [ "$HTMLFILE" ]; then 732 echo "HTML File: $HTMLFILE" 733 fi 734 735 echo "Running tests......." 736 test_start_time=$(date) 737 738 # User wants testing with Kernel Fault Injection 739 if [ $INJECT_KERNEL_FAULT ] ; then 740 #See if Debugfs is mounted, and 741 #Fault Injection Framework available through Debugfs 742 use_faultinjection=true 743 for debug_subdir in \ 744 fail_io_timeout \ 745 fail_make_request \ 746 fail_page_alloc \ 747 failslab \ 748 ; do 749 if [ -d "/sys/kernel/debug/$debug_subdir" ] 750 then 751 use_faultinjection=true 752 break 753 fi 754 done 755 if $use_faultinjection; then 756 #If at least one of the Framework is available 757 #Go ahead to Inject Fault & Create required 758 #Command Files for LTP run 759 echo Running tests with Fault Injection Enabled in the Kernel... 760 awk -v LOOPS=$INJECT_FAULT_LOOPS_PER_TEST \ 761 -v PERCENTAGE=$INJECT_KERNEL_FAULT_PERCENTAGE \ 762 -f ${LTPROOT}/bin/create_kernel_faults_in_loops_and_probability.awk \ 763 ${TMP}/alltests > ${TMP}/alltests.tmp 764 cp ${TMP}/alltests.tmp ${TMP}/alltests 765 rm -rf ${TMP}/alltests.tmp 766 else 767 echo Fault Injection not enabled in the Kernel.. 768 echo Running tests normally... 769 fi 770 fi 771 772 ## Valgrind Check will work only when Kernel Fault Injection is not expected, 773 ## We do not want to test Faults when valgrind is running 774 if [ $VALGRIND_CHECK ]; then 775 if [ ! $INJECT_KERNEL_FAULT ]; then 776 which valgrind || VALGRIND_CHECK_TYPE=XYZ 777 case $VALGRIND_CHECK_TYPE in 778 [1-3]) 779 awk -v CHECK_LEVEL=$VALGRIND_CHECK_TYPE \ 780 -f ${LTPROOT}/bin/create_valgrind_check.awk \ 781 ${TMP}/alltests $VALGRIND_CHECK_TYPE > \ 782 ${TMP}/alltests.tmp 783 cp ${TMP}/alltests.tmp ${TMP}/alltests 784 rm -rf ${TMP}/alltests.tmp 785 ;; 786 *) 787 echo "Invalid Memory Check Type, or, Valgrind is not available" 788 ;; 789 esac 790 fi 791 fi 792 793 if [ $ALT_DMESG_OUT -eq 1 ] ; then 794 #We want to print dmesg output for each test,lets do the trick inside the script 795 echo Enabling dmesg output logging for each test... 796 awk -v DMESG_DIR=$DMESG_DIR \ 797 -f ${LTPROOT}/bin/create_dmesg_entries_for_each_test.awk \ 798 ${TMP}/alltests > ${TMP}/alltests.tmp 799 cp ${TMP}/alltests.tmp ${TMP}/alltests 800 rm -rf ${TMP}/alltests.tmp 801 fi 802 # Some tests need to run inside the "bin" directory. 803 cd "${LTPROOT}/testcases/bin" 804 "${LTPROOT}/bin/ltp-pan" $QUIET_MODE $NO_KMSG -e -S $INSTANCES $DURATION -a ${ZOOFILE} -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE $TCONFCMDFILE 805 806 if [ $? -eq 0 ]; then 807 echo "INFO: ltp-pan reported all tests PASS" 808 VALUE=0 809 export LTP_EXIT_VALUE=0; 810 else 811 echo "INFO: ltp-pan reported some tests FAIL" 812 VALUE=1 813 export LTP_EXIT_VALUE=1; 814 fi 815 cd .. 816 echo "LTP Version: $version_date" 817 818 # $DMESG_DIR is used to cache messages obtained from dmesg after a test run. 819 # Proactively reap all of the 0-byte files in $DMESG_DIR as they have zero value 820 # and only clutter up the filesystem. 821 822 if [ $ALT_DMESG_OUT -eq 1 ] ; then 823 if ! find "$DMESG_DIR" -size 0 -exec rm {} + ; then 824 echo "cd to $DMESG_DIR failed: $?" 825 fi 826 if [ -n "$(ls "$DMESG_DIR")" ] ; then 827 echo "Kernel messages were generated for LTP tests $version_date" 828 else 829 echo "No Kernel messages were generated for LTP tests $version_date" 830 fi 831 fi 832 833 if [ "$ALT_HTML_OUT" -eq 1 ] ; then #User wants the HTML output to be created, it then needs to be generated 834 export LTP_VERSION=$version_date 835 export TEST_START_TIME="$test_start_time" 836 export TEST_END_TIME="$(date)" 837 OUTPUT_FILE=`echo $OUTPUTFILE | cut -c4-` 838 LOGS_DIRECTORY="$LTPROOT/results" 839 export TEST_OUTPUT_DIRECTORY="$LTPROOT/output" 840 export TEST_LOGS_DIRECTORY=$LOGS_DIRECTORY 841 echo "Generating HTML Output.....!!" 842 ( perl $LTPROOT/bin/genhtml.pl $LTPROOT/bin/html_report_header.txt test_start test_end test_output execution_status $OUTPUT_FILE > $HTMLFILE; ) 843 echo "Generated HTML Output.....!!" 844 echo "Location: $HTMLFILE"; 845 846 fi 847 848 if [ "$ALT_EMAIL_OUT" -eq 1 ] ; then ## User wants reports to be e-mailed 849 TAR_FILE_NAME=LTP_RUN_$version_date$DEFAULT_FILE_NAME_GENERATION_TIME.tar 850 if [ "$HTMLFILE_NAME" ] ; then ## HTML file Exists 851 if [ "$ALT_HTML_OUT" -ne 1 ] ; then ## The HTML file path is absolute and not $LTPROOT/output 852 mkdir -p $LTPROOT/output ## We need to create this Directory 853 cp $HTMLFILE_NAME $LTPROOT/output/ 854 fi 855 fi 856 if [ "$OUTPUTFILE_NAME" ] ; then ## Output file exists 857 if [ "$ALT_DIR_OUT" -ne 1 ] ; then ## The Output file path is absolute and not $LTPROOT/output 858 mkdir -p $LTPROOT/output ## We need to create this Directory 859 cp $OUTPUTFILE_NAME $LTPROOT/output/ 860 fi 861 fi 862 if [ "$LOGFILE_NAME" ] ; then ## Log file exists 863 if [ "$ALT_DIR_RES" -ne 1 ] ; then ## The Log file path is absolute and not $LTPROOT/results 864 mkdir -p $LTPROOT/results ## We need to create this Directory 865 cp $LOGFILE_NAME $LTPROOT/results/ 866 fi 867 fi 868 if [ -d $LTPROOT/output ] ; then 869 tar -cf ./$TAR_FILE_NAME $LTPROOT/output 870 if [ $? -eq 0 ]; then 871 echo "Created TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/output" 872 else 873 echo "Cannot Create TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/output" 874 fi 875 fi 876 if [ -d $LTPROOT/results ] ; then 877 tar -uf ./$TAR_FILE_NAME $LTPROOT/results 878 if [ $? -eq 0 ]; then 879 echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/results" 880 else 881 echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/results" 882 fi 883 fi 884 if [ -e $LTPROOT/nohup.out ] ; then ## If User would have Chosen nohup to do ltprun 885 tar -uf ./$TAR_FILE_NAME $LTPROOT/nohup.out 886 if [ $? -eq 0 ]; then 887 echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/nohup.out" 888 else 889 echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/nohup.out" 890 fi 891 fi 892 gzip ./$TAR_FILE_NAME ## gzip this guy 893 if [ $? -eq 0 ]; then 894 echo "Gunzipped TAR File: ./$TAR_FILE_NAME" 895 else 896 echo "Cannot Gunzip TAR File: ./$TAR_FILE_NAME" 897 fi 898 if which mutt >/dev/null 2>&1; then 899 echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz" 900 mutt -a ./$TAR_FILE_NAME.gz -s "LTP Reports on $test_start_time" -- $EMAIL_TO < /dev/null 901 if [ $? -eq 0 ]; then 902 echo "Reports Successfully mailed to: $EMAIL_TO" 903 else 904 echo "Reports cannot be mailed to: $EMAIL_TO" 905 fi 906 else ## Use our Ageold mail program 907 echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz" 908 uuencode ./$TAR_FILE_NAME.gz $TAR_FILE_NAME.gz | mail $EMAIL_TO -s "LTP Reports on $test_start_time" 909 if [ $? -eq 0 ]; then 910 echo "Reports Successfully mailed to: $EMAIL_TO" 911 else 912 echo "Reports cannot be mailed to: $EMAIL_TO" 913 fi 914 fi 915 fi 916 917 [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test end time: $(date)" ; } 918 919 [ "$GENLOAD" -eq 1 ] && { killall -9 genload >/dev/null 2>&1; } 920 [ "$NETPIPE" -eq 1 ] && { killall -9 NPtcp >/dev/null 2>&1; } 921 922 [ "$ALT_DIR_OUT" -eq 1 ] || [ "$ALT_DIR_RES" -eq 1 ] && \ 923 { 924 cat <<-EOF >&1 925 926 ############################################################### 927 928 Done executing testcases. 929 LTP Version: $version_date 930 ############################################################### 931 932 EOF 933 } 934 935 deprecated 936 937 exit $VALUE 938} 939 940set_block_device() 941{ 942 if [ -n "$DEVICE" ]; then 943 export LTP_DEV=$DEVICE 944 fi 945} 946 947cleanup() 948{ 949 [ "$LOOP_DEV" ] && losetup -d $LOOP_DEV 950 rm -rf ${TMP} 951} 952 953 954LTP_SCRIPT="$(basename $0)" 955 956if [ "$LTP_SCRIPT" = "runltp" ]; then 957 setup 958 main "$@" 959fi 960