1 | #! /bin/sh |
---|
2 | # |
---|
3 | # Shell script to ease invocation of the powerpc simulator |
---|
4 | # |
---|
5 | # COPYRIGHT (c) 1989-2006. |
---|
6 | # On-Line Applications Research Corporation (OAR). |
---|
7 | # |
---|
8 | # The license and distribution terms for this file may be |
---|
9 | # found in found in the file LICENSE in this distribution or at |
---|
10 | # http://www.rtems.com/license/LICENSE. |
---|
11 | # |
---|
12 | # $Id$ |
---|
13 | # |
---|
14 | |
---|
15 | TREE_FILE=psim_tree.${LOGNAME} |
---|
16 | RUN=powerpc-rtems4.7-run |
---|
17 | |
---|
18 | |
---|
19 | progname=${0##*/} # fast basename hack for ksh, bash |
---|
20 | |
---|
21 | USAGE=\ |
---|
22 | "usage: $progname [ -opts ] test [ test ... ] |
---|
23 | -v -- verbose |
---|
24 | -l limit -- specify time limit (default is 'no limit') |
---|
25 | " |
---|
26 | |
---|
27 | # log an error to stderr |
---|
28 | prerr() |
---|
29 | { |
---|
30 | echo "$*" >&2 |
---|
31 | } |
---|
32 | |
---|
33 | fatal() { |
---|
34 | [ "$1" ] && prerr $* |
---|
35 | prerr "$USAGE" |
---|
36 | exit 1 |
---|
37 | } |
---|
38 | |
---|
39 | warn() { |
---|
40 | [ "$1" ] && prerr $* |
---|
41 | } |
---|
42 | |
---|
43 | # |
---|
44 | # process the options |
---|
45 | # |
---|
46 | # defaults for getopt vars |
---|
47 | # |
---|
48 | |
---|
49 | verbose="" |
---|
50 | limit="0" |
---|
51 | |
---|
52 | while getopts vl: OPT |
---|
53 | do |
---|
54 | case "$OPT" in |
---|
55 | v) |
---|
56 | verbose="yes";; |
---|
57 | l) |
---|
58 | limit="$OPTARG";; |
---|
59 | *) |
---|
60 | fatal;; |
---|
61 | esac |
---|
62 | done |
---|
63 | shiftcount=`expr $OPTIND - 1` |
---|
64 | shift $shiftcount |
---|
65 | |
---|
66 | args=$* |
---|
67 | |
---|
68 | # RUN_DEBUG="-t sem_device" |
---|
69 | |
---|
70 | # Build this user's device tree file |
---|
71 | echo "/#address-cells 2" > ${TREE_FILE} |
---|
72 | echo "/openprom/init/register/pvr 0xfffe0000" >> ${TREE_FILE} |
---|
73 | echo "/openprom/options/oea-memory-size 8388608" >> ${TREE_FILE} |
---|
74 | |
---|
75 | # These require the semaphore and shared memory device models. |
---|
76 | # echo "/shm@0xc0000000/reg 0xc0000000 0x10000" >> ${TREE_FILE} |
---|
77 | # echo "/shm@0xc0000000/key ${RTEMS_SHM_KEY}" >> ${TREE_FILE} |
---|
78 | # echo "/sem@0xc0010000/reg 0xc0010000 12" >> ${TREE_FILE} |
---|
79 | # echo "/sem@0xc0010000/key ${RTEMS_SHM_SEMAPHORE_KEY}" >> ${TREE_FILE} |
---|
80 | # echo "/sem@0xc0010000/value -1" >> ${TREE_FILE} |
---|
81 | |
---|
82 | runtest() |
---|
83 | { |
---|
84 | testname=${1} |
---|
85 | max_run_time=${2} |
---|
86 | if [ ${max_run_time} -eq 0 ] ; then |
---|
87 | #echo run ${testname} forever |
---|
88 | ${RUN} -f ${TREE_FILE} ${RUN_DEBUG} ${testname} |
---|
89 | else |
---|
90 | #echo run ${testname} for maximum ${max_run_time} seconds |
---|
91 | ${RUN} -f ${TREE_FILE} ${RUN_DEBUG} ${testname} & |
---|
92 | pid=$! |
---|
93 | |
---|
94 | # Make sure it won't run forever... |
---|
95 | time_run=0 |
---|
96 | while [ $time_run -lt $max_run_time ] |
---|
97 | do |
---|
98 | # sleep 5s at a time waiting for job to finish or timer to expire |
---|
99 | # if job has exited, then we exit, too. |
---|
100 | sleep 1 |
---|
101 | kill -0 $pid 2> /dev/null |
---|
102 | running=$? |
---|
103 | if [ $running -eq 0 ] ; then |
---|
104 | time_run=$((time_run + 5)) |
---|
105 | if [ $time_run -ge $max_run_time ]; then |
---|
106 | kill -9 $pid 2> /dev/null |
---|
107 | ran_too_long="yes" |
---|
108 | echo "${testname} killed after running ${max_run_time} seconds" |
---|
109 | fi |
---|
110 | else |
---|
111 | ran_too_long="no" |
---|
112 | break |
---|
113 | fi |
---|
114 | done |
---|
115 | fi |
---|
116 | } |
---|
117 | |
---|
118 | runtest ${1} ${limit} |
---|
119 | rm -f ${TREE_FILE} |
---|
120 | exit $? |
---|
121 | |
---|