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

4.11
Last change on this file since 33a3fc7 was 33a3fc7, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 13, 2009 at 9:24:46 PM

2009-08-13 Joel Sherrill <joel.sherrill@…>

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