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

Last change on this file since ee0e1a3 was ee0e1a3, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 29, 2014 at 7:58:57 AM

sim-scripts/gdb-sim-run.in: No kill generic exits

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