[PATCH] Bash script to review BSP File Organization

Vipul Nayyar nayyar_vipul at yahoo.com
Sat Sep 14 20:05:36 UTC 2013


Hello Gedare, Joel

I've submitted the patch to add the bash script in the rtems-testing tree as you required. Please review it. Modified & added some new functionality.

* The internal functions( starting with an '_' ) used in a bsp is now checked for a ';' at the end of the same line & across multiple lines to ensure that the function is actually being called, not just written there. I hope I've covered all of the discrepancies present in previous output sent to you.

* If a function belonging to a file does not exist there or the file itself is not there, the script will locate the definition of that function in the bsp & report it. For Example, Some output which I got is :

arm/gumstix : bspreset.c not compiled 
arm/gumstix : bsp_reset() present in file startup/bspstart.c

powerpc/beatnik : bspreset.c not compiled 
powerpc/beatnik : bsp_reset() present in file include/bsp.h startup/reboot.c

powerpc/mpc55xxevb : start.S not present in correct path 

powerpc/mpc55xxevb : bspreset.c not compiled 
powerpc/mpc55xxevb : bsp_reset() present in file startup/reset.c 

powerpc/mpc55xxevb : bspgetworkarea.c not compiled 
powerpc/mpc55xxevb : bsp_work_area_initialize() present in file startup/bspworkareainit.c


As always, the updated output of the script is attached with the mail.

Hoping to hear your views soon !!

Regards
Vipul Nayyar 



________________________________
 From: Vipul Nayyar <nayyar_vipul at yahoo.com>
To: rtems-devel at rtems.org 
Sent: Sunday, 15 September 2013 1:31 AM
Subject: [PATCH] Bash script to review BSP File Organization
 

---
merge-helpers/review_bsp_files | 465 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 465 insertions(+)
create mode 100755 merge-helpers/review_bsp_files

diff --git a/merge-helpers/review_bsp_files b/merge-helpers/review_bsp_files
new file mode 100755
index 0000000..422d256
--- /dev/null
+++ b/merge-helpers/review_bsp_files
@@ -0,0 +1,465 @@
+#! /bin/bash
+
+# Bash Script to find discrepancies in BSP file organization
+# Author : Vipul Nayyar <nayyar_vipul at 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"
+
+
+# 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
+
+}
+
+# Reviewing for a BSP Starts
+function main(){
+
+    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
+
+    # Finding all internal functions being used in a bsp
+    find_bsp_internal
+
+    if [[ $flag == "1" ]]; then
+        echo -e "\n"
+    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
+        cd ../../../../../../cpukit
+        find_rtems_internal
+
+        cd - > /dev/null
+        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
+                    cd ../../../../../cpukit
+                    find_rtems_internal
+                    cd - > /dev/null
+                    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
+                    cd ../../../../cpukit
+                    find_rtems_internal
+                    cd - > /dev/null
+                    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"
+            ;;
+
+            "--help") echo "Help to be 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
-- 
1.7.11.7

_______________________________________________
rtems-devel mailing list
rtems-devel at rtems.org
http://www.rtems.org/mailman/listinfo/rtems-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20130915/1161b689/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: per_bsp_observation.txt
URL: <http://lists.rtems.org/pipermail/devel/attachments/20130915/1161b689/attachment-0001.txt>


More information about the devel mailing list