source: rtems/c/src/lib/libbsp/c4x/c4xsim/tools/runtest.in @ 3c769d9

4.104.114.95
Last change on this file since 3c769d9 was 3c769d9, checked in by Joel Sherrill <joel.sherrill@…>, on 03/11/08 at 20:17:23

2008-03-11 Joel Sherrill <joel.sherrill@…>

  • runtest.in: Skip all fatal error tests.
  • Property mode set to 100644
File size: 7.1 KB
Line 
1#!@KSH@ -p
2#
3#  $Id$
4#
5# Run rtems tests on the c4x simulator built into gdb
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=$((6 * 60))  # is 5 on other simulators.
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       capture* | 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           fatal "MP tests not supported"
147           warn "Running both nodes associated with $tname"
148           tname=`echo $tname | sed 's/-node.*//'`
149           TEST_TYPE="mp"
150           ;;
151       stackchk*|*fatal*|malloctest*|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 "target sim -3"
185               echo "sim m r 0"
186               echo "sim m w 0"
187               echo "load"
188               echo ""
189               echo "printf \"START_OF_TEST\\n\""
190               echo "run"
191               echo "printf \"END_OF_TEST\\n\""
192               echo "quit"
193               ;;
194       esac
195
196   } > ${scriptfile}
197
198   if [ "$script_and_exit" = "yes" ]
199   then
200        mv ${scriptfile} $tname.ss
201        warn "script left in $tname.ss"
202        test_exit 0
203   fi
204
205   # Spin off the simulator in the background
206   c4x-rtems-gdb $extra_options -n \
207        --command ${scriptfile} ${tfile} >${logfile}.tmp 2>&1 &
208   sim_pid=$!
209
210   # Make sure it won't run forever...
211   {
212       time_run=0
213       while [ $time_run -lt $max_run_time ]
214       do
215           # sleep 10s at a time waiting for job to finish or timer to expire
216           # if job has exited, then we exit, too.
217           sleep 10
218           if kill -0 $sim_pid 2>/dev/null
219           then
220                time_run=$((time_run + 10))
221           else
222                exit 0
223           fi
224       done
225
226       kill -2 $sim_pid 2>/dev/null
227       { sleep 5; kill -9 $sim_pid 2>/dev/null; } &
228   } &
229
230   wait $sim_pid
231   status=$?
232   if [ $status -ne 0 ]
233   then
234       ran_too_long="yes"
235   else
236       ran_too_long="no"
237   fi
238
239   sim_pid=""
240
241   # fix up the printf output from the test
242   case $TEST_TYPE in
243       mp)
244           fatal "MP not supported"
245           ;;
246       *)
247           output_it=0
248           clean_exit=0
249           sed -e '1,9d' \
250               -e 's/ //' -e '/^$/d' < ${logfile}.tmp |
251             while read line
252              do
253                if [ $output_it -eq 1 ] ; then
254                   case $line in
255                       END_OF_TEST*)
256                       output_it=0
257                       ;;
258                      *simio.c:86*)
259                        output_it=0
260                        clean_exit=1
261                        ;;
262                      *)
263                        echo "$line"
264                        ;;
265                     esac
266                 else
267                   if [ "$line" = "START_OF_TEST" ] ; then
268                     output_it=1
269                   fi
270                 fi
271               done > ${logfile}_1
272               if [ ${clean_exit} -eq 0 ] ; then
273                 mv ${logfile}_1 ${logfile}_1.XXX
274                 sed -e '/^Program received signal SIGTRAP/d' \
275                    <${logfile}_1.XXX >${logfile}_1
276                 rm -f ${logfile}_1.XXX
277               fi
278           ;;
279   esac
280
281   # Create the info files
282   for cpu in $cpus
283   do
284   {
285       echo "$date"
286       echo "Test run on: `uname -n`    ( `uname -a` )"
287
288       output_it=1
289       sed -e 's/ //' < ${logfile}.tmp |
290         while read line
291         do
292           if [ $output_it -eq 0 ] ; then
293              if [ "$line" = "END_OF_TEST" ] ; then
294                output_it=1
295              fi
296            else
297              if [ "$line" = "START_OF_TEST" ] ; then
298                output_it=0
299              else
300                echo "$line"
301              fi
302            fi
303          done
304
305
306       if [ "$ran_too_long" = "yes" ]
307       then
308           echo "Test did NOT finish normally; killed after $max_run_time seconds"
309       fi
310
311       echo
312       date;
313   } > ${infofile}_$cpu
314   done
315
316   rm -f ${logfile}.tmp*
317
318   if [ "$cpus" = "1" ]
319   then
320        mv ${infofile}_1 ${infofile}
321        mv ${logfile}_1  ${logfile}
322   fi
323
324done
325
326test_exit 0
327
328# Local Variables: ***
329# mode:ksh ***
330# End: ***
331
Note: See TracBrowser for help on using the repository browser.