source: rtems/c/src/lib/libbsp/sparc/leon2/tools/runtest.in @ 13602a5

4.104.114.84.9
Last change on this file since 13602a5 was 13602a5, checked in by Joel Sherrill <joel.sherrill@…>, on May 11, 2007 at 9:03:48 PM

2007-05-11 Joel Sherrill <joel.sherrill@…>

  • runtest.in: Now works with tsim.
  • Property mode set to 100644
File size: 6.4 KB
Line 
1#!@KSH@ -p
2#
3#  $Id$
4#
5# Run rtems tests on the hppa simulator
6# This program generates a simulator script to run each test
7# Typically the test is then run, although it can be generated
8# and left as a file using -s
9#
10
11# progname=`basename $0`
12progname=${0##*/}        # fast basename hack for ksh, bash
13
14USAGE=\
15"usage: $progname [ -opts ] test [ test ... ]
16        -o options  -- specify options to be passed to simulator
17        -v          -- verbose
18        -s          -- generate script file (as 'test'.ss) and exit
19        -l logdir   -- specify log directory (default is 'logdir')
20
21  Specify test as 'test' or 'test.exe'.
22  All multiprocessing tests *must* be specified simply as 'mp01', etc.
23"
24
25# export everything
26set -a
27
28#   log an error to stderr
29prerr()
30{
31    echo "$*" >&2
32}
33
34fatal() {
35    [ "$1" ] && prerr $*
36    prerr "$USAGE"
37    exit 1
38}
39
40warn() {
41    [ "$1" ] && prerr $*
42}
43
44# print args, 1 per line
45ml_echo()
46{
47    for l
48    do
49       echo "$l"
50    done
51}
52
53# run at normal and signalled exit
54test_exit()
55{
56    exit_code=$1
57
58    rm -f ${statfile}* ${scriptfile}* ${logfile}.tmp*
59    [ "$sim_pid" ] && kill -9 $sim_pid
60
61    exit $exit_code
62}
63
64#
65# process the options
66#
67# defaults for getopt vars
68#
69# max_run_time is defaulted to 5 minutes
70#
71
72verbose=""
73extra_options=""
74script_and_exit=""
75stdio_setup="yes"
76run_to_completion="yes"
77logdir=log
78update_on_tick="no"
79max_run_time=$((5 * 60))
80using_print_buffer="yes"
81
82while getopts vhr12o:c:sl:t OPT
83do
84    case "$OPT" in
85        v)
86            verbose="yes";;
87        s)
88            script_and_exit="yes"
89            run_to_completion="no"
90            stdio_setup="no";;
91        l)
92            logdir="$OPTARG";;
93        o)
94            extra_options="$OPTARG";;
95        *)
96            fatal;;
97    esac
98done
99
100let $((shiftcount = $OPTIND - 1))
101shift $shiftcount
102
103args=$*
104
105#
106# Run the tests
107#
108
109tests="$args"
110if [ ! "$tests" ]
111then
112     set -- `echo *.exe`
113     tests="$*"
114fi
115
116[ -d $logdir ] ||
117  mkdir $logdir || fatal "could not create log directory ($logdir)"
118
119cpus=1
120
121# where the tmp files go
122statfile=/tmp/stats$$
123scriptfile=/tmp/script$$
124
125trap "test_exit" 1 2 3 13 14 15
126
127for tfile in $tests
128do
129
130   tname=`basename $tfile .exe`
131   TEST_TYPE="single"
132
133   case $tname in
134       monitor* | termios* | fileio* | pppd*)
135           if [ $run_to_completion = "yes" ]
136           then
137                warn "Skipping $tname; it is interactive"
138                continue
139           fi
140           ;;
141       *-node2*)
142           fatal "MP tests not supported"
143           warn "Skipping $tname; 'runtest' runs both nodes when for *-node1"
144           continue;;
145      *-node1*)
146           warn "Running both nodes associated with $tname"
147           variant=`echo $tname | sed 's/.*-node[12]//' | sed 's/\.exe//'`
148           tname=`echo $tname | sed 's/-node.*//'`
149           TEST_TYPE="mp"
150           ;;
151       minimum*|stackchk*|spfatal*|termio*)
152           warn "Skipping $tname; it locks up or takes a VERY long time to run"
153           continue
154           ;;
155   esac
156
157   # Change the title bar to indicate which test we are running
158   # The simulator screen doesn't provide any indication
159
160   logfile=$logdir/$tname
161   infofile=$logfile.info
162
163   rm -f ${statfile}* ${scriptfile}* ${logfile}.tmp*
164
165   date=`date`
166   echo "Starting $tname at $date"
167
168   # Generate a script file to get the work done.
169   # The script file must do the following:
170   #
171   #       load the program (programs if MP test)
172   #       arrange for capture of output
173   #       run the program
174   #       produce statistics
175
176   {
177       case $TEST_TYPE in
178           "mp")
179               fatal "MP tests not supported"
180               ;;
181
182           # All other tests (single-processor)
183           *)
184               echo "load $tfile"
185               echo "go 0x40000000"
186               echo ""
187               echo "perf"
188               echo "quit"
189               ;;
190       esac
191
192   } > ${scriptfile}
193
194   if [ "$script_and_exit" = "yes" ]
195   then
196        mv ${scriptfile} $tname.ss
197        warn "script left in $tname.ss"
198        test_exit 0
199   fi
200
201   # Spin off the simulator in the background
202   tsim-leon $extra_options -c ${scriptfile} >${logfile}.tmp &
203   sim_pid=$!
204
205   # Make sure it won't run forever...
206   {
207       time_run=0
208       while [ $time_run -lt $max_run_time ]
209       do
210           # sleep 10s at a time waiting for job to finish or timer to expire
211           # if job has exited, then we exit, too.
212           sleep 10
213           if kill -0 $sim_pid 2>/dev/null
214           then
215                time_run=$((time_run + 10))
216           else
217                exit 0
218           fi
219       done
220
221       kill -2 $sim_pid 2>/dev/null
222       { sleep 5; kill -9 $sim_pid 2>/dev/null; } &
223   } &
224
225   wait $sim_pid
226   status=$?
227   if [ $status -ne 0 ]
228   then
229       ran_too_long="yes"
230   else
231       ran_too_long="no"
232   fi
233
234   sim_pid=""
235
236   # fix up the printf output from the test
237   case $TEST_TYPE in
238       mp)
239           fatal "MP not supported"
240           ;;
241       *)
242           output_it=1
243           sed -e '1,19d' \
244               -e 's/
245//' -e '/^$/d' < ${logfile}.tmp |
246             while read line
247              do
248                if [ $output_it -eq 1 ] ; then
249                   if [ "$line" = "tsim> perf" ] ; then
250                     output_it=0
251                   elif [ "$line" = "tsim> quit" ] ; then
252                     output_it=0
253                   elif [ "$line" = "tsim>" ] ; then
254                     output_it=0
255                   else
256                     echo "$line"
257                   fi   
258                 fi 
259               done > ${logfile}_1
260           ;;
261   esac
262
263   # Create the info files
264   for cpu in $cpus
265   do
266   {
267       echo "$date"
268       echo "Test run on: `uname -n`    ( `uname -a` )"
269
270       output_it=0
271       sed -e 's/
272//' < ${logfile}.tmp |
273         while read line
274         do
275           if [ $output_it -eq 1 ] ; then
276              if [ "$line" = "tsim> quit" ] ; then
277                output_it=0
278              else
279                echo "$line"
280              fi
281            else
282              if [ "$line" = "tsim> perf" ] ; then
283                output_it=1
284              fi
285            fi
286          done
287
288
289       if [ "$ran_too_long" = "yes" ]
290       then
291           echo "Test did NOT finish normally; killed after $max_run_time seconds"
292       fi
293
294       echo
295       date;
296   } > ${infofile}_$cpu
297   done
298
299   rm -f ${logfile}.tmp*
300
301   if [ "$cpus" = "1" ]
302   then
303        mv ${infofile}_1 ${infofile}
304        mv ${logfile}_1  ${logfile}
305   fi
306
307done
308
309test_exit 0
310
311# Local Variables: ***
312# mode:ksh ***
313# End: ***
314
Note: See TracBrowser for help on using the repository browser.