5 # Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
6 # Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
7 # Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
9 # This software is available to you under a choice of one of two
10 # licenses. You may choose to be licensed under the terms of the GNU
11 # General Public License (GPL) Version 2, available from the file
12 # COPYING in the main directory of this source tree, or the
13 # OpenIB.org BSD license below:
15 # Redistribution and use in source and binary forms, with or
16 # without modification, are permitted provided that the following
19 # - Redistributions of source code must retain the above
20 # copyright notice, this list of conditions and the following
23 # - Redistributions in binary form must reproduce the above
24 # copyright notice, this list of conditions and the following
25 # disclaimer in the documentation and/or other materials
26 # provided with the distribution.
28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 # Perl script for simple source code error checking.
51 # This script performs some simple conformance checks on the
52 # OpenSM source code. It does NOT attempt to act like a full
53 # blown 'C' language parser, so it can be fooled. Something
54 # is better than nothing. Running the 'osm_indent' script before
55 # running this script will increase your chances of catching
59 # The following checks are performed:
60 # 1) Verify that the function name provided in a log statement
61 # matches the name of the current function.
63 # 2) Verify that log statements are in the form that this script
64 # can readily parse. Improvements to the regular expressions
65 # might make this unnecessary.
67 # 3) Verify that lower two digits of the error codes used in log
68 # statements are unique within that file.
70 # 4) Verify that upper two digits of the error codes used in log
71 # statements are not used by any other module.
75 # In the OpenSM source directory, type:
79 # Do necessary upfront initialization
83 if( !exists $ARGV[0] )
85 print "ERROR: You must specify the files on which to operate, such as '*.c'\n";
90 # loop through all the command line options
95 # First, look for command line options.
96 if( $ARGV[0] =~ /-[v|V]/ )
100 print "Verbose mode on, level = $verbose.\n";
104 if( !exists $ARGV[0] )
106 print "ERROR: You must specify the files on which to operate, such as '*.c'\n";
110 }while( $doing_params == 1 );
114 # Skip C single line C style comments
115 # This line must come before the multi-line C comment check!
122 # skip multi-line C style comments
129 # end skipping of multi-line C style comments
136 # We're still in a C comment, so ignore input
137 if( $in_c_comment == 1 )
143 # skip C++ style comment lines
149 # check for bad PRIx64 usage
150 # It's a common mistake to forget the % before the PRIx64
151 if( /[^%]\"\s*PRIx64/ )
153 print "No % sign before PRx64!!: $ARGV $.\n";
156 # This simple script doesn't handle checking PRIx64 usage
157 # when PRIx64 starts the line. Just give a warning.
160 print "Warning: PRIx64 at start of line. $ARGV $.\n";
163 # Attempt to locate function names.
164 # Function names must start on the beginning of the line.
170 print "Processing $ARGV: $current_func\n";
174 # Attempt to find OSM_LOG_ENTER entries.
175 # When found, verify that the function name provided matches
176 # the actual function.
177 if( /OSM_LOG_ENTER\s*\(\s*([\-\.\>\w]+)\s*,\s*(\w+)\s*\)/ )
180 if( $current_func ne $log_func )
182 printf "MISMATCH!! $ARGV $.: $current_func != $log_func\n";
186 # Check for non-conforming log statements.
187 # Log statements must not start the log string on the same line
188 # as the osm_log function itself.
189 # Watch out for the #include "osm_log.h" statement as a false positive.
190 if( /osm_log\s*\(.*\"/ )
192 print "NON-CONFORMING LOG STATEMENT!! $ARGV $.\n";
195 # Attempt to find osm_log entries.
199 if( $current_func ne $log_func )
201 print "MISMATCHED LOG FUNCTION!! $ARGV $.: $current_func != $log_func\n";
205 # Error logging must look like 'ERR 1234:'
206 # The upper two digits are error range assigned to that module.
207 # The lower two digits are the error code itself.
208 # Error codes are in hexadecimal.
209 if( /ERR(\s+)([0-9a-fA-F]{2})([0-9a-fA-F]{2})(..)/ )
211 # Check if we already established the error prefix for this module
212 $err_prefix = $module_err_prefixes{$ARGV};
215 if( $err_prefix ne $2 )
217 print "BAD ERR RANGE IN LOG ENTRY!! $ARGV $.: $current_func\n";
218 print "\tExpected $err_prefix but found $2\n";
223 # Create a new prefix for this module.
224 $module_err_prefixes{$ARGV} = $2;
227 $err_base = $module_err_bases{$3};
230 print "DUPLICATE ERR NUMBER IN LOG ENTRY!! $ARGV $.: $current_func: $3\n";
231 print "\tPrevious use on line $err_base.\n";
235 # Add this error code to the list used by this module
236 # The data stored in the line number on which it is used.
237 $module_err_bases{$3} = $.;
240 print "Adding new error: $1$2 in $ARGV.\n";
246 print "MALFORMED LOG STATEMENT!! NEEDS ': ' $ARGV $.\n";
251 print "USE ONLY 1 SPACE AFTER ERR!! $ARGV $.\n";
255 # verify expected use of sizeof() with pointers
256 if( /sizeof\s*\(\s*[h|p]_/ )
258 print "SUSPICIOUS USE OF SIZEOF(), DO YOU NEED AN '*' $ARGV $.\n";
265 # reset the module base error index when we finished out
269 # reset the base error value, since each module can
271 %module_err_bases = ();
272 # closing the file here resets the line number with each new file
280 print "osm_check.pl [-v|V] <file list>\n";
281 print "[-v|V] - enable verbose mode.\n\n";