• 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 (Seperate 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 (Seperate 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
175
176
177    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}
178
179
180	EOF
181exit 0
182}
183
184main()
185{
186    local CMDFILES=
187    local PRETTY_PRT=
188    local ALT_DIR_OUT=0
189    local ALT_DIR_RES=0
190    local ALT_HTML_OUT=0
191    local ALT_EMAIL_OUT=0
192    local ALT_DMESG_OUT=0
193    local RUN_NETEST=0
194    local RUN_REPEATED=0
195    local QUIET_MODE=
196    local NO_KMSG=
197    local NETPIPE=0
198    local GENLOAD=0
199    local MEMSIZE=0
200    local DURATION=
201    local CMDFILEADDR=
202    local FAILCMDFILE=
203    local TCONFCMDFILE=
204    local INJECT_KERNEL_FAULT=
205    local INJECT_KERNEL_FAULT_PERCENTAGE=
206    local INJECT_FAULT_LOOPS_PER_TEST=
207    local VALGRIND_CHECK=
208    local VALGRIND_CHECK_TYPE=
209    local LOGFILE_NAME=
210    local LOGFILE=
211    local OUTPUTFILE_NAME=
212    local OUTPUTFILE=
213    local HTMLFILE_NAME=
214    local HTMLFILE=
215    local DMESG_DIR=
216    local EMAIL_TO=
217    local TAG_RESTRICT_STRING=
218    local PAN_COMMAND=
219    local RANDOMRUN=0
220    local DEFAULT_FILE_NAME_GENERATION_TIME=`date +"%Y_%m_%d-%Hh_%Mm_%Ss"`
221    local scenfile=
222
223    version_date=$(cat "$LTPROOT/Version")
224
225    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: arg
226    do  case $arg in
227        a)  EMAIL_TO=$OPTARG
228            ALT_EMAIL_OUT=1;;
229        c)
230            NUM_PROCS=$(($OPTARG))
231            if   [ "$NUM_PROCS" -eq 0 ]; then
232                # User Did not Define the Value ,or, User Defined Zero,
233                # hence, prevent from creating infinite processes
234                NUM_PROCS=1
235            fi
236            $LTPROOT/testcases/bin/genload --cpu $NUM_PROCS >/dev/null 2>&1 &
237            GENLOAD=1 ;;
238
239        C)
240            case $OPTARG in
241            /*)
242                FAILCMDFILE="-C $OPTARG" ;;
243            *)
244                FAILCMDFILE="-C $LTPROOT/output/$OPTARG"
245                ALT_DIR_OUT=1 ;;
246            esac ;;
247
248        T)
249            case $OPTARG in
250            /*)
251                TCONFCMDFILE="-T $OPTARG" ;;
252            *)
253                TCONFCMDFILE="-T $LTPROOT/output/$OPTARG"
254                ALT_DIR_OUT=1 ;;
255            esac ;;
256
257        d)  # convert the user path to absolute path.
258            export TMPBASE=$(readlink -f ${OPTARG}) ;;
259
260        D)  NUM_PROCS=1; NUM_FILES=1; NUM_BYTES=$((1024 * 1024 * 1024)); CLEAN_FLAG=0
261            ARGUMENT_LIST=$OPTARG
262            TOTAL_ARGUMENTS=1
263            for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '`
264            do
265                case $TOTAL_ARGUMENTS in
266                    1) NUM_PROCS="$ARGUMENT" ;;
267                    2) NUM_FILES="$ARGUMENT" ;;
268                    3) NUM_BYTES="$ARGUMENT" ;;
269                    4) CLEAN_FLAG="$ARGUMENT" ;;
270                esac
271                TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1`
272            done
273            # just to get the default values if the user passed 0
274            if [ "$NUM_PROCS" -eq 0 ]; then
275                NUM_PROCS=1
276            fi
277            if [ "$NUM_FILES" -eq 0 ]; then
278                NUM_FILES=1
279            fi
280            if [ "$NUM_BYTES" -eq 0 ]; then
281                NUM_BYTES=$((1024 * 1024 * 1024))
282            fi
283            if [ "$CLEAN_FLAG" -ne 1 ]; then
284                CLEAN_FLAG=0
285            fi
286            if [ "$CLEAN_FLAG" -eq 1 ]; then
287                # Do not unlink file in this case
288                $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \
289                    $NUM_FILES --hdd-bytes $NUM_BYTES >/dev/null 2>&1 &
290            else
291                # Cleanup otherwise
292                $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \
293                    $NUM_FILES --hdd-bytes $NUM_BYTES --hdd-noclean >/dev/null 2>&1 &
294            fi
295            GENLOAD=1;;
296
297        e)  # Print out the version of LTP
298            version_of_ltp
299	    ;;
300        f)  # Execute user defined set of testcases.
301            # Can be more then one file, just separate it with ',', like:
302            # -f nfs,commands,/tmp/testfile
303            CMDFILES=$OPTARG;;
304	F)	INJECT_KERNEL_FAULT=1
305		#Seperate out the NO_OF_LOOPS & FAULT_PERCENTAGE
306		INJECT_FAULT_LOOPS_PER_TEST=`echo $OPTARG |cut -d',' -f1 | tr -d '\n' | tr -d ' '`
307		INJECT_KERNEL_FAULT_PERCENTAGE=`echo $OPTARG |cut -d',' -f2 | tr -d '\n' | tr -d ' '`
308		if [ ! $INJECT_FAULT_LOOPS_PER_TEST ]; then
309			echo "Loops not properly defined. Resorting to default 5..."
310			export INJECT_FAULT_LOOPS_PER_TEST=5
311		fi
312		if [ ! $INJECT_KERNEL_FAULT_PERCENTAGE ]; then
313			echo "Fault Persentage not properly defined. Resorting to default 10..."
314			export INJECT_KERNEL_FAULT_PERCENTAGE=10
315		fi;;
316        g)  HTMLFILE_NAME="$OPTARG"
317            case $OPTARG in
318            /*)
319                HTMLFILE="$OPTARG";;
320            *)
321                HTMLFILE="$LTPROOT/output/$OPTARG";;
322            esac
323            ALT_DIR_OUT=1
324            ALT_HTML_OUT=1;;
325        h)  usage;;
326
327        i)
328            NUM_PROCS=$(($OPTARG))
329            if   [ "$NUM_PROCS" -eq 0 ]; then
330                # User Did not Define the Value ,or, User Defined Zero,
331                # hence, prevent from creating infinite processes
332                NUM_PROCS=1
333            fi
334            $LTPROOT/testcases/bin/genload --io $NUM_PROCS >/dev/null 2>&1 &
335            GENLOAD=1 ;;
336
337        K)
338	    case $OPTARG in
339        	   /*)
340			DMESG_DIR="$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";;
341	            *)
342		        DMESG_DIR="$LTPROOT/output/$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";;
343	    esac
344            mkdir -p $DMESG_DIR
345            ALT_DMESG_OUT=1;;
346        l)
347            LOGFILE_NAME="$OPTARG"
348            case $OPTARG in
349            /*)
350                LOGFILE="-l $OPTARG" ;;
351            *)
352                LOGFILE="-l $LTPROOT/results/$OPTARG"
353                ALT_DIR_RES=1 ;;
354            esac ;;
355
356        m)  NUM_PROCS=1; CHUNKS=1; BYTES=$((256 * 1024 * 1024)); HANGUP_FLAG=0
357            ARGUMENT_LIST=$OPTARG
358            TOTAL_ARGUMENTS=1
359            for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '`
360            do
361                case $TOTAL_ARGUMENTS in
362                    1) NUM_PROCS="$ARGUMENT" ;;
363                    2) CHUNKS="$ARGUMENT" ;;
364                    3) BYTES="$ARGUMENT" ;;
365                    4) HANGUP_FLAG="$ARGUMENT" ;;
366                esac
367                TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1`
368            done
369            # just to get the default values if the user passed 0
370            if [ "$NUM_PROCS" -eq 0 ]; then
371                NUM_PROCS=1
372            fi
373            if [ "$CHUNKS" -eq 0 ]; then
374                CHUNKS=1
375            fi
376            if [ "$BYTES" -eq 0 ]; then
377                BYTES=$((256 * 1024 * 1024))
378            fi
379            if [ "$HANGUP_FLAG" -ne 1 ]; then
380                HANGUP_FLAG=0
381            fi
382            if [ "$HANGUP_FLAG" -eq 1 ]; then
383                # Hang in a Sleep loop after memory allocated
384                $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \
385                    $CHUNKS --vm-bytes $BYTES --vm-hang >/dev/null 2>&1 &
386            else
387                # Otherwise Do not Hangup
388                $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \
389                    $CHUNKS --vm-bytes $BYTES >/dev/null 2>&1 &
390            fi
391            GENLOAD=1;;
392	M)
393		VALGRIND_CHECK=1
394		VALGRIND_CHECK_TYPE="$OPTARG";;
395
396        N)  RUN_NETEST=1;;
397
398        o)  OUTPUTFILE_NAME="$OPTARG"
399            case $OPTARG in
400            /*)
401                OUTPUTFILE="-o $OPTARG";;
402            *)
403                OUTPUTFILE="-o $LTPROOT/output/$OPTARG"
404                ALT_DIR_OUT=1 ;;
405            esac ;;
406
407        p)  PRETTY_PRT="-p";;
408
409        q)  QUIET_MODE="-q";;
410
411        Q)  NO_KMSG="-Q";;
412
413        r)  LTPROOT=$OPTARG;;
414
415        R)  RANDOMRUN=1;;
416
417        s)  TAG_RESTRICT_STRING=$OPTARG;;
418
419	S)  case $OPTARG in
420            /*)
421                SKIPFILE=$OPTARG;;
422            *)
423                SKIPFILE="$LTPROOT/$OPTARG";;
424            esac ;;
425
426        t)  # In case you want to specify the time
427            # to run from the command line
428            # (2m = two minutes, 2h = two hours, etc)
429            DURATION="-t $OPTARG" ;;
430
431        I)  # In case you want the testcases to runsequentially RUN_REPEATED times
432            RUN_REPEATED=$OPTARG;;
433
434        w)  CMDFILEADDR=$OPTARG;;
435
436        x)  # number of ltp's to run
437            cat <<-EOF >&1
438            WARNING: The use of -x can cause unpredictable failures, as a
439                     result of concurrently running multiple tests designed
440                     to be ran exclusively.
441                     Pausing for 10 seconds..."
442	EOF
443            sleep 10
444            INSTANCES="-x $OPTARG";;
445        b) DEVICE=$OPTARG;;
446        B) LTP_DEV_FS_TYPE=$OPTARG;;
447        z) BIG_DEVICE=$OPTARG;;
448        Z) BIG_DEVICE_FS_TYPE=$OPTARG;;
449        \?) usage;;
450        esac
451    done
452
453    ## It would be nice to create a default log file even if the user has not mentioned
454    if [ ! "$LOGFILE" ]; then                                ## User has not mentioned about Log File name
455       LOGFILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME"
456       LOGFILE="-l $LTPROOT/results/LTP_RUN_ON-$LOGFILE_NAME.log"
457       ALT_DIR_RES=1
458       PRETTY_PRT="-p"
459    fi
460
461    ## It would be nice if a Failed File is compulsorily created (gives User better Idea of Tests that failed)
462
463    if [ ! "$FAILCMDFILE" ]; then                            ## User has not mentioned about Failed File name
464         ALT_DIR_OUT=1
465         if [ ! "$OUTPUTFILE" ]; then		             ## User has not mentioned about Output File name either
466            if [ ! "$LOGFILE" ]; then                        ## User has not mentioned about Log File name either
467               FAILED_FILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME"
468               FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
469            else					     ## User Fortunately wanted a log file,
470               FAILED_FILE_NAME=`basename $LOGFILE_NAME`     ## Extract log file name and use it to construct Failed file name
471               FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
472            fi
473         else                                                ## User Fortunately wanted a Output file
474               FAILED_FILE_NAME=`basename $OUTPUTFILE_NAME`  ## Extract output file name and use it to construct Failed file name
475               FAILCMDFILE="-C $LTPROOT/output/LTP_RUN_ON-$FAILED_FILE_NAME.failed"
476         fi
477    fi
478
479    if [ ! "$TCONFCMDFILE" ]; then
480         ALT_DIR_OUT=1
481         if [ ! "$OUTPUTFILE" ]; then
482            if [ ! "$LOGFILE" ]; then
483               TCONF_FILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME"
484               TCONFCMDFILE="-T $LTPROOT/output/LTP_RUN_ON-${TCONF_FILE_NAME}.tconf"
485            else
486               TCONF_FILE_NAME=`basename $LOGFILE_NAME`
487               TCONFCMDFILE="-T $LTPROOT/output/LTP_RUN_ON-${TCONF_FILE_NAME}.tconf"
488            fi
489         else
490               TCONF_FILE_NAME=`basename $OUTPUTFILE_NAME`
491               TCONFCMDFILE="-T $LTPROOT/output/LTP_RUN_ON-${TCONF_FILE_NAME}.tconf"
492         fi
493    fi
494
495    if [ "$ALT_HTML_OUT" -eq 1 ] ; then                      ## User wants the HTML version of the output
496       QUIET_MODE=""                                         ## Suppressing this guy as it will prevent generation of proper output
497                                                             ## which the HTML parser will require
498       if [ ! "$OUTPUTFILE" ]; then                          ## User has not mentioned about the Outputfile name, then we need to definitely generate one
499          OUTPUTFILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME"
500          OUTPUTFILE="-o $LTPROOT/output/LTP_RUN_ON-$OUTPUTFILE_NAME.output"
501          ALT_DIR_OUT=1
502          if [ ! "$HTMLFILE" ] ; then                        ## User has not mentioned HTML File name, We need to create one
503             HTMLFILE_NAME=`basename $OUTPUTFILE_NAME`
504             HTMLFILE="$LTPROOT/output/$HTMLFILE_NAME.html"
505          fi
506       fi
507    fi
508
509    # If we need, create the output directory
510    [ "$ALT_DIR_OUT" -eq 1 ] && \
511    {
512        [ ! -d $LTPROOT/output ] && \
513        {
514           echo "INFO: creating $LTPROOT/output directory"
515           mkdir -p $LTPROOT/output || \
516           {
517               echo "ERROR: failed to create $LTPROOT/output"
518               exit 1
519            }
520        }
521    }
522    # If we need, create the results directory
523    [ "$ALT_DIR_RES" -eq 1 ] && \
524    {
525        echo "INFO: creating $LTPROOT/results directory"
526        [ ! -d $LTPROOT/results ] && \
527        {
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    chmod 777 $TMP || \
556    {
557      echo "unable to chmod 777 $TMP ... aborting"
558      exit 1
559    }
560
561    cd $TMP || \
562    {
563      echo "could not cd ${TMP} ... exiting"
564      exit 1
565    }
566
567    [ -n "$INSTANCES" ] && \
568    {
569      INSTANCES="$INSTANCES -O ${TMP}"
570    }
571
572    # If user does not provide a command file select a default set of testcases
573    # to execute.
574    if [ -z "$CMDFILES" ] && [ -z "$CMDFILEADDR" ]; then
575
576        SCENARIO_LISTS="$LTPROOT/scenario_groups/default"
577        if [ "$RUN_NETEST" -eq 1 ]; then
578            SCENARIO_LISTS="$LTPROOT/scenario_groups/network"
579        fi
580
581        cat <<-EOF >&1
582INFO: no command files were provided. Executing following runtest scenario files:
583`cat $SCENARIO_LISTS | tr '\012' ' '`
584
585EOF
586        cat_ok_sentinel=$TMP/cat_ok.$$
587        touch "$cat_ok_sentinel"
588        cat $SCENARIO_LISTS | while read scenfile; do
589            scenfile=${LTPROOT}/runtest/$scenfile
590            [ -f "$scenfile" ] || continue
591
592            cat $scenfile >> "$TMP/alltests" || {
593                echo "FATAL: unable to append to command file"
594                rm -Rf "$TMP"
595                rm -f "$cat_ok_sentinel"
596                exit 1
597            }
598        done
599        rm -f "$cat_ok_sentinel"
600    fi
601
602    [ -n "$CMDFILES" ] && \
603    {
604        for scenfile in `echo "$CMDFILES" | tr ',' ' '`
605        do
606            [ -f "$scenfile" ] || scenfile="$LTPROOT/runtest/$scenfile"
607            cat "$scenfile" >> ${TMP}/alltests || \
608            {
609                echo "FATAL: unable to create command file"
610                rm -Rf "$TMP"
611                exit 1
612            }
613        done
614    }
615
616    [ -n "$CMDFILEADDR" ] && \
617    {
618        wget -q "${CMDFILEADDR}" -O ${TMP}/wgetcmdfile
619        if [ $? -ne 0 ]; then
620            echo "FATAL: error while getting the command file with wget (address $CMDFILEADDR)"
621            exit 1
622        fi
623        cat "${TMP}/wgetcmdfile" >> ${TMP}/alltests || \
624        {
625            echo "FATAL: unable to create command file"
626            exit 1
627        }
628    }
629
630    # The fsx-linux tests use the SCRATCHDEV environment variable as a location
631    # that can be reformatted and run on.  Set SCRATCHDEV if you want to run
632    # these tests.  As a safeguard, this is disabled.
633    unset SCRATCHDEV
634    [ -n "$SCRATCHDEV" ] && \
635    {
636         cat ${LTPROOT}/runtest/fsx >> ${TMP}/alltests ||
637         {
638             echo "FATAL: unable to create  fsx-linux tests command file"
639             exit 1
640         }
641    }
642
643    # If enabled, execute only test cases that match the PATTERN
644    if [ -n "$TAG_RESTRICT_STRING" ]
645    then
646        mv -f ${TMP}/alltests ${TMP}/alltests.orig
647	    grep $TAG_RESTRICT_STRING ${TMP}/alltests.orig > ${TMP}/alltests #Not worth checking return codes for this case
648    fi
649
650    # Blacklist or skip tests if a SKIPFILE was specified with -S
651    if [ -n "${SKIPFILE}" ]; then
652        for test_name in $(awk '{print $1}' "${SKIPFILE}"); do
653            case "${test_name}" in \#*) continue;; esac
654            sed -i "/\<${test_name}\>/c\\${test_name} exit 32;" alltests
655        done
656    fi
657
658    # check for required users and groups
659    ${LTPROOT}/IDcheck.sh || \
660    {
661        echo "WARNING: required users and groups not present"
662        echo "WARNING: some test cases may fail"
663    }
664
665    # display versions of installed software
666    [ -z "$QUIET_MODE" ] && \
667    {
668        ${LTPROOT}/ver_linux || \
669        {
670            echo "WARNING: unable to display versions of software installed"
671            exit 1
672    }
673    }
674
675    set_block_device
676
677    # here even if the user don't specify a big block device, we
678    # also don't create the big block device.
679    if [ -z "$BIG_DEVICE" ]; then
680        echo "no big block device was specified on commandline."
681        echo "Tests which require a big block device are disabled."
682        echo "You can specify it with option -z"
683    else
684        export LTP_BIG_DEV=$BIG_DEVICE
685        if [ -z "$BIG_DEVICE_FS_TYPE" ]; then
686            export LTP_BIG_DEV_FS_TYPE="ext2"
687        else
688            export LTP_BIG_DEV_FS_TYPE=$BIG_DEVICE_FS_TYPE
689        fi
690    fi
691
692    if [ $RUN_REPEATED -gt 1 ]; then # You need to specify at least more than 1 sequential run, else it runs default
693         echo "PAN will run these test cases $RUN_REPEATED times....."
694         echo "Test Tags will be Prepended with ITERATION NO.s....."
695         inc=1
696         sed -e '/^$/ d' -e 's/^[ ,\t]*//' -e '/^#/ d' < ${TMP}/alltests > ${TMP}/alltests.temp ##This removes all newlines, leading spaces, tabs, #
697         sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp > ${TMP}/alltests ## .temp is kept as Base file
698         while [ $inc -lt $RUN_REPEATED ] ; do
699               inc=`expr $inc + 1`
700               sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp >> ${TMP}/alltests #Keep appending with Iteration No.s
701         done
702    fi
703
704    if [ "$RANDOMRUN" != "0" ]; then
705        sort -R ${TMP}/alltests -o ${TMP}/alltests
706    fi
707
708    [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test start time: $(date)" ; }
709    PAN_COMMAND="${LTPROOT}/bin/ltp-pan $QUIET_MODE $NO_KMSG -e -S $INSTANCES $DURATION -a $$ \
710    -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE $TCONFCMDFILE"
711    echo "COMMAND:    $PAN_COMMAND"
712    if [ ! -z "$TAG_RESTRICT_STRING" ] ; then
713      echo "INFO: Restricted to $TAG_RESTRICT_STRING"
714    fi
715    #$PAN_COMMAND #Duplicated code here, because otherwise if we fail, only "PAN_COMMAND" gets output
716
717    ## Display the Output/Log/Failed/HTML file names here
718    printf "LOG File: "
719    echo $LOGFILE | cut -b4-
720
721    if [ "$OUTPUTFILE" ]; then
722       printf "OUTPUT File: "
723       echo $OUTPUTFILE | cut -b4-
724    fi
725
726    printf "FAILED COMMAND File: "
727    echo $FAILCMDFILE | cut -b4-
728
729   printf "TCONF COMMAND File: "
730   echo $TCONFCMDFILE | cut -b4-
731
732    if [ "$HTMLFILE" ]; then
733       echo "HTML File: $HTMLFILE"
734    fi
735
736    echo "Running tests......."
737    test_start_time=$(date)
738
739	# User wants testing with Kernel Fault Injection
740	if [ $INJECT_KERNEL_FAULT ] ; then
741		#See if Debugfs is mounted, and
742		#Fault Injection Framework available through Debugfs
743		use_faultinjection=true
744		for debug_subdir in \
745			fail_io_timeout \
746			fail_make_request \
747			fail_page_alloc \
748			failslab \
749		; do
750			if [ -d "/sys/kernel/debug/$debug_subdir" ]
751			then
752				use_faultinjection=true
753				break
754			fi
755		done
756		if $use_faultinjection; then
757			#If atleast one of the Framework is available
758			#Go ahead to Inject Fault & Create required
759			#Command Files for LTP run
760			echo Running tests with Fault Injection Enabled in the Kernel...
761			awk -v LOOPS=$INJECT_FAULT_LOOPS_PER_TEST \
762				-v PERCENTAGE=$INJECT_KERNEL_FAULT_PERCENTAGE \
763				-f ${LTPROOT}/bin/create_kernel_faults_in_loops_and_probability.awk \
764				${TMP}/alltests > ${TMP}/alltests.tmp
765			cp ${TMP}/alltests.tmp ${TMP}/alltests
766			rm -rf ${TMP}/alltests.tmp
767		else
768			echo Fault Injection not enabled in the Kernel..
769			echo Running tests normally...
770		fi
771	fi
772
773	## Valgrind Check will work only when Kernel Fault Injection is not expected,
774	## We do not want to test Faults when valgrind is running
775	if [ $VALGRIND_CHECK ]; then
776		if [ ! $INJECT_KERNEL_FAULT ]; then
777			which valgrind || VALGRIND_CHECK_TYPE=XYZ
778			case $VALGRIND_CHECK_TYPE in
779			[1-3])
780				awk -v CHECK_LEVEL=$VALGRIND_CHECK_TYPE \
781					-f ${LTPROOT}/bin/create_valgrind_check.awk \
782					${TMP}/alltests $VALGRIND_CHECK_TYPE > \
783					${TMP}/alltests.tmp
784				cp ${TMP}/alltests.tmp ${TMP}/alltests
785				rm -rf ${TMP}/alltests.tmp
786				;;
787			*)
788				echo "Invalid Memory Check Type, or, Valgrind is not available"
789				;;
790			esac
791		fi
792	fi
793
794	if [ $ALT_DMESG_OUT -eq 1 ] ; then
795		#We want to print dmesg output for each test,lets do the trick inside the script
796		echo Enabling dmesg output logging for each test...
797		awk -v DMESG_DIR=$DMESG_DIR \
798			-f ${LTPROOT}/bin/create_dmesg_entries_for_each_test.awk \
799			${TMP}/alltests > ${TMP}/alltests.tmp
800		cp ${TMP}/alltests.tmp ${TMP}/alltests
801		rm -rf ${TMP}/alltests.tmp
802	fi
803    # Some tests need to run inside the "bin" directory.
804    cd "${LTPROOT}/testcases/bin"
805    "${LTPROOT}/bin/ltp-pan" $QUIET_MODE $NO_KMSG -e -S $INSTANCES $DURATION -a $$ -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE $TCONFCMDFILE
806
807    if [ $? -eq 0 ]; then
808      echo "INFO: ltp-pan reported all tests PASS"
809      VALUE=0
810      export LTP_EXIT_VALUE=0;
811    else
812      echo "INFO: ltp-pan reported some tests FAIL"
813      VALUE=1
814      export LTP_EXIT_VALUE=1;
815    fi
816    cd ..
817    echo "LTP Version: $version_date"
818
819	# $DMESG_DIR is used to cache messages obtained from dmesg after a test run.
820	# Proactively reap all of the 0-byte files in $DMESG_DIR as they have zero value
821	# and only clutter up the filesystem.
822
823	if [ $ALT_DMESG_OUT -eq 1 ] ; then
824		if ! find "$DMESG_DIR" -size 0 -exec rm {} + ; then
825			echo "cd to $DMESG_DIR failed: $?"
826		fi
827		if [ -n "$(ls "$DMESG_DIR")" ] ; then
828			echo "Kernel messages were generated for LTP tests $version_date"
829		else
830			echo "No Kernel messages were generated for LTP tests $version_date"
831		fi
832	fi
833
834    if [ "$ALT_HTML_OUT" -eq 1 ] ; then        #User wants the HTML output to be created, it then needs to be generated
835       export LTP_VERSION=$version_date
836       export TEST_START_TIME="$test_start_time"
837       export TEST_END_TIME="$(date)"
838       OUTPUT_DIRECTORY=`echo $OUTPUTFILE | cut -c4-`
839       LOGS_DIRECTORY="$LTPROOT/results"
840       export TEST_OUTPUT_DIRECTORY="$LTPROOT/output"
841       export TEST_LOGS_DIRECTORY=$LOGS_DIRECTORY
842       echo "Generating HTML Output.....!!"
843       ( perl $LTPROOT/bin/genhtml.pl $LTPROOT/bin/html_report_header.txt test_start test_end test_output execution_status $OUTPUT_DIRECTORY  > $HTMLFILE; )
844       echo "Generated HTML Output.....!!"
845       echo "Location: $HTMLFILE";
846
847    fi
848
849    if [ "$ALT_EMAIL_OUT" -eq 1 ] ; then                    ## User wants reports to be e-mailed
850        TAR_FILE_NAME=LTP_RUN_$version_date$DEFAULT_FILE_NAME_GENERATION_TIME.tar
851        if [ "$HTMLFILE_NAME" ] ; then                      ## HTML file Exists
852            if [ "$ALT_HTML_OUT" -ne 1 ] ; then             ## The HTML file path is absolute and not $LTPROOT/output
853                mkdir -p $LTPROOT/output                    ## We need to create this Directory
854                cp $HTMLFILE_NAME $LTPROOT/output/
855            fi
856        fi
857        if [ "$OUTPUTFILE_NAME" ] ; then                    ## Output file exists
858            if [ "$ALT_DIR_OUT" -ne 1 ] ; then              ## The Output file path is absolute and not $LTPROOT/output
859                mkdir -p $LTPROOT/output                    ## We need to create this Directory
860                cp $OUTPUTFILE_NAME $LTPROOT/output/
861            fi
862        fi
863        if [ "$LOGFILE_NAME" ] ; then                       ## Log file exists
864            if [ "$ALT_DIR_RES" -ne 1 ] ; then              ## The Log file path is absolute and not $LTPROOT/results
865                mkdir -p $LTPROOT/results                   ## We need to create this Directory
866                cp $LOGFILE_NAME $LTPROOT/results/
867            fi
868        fi
869        if [ -d $LTPROOT/output ] ; then
870            tar -cf  ./$TAR_FILE_NAME $LTPROOT/output
871            if [ $? -eq 0 ]; then
872                echo "Created TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/output"
873            else
874                echo "Cannot Create TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/output"
875            fi
876        fi
877        if [ -d $LTPROOT/results ] ; then
878            tar -uf ./$TAR_FILE_NAME $LTPROOT/results
879            if [ $? -eq 0 ]; then
880                echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/results"
881            else
882                echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/results"
883            fi
884        fi
885        if [ -e $LTPROOT/nohup.out ] ; then                 ## If User would have Chosen nohup to do ltprun
886            tar -uf ./$TAR_FILE_NAME $LTPROOT/nohup.out
887            if [ $? -eq 0 ]; then
888                echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/nohup.out"
889            else
890                echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/nohup.out"
891            fi
892        fi
893        gzip ./$TAR_FILE_NAME                               ## gzip this guy
894        if [ $? -eq 0 ]; then
895            echo "Gunzipped TAR File: ./$TAR_FILE_NAME"
896        else
897            echo "Cannot Gunzip TAR File: ./$TAR_FILE_NAME"
898        fi
899        if which mutt >/dev/null 2>&1; then
900            echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz"
901            mutt -a ./$TAR_FILE_NAME.gz -s "LTP Reports on $test_start_time" -- $EMAIL_TO < /dev/null
902            if [ $? -eq 0 ]; then
903                echo "Reports Successfully mailed to: $EMAIL_TO"
904            else
905                echo "Reports cannot be mailed to: $EMAIL_TO"
906            fi
907        else ## Use our Ageold mail program
908            echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz"
909            uuencode ./$TAR_FILE_NAME.gz $TAR_FILE_NAME.gz | mail  $EMAIL_TO -s "LTP Reports on $test_start_time"
910            if [ $? -eq 0 ]; then
911                echo "Reports Successfully mailed to: $EMAIL_TO"
912            else
913                echo "Reports cannot be mailed to: $EMAIL_TO"
914            fi
915        fi
916    fi
917
918    [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test end time: $(date)" ; }
919
920    [ "$GENLOAD" -eq 1 ] && { killall -9 genload  >/dev/null 2>&1; }
921    [ "$NETPIPE" -eq 1 ] && { killall -9 NPtcp  >/dev/null 2>&1; }
922
923    [ "$ALT_DIR_OUT" -eq 1 ] || [ "$ALT_DIR_RES" -eq 1 ] && \
924    {
925    cat <<-EOF >&1
926
927       ###############################################################
928
929            Done executing testcases.
930            LTP Version:  $version_date
931       ###############################################################
932
933	EOF
934    }
935    exit $VALUE
936}
937
938create_block()
939{
940    #create a block device
941    dd if=/dev/zero of=${TMP}/test.img bs=1024 count=262144 >/dev/null 2>&1
942    if [ $? -ne 0 ]; then
943        echo "Failed to create loopback device image, please check disk space and re-run"
944        return 1
945    else
946        ##search for an unused loop dev
947        LOOP_DEV=$(losetup -f)
948        if [ $? -ne 0 ]; then
949            echo "no unused loop device is found"
950            return 1
951        else
952            ##attach the created file to loop dev.
953            losetup $LOOP_DEV ${TMP}/test.img
954            if [ $? -ne 0 ]; then
955                echo "losetup failed to create block device"
956                return 1
957            fi
958            DEVICE=$LOOP_DEV
959            return 0
960        fi
961    fi
962}
963
964set_block_device()
965{
966    if [ -z "$DEVICE" ]; then
967        create_block
968        if [ $? -ne 0 ]; then
969            echo "no block device was specified on commandline."
970            echo "Block device could not be created using loopback device"
971            echo "Tests which require block device are disabled."
972            echo "You can specify it with option -b"
973	else
974            export LTP_DEV=$DEVICE
975        fi
976    else
977        export LTP_DEV=$DEVICE
978    fi
979}
980
981cleanup()
982{
983    [ "$LOOP_DEV" ] && losetup -d $LOOP_DEV
984    rm -rf ${TMP}
985}
986
987
988LTP_SCRIPT="$(basename $0)"
989
990if [ "$LTP_SCRIPT" = "runltp" ]; then
991    trap "cleanup" 0
992    setup
993    main "$@"
994fi
995