blob: 174b36d6ff90dec2c5245054b266570475934a6f [file] [log] [blame]
Joseph Beckenbach169720f2014-03-26 15:08:46 +00001#!/bin/bash
subrata_modak2173c482007-12-27 10:02:41 +00002################################################################################
3## ##
subrata_modak13782052008-02-22 14:43:53 +00004## Copyright © International Business Machines Corp., 2007, 2008 ##
subrata_modak2173c482007-12-27 10:02:41 +00005## ##
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 ##
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
subrata_modak2173c482007-12-27 10:02:41 +000019## ##
20################################################################################
21
22
subrata_modak6acdc8e2007-12-26 11:11:45 +000023#
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
Garrett Cooperead440f2010-11-01 23:58:28 -070033usage()
subrata_modak6acdc8e2007-12-26 11:11:45 +000034{
Garrett Cooperead440f2010-11-01 23:58:28 -070035 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
subrata_modak6acdc8e2007-12-26 11:11:45 +000055}
Garrett Cooperead440f2010-11-01 23:58:28 -070056check_error()
subrata_modak13782052008-02-22 14:43:53 +000057{
58 if [ $? -gt 0 ]; then
Garrett Cooperead440f2010-11-01 23:58:28 -070059 echo
60 echo " $1 Failed"
61 echo
62 exit 1
subrata_modak13782052008-02-22 14:43:53 +000063 fi
64}
subrata_modak6acdc8e2007-12-26 11:11:45 +000065list_tests()
66{
Garrett Cooperead440f2010-11-01 23:58:28 -070067 echo
68 echo " Available tests are:"
69 echo
subrata_modak6acdc8e2007-12-26 11:11:45 +000070
subrata_modak13782052008-02-22 14:43:53 +000071 pushd $TESTS_DIR >/dev/null
subrata_modak6acdc8e2007-12-26 11:11:45 +000072 for file in `find -name run_auto.sh`
73 do
Petr Vorel0702d492016-11-29 09:22:40 +010074 echo " `dirname $file `"
subrata_modak6acdc8e2007-12-26 11:11:45 +000075 done
Petr Vorel0702d492016-11-29 09:22:40 +010076 printf " \n\n"
subrata_modak6acdc8e2007-12-26 11:11:45 +000077}
78
Garrett Cooperead440f2010-11-01 23:58:28 -070079run_test()
subrata_modak6acdc8e2007-12-26 11:11:45 +000080{
subrata_modak1ffddf02008-05-22 12:03:14 +000081 local profile
82
83 profile=$1
84 shift
85
subrata_modak6acdc8e2007-12-26 11:11:45 +000086 iter=0
Garrett Cooperead440f2010-11-01 23:58:28 -070087 LOOPS=$(( 0 + $2 ))
88 if [ $LOOPS -eq 0 ]; then
subrata_modak1ffddf02008-05-22 12:03:14 +000089 LOOPS=1
subrata_modak13782052008-02-22 14:43:53 +000090 fi
subrata_modak6acdc8e2007-12-26 11:11:45 +000091 if [ -d "$test" ]; then
subrata_modak1ffddf02008-05-22 12:03:14 +000092 pushd $test >/dev/null
93 if [ -f "run_auto.sh" ]; then
subrata_modak13782052008-02-22 14:43:53 +000094 echo " Running $LOOPS runs of $subdir "
Garrett Cooperead440f2010-11-01 23:58:28 -070095 iter=0
96 while [ $iter -lt $LOOPS ]; do
subrata_modak1ffddf02008-05-22 12:03:14 +000097 ./run_auto.sh $profile
Garrett Cooperead440f2010-11-01 23:58:28 -070098 : $(( iter += 1 ))
subrata_modak6acdc8e2007-12-26 11:11:45 +000099 done
Garrett Cooperead440f2010-11-01 23:58:28 -0700100 else
101 echo
102 echo " Failed to find run script in $test \n"
subrata_modak1ffddf02008-05-22 12:03:14 +0000103 fi
104 pushd $TESTS_DIR >/dev/null
subrata_modak6acdc8e2007-12-26 11:11:45 +0000105 else
Petr Vorel0702d492016-11-29 09:22:40 +0100106 printf "\n $test is not a valid test subdirectory \n"
subrata_modak6acdc8e2007-12-26 11:11:45 +0000107 usage
108 exit 1
109 fi
Chris Dearman37550cf2012-10-17 19:54:01 -0700110}
subrata_modak6acdc8e2007-12-26 11:11:45 +0000111
Garrett Cooperead440f2010-11-01 23:58:28 -0700112make_clean()
subrata_modak6acdc8e2007-12-26 11:11:45 +0000113{
subrata_modak13782052008-02-22 14:43:53 +0000114 pushd $TESTS_DIR >/dev/null
subrata_modak6acdc8e2007-12-26 11:11:45 +0000115 rm -rf logs/*
116 for mfile in `find -name "Makefile"`;
117 do
subrata_modak1ffddf02008-05-22 12:03:14 +0000118 target_dir=`dirname $mfile`
119 pushd $target_dir >/dev/null
120 make clean
121 pushd $TESTS_DIR >/dev/null
subrata_modak6acdc8e2007-12-26 11:11:45 +0000122 done
123}
124
subrata_modak13782052008-02-22 14:43:53 +0000125find_test()
126{
subrata_modak1ffddf02008-05-22 12:03:14 +0000127 local profile
subrata_modak13782052008-02-22 14:43:53 +0000128
subrata_modak1ffddf02008-05-22 12:03:14 +0000129 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
subrata_modak78596952008-09-18 10:30:56 +0000144 TESTLIST="func stress perf"
subrata_modak1ffddf02008-05-22 12:03:14 +0000145 ;;
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
Garrett Cooperead440f2010-11-01 23:58:28 -0700173 echo
174 echo " $subdir not found; check name/path with $0 list "
subrata_modak1ffddf02008-05-22 12:03:14 +0000175 fi
176 done
subrata_modak13782052008-02-22 14:43:53 +0000177
178}
179
Garrett Cooperead440f2010-11-01 23:58:28 -0700180SCRIPTS_DIR="$(readlink -f "$(dirname "$0")")/scripts"
subrata_modak6acdc8e2007-12-26 11:11:45 +0000181source $SCRIPTS_DIR/setenv.sh
182
183if [ $# -lt 1 ]; then
subrata_modak1ffddf02008-05-22 12:03:14 +0000184 usage
subrata_modak6acdc8e2007-12-26 11:11:45 +0000185fi
subrata_modak13782052008-02-22 14:43:53 +0000186pushd $TESTS_DIR >/dev/null
187
Anders Roxell45929dc2013-08-05 21:02:58 +0200188# 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
subrata_modak13782052008-02-22 14:43:53 +0000198
199ISLOOP=0
200index=0
Garrett Cooperead440f2010-11-01 23:58:28 -0700201while getopts "hl:p:t:" option
subrata_modak6acdc8e2007-12-26 11:11:45 +0000202do
subrata_modak1ffddf02008-05-22 12:03:14 +0000203 case "$option" in
204
subrata_modak13782052008-02-22 14:43:53 +0000205 t )
subrata_modak1ffddf02008-05-22 12:03:14 +0000206 if [ $ISLOOP -eq 1 ]; then
207 LOOP=1
208 tests[$index]=$LOOP
Garrett Cooperead440f2010-11-01 23:58:28 -0700209 : $(( index += 1 ))
subrata_modak1ffddf02008-05-22 12:03:14 +0000210 fi
211
212 tests[$index]="$OPTARG"
Garrett Cooperead440f2010-11-01 23:58:28 -0700213 : $((index += 1 ))
subrata_modak1ffddf02008-05-22 12:03:14 +0000214 TESTCASE="$OPTARG"
Chris Dearman37550cf2012-10-17 19:54:01 -0700215 ISLOOP=1
subrata_modak1ffddf02008-05-22 12:03:14 +0000216 ;;
217
Chris Dearman37550cf2012-10-17 19:54:01 -0700218 l )
subrata_modak1ffddf02008-05-22 12:03:14 +0000219 ISLOOP=0
220 tests[$index]="$OPTARG"
221 LOOP="$OPTARG"
222 index=$((index+1))
223 ;;
224 p )
225 profile=$OPTARG
226 ;;
subrata_modak13782052008-02-22 14:43:53 +0000227 h )
Chris Dearman37550cf2012-10-17 19:54:01 -0700228 usage
subrata_modak1ffddf02008-05-22 12:03:14 +0000229 ;;
subrata_modak13782052008-02-22 14:43:53 +0000230 * ) echo "Unrecognized option specified"
subrata_modak1ffddf02008-05-22 12:03:14 +0000231 usage
232 ;;
233 esac
subrata_modak6acdc8e2007-12-26 11:11:45 +0000234done
Garrett Cooperead440f2010-11-01 23:58:28 -0700235i=0
236while [ $i -lt $index ]; do
subrata_modak1ffddf02008-05-22 12:03:14 +0000237 find_test "$profile" ${tests[$i]} ${tests[$((i+1))]}
Garrett Cooperead440f2010-11-01 23:58:28 -0700238 : $(( i += 2 ))
subrata_modak6acdc8e2007-12-26 11:11:45 +0000239done