• 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"
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 [ -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    -n              Run LTP with network traffic in background.
152    -o OUTPUTFILE   Redirect test output to a file.
153    -p              Human readable format logfiles.
154    -q              Print less verbose output to screen.
155    -r LTPROOT      Fully qualified path where testsuite is installed.
156    -R              Randomize test order.
157    -s PATTERN      Only run test cases which match PATTERN.
158    -S SKIPFILE     Skip tests specified in SKIPFILE
159    -t DURATION     Execute the testsuite for given duration. Examples:
160                      -t 60s = 60 seconds
161                      -t 45m = 45 minutes
162                      -t 24h = 24 hours
163                      -t 2d  = 2 days
164    -I ITERATIONS   Execute the testsuite ITERATIONS times.
165    -w CMDFILEADDR  Uses wget to get the user's list of testcases.
166    -x INSTANCES    Run multiple instances of this testsuite.
167    -b DEVICE       Some tests require an unmounted block device
168                    to run correctly.
169    -B LTP_DEV_FS_TYPE The file system of test block devices.
170    -z BIG_DEVICE   Some tests require a big unmounted block device
171                    to run correctly.
172    -Z  LTP_BIG_DEV_FS_TYPE The file system of the big device
173
174
175
176    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}
177
178
179	EOF
180exit 0
181}
182
183main()
184{
185    local CMDFILES=""
186    local PRETTY_PRT=""
187    local ALT_DIR_OUT=0
188    local ALT_DIR_RES=0
189    local ALT_HTML_OUT=0
190    local ALT_EMAIL_OUT=0
191    local ALT_DMESG_OUT=0
192    local RUN_NETEST=0
193    local RUN_REPEATED=0
194    local QUIET_MODE=""
195    local NETPIPE=0
196    local GENLOAD=0
197    local MEMSIZE=0
198    local DURATION=""
199    local CMDFILEADDR=""
200    local FAILCMDFILE=""
201    local TCONFCMDFILE=""
202    local INJECT_KERNEL_FAULT=""
203    local INJECT_KERNEL_FAULT_PERCENTAGE=""
204    local INJECT_FAULT_LOOPS_PER_TEST=""
205    local VALGRIND_CHECK=""
206    local VALGRIND_CHECK_TYPE=""
207    local LOGFILE_NAME=""
208    local LOGFILE=""
209    local OUTPUTFILE_NAME=""
210    local OUTPUTFILE=""
211    local HTMLFILE_NAME=""
212    local HTMLFILE=""
213    local DMESG_DIR=""
214    local EMAIL_TO=""
215    local TAG_RESTRICT_STRING=""
216    local PAN_COMMAND=""
217    local RANDOMRUN=0
218    local DEFAULT_FILE_NAME_GENERATION_TIME=`date +"%Y_%m_%d-%Hh_%Mm_%Ss"`
219    local scenfile=
220
221    version_date=$(cat "$LTPROOT/Version")
222
223    while getopts a:c:C:T:d:D:f:F:ehi:I:K:g:l:m:M:Nno:pqr:Rs:S:t:T:w:x:b:B:z:Z: arg
224    do  case $arg in
225        a)  EMAIL_TO=$OPTARG
226            ALT_EMAIL_OUT=1;;
227        c)
228            NUM_PROCS=$(($OPTARG))
229            if   [ "$NUM_PROCS" -eq 0 ]; then
230                # User Did not Define the Value ,or, User Defined Zero,
231                # hence, prevent from creating infinite processes
232                NUM_PROCS=1
233            fi
234            $LTPROOT/testcases/bin/genload --cpu $NUM_PROCS >/dev/null 2>&1 &
235            GENLOAD=1 ;;
236
237        C)
238            case $OPTARG in
239            /*)
240                FAILCMDFILE="-C $OPTARG" ;;
241            *)
242                FAILCMDFILE="-C $LTPROOT/output/$OPTARG"
243                ALT_DIR_OUT=1 ;;
244            esac ;;
245
246        T)
247            case $OPTARG in
248            /*)
249                TCONFCMDFILE="-T $OPTARG" ;;
250            *)
251                TCONFCMDFILE="-T $LTPROOT/output/$OPTARG"
252                ALT_DIR_OUT=1 ;;
253            esac ;;
254
255        d)  # convert the user path to absolute path.
256            export TMPBASE=$(readlink -f ${OPTARG}) ;;
257
258        D)  NUM_PROCS=1; NUM_FILES=1; NUM_BYTES=$((1024 * 1024 * 1024)); CLEAN_FLAG=0
259            ARGUMENT_LIST=$OPTARG
260            TOTAL_ARGUMENTS=1
261            for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '`
262            do
263                case $TOTAL_ARGUMENTS in
264                    1) NUM_PROCS="$ARGUMENT" ;;
265                    2) NUM_FILES="$ARGUMENT" ;;
266                    3) NUM_BYTES="$ARGUMENT" ;;
267                    4) CLEAN_FLAG="$ARGUMENT" ;;
268                esac
269                TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1`
270            done
271            # just to get the default values if the user passed 0
272            if [ "$NUM_PROCS" -eq 0 ]; then
273                NUM_PROCS=1
274            fi
275            if [ "$NUM_FILES" -eq 0 ]; then
276                NUM_FILES=1
277            fi
278            if [ "$NUM_BYTES" -eq 0 ]; then
279                NUM_BYTES=$((1024 * 1024 * 1024))
280            fi
281            if [ "$CLEAN_FLAG" -ne 1 ]; then
282                CLEAN_FLAG=0
283            fi
284            if [ "$CLEAN_FLAG" -eq 1 ]; then
285                # Do not unlink file in this case
286                $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \
287                    $NUM_FILES --hdd-bytes $NUM_BYTES >/dev/null 2>&1 &
288            else
289                # Cleanup otherwise
290                $LTPROOT/testcases/bin/genload --hdd $NUM_PROCS --hdd-files \
291                    $NUM_FILES --hdd-bytes $NUM_BYTES --hdd-noclean >/dev/null 2>&1 &
292            fi
293            GENLOAD=1;;
294
295        e)  # Print out the version of LTP
296            version_of_ltp
297	    ;;
298        f)  # Execute user defined set of testcases.
299            # Can be more then one file, just separate it with ',', like:
300            # -f nfs,commands,/tmp/testfile
301            CMDFILES=$OPTARG;;
302	F)	INJECT_KERNEL_FAULT=1
303		#Seperate out the NO_OF_LOOPS & FAULT_PERCENTAGE
304		INJECT_FAULT_LOOPS_PER_TEST=`echo $OPTARG |cut -d',' -f1 | tr -d '\n' | tr -d ' '`
305		INJECT_KERNEL_FAULT_PERCENTAGE=`echo $OPTARG |cut -d',' -f2 | tr -d '\n' | tr -d ' '`
306		if [ ! $INJECT_FAULT_LOOPS_PER_TEST ]; then
307			echo "Loops not properly defined. Resorting to default 5..."
308			export INJECT_FAULT_LOOPS_PER_TEST=5
309		fi
310		if [ ! $INJECT_KERNEL_FAULT_PERCENTAGE ]; then
311			echo "Fault Persentage not properly defined. Resorting to default 10..."
312			export INJECT_KERNEL_FAULT_PERCENTAGE=10
313		fi;;
314        g)  HTMLFILE_NAME="$OPTARG"
315            case $OPTARG in
316            /*)
317                HTMLFILE="$OPTARG";;
318            *)
319                HTMLFILE="$LTPROOT/output/$OPTARG";;
320            esac
321            ALT_DIR_OUT=1
322            ALT_HTML_OUT=1;;
323        h)  usage;;
324
325        i)
326            NUM_PROCS=$(($OPTARG))
327            if   [ "$NUM_PROCS" -eq 0 ]; then
328                # User Did not Define the Value ,or, User Defined Zero,
329                # hence, prevent from creating infinite processes
330                NUM_PROCS=1
331            fi
332            $LTPROOT/testcases/bin/genload --io $NUM_PROCS >/dev/null 2>&1 &
333            GENLOAD=1 ;;
334
335        K)
336	    case $OPTARG in
337        	   /*)
338			DMESG_DIR="$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";;
339	            *)
340		        DMESG_DIR="$LTPROOT/output/$OPTARG-dmesg-output-`echo $$-``date +%X | tr -d ' '`";;
341	    esac
342            mkdir -p $DMESG_DIR
343            ALT_DMESG_OUT=1;;
344        l)
345            LOGFILE_NAME="$OPTARG"
346            case $OPTARG in
347            /*)
348                LOGFILE="-l $OPTARG" ;;
349            *)
350                LOGFILE="-l $LTPROOT/results/$OPTARG"
351                ALT_DIR_RES=1 ;;
352            esac ;;
353
354        m)  NUM_PROCS=1; CHUNKS=1; BYTES=$((256 * 1024 * 1024)); HANGUP_FLAG=0
355            ARGUMENT_LIST=$OPTARG
356            TOTAL_ARGUMENTS=1
357            for ARGUMENT in `echo "$ARGUMENT_LIST" | tr ',' ' '`
358            do
359                case $TOTAL_ARGUMENTS in
360                    1) NUM_PROCS="$ARGUMENT" ;;
361                    2) CHUNKS="$ARGUMENT" ;;
362                    3) BYTES="$ARGUMENT" ;;
363                    4) HANGUP_FLAG="$ARGUMENT" ;;
364                esac
365                TOTAL_ARGUMENTS=`expr $TOTAL_ARGUMENTS + 1`
366            done
367            # just to get the default values if the user passed 0
368            if [ "$NUM_PROCS" -eq 0 ]; then
369                NUM_PROCS=1
370            fi
371            if [ "$CHUNKS" -eq 0 ]; then
372                CHUNKS=1
373            fi
374            if [ "$BYTES" -eq 0 ]; then
375                BYTES=$((256 * 1024 * 1024))
376            fi
377            if [ "$HANGUP_FLAG" -ne 1 ]; then
378                HANGUP_FLAG=0
379            fi
380            if [ "$HANGUP_FLAG" -eq 1 ]; then
381                # Hang in a Sleep loop after memory allocated
382                $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \
383                    $CHUNKS --vm-bytes $BYTES --vm-hang >/dev/null 2>&1 &
384            else
385                # Otherwise Do not Hangup
386                $LTPROOT/testcases/bin/genload --vm $NUM_PROCS --vm-chunks \
387                    $CHUNKS --vm-bytes $BYTES >/dev/null 2>&1 &
388            fi
389            GENLOAD=1;;
390	M)
391		VALGRIND_CHECK=1
392		VALGRIND_CHECK_TYPE="$OPTARG";;
393
394        N)  RUN_NETEST=1;;
395
396        n)
397            $LTPROOT/testcases/bin/netpipe.sh
398            NETPIPE=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        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    [ "$RUN_NETEST" -eq 1 ] && \
573    {
574        [ -z "$RHOST" ] || [ -z "$PASSWD" ] && \
575        {
576            [ -z "$RHOST" ] && \
577            {
578                printf "INFO: Enter RHOST = 'name of the remote host machine'"
579                printf "\n-> "
580                read RHOST
581            }
582
583            [ -z "$PASSWD" ] && \
584            {
585                printf "\nINFO: "
586                printf "Enter PASSWD = 'root passwd of the remote host machine'"
587                printf "\n-> "
588                read PASSWD
589            }
590            export RHOST=$RHOST
591            export PASSWD=$PASSWD
592            echo "WARNING: security of $RHOST may be compromised"
593        }
594    }
595
596    # If user does not provide a command file select a default set of testcases
597    # to execute.
598    if [ -z "$CMDFILES" ] && [ -z "$CMDFILEADDR" ]
599    then
600        cat <<-EOF >&1
601
602    INFO: no command files were provided. Will execute the following
603          runtest scenario files:
604
605`cat $LTPROOT/scenario_groups/default | tr '\012' ' '`
606
607	EOF
608
609	SCENARIO_LISTS="$LTPROOT/scenario_groups/default"
610        if [ "$RUN_NETEST" -eq 1 ]; then
611            SCENARIO_LISTS="$SCENARIO_LISTS $LTPROOT/scenario_groups/network"
612        fi
613
614    # DO NOT INDENT/DEDENT!
615        if [ -n "$SCENARIO_LISTS" ]; then
616            # Insurance to make sure that the first element in the pipe
617            # completed successfully.
618            cat_ok_sentinel=$TMP/cat_ok.$$
619	    (cat $SCENARIO_LISTS && touch "$cat_ok_sentinel") | \
620                while read scenfile; do
621
622                    scenfile=${LTPROOT}/runtest/$scenfile
623
624                    # Skip over non-existent scenario files; things are
625                    # robust enough now that the build will fail if these
626                    # files don't exist.
627                    [ -f "$scenfile" ] || continue
628
629                    cat $scenfile >> "$TMP/alltests" || {
630                        echo "FATAL: unable to append to command file"
631                        rm -Rf "$TMP"
632                        rm -f "$cat_ok_sentinel"
633                        exit 1
634                    }
635
636                done
637
638            rm -f "$cat_ok_sentinel"
639
640        fi
641    # ^^DO NOT INDENT/DEDENT!^^
642
643    fi
644
645    [ -n "$CMDFILES" ] && \
646    {
647        for scenfile in `echo "$CMDFILES" | tr ',' ' '`
648        do
649            [ -f "$scenfile" ] || scenfile="$LTPROOT/runtest/$scenfile"
650            cat "$scenfile" >> ${TMP}/alltests || \
651            {
652                echo "FATAL: unable to create command file"
653                rm -Rf "$TMP"
654                exit 1
655            }
656        done
657    }
658
659    [ -n "$CMDFILEADDR" ] && \
660    {
661        wget -q "${CMDFILEADDR}" -O ${TMP}/wgetcmdfile
662        if [ $? -ne 0 ]; then
663            echo "FATAL: error while getting the command file with wget (address $CMDFILEADDR)"
664            exit 1
665        fi
666        cat "${TMP}/wgetcmdfile" >> ${TMP}/alltests || \
667        {
668            echo "FATAL: unable to create command file"
669            exit 1
670        }
671    }
672
673    # The fsx-linux tests use the SCRATCHDEV environment variable as a location
674    # that can be reformatted and run on.  Set SCRATCHDEV if you want to run
675    # these tests.  As a safeguard, this is disabled.
676    unset SCRATCHDEV
677    [ -n "$SCRATCHDEV" ] && \
678    {
679         cat ${LTPROOT}/runtest/fsx >> ${TMP}/alltests ||
680         {
681             echo "FATAL: unable to create  fsx-linux tests command file"
682             exit 1
683         }
684    }
685
686    # If enabled, execute only test cases that match the PATTERN
687    if [ -n "$TAG_RESTRICT_STRING" ]
688    then
689        mv -f ${TMP}/alltests ${TMP}/alltests.orig
690	    grep $TAG_RESTRICT_STRING ${TMP}/alltests.orig > ${TMP}/alltests #Not worth checking return codes for this case
691    fi
692
693    # Blacklist or skip tests if a SKIPFILE was specified with -S
694    if [ -n "$SKIPFILE" ]
695    then
696        for file in $( cat $SKIPFILE ); do
697            sed -i "/^$file[ \t]/d" ${TMP}/alltests
698        done
699    fi
700
701    # check for required users and groups
702    ${LTPROOT}/IDcheck.sh || \
703    {
704        echo "WARNING: required users and groups not present"
705        echo "WARNING: some test cases may fail"
706    }
707
708    # display versions of installed software
709    [ -z "$QUIET_MODE" ] && \
710    {
711        ${LTPROOT}/ver_linux || \
712        {
713            echo "WARNING: unable to display versions of software installed"
714            exit 1
715    }
716    }
717
718    set_block_device
719
720    # here even if the user don't specify a big block device, we
721    # also don't create the big block device.
722    if [ -z "$BIG_DEVICE" ]; then
723        echo "no big block device was specified on commandline."
724        echo "Tests which require a big block device are disabled."
725        echo "You can specify it with option -z"
726    else
727        export LTP_BIG_DEV=$BIG_DEVICE
728        if [ -z "$BIG_DEVICE_FS_TYPE" ]; then
729            export LTP_BIG_DEV_FS_TYPE="ext2"
730        else
731            export LTP_BIG_DEV_FS_TYPE=$BIG_DEVICE_FS_TYPE
732        fi
733    fi
734
735    if [ $RUN_REPEATED -gt 1 ]; then # You need to specify at least more than 1 sequential run, else it runs default
736         echo "PAN will run these test cases $RUN_REPEATED times....."
737         echo "Test Tags will be Prepended with ITERATION NO.s....."
738         inc=1
739         sed -e '/^$/ d' -e 's/^[ ,\t]*//' -e '/^#/ d' < ${TMP}/alltests > ${TMP}/alltests.temp ##This removes all newlines, leading spaces, tabs, #
740         sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp > ${TMP}/alltests ## .temp is kept as Base file
741         while [ $inc -lt $RUN_REPEATED ] ; do
742               inc=`expr $inc + 1`
743               sed 's/^[0-9,a-z,A-Z]*/'"$inc"'_ITERATION_&/' < ${TMP}/alltests.temp >> ${TMP}/alltests #Keep appending with Iteration No.s
744         done
745    fi
746
747    if [ "$RANDOMRUN" != "0" ]; then
748        sort -R ${TMP}/alltests -o ${TMP}/alltests
749    fi
750
751    [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test start time: $(date)" ; }
752    PAN_COMMAND="${LTPROOT}/bin/ltp-pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \
753    -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE $TCONFCMDFILE"
754    echo "COMMAND:    $PAN_COMMAND"
755    if [ ! -z "$TAG_RESTRICT_STRING" ] ; then
756      echo "INFO: Restricted to $TAG_RESTRICT_STRING"
757    fi
758    #$PAN_COMMAND #Duplicated code here, because otherwise if we fail, only "PAN_COMMAND" gets output
759
760    ## Display the Output/Log/Failed/HTML file names here
761    printf "LOG File: "
762    echo $LOGFILE | cut -b4-
763
764    if [ "$OUTPUTFILE" ]; then
765       printf "OUTPUT File: "
766       echo $OUTPUTFILE | cut -b4-
767    fi
768
769    printf "FAILED COMMAND File: "
770    echo $FAILCMDFILE | cut -b4-
771
772   printf "TCONF COMMAND File: "
773   echo $TCONFCMDFILE | cut -b4-
774
775    if [ "$HTMLFILE" ]; then
776       echo "HTML File: $HTMLFILE"
777    fi
778
779    echo "Running tests......."
780    test_start_time=$(date)
781
782	# User wants testing with Kernel Fault Injection
783	if [ $INJECT_KERNEL_FAULT ] ; then
784		#See if Debugfs is mounted, and
785		#Fault Injection Framework available through Debugfs
786		use_faultinjection=true
787		for debug_subdir in \
788			fail_io_timeout \
789			fail_make_request \
790			fail_page_alloc \
791			failslab \
792		; do
793			if [ -d "/sys/kernel/debug/$debug_subdir" ]
794			then
795				use_faultinjection=true
796				break
797			fi
798		done
799		if $use_faultinjection; then
800			#If atleast one of the Framework is available
801			#Go ahead to Inject Fault & Create required
802			#Command Files for LTP run
803			echo Running tests with Fault Injection Enabled in the Kernel...
804			awk -v LOOPS=$INJECT_FAULT_LOOPS_PER_TEST \
805				-v PERCENTAGE=$INJECT_KERNEL_FAULT_PERCENTAGE \
806				-f ${LTPROOT}/bin/create_kernel_faults_in_loops_and_probability.awk \
807				${TMP}/alltests > ${TMP}/alltests.tmp
808			cp ${TMP}/alltests.tmp ${TMP}/alltests
809			rm -rf ${TMP}/alltests.tmp
810		else
811			echo Fault Injection not enabled in the Kernel..
812			echo Running tests normally...
813		fi
814	fi
815
816	## Valgrind Check will work only when Kernel Fault Injection is not expected,
817	## We do not want to test Faults when valgrind is running
818	if [ $VALGRIND_CHECK ]; then
819		if [ ! $INJECT_KERNEL_FAULT ]; then
820			which valgrind || VALGRIND_CHECK_TYPE=XYZ
821			case $VALGRIND_CHECK_TYPE in
822			[1-3])
823				awk -v CHECK_LEVEL=$VALGRIND_CHECK_TYPE \
824					-f ${LTPROOT}/bin/create_valgrind_check.awk \
825					${TMP}/alltests $VALGRIND_CHECK_TYPE > \
826					${TMP}/alltests.tmp
827				cp ${TMP}/alltests.tmp ${TMP}/alltests
828				rm -rf ${TMP}/alltests.tmp
829				;;
830			*)
831				echo "Invalid Memory Check Type, or, Valgrind is not available"
832				;;
833			esac
834		fi
835	fi
836
837	if [ $ALT_DMESG_OUT -eq 1 ] ; then
838		#We want to print dmesg output for each test,lets do the trick inside the script
839		echo Enabling dmesg output logging for each test...
840		awk -v DMESG_DIR=$DMESG_DIR \
841			-f ${LTPROOT}/bin/create_dmesg_entries_for_each_test.awk \
842			${TMP}/alltests > ${TMP}/alltests.tmp
843		cp ${TMP}/alltests.tmp ${TMP}/alltests
844		rm -rf ${TMP}/alltests.tmp
845	fi
846    # Some tests need to run inside the "bin" directory.
847    cd "${LTPROOT}/testcases/bin"
848    "${LTPROOT}/bin/ltp-pan" $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE $FAILCMDFILE $TCONFCMDFILE
849
850    if [ $? -eq 0 ]; then
851      echo "INFO: ltp-pan reported all tests PASS"
852      VALUE=0
853      export LTP_EXIT_VALUE=0;
854    else
855      echo "INFO: ltp-pan reported some tests FAIL"
856      VALUE=1
857      export LTP_EXIT_VALUE=1;
858    fi
859    cd ..
860    echo "LTP Version: $version_date"
861
862	# $DMESG_DIR is used to cache messages obtained from dmesg after a test run.
863	# Proactively reap all of the 0-byte files in $DMESG_DIR as they have zero value
864	# and only clutter up the filesystem.
865
866	if [ $ALT_DMESG_OUT -eq 1 ] ; then
867		if ! find "$DMESG_DIR" -size 0 -exec rm {} + ; then
868			echo "cd to $DMESG_DIR failed: $?"
869		fi
870		if [ -n "$(ls "$DMESG_DIR")" ] ; then
871			echo "Kernel messages were generated for LTP tests $version_date"
872		else
873			echo "No Kernel messages were generated for LTP tests $version_date"
874		fi
875	fi
876
877    if [ "$ALT_HTML_OUT" -eq 1 ] ; then        #User wants the HTML output to be created, it then needs to be generated
878       export LTP_VERSION=$version_date
879       export TEST_START_TIME="$test_start_time"
880       export TEST_END_TIME="$(date)"
881       OUTPUT_DIRECTORY=`echo $OUTPUTFILE | cut -c4-`
882       LOGS_DIRECTORY="$LTPROOT/results"
883       export TEST_OUTPUT_DIRECTORY="$LTPROOT/output"
884       export TEST_LOGS_DIRECTORY=$LOGS_DIRECTORY
885       echo "Generating HTML Output.....!!"
886       ( perl $LTPROOT/bin/genhtml.pl $LTPROOT/bin/html_report_header.txt test_start test_end test_output execution_status $OUTPUT_DIRECTORY  > $HTMLFILE; )
887       echo "Generated HTML Output.....!!"
888       echo "Location: $HTMLFILE";
889
890    fi
891
892    if [ "$ALT_EMAIL_OUT" -eq 1 ] ; then                      ## User wants reports to be e-mailed
893       if [ [ ! "$HTMLFILE_NAME" ] -o [ ! "$OUTPUTFILE_NAME" ] -o [ ! "$LOGFILE_NAME" ] ] ; then
894          ##User does not have output/logs/html-output, nothing to be mailed in this situation
895          echo "Nothing to be mailed here...."
896       else
897           TAR_FILE_NAME=LTP_RUN_$version_date$DEFAULT_FILE_NAME_GENERATION_TIME.tar
898           if [ "$HTMLFILE_NAME" ] ; then                          ## HTML file Exists
899              if [ "$ALT_HTML_OUT" -ne 1 ] ; then                  ## The HTML file path is absolute and not $LTPROOT/output
900                 mkdir -p $LTPROOT/output                          ## We need to create this Directory
901                 cp $HTMLFILE_NAME $LTPROOT/output/
902              fi
903           fi
904           if [ "$OUTPUTFILE_NAME" ] ; then                        ## Output file exists
905              if [ "$ALT_DIR_OUT" -ne 1 ] ; then                   ## The Output file path is absolute and not $LTPROOT/output
906                 mkdir -p $LTPROOT/output                          ## We need to create this Directory
907                 cp $OUTPUTFILE_NAME $LTPROOT/output/
908              fi
909           fi
910           if [ "$LOGFILE_NAME" ] ; then                           ## Log file exists
911              if [ "$ALT_DIR_RES" -ne 1 ] ; then                   ## The Log file path is absolute and not $LTPROOT/results
912                 mkdir -p $LTPROOT/results                         ## We need to create this Directory
913                 cp $LOGFILE_NAME $LTPROOT/results/
914              fi
915           fi
916           if [ -d $LTPROOT/output ] ; then
917              tar -cf  ./$TAR_FILE_NAME $LTPROOT/output
918              if [ $? -eq 0 ]; then
919                 echo "Created TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/output"
920              else
921                 echo "Cannot Create TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/output"
922              fi
923           fi
924           if [ -d $LTPROOT/results ] ; then
925              tar -uf ./$TAR_FILE_NAME $LTPROOT/results
926              if [ $? -eq 0 ]; then
927                 echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/results"
928              else
929                 echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/results"
930              fi
931           fi
932           if [ -e $LTPROOT/nohup.out ] ; then                     ## If User would have Chosen nohup to do ltprun
933              tar -uf ./$TAR_FILE_NAME $LTPROOT/nohup.out
934              if [ $? -eq 0 ]; then
935                 echo "Updated TAR File: ./$TAR_FILE_NAME successfully, added $LTPROOT/nohup.out"
936              else
937                 echo "Cannot Update TAR File: ./$TAR_FILE_NAME for adding $LTPROOT/nohup.out"
938              fi
939           fi
940           gzip ./$TAR_FILE_NAME                                     ## gzip this guy
941           if [ $? -eq 0 ]; then
942              echo "Gunzipped TAR File: ./$TAR_FILE_NAME"
943           else
944              echo "Cannot Gunzip TAR File: ./$TAR_FILE_NAME"
945           fi
946           if [ -e /usr/bin/mutt ] ; then                          ## This is a better mail client than others
947              echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz"
948              mutt -a ./$TAR_FILE_NAME.gz -s "LTP Reports on $test_start_time" $EMAIL_TO < /dev/null
949              if [ $? -eq 0 ]; then
950                 echo "Reports Successfully mailed to: $EMAIL_TO"
951              else
952                 echo "Reports cannot be mailed to: $EMAIL_TO"
953              fi
954           else ## Use our Ageold mail program
955              echo "Starting mailing reports to: $EMAIL_TO, file: ./$TAR_FILE_NAME.gz"
956              uuencode ./$TAR_FILE_NAME.gz $TAR_FILE_NAME.gz | mail  $EMAIL_TO -s "LTP Reports on $test_start_time"
957              if [ $? -eq 0 ]; then
958                 echo "Reports Successfully mailed to: $EMAIL_TO"
959              else
960                 echo "Reports cannot be mailed to: $EMAIL_TO"
961              fi
962           fi
963       fi
964    fi
965
966    [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test end time: $(date)" ; }
967
968    [ "$GENLOAD" -eq 1 ] && { killall -9 genload  >/dev/null 2>&1; }
969    [ "$NETPIPE" -eq 1 ] && { killall -9 NPtcp  >/dev/null 2>&1; }
970
971    [ "$ALT_DIR_OUT" -eq 1 ] || [ "$ALT_DIR_RES" -eq 1 ] && \
972    {
973    cat <<-EOF >&1
974
975       ###############################################################
976
977            Done executing testcases.
978            LTP Version:  $version_date
979       ###############################################################
980
981	EOF
982    }
983    exit $VALUE
984}
985
986create_block()
987{
988    #create a block device
989    dd if=/dev/zero of=${TMP}/test.img bs=1024 count=262144 >/dev/null 2>&1
990    if [ $? -ne 0 ]; then
991        echo "Failed to create loopback device image, please check disk space and re-run"
992        return 1
993    else
994        ##search for an unused loop dev
995        LOOP_DEV=$(losetup -f)
996        if [ $? -ne 0 ]; then
997            echo "no unused loop device is found"
998            return 1
999        else
1000            ##attach the created file to loop dev.
1001            losetup $LOOP_DEV ${TMP}/test.img
1002            if [ $? -ne 0 ]; then
1003                echo "losetup failed to create block device"
1004                return 1
1005            fi
1006            DEVICE=$LOOP_DEV
1007            return 0
1008        fi
1009    fi
1010}
1011
1012set_block_device()
1013{
1014    if [ -z "$DEVICE" ]; then
1015        create_block
1016        if [ $? -ne 0 ]; then
1017            echo "no block device was specified on commandline."
1018            echo "Block device could not be created using loopback device"
1019            echo "Tests which require block device are disabled."
1020            echo "You can specify it with option -b"
1021	else
1022            export LTP_DEV=$DEVICE
1023        fi
1024    else
1025        export LTP_DEV=$DEVICE
1026    fi
1027}
1028
1029cleanup()
1030{
1031    [ "$LOOP_DEV" ] && losetup -d $LOOP_DEV
1032    rm -rf ${TMP}
1033}
1034
1035
1036LTP_SCRIPT="$(basename $0)"
1037
1038if [ "$LTP_SCRIPT" = "runltp" ]; then
1039    trap "cleanup" 0
1040    setup
1041    main "$@"
1042fi
1043