source: rtems-testing/sim-scripts/gdb-sim-run.in @ 29c59b5

4.11
Last change on this file since 29c59b5 was 29c59b5, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 22, 2009 at 4:06:44 PM

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

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