summaryrefslogblamecommitdiffstats
path: root/merge-helpers/check_submission
blob: 8d7208743a0f56eb5eacf9c3654b9b5300cd3773 (plain) (tree)
1
2
3
4
5
6
7
8




                                                                

          
 



                                    

                                         






              
        









                                                
 


            
 
















                                                                      



                                 





                                                   

  

             
                      
                                 






                        
                               


                           
                                         



    






                               
                                                                  



    


                             
                               




                                   
                                                                              


    

                    
                        
                               
    


                                
                        
                                                     
    
 
 







                                                       
                                                










                                                        

 





                                                     
                                                                        



                           
                                                              
                                         
                          
  
                                        


                                            
                                      
                             
  
                                

    

                                                         
                                   



                                                              







                                                                        










                                                                

















                                                       


                     

















                                                                          
                                                 















                                                               





                                                                      
                                     




                                                        


                                    
      
                                    
                                      
                                                   

                                         








                                                       



      
      
#
#  Script to test for various things we want in a BSP when it is
#  submitted.
#
#  Test for:
#    - XXX
#

usage()
{
cat <<EOF
check_submission [options] directory
  -b - check assuming directory is a BSP
  -t - check assuming directory is a test
  -v - verbose
EOF
}

fatal()
{
  usage
  exit 1
}

toggle()
{
  case $1 in
    no)  echo "yes" ;;
    yes) echo "no" ;;
    *)   fatal "Unknown value to toggle ($1)" ;;
  esac
}

verbose="no"
do_bsp="no"
do_test="no"

while getopts vbt OPT
do
    case "$OPT" in
        b) do_bsp="yes" ; do_test="no"  ;;
        t) do_bsp="no"  ; do_test="yes" ;;
        v) verbose=`toggle ${verbose}` ;;
        *) fatal ;;
    esac
done

########################### Grab Directory ###########################

shiftcount=`expr $OPTIND - 1`
shift $shiftcount

basedir=${1}

if [ "${basedir}X" = "X" ] ; then
  basedir=.
fi

if [ ${do_bsp} = "no" -a ${do_test} = "no" ] ; then
  fatal must select test or bsp check mode
fi

if [ ! -d ${basedir} ] ; then
  fatal ${basedir} is not a directory
fi


cd ${basedir}
if [ $? -ne 0 ] ; then
  echo Unable to cd to ${basedir}
  exit 1
fi


test_its_there()
{
  if [ $# -ne 2 ] ; then
    echo Usage: $0 FILE pattern
  fi
  grep ${2} ${1} >/dev/null
  if [ $? -ne 0 ] ; then
    echo "${2} is NOT in ${basedir}/${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 "${2} is NOT in ${basedir}/${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 "(${*}) SHOULD NOT BE IN ${basedir}/${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 "(${*}) SHOULD NOT BE IN ${basedir}/${FILE}"
  fi
}

find_source()
{
  findArgs=
  while getopts "cCm" 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}
}

# Verify no lines longer than 80 columns
echo "=== Checking for lines greater than 79 columns"
find_source -m -c -C | while read f
do
  grep  ".\{80,\}" ${f} >/dev/null
  if [ $? -eq 0 ] ; then
    echo "*** ${basedir}/${f} has the following lines that are too long"
    grep -n '.\{80,\}' ${f}
  fi
done

# really need to make the copyright strings consistent in BSPs
echo "=== 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 "$f has spaces at the end of one or more lines."
done

# We do not want tabs in source files
echo "=== Checking for tabs in source files"
find_source | while read f
do
  grep -P '\t' $f >/dev/null
  if [ $? -eq 0 ]; then
    echo "*** ${basedir}/${f} has the following lines with tabs"
    grep -P '\t' $f
  fi
done

# We do not want GPL code
echo "=== 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

#
# BSP specific checks
#
if [ ${do_bsp} = "yes" ] ; then
  # 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_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
fi  ## END OF IF BSP

#
# Test specific checks
#
if [ ${do_test} = "yes" ] ; then
  # 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
    fatal "Unable to locate any test Makefile.am files."
  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

exit 0