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

4.11
Last change on this file since 1ba5b39 was 1ba5b39, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 13, 2009 at 3:00:05 PM

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

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