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

4.11
Last change on this file since 22c7ee1 was 4856251, checked in by Joel Sherrill <joel.sherrill@…>, on May 29, 2013 at 8:24:31 PM

sim-scripts: Add initial support for specifying number of cores

Attempted to add support to pc386 (untested).

  • Property mode set to 100755
File size: 12.2 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 (default=1)
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=1
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  [1-9]) ;;
121  0)
122    echo "Zero cores does not make sense"
123    exit 1
124    ;;
125  *) 
126    echo "Cores specified (${number_of_cores}) is either not a valid"
127    echo "  number or supported quantity."
128    exit 1
129esac
130
131if [ ${interactive} = "yes" ] ; then
132  defaultLimit=0
133else
134  if [ ! -d ${logdir} ] ; then
135    mkdir $logdir || fatal "could not create log directory ($logdir)"
136  fi
137fi
138
139### Set BSP defaults.  If BSP does not have default, it will override
140bspGeneratesDeviceTree="no"
141bspSupportsSystemVIPC="no"
142bspUsesGDBSimulator="yes"
143bspNeedsDos2Unix="no"
144bspSimTrustedToExit="no"
145bspSupportsGDBServerMode="no"
146bspSupportsDisplayAdapter="no"
147bspSupportsNIC="no"
148bspNeedsSttySane="yes"
149bspNeedsTraceConversion="no"
150bspRunsFailRandomly="no"
151bspInputDevice=/dev/console
152bspRedirectInput=no
153bspSkipInterruptCriticalSectionTests="no"
154bspSupportsSMP="no"
155
156for v in 4.11 4.10 4.9 4.8 4.7 ""
157do
158  type @CPU_TARGET@-rtems${v}-run >/dev/null 2>&1
159  if [ $? -eq 0 ] ; then
160    defaultRUN=@CPU_TARGET@-rtems${v}-run
161    break
162  fi
163done
164
165test ${verbose} = "yes" && echo Default program to run is ${defaultRUN}
166runBSP=${defaultRUN}
167
168###################################################################
169###################################################################
170###################################################################
171##INSERT BSP SUPPORT HERE
172###################################################################
173###################################################################
174###################################################################
175
176if [ ${bspSupportsSystemVIPC} = "no" -a ${use_sysv_ipc} = "yes"  ]; then
177  echo "Simulator does not support System V IPC."
178  exit 1
179fi
180
181if [ ${bspSupportsNIC} = "no" -a ${enable_network} = "yes"  ]; then
182  echo "Simulator does not support a Network Interface Controller."
183  exit 1
184fi
185
186if [ ${bspSupportsDisplayAdapter} = "no" -a \
187     ${enable_display_adapter} = "yes"  ]; then
188  echo "Simulator does not support Graphics Display Adapter."
189  exit 1
190fi
191
192if [ ${bspSupportsSMP} = "no" -a ${number_of_cores} != 1 ] ; then
193  echo "Simulator does not support multiple cores."
194  exit 1
195fi
196
197if [ X${runBSP} = X ] ; then
198  echo "Unable to find a way to run @CPU_TARGET@/@BSP@"
199  exit 1
200fi
201
202test ${verbose} = "yes" && echo Using ${runBSP}
203
204type ${runBSP}
205check_status $? "Path appears to be broken (cannot find ${runBSP})"
206
207killpid()
208{
209  pid=$1
210  kill -2 $pid 2> /dev/null
211  if [ ${coverage} = "yes" ] ; then
212    sleep 1
213  else
214    usleep 1000
215  fi
216  kill -9 $pid 2> /dev/null
217}
218
219## These are faults any BSP may generate.  They are common to RTEMS.
220checkGenericExits()
221{
222  logfile=$1
223
224  ## Clean exit patterns -- delay for coverage to get written
225  for pattern in  \
226      "^\*\*\* END OF " \
227      "^.*EXECUTIVE SHUTDOWN" \
228      "^assertion .* failed: file .*, line .*, function:" \
229      "\*\*\*.*FAILED.*\*\*\*" \
230      "===.*PASSED.*===" \
231      "^raised .*_ERROR" \
232      "FAULTY THREAD WILL BE " \
233      "\*\*\* EXIT code "
234  do
235    grep "${pattern}" ${logfile} >/dev/null 2>&1
236    if [ $? -eq 0 ] ; then
237      if [ ${coverage} = "yes" ] ; then
238        # give the simulator a chance to write the coverage
239        # ASSUME: It will exit
240        # TODO:  Add timeout logic here
241        while :
242        do
243          kill -0 $pid 2> /dev/null
244          running=$?
245          if [ $running -eq 0 ] ; then
246            killpid ${pid}
247          else
248            return 1
249          fi
250        done
251      fi
252      return 1
253    fi
254  done
255
256  ## Error exit patterns -- should not happen on coverage runs
257  for pattern in  \
258     "Suspending faulting task" \
259     "assertion failed"
260  do
261    grep "${pattern}" ${logfile} >/dev/null 2>&1
262    if [ $? -eq 0 ] ; then
263      return 1
264    fi
265  done
266  return 0
267}
268
269catLog()
270{
271  logfile=${1}
272  if [ ${doCatOutput} = "no" ] ; then
273    return
274  fi
275
276  if [ ${bspNeedsDos2Unix} = "yes" ] ; then
277    dos2unix ${logfile}
278  fi
279
280  tr -d "\015" <${logfile}
281  echo
282}
283
284get_tname()
285{
286  echo $1 | grep "exe$" >/dev/null
287  if [ $? -eq 0 ] ; then
288    ext=.exe
289  else
290    ext=.ralf
291  fi
292  tfile=`basename $1`
293  echo `basename $tfile ${ext}`
294}
295
296runtest()
297{
298  testname=${1}
299  testtype=${2}
300  max_run_time=${3}
301
302  # Just in case the simulator aborts and messes up the terminal
303  trap "test ${bspNeedsSttySane} = yes && stty sane 2>/dev/null" SIGABRT return
304
305  test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${testname}`
306
307  if [ ${max_run_time} -eq 0 ] ; then
308    #echo run ${testname} forever
309    if [ ${bspRedirectInput} = yes ] ; then
310      ${runBSP} `runARGS ${testname}` <${bspInputDevice}
311    else
312      ${runBSP} `runARGS ${testname}`
313    fi
314    return
315  fi
316
317  echo $testname | grep "exe$" >/dev/null
318  tname=`get_tname $testname`
319
320  logfile=${logdir}/${tname}
321
322  if [ ${bspSimTrustedToExit} = "yes" ] ; then
323    if [ ${bspRedirectInput} = yes ] ; then
324      ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1
325    else
326      ${runBSP} `runARGS ${testname}` >${logfile} 2>&1
327    fi
328    catLog ${logfile}
329    return
330  fi
331
332  if [ ${bspRedirectInput} = yes ] ; then
333    ${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1 &
334  else
335    ${runBSP} `runARGS ${testname}` >${logfile} 2>&1 &
336  fi
337  pid=$!
338
339  # Make sure it won't run forever...
340  millilimit=`expr ${max_run_time} \* 1000`
341  milliseconds=0
342  echo -n "running ${testname} for maximum ${max_run_time} seconds... "
343  while :
344  do
345    # sleep 50ms at a time waiting for job to finish or timer to expire
346    # if job has exited, then we exit, too.
347    usleep 50000  # fifty milliseconds
348    milliseconds=`expr ${milliseconds} + 50`
349    kill -0 $pid 2> /dev/null
350    running=$?
351    if [ $running -eq 0 ] ; then
352      if [ ${milliseconds} -ge ${millilimit} ]; then
353        killpid ${pid}
354        echo -n "killed due to over time... "
355        break
356      fi
357      if [ ! -r ${logfile} ] ; then
358        continue
359      fi
360      # check for BSP specific messages which indicate program ended
361      checkBSPFaults ${logfile} >/dev/null 2>&1
362      if [ $? -ne 0  ] ; then
363        killpid ${pid}
364        echo -n "killed due to BSP fault... "
365        break
366      fi
367      # check for cross platform messages which indicate program ended
368      checkGenericExits ${logfile} #>/dev/null 2>&1
369      if [ $? -ne 0 ] ; then
370        killpid ${pid}
371        echo -n "killed due to generic exit... "
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.