source: rtems-testing/sim-scripts/gdb-sim-run.in @ e6cc2b7

4.11
Last change on this file since e6cc2b7 was e6cc2b7, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 12, 2009 at 5:32:29 PM

2009-08-12 Josh Switnicki <josh.switnicki@…>

  • .cvsignore, Makefile, gdb-sim-run.in: Add support for avrtest BSP using simulavrxx.
  • avrtest.in: New file.
  • Property mode set to 100755
File size: 8.8 KB
Line 
1#! /bin/sh
2#
3#  Framework script tailored for the @CPU@/@BSP@
4#
5#  NOTE: If the does not have the name of a specific CPU/BSP pair, then
6#        this is the source file.  If it does have specific CPU/BSP pair,
7#        then this is generated output and should NOT be edited.
8
9#  $Id$
10#
11
12trap "test_exit 1" 1 2 3 13 14 15
13
14test_exit()
15{
16  exit_code=$1
17  exit $exit_code
18}
19
20
21progname=${0##*/}        # fast basename hack for ksh, bash
22
23USAGE=\
24"usage: $progname [ -opts ] test [ test ... ]
25        -v         -- verbose
26        -c         -- enabled coverage (default=no)
27        -C         -- cat test output if not interactive (default=no)
28        -g         -- generate device tree and exit (default=no)
29        -i         -- interactive (default=no time limit)
30        -s         -- force System V IPC support (default=no)
31        -l limit   -- specify time limit (default is 'BSP dependent')
32        -L dir     -- specify log directory (default is 'log')
33
34System V IPC and Coverage are not supported by all BSPs or simulators.
35
36When you generate a device tree and exit, remember to specify an executable.
37Otherwise, the script won't know what to generate it for.
38"
39
40#   log an error to stderr
41prerr()
42{
43    echo "$*" >&2
44}
45
46fatal() {
47    [ "$1" ] && prerr $*
48    prerr "$USAGE"
49    exit 1
50}
51
52warn() {
53    [ "$1" ] && prerr $*
54}
55
56check_status()
57{
58  if [ $1 -ne 0 ] ; then
59    shift
60    echo "FAILED: " "$*" >&2
61    exit 1
62  fi
63}
64
65
66#
67# process the options
68#
69# defaults for getopt vars
70#
71
72doCatOutput="no"
73coverage="no"
74verbose="no"
75defaultLimit="not_set"
76interactive="no"
77use_sysv_ipc="no"
78generate_tree_and_exit="no"
79logdir="log"
80
81while getopts "vcCgil:L:s" OPT
82do
83 case "$OPT" in
84   v) verbose="yes";;
85   c) coverage="yes";;
86   C) doCatOutput="yes";;
87   g) generate_tree_and_exit="yes" ;;
88   i) interactive="yes";;
89   l) defaultLimit="$OPTARG";;
90   L) loggir="$OPTARG";;
91   s) use_sysv_ipc="yes";;
92   *) fatal;;
93 esac
94done
95
96shiftcount=`expr $OPTIND - 1`
97shift $shiftcount
98
99args=$*
100
101if [ ${interactive} = "yes" ] ; then
102  defaultLimit=0
103else
104  if [ ! -d ${logdir} ] ; then
105    mkdir $logdir || fatal "could not create log directory ($logdir)"
106  fi
107fi
108
109### Set BSP defaults.  If BSP does not have default, it will override
110if [ ${coverage} = "yes" ] ; then
111  bspRunFatal="yes"
112else
113  bspRunFatal="no"
114fi
115bspGeneratesDeviceTree="no"
116bspSupportsSystemVIPC="no"
117bspUsesGDBSimulator="yes"
118bspNeedsDos2Unix="no"
119bspSimTrustedToExit="no"
120
121for v in 4.10 4.9 4.8 4.7 ""
122do
123  type @CPU_TARGET@-rtems${v}-run >/dev/null 2>&1
124  if [ $? -eq 0 ] ; then
125    defaultRUN=@CPU_TARGET@-rtems${v}-run
126    break
127  fi
128done
129
130test ${verbose} = "yes" && echo Default program to run is ${defaultRUN}
131runBSP=${defaultRUN}
132
133###################################################################
134###################################################################
135###################################################################
136##INSERT BSP SUPPORT HERE
137###################################################################
138###################################################################
139###################################################################
140
141if [ ${bspSupportsSystemVIPC} = "no" -a ${use_sysv_ipc} = "yes"  ]; then
142  echo "Simulator does not support System V IPC."
143  exit 1
144fi
145
146if [ X${runBSP} = X ] ; then
147  echo "Unable to find a way to run @CPU_TARGET@/@BSP@"
148  exit 1
149fi
150
151test ${verbose} = "yes" && echo Using ${runBSP}
152
153type ${runBSP}
154check_status $? "Path appears to be broken (cannot find ${runBSP})"
155
156killpid()
157{
158  pid=$1
159  kill -2 $pid 2> /dev/null
160  if [ ${coverage} = "yes" ] ; then
161    sleep 1
162  else
163    usleep 1000
164  fi
165  kill -9 $pid 2> /dev/null
166}
167
168## These are faults any BSP may generate.  They are common to RTEMS.
169checkGenericExits()
170{
171  logfile=$1
172
173  ## Clean exit patterns -- delay for coverage to get written
174  for pattern in  \
175      "^\*\*\* END OF " \
176      "^.*EXECUTIVE SHUTDOWN" \
177      "===.*FAILED.*===" \
178      "===.*PASSED.*===" \
179      "FAULTY THREAD WILL BE DELETED"
180  do
181    grep "${pattern}" ${logfile} >/dev/null 2>&1
182    if [ $? -eq 0 ] ; then
183      if [ ${coverage} = "yes" ] ; then
184        # give the simulator a chance to write the coverage
185        # ASSUME: It will exit
186        # TODO:  Add timeout logic here
187        while :
188        do
189          kill -0 $pid 2> /dev/null
190          running=$?
191          if [ $running -eq 0 ] ; then
192            killpid ${pid}
193          else
194            return 1
195          fi
196        done
197      fi
198      return 1
199    fi
200  done
201
202  ## Error exit patterns -- should not happen on coverage runs
203  for pattern in  \
204     "Suspending faulting task" \
205     "assertion failed"
206  do
207    grep "${pattern}" ${logfile} >/dev/null 2>&1
208    if [ $? -eq 0 ] ; then
209      return 1
210    fi
211  done
212  return 0
213}
214
215catLog()
216{
217  logfile=${1}
218  if [ ${doCatOutput} = "no" ] ; then
219    return
220  fi
221
222  if [ ${bspNeedsDos2Unix} = "yes" ] ; then
223    dos2unix ${logfile}
224  fi
225
226  tr -d "\015" <${logfile}
227  echo
228}
229
230runtest()
231{
232  testname=${1}
233  testtype=${2}
234  max_run_time=${3}
235
236  test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${testname}`
237
238  if [ ${max_run_time} -eq 0 ] ; then
239    #echo run ${testname} forever
240    ${runBSP} `runARGS ${testname}`
241    return
242  fi
243
244  echo Running ${testname} for maximum ${max_run_time} seconds
245  echo $testname | grep "exe$" >/dev/null
246  if [ $? -eq 0 ] ; then
247    ext=.exe
248  else
249    ext=.ralf
250  fi
251  tfile=`basename $testname`
252  tname=`basename $tfile ${ext}`
253
254  logfile=${logdir}/${tname}
255
256  if [ ${bspSimTrustedToExit} = "yes" ] ; then
257    ${runBSP} `runARGS ${testname}` >${logfile} 2>&1
258    catLog ${logfile}
259    return
260  fi
261  ${runBSP} `runARGS ${testname}` >${logfile} 2>&1 &
262  pid=$!
263  # Make sure it won't run forever...
264  millilimit=`expr ${max_run_time} \* 1000`
265  milliseconds=0
266  while :
267  do
268    # sleep 10ms at a time waiting for job to finish or timer to expire
269    # if job has exited, then we exit, too.
270    usleep 25000  # twenty five milliseconds
271    milliseconds=`expr ${milliseconds} + 25`
272    kill -0 $pid 2> /dev/null
273    running=$?
274    if [ $running -eq 0 ] ; then
275      if [ ${milliseconds} -ge ${millilimit} ]; then
276        killpid ${pid}
277        catLog ${logfile}
278        echo "${testname} killed after running ${max_run_time} seconds"
279        break
280      fi
281      if [ ! -r ${logfile} ] ; then
282        continue
283      fi
284      # check for BSP specific messages which indicate program ended
285      checkBSPFaults ${logfile} >/dev/null 2>&1
286      bspFaults=$?
287      # check for cross platform messages which indicate program ended
288      checkGenericExits ${logfile} #>/dev/null 2>&1
289      genericExits=$?
290      if [ ${bspFaults} -ne 0 -o ${genericExits} -ne 0 ] ; then
291        killpid ${pid}
292        catLog ${logfile}
293        echo Ran in ${milliseconds} milliseconds
294      break
295      fi
296  else
297    # done normally
298    catLog ${logfile}
299    test ${verbose} = "yes" && \
300      echo "${testname} ran in ${milliseconds} milliseconds"
301    break
302  fi
303  done
304}
305
306if [ "X${args}" = "X" ] ; then
307  echo no tests to run
308  exit 1
309fi
310
311## Now run the tests
312test ${verbose} = "yes" && \
313  echo TESTS TO RUN: ${args}
314for toRun in $args
315do
316  baseToRun=`basename ${toRun}`
317  case ${baseToRun} in
318    *-node*) testtype="mp"     ;;
319    *fatal*) testtype="fatal"  ;;
320    *)       testtype="single" ;;
321  esac
322  # calculate the limit in case it is used by the simulator script
323  if [ ${defaultLimit} = "not_set" ] ; then
324    bspLimit ${toRun}
325    limit=$?
326  else
327    limit=${defaultLimit}
328  fi
329
330  ## Some BSPs must generate device trees or scripts to provide to the simulator
331  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
332    bspGenerateDeviceTree ${baseToRun} ${toRun} >${bspTreeFile}
333    if [ ${generate_tree_and_exit} = "yes" ] ; then
334      echo "Device tree generated and in ${bspTreeFile}"
335      exit 0
336    fi
337    if [ ${verbose} = "yes" ] ; then
338      echo "=================================================="
339      cat ${bspTreeFile}
340      echo "=================================================="
341    fi
342  fi
343
344  if [ ${interactive} = "yes" ] ; then
345    test ${verbose} = "yes" && \
346      echo INTERACTIVE runtest ${toRun} ${testtype} 0
347    runtest ${toRun} ${testtype} 0
348    continue
349  fi
350
351  if [ ${testtype} = "fatal" -a ${bspRunFatal} = "no" ] ; then
352    warn "Skipping fatal error test ${toRun}"
353    continue
354  fi
355
356  ## If the test is known to be interactive or locks up and we are
357  ## in batch mode, skip it.
358  case ${toRun} in
359    monitor*|termios*|fileio*|capture*)
360        warn "Skipping ${toRun}; it is interactive"
361        continue
362        ;;
363    *-node2*)
364        fatal "MP tests not supported"
365        warn "Skipping ${toRun}; 'runtest' runs both nodes when for *-node1"
366        continue;;
367    *-node1*)
368      warn "Running both nodes associated with ${toRun}"
369      ;;
370    minimum*|pppd*)
371      warn "Skipping ${toRun}; it locks up or takes a VERY long time to run"
372      continue
373      ;;
374   esac
375
376  test ${verbose} = "yes" && \
377    echo BACKGROUND runtest ${toRun} ${testtype} ${limit}
378  runtest ${toRun} ${testtype} ${limit}
379
380  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
381    rm -f ${bspTreeFile}
382  fi
383done
384
385exit $?
386
Note: See TracBrowser for help on using the repository browser.