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