blob: 22c369282c331e155199f0c7680f90a08d6c930c [file] [log] [blame]
subrata_modak13782052008-02-22 14:43:53 +00001################################################################################
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 Gao4548c6c2012-10-19 18:03:36 +080017## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
subrata_modak13782052008-02-22 14:43:53 +000018## ##
19################################################################################
20
21
subrata_modakc8aeefb2007-12-28 09:13:09 +000022#! /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#
32echo "Real-time tests run"
33
34export LTPROOT=${PWD}
35echo $LTPROOT | grep testscripts > /dev/null 2>&1
36if [ $? -eq 0 ]; then
37 cd ..
38 export LTPROOT=${PWD}
39fi
40
41
42function usage()
43{
subrata_modak13782052008-02-22 14:43:53 +000044 echo -e "\nUsage: test_realtime.sh -t test-argument [-l loop num_of_iterations] [-t test-argument1 [-l loop ...]] ..."
subrata_modak3d688dd2008-01-10 10:28:14 +000045 echo -e "\nWhere test-argument = func | stress | perf | all | list | clean | test_name"
46 echo -e "\nand:\n"
subrata_modakc8aeefb2007-12-28 09:13:09 +000047 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_modak13782052008-02-22 14:43:53 +000058function check_error()
59{
60 if [ $? -gt 0 ]; then
61 echo -e "\n $1 Failed\n"
62 exit 1
63 fi
64}
65
subrata_modakc8aeefb2007-12-28 09:13:09 +000066list_tests()
67{
subrata_modak3d688dd2008-01-10 10:28:14 +000068 echo -e "\nAvailable tests are:\n"
subrata_modakc8aeefb2007-12-28 09:13:09 +000069
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
78function run_test()
79{
subrata_modak13782052008-02-22 14:43:53 +000080 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_modakc8aeefb2007-12-28 09:13:09 +0000108}
109
110function make_clean()
111{
subrata_modak13782052008-02-22 14:43:53 +0000112 pushd $TESTS_DIR >/dev/null
subrata_modak58f0b1a2008-03-24 09:37:59 +0000113 rm -rf logs
114 make clean
subrata_modak13782052008-02-22 14:43:53 +0000115}
116
117find_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_modakc8aeefb2007-12-28 09:13:09 +0000163}
164
165source $LTPROOT/testcases/realtime/scripts/setenv.sh
166
subrata_modak13782052008-02-22 14:43:53 +0000167if [ $# -lt 1 ]; then
subrata_modakc8aeefb2007-12-28 09:13:09 +0000168 usage
169fi
subrata_modak13782052008-02-22 14:43:53 +0000170pushd $TESTS_DIR >/dev/null
subrata_modakc8aeefb2007-12-28 09:13:09 +0000171
172cd $TESTS_DIR
subrata_modak3d688dd2008-01-10 10:28:14 +0000173if [ ! -e "logs" ]; then
174 mkdir logs
175 echo " creating logs directory as $TESTS_DIR/logs "
176 chmod -R 775 logs
177fi
178
subrata_modak13782052008-02-22 14:43:53 +0000179#Only build the library, most of the tests depend upon.
180#The Individual tests will be built, just before they run.
181pushd lib
subrata_modakc8aeefb2007-12-28 09:13:09 +0000182make
subrata_modak13782052008-02-22 14:43:53 +0000183check_error make
184popd
subrata_modakc8aeefb2007-12-28 09:13:09 +0000185
subrata_modak13782052008-02-22 14:43:53 +0000186ISLOOP=0
187index=0
188while getopts ":t:l:h" option
subrata_modakc8aeefb2007-12-28 09:13:09 +0000189do
subrata_modak13782052008-02-22 14:43:53 +0000190 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_modakc8aeefb2007-12-28 09:13:09 +0000218done
subrata_modak13782052008-02-22 14:43:53 +0000219for(( i=0; $i < $index ; $((i+=2)) )); do
220 find_test ${tests[$i]} ${tests[$((i+1))]}
221done
222