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

4.11
Last change on this file since 88fd1e0 was 88fd1e0, checked in by Sebastian Huber <sebastian.huber@…>, on May 31, 2013 at 1:27:00 PM

sim-scripts: Add realview_pbx_a9_qemu_smp

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