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

4.11
Last change on this file since 26f6c12 was 26f6c12, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 12, 2012 at 10:51:34 PM

gdb-sim-run.in: Add skip interrupt critical section tests option

This is the -S option. These take a long time to run and will never
produce any useful results if the BSP uses the IDLE Clock Tick
implementation.

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