Home | History | Annotate | Download | only in testscripts
      1 #!/bin/bash
      2 ################################################################################
      3 ##                                                                            ##
      4 ## Copyright   International Business Machines  Corp., 2007, 2008            ##
      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 
     22 
     23 #
     24 # Script to run the tests in testcases/realtime
     25 #
     26 # Usage: $0 test_argument
     27 #
     28 # where test-argument = func | stress | perf | all | list | clean | test_name
     29 #
     30 # test_name is the name of a subdirectory in func/, stress/ or perf/
     31 #
     32 echo "Real-time tests run"
     33 
     34 export LTPROOT=${PWD}
     35 echo $LTPROOT | grep testscripts > /dev/null 2>&1
     36 if [ $? -eq 0 ]; then
     37         cd ..
     38         export LTPROOT=${PWD}
     39 fi
     40 
     41 
     42 function usage()
     43 {
     44 	cat <<EOF
     45 Usage: test_realtime.sh  -t test-argument [-l loop num_of_iterations] [-t test-argument1 [-l loop ...]] ...
     46 
     47  test-argument: func | stress | perf | all | list | clean | test_name
     48  func:	 	all functional tests will be run
     49  stress: 	all stress tests will be run
     50  perf:		all perf tests will be run
     51  all:		all tests will be run
     52  list:	 	all available tests will be listed
     53  clean: 	all logs deleted, make clean performed
     54  test_name:	only test_name subdir will be run (e.g: func/pi-tests)
     55 EOF
     56 	exit 1;
     57 }
     58 
     59 function check_error()
     60 {
     61         if [ $? -gt 0 ]; then
     62         printf "\n $1 Failed\n\n"
     63         exit 1
     64         fi
     65 }
     66 
     67 list_tests()
     68 {
     69 	printf "\nAvailable tests are:\n\n"
     70 
     71 	cd $TESTS_DIR
     72 	for file in `find -name run_auto.sh`
     73 	do
     74 		printf " `dirname  $file `\n"
     75 	done
     76 		printf " \n\n"
     77 }
     78 
     79 function run_test()
     80 {
     81         iter=0
     82         if [ -z "$2" ]; then
     83             LOOPS=1
     84         else
     85          LOOPS=$2
     86         fi
     87         #Test if $LOOPS is a integer
     88         if [[ ! $LOOPS =~ ^[0-9]+$ ]]; then
     89             echo "\"$LOOPS\" doesn't appear to be a number"
     90             usage
     91             exit
     92         fi
     93         if [ -d "$test" ]; then
     94             pushd $test >/dev/null
     95             if [ -f "run_auto.sh" ]; then
     96                 echo " Running $LOOPS runs of $subdir "
     97                 for((iter=0; $iter < $LOOPS; iter++)); do
     98                 ./run_auto.sh
     99                 done
    100             else
    101                 printf "\n Failed to find run script in $test \n\n"
    102             fi
    103             pushd $TESTS_DIR >/dev/null
    104         else
    105                 printf "\n $test is not a valid test subdirectory \n"
    106                 usage
    107                 exit 1
    108         fi
    109 }
    110 
    111 function make_clean()
    112 {
    113         pushd $TESTS_DIR >/dev/null
    114         rm -rf logs
    115         make clean
    116 }
    117 
    118 find_test()
    119 {
    120     case $1 in
    121         func)
    122             TESTLIST="func"
    123             ;;
    124         stress)
    125             TESTLIST="stress"
    126             ;;
    127         perf)
    128             TESTLIST="perf"
    129             ;;
    130         all)
    131         # Run all tests which have run_auto.sh
    132             TESTLIST="func stress perf"
    133             ;;
    134         list)
    135         # This will only display subdirs which have run_auto.sh
    136             list_tests
    137             exit
    138             ;;
    139         clean)
    140         # This will clobber logs, out files, .o's etc
    141             make_clean
    142             exit
    143             ;;
    144 
    145         *)
    146         # run the tests in the individual subdirectory if it exists
    147             TESTLIST="$1"
    148             ;;
    149     esac
    150     for subdir in $TESTLIST; do
    151         if [ -d $subdir ]; then
    152             pushd $subdir >/dev/null
    153             for name in `find -name "run_auto.sh"`; do
    154                 test="`dirname $name`"
    155                 run_test "$test" "$2"
    156                 pushd $subdir > /dev/null
    157             done
    158                 pushd $TESTS_DIR >/dev/null
    159         else
    160             printf "\n $subdir not found; check name/path with run.sh list \n"
    161         fi
    162     done
    163 
    164 }
    165 
    166 source $LTPROOT/testcases/realtime/scripts/setenv.sh
    167 
    168 if [ $# -lt 1 ]; then
    169 	usage
    170 fi
    171 pushd $TESTS_DIR >/dev/null
    172 
    173 cd $TESTS_DIR
    174 if [ ! -e "logs" ]; then
    175         mkdir logs
    176         echo " creating logs directory as $TESTS_DIR/logs "
    177         chmod -R 775 logs
    178 fi
    179 
    180 # if INSTALL_DIR != top_srcdir assume the individual tests are built and installed.
    181 # So no need to build lib
    182 if [[ -d lib ]]; then
    183     #Only build the library, most of the tests depend upon.
    184     #The Individual tests will be built, just before they run.
    185     pushd lib
    186     make
    187     check_error make
    188     popd
    189 fi
    190 
    191 ISLOOP=0
    192 index=0
    193 while getopts ":t:l:h" option
    194 do
    195     case "$option" in
    196 
    197         t )
    198             if [ $ISLOOP -eq 1 ]; then
    199                 LOOP=1
    200                 tests[$index]=$LOOP
    201                 index=$((index+1))
    202             fi
    203 
    204             tests[$index]="$OPTARG"
    205             index=$((index+1))
    206             TESTCASE="$OPTARG"
    207             ISLOOP=1
    208             ;;
    209 
    210         l )
    211             ISLOOP=0
    212             tests[$index]="$OPTARG"
    213             LOOP="$OPTARG"
    214             index=$((index+1))
    215             ;;
    216         h )
    217             usage
    218             ;;
    219         * ) echo "Unrecognized option specified"
    220             usage
    221             ;;
    222     esac
    223 done
    224 for(( i=0; $i < $index ; $((i+=2)) )); do
    225     find_test ${tests[$i]} ${tests[$((i+1))]}
    226 done
    227 
    228