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

4.104.114.84.9
Last change on this file since bd8dd9e was bd8dd9e, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 17, 2007 at 5:37:29 PM

2007-04-17 Joel Sherrill <joel@…>

  • c4xsim/tools/runtest.in: Do not run pppd.exe from batch mode script.
  • 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       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*|spfatal*|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/
251//' -e '/^$/d' < ${logfile}.tmp |
252             while read line
253              do
254                if [ $output_it -eq 1 ] ; then
255                   case $line in
256                       END_OF_TEST*)
257                       output_it=0
258                       ;;
259                      *simio.c:86*)
260                        output_it=0
261                        clean_exit=1
262                        ;;
263                      *)
264                        echo "$line"
265                        ;;
266                     esac
267                 else
268                   if [ "$line" = "START_OF_TEST" ] ; then
269                     output_it=1
270                   fi
271                 fi
272               done > ${logfile}_1
273               if [ ${clean_exit} -eq 0 ] ; then
274                 mv ${logfile}_1 ${logfile}_1.XXX
275                 sed -e '/^Program received signal SIGTRAP/d' \
276                    <${logfile}_1.XXX >${logfile}_1
277                 rm -f ${logfile}_1.XXX
278               fi
279           ;;
280   esac
281
282   # Create the info files
283   for cpu in $cpus
284   do
285   {
286       echo "$date"
287       echo "Test run on: `uname -n`    ( `uname -a` )"
288
289       output_it=1
290       sed -e 's/
291//' < ${logfile}.tmp |
292         while read line
293         do
294           if [ $output_it -eq 0 ] ; then
295              if [ "$line" = "END_OF_TEST" ] ; then
296                output_it=1
297              fi
298            else
299              if [ "$line" = "START_OF_TEST" ] ; then
300                output_it=0
301              else
302                echo "$line"
303              fi
304            fi
305          done
306
307
308       if [ "$ran_too_long" = "yes" ]
309       then
310           echo "Test did NOT finish normally; killed after $max_run_time seconds"
311       fi
312
313       echo
314       date;
315   } > ${infofile}_$cpu
316   done
317
318   rm -f ${logfile}.tmp*
319
320   if [ "$cpus" = "1" ]
321   then
322        mv ${infofile}_1 ${infofile}
323        mv ${logfile}_1  ${logfile}
324   fi
325
326done
327
328test_exit 0
329
330# Local Variables: ***
331# mode:ksh ***
332# End: ***
333
Note: See TracBrowser for help on using the repository browser.