Example #1
0
 def tearDown(self):
     libxml2.cleanupParser()
     if libxml2.debugMemory(1) != 0:
         libxml2.dumpMemory()
         self.fail("Memory leak %d bytes" % (libxml2.debugMemory(1), ))
     else:
         print("OK")
Example #2
0
 def __del__(self):
     if self.doc != None:
         self.doc.freeDoc()
     libxml2.cleanupParser()
     if libxml2.debugMemory(1) != 0:
         print "Memory leak %d bytes" % (libxml2.debugMemory(1))
         libxml2.dumpMemory()
    def tearDown(self):
        libxml2.cleanupParser()
        if libxml2.debugMemory(1) != 0:
            libxml2.dumpMemory() 
            self.fail("Memory leak %d bytes" % (libxml2.debugMemory(1),))
	else:
	    print "OK"
Example #4
0
    def stop(self):
        sMessage = None
        # Memory debug specific

        libxml2.cleanupParser()
        if libxml2.debugMemory(1) != 0:
            sMessage = _("LIBXML2 Memory leak %d bytes") %\
                       (libxml2.debugMemory(1))
        libxml2.dumpMemory()
        return sMessage
Example #5
0
def publish(base_dir, pub_repo, pub_msg):
    """
    Run the publish application.
    """ 
    libxml2.debugMemory(1)
    
    app = publishApplication(base_dir, 'vcjb.cfg', pub_repo, pub_msg)
    
    app.run()
    
    libxml2.cleanupParser()
    def test_CheckListCreateMemoryTest(self):
        '''Create a checklist with no memory leaks

        libxml2 requires special memory handling.  Check that we can create a
        CheckList and destory it without any memory leaks from the libxml2
        library.
        '''
        self.checklist = checklist.CheckList(os.path.join(self.dataDir,
            'fedoraus.xml'))
        libxml2.cleanupParser()
        self.assert_(libxml2.debugMemory(1) == 0,
                'FAIL: %d bytes leaked' % (libxml2.debugMemory(1)))
        del self.checklist
Example #7
0
def handle_invalid(node, schema):
    global log
    global nb_instances_success
    global nb_instances_failed

    instance = node.prop("dtd")
    if instance == None:
        instance = ""
    child = node.children
    while child != None:
        if child.type != 'text':
            instance = instance + child.serialize()
        child = child.next

    mem = libxml2.debugMemory(1)

    try:
        doc = libxml2.parseDoc(instance)
    except:
        doc = None

    if doc == None:
        log.write("\nStrange: failed to parse incorrect instance:\n-----\n")
        log.write(instance)
        log.write("\n-----\n")
        return

    if debug:
        print "instance line %d" % (node.lineNo())

    try:
        ctxt = schema.relaxNGNewValidCtxt()
        ret = doc.relaxNGValidateDoc(ctxt)
        del ctxt

    except:
        ret = -1

    doc.freeDoc()
    if mem != libxml2.debugMemory(1):
        print "validating instance %d line %d leaks" % (nb_instances_tests,
                                                        node.lineNo())

    if ret == 0:
        log.write(
            "\nFailed to detect validation problem in instance:\n-----\n")
        log.write(instance)
        log.write("\n-----\n")
        nb_instances_failed = nb_instances_failed + 1
    else:
        nb_instances_success = nb_instances_success + 1
def handle_invalid(node, schema):
    global log
    global nb_instances_success
    global nb_instances_failed

    instance = node.prop("dtd")
    if instance == None:
        instance = ""
    child = node.children
    while child != None:
        if child.type != 'text':
	    instance = instance + child.serialize()
	child = child.next

    mem = libxml2.debugMemory(1);

    try:
	doc = libxml2.parseDoc(instance)
    except:
        doc = None

    if doc == None:
        log.write("\nStrange: failed to parse incorrect instance:\n-----\n")
	log.write(instance)
        log.write("\n-----\n")
	return

    if debug:
        print "instance line %d" % (node.lineNo())
       
    try:
        ctxt = schema.relaxNGNewValidCtxt()
	ret = doc.relaxNGValidateDoc(ctxt)
	del ctxt

    except:
        ret = -1

    doc.freeDoc()
    if mem != libxml2.debugMemory(1):
	print "validating instance %d line %d leaks" % (
		  nb_instances_tests, node.lineNo())
    
    if ret == 0:
        log.write("\nFailed to detect validation problem in instance:\n-----\n")
	log.write(instance)
        log.write("\n-----\n")
	nb_instances_failed = nb_instances_failed + 1
    else:
	nb_instances_success = nb_instances_success + 1
