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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
|
#! /bin/bash
#
# Framework script tailored for the @CPU@/@BSP@
#
# NOTE: If the does not have the name of a specific CPU/BSP pair, then
# this is the source file. If it does have specific CPU/BSP pair,
# then this is generated output and should NOT be edited.
#
trap "test_exit 1" 1 2 3 13 14 15
inGDBScript=no
test_exit()
{
exit_code=$1
exit $exit_code
}
progname=${0##*/} # fast basename hack for ksh, bash
USAGE=\
"usage: $progname [ -opts ] test [ test ... ]
-v -- verbose
-c -- enabled coverage (default=no)
-C -- cat test output if not interactive (default=no)
-g -- generate device tree and exit (default=no)
-D -- enable use of display adapter (default=no)
-N -- enable use of network adapter (default=no)
-G -- put simulator in GDB server mode (default=no)
-i -- interactive (default=no time limit)
-s -- force System V IPC support (default=no)
-S -- skip Interrupt Critical Section Tests (default=no)
-l limit -- specify time limit (default is 'BSP dependent')
-L dir -- specify log directory (default is 'log')
-T -- rtems-test command mode
NOTES:
+ System V IPC and Coverage are not supported by all BSPs or simulators.
+ GDB Server mode is only supported by stand-along simulators.
+ When you generate a device tree and exit, remember to specify an
executable. Otherwise, the script won't know what to generate it for.
"
# log an error to stderr
prerr()
{
echo "$*" >&2
}
fatal() {
[ "$1" ] && prerr $*
prerr "$USAGE"
exit 1
}
warn() {
[ "$1" ] && prerr $*
}
check_status()
{
if [ $1 -ne 0 ] ; then
shift
echo "FAILED: " "$*" >&2
exit 1
fi
}
#
# process the options
#
# defaults for getopt vars
#
doCatOutput="no"
coverage="no"
verbose="no"
defaultLimit="not_set"
interactive="no"
gdb_server_mode="no"
use_sysv_ipc="no"
generate_tree_and_exit="no"
logdir="log"
doTrace="no"
enable_display_adapter="no"
enable_network="no"
rtems_test="no"
skip_interrupt_critical_section_tests="no"
while getopts "vcCgGil:L:DsNT" OPT
do
case "$OPT" in
v) verbose="yes";;
c) coverage="yes";;
C) doCatOutput="yes";;
D) enable_display_adapter="yes";;
g) generate_tree_and_exit="yes" ;;
G) gdb_server_mode="yes" ;;
N) enable_network="yes" ;;
i) interactive="yes";;
l) defaultLimit="$OPTARG";;
L) logdir="$OPTARG";;
s) use_sysv_ipc="yes";;
S) skip_interrupt_critical_section_tests="yes";;
t) doTrace="yes";;
T) rtems_test="yes";;
*) fatal;;
esac
done
shiftcount=`expr $OPTIND - 1`
shift $shiftcount
args=$*
if [ ${interactive} = "yes" ] ; then
defaultLimit=0
else
if [ ! -d ${logdir} ] ; then
mkdir $logdir || fatal "could not create log directory ($logdir)"
fi
fi
### Set BSP defaults. If BSP does not have default, it will override
bspGeneratesDeviceTree="no"
bspSupportsSystemVIPC="no"
bspUsesGDBSimulator="yes"
bspNeedsDos2Unix="no"
bspSimTrustedToExit="no"
bspSupportsGDBServerMode="no"
bspSupportsDisplayAdapter="no"
bspSupportsNIC="no"
bspNeedsSttySane="yes"
bspNeedsTraceConversion="no"
bspRunsFailRandomly="no"
bspInputDevice=/dev/console
bspRedirectInput=no
bspSkipInterruptCriticalSectionTests="no"
for v in 4.11 4.10 4.9 4.8 4.7 ""
do
type @CPU_TARGET@-rtems${v}-run >/dev/null 2>&1
if [ $? -eq 0 ] ; then
defaultRUN=@CPU_TARGET@-rtems${v}-run
break
fi
done
test ${verbose} = "yes" && echo Default program to run is ${defaultRUN}
runBSP=${defaultRUN}
###################################################################
###################################################################
###################################################################
##INSERT BSP SUPPORT HERE
###################################################################
###################################################################
###################################################################
if [ ${bspSupportsSystemVIPC} = "no" -a ${use_sysv_ipc} = "yes" ]; then
echo "Simulator does not support System V IPC."
exit 1
fi
if [ ${bspSupportsNIC} = "no" -a ${enable_network} = "yes" ]; then
echo "Simulator does not support a Network Interface Controller."
exit 1
fi
if [ ${bspSupportsDisplayAdapter} = "no" -a \
${enable_display_adapter} = "yes" ]; then
echo "Simulator does not support Graphics Display Adapter."
exit 1
fi
if [ X${runBSP} = X ] ; then
echo "Unable to find a way to run @CPU_TARGET@/@BSP@"
exit 1
fi
test ${verbose} = "yes" && echo Using ${runBSP}
type ${runBSP}
check_status $? "Path appears to be broken (cannot find ${runBSP})"
killpid()
{
pid=$1
kill -2 $pid 2> /dev/null
if [ ${coverage} = "yes" ] ; then
sleep 1
else
usleep 1000
fi
kill -9 $pid 2> /dev/null
}
## These are faults any BSP may generate. They are common to RTEMS.
checkGenericExits()
{
logfile=$1
## Clean exit patterns -- delay for coverage to get written
for pattern in \
"^\*\*\* END OF " \
"^.*EXECUTIVE SHUTDOWN" \
"^assertion .* failed: file .*, line .*, function:" \
"\*\*\*.*FAILED.*\*\*\*" \
"===.*PASSED.*===" \
"^raised .*_ERROR" \
"FAULTY THREAD WILL BE " \
"\*\*\* EXIT code "
do
grep "${pattern}" ${logfile} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
if [ ${coverage} = "yes" ] ; then
# give the simulator a chance to write the coverage
# ASSUME: It will exit
# TODO: Add timeout logic here
while :
do
kill -0 $pid 2> /dev/null
running=$?
if [ $running -eq 0 ] ; then
killpid ${pid}
else
return 1
fi
done
fi
return 1
fi
done
## Error exit patterns -- should not happen on coverage runs
for pattern in \
"Suspending faulting task" \
"assertion failed"
do
grep "${pattern}" ${logfile} >/dev/null 2>&1
if [ $? -eq 0 ] ; then
return 1
fi
done
return 0
}
catLog()
{
logfile=${1}
if [ ${doCatOutput} = "no" ] ; then
return
fi
if [ ${bspNeedsDos2Unix} = "yes" ] ; then
dos2unix ${logfile}
fi
tr -d "\015" <${logfile}
echo
}
get_tname()
{
echo $1 | grep "exe$" >/dev/null
if [ $? -eq 0 ] ; then
ext=.exe
else
ext=.ralf
fi
tfile=`basename $1`
echo `basename $tfile ${ext}`
}
runtest()
{
testname=${1}
testtype=${2}
max_run_time=${3}
# Just in case the simulator aborts and messes up the terminal
trap "test ${bspNeedsSttySane} = yes && stty sane 2>/dev/null" SIGABRT return
test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${testname}`
if [ ${max_run_time} -eq 0 ] ; then
#echo run ${testname} forever
if [ ${bspRedirectInput} = yes ] ; then
${runBSP} `runARGS ${testname}` <${bspInputDevice}
else
${runBSP} `runARGS ${testname}`
fi
return
fi
echo $testname | grep "exe$" >/dev/null
tname=`get_tname $testname`
logfile=${logdir}/${tname}
if [ ${bspSimTrustedToExit} = "yes" ] ; then
if [ ${bspRedirectInput} = yes ] ; then
${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1
else
${runBSP} `runARGS ${testname}` >${logfile} 2>&1
fi
catLog ${logfile}
return
fi
if [ ${bspRedirectInput} = yes ] ; then
${runBSP} `runARGS ${testname}` <${bspInputDevice} >${logfile} 2>&1 &
else
${runBSP} `runARGS ${testname}` >${logfile} 2>&1 &
fi
pid=$!
# Make sure it won't run forever...
millilimit=`expr ${max_run_time} \* 1000`
milliseconds=0
echo -n "running ${testname} for maximum ${max_run_time} seconds... "
while :
do
# sleep 50ms at a time waiting for job to finish or timer to expire
# if job has exited, then we exit, too.
usleep 50000 # fifty milliseconds
milliseconds=`expr ${milliseconds} + 50`
kill -0 $pid 2> /dev/null
running=$?
if [ $running -eq 0 ] ; then
if [ ${milliseconds} -ge ${millilimit} ]; then
killpid ${pid}
echo -n "killed due to over time... "
break
fi
if [ ! -r ${logfile} ] ; then
continue
fi
# check for BSP specific messages which indicate program ended
checkBSPFaults ${logfile} >/dev/null 2>&1
if [ $? -ne 0 ] ; then
killpid ${pid}
echo -n "killed due to BSP fault... "
break
fi
# check for cross platform messages which indicate program ended
checkGenericExits ${logfile} #>/dev/null 2>&1
if [ $? -ne 0 ] ; then
killpid ${pid}
echo -n "killed due to generic exit... "
break
fi
else
# done normally
break
fi
done
catLog ${logfile}
echo "${milliseconds} ms run time"
}
if [ "X${args}" = "X" ] ; then
echo no tests to run
exit 1
fi
## Now run the tests
test ${verbose} = "yes" && \
echo TESTS TO RUN: ${args}
for toRun in $args
do
baseToRun=`basename ${toRun}`
case ${baseToRun} in
*-node*) testtype="mp" ;;
*) testtype="single" ;;
esac
# calculate the limit in case it is used by the simulator script
if [ ${defaultLimit} = "not_set" ] ; then
limit=`bspLimit ${toRun}`
else
limit=${defaultLimit}
fi
## Some BSPs must generate device trees or scripts to provide to the simulator
if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
bspGenerateDeviceTree ${baseToRun} ${toRun} >${bspTreeFile}
if [ ${generate_tree_and_exit} = "yes" ] ; then
echo "Device tree generated and in ${bspTreeFile}"
exit 0
fi
if [ ${verbose} = "yes" ] ; then
echo "=================================================="
cat ${bspTreeFile}
echo "=================================================="
fi
fi
if [ ${bspSupportsGDBServerMode} = "yes" -a ${gdb_server_mode} = "yes" ];then
test ${verbose} == 'yes' && echo ${runBSP} `runARGS ${toRun}`
${runBSP} `gdbServerARGS ${toRun}` <${bspInputDevice}
exit 0
fi
if [ ${interactive} = "yes" ] ; then
test ${verbose} = "yes" && \
echo INTERACTIVE runtest ${toRun} ${testtype} 0
runtest ${toRun} ${testtype} 0
continue
fi
## If the test is known to be interactive or locks up and we are
## in batch mode, skip it.
case ${baseToRun} in
appstart*)
warn "skipping intermediate file ${baseToRun}"
continue
;;
*-node2*)
fatal "MP tests not supported"
warn "Skipping ${baseToRun}; 'runtest' runs both nodes when for *-node1"
continue
;;
*-node1*)
warn "Running both nodes associated with ${baseToRun}"
;;
spintr*|psxintr*)
if [ ${skip_interrupt_critical_section_tests} = "yes" -o \
${bspSkipInterruptCriticalSectionTests} = "yes" ]; then
warn "Skipping interrupt critical section test ${baseToRun}"
continue
fi
;;
fileio.*|termios.*)
warn "skipping interactive ${baseToRun}"
continue
;;
pppd*)
warn "skipping long running ${baseToRun}"
continue
;;
esac
test ${verbose} = "yes" && \
echo BACKGROUND runtest ${toRun} ${testtype} ${limit}
runtest ${toRun} ${testtype} ${limit}
# Some simulators fail to work correctly all the time. If this is one AND
# the run looks like it did not work right, then run again until it does
if [ ${bspRunsFailRandomly} = "yes" ] ; then
tries=1
while [ `bspCheckRunWasOK` -eq 1 -a ${tries} -lt 3 ]
do
tries=`expr ${tries} + 1`
echo "Rerunning ${toRun} due to random run failure (try=${tries})"
runtest ${toRun} ${testtype} ${limit}
done
if [ ${tries} -eq 3 ] ; then
echo "WARNING ${toRun} does not look like it had any output"
fi
fi
# some BSPs produce trace oriented files which need to be converted
# to object coverage maps
if [ ${coverage} = "yes" -a ${bspNeedsTraceConversion} = "yes" ] ; then
test ${verbose} = "yes" && echo Converting trace map for ${toRun}
convertTraceToCoverageMap ${toRun}
fi
if [ ${bspGeneratesDeviceTree} = "yes" ] ; then
rm -f ${bspTreeFile}
fi
done
exit $?
|