1#!/bin/sh
2
3# Copyright (c) 2005, Wipro Technologies Ltd. All rights reserved.
4# Created by:  Dr. B. Thangaraju <balat.raju@wipro.com>
5#              Prashant P Yendigeri <prashant.yendigeri@wipro.com>
6# This file is licensed under the GPL license.  For the full content
7# of this license, see the COPYING file at the top level of this
8# source tree.
9#
10# This execute.sh script executes executables and format the results
11# including time statistics like time taken to execute OPTS.
12# This script doesn't use 'make' or 'gcc'. This script will be useful
13# to run test cases on embedded target.
14
15
16# Run all the tests in the conformance area.
17
18# Function to calculate starting time
19start_func()
20{
21      START_DATE=`date`
22      START_HOUR=`date +%H`
23      START_MIN=`date +%M`
24      START_SEC=`date +%S`
25
26      if [ $START_HOUR -eq 0 ]
27      then
28            TOTAL_START_HOUR=0
29
30      else
31            TOTAL_START_HOUR=`expr $START_HOUR '*' 3600`
32      fi
33
34      if [ $START_MIN -eq 0 ]
35      then
36            TOTAL_START_MIN=0
37      else
38            TOTAL_START_MIN=`expr $START_MIN '*' 60`
39      fi
40
41      TOTAL_START_TEMP=`expr $TOTAL_START_HOUR + $TOTAL_START_MIN`
42
43      TOTAL_START_SECS=`expr $TOTAL_START_TEMP + $START_SEC`
44}
45
46
47end_func_noday_change()
48{
49
50 END_DATE=`date`
51 END_HOUR=`date +%H`
52 END_MIN=`date +%M`
53 END_SEC=`date +%S`
54
55 TOTAL_END_HOUR=`expr $END_HOUR '*' 3600`
56 TOTAL_END_MIN=`expr $END_MIN '*' 60`
57 TOTAL_END_TEMP=`expr $TOTAL_END_HOUR + $TOTAL_END_MIN`
58
59 TOTAL_END_SECS=`expr $TOTAL_END_TEMP + $END_SEC`
60 TOTAL_TIME=`expr $TOTAL_END_SECS - $TOTAL_START_SECS`
61
62 TOTAL_HR=`expr $TOTAL_TIME / 3600`
63 TOTAL_MIN=`expr $TOTAL_TIME / 60`
64 TOTAL_SEC=$TOTAL_TIME
65
66 if [ $TOTAL_SEC -gt 60 ]
67 then
68        TOTAL_SEC=`expr $TOTAL_SEC % 60`
69 fi
70
71 if [ $TOTAL_MIN -gt 60 ]
72 then
73        TOTAL_MIN=`expr $TOTAL_MIN % 60`
74 fi
75
76 if [ $TOTAL_HR -gt 60 ]
77 then
78        TOTAL_HR=`expr $TOTAL_HR % 60`
79 fi
80
81}
82
83# Function to calculate end time
84end_func()
85{
86
87 END_DATE=`date`
88 END_HOUR=`date +%H`
89 END_MIN=`date +%M`
90 END_SEC=`date +%S`
91
92
93if [ $END_HOUR -eq 0 ]
94then
95      TOTAL_END_HOUR=0
96else
97      TOTAL_END_HOUR=`expr $END_HOUR '*' 3600`
98fi
99
100
101if [ $END_MIN -eq 0 ]
102then
103      TOTAL_END_MIN=0
104else
105      TOTAL_END_MIN=`expr $END_MIN '*' 60`
106fi
107
108
109 TOTAL_END_TEMP=`expr $TOTAL_END_HOUR + $TOTAL_END_MIN`
110
111 TOTAL_END_SECS=`expr $TOTAL_END_TEMP + $END_SEC`
112 TOTAL_START_SECS=`expr 86400 - $TOTAL_START_SECS`
113
114 TOTAL_TIME=`expr $TOTAL_END_SECS + $TOTAL_START_SECS`
115
116 TOTAL_HR=`expr $TOTAL_TIME / 3600`
117
118 TOTAL_MIN=`expr $TOTAL_TIME / 60`
119 TOTAL_SEC=$TOTAL_TIME
120
121 if [ $TOTAL_SEC -gt 60 ]
122 then
123      TOTAL_SEC=`expr $TOTAL_SEC % 60`
124 fi
125
126 if [ $TOTAL_MIN -gt 60 ]
127 then
128      TOTAL_MIN=`expr $TOTAL_MIN % 60`
129 fi
130
131 if [ $TOTAL_HR -gt 60 ]
132 then
133      TOTAL_HR=`expr $TOTAL_HR % 60`
134 fi
135}
136
137# Function to display the Execution Time Statistics
138display_func()
139{
140            echo -ne "\n\n\n\n\t\t*******************************************\n"
141            echo -ne "\t\t*         EXECUTION TIME STATISTICS       *\n"
142            echo -ne "\t\t*******************************************\n"
143            echo -ne "\t\t* START    : $START_DATE *\n"
144            echo -ne "\t\t* END      : $END_DATE *\n"
145            echo -ne "\t\t* DURATION :                              *\n"
146    echo -ne "\t\t*            $TOTAL_HR hours                      *\n"
147    echo -ne "\t\t*            $TOTAL_MIN minutes                    *\n"
148    echo -ne "\t\t*            $TOTAL_SEC seconds                    *\n"
149    echo -ne "\t\t*******************************************\n"
150
151}
152
153
154# Variables for formatting the OPTS results
155declare -i TOTAL=0
156declare -i PASS=0
157declare -i FAIL=0
158declare -i UNRES=0
159declare -i UNSUP=0
160declare -i UNTEST=0
161declare -i INTR=0
162declare -i HUNG=0
163declare -i SEGV=0
164declare -i OTH=0
165
166# Maximum Two minutes waiting time period to execute a test. If it exceeds, the test case will go into the 'HUNG' category.
167TIMEOUT_VAL=120
168
169# if gcc available then remove the below line comment else put the t0 in posixtestsuite directory.
170#gcc -o t0 t0.c
171./t0 0 > /dev/null 2>&1
172TIMEVAL_RET=$?
173
174# Find executable files from the conformance directory
175# If you want to execute any specific test cases, you should modify here.
176
177FINDFILESsh=`find ./conformance/ -name '*-*.sh' -print`
178FINDFILES=`find ./conformance/ -name '*-*.test' -print | grep -v core`
179
180NEWSTR=`echo $FINDFILES $FINDFILESsh`
181
182
183# Main program
184
185start_func
186PM_TO_AM=`date +%P`
187if [ $PM_TO_AM  = "pm" ]
188then
189      COUNT=1
190fi
191echo "Run the conformance tests"
192echo "=========================================="
193
194count=1
195while $TRUE
196do
197      FILE=`echo $NEWSTR | cut -f$count -d" "`
198        if [ -z $FILE ]
199      then
200
201PM_TO_AM=`date +%P`
202if [ $PM_TO_AM = "am" ]
203then
204      COUNT=`expr $COUNT + 1`
205fi
206
207if [ $COUNT -eq 2 ]
208then
209      end_func
210else
211      end_func_noday_change
212fi
213            echo
214            echo -ne "\t\t***************************\n"
215            echo -ne "\t\t CONFORMANCE TEST RESULTS\n"
216            echo -ne "\t\t***************************\n"
217            echo -ne "\t\t* TOTAL:  " $TOTAL "\n"
218            echo -ne "\t\t* PASSED: " $PASS "\n"
219            echo -ne "\t\t* FAILED: " $FAIL "\n"
220            echo -ne "\t\t* UNRESOLVED: " $UNRES "\n"
221            echo -ne "\t\t* UNSUPPORTED: " $UNSUP "\n"
222            echo -ne "\t\t* UNTESTED: " $UNTEST "\n"
223            echo -ne "\t\t* INTERRUPTED: " $INTR "\n"
224            echo -ne "\t\t* HUNG: " $HUNG "\n"
225            echo -ne "\t\t* SEGV: " $SEGV "\n"
226            echo -ne "\t\t* OTHERS: " $OTH "\n"
227      echo -ne "\t\t***************************\n"
228            display_func
229                  echo "Finished"
230            exit
231
232      elif [ -x $FILE ]
233            then
234            FILEcut=`echo $FILE | cut -b3-80`
235            TOTAL=$TOTAL+1
236            ./t0 $TIMEOUT_VAL $FILE > /dev/null 2>&1
237
238            RET_VAL=$?
239
240      if [ $RET_VAL -gt 5  -a  $RET_VAL -ne $TIMEVAL_RET ]
241      then
242            INTR_VAL=10
243      fi
244
245      case $RET_VAL in
246
247      0)
248                  PASS=$PASS+1
249            echo  "$FILEcut:execution:PASS "
250            ;;
251      1)
252                  FAIL=$FAIL+1
253            echo  "$FILEcut:execution:FAIL "
254            ;;
255
256
257      255)
258                  FAIL=$FAIL+1
259            echo  "$FILEcut:execution:FAIL "
260            ;;
261
262
263      2)
264            UNRES=$UNRES+1
265            echo  "$FILEcut:execution:UNRESOLVED "
266            ;;
267
268      3)
269            ;;
270
271      4)
272            UNSUP=$UNSUP+1
273            echo  "$FILEcut:execution:UNSUPPORTED "
274            ;;
275
276      5)
277            UNTEST=$UNTEST+1
278            echo  "$FILEcut:execution:UNTESTED "
279            ;;
280
281      10)
282            INTR=$INTR+1
283            echo  "$FILEcut:execution:INTERRUPTED "
284            ;;
285
286      $TIMEVAL_RET)
287                  HUNG=$HUNG+1
288                  echo  "$FILEcut:execution:HUNG "
289                  ;;
290      139)
291            SEGV=$SEGV+1
292            echo "$FILEcut:execution:Segmentaion Fault "
293            ;;
294
295      *)
296            OTH=$OTH+1
297            echo "OTHERS: RET_VAL for $FILE : $RET_VAL"
298            ;;
299      esac
300      fi
301      count=`expr $count + 1`
302done
303
304
305######################################################################################
306
307
308
309