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 rt-test 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 33usage() 34{ 35 cat <<EOF 36usage: $(basename "$0") [-p profile] -t test-argument [-l num_of_loops] 37 38 -h help 39 -p profile Use profile instead of default (see 40 doc/AUTOMATED_RUN) 41 -t test-arguments Where test-argument can be a space separated 42 sequence of: 43 func all functional tests will be run 44 stress all stress tests will be run 45 perf all perf tests will be run 46 all all tests will be run 47 list all available tests will be listed 48 clean all logs deleted, make clean 49 performed 50 test_name only test_name subdir will be run 51 (e.g: func/pi-tests) 52 53EOF 54 exit 1 55} 56check_error() 57{ 58 if [ $? -gt 0 ]; then 59 echo 60 echo " $1 Failed" 61 echo 62 exit 1 63 fi 64} 65list_tests() 66{ 67 echo 68 echo " Available tests are:" 69 echo 70 71 pushd $TESTS_DIR >/dev/null 72 for file in `find -name run_auto.sh` 73 do 74 echo " `dirname $file `" 75 done 76 printf " \n\n" 77} 78 79run_test() 80{ 81 local profile 82 83 profile=$1 84 shift 85 86 iter=0 87 LOOPS=$(( 0 + $2 )) 88 if [ $LOOPS -eq 0 ]; then 89 LOOPS=1 90 fi 91 if [ -d "$test" ]; then 92 pushd $test >/dev/null 93 if [ -f "run_auto.sh" ]; then 94 echo " Running $LOOPS runs of $subdir " 95 iter=0 96 while [ $iter -lt $LOOPS ]; do 97 ./run_auto.sh $profile 98 : $(( iter += 1 )) 99 done 100 else 101 echo 102 echo " Failed to find run script in $test \n" 103 fi 104 pushd $TESTS_DIR >/dev/null 105 else 106 printf "\n $test is not a valid test subdirectory \n" 107 usage 108 exit 1 109 fi 110} 111 112make_clean() 113{ 114 pushd $TESTS_DIR >/dev/null 115 rm -rf logs/* 116 for mfile in `find -name "Makefile"`; 117 do 118 target_dir=`dirname $mfile` 119 pushd $target_dir >/dev/null 120 make clean 121 pushd $TESTS_DIR >/dev/null 122 done 123} 124 125find_test() 126{ 127 local profile 128 129 profile=$1 130 shift 131 132 case $1 in 133 func) 134 TESTLIST="func" 135 ;; 136 stress) 137 TESTLIST="stress" 138 ;; 139 perf) 140 TESTLIST="perf" 141 ;; 142 all) 143 # Run all tests which have run_auto.sh 144 TESTLIST="func stress perf" 145 ;; 146 list) 147 # This will only display subdirs which have run_auto.sh 148 list_tests 149 exit 150 ;; 151 clean) 152 # This will clobber logs, out files, .o's etc 153 make_clean 154 exit 155 ;; 156 157 *) 158 # run the tests in the individual subdirectory if it exists 159 TESTLIST="$1" 160 ;; 161 esac 162 163 for subdir in $TESTLIST; do 164 if [ -d $subdir ]; then 165 pushd $subdir >/dev/null 166 for name in `find -name "run_auto.sh"`; do 167 test="`dirname $name`" 168 run_test "$profile" "$test" "$2" 169 pushd $subdir > /dev/null 170 done 171 pushd $TESTS_DIR >/dev/null 172 else 173 echo 174 echo " $subdir not found; check name/path with $0 list " 175 fi 176 done 177 178} 179 180SCRIPTS_DIR="$(readlink -f "$(dirname "$0")")/scripts" 181source $SCRIPTS_DIR/setenv.sh 182 183if [ $# -lt 1 ]; then 184 usage 185fi 186pushd $TESTS_DIR >/dev/null 187 188# if INSTALL_DIR != top_srcdir assume the individual tests are built and installed. 189# So no need to build lib 190if [[ -d lib ]]; then 191 #Only build the library, most of the tests depend upon. 192 #The Individual tests will be built, just before they run. 193 pushd lib 194 make 195 check_error make 196 popd 197fi 198 199ISLOOP=0 200index=0 201while getopts "hl:p:t:" option 202do 203 case "$option" in 204 205 t ) 206 if [ $ISLOOP -eq 1 ]; then 207 LOOP=1 208 tests[$index]=$LOOP 209 : $(( index += 1 )) 210 fi 211 212 tests[$index]="$OPTARG" 213 : $((index += 1 )) 214 TESTCASE="$OPTARG" 215 ISLOOP=1 216 ;; 217 218 l ) 219 ISLOOP=0 220 tests[$index]="$OPTARG" 221 LOOP="$OPTARG" 222 index=$((index+1)) 223 ;; 224 p ) 225 profile=$OPTARG 226 ;; 227 h ) 228 usage 229 ;; 230 * ) echo "Unrecognized option specified" 231 usage 232 ;; 233 esac 234done 235 236tests[$index]=1 237 238i=0 239while [ $i -lt $index ]; do 240 find_test "$profile" ${tests[$i]} ${tests[$((i+1))]} 241 : $(( i += 2 )) 242done 243