summaryrefslogtreecommitdiffstats
path: root/merge-helpers/check_submission
blob: e8381217d8006185dbf7183aa09d3989498d8b92 (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
#
#  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_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
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