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

4.11
Last change on this file since 9f23aff was 9f23aff, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 13, 2013 at 12:53:52 PM

sim-scripts/gdb-sim-run.in: Add -T option

The -T option can be used to specify a TAP network interface used for
example by the Qemu simulator.

  • Property mode set to 100755
File size: 12.4 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        -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}
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  if [ ${doCatOutput} = "no" ] ; then
278    return
279  fi
280
281  if [ ${bspNeedsDos2Unix} = "yes" ] ; then
282    dos2unix ${logfile}
283  fi
284
285  tr -d "\015" <${logfile}
286  echo
287}
288
289get_tname()
290{
291  echo $1 | grep "exe$" >/dev/null
292  if [ $? -eq 0 ] ; then
293    ext=.exe
294  else
295    ext=.ralf
296  fi
297  tfile=`basename $1`
298  echo `basename $tfile ${ext}`
299}
300
301runtest()
302{
303  testname=${1}
304  testtype=${2}
305  max_run_time=${3}
306
307  # Just in case the simulator aborts and messes up the terminal
308  trap "test ${bspNeedsSttySane} = yes && stty sane 2>/dev/null" SIGABRT return
309
310  test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${testname}`
311
312  if [ ${max_run_time} -eq 0 ] ; then
313    #echo run ${testname} forever
314    if [ ${bspRedirectInput} = yes ] ; then
315      ${runBSP} `runARGS ${testname}` <${bspInputDevice}
316    else
317      ${runBSP} `runARGS ${testname}`
318    fi
319    return
320  fi
321
322  echo $testname | grep "exe$" >/dev/null
323  tname=`get_tname $testname`
324
325  logfile=${logdir}/${tname}
326
327  if [ ${bspSimTrustedToExit} = "yes" ] ; then
328    if [ ${bspRedirectInput} = yes ] ; then
329      ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1
330    else
331      ${runBSP} `runARGS ${testname}` >${logfile} 2>&1
332    fi
333    catLog ${logfile}
334    return
335  fi
336
337  if [ ${bspRedirectInput} = yes ] ; then
338    ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1 &
339  else
340    ${runBSP} `runARGS ${testname}` >${logfile} 2>&1 &
341  fi
342  pid=$!
343
344  # Make sure it won't run forever...
345  millilimit=`expr ${max_run_time} \* 1000`
346  milliseconds=0
347  echo -n "running ${testname} for maximum ${max_run_time} seconds... "
348  while :
349  do
350    # sleep 50ms at a time waiting for job to finish or timer to expire
351    # if job has exited, then we exit, too.
352    usleep 50000  # fifty milliseconds
353    milliseconds=`expr ${milliseconds} + 50`
354    kill -0 $pid 2> /dev/null
355    running=$?
356    if [ $running -eq 0 ] ; then
357      if [ ${milliseconds} -ge ${millilimit} ]; then
358        killpid ${pid}
359        echo -n "killed due to over time... "
360        break
361      fi
362      if [ ! -r ${logfile} ] ; then
363        continue
364      fi
365      # check for BSP specific messages which indicate program ended
366      checkBSPFaults ${logfile} >/dev/null 2>&1
367      if [ $? -ne 0  ] ; then
368        killpid ${pid}
369        echo -n "killed due to BSP fault... "
370        break
371      fi
372      # check for cross platform messages which indicate program ended
373      checkGenericExits ${logfile} #>/dev/null 2>&1
374      if [ $? -ne 0 ] ; then
375        killpid ${pid}
376        echo -n "killed due to generic exit... "
377        break
378      fi
379    else
380      # done normally
381      break
382    fi
383  done
384  catLog ${logfile}
385  echo "${milliseconds} ms run time"
386}
387
388if [ "X${args}" = "X" ] ; then
389  echo no tests to run
390  exit 1
391fi
392
393## Now run the tests
394test ${verbose} = "yes" && \
395  echo TESTS TO RUN: ${args}
396for toRun in $args
397do
398  baseToRun=`basename ${toRun}`
399  case ${baseToRun} in
400    *-node*)   testtype="mp"     ;;
401    *)         testtype="single" ;;
402  esac
403  # calculate the limit in case it is used by the simulator script
404  if [ ${defaultLimit} = "not_set" ] ; then
405    limit=`bspLimit ${toRun}`
406  else
407    limit=${defaultLimit}
408  fi
409
410  ## Some BSPs must generate device trees or scripts to provide to the simulator
411  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
412    bspGenerateDeviceTree ${baseToRun} ${toRun} >${bspTreeFile}
413    if [ ${generate_tree_and_exit} = "yes" ] ; then
414      echo "Device tree generated and in ${bspTreeFile}"
415      exit 0
416    fi
417    if [ ${verbose} = "yes" ] ; then
418      echo "=================================================="
419      cat ${bspTreeFile}
420      echo "=================================================="
421    fi
422  fi
423
424  if [ ${bspSupportsGDBServerMode} = "yes" -a ${gdb_server_mode} = "yes" ];then
425    test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${toRun}`
426    ${runBSP} `gdbServerARGS ${toRun}` <${bspInputDevice}
427    exit 0
428  fi
429
430  if [ ${interactive} = "yes" ] ; then
431    test ${verbose} = "yes" && \
432      echo INTERACTIVE runtest ${toRun} ${testtype} 0
433    runtest ${toRun} ${testtype} 0
434    continue
435  fi
436
437  ## If the test is known to be interactive or locks up and we are
438  ## in batch mode, skip it.
439  case ${baseToRun} in
440    appstart*)
441      warn "skipping intermediate file ${baseToRun}"
442      continue
443      ;;
444    *-node2*)
445      fatal "MP tests not supported"
446      warn "Skipping ${baseToRun}; 'runtest' runs both nodes when for *-node1"
447      continue
448      ;;
449    *-node1*)
450      warn "Running both nodes associated with ${baseToRun}"
451      ;;
452    spintr*|psxintr*)
453      if [ ${skip_interrupt_critical_section_tests} = "yes" -o \
454           ${bspSkipInterruptCriticalSectionTests} = "yes" ]; then
455        warn "Skipping interrupt critical section test ${baseToRun}"
456        continue
457      fi
458      ;;
459    fileio.*|termios.*)
460      warn "skipping interactive ${baseToRun}"
461      continue
462      ;;
463    pppd*)
464      warn "skipping long running ${baseToRun}"
465      continue
466      ;;
467   esac
468
469  test ${verbose} = "yes" && \
470    echo BACKGROUND runtest ${toRun} ${testtype} ${limit}
471  runtest ${toRun} ${testtype} ${limit}
472  # Some simulators fail to work correctly all the time.  If this is one AND
473  # the run looks like it did not work right, then run again until it does
474  if [ ${bspRunsFailRandomly} = "yes" ] ; then
475    tries=1
476    while [ `bspCheckRunWasOK` -eq 1 -a ${tries} -lt 3 ]
477    do
478      tries=`expr ${tries} + 1`
479      echo "Rerunning ${toRun} due to random run failure (try=${tries})"
480      runtest ${toRun} ${testtype} ${limit}
481    done
482    if [ ${tries} -eq 3 ] ; then
483      echo "WARNING ${toRun} does not look like it had any output"
484    fi
485  fi
486
487  # some BSPs produce trace oriented files which need to be converted
488  # to object coverage maps
489  if [ ${coverage} = "yes" -a ${bspNeedsTraceConversion} = "yes" ] ; then
490    test ${verbose} = "yes" && echo Converting trace map for ${toRun}
491    convertTraceToCoverageMap ${toRun}
492  fi
493
494
495  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
496    rm -f ${bspTreeFile}
497  fi
498done
499
500exit $?
501
Note: See TracBrowser for help on using the repository browser.