Example #9
0
 def setUp(self):
     #
     # Set up Libxml2.
     #
     self.initialMemUsed = libxml2.debugMemory(1)
     libxml2.initParser()
     libxml2.lineNumbersDefault(1)
     libxml2.registerErrorHandler(handleError, self)
Example #10
0
	def setUp(self):
		#
		# Set up Libxml2.
		#
		self.initialMemUsed = libxml2.debugMemory(1)
		libxml2.initParser()
		libxml2.lineNumbersDefault(1)
		libxml2.registerErrorHandler(handleError, self)
Example #11
0
    def collect_figures(self):
        libxml2.cleanupParser()
        gc.collect()

        figures = []
        figures.append(("Objects in gc.garbage", len(gc.garbage), ""))
        figures.append(("libxml2 memory leak", libxml2.debugMemory(1), "bytes"))
        return figures
Example #12
0
def main():
    o = OptionParser()
    o.add_option("-s", "--safe",
                 dest="safe",
                 action="store_true",
                 help="Safe mode (ignore configuration)")
    o.add_option("-c", "--config",
                 dest="config",
                 help="Use alternate configuration directory")
    o.add_option("-p", "--profile",
                 dest="profile",
                 action="store_true",
                 help="Enable profiling")
    (opts, args) = o.parse_args()

    from d_rats import platform

    if opts.config:
        platform.get_platform(opts.config)

    from d_rats import mainapp

    install_excepthook()

    import libxml2

    libxml2.debugMemory(1)

    app = mainapp.MainApp(safe=opts.safe)
    if opts.profile:
        import cProfile
        cProfile.run('app.main()')
    else:
        rc = app.main()
        uninstall_excepthook()
        libxml2.dumpMemory()
        sys.exit(rc)
Example #13
0
import libxml2
try:
    import StringIO
    str_io = StringIO.StringIO
except:
    import io
    str_io = io.StringIO

docstr="""<?xml version='1.0'?>
<!DOCTYPE doc [
<!ENTITY tst "<p>test</p>">
]>
<doc>&tst;</doc>"""

# Memory debug specific
libxml2.debugMemory(1)

#
# First test, normal don't substitute entities.
#
f = str_io(docstr)
input = libxml2.inputBuffer(f)
reader = input.newTextReader("test_noent")
ret = reader.Read()
if ret != 1:
    print("Error reading to root")
    sys.exit(1)
if reader.Name() == "doc" or reader.NodeType() == 10:
    ret = reader.Read()
if ret != 1:
    print("Error reading to root")
Example #14
0
ARG = 'test string'


class ErrorHandler:
    def __init__(self):
        self.errors = []

    def handler(self, msg, data):
        if data != ARG:
            raise Exception("Error handler did not receive correct argument")
        self.errors.append(msg)


# Memory debug specific
libxml2.debugMemory(1)

schema = """<?xml version="1.0" encoding="iso-8859-1"?>
<schema xmlns = "http://www.w3.org/2001/XMLSchema">
	<element name = "Customer">
		<complexType>
			<sequence>
				<element name = "FirstName" type = "string" />
				<element name = "MiddleInitial" type = "string" />
				<element name = "LastName" type = "string" />
			</sequence>
			<attribute name = "customerID" type = "integer" />
		</complexType>
	</element>
</schema>"""
Example #15
0
    def start(self):
        # Memory debug specific
        libxml2.debugMemory(1)

        # init error handler
        libxml2.registerErrorHandler(noerr, None)
Example #16
0
#!/usr/bin/python
import sys, libxml2

libxml2.debugMemory(True)

expect="""--> Invalid expression
--> xmlXPathEval: evaluation failed
--> Invalid expression
--> xmlXPathEval: evaluation failed
--> Invalid expression
--> xmlXPathEval: evaluation failed
--> Invalid expression
--> xmlXPathEval: evaluation failed
--> Invalid expression
--> xmlXPathEval: evaluation failed
--> Invalid expression
--> xmlXPathEval: evaluation failed
"""
err=""
def callback(ctx, str):
     global err

     err = err + "%s %s" % (ctx, str)

