source: rtems/c/src/lib/libbsp/mips/jmr3904/tools/runtest @ df393962

4.104.115
Last change on this file since df393962 was 84976d0, checked in by Joel Sherrill <joel.sherrill@…>, on 08/15/08 at 16:25:23

2008-08-15 Joel Sherrill <joel.sherrill@…>

  • runtest: Attempt to prevent runaways.
  • Property mode set to 100755
File size: 6.2 KB
Line 
1#!/bin/sh -p
2#
3# Run rtems tests on the powerpc simulator
4# This program generates a simulator script to run each test
5# Typically the test is then run, although it can be generated
6# and left as a file using -s
7#
8#  COPYRIGHT (c) 1989-1999.
9#  On-Line Applications Research Corporation (OAR).
10#
11#  The license and distribution terms for this file may be
12#  found in found in the file LICENSE in this distribution or at
13#  http://www.rtems.com/license/LICENSE.
14#
15#  $Id$
16#
17
18# progname=`basename $0`
19progname=${0##*/}        # fast basename hack for ksh, bash
20
21USAGE=\
22"usage: $progname [ -opts ] test [ test ... ]
23        -o options  -- specify options to be passed to simulator
24        -v          -- verbose
25        -d          -- generate device tree file (as 'test'.device) and exit
26        -l logdir   -- specify log directory (default is 'logdir')
27
28  Specify test as 'test' or 'test.exe'.
29  All multiprocessing tests *must* be specified simply as 'mp01', etc.
30"
31
32# export everything
33set -a
34
35#   log an error to stderr
36prerr()
37{
38    echo "$*" >&2
39}
40
41fatal() {
42    [ "$1" ] && prerr $*
43    prerr "$USAGE"
44    exit 1
45}
46
47warn() {
48    [ "$1" ] && prerr $*
49}
50
51# print args, 1 per line
52ml_echo()
53{
54    for l
55    do
56       echo "$l"
57    done
58}
59
60# run at normal and signalled exit
61test_exit()
62{
63    exit_code=$1
64
65    rm -f ${logfile}.tmp*
66    [ "$sim_pid" ] && kill -9 $sim_pid
67
68    exit $exit_code
69}
70
71#
72# process the options
73#
74# defaults for getopt vars
75#
76# max_run_time is defaulted to 5 minutes
77#
78
79verbose=""
80extra_options=""
81device_and_exit=""
82stdio_setup="yes"
83run_to_completion="yes"
84logdir=log
85update_on_tick="no"
86max_run_time=$((5 * 60))
87using_print_buffer="yes"
88simulator=mipstx39-rtems4.9-run
89
90while getopts vdl:o:s: OPT
91do
92    case "$OPT" in
93        v)
94            verbose="yes";;
95        d)
96            device_and_exit="yes"
97            run_to_completion="no"
98            stdio_setup="no";;
99        l)
100            logdir="$OPTARG";;
101        o)
102            extra_options="$OPTARG";;
103        s)
104            simulator="$OPTARG";;
105        *)
106            fatal;;
107    esac
108done
109
110let $((shiftcount = $OPTIND - 1))
111shift $shiftcount
112
113args=$*
114
115#
116#  Check some parameters
117#
118
119# JRS CHANGE
120# if [ ! -x ${simulator} ] ; then
121#    fatal "${simulator} is not executable"
122# fi;
123
124#
125# Run the tests
126#
127
128tests="$args"
129if [ ! "$tests" ]
130then
131     set -- `ls -1 *.exe *.ralf 2>/dev/null`
132     tests="$*"
133fi
134
135[ -d $logdir ] ||
136  mkdir $logdir || fatal "could not create log directory ($logdir)"
137
138# where the tmp files go
139trap "test_exit" 1 2 3 13 14 15
140
141for tfile in $tests
142do
143
144   tname=`basename $tfile .exe`
145   tname=`basename $tname .ralf`
146   cpus="1"
147   TEST_TYPE="single"
148
149   case $tname in
150       # size is no longer interactive.
151       capture* | monitor* | termios* | fileio* | pppd*)
152            if [ $run_to_completion = "yes" ]
153            then
154                 warn "Skipping $tname; it is interactive"
155                 continue
156            fi
157            ;;
158       *-node2*)
159           warn "Skipping $tname; 'runtest' runs both nodes when for *-node1"
160           continue;;
161       *-node1*)
162           warn "Running both nodes associated with $tname"
163           variant=`echo $tname | sed 's/.*-node[12]//' | sed 's/\.exe//'`
164           tname=`echo $tname | sed 's/-node.*//'`
165           TEST_TYPE="mp"
166           ;;
167       minimum*|stackchk*|*fatal*|termio*)
168           continue
169           ;;
170   esac
171
172   if [ $TEST_TYPE = "mp" ]
173   then
174       cpus="1 2"
175
176       logfile1=$logdir/${tname}_1${variant}
177       logfile2=$logdir/${tname}_2${variant}
178       infofile1=$logfile1.info
179       infofile2=$logfile2.info
180
181       rm -f ${logfile1} ${logfile2}
182
183       date=`date`
184       echo "Starting $tname at $date"
185
186       ${simulator} --board=jmr3904 ${tname}-node1${variant}.exe | \
187         sed -e 's/ //' -e '/^$/d' > ${logfile1} &
188
189       ${simulator} --board=jmr3904 ${tname}-node2${variant}.exe | \
190         sed -e 's/ //' -e '/^$/d' > ${logfile2} &
191
192       wait
193
194   fi
195
196   if [ $TEST_TYPE = "single" ]
197   then
198     logfile=$logdir/${tname}_1
199     infofile=$logfile.info
200
201     rm -f ${logfile}.tmp*
202
203     date=`date`
204     echo "Starting $tname at $date"
205
206     # Generate a device file to get the work done.
207     # The device file must do the following:
208     #
209     #       arrange for more memory (2 Mb)
210
211     if [ "$device_and_exit" = "yes" ]
212     then
213          fatal "Cannot currently generate device files"
214     fi
215
216     # Spin off the simulator in the background
217
218     ${simulator} --board=jmr3904 $tfile </dev/null | \
219       sed -e 's/ //' -e '/^$/d' > ${logfile} 2>&1 &
220     pid=$!
221
222     # Make sure it won't run forever...
223     millilimit=`expr ${max_run_time} \* 1000`
224     milliseconds=0
225     while :
226     do
227       # sleep 10ms at a time waiting for job to finish or timer to expire
228       # if job has exited, then we exit, too.
229       usleep 10000  # ten milliseconds
230       milliseconds=`expr ${milliseconds} + 10`
231       kill -0 $pid 2> /dev/null
232       running=$?
233       if [ $running -eq 0 ] ; then
234         if [ ${milliseconds} -ge ${millilimit} ]; then
235           kill -9 $pid 2> /dev/null
236           #cat ${logfile}
237           echo "${tname} killed after running ${max_run_time} seconds"
238           break
239         fi
240         grep "^Unhandled exception" ${logfile} >/dev/null
241         exceptionExit=$?
242         grep "^mips-core: " ${logfile} >/dev/null
243         badAccessExit=$?
244         if [ $badAccessExit -eq 0 -o $exceptionExit -eq 0 ] ; then
245           kill -9 ${pid} >/dev/null 2>&1
246           #cat ${logfile}
247           # echo Ran in ${milliseconds} milliseconds
248         fi
249
250       else
251         # done normally
252         # cat ${logfile}
253         # echo "${tname} ran in ${milliseconds} milliseconds"
254         break
255       fi
256     done
257   fi
258
259   # Create the info files
260   for cpu in $cpus
261   do
262   {
263       echo "$date"
264       echo "Test run on: `uname -n`"
265       echo "Host Information:"
266       echo `uname -a`
267       echo
268
269       #sed -e 's/ //' < ${logdir}/${tname}_${cpu}
270       cat ${logdir}/${tname}_${cpu}
271
272       if [ "$ran_too_long" = "yes" ]
273       then
274           echo "Test did NOT finish normally; killed after $max_run_time seconds"
275       fi
276
277       echo
278       date;
279   } > ${logdir}/${tname}_${cpu}.info
280   done
281
282   if [ "$cpus" = "1" ]
283   then
284        mv ${infofile} $logdir/${tname}.info
285        mv ${logfile}  $logdir/${tname}
286   fi
287
288done
289
290echo "Tests completed at " `date`
291test_exit 0
292
293# Local Variables: ***
294# mode:ksh ***
295# End: ***
296
Note: See TracBrowser for help on using the repository browser.