Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:47

0001 #! /bin/sh -p
0002 #
0003 # Run rtems tests on the Motorola MCF5206eLITE Coldfire Evaluation board
0004 # using gdb configured with P&E Micro Background Debug Mode debugging
0005 # interface.
0006 #
0007 # This program generates a gdb script to run each test, intercept
0008 # serial port output and put log into output file.
0009 #
0010 # Author: Victor V. Vengerov <vvv@oktet.ru>
0011 # Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
0012 #
0013 # Partially based on runtest script for powerpc psim.
0014 #
0015 #  COPYRIGHT (c) 1989-1999.
0016 #  On-Line Applications Research Corporation (OAR).
0017 #
0018 #  The license and distribution terms for this file may be
0019 #  found in the file LICENSE in this distribution or at
0020 #  http://www.rtems.org/license/LICENSE.
0021 #
0022 
0023 # progname=`basename $0`
0024 progname=${0##*/}        # fast basename hack for ksh, bash
0025 
0026 USAGE=\
0027 "usage: $progname [ -opts ] test [ test ... ]
0028         -s ttydevice -- specify serial device to be used to capture test
0029                         output
0030         -r baud      -- set serial port baud rate (19200 by default)
0031         -b bdmdevice -- specify BDM device to be used to control the target
0032         -g gdbname   -- specify name of gdb program to be used
0033         -v           -- verbose output
0034         -d           -- don't remove temporary files (for debugging only)
0035         -i           -- use interrupt driven console I/O when test is running
0036                         (many tests failed when interrupt driven console
0037                         input/output is used due undetermenistic tests
0038                         behaviour)
0039         -p           -- use termios poll console I/O
0040         -l logdir    -- specify log directory (default is 'logdir')
0041 
0042   Specify test as 'test' or 'test.exe'.
0043   All multiprocessing tests *must* be specified simply as 'mp01', etc.
0044 "
0045 
0046 # export everything
0047 set -a
0048 
0049 #   log an error to stderr
0050 prerr()
0051 {
0052     echo "$*" >&2
0053 }
0054 
0055 fatal() {
0056     [ "$1" ] && prerr $*
0057     prerr "$USAGE"
0058     exit 1
0059 }
0060 
0061 warn() {
0062     [ "$1" ] && prerr $*
0063 }
0064 
0065 # run at normal and signalled exit
0066 test_exit()
0067 {
0068     exit_code=$1
0069 
0070     rm -f ${logfile}.tmp*
0071     [ "$gdb_pid" ] && kill -9 $gdb_pid
0072     [ "$serial_pid" ] && kill -9 $serial_pid
0073 
0074     exit $exit_code
0075 }
0076 
0077 #
0078 # process the options
0079 #
0080 # defaults for getopt vars
0081 #
0082 # max_run_time is defaulted to 5 minutes
0083 #
0084 
0085 verbose=""
0086 serial_device=/dev/ttyS0
0087 bdm_device=/dev/bdmcf0
0088 gdbprog=true
0089 for i in rtems bdm-rtems bdm bdm-elf bdm-coff ; do
0090     if m68k-$i-gdb --version > /dev/null 2>&1 ; then
0091         gdbprog=m68k-$i-gdb ;
0092         break ;
0093     fi
0094 done
0095 logdir=log
0096 max_run_time=$((5 * 60))
0097 sizeof_ram=$((1 * 1024 * 1024))
0098 debugging="no"
0099 baudrate="19200"
0100 console_mode=0
0101 
0102 while getopts vdips:r:b:l: OPT
0103 do
0104     case "$OPT" in
0105         v)
0106             verbose="yes";;
0107         d)
0108             debugging="yes";;
0109         s)
0110             serial_device="$OPTARG";;
0111         r)
0112             baudrate="$OPTARG";;
0113         b)
0114             bdm_device="$OPTARG";;
0115         l)
0116             logdir="$OPTARG";;
0117         s)
0118             gdbprog="$OPTARG";;
0119         p)
0120             console_mode=1;;
0121         i)
0122             console_mode=2;;
0123         *)
0124             fatal;;
0125     esac
0126 done
0127 
0128 let $((shiftcount = $OPTIND - 1))
0129 shift $shiftcount
0130 
0131 args=$*
0132 
0133 #
0134 # Run the tests
0135 #
0136 
0137 tests="$args"
0138 if [ ! "$tests" ]
0139 then
0140      set -- `echo *.exe`
0141      tests="$*"
0142 fi
0143 
0144 [ -d $logdir ] ||
0145   mkdir $logdir || fatal "could not create log directory ($logdir)"
0146 
0147 # where the tmp files go
0148 trap "test_exit" 1 2 3 13 14 15
0149 
0150 for tfile in $tests
0151 do
0152 
0153    tname=`basename $tfile .exe`
0154    cpus="1"
0155    TEST_TYPE="single"
0156 
0157    case "$tname" in
0158        # size is no longer interactive.
0159        capture* | monitor* | termios* | fileio* | pppd*)
0160             warn "Skipping $tname; it is interactive"
0161             continue
0162             ;;
0163        *-node2*)
0164            warn "Skipping $tname; 'runtest' runs both nodes when for *-node1"
0165            continue
0166            ;;
0167        *-node1*)
0168            warn "Running both nodes associated with $tname"
0169            tname=`echo $tname | sed 's/-node.*//'`
0170            TEST_TYPE="mp"
0171            ;;
0172        minimum*|stackchk*|*fatal*|malloctest*)
0173            continue
0174            ;;
0175    esac
0176 
0177    if [ "$TEST_TYPE" = "mp" ] ; then
0178        fatal "MP tests not supported for this board"
0179    fi
0180 
0181    if [ $TEST_TYPE = "single" ] ; then
0182      logfile=$logdir/${tname}
0183      infofile=${logfile}.info
0184      scriptfile=${logfile}.ss
0185      gdblogfile=${logfile}.gdb
0186 
0187      rm -f ${logfile}.tmp*
0188 
0189      date=`date`
0190      echo "Starting $tname at $date"
0191 
0192      # Set serial port parameters
0193      if ! stty -F ${serial_device} raw cs8 -cstopb cread crtscts \
0194                     ispeed ${baudrate} ospeed ${baudrate} \
0195                     > /dev/null 2> /dev/null ; then
0196          fatal "Serial port couldn't be configured"
0197      fi
0198 
0199      # Flush serial port
0200      cat ${serial_device} > /dev/null &
0201      serial_pid=$!
0202      sleep 1s
0203      kill ${serial_pid}
0204 
0205      # Capture serial port
0206      cat ${serial_device} > $logfile &
0207      serial_pid=$!
0208 
0209      cat > "${scriptfile}" <<EOF
0210 target bdm $bdm_device
0211 set \$mbar  = 0x10000001
0212 set \$csar0 = \$mbar - 1 + 0x064
0213 set \$csmr0 = \$mbar - 1 + 0x068
0214 set \$cscr0 = \$mbar - 1 + 0x06E
0215 set \$csar1 = \$mbar - 1 + 0x070
0216 set \$csmr1 = \$mbar - 1 + 0x074
0217 set \$cscr1 = \$mbar - 1 + 0x07A
0218 set \$csar2 = \$mbar - 1 + 0x07C
0219 set \$csmr2 = \$mbar - 1 + 0x080
0220 set \$cscr2 = \$mbar - 1 + 0x086
0221 set \$csar3 = \$mbar - 1 + 0x088
0222 set \$csmr3 = \$mbar - 1 + 0x08C
0223 set \$cscr3 = \$mbar - 1 + 0x092
0224 set \$csar4 = \$mbar - 1 + 0x094
0225 set \$csmr4 = \$mbar - 1 + 0x098
0226 set \$cscr4 = \$mbar - 1 + 0x09E
0227 set \$csar5 = \$mbar - 1 + 0x0A0
0228 set \$csmr5 = \$mbar - 1 + 0x0A4
0229 set \$cscr5 = \$mbar - 1 + 0x0AA
0230 set \$csar6 = \$mbar - 1 + 0x0AC
0231 set \$csmr6 = \$mbar - 1 + 0x0B0
0232 set \$cscr6 = \$mbar - 1 + 0x0B6
0233 set \$csar7 = \$mbar - 1 + 0x0B8
0234 set \$csmr7 = \$mbar - 1 + 0x0BC
0235 set \$cscr7 = \$mbar - 1 + 0x0C2
0236 #  
0237 set *((short*) \$csar0) = 0xffe0
0238 set *((int*)   \$csmr0) = 0x000f0000
0239 set *((short*) \$cscr0) = 0x1da3
0240 set *((short*) \$csar1) = 0x5000
0241 set *((int*)   \$csmr1) = 0x00000000
0242 set *((short*) \$cscr1) = 0x3d43
0243 set *((short*) \$csar2) = 0x3000
0244 set *((int*)   \$csmr2) = 0x000f0000
0245 set *((short*) \$cscr2) = 0x1903
0246 set *((short*) \$csar3) = 0x4000
0247 set *((int*)   \$csmr3) = 0x000f0000
0248 set *((short*) \$cscr3) = 0x0083
0249 #
0250 load
0251 # Many tests not working properly when interrupt driven console I/O is used.
0252 set console_mode=$console_mode
0253 set \$pc=start
0254 set \$sp=0x20001ffc
0255 #
0256 break bsp_cleanup
0257 commands
0258 shell kill $serial_pid
0259 quit
0260 end
0261 #
0262 break _stop
0263 commands
0264 shell kill $serial_pid
0265 quit 1
0266 end
0267 #
0268 continue
0269 quit 2
0270 EOF
0271      ${gdbprog} -x "${scriptfile}" "${tfile}" > "${gdblogfile}"  2>&1 &
0272      gdb_pid=$!
0273      {
0274          time_run=0
0275          while [ $time_run -lt $max_run_time ] ; do
0276              sleep 10s
0277              if kill -0 $gdb_pid 2> /dev/null ; then
0278                  time_run=$((time_run+10)) ;
0279              else
0280                  exit 0
0281              fi
0282          done
0283          kill -2 $serial_pid 2> /dev/null
0284          kill -2 $gdb_pid 2> /dev/null
0285          {
0286              sleep 5s ; 
0287              if kill -0 $gdb_pid 2> /dev/null ; then
0288                  kill -9 $gdb_pid 2> /dev/null ;
0289              fi
0290              if kill -0 $serial_pid 2> /dev/null ; then
0291                  kill -9 $serial_pid 2> /dev/null ;
0292              fi
0293          } &
0294      } &
0295      wait $gdb_pid
0296      gdb_status=$?
0297      {
0298          if kill -0 $serial_pid 2> /dev/null ; then
0299              kill $serial_pid 2> /dev/null ;
0300          fi
0301          sleep 5s ;
0302          if kill -0 $serial_pid 2> /dev/null ; then
0303              kill -9 $serial_pid 2> /dev/null ;
0304          fi
0305      } &
0306      if [ $gdb_status -ge 128 ] ; then
0307          ran_too_long="yes" ;
0308      else
0309          ran_too_long="no"
0310      fi
0311      if [ $gdb_status -ne 0 ] ; then
0312          test_failed="yes" ;
0313      else
0314          test_failed="no"
0315      fi
0316      gdb_pid=""
0317      serial_pid=""
0318    fi
0319 
0320    # Create the info files
0321    {
0322        echo "$date"
0323        echo "Test run on: `uname -n`"
0324        echo "Host Information:"
0325        echo `uname -a`
0326        echo
0327        echo "Serial port: ${serial_device}"
0328        echo "Baud rate:   ${baudrate}"
0329        echo "BDM port:    ${bdm_device}"
0330        echo "gdb:         `type -path ${gdbprog}`"
0331 
0332        cat ${logfile}
0333 
0334        if [ "$test_failed" = "yes" ] ; then
0335            echo -e "\\n\\nTest did not finish normally"
0336            if [ "$ran_too_long" = "yes" ] ; then
0337                echo "Test killed after $max_run_time seconds"
0338            fi
0339        fi
0340 
0341        echo
0342        date;
0343    } > ${infofile}
0344    if [ "${debugging}" = "no" ] ; then
0345        rm -f ${scriptfile}
0346        rm -f ${gdblogfile}
0347    fi
0348 done
0349 
0350 echo "Tests completed at " `date`
0351 test_exit 0