source: rtems-testing/sim-scripts/gdb-sim-run.in @ 055296c

4.11
Last change on this file since 055296c was 055296c, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 20, 2009 at 7:41:25 PM

2009-03-20 Joel Sherrill <joel.sherrill@…>

  • edb7312.in, gdb-sim-run.in, skyeye-support, tsim-support: More tunning on skyeye and erc32.
  • Property mode set to 100755
File size: 8.0 KB
Line 
1#! /bin/sh
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#  $Id$
10#
11
12trap "test_exit 1" 1 2 3 13 14 15
13
14test_exit()
15{
16  exit_code=$1
17  exit $exit_code
18}
19
20
21progname=${0##*/}        # fast basename hack for ksh, bash
22
23USAGE=\
24"usage: $progname [ -opts ] test [ test ... ]
25        -v         -- verbose
26        -c         -- enabled coverage (default=no)
27        -g         -- generate device tree and exit (default=no)
28        -i         -- interactive (default=no time limit)
29        -s         -- force System V IPC support (default=no)
30        -l limit   -- specify time limit (default is 'BSP dependent')
31
32System V IPC and Coverage are not supported by all BSPs or simulators.
33
34When you generate a device tree and exit, remember to specify an executable.
35Otherwise, the script won't know what to generate it for.
36"
37
38#   log an error to stderr
39prerr()
40{
41    echo "$*" >&2
42}
43
44fatal() {
45    [ "$1" ] && prerr $*
46    prerr "$USAGE"
47    exit 1
48}
49
50warn() {
51    [ "$1" ] && prerr $*
52}
53
54#
55# process the options
56#
57# defaults for getopt vars
58#
59
60coverage="no"
61verbose="no"
62defaultLimit="not_set"
63interactive="no"
64use_sysv_ipc="no"
65generate_tree_and_exit="no"
66
67while getopts vcgil:s OPT
68do
69 case "$OPT" in
70   v) verbose="yes";;
71   c) coverage="yes";;
72   g) generate_tree_and_exit="yes" ;;
73   i) interactive="yes";;
74   l) defaultLimit="$OPTARG";;
75   s) use_sysv_ipc="yes";;
76   *) fatal;;
77 esac
78done
79
80shiftcount=`expr $OPTIND - 1`
81shift $shiftcount
82
83if [ ${interactive} = "yes" ] ; then
84  defaultLimit=0
85fi
86
87args=$*
88
89### Set BSP defaults.  If BSP does not have default, it will override
90bspRunFatal="no"
91bspGeneratesDeviceTree="no"
92bspSupportsSystemVIPC="no"
93bspUsesGDBSimulator="yes"
94bspNeedsDos2Unix="no"
95bspSimTrustedToExit="no"
96
97for v in 4.10 4.9 4.8 4.7 ""
98do
99  type @CPU_TARGET@-rtems${v}-run >/dev/null 2>&1
100  if [ $? -eq 0 ] ; then
101    defaultRUN=@CPU_TARGET@-rtems${v}-run
102    break
103  fi
104done
105
106test ${verbose} = "yes" && echo Default program to run is ${defaultRun}
107runBSP=${defaultRUN}
108
109###################################################################
110###################################################################
111###################################################################
112##INSERT BSP SUPPORT HERE
113###################################################################
114###################################################################
115###################################################################
116
117if [ ${bspSupportsSystemVIPC} = "no" -a ${use_sysv_ipc} = "yes"  ]; then
118  echo "Simulator does not support System V IPC."
119  exit 1
120fi
121
122if [ X${runBSP} = X ] ; then
123  echo "Unable to find a way to run @CPU_TARGET@/@BSP@"
124  exit 1
125fi
126
127test ${verbose} = "yes" && echo Using ${runBSP}
128
129## These are faults any BSP may generate.  They are common to RTEMS.
130checkGenericExits()
131{
132  logfile=$1
133
134  ## Clean exit patterns -- delay for coverage to get written
135  for pattern in  \
136      "^\*\*\* END OF " \
137      "^.*EXECUTIVE SHUTDOWN" \
138      "===.*FAILED.*===" \
139      "===.*PASSED.*===" \
140      "FAULTY THREAD WILL BE DELETED"
141  do
142    grep "${pattern}" ${logfile} >/dev/null 2>&1
143    if [ $? -eq 0 ] ; then
144      if [ ${coverage} = "yes" ] ; then
145        # give the simulator a chance to write the coverage
146        # ASSUME: It will exit
147        # TODO:  Add timeout logic here
148        while :
149        do
150          kill -0 $pid 2> /dev/null
151          running=$?
152          if [ $running -eq 0 ] ; then
153            kill -2 ${pid} 2>/dev/null  # SIGINT
154            sleep 1
155            kill -9 ${pid} 2>/dev/null
156          else
157            return 1
158          fi
159        done
160      fi
161      return 1
162    fi
163  done
164
165  ## Error exit patterns -- should not happen on coverage runs
166  for pattern in  \
167     "Suspending faulting task" \
168     "assertion failed"
169  do
170    grep "${pattern}" ${logfile} >/dev/null 2>&1
171    if [ $? -eq 0 ] ; then
172      return 1
173    fi
174  done
175  return 0
176}
177
178catLog()
179{
180  if [ ${bspNeedsDos2Unix} = "yes" ] ; then
181    dos2unix ${1}
182  fi
183
184  tr -d "\015" <${1}
185  echo
186}
187
188runtest()
189{
190  testname=${1}
191  testtype=${2}
192  max_run_time=${3}
193  if [ ${max_run_time} -eq 0 ] ; then
194    #echo run ${testname} forever
195    ${runBSP} `runARGS ${testname}`
196    return
197  fi
198
199  echo run ${testname} for maximum ${max_run_time} seconds
200  logfile=${testname}.tmp
201
202  if [ ${bspSimTrustedToExit} = "yes" ] ; then
203    ${runBSP} `runARGS ${testname}` >${logfile} 2>&1
204    catLog ${logfile}
205    rm -f ${logfile}
206    return
207  fi
208  ${runBSP} `runARGS ${testname}` >${logfile} 2>&1 &
209  pid=$!
210  # Make sure it won't run forever...
211  millilimit=`expr ${max_run_time} \* 1000`
212  milliseconds=0
213  while :
214  do
215    # sleep 10ms at a time waiting for job to finish or timer to expire
216    # if job has exited, then we exit, too.
217    usleep 25000  # twenty five milliseconds
218    milliseconds=`expr ${milliseconds} + 25`
219    kill -0 $pid 2> /dev/null
220    running=$?
221    if [ $running -eq 0 ] ; then
222      if [ ${milliseconds} -ge ${millilimit} ]; then
223        kill -2 $pid 2> /dev/null
224        usleep 1000
225        kill -9 $pid 2> /dev/null
226        catLog ${logfile}
227        echo "${testname} killed after running ${max_run_time} seconds"
228        break
229      fi
230      if [ ! -r ${logfile} ] ; then
231        continue
232      fi
233      # check for BSP specific messages which indicate program ended
234      checkBSPFaults ${logfile} >/dev/null 2>&1
235      bspFaults=$?
236      # check for cross platform messages which indicate program ended
237      checkGenericExits ${logfile} #>/dev/null 2>&1
238      genericExits=$?
239      if [ ${bspFaults} -ne 0 -o ${genericExits} -ne 0 ] ; then
240        kill -2 $pid 2> /dev/null
241        usleep 1000
242        kill -9 ${pid} >/dev/null 2>&1
243        catLog ${logfile}
244        echo Ran in ${milliseconds} milliseconds
245      break
246      fi
247  else
248    # done normally
249    catLog ${logfile}
250    echo "${testname} ran in ${milliseconds} milliseconds"
251    break
252  fi
253  done
254  kill -9 $pid >/dev/null 2>&1
255
256  rm ${logfile}
257}
258
259if [ "X${args}" = "X" ] ; then
260  echo no tests to run
261  exit 1
262fi
263
264## Now run the tests
265test ${verbose} = "yes" && \
266  echo TESTS TO RUN: ${args}
267for toRun in $args
268do
269  baseToRun=`basename ${toRun}`
270  case ${baseToRun} in
271    *-node*) testtype="mp"     ;;
272    *fatal*) testtype="fatal"  ;;
273    *)       testtype="single" ;;
274  esac
275  # calculate the limit in case it is used by the simulator script
276  if [ ${defaultLimit} = "not_set" ] ; then
277    bspLimit ${toRun}
278    limit=$?
279  else
280    limit=${defaultLimit}
281  fi
282
283  ## Some BSPs must generate device trees or scripts to provide to the simulator
284  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
285    bspGenerateDeviceTree ${baseToRun} ${toRun} >${bspTreeFile}
286    if [ ${generate_tree_and_exit} = "yes" ] ; then
287      echo "Device tree generated and in ${bspTreeFile}"
288      exit 0
289    fi
290    if [ ${verbose} = "yes" ] ; then
291      echo "=================================================="
292      cat ${bspTreeFile}
293      echo "=================================================="
294    fi
295  fi
296
297  if [ ${interactive} = "yes" ] ; then
298    test ${verbose} = "yes" && \
299      echo INTERACTIVE runtest ${toRun} ${testtype} 0
300    runtest ${toRun} ${testtype} 0
301    continue
302  fi
303
304  if [ ${testtype} = "fatal" -a ${bspRunFatal} = "no" ] ; then
305    warn "Skipping fatal error test ${toRun}"
306    continue
307  fi
308
309  ## If the test is known to be interactive or locks up and we are
310  ## in batch mode, skip it.
311  case ${toRun} in
312    monitor* | termios* | fileio* | capture*)
313        warn "Skipping $tname; it is interactive"
314        continue
315        ;;
316    *-node2*)
317        fatal "MP tests not supported"
318        warn "Skipping $tname; 'runtest' runs both nodes when for *-node1"
319        continue;;
320    *-node1*)
321      warn "Running both nodes associated with $tname"
322      ;;
323    minimum*|spfatal|termio*)
324      warn "Skipping $tname; it locks up or takes a VERY long time to run"
325      continue
326      ;;
327   esac
328
329  test ${verbose} = "yes" && \
330    echo BACKGROUND runtest ${toRun} ${testtype} ${limit}
331  runtest ${toRun} ${testtype} ${limit}
332
333  if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
334    rm -f ${bspTreeFile}
335  fi
336done
337
338exit $?
339
Note: See TracBrowser for help on using the repository browser.