summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/psim/tools/psim
blob: faa8a2e8b90acf50cab099468ea11ca1e2e4c623 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /bin/sh
#
#  Shell script to ease invocation of the powerpc simulator
#
#  COPYRIGHT (c) 1989-2006.
#  On-Line Applications Research Corporation (OAR).
#
#  The license and distribution terms for this file may be
#  found in found in the file LICENSE in this distribution or at
#  http://www.rtems.com/license/LICENSE.
#
#  $Id$
#

TREE_FILE=psim_tree.${LOGNAME}
RUN=powerpc-rtems4.8-run


progname=${0##*/}        # fast basename hack for ksh, bash

USAGE=\
"usage: $progname [ -opts ] test [ test ... ]
	-v	   -- verbose
        -l limit   -- specify time limit (default is 'no limit')
"

#   log an error to stderr
prerr()
{
    echo "$*" >&2
}

fatal() {
    [ "$1" ] && prerr $*
    prerr "$USAGE"
    exit 1
}

warn() {
    [ "$1" ] && prerr $*
}

#
# process the options
#
# defaults for getopt vars
#

verbose=""
limit="0"

while getopts vl: OPT
do
    case "$OPT" in
	v)
	    verbose="yes";;
        l)
            limit="$OPTARG";;
        *)
            fatal;;
    esac
done
shiftcount=`expr $OPTIND - 1`
shift $shiftcount

args=$*

# RUN_DEBUG="-t sem_device"

#  Build this user's device tree file
echo "/#address-cells 2"                              >  ${TREE_FILE}
echo "/openprom/init/register/pvr 0xfffe0000"         >> ${TREE_FILE}
echo "/openprom/options/oea-memory-size 8388608"      >> ${TREE_FILE}

# These require the semaphore and shared memory device models.
# echo "/shm@0xc0000000/reg 0xc0000000 0x10000"         >> ${TREE_FILE}
# echo "/shm@0xc0000000/key ${RTEMS_SHM_KEY}"           >> ${TREE_FILE}
# echo "/sem@0xc0010000/reg 0xc0010000 12"              >> ${TREE_FILE}
# echo "/sem@0xc0010000/key ${RTEMS_SHM_SEMAPHORE_KEY}" >> ${TREE_FILE}
# echo "/sem@0xc0010000/value -1"                       >> ${TREE_FILE}

runtest()
{
  testname=${1}
  max_run_time=${2}
  if [ ${max_run_time} -eq 0 ] ; then
    #echo run ${testname} forever
    ${RUN} -f ${TREE_FILE} ${RUN_DEBUG} ${testname}
  else
    #echo run ${testname} for maximum ${max_run_time} seconds
    ${RUN} -f ${TREE_FILE} ${RUN_DEBUG} ${testname} &
    pid=$!

    # Make sure it won't run forever...
    time_run=0
    while [ $time_run -lt $max_run_time ]
    do
      # sleep 5s at a time waiting for job to finish or timer to expire
      # if job has exited, then we exit, too.
      sleep 1
      kill -0 $pid 2> /dev/null
      running=$?
      if [ $running -eq 0 ] ; then
        time_run=$((time_run + 5))
        if [ $time_run -ge $max_run_time ]; then
	  kill -9 $pid 2> /dev/null
	  ran_too_long="yes"
          echo "${testname} killed after running ${max_run_time} seconds"
        fi
      else
        ran_too_long="no"
        break
      fi
    done
  fi
}

runtest ${1} ${limit}
rm -f ${TREE_FILE}
exit $?