• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2################################################################################
3##                                                                            ##
4## Copyright (c) International Business Machines  Corp., 2001,2005            ##
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: runltplite
22#
23# Description:  This script can be used to run a subset the tests in the LTP test suite
24#               This script is typically used as a quick test to check an install base.
25#
26# Authors:      Manoj Iyer - manoji@us.ibm.com
27#               Robbie Williamson - robbiew@us.ibm.com
28#               Marty Ridgeway - mridge@us.ibm.com
29#
30# History:      Created runltplite script to run a subset of the LTP testsuite
31#
32#
33#
34#
35#
36#
37#
38#
39
40. "$(dirname $0)/runltp"
41
42setup()
43{
44    cd `dirname $0` || \
45    {
46        echo "FATAL: unable to change directory to $(dirname $0)"
47        exit 1
48    }
49    export LTPROOT=${PWD}
50    export TMPBASE="/tmp"
51    export TMP="${TMPBASE}/ltp-$$"
52    export PATH="${PATH}:${LTPROOT}/testcases/bin"
53
54    export LTP_DEV=""
55    export LTP_DEV_FS_TYPE="ext2"
56
57    [ -d $LTPROOT/testcases/bin ] ||
58    {
59        echo "FATAL: LTP not installed correctly"
60        echo "INFO:  Follow directions in INSTALL!"
61        exit 1
62    }
63
64    [ -e $LTPROOT/bin/ltp-pan ] ||
65    {
66        echo "FATAL: Test suite driver 'ltp-pan' not found"
67        echo "INFO:  Follow directions in INSTALL!"
68        exit 1
69    }
70}
71
72
73usage()
74{
75    cat <<-EOF >&2
76
77    usage: ${0##*/} -c [-d TMPDIR] [-i # (in Mb)]
78    [ -l LOGFILE ] [ -o OUTPUTFILE ] [ -m # (in Mb)] -N -q
79    [ -r LTPROOT ] -v
80
81    -c NUM_PROCS    Run LTP under additional background CPU load.
82    -d TMPDIR       Directory where temporary files will be created.
83    -h              Help. Prints all available options.
84    -i # (in Mb)    Run LTP with a _min_ IO load of # Mb in background.
85    -l LOGFILE      Log results of test in a logfile.
86    -m # (in Mb)    Run LTP with a _min_ memory load of # Mb in background.
87    -N              Run all the networking tests.
88    -o OUTPUTFILE   Redirect test output to a file.
89    -p              Human readable format logfiles.
90    -q              Print less verbose output to screen.
91    -r LTPROOT      Fully qualified path where testsuite is installed.
92    -S SKIPFILE     Skip tests specified in SKIPFILE.
93    -b DEVICE       Some tests require an unmounted block device to run
94                    correctly.
95    -B LTP_DEV_FS_TYPE  The file system of test block devices.
96
97    example: ${0##*/} -i 1024 -m 128 -p -q  -l /tmp/resultlog.$$ -d ${PWD}
98
99
100	EOF
101exit 0
102}
103
104
105main()
106{
107    local CMDFILE="ltplite"
108    local PRETTY_PRT=""
109    local ALT_DIR=0
110    local RUN_NETEST=0
111    local QUIET_MODE=""
112    local VERBOSE_MODE=""
113    local NETPIPE=0
114    local GENLOAD=0
115    local MEMSIZE=0
116    local DURATION=""
117    local BYTESIZE=0
118    local LOGFILE=""
119    local PRETTY_PRT=""
120    local TAG_RESTRICT_STRING=""
121    local PAN_COMMAND=""
122
123    local scenfile=""
124
125    while getopts c:d:hi:l:m:No:pqr:S:b:B: arg
126    do  case $arg in
127        c)
128	    NUM_PROCS=$(($OPTARG))
129            $LTPROOT/testcases/bin/genload --cpu $NUM_PROCS >/dev/null 2>&1 &
130            GENLOAD=1 ;;
131
132        d)  # append $$ to TMP, as it is recursively
133            # removed at end of script.
134            TMPBASE=$OPTARG
135            TMP="${TMPBASE}/ltp-$$"
136            export TMPDIR="$TMP";;
137
138        h)  usage;;
139
140        i)
141            BYTESIZE=$(($OPTARG * 1024 * 1024))
142            $LTPROOT/testcases/bin/genload --io 1 >/dev/null 2>&1 &
143            $LTPROOT/testcases/bin/genload --hdd 0 --hdd-bytes $BYTESIZE \
144            >/dev/null 2>&1 &
145            GENLOAD=1 ;;
146
147        l)
148
149            [ ! -d $LTPROOT/results ] && \
150            {
151               echo "INFO: creating $LTPROOT/results directory"
152               mkdir -p $LTPROOT/results || \
153               {
154                   echo "ERROR: failed to create $LTPROOT/results"
155                   exit 1
156                }
157            }
158            case $OPTARG in
159	    /*)
160                LOGFILE="-l $OPTARG" ;;
161            *)
162                LOGFILE="-l $LTPROOT/results/$OPTARG"
163                ALT_DIR=1 ;;
164            esac ;;
165
166        m)
167            MEMSIZE=$(($OPTARG * 1024 * 1024))
168            $LTPROOT/testcases/bin/genload  --vm 0 --vm-bytes $MEMSIZE \
169                >/dev/null 2>&1 &
170            GENLOAD=1;;
171
172        N)  RUN_NETEST=1;;
173
174        o)  OUTPUTFILE="-o $OPTARG" ;;
175
176        p)  PRETTY_PRT=" -p ";;
177
178        q)  QUIET_MODE=" -q ";;
179
180        r)  LTPROOT=$OPTARG;;
181
182        S)  case $OPTARG in
183                /*)
184                    SKIPFILE=$OPTARG;;
185                *)
186                    SKIPFILE="$LTPROOT/$OPTARG";;
187            esac ;;
188
189        b)  DEVICE=$OPTARG;;
190
191        B)  LTP_DEV_FS_TYPE=$OPTARG;;
192
193
194        \?) usage;;
195        esac
196    done
197
198
199    mkdir -p $TMP || \
200    {
201        echo "FATAL: Unable to make temporary directory $TMP"
202        exit 1
203    }
204
205    cd $TMP || \
206    {
207      echo "could not cd ${TMP} ... exiting"
208      exit 1
209    }
210
211# Run Networking tests ?
212
213    [ "$RUN_NETEST" -eq 1 ] && \
214    {
215        [ -z "$RHOST" ] || [ -z "$PASSWD" ] && \
216        {
217            [ -z "$RHOST" ] && \
218            {
219                echo \
220                "INFO: Enter RHOST = 'name of the remote host machine'"
221                echo -n "-> "
222                read RHOST
223            }
224
225            [ -z "$PASSWD" ] && \
226            {
227                echo " "
228                echo \
229                "INFO: Enter PASSWD = 'root passwd of the remote host machine'"
230                echo -n "-> "
231                read PASSWD
232            }
233            export RHOST=$RHOST
234            export PASSWD=$PASSWD
235            echo "WARNING: security of $RHOST may be compromised"
236        }
237    }
238
239    # If user does not provide a command file select a default set of testcases
240    # to execute.
241    if   [ -f $CMDFILE ] || \
242                CMDFILE="$LTPROOT/runtest/$CMDFILE"
243	then
244        cat $CMDFILE > ${TMP}/alltests || \
245        {
246            echo "FATAL: Unable to create command file"
247            exit 1
248        }
249    fi
250
251    if [ "$RUN_NETEST" -eq 1 ]; then
252        SCENARIO_LISTS="$SCENARIO_LISTS $LTPROOT/scenario_groups/network"
253    fi
254
255    # DO NOT INDENT/DEDENT!
256        if [ -n "$SCENARIO_LISTS" ]; then
257            # Insurance to make sure that the first element in the pipe
258            # completed successfully.
259            cat_ok_sentinel=$TMP/cat_ok.$$
260	    (cat $SCENARIO_LISTS && touch "$cat_ok_sentinel") | \
261                while read scenfile; do
262
263                    scenfile=${LTPROOT}/runtest/$scenfile
264
265                    # Skip over non-existent scenario files; things are
266                    # robust enough now that the build will fail if these
267                    # files don't exist.
268                    [ -f "$scenfile" ] || continue
269
270                    cat $scenfile >> "$TMP/alltests" || {
271                        echo "FATAL: unable to append to command file"
272                        rm -Rf "$TMP"
273                        rm -f "$cat_ok_sentinel"
274                        exit 1
275                    }
276
277                done
278
279            rm -f "$cat_ok_sentinel"
280
281        fi
282    # ^^DO NOT INDENT/DEDENT!^^
283
284    # The fsx-linux tests use the SCRATCHDEV environment variable as a location
285    # that can be reformatted and run on.  Set SCRATCHDEV if you want to run
286    # these tests.  As a safeguard, this is disabled.
287    unset SCRATCHDEV
288    [ -n "$SCRATCHDEV" ] && \
289    {
290         cat ${LTPROOT}/runtest/fsx >> ${TMP}/alltests ||
291         {
292             echo "FATAL: unable to create  fsx-linux tests command file"
293             exit 1
294         }
295    }
296
297    # check for required users and groups
298    ${LTPROOT}/IDcheck.sh >/dev/null 2>&1 || \
299    {
300        echo "WARNING: required users and groups not present"
301        echo "WARNING: some test cases may fail"
302    }
303
304    [ -n "$CMDFILES" ] && \
305    {
306        for scenfile in `echo "$CMDFILES" | tr ',' ' '`
307        do
308            [ -f "$scenfile" ] || scenfile="$LTPROOT/runtest/$scenfile"
309            cat "$scenfile" >> ${TMP}/alltests || \
310            {
311                echo "FATAL: unable to create command file"
312                rm -Rf "$TMP"
313                exit 1
314            }
315        done
316    }
317
318    # Blacklist or skip tests if a SKIPFILE was specified with -S
319    if [ -n "$SKIPFILE" ]
320    then
321        for file in $( cat $SKIPFILE ); do
322            sed -i "/^$file[ \t]/d" ${TMP}/alltests
323        done
324    fi
325
326    # display versions of installed software
327    [ -z "$QUIET_MODE" ] && \
328    {
329        ${LTPROOT}/ver_linux || \
330        {
331            echo "WARNING: unable to display versions of software installed"
332            exit 1
333        }
334    }
335
336    set_block_device
337
338    [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test start time: $(date)" ; }
339    PAN_COMMAND="${LTPROOT}/bin/ltp-pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \
340    -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE"
341    if [ ! -z "$VERBOSE_MODE" ] ; then
342      echo "COMMAND:    $PAN_COMMAND"
343      if [ ! -z "$TAG_RESTRICT_STRING" ] ; then
344        echo "INFO: Restricted to $TAG_RESTRICT_STRING"
345      fi
346    fi
347    #$PAN_COMMAND #Duplicated code here, because otherwise if we fail, only "PAN_COMMAND" gets output
348    # Some tests need to run inside the "bin" directory.
349    cd "${LTPROOT}/testcases/bin"
350    ${LTPROOT}/bin/ltp-pan $QUIET_MODE -e -S $INSTANCES $DURATION -a $$ \
351    -n $$ $PRETTY_PRT -f ${TMP}/alltests $LOGFILE $OUTPUTFILE
352
353    if [ $? -eq 0 ]; then
354      echo "INFO: ltp-pan reported all tests PASS"
355      VALUE=0
356    else
357      echo "INFO: ltp-pan reported some tests FAIL"
358      VALUE=1
359    fi
360    cd ..
361    [ ! -z "$QUIET_MODE" ] && { echo "INFO: Test end time: $(date)" ; }
362
363    [ "$GENLOAD" -eq 1 ] && { killall -9 genload ; }
364    [ "$NETPIPE" -eq 1 ] && { killall -9 NPtcp ; }
365
366    [ "$ALT_DIR" -eq 1 ] && \
367    {
368    cat <<-EOF >&1
369
370       ###############################################################"
371
372            Done executing testcases."
373            result log is in the $LTPROOT/results directory"
374
375       ###############################################################"
376
377	EOF
378    }
379    exit $VALUE
380}
381
382cleanup()
383{
384    rm -rf ${TMP}
385}
386
387trap "cleanup" 0
388setup
389main "$@"
390
391#vim: syntax=sh
392