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