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