diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-03-04 14:51:23 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-03-04 14:51:23 +0000 |
commit | 99aa8c60282c7b8072eb35eb9ac815702f5bf586 (patch) | |
tree | bda96bf8c3a4c2875a083d7b16720533c8ffeaf4 /ACE/bin/PythonACE/fuzz | |
parent | c4078c377d74290ebe4e66da0b4975da91732376 (diff) | |
download | ATCD-99aa8c60282c7b8072eb35eb9ac815702f5bf586.tar.gz |
undoing accidental deletion
Diffstat (limited to 'ACE/bin/PythonACE/fuzz')
21 files changed, 608 insertions, 0 deletions
diff --git a/ACE/bin/PythonACE/fuzz/__init__.py b/ACE/bin/PythonACE/fuzz/__init__.py new file mode 100644 index 00000000000..26a7b9a3faf --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/__init__.py @@ -0,0 +1,97 @@ +""" This init script loads all python modules in the current directory that + do not start with an '_', loads them as a module""" + +file_type_handlers = dict () + +def register_handler (module): + + for item in module.type_list: + if file_type_handlers.has_key (item): + file_type_handlers[item].append (module.handler) + else: + handlers = list () + handlers.append (module.handler) + file_type_handlers[item] = handlers + +import re + +extension_re = re.compile(".+\.([^.]+)$") + + + +# The following is the initialization logic that is executed +# when the fuzz module is loaded +from os import listdir, chdir, getcwd +from sys import stderr, path +oldwd = getcwd () + +try: + # The following is a trick to get the directory THIS SCRIPT - note, not necessarily the CWD - + # is located. We use this path later to load all of the available fuzz checks. + import _path + script_path = str (_path).split ()[3][1:-11] + if script_path == "": + script_path = "." + + chdir (script_path) + + path.append (getcwd ()) + + files = listdir (".") + + modules = list () + + # We need to import the warning handler here. If we use a traditional import elsewhere, + # we get all kinds of problems with the warning_handler being imported twice - once as + # fuzz._warning_handler and again as _warning_handler - making the singleton instances + # NOT the same. + _warning_handler = __import__ ("_warning_handler") + Warning_Handler = _warning_handler.Warning_Handler + STDERR = _warning_handler.STDERR + MAILER = _warning_handler.MAILER + + for item in files: + if (item[0] != '_') and (item[-3:] == ".py"): + print "Registering " + item [:-3] + try: + module = __import__ (item[:-3]) + register_handler (module) + except: + stderr.write ("FUZZ ERROR: Unable to load the " + item[:-3] + " module, please notify the build czar\n") + +finally: + chdir (oldwd) + + +def fuzz_check (file_name, file_content): + # If the user of the module has not instanciated the warning handler, + # lets do it here + if not Warning_Handler._isInstantiated (): + Warning_Handler.getInstance (STDERR) + + # get the file extension + ext_match = extension_re.search (file_name) + if ext_match == None: + # we don't have no stinking file extension! + ext = "" + else: + ext = ext_match.group (1) + + retval = 0 + + if file_type_handlers.has_key (ext): + for handler in file_type_handlers[ext]: + try: # We don't want one misbehaving handler to screw up the whole sustem + retval += handler (file_name, file_content) + except: + stderr.write ("An unknown exception was thrown while trying to run one of the handlers\n") + + # Run the generic handlers + for handler in file_type_handlers["*"]: + try: # We don't want one misbehaving handler to screw up the whole sustem + retval += handler (file_name, file_content) + except: + stderr.write ("An unknown exception was thrown while trying to run one of the handlers\n") + + + return retval diff --git a/ACE/bin/PythonACE/fuzz/_fuzz.py b/ACE/bin/PythonACE/fuzz/_fuzz.py new file mode 100644 index 00000000000..5dccaa8136e --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/_fuzz.py @@ -0,0 +1,3 @@ +""" Defines the fuzz_check function """ + + diff --git a/ACE/bin/PythonACE/fuzz/_generic_handler.py b/ACE/bin/PythonACE/fuzz/_generic_handler.py new file mode 100644 index 00000000000..ffc7bc10167 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/_generic_handler.py @@ -0,0 +1,44 @@ +""" Defines a generic handler that tests against a given regex, and allows for exclusions. """ + +from sys import stderr +import _warning_handler + +def generic_handler (regex, begin_exclude, end_exclude, error_message, file_name, file_content, warn = False): + retval = 0 + + if regex.search (file_content) != None: + # We have a potential violation, lets check + lines = file_content.splitlines () + exclusion = False + for line in range (len (lines)): + if begin_exclude.search (lines[line]) != None: + exclusion = True + elif end_exclude.search (lines[line]) != None: + exclusion = False + elif (exclusion == False) and (regex.search (lines[line]) != None): + # Violation! + msg = file_name + ':' + str (line + 1) + error_message + if not warn: + stderr.write (msg) + retval = 1 + else: + handler = _warning_handler.Warning_Handler.getInstance () + handler.add_warning (msg) + return retval + +def generic_handler_no_exceptions (regex, error_message, file_name, file_content, warn = False): + retval = 0 + + if regex.search (file_content) != None: + # We have a potential violation, lets check + lines = file_content.splitlines () + for line in range (len (lines)): + if regex.search (lines[line]) != None: + msg = file_name + ':' + str (line + 1) + error_message + # Violation! + if not warn: + stderr.write (msg) + retval = 1 + else: + Warning_Handler.getInstance ().add_warning (msg) + return retval diff --git a/ACE/bin/PythonACE/fuzz/_mailer.py b/ACE/bin/PythonACE/fuzz/_mailer.py new file mode 100644 index 00000000000..6e33cc82c9e --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/_mailer.py @@ -0,0 +1,106 @@ +""" This module implements a mailer to mail a user about fuzz warnings """ + +import _singleton + +def ldap_lookup (username): + """ Performs a ldap lookup to find the email address associated with + username. If none exists, it returns the empty string.""" + import ldap + + try: + conn = ldap.open ("ldap.dre.vanderbilt.edu") + conn.protocol_version = ldap.VERSION3 + + baseDN = "dc=dre,dc=vanderbilt,dc=edu" + scope = ldap.SCOPE_SUBTREE + attrFilter = None + searchFilter = "uid=" + username + + result = conn.search (baseDN, scope, searchFilter, attrFilter) + + result_type, result_data = conn.result (result, 0) + email = "" + if (result_data != []) and (result_type == ldap.RES_SEARCH_ENTRY): + # we have a valid result! + if (result_data[0][1].has_key ('mail')): + email = result_data[0][1]['mail'][0] + elif (result_data[0][1].has_key ('svnmail')): + email = result_data[0][1]['svnmail'][0] + else: + email = "" + + conn.unbind () + + return email + except: + # Some error occurred when looking this guy up. + return "" + + + +class Mailer: + def __init__ (self): + self.recipient = "" + self.body = """\ +This is an automatically generated message from the fuzz check system +in the subversion repository. + +Your recent commit to the ACE/TAO/CIAO repository had a number of warnings +which should be addressed. + +""" + self.warnings = "" + self.subject = "Your recent commit to the DOC group repository." + self.sent = False + + def get_messages (self): + return self.warnings + def open (self, ldap_user_name): + from sys import stderr + stderr.write ("LDAP Name: " + ldap_user_name.rstrip () + "\n") + self.recipient = ldap_lookup (ldap_user_name.rstrip ()) + + def add_warning (self, warning_text): + self.warnings += warning_text + + def close (self): + try: + message = """\ +From: %s +To: %s +Subject: %s +\r\n +%s +""" % ("bczar@dre.vanderbilt.edu", + self.recipient, + self.subject, + self.body + self.warnings) + + print message + + import smtplib + server = smtplib.SMTP('discovery.isis.vanderbilt.edu') + server.sendmail ("bczar@dre.vanderbilt.edu", + [self.recipient], + message) + except smtplib.SMTPRecipientsRefused: + print "Recipients refused exception" + server.close () + except smtplib.SMTPHeloError: + print "Helo error" + server.close () + except smtplib.SMTPSenderRefused: + print "Sender refused" + server.close () + except smtplib.SMTPDataError: + print "Data error" + server.close () + except: + from sys import stderr + stderr.write ("Caught exception while sending email\n") + server.close () + + + + + diff --git a/ACE/bin/PythonACE/fuzz/_path.py b/ACE/bin/PythonACE/fuzz/_path.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/_path.py diff --git a/ACE/bin/PythonACE/fuzz/_singleton.py b/ACE/bin/PythonACE/fuzz/_singleton.py new file mode 100644 index 00000000000..f7a686d4988 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/_singleton.py @@ -0,0 +1,60 @@ +""" Implements a singleton mixin class """ + +# The following code was written by Gary Robinson +# (grobinson@transpose.com) and placed in the public domain. His +# copyright notice is as follows: + +# By Gary Robinson, grobinson@transpose.com. No rights reserved -- +# placed in the public domain -- which is only reasonable considering +# how much it owes to other people's version which are in the +# public domain. The idea of using a metaclass came from +# a comment on Gary's blog (see +# http://www.garyrobinson.net/2004/03/python_singleto.html#comments). +# Other improvements came from comments and email from other +# people who saw it online. (See the blog post and comments +# for further credits.) + +# Not guaranteed to be fit for any particular purpose. Use at your +# own risk. + + +class SingletonException(Exception): + pass + +class MetaSingleton(type): + def __new__(metaclass, strName, tupBases, dict): + if dict.has_key('__new__'): + raise SingletonException, 'Can not override __new__ in a Singleton' + return super(MetaSingleton,metaclass).__new__(metaclass, strName, tupBases, dict) + + def __call__(cls, *lstArgs, **dictArgs): + raise SingletonException, 'Singletons may only be instantiated through getInstance()' + +class Singleton(object): + __metaclass__ = MetaSingleton + + def getInstance(cls, *lstArgs): + """ + Call this to instantiate an instance or retrieve the existing instance. + If the singleton requires args to be instantiated, include them the first + time you call getInstance. + """ + if cls._isInstantiated(): + if len(lstArgs) != 0: + raise SingletonException, 'If no supplied args, singleton must already be instantiated, or __init__ must require no args' + else: + if cls._getConstructionArgCountNotCountingSelf() > 0 and len(lstArgs) <= 0: + raise SingletonException, 'If the singleton requires __init__ args, supply them on first instantiation' + instance = cls.__new__(cls) + instance.__init__(*lstArgs) + cls.cInstance = instance + return cls.cInstance + getInstance = classmethod(getInstance) + + def _isInstantiated(cls): + return hasattr(cls, 'cInstance') + _isInstantiated = classmethod(_isInstantiated) + + def _getConstructionArgCountNotCountingSelf(cls): + return cls.__init__.im_func.func_code.co_argcount - 1 + _getConstructionArgCountNotCountingSelf = classmethod(_getConstructionArgCountNotCountingSelf) diff --git a/ACE/bin/PythonACE/fuzz/_types.py b/ACE/bin/PythonACE/fuzz/_types.py new file mode 100644 index 00000000000..d5cb851c440 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/_types.py @@ -0,0 +1,6 @@ +""" Defines a number of file extension groupings """ + +source_files = ["c", "cc", "cpp", "cxx"] +header_files = ["h", "cc", "cpp", "cxx"] +inline_files = ["i", "ipp", "inl", "ixx"] +idl_files = ["idl"] diff --git a/ACE/bin/PythonACE/fuzz/_warning_handler.py b/ACE/bin/PythonACE/fuzz/_warning_handler.py new file mode 100644 index 00000000000..f88b43a0782 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/_warning_handler.py @@ -0,0 +1,53 @@ +""" Implements a warning handler base class and a simple handler that simply + outputs warnings to stderr. """ + +import _singleton + +# Constants +STDERR = 1 +MAILER = 2 + +from sys import stderr + +class Warning_Handler (_singleton.Singleton): + def __init__(self, handlertype=STDERR): + """ Constructor. Type should be either STDERR or MAILER. + There are probably better ways to do this, but it is implemented + this way because I only wanted to have a dependancy on ldap if someone + actually wanted to use the mailer. """ + super (Warning_Handler, self).__init__ () + self.messages = "" + self.add_warning = self.default_add_warning + self.close = self.default_close + self.open = self.default_open + + if handlertype is STDERR: + self.add_warning = self.stderr_add_warning + elif handlertype is MAILER: + from _mailer import Mailer + self.handler = Mailer () + self.add_warning = self.handler.add_warning + self.open = self.handler.open + self.close = self.handler.close + self.get_messages = self.handler.get_messages + else: + self.add_warning = self.stderr_add_warning + + def default_add_warning (self, warning_text): + pass + + def default_open (self, arg = ""): + pass + + def default_close (self, arg = ""): + pass + + def get_messages (self): + return self.messages + + def stderr_add_warning (self, warning_text): + stderr.write (warning_text) + return + + + diff --git a/ACE/bin/PythonACE/fuzz/check_includes.py b/ACE/bin/PythonACE/fuzz/check_includes.py new file mode 100644 index 00000000000..7fd8e744c90 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/check_includes.py @@ -0,0 +1,20 @@ +""" Checks that includes of files in ace/tao/ciao use "" instead of <> """ + +import _types +type_list = _types.source_files + _types.header_files + _types.inline_files + _types.idl_files + +from sys import stderr +import re + +regex = re.compile ("\s*#\s*include\s*(\/\*\*\/){0,1}\s*<(ace|tao|ciao|TAO|CIAO).*>") +begin_exclude = re.compile ("FUZZ\: disable check_for_include") +end_exclude = re.compile ("FUZZ\: enable check_for_include") + +error_message = ": error: contains an include to ace/tao/ciao code using <>, instead of \"\"\n" + +from _generic_handler import generic_handler + +def handler (file_name, file_content): + return generic_handler (regex, begin_exclude, end_exclude, error_message, file_name, file_content) + + diff --git a/ACE/bin/PythonACE/fuzz/cpp_inline.py b/ACE/bin/PythonACE/fuzz/cpp_inline.py new file mode 100644 index 00000000000..1db614c103b --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/cpp_inline.py @@ -0,0 +1,23 @@ +""" Checks for ACE_INLINE or and ASYS_INLINE in a .cpp file """ +from _types import source_files +type_list = source_files + + +import re +from sys import stderr +regex = re.compile ("(^\s*ACE_INLINE)|(^\s*ASYS_INLINE)", re.MULTILINE) + +error_message = ": error: ACE_INLINE or ASYS_INLINE found in .cpp file\n" + +def handler (file_name, file_content): + if regex.search (file_content) != None: + # Lets take some time to generate a detailed error report + # since we appear to have a violation + lines = file_content.splitlines () + for line in range (len (lines)): + if regex.search (lines[line]) != None: + stderr.write (file_name + ':' + str (line + 1) + error_message) + + return 1 + else: + return 0 diff --git a/ACE/bin/PythonACE/fuzz/inline.py b/ACE/bin/PythonACE/fuzz/inline.py new file mode 100644 index 00000000000..c981289d105 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/inline.py @@ -0,0 +1,19 @@ +""" Checks that the C++ inline keyword is not used """ + +from _types import inline_files +type_list = inline_files + +from sys import stderr +import re + +regex = re.compile ("(\s|^)+inline\s+") +begin_exclude = re.compile ("FUZZ\: disable check_for_inline") +end_exclude = re.compile ("FUZZ\: enable check_for_inline") + +error_message = ": error: contains a C++ inline keyword, instead of ACE_INLINE\n" + +from _generic_handler import generic_handler + +def handler (file_name, file_content): + return generic_handler (regex, begin_exclude, end_exclude, error_message, file_name, file_content) + diff --git a/ACE/bin/PythonACE/fuzz/math_include.py b/ACE/bin/PythonACE/fuzz/math_include.py new file mode 100644 index 00000000000..cedbddb0b31 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/math_include.py @@ -0,0 +1,19 @@ +""" Checks that the C++ inline keyword is not used """ + +import _types +type_list = _types.source_files + _types.header_files + _types.inline_files + +from sys import stderr +import re + +regex = re.compile ("^\s*#\s*include\s*(\/\*\*\/){0,1}\s*\<math\.h\>") +begin_exclude = re.compile ("FUZZ\: disable check_math_include") +end_exclude = re.compile ("FUZZ\: enable check_math_include") + +error_message = ": error: contains an include to math.h\n" + +from _generic_handler import generic_handler + +def handler (file_name, file_content): + return generic_handler (regex, begin_exclude, end_exclude, error_message, file_name, file_content) + diff --git a/ACE/bin/PythonACE/fuzz/max_filename.py b/ACE/bin/PythonACE/fuzz/max_filename.py new file mode 100644 index 00000000000..26932064258 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/max_filename.py @@ -0,0 +1,16 @@ +""" Checks that filenames are the correct length """ + +type_list = ["*"] + +max_filename_length = 50 + +from os.path import split +from sys import stderr + +def handler (file_name, file_content): + path, filename = split (file_name) + if len (filename) >= max_filename_length: + stderr.write (file_name + ":0: error: File name meets or exceeds maximum allowable length (" + + str (max_filename_length) + ")\n") + return 1 + return 0 diff --git a/ACE/bin/PythonACE/fuzz/max_project_len.py b/ACE/bin/PythonACE/fuzz/max_project_len.py new file mode 100644 index 00000000000..e00c7937026 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/max_project_len.py @@ -0,0 +1,27 @@ +""" Checks that project names are not too long """ + +from max_filename import max_filename_length + +type_list = ["mpc"] + +max_proj_len = max_filename_length - 12 # GNUmakefile. + +from sys import stderr +import re + +regex = re.compile ("\s*project\s*\((\w+)\)") + +def handler (file_name, file_content): + match = regex.search (file_content) + if match == None: + return 0 + else: + for group in match.groups (): + if (len (group) >= max_proj_len): + stderr.write (file_name + ":0: error: Project named " + group + + " meets or exceeds the maximum project name length of " + + str (max_proj_len) + " characters\n") + + return 1 + + diff --git a/ACE/bin/PythonACE/fuzz/newline.py b/ACE/bin/PythonACE/fuzz/newline.py new file mode 100644 index 00000000000..39847e05c65 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/newline.py @@ -0,0 +1,17 @@ +""" Checks that the file has a newline at the end. """ + +type_list = ["cpp", "h", "inl", "html", "idl", "pl"] + +import re +from sys import stderr + +regex = re.compile ("\n\Z") + +def handler (file_name, file_content): + if regex.search (file_content) == None: + stderr.write (file_name + ":0: error: " + file_name + " lacks a newline at the end of the file.\n") + return 1 + else: + return 0 + + diff --git a/ACE/bin/PythonACE/fuzz/no_conflict_markers.py b/ACE/bin/PythonACE/fuzz/no_conflict_markers.py new file mode 100644 index 00000000000..62066b42333 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/no_conflict_markers.py @@ -0,0 +1,20 @@ +""" Checks that the file does not contain SVN conflict markers """ + + +type_list = ["*"] + +from sys import stderr +import re + +regex = re.compile ("^<<<<<<< \.|>>>>>>> \.r|^=======$", re.MULTILINE) +begin_exclude = re.compile ("FUZZ\: disable conflict_marker_check") +end_exclude = re.compile ("FUZZ\: enable conflict_marker_check") + +error_message = ": error: contains a SVN conflict marker. Please resolve the conflict before committing.\n" + +from _generic_handler import generic_handler + +def handler (file_name, file_content): + return generic_handler (regex, begin_exclude, end_exclude, error_message, file_name, file_content) + + diff --git a/ACE/bin/PythonACE/fuzz/noncvs.py b/ACE/bin/PythonACE/fuzz/noncvs.py new file mode 100644 index 00000000000..de52422c80d --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/noncvs.py @@ -0,0 +1,12 @@ +""" Catches most files disallowed in CVS """ + +type_list = ["icc", "ncb", "opt", "zip", "dsw", + "vcproj", "dsw", "bor", "vcp", "pdb", + "o", "ilk", "pyc", "so", "dll", "lib" ] + +from sys import stderr + +def handler (file_name, file_content): + stderr.write (file_name + ":0: error: This file should not be checked into the repository\n") + return 1 + diff --git a/ACE/bin/PythonACE/fuzz/ptr_arith_t.py b/ACE/bin/PythonACE/fuzz/ptr_arith_t.py new file mode 100644 index 00000000000..4ee73babb43 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/ptr_arith_t.py @@ -0,0 +1,17 @@ +""" Checks that ptr_arith_t usage in source code. ptr_arithh_t is non-portable + use ptrdiff_t instead. """ + +import _types +type_list = _types.source_files + _types.header_files + _types.inline_files + +from sys import stderr +import re + +regex = re.compile ("(ptr_arith_t )|(ptr_arith_t,)") +error_message = ": error: contains a non portable reference to ptr_arith_t, use ptrdiff_t instead.\n" + +from _generic_handler import generic_handler_no_exceptions + +def handler (file_name, file_content): + return generic_handler_no_exceptions (regex, error_message, file_name, file_content) + diff --git a/ACE/bin/PythonACE/fuzz/refcountservantbase.py b/ACE/bin/PythonACE/fuzz/refcountservantbase.py new file mode 100644 index 00000000000..31d8d5bb3a9 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/refcountservantbase.py @@ -0,0 +1,17 @@ +""" Checks that an obsolete PortableServer::RefCountServantBase is not used """ + +from _types import header_files +type_list = header_files + +from sys import stderr +import re + +regex = re.compile ("RefCountServantBase") + +error_message = ": error: reference to deprecated PortableServer::RefCountServantBase\n" + +from _generic_handler import generic_handler_no_exceptions + +def handler (file_name, file_content): + return generic_handler_no_exceptions (regex, error_message, file_name, file_content) + diff --git a/ACE/bin/PythonACE/fuzz/streams_include.py b/ACE/bin/PythonACE/fuzz/streams_include.py new file mode 100644 index 00000000000..24def75fd66 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/streams_include.py @@ -0,0 +1,19 @@ +""" Checks for inclusion of a non efficient streams include """ + +import _types +type_list = _types.source_files +_types. header_files + _types.inline_files + +import re + +regex = re.compile ("^\s*#\s*include\s*(\/\*\*\/){0,1}\s*\"ace\/streams\.h\"") +begin_exclude = re.compile ("FUZZ\: disable check_for_streams_include") +end_exclude = re.compile ("FUZZ\: enable check_for_streams_include") + +error_message = ": warning: expensive ace/streams.h included; consider ace/iosfwd.h\n" + +from _generic_handler import generic_handler +def handler (file_name, file_content): + return generic_handler (regex, begin_exclude, + end_exclude, error_message, + file_name, file_content, True) + diff --git a/ACE/bin/PythonACE/fuzz/verify_changelog.py b/ACE/bin/PythonACE/fuzz/verify_changelog.py new file mode 100644 index 00000000000..b84f2b3d147 --- /dev/null +++ b/ACE/bin/PythonACE/fuzz/verify_changelog.py @@ -0,0 +1,13 @@ +""" Verifies that changelogs obey certain properties """ + +type_list = [""] + +from sys import stderr +import re + +backslashes = re.compile ("") + +def handler (filename, filetext): + return 0 + + |