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