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

4.11
Last change on this file since 9b2d900 was 9b2d900, checked in by Joel Sherrill <joel.sherrill@…>, on May 15, 2012 at 9:03:54 PM

XXX

  • Property mode set to 100755
File size: 11.3 KB
Line 
1#! /bin/bash
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
10trap "test_exit 1" 1 2 3 13 14 15
11
12inGDBScript=no
13
14test_exit()
15{
16  exit_code=$1
17  exit $exit_code
18}
19
20progname=${0##*/}        # fast basename hack for ksh, bash
21
22USAGE=\
23"usage: $progname [ -opts ] test [ test ... ]
24        -v         -- verbose
25        -c         -- enabled coverage (default=no)
26        -C         -- cat test output if not interactive (default=no)
27        -g         -- generate device tree and exit (default=no)
28        -D         -- enable use of display adapter (default=no)
29        -N         -- enable use of network adapter (default=no)
30        -G         -- put simulator in GDB server mode (default=no)
31        -i         -- interactive (default=no time limit)
32        -s         -- force System V IPC support (default=no)
33        -S         -- skip Interrupt Critical Section Tests (default=no)
34        -l limit   -- specify time limit (default is 'BSP dependent')
35        -L dir     -- specify log directory (default is 'log')
36        -T         -- rtems-test command mode
37
38NOTES:
39  + System V IPC and Coverage are not supported by all BSPs or simulators.
40  + GDB Server mode is only supported by stand-along simulators.
41  + When you generate a device tree and exit, remember to specify an
42    executable.  Otherwise, the script won't know what to generate it for.
43"
44
45#   log an error to stderr
46prerr()
47{
48    echo "$*" >&2
49}
50
51fatal() {
52    [ "$1" ] && prerr $*
53    prerr "$USAGE"
54    exit 1
55}
56
57warn() {
58    [ "$1" ] && prerr $*
59}
60
61check_status()
62{
63  if [ $1 -ne 0 ] ; then
64    shift
65    echo "FAILED: " "$*" >&2
66    exit 1
67  fi
68}
69
70
71#
72# process the options
73#
74# defaults for getopt vars
75#
76
77doCatOutput="no"
78coverage="no"
79verbose="no"
80defaultLimit="not_set"
81interactive="no"
82gdb_server_mode="no"
83use_sysv_ipc="no"
84generate_tree_and_exit="no"
85logdir="log"
86doTrace="no"
87enable_display_adapter="no"
88enable_network="no"
89rtems_test="no"
90
91while getopts "vcCgGil:L:DsNT" OPT
92do
93 case "$OPT" in
94   v) verbose="yes";;
95   c) coverage="yes";;
96   C) doCatOutput="yes";;
97   D) enable_display_adapter="yes";;
98   g) generate_tree_and_exit="yes" ;;
99   G) gdb_server_mode="yes" ;;
100   N) enable_network="yes" ;;
101   i) interactive="yes";;
102   l) defaultLimit="$OPTARG";;
103   L) logdir="$OPTARG";;
104   s) use_sysv_ipc="yes";;
105   t) doTrace="yes";;
106   T) rtems_test="yes";;
107   *) fatal;;
108 esac
109done
110
111shiftcount=`expr $OPTIND - 1`
112shift $shiftcount
113
114args=$*
115
116if [ ${interactive} = "yes" ] ; then
117  defaultLimit=0
118else
119  if [ ! -d ${logdir} ] ; then
120    mkdir $logdir || fatal "could not create log directory ($logdir)"
121  fi
122fi
123
124### Set BSP defaults.  If BSP does not have default, it will override
125bspGeneratesDeviceTree="no"
126bspSupportsSystemVIPC="no"
127bspUsesGDBSimulator="yes"
128bspNeedsDos2Unix="no"
129bspSimTrustedToExit="no"
130bspSupportsGDBServerMode="no"
131bspSupportsDisplayAdapter="no"
132bspSupportsNIC="no"
133bspNeedsSttySane="yes"
134bspNeedsTraceConversion="no"
135bspRunsFailRandomly="no"
136bspInputDevice=/dev/console
137bspRedirectInput=no
138
139for v in 4.11 4.10 4.9 4.8 4.7 ""
140do
141  type @CPU_TARGET@-rtems${v}-run >/dev/null 2>&1
142  if [ $? -eq 0 ] ; then
143    defaultRUN=@CPU_TARGET@-rtems${v}-run
144    break
145  fi
146done
147
148test ${verbose} = "yes" && echo Default program to run is ${defaultRUN}
149runBSP=${defaultRUN}
150
151###################################################################
152###################################################################
153###################################################################
154##INSERT BSP SUPPORT HERE
155###################################################################
156###################################################################
157###################################################################
158
159if [ ${bspSupportsSystemVIPC} = "no" -a ${use_sysv_ipc} = "yes"  ]; then
160  echo "Simulator does not support System V IPC."
161  exit 1
162fi
163
164if [ ${bspSupportsNIC} = "no" -a ${enable_network} = "yes"  ]; then
165  echo "Simulator does not support a Network Interface Controller."
166  exit 1
167fi
168if [ ${bspSupportsDisplayAdapter} = "no" -a \
169     ${enable_display_adapter} = "yes"  ]; then
170  echo "Simulator does not support Graphics Display Adapter."
171  exit 1
172fi
173
174if [ X${runBSP} = X ] ; then
175  echo "Unable to find a way to run @CPU_TARGET@/@BSP@"
176  exit 1
177fi
178
179test ${verbose} = "yes" && echo Using ${runBSP}
180
181type ${runBSP}
182check_status $? "Path appears to be broken (cannot find ${runBSP})"
183
184killpid()
185{
186  pid=$1
187  kill -2 $pid 2> /dev/null
188  if [ ${coverage} = "yes" ] ; then
189    sleep 1
190  else
191    usleep 1000
192  fi
193  kill -9 $pid 2> /dev/null
194}
195
196## These are faults any BSP may generate.  They are common to RTEMS.
197checkGenericExits()
198{
199  logfile=$1
200
201  ## Clean exit patterns -- delay for coverage to get written
202  for pattern in  \
203      "^\*\*\* END OF " \
204      "^.*EXECUTIVE SHUTDOWN" \
205      "^assertion .* failed: file .*, line .*, function:" \
206      "\*\*\*.*FAILED.*\*\*\*" \
207      "===.*PASSED.*===" \
208      "^raised .*_ERROR" \
209      "FAULTY THREAD WILL BE " \
210      "\*\*\* EXIT code "
211  do
212    grep "${pattern}" ${logfile} >/dev/null 2>&1
213    if [ $? -eq 0 ] ; then
214      if [ ${coverage} = "yes" ] ; then
215        # give the simulator a chance to write the coverage
216        # ASSUME: It will exit
217        # TODO:  Add timeout logic here
218        while :
219        do
220          kill -0 $pid 2> /dev/null
221          running=$?
222          if [ $running -eq 0 ] ; then
223            killpid ${pid}
224          else
225            return 1
226          fi
227        done
228      fi
229      return 1
230    fi
231  done
232
233  ## Error exit patterns -- should not happen on coverage runs
234  for pattern in  \
235     "Suspending faulting task" \
236     "assertion failed"
237  do
238    grep "${pattern}" ${logfile} >/dev/null 2>&1
239    if [ $? -eq 0 ] ; then
240      return 1
241    fi
242  done
243  return 0
244}
245
246catLog()
247{
248  logfile=${1}
249  if [ ${doCatOutput} = "no" ] ; then
250    return
251  fi
252
253  if [ ${bspNeedsDos2Unix} = "yes" ] ; then
254    dos2unix ${logfile}
255  fi
256
257  tr -d "\015" <${logfile}
258  echo
259}
260
261get_tname()
262{
263  echo $1 | grep "exe$" >/dev/null
264  if [ $? -eq 0 ] ; then
265    ext=.exe
266  else
267    ext=.ralf
268  fi
269  tfile=`basename $1`
270  echo `basename $tfile ${ext}`
271}
272
273runtest()
274{
275  testname=${1}
276  testtype=${2}
277  max_run_time=${3}
278
279  # Just in case the simulator aborts and messes up the terminal
280  trap "test ${bspNeedsSttySane} = yes && stty sane 2>/dev/null" SIGABRT return
281
282  test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${testname}`
283
284  if [ ${max_run_time} -eq 0 ] ; then
285    #echo run ${testname} forever
286    if [ ${bspRedirectInput} = yes ] ; then
287      ${runBSP} `runARGS ${testname}` <${bspInputDevice}
288    else
289      ${runBSP} `runARGS ${testname}`
290    fi
291    return
292  fi
293
294  echo $testname | grep "exe$" >/dev/null
295  tname=`get_tname $testname`
296
297  logfile=${logdir}/${tname}
298
299  if [ ${bspSimTrustedToExit} = "yes" ] ; then
300    if [ ${bspRedirectInput} = yes ] ; then
301      ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1
302    else
303      ${runBSP} `runARGS ${testname}` >${logfile} 2>&1
304    fi
305    catLog ${logfile}
306    return
307  fi
308
309  if [ ${bspRedirectInput} = yes ] ; then
310    ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1 &
311  else
312    ${runBSP} `runARGS ${testname}` >${logfile} 2>&1 &
313  fi
314  pid=$!
315
316  # Make sure it won't run forever...
317  millilimit=`expr ${max_run_time} \* 1000`
318  milliseconds=0
319  echo -n "running ${testname} for maximum ${max_run_time} seconds... "
320  while :
321  do
322    # sleep 50ms at a time waiting for job to finish or timer to expire
323    # if job has exited, then we exit, too.
324    usleep 50000  # fifty milliseconds
325    milliseconds=`expr ${milliseconds} + 50`
326    kill -0 $pid 2> /dev/null
327    running=$?
328    if [ $running -eq 0 ] ; then
329      if [ ${milliseconds} -ge ${millilimit} ]; then
330        killpid ${pid}
331        echo -n "killed due to over time... "
332        break
333      fi
334      if [ ! -r ${logfile} ] ; then
335        continue
336      fi
337      # check for BSP specific messages which indicate program ended
338      checkBSPFaults ${logfile} >/dev/null 2>&1
339      if [ $? -ne 0  ] ; then
340        killpid ${pid}
341        echo -n "killed due to BSP fault... "
342        break
343      fi
344      # check for cross platform messages which indicate program ended
345      checkGenericExits ${logfile} #>/dev/null 2>&1
346      if [ $? -ne 0 ] ; then
347        killpid ${pid}
348        echo -n "killed due to generic exit... "
349        break
350      fi
351    else
352      # done normally
353      break
354    fi
355  done
356  catLog ${logfile}
357  echo "${milliseconds} ms run time"
358}
359
360if [ "X${args}" = "X" ] ; then
361  echo no tests to run
362  exit 1
363fi
364
365## Now run the tests
366test ${verbose} = "yes" && \
367  echo TESTS TO RUN: ${args}
368for toRun in $args
369do
370  baseToRun=`basename ${toRun}`
371  case ${baseToRun} in
372    *-node*)   testtype="mp"     ;;
373    *)         testtype="single" ;;
374  esac
375  # calculate the limit in case it is used by the simulator script
376  if [ ${defaultLimit} = "not_set" ] ; then
377    limit=`bspLimit ${toRun}`
378  else
379    limit=${defaultLimit}
380  fi
381
382  ## Some BSPs must generate device trees or scripts to provide to the simulator
383  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
384    bspGenerateDeviceTree ${baseToRun} ${toRun} >${bspTreeFile}
385    if [ ${generate_tree_and_exit} = "yes" ] ; then
386      echo "Device tree generated and in ${bspTreeFile}"
387      exit 0
388    fi
389    if [ ${verbose} = "yes" ] ; then
390      echo "=================================================="
391      cat ${bspTreeFile}
392      echo "=================================================="
393    fi
394  fi
395
396  if [ ${bspSupportsGDBServerMode} = "yes" -a ${gdb_server_mode} = "yes" ];then
397    test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${toRun}`
398    ${runBSP} `gdbServerARGS ${toRun}` <${bspInputDevice}
399    exit 0
400  fi
401
402  if [ ${interactive} = "yes" ] ; then
403    test ${verbose} = "yes" && \
404      echo INTERACTIVE runtest ${toRun} ${testtype} 0
405    runtest ${toRun} ${testtype} 0
406    continue
407  fi
408
409  ## If the test is known to be interactive or locks up and we are
410  ## in batch mode, skip it.
411  case ${baseToRun} in
412    appstart*)
413        warn "skipping intermediate file ${baseToRun}"
414        continue
415        ;;
416    *-node2*)
417        fatal "MP tests not supported"
418        warn "Skipping ${baseToRun}; 'runtest' runs both nodes when for *-node1"
419        continue;;
420    *-node1*)
421      warn "Running both nodes associated with ${baseToRun}"
422      ;;
423    pppd*)
424      warn "skipping long running ${baseToRun}"
425      continue
426      ;;
427   esac
428
429  test ${verbose} = "yes" && \
430    echo BACKGROUND runtest ${toRun} ${testtype} ${limit}
431  runtest ${toRun} ${testtype} ${limit}
432  # Some simulators fail to work correctly all the time.  If this is one AND
433  # the run looks like it did not work right, then run again until it does
434  if [ ${bspRunsFailRandomly} = "yes" ] ; then
435    tries=1
436    while [ `bspCheckRunWasOK` -eq 1 -a ${tries} -lt 3 ]
437    do
438      tries=`expr ${tries} + 1`
439      echo "Rerunning ${toRun} due to random run failure (try=${tries})"
440      runtest ${toRun} ${testtype} ${limit}
441    done
442    if [ ${tries} -eq 3 ] ; then
443      echo "WARNING ${toRun} does not look like it had any output"
444    fi
445  fi
446
447  # some BSPs produce trace oriented files which need to be converted
448  # to object coverage maps
449  if [ ${coverage} = "yes" -a ${bspNeedsTraceConversion} = "yes" ] ; then
450    test ${verbose} = "yes" && echo Converting trace map for ${toRun}
451    convertTraceToCoverageMap ${toRun}
452  fi
453
454
455  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
456    rm -f ${bspTreeFile}
457  fi
458done
459
460exit $?
461
Note: See TracBrowser for help on using the repository browser.