-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-testsuite.sh
executable file
·557 lines (502 loc) · 13.4 KB
/
run-testsuite.sh
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#!/bin/bash
#################################################
#
# Script for running the RTEMS testsuite
#
# Author: André Rocha <[email protected]>
# Stefan Hepp <[email protected]>
#
#################################################
# files and dirs
curdir=$(pwd)
sourcedir=$curdir/testsuites
builddir=$curdir/../rtems-build
patmosdir=~/t-crest/build-rtems/patmos
ise_ds_path="/opt/Xilinx/14.7/ISE_DS"
comport=/dev/ttyUSB1
makefile=
# script flow helpers
cdlevel=0
javatoolsflag=0
xilinxfpgaflag=0
toolsflag=1
valuesflag=1
bitflag=0
resumeflag=0
genflag=0
cleanflag=0
partest=
sim=
simargs=()
bsp=
# script lists
tests=(itrontests libtests mptests psxtests samples sptests tmitrontests tmtests)
simulators=(ML605 pasim patex tsim-leon3)
runtests=()
resumetests=()
# test counters
failtests=0
successtests=0
noexectests=0
noresulttests=0
# defaults are set after options are read
bitfile=
biturl=
resultsdir=
log=
toolslog=
# timeout 360s = 6 mins
timeout=360
# string helpers
checklog=" [check tools log for more information]"
logseparator=">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
function usage() {
cat <<EOT
Usage: $0 [-h] [-c] [-r] [-g] [-j] [-f] [-p <sim args>] [-t <tests>] [-s <source dir>] [-b <build dir>] [-i <patmos dir>] [-o <report dir>] [-l <log file>] [-m <simulator>] [-x <bsp>] [-u <com port>] [-d <bit file>] [-e <bit file>] [-v <path Xilinx>] [-z <timeout>]
-h Display help contents
-c Clean files created during testsuite runs
-r Resume test execution
-g Regenerate .scn files
-j Build javatools
-f Configure Xilinx ML605 FPGA
-p <sim args> Pass additional arguments to the simulator. Arguments should be passed between quotation marks
-t <tests> Tests to be executed (itrontests, libtests, mptests, psxtests, samples, sptests, tmitrontests, tmtests)
-s <source dir> Directory containing the testsuites sources
-b <build dir> Build directory of the testsuites
-i <patmos dir> Directory containing the patmos repository
-o <report dir> Report output directory
-l <log file> Override the default log file
-m <simulator> Override the default simulator (ML605), available simulators are: ML605, pasim, patex, tsim-leon3
-x <bsp> Override the default BSP (tcrest)
-u <com port> Specify the communication port
-d <bit file> Download Xilinx bitfile
-e <bit file> Path to Xilinx bitfile
-v <path Xilinx> Path to Xilinx ISE DS folder
-z <timeout> Timeout, in seconds, for downloading elf files to FPGA (360s)
EOT
}
function containsElement() {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 1; done
return 0
}
function cleanFiles() {
rm -rf $resultsdir
}
function writeFile() {
if [[ ! -f $1 ]]; then
touch $1
fi
echo -e $2 >> $1
}
function addSimArg() {
containsElement $1 "${simargs[@]}"
if [[ $? == 0 ]]; then
simargs=( "${simargs[@]}" $1 )
fi
}
function checkUserValues() {
if [[ $valuesflag == 0 ]]; then
exit 1
fi
}
# function arguments:
# 1 - makefile target
function useMakefile() {
make -C $patmosdir COM_PORT=$comport $1 >> $toolslog 2>&1
}
function configureXilinxFPGA() {
local tmp_script=tmp-impact.sh
rm -rf $tmp_script
touch $tmp_script
echo -e "source $ise_ds_path/settings32.sh\nexport LD_PRELOAD=/opt/libusb/libusb-driver.so\nimpact -batch <<EOF\ncleancablelock\nsetMode -bs\nsetCable -port auto\nIdentify -inferir\nidentifyMPM\nassignfile -p 2 -file $bitfile\nprogram -p 2\nexit\nEOF" >> $tmp_script
chmod 777 $tmp_script
echo "Configuring ML605...$checklog"
writeFile $toolslog $logseparator
./$tmp_script >> $toolslog 2>&1
writeFile $toolslog $logseparator
rm -rf tmp-impact.sh
rm -rf _impactbatch.log
}
function testsOnResume() {
if [[ -f $1 ]]; then
while read line
do
resumetests=( "${resumetests[@]}" $(echo "${line%%:*}"))
local testresult=$(echo "${line##*:}")
if [[ $testresult =~ "Failed" ]]; then
let failtests+=1
elif [[ $testresult =~ "Passed" ]]; then
let successtests+=1
elif [[ $testresult =~ "check" ]]; then
let noresulttests+=1
elif [[ $testresult =~ "file not found" ]]; then
let noexectests+=1
fi
done < $1
fi
}
function runTest() {
local bin=$(find $testsuitedir -iname "$1.exe")
if [[ $bin ]]; then
local retcode
local tmplog=$resultsdir/$1-tmp.txt
local exelog=$resultsdir/$1-exe.txt
local testlog=$resultsdir/$1-log.txt
case $sim in
pasim|patex)
$sim "${simargs[@]}" -O $tmplog $bin > $exelog 2>&1
retcode=$?
;;
tsim-leon3)
echo -e "load $bin\ngo\nquit\n" >> tsim-script.txt
$sim "${simargs[@]}" -c tsim-script.txt > $exelog
retcode=$?
sed -e '1,24d;$d' $exelog > $tmplog
rm -rf tsim-script.txt
;;
ML605)
local patserdow=$(find $patmosdir -iname "patserdow" -type f -executable | head -1)
if [[ $patserdow == "" ]]; then
echo "Error: patserdow java script not found"
exit 1
fi
configureXilinxFPGA
timeout --foreground $timeout"s" $patserdow -v $comport $bin > $exelog 2>&1
retcode=$?
sed -i "/\[..........\]/d" $exelog
local tmp=$resultsdir/$1-tmp-tmp.txt
sed -ne '/\<Entry point:\(.*\)\>/,/\<EXIT 0\>/{/\<Entry point:\(.*\)\>/{h;d};H;/\<EXIT 0\>/{x;p}}' $exelog > $tmplog
tail -n +3 $tmplog | head -n -2 > $tmp && mv $tmp $tmplog
;;
esac
if [[ -f $tmplog ]]; then
sed -i "s/\r//" $tmplog
fi
if [[ $genflag == 1 ]]; then
cp -f $tmplog $1.scn
writeFile $log "$3: generating file $1.scn"
echo "$3: generating file $1.scn"
rm -rf $tmplog $exelog
else
if [[ $retcode != 0 ]]; then
writeFile $log "$3: Test executed: Failed with return code $retcode!"
echo "$(tput setaf 1)$3: Test executed: Failed with return code $retcode!$(tput setaf 7)"
let failtests+=1
#timeout, kill processes hanging port and reconfigure FPGA
if [[ $sim == "ML605" && $retcode == 124 ]]; then
lsof | grep $comport | awk 'NR!=1 {print $3}' | xargs kill
fi
else
if [[ $sim == "pasim" ]]; then
mv -f $exelog $resultsdir/$1-stats.txt
fi
if [[ $(find -maxdepth 1 -iname "*.scn" ) ]]; then
# TODO for some reasons, the pasim output has two empty lines at the beginning and windows newlines,
# should be fixed (?), for now we just ignore this
diff --ignore-space-change $tmplog $1.scn > $testlog
if [[ -s $testlog ]]; then
writeFile $log "$3: Test executed: Failed!"
if [[ $sim == "ML605" || $sim == "tsim-leon3" ]]; then
mv -f $exelog $resultsdir/$1-out.txt
else
mv -f $tmplog $resultsdir/$1-out.txt
fi
echo "$(tput setaf 1)$3: Test executed: Failed!$(tput setaf 7)"
let failtests+=1
else
writeFile $log "$3: Test executed: Passed!"
echo "$(tput setaf 2)$3: Test executed: Passed!$(tput setaf 7)"
let successtests+=1
rm -rf $testlog
fi
else
local noresultlog=$resultsdir/$2-log.txt
writeFile $noresultlog "##### $3 #####"
cat $tmplog >> $noresultlog
writeFile $noresultlog "##### $3 #####"
writeFile $log "$3: Test executed: check $2-log.txt"
echo "$3: Test executed: check $2-log.txt"
let noresulttests+=1
fi
rm -rf $exelog
fi
rm -rf $tmplog
fi
elif [[ $(find -maxdepth 1 -iname "*.scn" ) && $genflag == 0 ]]; then
writeFile $log "$3: Test not executed: $1.exe file not found"
echo "$(tput setaf 3)$3: Test not executed: $1.exe file not found$(tput setaf 7)"
let noexectests+=1
fi
}
function recurseDirs
{
for f in "$@"
do
local testflag=1
if [[ $cdlevel == 0 ]]; then
testdir="$f"
containsElement "$f" "${runtests[@]}"
if [[ $? == 0 && ${#runtests[@]} -gt 0 ]]; then
testflag=0
fi
fi
if [[ -d "$f" && $testflag == 1 ]]; then
cd "$f"
let cdlevel+=1
if [[ $cdlevel -gt 1 ]]; then
testdir="$testdir/$f"
fi
containsElement "$testdir" "${resumetests[@]}"
if [[ $? == 0 || ${#resumetests[@]} == 0 ]]; then
runTest "$f" $(echo "${testdir%%/*}") "$testdir"
fi
recurseDirs $(ls -1)
if [[ $cdlevel != 1 ]]; then
testdir=$(echo "${testdir%/*}")
fi
cd ..
let cdlevel-=1
fi
done
}
while getopts ":hHp:P:t:T:l:L:cCrRb:B:s:S:o:O:m:M:x:X:gGjJfFu:U:e:E:d:D:v:V:i:I:z:Z:" opt; do
case "$opt" in
h|H)
usage
exit 1
;;
p|P)
addSimArg "$OPTARG"
;;
t|T)
containsElement "$OPTARG" "${tests[@]}"
if [[ $? == 1 ]]; then
runtests=( "${runtests[@]}" "$OPTARG" )
else
echo "Invalid test: $OPTARG"
usage
exit 1
fi
;;
l|L)
log="$OPTARG"
;;
c|C)
cleanflag=1
;;
r|R)
resumeflag=1
;;
s|S)
sourcedir=${OPTARG%/}
;;
b|B)
builddir=${OPTARG/%"/"/}
;;
o|O)
resultsdir=${OPTARG%/}
;;
m|M)
containsElement "$OPTARG" "${simulators[@]}"
if [[ $? == 1 ]]; then
sim="$OPTARG"
simargs=()
else
echo "Invalid simulator: $OPTARG"
usage
exit 1
fi
;;
x|X)
bsp="$OPTARG"
;;
g|G)
genflag=1
;;
j|J)
javatoolsflag=1
;;
f|F)
xilinxfpgaflag=1
;;
u|U)
comport="$OPTARG"
;;
e|E)
bitfile="$OPTARG"
;;
d|D)
biturl="$OPTARG"
bitflag=1
;;
v|V)
ise_ds_path=${OPTARG%/}
;;
i|I)
patmosdir=${OPTARG%/}
;;
z|Z)
timeout="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG"
usage
exit 1
;;
:)
echo "Option -$OPTARG requires an argument"
usage
exit 1
;;
esac
done
# check user-specified and default values
if [[ ! -d $sourcedir ]]; then
echo "Error: $sourcedir not found. Go to RTEMS source dir or specify the testsuites source dir with -s."
valuesflag=0
fi
if [[ ! -d $builddir ]]; then
echo "Error: $builddir not found. Specify RTEMS build dir with -b."
valuesflag=0
fi
checkUserValues
if [[ "$resultsdir" == "" ]]; then
resultsdir=$sourcedir/results
fi
# check if user chose to clean results folder
if [[ $cleanflag == 1 ]]; then
cleanFiles
exit 1
fi
# make results dir if it does not exist
if [[ ! -d $resultsdir ]]; then
mkdir -p $resultsdir
fi
# get absolute path of results dir
curdir=$(pwd)
cd $resultsdir
resultsdir=$(pwd)
cd $curdir
# update log file
if [[ "$log" == "" ]]; then
log=$resultsdir/testsuite-log.txt
else
log=$resultsdir/$(basename $log)
fi
toolslog=$resultsdir/tools-log.txt
rm -rf $toolslog
if [[ "$bsp" == "" ]]; then
bsp="tcrest"
fi
# get absolute path of results dir
curdir=$(pwd)
cd $builddir
builddir=$(pwd)
cd $curdir
case $bsp in
leon*|erc32)
testsuitedir=$builddir/sparc-rtems4.10/c/$bsp/testsuites
;;
*)
testsuitedir=$builddir/patmos-unknown-rtems/c/$bsp/testsuites
;;
esac
makefile=$patmosdir/Makefile
if [[ "$bitfile" == "" ]]; then
bitfile=$resultsdir/t-crest.bit
fi
if [[ "$sim" == "" ]]; then
sim="ML605"
elif [[ "$sim" == "pasim" ]]; then
addSimArg "--interrupt=1"
addSimArg "--freq=5"
addSimArg "-v"
fi
if [[ $resumeflag == 0 ]]; then
rm -rf $log
else
testsOnResume $log
fi
# check if files and directories exist
if [[ ! -d $testsuitedir ]]; then
echo "Error: $testsuitedir not found. Check if the specified BSP is correct."
valuesflag=0
fi
if [[ ($sim == "ML605" || $javatoolsflag == 1) && ! -d $patmosdir ]]; then
echo "Error: $patmosdir not found. Specify the correct patmos dir with -i."
valuesflag=0
fi
if [[ ($sim == "ML605" || $xilinxfpgaflag == 1) && ! -d $ise_ds_path ]]; then
echo "Error: $ise_ds_path not found. Specify the correct path to Xilinx ISE DS folder with -v."
valuesflag=0
fi
if [[ $sim == "ML605" && ! -c $comport ]]; then
echo "Error: $comport not found. Specify the correct communication port with -u."
valuesflag=0
fi
if [[ ($sim == "ML605" || $xilinxfpgaflag == 1) && ! -f $bitfile && $bitflag == 0 ]]; then
echo "Error: $bitfile not found. Specify the correct path to bitfile or download new bitfile with -d."
valuesflag=0
fi
# check if timeout is number and is positive or zero
if [[ $sim == "ML605" && (! $timeout =~ ^[\-0-9]+$ || $timeout -lt 0) ]]; then
echo "Error: $timeout not valid for timeout. Specify zero or a positive integer with option -z."
valuesflag=0
fi
checkUserValues
# make javatools for downloading elf files to fpga
if [[ $javatoolsflag == 1 ]]; then
# check if Makefile exists
if [[ ! -f $makefile ]]; then
echo "Error: $makefile not found. Check if the specified patmos dir is correct."
exit 1
fi
echo "Making javatools..."
writeFile $toolslog $logseparator
useMakefile "javatools scripttools"
if [[ $? != 0 ]]; then
echo "Error: making javatools$checklog"
toolsflag=0
fi
writeFile $toolslog $logseparator
fi
# download specified bitfile
if [[ $bitflag == 1 ]]; then
echo "Downloading bitfile..."
rm -rf $bitfile
writeFile $toolslog $logseparator
wget $biturl -O $bitfile >> $toolslog 2>&1
if [[ $? != 0 ]]; then
echo "Error: downloading bitfile$checklog"
toolsflag=0
fi
writeFile $toolslog $logseparator
fi
if [[ $toolsflag == 0 ]]; then
exit 1
fi
if [[ $xilinxfpgaflag == 1 ]]; then
configureXilinxFPGA
fi
cd $sourcedir
recurseDirs $(ls -1)
if [[ $genflag == 0 ]]; then
let totaltests=$successtests+$failtests+$noexectests+$noresulttests
successper=0
failper=0
noexecper=0
noresultper=0
if [[ $totaltests != 0 ]]; then
let successper=$successtests*100/$totaltests
let failper=$failtests*100/$totaltests
let noexecper=$noexectests*100/$totaltests
let noresultper=$noresulttests*100/$totaltests
fi
writeFile $log ""
writeFile $log "---------- Results ----------"
writeFile $log "Successful tests: $successtests ($successper%)"
writeFile $log "Failed tests: $failtests ($failper%)"
writeFile $log "Not executed tests: $noexectests ($noexecper%)"
writeFile $log "No result tests: $noresulttests ($noresultper%)"
fi