subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 1 | ################################################################################ |
| 2 | ## ## |
| 3 | ## Copyright © International Business Machines Corp., 2007, 2008 ## |
| 4 | ## ## |
| 5 | ## This program is free software; you can redistribute it and#or modify ## |
| 6 | ## it under the terms of the GNU General Public License as published by ## |
| 7 | ## the Free Software Foundation; either version 2 of the License, or ## |
| 8 | ## (at your option) any later version. ## |
| 9 | ## ## |
| 10 | ## This program is distributed in the hope that it will be useful, but ## |
| 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## |
| 12 | ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## |
| 13 | ## for more details. ## |
| 14 | ## ## |
| 15 | ## You should have received a copy of the GNU General Public License ## |
| 16 | ## along with this program; if not, write to the Free Software ## |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 18 | ## ## |
| 19 | ################################################################################ |
| 20 | |
| 21 | |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 22 | #! /bin/bash |
| 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 | { |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 44 | echo -e "\nUsage: test_realtime.sh -t test-argument [-l loop num_of_iterations] [-t test-argument1 [-l loop ...]] ..." |
subrata_modak | 3d688dd | 2008-01-10 10:28:14 +0000 | [diff] [blame] | 45 | echo -e "\nWhere test-argument = func | stress | perf | all | list | clean | test_name" |
| 46 | echo -e "\nand:\n" |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 47 | echo -e " func = all functional tests will be run " |
| 48 | echo -e " stress = all stress tests will be run " |
| 49 | echo -e " perf = all perf tests will be run " |
| 50 | echo -e " all = all tests will be run " |
| 51 | echo -e " list = all available tests will be listed " |
| 52 | echo -e " clean = all logs deleted, make clean performed " |
| 53 | echo -e " test_name = only test_name subdir will be run (e.g: func/pi-tests) " |
| 54 | echo -e "\n" |
| 55 | exit 1; |
| 56 | } |
| 57 | |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 58 | function check_error() |
| 59 | { |
| 60 | if [ $? -gt 0 ]; then |
| 61 | echo -e "\n $1 Failed\n" |
| 62 | exit 1 |
| 63 | fi |
| 64 | } |
| 65 | |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 66 | list_tests() |
| 67 | { |
subrata_modak | 3d688dd | 2008-01-10 10:28:14 +0000 | [diff] [blame] | 68 | echo -e "\nAvailable tests are:\n" |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 69 | |
| 70 | cd $TESTS_DIR |
| 71 | for file in `find -name run_auto.sh` |
| 72 | do |
| 73 | echo -e " `dirname $file `" |
| 74 | done |
| 75 | echo -e " \n" |
| 76 | } |
| 77 | |
| 78 | function run_test() |
| 79 | { |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 80 | iter=0 |
| 81 | if [ -z "$2" ]; then |
| 82 | LOOPS=1 |
| 83 | else |
| 84 | LOOPS=$2 |
| 85 | fi |
| 86 | #Test if $LOOPS is a integer |
| 87 | if [[ ! $LOOPS =~ ^[0-9]+$ ]]; then |
| 88 | echo "\"$LOOPS\" doesn't appear to be a number" |
| 89 | usage |
| 90 | exit |
| 91 | fi |
| 92 | if [ -d "$test" ]; then |
| 93 | pushd $test >/dev/null |
| 94 | if [ -f "run_auto.sh" ]; then |
| 95 | echo " Running $LOOPS runs of $subdir " |
| 96 | for((iter=0; $iter < $LOOPS; iter++)); do |
| 97 | ./run_auto.sh |
| 98 | done |
| 99 | else |
| 100 | echo -e "\n Failed to find run script in $test \n" |
| 101 | fi |
| 102 | pushd $TESTS_DIR >/dev/null |
| 103 | else |
| 104 | echo -e "\n $test is not a valid test subdirectory " |
| 105 | usage |
| 106 | exit 1 |
| 107 | fi |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | function make_clean() |
| 111 | { |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 112 | pushd $TESTS_DIR >/dev/null |
subrata_modak | 58f0b1a | 2008-03-24 09:37:59 +0000 | [diff] [blame] | 113 | rm -rf logs |
| 114 | make clean |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | find_test() |
| 118 | { |
| 119 | case $1 in |
| 120 | func) |
| 121 | TESTLIST="func" |
| 122 | ;; |
| 123 | stress) |
| 124 | TESTLIST="stress" |
| 125 | ;; |
| 126 | perf) |
| 127 | TESTLIST="perf" |
| 128 | ;; |
| 129 | all) |
| 130 | # Run all tests which have run_auto.sh |
| 131 | TESTLIST="func stress java perf" |
| 132 | ;; |
| 133 | list) |
| 134 | # This will only display subdirs which have run_auto.sh |
| 135 | list_tests |
| 136 | exit |
| 137 | ;; |
| 138 | clean) |
| 139 | # This will clobber logs, out files, .o's etc |
| 140 | make_clean |
| 141 | exit |
| 142 | ;; |
| 143 | |
| 144 | *) |
| 145 | # run the tests in the individual subdirectory if it exists |
| 146 | TESTLIST="$1" |
| 147 | ;; |
| 148 | esac |
| 149 | for subdir in $TESTLIST; do |
| 150 | if [ -d $subdir ]; then |
| 151 | pushd $subdir >/dev/null |
| 152 | for name in `find -name "run_auto.sh"`; do |
| 153 | test="`dirname $name`" |
| 154 | run_test "$test" "$2" |
| 155 | pushd $subdir > /dev/null |
| 156 | done |
| 157 | pushd $TESTS_DIR >/dev/null |
| 158 | else |
| 159 | echo -e "\n $subdir not found; check name/path with run.sh list " |
| 160 | fi |
| 161 | done |
| 162 | |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | source $LTPROOT/testcases/realtime/scripts/setenv.sh |
| 166 | |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 167 | if [ $# -lt 1 ]; then |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 168 | usage |
| 169 | fi |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 170 | pushd $TESTS_DIR >/dev/null |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 171 | |
| 172 | cd $TESTS_DIR |
subrata_modak | 3d688dd | 2008-01-10 10:28:14 +0000 | [diff] [blame] | 173 | if [ ! -e "logs" ]; then |
| 174 | mkdir logs |
| 175 | echo " creating logs directory as $TESTS_DIR/logs " |
| 176 | chmod -R 775 logs |
| 177 | fi |
| 178 | |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 179 | #Only build the library, most of the tests depend upon. |
| 180 | #The Individual tests will be built, just before they run. |
| 181 | pushd lib |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 182 | make |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 183 | check_error make |
| 184 | popd |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 185 | |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 186 | ISLOOP=0 |
| 187 | index=0 |
| 188 | while getopts ":t:l:h" option |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 189 | do |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 190 | case "$option" in |
| 191 | |
| 192 | t ) |
| 193 | if [ $ISLOOP -eq 1 ]; then |
| 194 | LOOP=1 |
| 195 | tests[$index]=$LOOP |
| 196 | index=$((index+1)) |
| 197 | fi |
| 198 | |
| 199 | tests[$index]="$OPTARG" |
| 200 | index=$((index+1)) |
| 201 | TESTCASE="$OPTARG" |
| 202 | ISLOOP=1 |
| 203 | ;; |
| 204 | |
| 205 | l ) |
| 206 | ISLOOP=0 |
| 207 | tests[$index]="$OPTARG" |
| 208 | LOOP="$OPTARG" |
| 209 | index=$((index+1)) |
| 210 | ;; |
| 211 | h ) |
| 212 | usage |
| 213 | ;; |
| 214 | * ) echo "Unrecognized option specified" |
| 215 | usage |
| 216 | ;; |
| 217 | esac |
subrata_modak | c8aeefb | 2007-12-28 09:13:09 +0000 | [diff] [blame] | 218 | done |
subrata_modak | 1378205 | 2008-02-22 14:43:53 +0000 | [diff] [blame] | 219 | for(( i=0; $i < $index ; $((i+=2)) )); do |
| 220 | find_test ${tests[$i]} ${tests[$((i+1))]} |
| 221 | done |
| 222 | |