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
RevLine 
[64b459b]1#! /bin/bash
[450998b]2#
[6cc4645]3#  Framework script tailored for the @CPU@/@BSP@
[450998b]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
[33a3fc7]12inGDBScript=no
13
[450998b]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
[2e284ff]25        -c         -- enabled coverage (default=no)
[29c59b5]26        -C         -- cat test output if not interactive (default=no)
[7f4ed08]27        -g         -- generate device tree and exit (default=no)
[b94baa0]28        -D         -- enable use of display adapter (default=no)
29        -N         -- enable use of network adapter (default=no)
[1ba5b39]30        -G         -- put simulator in GDB server mode (default=no)
[2e284ff]31        -i         -- interactive (default=no time limit)
[88fd1e0]32        -p cores   -- number of cores for SMP
[2e284ff]33        -s         -- force System V IPC support (default=no)
[61039c7]34        -S         -- skip Interrupt Critical Section Tests (default=no)
[450998b]35        -l limit   -- specify time limit (default is 'BSP dependent')
[29c59b5]36        -L dir     -- specify log directory (default is 'log')
[2e284ff]37
[1ba5b39]38NOTES:
[4856251]39  + Most simulators do not support multicore support.
[1ba5b39]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.
[450998b]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
[d64a924]62check_status()
63{
64  if [ $1 -ne 0 ] ; then
65    shift
66    echo "FAILED: " "$*" >&2
67    exit 1
68  fi
69}
70
71
[450998b]72#
73# process the options
74#
75# defaults for getopt vars
76#
77
[29c59b5]78doCatOutput="no"
[450998b]79coverage="no"
80verbose="no"
[055296c]81defaultLimit="not_set"
[450998b]82interactive="no"
[1ba5b39]83gdb_server_mode="no"
[2e284ff]84use_sysv_ipc="no"
[7f4ed08]85generate_tree_and_exit="no"
[29c59b5]86logdir="log"
[0556e28]87doTrace="no"
[b94baa0]88enable_display_adapter="no"
89enable_network="no"
[26f6c12]90skip_interrupt_critical_section_tests="no"
[88fd1e0]91number_of_cores=
[450998b]92
[4856251]93while getopts "vcCgGil:L:p:DsNT" OPT
[450998b]94do
[2e284ff]95 case "$OPT" in
96   v) verbose="yes";;
97   c) coverage="yes";;
[29c59b5]98   C) doCatOutput="yes";;
[b94baa0]99   D) enable_display_adapter="yes";;
[7f4ed08]100   g) generate_tree_and_exit="yes" ;;
[1ba5b39]101   G) gdb_server_mode="yes" ;;
[b94baa0]102   N) enable_network="yes" ;;
[2e284ff]103   i) interactive="yes";;
[055296c]104   l) defaultLimit="$OPTARG";;
[ae809fc]105   L) logdir="$OPTARG";;
[4856251]106   p) number_of_cores="$OPTARG";;
[2e284ff]107   s) use_sysv_ipc="yes";;
[26f6c12]108   S) skip_interrupt_critical_section_tests="yes";;
[0556e28]109   t) doTrace="yes";;
[2e284ff]110   *) fatal;;
111 esac
[450998b]112done
[2e284ff]113
[450998b]114shiftcount=`expr $OPTIND - 1`
115shift $shiftcount
116
[29c59b5]117args=$*
118
[4856251]119case ${number_of_cores} in
[88fd1e0]120  "");;
[4856251]121  [1-9]) ;;
[88fd1e0]122  [1-9][0-9]) ;;
[4856251]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
[450998b]133if [ ${interactive} = "yes" ] ; then
[055296c]134  defaultLimit=0
[3c390fc]135else
136  if [ ! -d ${logdir} ] ; then
137    mkdir $logdir || fatal "could not create log directory ($logdir)"
138  fi
[29c59b5]139fi
[450998b]140
141### Set BSP defaults.  If BSP does not have default, it will override
142bspGeneratesDeviceTree="no"
[2e284ff]143bspSupportsSystemVIPC="no"
[20873580]144bspUsesGDBSimulator="yes"
[96c31138]145bspNeedsDos2Unix="no"
[055296c]146bspSimTrustedToExit="no"
[1ba5b39]147bspSupportsGDBServerMode="no"
[b94baa0]148bspSupportsDisplayAdapter="no"
149bspSupportsNIC="no"
[cf57801]150bspNeedsSttySane="yes"
[f630cdd]151bspNeedsTraceConversion="no"
[c4328b2]152bspRunsFailRandomly="no"
[c08f442]153bspInputDevice=/dev/console
[e3d7a05]154bspRedirectInput=no
[26f6c12]155bspSkipInterruptCriticalSectionTests="no"
[4856251]156bspSupportsSMP="no"
[20873580]157
[d17c1ab]158for v in 4.11 4.10 4.9 4.8 4.7 ""
[20873580]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
[29c59b5]167test ${verbose} = "yes" && echo Default program to run is ${defaultRUN}
[20873580]168runBSP=${defaultRUN}
[450998b]169
170###################################################################
171###################################################################
172###################################################################
173##INSERT BSP SUPPORT HERE
174###################################################################
175###################################################################
176###################################################################
177
[2e284ff]178if [ ${bspSupportsSystemVIPC} = "no" -a ${use_sysv_ipc} = "yes"  ]; then
179  echo "Simulator does not support System V IPC."
180  exit 1
181fi
182
[b94baa0]183if [ ${bspSupportsNIC} = "no" -a ${enable_network} = "yes"  ]; then
184  echo "Simulator does not support a Network Interface Controller."
185  exit 1
186fi
[4856251]187
[b94baa0]188if [ ${bspSupportsDisplayAdapter} = "no" -a \
189     ${enable_display_adapter} = "yes"  ]; then
190  echo "Simulator does not support Graphics Display Adapter."
191  exit 1
192fi
193
[88fd1e0]194if [ ${bspSupportsSMP} = "no" -a ${number_of_cores:-1} != 1 ] ; then
[4856251]195  echo "Simulator does not support multiple cores."
196  exit 1
197fi
198
[20873580]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
[c8d5e06]206type ${runBSP}
207check_status $? "Path appears to be broken (cannot find ${runBSP})"
208
[aeb8e90]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
[450998b]221## These are faults any BSP may generate.  They are common to RTEMS.
[96c31138]222checkGenericExits()
[450998b]223{
224  logfile=$1
225
[3e4b04d]226  ## Clean exit patterns -- delay for coverage to get written
[9cb0643]227  for pattern in  \
[96c31138]228      "^\*\*\* END OF " \
229      "^.*EXECUTIVE SHUTDOWN" \
[8a2d982]230      "^assertion .* failed: file .*, line .*, function:" \
[e7d6d832]231      "\*\*\*.*FAILED.*\*\*\*" \
[96c31138]232      "===.*PASSED.*===" \
[4124d31]233      "^raised .*_ERROR" \
[af81f97]234      "FAULTY THREAD WILL BE " \
235      "\*\*\* EXIT code "
[3e4b04d]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
[aeb8e90]248            killpid ${pid}
[3e4b04d]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  \
[9cb0643]260     "Suspending faulting task" \
261     "assertion failed"
262  do
[3e4b04d]263    grep "${pattern}" ${logfile} >/dev/null 2>&1
[9cb0643]264    if [ $? -eq 0 ] ; then
265      return 1
266    fi
267  done
[450998b]268  return 0
269}
270
[96c31138]271catLog()
272{
[29c59b5]273  logfile=${1}
274  if [ ${doCatOutput} = "no" ] ; then
275    return
276  fi
277
[96c31138]278  if [ ${bspNeedsDos2Unix} = "yes" ] ; then
[29c59b5]279    dos2unix ${logfile}
[96c31138]280  fi
281
[29c59b5]282  tr -d "\015" <${logfile}
[96c31138]283  echo
284}
285
[eee058b]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
[450998b]298runtest()
299{
300  testname=${1}
301  testtype=${2}
302  max_run_time=${3}
[e6cc2b7]303
[48ddcb2]304  # Just in case the simulator aborts and messes up the terminal
[ff72703]305  trap "test ${bspNeedsSttySane} = yes && stty sane 2>/dev/null" SIGABRT return
[48ddcb2]306
[e6cc2b7]307  test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${testname}`
308
[450998b]309  if [ ${max_run_time} -eq 0 ] ; then
310    #echo run ${testname} forever
[e3d7a05]311    if [ ${bspRedirectInput} = yes ] ; then
312      ${runBSP} `runARGS ${testname}` <${bspInputDevice}
313    else
314      ${runBSP} `runARGS ${testname}`
315    fi
[450998b]316    return
317  fi
318
[29c59b5]319  echo $testname | grep "exe$" >/dev/null
[eee058b]320  tname=`get_tname $testname`
[29c59b5]321
322  logfile=${logdir}/${tname}
[055296c]323
324  if [ ${bspSimTrustedToExit} = "yes" ] ; then
[e3d7a05]325    if [ ${bspRedirectInput} = yes ] ; then
326      ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1
327    else
328      ${runBSP} `runARGS ${testname}` >${logfile} 2>&1
329    fi
[055296c]330    catLog ${logfile}
331    return
332  fi
[ff72703]333
[e3d7a05]334  if [ ${bspRedirectInput} = yes ] ; then
335    ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1 &
336  else
337    ${runBSP} `runARGS ${testname}` >${logfile} 2>&1 &
338  fi
[450998b]339  pid=$!
[ff72703]340
[450998b]341  # Make sure it won't run forever...
342  millilimit=`expr ${max_run_time} \* 1000`
343  milliseconds=0
[1ecb62c]344  echo -n "running ${testname} for maximum ${max_run_time} seconds... "
[450998b]345  while :
346  do
[1ecb62c]347    # sleep 50ms at a time waiting for job to finish or timer to expire
[450998b]348    # if job has exited, then we exit, too.
[ef308ab]349    usleep 50000  # fifty milliseconds
350    milliseconds=`expr ${milliseconds} + 50`
[450998b]351    kill -0 $pid 2> /dev/null
352    running=$?
353    if [ $running -eq 0 ] ; then
354      if [ ${milliseconds} -ge ${millilimit} ]; then
[aeb8e90]355        killpid ${pid}
[1ecb62c]356        echo -n "killed due to over time... "
[450998b]357        break
358      fi
[9cb0643]359      if [ ! -r ${logfile} ] ; then
360        continue
361      fi
[96c31138]362      # check for BSP specific messages which indicate program ended
[450998b]363      checkBSPFaults ${logfile} >/dev/null 2>&1
[1ecb62c]364      if [ $? -ne 0  ] ; then
365        killpid ${pid}
366        echo -n "killed due to BSP fault... "
367        break
368      fi
[96c31138]369      # check for cross platform messages which indicate program ended
[6871c37]370      checkGenericExits ${logfile} #>/dev/null 2>&1
[1ecb62c]371      if [ $? -ne 0 ] ; then
[aeb8e90]372        killpid ${pid}
[1ecb62c]373        echo -n "killed due to generic exit... "
374        break
[9cb0643]375      fi
[1ecb62c]376    else
377      # done normally
378      break
379    fi
[450998b]380  done
[1ecb62c]381  catLog ${logfile}
382  echo "${milliseconds} ms run time"
[450998b]383}
384
385if [ "X${args}" = "X" ] ; then
386  echo no tests to run
387  exit 1
388fi
389
390## Now run the tests
[3e4b04d]391test ${verbose} = "yes" && \
392  echo TESTS TO RUN: ${args}
[450998b]393for toRun in $args
394do
[2e284ff]395  baseToRun=`basename ${toRun}`
396  case ${baseToRun} in
[a00ab66]397    *-node*)   testtype="mp"     ;;
398    *)         testtype="single" ;;
[450998b]399  esac
[66dcbe8]400  # calculate the limit in case it is used by the simulator script
[055296c]401  if [ ${defaultLimit} = "not_set" ] ; then
[016b70c]402    limit=`bspLimit ${toRun}`
[055296c]403  else
404    limit=${defaultLimit}
[66dcbe8]405  fi
[450998b]406
[66dcbe8]407  ## Some BSPs must generate device trees or scripts to provide to the simulator
[2e284ff]408  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
[66dcbe8]409    bspGenerateDeviceTree ${baseToRun} ${toRun} >${bspTreeFile}
[7f4ed08]410    if [ ${generate_tree_and_exit} = "yes" ] ; then
411      echo "Device tree generated and in ${bspTreeFile}"
412      exit 0
413    fi
[3e4b04d]414    if [ ${verbose} = "yes" ] ; then
415      echo "=================================================="
416      cat ${bspTreeFile}
417      echo "=================================================="
418    fi
[2e284ff]419  fi
420
[1ba5b39]421  if [ ${bspSupportsGDBServerMode} = "yes" -a ${gdb_server_mode} = "yes" ];then
422    test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${toRun}`
[c08f442]423    ${runBSP} `gdbServerARGS ${toRun}` <${bspInputDevice}
[1ba5b39]424    exit 0
425  fi
426
[450998b]427  if [ ${interactive} = "yes" ] ; then
[3e4b04d]428    test ${verbose} = "yes" && \
429      echo INTERACTIVE runtest ${toRun} ${testtype} 0
[2e284ff]430    runtest ${toRun} ${testtype} 0
[450998b]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.
[61039c7]436  case ${baseToRun} in
437    appstart*)
[26f6c12]438      warn "skipping intermediate file ${baseToRun}"
439      continue
440      ;;
[450998b]441    *-node2*)
[26f6c12]442      fatal "MP tests not supported"
443      warn "Skipping ${baseToRun}; 'runtest' runs both nodes when for *-node1"
444      continue
445      ;;
[450998b]446    *-node1*)
[61039c7]447      warn "Running both nodes associated with ${baseToRun}"
[450998b]448      ;;
[26f6c12]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      ;;
[a00ab66]460    pppd*)
[61039c7]461      warn "skipping long running ${baseToRun}"
[450998b]462      continue
463      ;;
464   esac
465
[3e4b04d]466  test ${verbose} = "yes" && \
467    echo BACKGROUND runtest ${toRun} ${testtype} ${limit}
[450998b]468  runtest ${toRun} ${testtype} ${limit}
[eee058b]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"
[f630cdd]481    fi
[eee058b]482  fi
[f630cdd]483
[eee058b]484  # some BSPs produce trace oriented files which need to be converted
485  # to object coverage maps
[c08f442]486  if [ ${coverage} = "yes" -a ${bspNeedsTraceConversion} = "yes" ] ; then
[4af9ee0]487    test ${verbose} = "yes" && echo Converting trace map for ${toRun}
[eee058b]488    convertTraceToCoverageMap ${toRun}
[f630cdd]489  fi
490
[450998b]491
[2e284ff]492  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
[9cb0643]493    rm -f ${bspTreeFile}
[2e284ff]494  fi
495done
[450998b]496
497exit $?
498
Note: See TracBrowser for help on using the repository browser.