libxml2.registerErrorHandler(callback, "-->")

doc = libxml2.parseDoc("<fish/>")
ctxt = doc.xpathNewContext()
ctxt.setContextNode(doc)
for expr in (":false()","bad:()","bad(:)",":bad(:)","bad:(:)","bad:bad(:)"):
	try:
Example #17
0
# knowledge of the CeCILL license and that you accept its terms.
#
# For more information, see the file COPYING

import sys, pprint
import libxml2
import os.path

from classRepresentation.packageGiws import packageGiws
from classRepresentation.objectGiws import objectGiws
from classRepresentation.methodGiws import methodGiws
from classRepresentation.parameterGiws import parameterGiws
from classRepresentation.returnDataGiws import returnDataGiws
from datatypes.dataFactoryGiws import dataFactoryGiws

libxml2.debugMemory(1)


class parseXMLEngine:
    __ctxt = None
    Jpackage = None

    def __init__(self, descFile):
        if os.path.isfile(descFile) != True:
            print('Could not find declaration file "%s"' % descFile)
            sys.exit(-2)
        try:
            doc = libxml2.parseFile(descFile)
        except libxml2.parserError:
            print('Error while parsing XML file "%s"' % descFile)
            sys.exit(-3)
 def setUp(self):
     libxml2.debugMemory(1)
Example #19
0
    # import the platform module - this will setup all the proper parameters for the different OSs
    from d_rats import platform

    if opts.config:
        print "D-Rats: re-config option found -- Reconfigure D-rats"
        platform.get_platform(opts.config)

    # import the D-Rats main application
    from d_rats import mainapp

    #stores away the value of sys.excepthook
    install_excepthook()

    import libxml2
    libxml2.debugMemory(1)


    # create the mainapp with the basic options 
    app = mainapp.MainApp(safe=opts.safe)


    # finally let's open the default application triggering it differently if we 
    # want to profile it (which is running the app under profile control to see what happens) 
    if opts.profile :
        import cProfile
        cProfile.run('app.main()')
    else:
        #execute the main app
        rc = app.main()
        #restores  the original value of sys.excepthook
Example #20
0
 def newfunc(*args, **kwargs):
     libxml2.debugMemory(1)
     testfunction(*args, **kwargs)
     libxml2.cleanupParser()
     leaked_bytes = libxml2.debugMemory(0) 
     assert leaked_bytes == 0, "libxml2 memory leak detected: %d bytes" % leaked_bytes
 def setUp(self):
     libxml2.debugMemory(1)
     self.dataDir = os.path.join(test.srcdir, '..', 'data')
Example #22
0
 def setUp(self):
     libxml2.debugMemory(1)
Example #23
0
#!/usr/bin/python
import sys, libxml2

libxml2.debugMemory(True)

expect = """--> Invalid expression
--> Invalid expression
--> Invalid expression
--> Invalid expression
--> Invalid expression
--> Invalid expression
--> Invalid expression
--> Invalid expression
--> Invalid expression
--> Invalid expression
"""
err = ""


def callback(ctx, str):
    global err

    err = err + "%s %s" % (ctx, str)


libxml2.registerErrorHandler(callback, "-->")

doc = libxml2.parseDoc("<fish/>")
ctxt = doc.xpathNewContext()
ctxt.setContextNode(doc)
badexprs = (":false()", "bad:()", "bad(:)", ":bad(:)", "bad:(:)", "bad:bad(:)",
Example #24
0
	def tearDown(self):
		libxml2.schemaCleanupTypes()
		libxml2.cleanupParser()
		self.memLeak = libxml2.debugMemory(1) - self.initialMemUsed
 def tearDown(self):
     libxml2.debugMemory(0)
Example #26
0
 def engine_started(self):
     libxml2.debugMemory(1)
Example #27
0
 def tearDown(self):
     libxml2.schemaCleanupTypes()
     libxml2.cleanupParser()
     self.memLeak = libxml2.debugMemory(1) - self.initialMemUsed