blob: 90908f12409c97345291feb572f9c35d3a3dd06e (
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
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
|
#! /bin/bash
# Bash Script to find discrepancies in BSP file organization.
# Author : Vipul Nayyar <nayyar_vipul@yahoo.com>
filename="0"
# Passing --verbose turns verbose to 1 & gives the whole story, otherwise '0' to give only important stuff.
verbose="0"
faults="0"
# Passing --warnings turns warnings to 1 & gives all the critical & non-critical bsp file org. problems.
warnings="0"
flag="0"
calling_path=`pwd`
path=""
important="1"
rtems_internal=""
internal_done="0"
do_test="0"
format="1"
# Finds all rtems internal functions ( name starting with '_' & type specifier)
# that are defined in cpukit & libcpu
function find_rtems_internal(){
if [[ $internal_done == "1" ]]; then
return
fi
echo "Compiling list of RTEMS Internal functions ..."
internal_files=""
for k in `find -name *.c`
do
for j in `grep -oE "[a-z|A-Z|0-9|_]+[\ |^][_]+[a-z|A-Z|0-9|_]*[\ ]*\(" $k`
do
if [[ $j == "_"* ]]; then
j=${j%%\(}
internal_files="$j $internal_files"
fi
done
done
for k in `find ../c/src/lib/libcpu/ -name *.c`
do
for j in `grep -oE "[a-z|A-Z|0-9|_]+[\ |^][_]+[a-z|A-Z|0-9|_]*[\ ]*\(" $k`
do
if [[ $j == "_"* ]]; then
j=${j%%\(}
internal_files="$j $internal_files"
fi
done
done
for k in $internal_files
do
if echo $rtems_internal |grep -q $k ; then
echo > /dev/null
else
rtems_internal="$k $rtems_internal"
fi
done
internal_done="1"
}
# Finds all internal functions common in bsp and (cpukit + libcpu)
function find_bsp_internal(){
bsp_methods=""
common_internal_methods=""
# Searching for internal functions starting with '_' called(i.e ending with a ';')
for i in `find -name *.c`
do
file_contents=`tr -d '\n' < $i | grep -oE "[ |^][_]+[a-z|A-Z|0-9|_]*[ ]*[\n]*\([^;]*\)[ ]*;" | tr -d '\n' `
for j in `echo "$file_contents" | grep -oE "[_]+[a-z|A-Z|0-9|_]*[ ]*\("`
do
if `echo "$bsp_methods" |grep -q "${j%%\(}"` ; then
echo > /dev/null
else
bsp_methods="${j%%\(} $bsp_methods"
fi
done
done
# Identifying common fucntions between $rtems_interval & $bsp_methods
for i in $rtems_internal
do
if [[ $i == "__asm__" || $i == "__attribute__" || $i == "__volatile__" || $i == "__"* ]];then
continue
fi
for j in $bsp_methods
do
if [[ $i == $j ]]; then
common_internal_methods="$j $common_internal_methods"
fi
done
done
if [[ $common_internal_methods != "" ]]; then
echo -e "$bsp : RTEMS Internal functions used : \c"
for i in $common_internal_methods
do
echo -e "${i}() \c"
done
flag="1"
fi
}
# Passing 1 initially to any check function states that the file/method/header
# being checked is of critical nature
function check_file(){
filename="0"
if [[ $1 == 1 ]]; then
important="1"
shift
else
important="0"
fi
#Grabbing the path of file being evaluated from Makefile.am
if grep -wqE "[ ]*[^\ ]*/($1)" Makefile.am ; then
file_path=`grep -woE "[ ]*[^\ ]*/($1)" Makefile.am | head --lines=1`
cd `dirname $file_path`
filename=$1
file_path=`pwd`
cd - > /dev/null
shift
# Checking if file lies in correct directory path
for i in $*
do
if [[ -d $i ]]; then
cd $i
else
continue
fi
if [[ "$file_path" == `pwd` ]]; then
filename="$file_path/$filename"
cd - >/dev/null
return
fi
cd - > /dev/null
done
echo "$bsp : $filename not present in correct path"
filename="$file_path/$filename"
return
else
if [[ $warnings -eq "1" || $important -eq "1" || $verbose -eq "1" ]]; then
flag="1"
echo "$bsp : $1 not compiled"
fi
fi
filename="0"
faults="1"
return
}
# Checking presence of functions in specific files
function check_methods(){
if [[ $1 == 1 ]]; then
important="1"
shift
else
important="0"
fi
for i in $*
do
# When correct file for this function does not exist
if [[ $filename == "0" ]];then
if grep -rqlE "[a-z|A-Z|0-9|_]+[ ]*$i[ ]*\(" * ;then
if [[ $warnings -eq "1" || $important -eq "1" || $verbose -eq "1" ]];then
echo $bsp : ${i%(*}"()" present in file `grep -rlE "[a-z|A-Z|0-9|_]+[ ]*$i[ ]*\(" *`
fi
fi
else
# When correct file for this function exists
if grep -Eq "[a-z|A-Z|0-9|_]+[ ]*$i[ ]*\(" $filename ; then
if [[ $verbose -eq "1" ]] ;then
echo "$bsp : `basename $filename` : ${i%(*}() present in file"
fi
else
if grep -rqlE "[a-z|A-Z|0-9|_]+[ ]*$i[ ]*\(" * ;then
if [[ $warnings -eq "1" || $important -eq "1" || $verbose -eq "1" ]];then
echo $bsp : ${i%(*}"()" present in file `grep -rlE "[a-z|A-Z|0-9|_]+[ ]*$i[ ]*\(" *`
fi
else
if [[ $warnings -eq "1" || $important -eq "1" || $verbose -eq "1" ]]; then
echo "$bsp : `basename $filename` : ${i%(*}() function does not exist in $filename "
flag="1"
fi
faults="1"
fi
fi
fi
done
}
# Checking presence of headers installed by bsp
function check_header(){
if [[ $1 == 1 ]]; then
important="1"
shift
else
important="0"
fi
for i in $*
do
if grep -wq "$i" Makefile.am ;then
if [[ ! -f "$i" && ! -f "${i}.in" ]] ;then
continue
fi
if [[ $verbose -eq "1" ]] ;then
cd `dirname $i`
echo "$bsp : `basename $i` installed from directory" ${PWD##*/c/src/lib/}
cd - > /dev/null
fi
return
fi
done
if [[ $warnings -eq "1" || $important -eq "1" || $verbose -eq "1" ]]; then
echo "${bsp%%[\ ]*} : `basename $1` not installed "
flag="1"
fi
filename="0"
faults="1"
return
}
test_its_there()
{
if [ $# -ne 2 ] ; then
echo Usage: $0 FILE pattern
fi
grep ${2} ${1} >/dev/null
if [ $? -ne 0 ] ; then
echo "$bsp : ${2} is NOT in ${1##./}"
fi
}
test_its_there_all_case()
{
if [ $# -ne 2 ] ; then
echo Usage: $0 FILE pattern
fi
grep -i ${2} ${1} >/dev/null
if [ $? -ne 0 ] ; then
echo "$bsp : ${2} is NOT in ${1##./} - case independent check"
fi
}
test_its_NOT_there_all_case()
{
if [ $# -lt 2 ] ; then
echo Usage: $0 FILE pattern
fi
FILE=$1
shift
grep -i "${*}" ${FILE} >/dev/null
if [ $? -eq 0 ] ; then
echo "$bsp : (${*}) SHOULD NOT BE IN ${FILE##./} - case independent check"
fi
}
test_its_NOT_there()
{
if [ $# -lt 2 ] ; then
echo Usage: $0 FILE pattern
fi
FILE=$1
shift
grep "${*}" ${FILE} >/dev/null
if [ $? -eq 0 ] ; then
echo "$bsp : (${*}) SHOULD NOT BE IN ${FILE##./}"
fi
}
find_source()
{
findArgs=
while getopts "cCdm" OPT
do
case "$OPT" in
c) findArgs="${findArgs} -o -name configure.ac" ;;
C) findArgs="${findArgs} -o -name *.cfg" ;;
d) findArgs="${findArgs} -o -name *.doc" ;;
m) findArgs="${findArgs} -o -name Makefile.am" ;;
*) echo "bad arg to find_source ($OPT)" ; exit 1 ;;
esac
done
shiftcount=`expr $OPTIND - 1`
shift $shiftcount
args=$*
find . -name "*.[chS]" ${findArgs}
}
function check_format(){
# Verify no lines longer than 80 columns
echo "=== Checking for lines greater than 80 columns"
find_source -m -c -C | while read f
do
grep ".\{81,\}" ${f} >/dev/null
if [ $? -eq 0 ] ; then
echo -e "\n$bsp : ${f#./} has more than 80 character lines"
for i in `grep -n '.\{80,\}' ${f} | cut -f1 -d:`
do
echo -e "$i \c"
done
fi
done
# really need to make the copyright strings consistent in BSPs
echo -e "\n=== Checking for copyright notices"
find_source | while read f
do
test_its_there_all_case ${f} COPYRIGHT
done
# We want CVS Id strings everywhere possible
echo "=== Checking for CVS Id strings"
find_source -d | while read f
do
test_its_NOT_there ${f} "\$Id"
done
# We do not want the reformatted license notice
echo "=== Checking for reformatted RTEMS license notices"
find_source -m -c -C | while read f
do
test_its_NOT_there ${f} "this file may be found in the file"
done
# We do not want spaces at the end of lines
echo "=== Checking for spaces at the end of lines"
find_source -m -c -C | while read f
do
egrep " +$" $f >/dev/null
test $? -eq 0 && echo -e "${f##./} \c"
done
# We do not want tabs in source files
echo -e "\n=== Checking for tabs in source files"
find_source | while read f
do
grep -P '\t' $f >/dev/null
test $? -eq 0 && echo -e "${f##./} \c"
done
# We do not want GPL code
echo -e "\n=== Checking for hints of GPL code"
find_source -m -c -C | while read f
do
test_its_NOT_there ${f} "Free Software Foundation"
test_its_NOT_there ${f} "program is free software"
test_its_NOT_there ${f} "General Public License"
done
# We do not want hints that there are things left to do
echo "=== Checking for TODO hints"
find_source -m -c -C | while read f
do
test_its_NOT_there ${f} XXX
test_its_NOT_there ${f} TODO
test_its_NOT_there ${f} TBD
done
}
# Reviewing for a BSP Starts
function main(){
if [[ $format -eq "1" ]]; then
check_format
fi
# We do not want stdio in a BSP
echo "=== Checking for stdio"
find_source -m -c -C | while read f
do
test_its_NOT_there ${f} printf
test_its_NOT_there ${f} "puts("
done
# BSPs should include RTEMS_BSP_CLEANUP_OPTIONS and maybe
# RTEMS_BSP_BOOTCARD_OPTIONS
if [ -r configure.ac ] ; then
echo "=== Checking for RTEMS_BSP_BOOTCARD_OPTIONS in BSP configure.ac"
test_its_NOT_there configure.ac RTEMS_BSP_BOOTCARD_OPTIONS
echo "=== Checking for RTEMS_BSP_CLEANUP_OPTIONS in BSP configure.ac"
test_its_there configure.ac RTEMS_BSP_CLEANUP_OPTIONS
fi
# If not using -O2, then we really want to know
# BSPs should normally use -O2
echo "=== Checking for not using -O2"
grep -H "\-O[013456789]" make/custom/*.cfg
# BSPs should not turn on extra warnings
echo "=== Checking for turning on extra GCC warning checks"
grep -H "\-W" make/custom/*.cfg
# Hopefully have some output from the tmtests
echo "=== Checking for timing information"
c=`ls -1 times* 2>/dev/null | wc -l`
if [ ${c} -eq 0 ] ; then
echo "Please run the timing tests and include the results."
fi
echo -e "\n=== Starting BSP Unified way checks"
flag="0"
check_file 1 start.S ../shared/start/ start/
if [[ $filename != "0" ]];then
if grep -wq "start" "$filename" || grep -wq "_start" "$filename"; then
if [[ $verbose -eq "1" ]] ;then
echo "$bsp : `basename $filename` start() present in $filename"
fi
else
echo "$bsp : `basename $filename` start() does not exist in start.S"
fi
fi
check_file 1 bspstart.c ../../shared/ ../shared/ startup/
check_methods "bsp_start"
check_file 1 bspreset.c ../../shared/ ../shared/ startup/
check_methods 1 "bsp_reset"
check_file 1 bootcard.c ../../shared/
check_header ../../shared/include/bootcard.h
check_file 1 bspclean.c ../../shared/ startup/
check_methods "bsp_fatal_extension"
check_file 1 bspgetworkarea.c ../../shared/ ../../shared/startup ../shared/ ../shared/startup/ startup/
check_methods 1 "bsp_work_area_initialize"
check_file 1 bsplibc.c ../../shared/
check_methods "bsp_libc_init"
check_file 1 bsppost.c ../../shared/
check_methods "bsp_postdriver_hook"
check_file 1 bsppredriverhook.c ../../shared/ ../shared/startup/ startup/
check_methods "bsp_predriver_hook"
check_file gnatinstallhandler.c ../../shared/
check_file sbrk.c ../../shared/ ../../shared/ startup/
check_methods "sbrk"
check_file stackalloc.c ../../shared/src/
check_methods "bsp_stack_allocate_init" "bsp_stack_allocate" "bsp_stack_free"
check_header ../../shared/include/stackalloc.h
# Interrupt Files
check_file 1 irq.c irq/
check_methods "bsp_interrupt_vector_enable" "bsp_interrupt_vector_disable" "bsp_interrupt_facility_initialize" "bsp_interrupt_dispatch"
check_header 1 include/irq.h
# PIC Support
check_file irq-default-handler.c ../../shared/src/
check_file 1 irq-generic.c ../../shared/src/
check_header 1 ../../shared/include/irq-generic.h
check_file irq-info.c ../../shared/src/
check_header ../../shared/include/irq-info.h
check_file irq-legacy.c ../../shared/src/
check_file irq-server.c ../../shared/src/
check_file irq-shell.c ../../shared/src/
# Real Time Clock
check_file rtc-config.c rtc/
check_methods "bsp_rtc_initialize" "bsp_rtc_get_time" "bsp_rtc_set_time" "bsp_rtc_probe"
check_file 1 tod.c ../../shared/ tod/
# Benchmark Timers
check_file benchmark_timer.c benchmark_timer/
check_methods "benchmark_timer_initialize" "benchmark_timer_read" "benchmark_timer_disable_subtracting_average_overhead"
# Standard Headers
check_header 1 include/bsp.h
check_header include/bspopts.h
check_header 1 ../../shared/include/coverhd.h include/coverhd.h
check_header ../../shared/include/utility.h
check_header 1 ../../shared/include/tm27.h include/tm27.h
cd ../../../../../../cpukit
find_rtems_internal
cd - > /dev/null
# Finding all internal functions being used in a bsp
find_bsp_internal
if [[ $flag == "1" ]]; then
echo -e "\n"
fi
#
# Test specific checks
#
if [ ${do_test} == "1" ] ; then
echo -e "\n=== Starting Test specific checks"
# find all the Makefile.am's with rtems_tests_PROGRAMS in them
Makefiles=`find . -name Makefile.am | xargs -e grep -l ^rtems_tests`
if [ "X${Makefiles}" = "X" ] ; then
echo -e "Unable to locate any test Makefile.am files.\n"
return
fi
echo "=== Checking for missing test support files"
for m in ${Makefiles}
do
directory=`dirname ${m}`
if [ ${directory} = "." ] ; then
directory=`pwd`
fi
testName=`basename ${directory}`
# Does this test have a .doc file?
if [ ! -r ${directory}/${testName}.doc ] ; then
echo ${testName}.doc is not present
fi
case ${directory} in
*/*tmtests*) ;;
*)
# Does this test have a .scn file?
if [ ! -r ${directory}/${testName}.scn ] ; then
echo ${testName}.scn is not present
fi
;;
esac
done
fi
}
# Verifying if the directory given or pwd is a valid bsp, shared architecture, or libbsp directory
function check_given_dir(){
if echo $cur_dir | grep -Eq "c/src/lib/libbsp/([^/]+)/([^/]+)/([^/]+)*" ; then
return 0
elif echo $cur_dir | grep -Eq "c/src/lib/libbsp/([^/]+)/([^/]+)" ; then
# BSP given
bsp=${cur_dir##*/}
if [[ $bsp == "shared" || $bsp == "autom4te.cache" || $bsp == "no_bsp" ]]; then
return 0
else
main
fi
elif echo $cur_dir | grep -Eq "c/src/lib/libbsp/([^/]+)" ; then
# Shared architecture given
for i in *
do
if [[ -d $i ]]; then
if [[ $i == "shared" || $i == "autom4te.cache" || $i == "no_bsp" ]]; then
echo -n
else
bsp=$i
cd $bsp
main
cd .. > /dev/null
fi
fi
done
elif echo $cur_dir | grep -Eq "c/src/lib/libbsp" ; then
# libbsp given
for i in */*/Makefile.am
do
i=`dirname $i`
if [[ -d $i ]]; then
if [[ $i == "shared" || $i == "autom4te.cache" || $i == "no_cpu/no_bsp" ]]; then
echo -n
else
bsp=$i
cd $bsp
main
cd ../../ > /dev/null
fi
fi
done
else
return 0
fi
}
# Evaluating Command Line Arguments
function start(){
for i in $*
do
case $i in
"--verbose") verbose="1" # The whole story
;;
"--warnings") warnings="1" # All warnings
verbose="0"
;;
"--no_format") format="0" # Disabling format checks
verbose="0"
;;
"--tests") do_test="1" # Enabling check of tests
verbose="0"
;;
"--help") echo "Help to be provided"
;;
"--"* | "-"* ) echo "Invalid options provided"
;;
*) path="$path $i" ;; # If not above options, then assumed to be a path for bsp
esac
done
# No path given, search for bsp from pwd
if [[ -z $path ]];then
path=$PWD
cur_dir=`pwd`
check_given_dir
if [[ $? -eq 1 ]];then
echo "Current directory does not seem a valid RTEMS directory"
fi
else
for i in $path
do
if [[ -d $i ]]; then
echo > /dev/null
else
echo "$i is an invalid directory."
continue
fi
cd $i
cur_dir=`pwd`
check_given_dir
if [[ $? -eq 1 ]];then
echo "$i does not seem a valid RTEMS directory"
fi
cd $calling_path
done
fi
}
# Let the Game begin !!
start $*
# End of Checks
if [[ $faults -eq "0" ]] ; then
echo -e "\nNo faults found in BSP organization"
fi
|