Imported Upstream version 20090930
[ltp-debian.git] / testscripts / test_realtime.sh
blobf95cb65fb2eda00f6efa80ca59d0fc1895deb58a
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 ##
17 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
18 ## ##
19 ################################################################################
22 #! /bin/bash
24 # Script to run the tests in testcases/realtime
26 # Usage: $0 test_argument
28 # where test-argument = func | stress | perf | all | list | clean | test_name
30 # test_name is the name of a subdirectory in func/, stress/ or perf/
32 echo "Real-time tests run"
34 export LTPROOT=${PWD}
35 echo $LTPROOT | grep testscripts > /dev/null 2>&1
36 if [ $? -eq 0 ]; then
37 cd ..
38 export LTPROOT=${PWD}
42 function usage()
44 echo -e "\nUsage: test_realtime.sh -t test-argument [-l loop num_of_iterations] [-t test-argument1 [-l loop ...]] ..."
45 echo -e "\nWhere test-argument = func | stress | perf | all | list | clean | test_name"
46 echo -e "\nand:\n"
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;
58 function check_error()
60 if [ $? -gt 0 ]; then
61 echo -e "\n $1 Failed\n"
62 exit 1
66 list_tests()
68 echo -e "\nAvailable tests are:\n"
70 cd $TESTS_DIR
71 for file in `find -name run_auto.sh`
73 echo -e " `dirname $file `"
74 done
75 echo -e " \n"
78 function run_test()
80 iter=0
81 if [ -z "$2" ]; then
82 LOOPS=1
83 else
84 LOOPS=$2
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
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"
102 pushd $TESTS_DIR >/dev/null
103 else
104 echo -e "\n $test is not a valid test subdirectory "
105 usage
106 exit 1
110 function make_clean()
112 pushd $TESTS_DIR >/dev/null
113 rm -rf logs
114 make clean
117 find_test()
119 case $1 in
120 func)
121 TESTLIST="func"
123 stress)
124 TESTLIST="stress"
126 perf)
127 TESTLIST="perf"
129 all)
130 # Run all tests which have run_auto.sh
131 TESTLIST="func stress java perf"
133 list)
134 # This will only display subdirs which have run_auto.sh
135 list_tests
136 exit
138 clean)
139 # This will clobber logs, out files, .o's etc
140 make_clean
141 exit
145 # run the tests in the individual subdirectory if it exists
146 TESTLIST="$1"
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 "
161 done
165 source $LTPROOT/testcases/realtime/scripts/setenv.sh
167 if [ $# -lt 1 ]; then
168 usage
170 pushd $TESTS_DIR >/dev/null
172 cd $TESTS_DIR
173 if [ ! -e "logs" ]; then
174 mkdir logs
175 echo " creating logs directory as $TESTS_DIR/logs "
176 chmod -R 775 logs
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
182 make
183 check_error make
184 popd
186 ISLOOP=0
187 index=0
188 while getopts ":t:l:h" option
190 case "$option" in
193 if [ $ISLOOP -eq 1 ]; then
194 LOOP=1
195 tests[$index]=$LOOP
196 index=$((index+1))
199 tests[$index]="$OPTARG"
200 index=$((index+1))
201 TESTCASE="$OPTARG"
202 ISLOOP=1
206 ISLOOP=0
207 tests[$index]="$OPTARG"
208 LOOP="$OPTARG"
209 index=$((index+1))
212 usage
214 * ) echo "Unrecognized option specified"
215 usage
217 esac
218 done
219 for(( i=0; $i < $index ; $((i+=2)) )); do
220 find_test ${tests[$i]} ${tests[$((i+1))]}
221 done