[asterisk-commits] sgriepentrog: branch sgriepentrog/testsuite-valgrind r4355 - in /asterisk/tea...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 21 16:27:14 CST 2013


Author: sgriepentrog
Date: Thu Nov 21 16:27:13 2013
New Revision: 4355

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4355
Log:
Fixed AMI timeout; significant enhancements to stack trace output

Modified:
    asterisk/team/sgriepentrog/testsuite-valgrind/lib/python/asterisk/asterisk.py
    asterisk/team/sgriepentrog/testsuite-valgrind/runtests.py

Modified: asterisk/team/sgriepentrog/testsuite-valgrind/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/sgriepentrog/testsuite-valgrind/lib/python/asterisk/asterisk.py?view=diff&rev=4355&r1=4354&r2=4355
==============================================================================
--- asterisk/team/sgriepentrog/testsuite-valgrind/lib/python/asterisk/asterisk.py (original)
+++ asterisk/team/sgriepentrog/testsuite-valgrind/lib/python/asterisk/asterisk.py Thu Nov 21 16:27:13 2013
@@ -265,8 +265,6 @@
         """
 
         def __start_asterisk_callback():
-            if self.valgrind:
-                logger.info("Running Asterisk under valgrind")
             self.processProtocol = AsteriskProtocol(self.host, self.__stop_deferred)
             self.process = reactor.spawnProcess(self.processProtocol,
                                                 self.cmd[0],
@@ -285,8 +283,10 @@
 
         def __wait_fully_booted_error(cli_command):
             """ Errback for CLI command waitfullybooted """
-            if time.time() - self.__start_asterisk_time > 5:
-                logger.error("Asterisk core waitfullybooted for %s failed" % self.host)
+            max_wait_time = 20
+            if time.time() - self.__start_asterisk_time > max_wait_time:
+                logger.error("Asterisk core waitfullybooted for %s failed and max wait time of %d seconds exceeded" %
+                    (self.host, max_wait_time))
                 self.__start_deferred.errback(Exception("Command core waitfullybooted failed"))
             else:
                 logger.debug("Asterisk core waitfullybooted failed, attempting again...")
@@ -305,16 +305,24 @@
             self.valgrind_log_filename = os.path.join(self.base, "valgrind.txt")
             self.valgrind_xml_filename = os.path.join(self.base, "valgrind.xml")
             self.valgrind_supp_filename = os.path.join(self.base, "etc/asterisk/valgrind.supp")
+
             if os.path.exists(self.valgrind_supp_filename):
                 logger.info("Using the valgrind suppression file %s" % (self.valgrind_supp_filename))
-                self.cmd = ["valgrind", "--log-file=%s" % (self.valgrind_log_filename), "--xml=yes",
-                            "--xml-file=%s" % (self.valgrind_xml_filename), "--suppressions=%s" % (
-                            self.valgrind_supp_filename), "--leak-check=full"] + self.cmd
-            else:
-                logger.info("Valgrind Suppression file does not exist %s" % (os.path.dirname(self.valgrind_supp_filename)))
-                self.cmd = ["valgrind", "--log-file=%s" % (self.valgrind_log_filename), "--xml=yes",
-                            "--xml-file=%s" % (self.valgrind_xml_filename), "--leak-check=full"] + self.cmd
-	print "Asterisk binary command [%s]" % (self.cmd) 
+                self.cmd = [ "--suppressions=%s" % (self.valgrind_supp_filename) ] + self.cmd
+
+            self.cmd = [
+                "valgrind",
+                "--log-file=%s" % (self.valgrind_log_filename),
+                "--xml=yes",
+                "--xml-file=%s" % (self.valgrind_xml_filename),
+                "--num-callers=50",
+                "--leak-check=full",
+#                "--show-possibly-list=no",
+#                "--show-reachable=yes",
+                "--gen-suppressions=all",
+            ] + self.cmd
+
+        print "Asterisk binary command [%s]" % (self.cmd) 
 
         # Make the start/stop deferreds - this method will return
         # the start deferred, and pass the stop deferred to the AsteriskProtocol

Modified: asterisk/team/sgriepentrog/testsuite-valgrind/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/sgriepentrog/testsuite-valgrind/runtests.py?view=diff&rev=4355&r1=4354&r2=4355
==============================================================================
--- asterisk/team/sgriepentrog/testsuite-valgrind/runtests.py (original)
+++ asterisk/team/sgriepentrog/testsuite-valgrind/runtests.py Thu Nov 21 16:27:13 2013
@@ -190,6 +190,103 @@
                 break
             i += 1
 
+    def __parse_valgrind_xml_doc(self, xmldoc):
+        count_bytes_leaked = 0
+        count_errors_found = 0
+        count_error_kinds = {}
+        code = {}
+        try:
+            error_list = xmldoc.getElementsByTagName('error')
+            count_errors_found = len(error_list)
+
+            def getText(nodelist):
+                text = []
+                for node in nodelist:
+                    if node.nodeType == node.ELEMENT_NODE:
+                        text.append(getText(node.childNodes))
+                    if node.nodeType == node.TEXT_NODE:
+                        text.append(str(node.data))
+                return ''.join(text)
+
+            def arrange_frames_by_code(tree, frames, error):
+                frame = frames[0]
+                fn = getText(frame.getElementsByTagName('fn'))
+                dir = getText(frame.getElementsByTagName('dir'))
+                file = getText(frame.getElementsByTagName('file'))
+                line = getText(frame.getElementsByTagName('line'))
+                obj = getText(frame.getElementsByTagName('obj'))
+
+                if "" == file:
+                    codefile = "{" + obj + "} " + fn + "()"
+                else:
+                    codefile = dir + "/" + file + " " + fn + "()"
+
+                errortag = error + " at line " + line
+
+                if not codefile in tree:
+                    tree[codefile] = {}
+
+                if 1 == len(frames):
+                    tree[codefile][errortag] = {}
+                else:
+                    arrange_frames_by_code(tree[codefile], frames[1:], error)
+
+            for error in error_list:
+                kind = getText(error.getElementsByTagName('kind'))
+                what = getText(error.getElementsByTagName('what'))
+
+                if kind == "Leak_DefinitelyLost":
+                    leaked_bytes = error.getElementsByTagName('leakedbytes')
+                    if len(leaked_bytes) == 1:
+                        dom_element = leaked_bytes[0]
+                        count_bytes_leaked += int(dom_element.childNodes[0].nodeValue)
+
+                stacks = error.getElementsByTagName('stack')
+                stack = stacks[0]
+                frames = stack.getElementsByTagName('frame')
+
+                arrange_frames_by_code(code, frames[::-1],
+                    "[" + kind + "] " + what)
+
+                if len(stacks) > 1:
+                    auxwhat = getText(error.getElementsByTagName('auxwhat'))
+                    auxstack = stacks[1]
+                    auxframes = auxstack.getElementsByTagName('frame')
+                    arrange_frames_by_code(code, auxframes[::-1],
+                        "[" + kind + "]-INFO: " + auxwhat)
+
+                if not kind in count_error_kinds:
+                    count_error_kinds[kind] = 0
+                count_error_kinds[kind] += 1
+
+        except Exception, e:
+            print "Exception checking elements valgrind XML: %s" % (e)
+            self.passed = False
+
+        def dump_code_errors(tree, depth):
+            for msg, branch in tree.items():
+                print '  ' * depth + msg
+                if len(branch):
+                    dump_code_errors(branch, depth+1)
+
+        dump_code_errors(code, 0)
+
+        for kind, count in count_error_kinds.iteritems():
+            msg =  "Valgrind found %d errors of type %s" % (count, kind)
+            self.stdout += msg + "\n"
+            print msg
+        if count_bytes_leaked > 0:
+            msg = "Valgrind detected %s bytes definitely leaked" % (count_bytes_leaked)
+            self.stdout += msg + "\n"
+            print msg
+            self.passed = False
+        if count_errors_found > 0:
+            msg = "Valgrind detected %s total errors" % (count_errors_found)
+            self.stdout += msg + "\n"
+            print msg
+            self.passed = False
+
+
     def __parse_valgrind_xml(self):
         #Parse valgrind XML and calculate number of bytes definately lost
         ast_directories = "%s/%s" % (Asterisk.test_suite_root, self.test_name.lstrip("tests/"))
@@ -197,92 +294,26 @@
         while True:
             if os.path.isdir("%s/ast%d" % (ast_directories, i)):
                 ast_dir = "%s/ast%d/" % (ast_directories, i)
-                if os.path.exists(ast_dir+"/valgrind.xml"):
+                xml_file = ast_dir+"/valgrind.xml"
+                if os.path.exists(xml_file):
                     print "Found the valgrind XML in %s " % ast_dir
-                    count_bytes_leaked = 0
-                    count_errors_found = 0
-                    count_error_kinds = {}
                     try:
-                        xmldoc = xml.dom.minidom.parse(ast_dir+"/valgrind.xml")
+                        xmldoc = xml.dom.minidom.parse(xml_file)
                     except Exception, e:
                         # valgrind may have left off the closing tag
-                        with open(ast_dir+"/valgrind.xml", "a") as xmlfile:
+                        with open(xml_file, "a") as xmlfile:
                             xmlfile.write("</valgrindoutput>")
                         try:
-                            xmldoc = xml.dom.minidom.parse(ast_dir+"/valgrind.xml")
+                            xmldoc = xml.dom.minidom.parse(xml_file)
                         except Exception, e:
-                            msg = "Exception while parsing %s/valgrind.xml: %s" % (ast_dir, e)
+                            msg = "Exception while parsing %s: %s" % (xml_file, e)
                             self.stdout += msg + "\n"
                             print msg
                             self.passed = False
                             i += 1
                             continue
 
-                    try:
-                        error_list = xmldoc.getElementsByTagName('error')
-                        count_errors_found = len(error_list)
-
-                        def getText(nodelist):
-                            text = []
-                            for node in nodelist:
-                                if node.nodeType == node.ELEMENT_NODE:
-                                    text.append(getText(node.childNodes))
-                                if node.nodeType == node.TEXT_NODE:
-                                    text.append(str(node.data))
-                            return ''.join(text)
-
-                        for error in error_list:
-                            kind = getText(error.getElementsByTagName('kind'))
-                            msg = ""
-
-                            stack = error.getElementsByTagName('stack')[0]
-                            frames = stack.getElementsByTagName('frame')
-                            for frame in frames:
-                                fn = getText(frame.getElementsByTagName('fn'))
-                                file = getText(frame.getElementsByTagName('file'))
-                                line = getText(frame.getElementsByTagName('line'))
-
-                                if "" == file:
-                                    msg += " %s()" % (fn)
-                                else:
-                                    msg += " %s()[%s:%s]" % (fn, file, line)
-
-                                #if len(msg) > 70:
-                                #    msg += " ..."
-                                #    break
-
-                            if not kind in count_error_kinds:
-                                count_error_kinds[kind] = []
-                            count_error_kinds[kind].append(msg)
-
-                            if kind == "Leak_DefinitelyLost":
-                                leaked_bytes = error.getElementsByTagName('leakedbytes')
-                                if len(leaked_bytes) == 1:
-                                    dom_element = leaked_bytes[0]
-                                    count_bytes_leaked += int(dom_element.childNodes[0].nodeValue)
-
-                    except Exception, e:
-                        print "Exception checking elements valgrind XML: %s" % (e)
-                        self.passed = False
-
-                    for kind, list in count_error_kinds.iteritems():
-                        msg =  "Valgrind found %d errors of type %s" % (len(list), kind)
-                        self.stdout += msg + "\n    first:" + list[0] + "\n"
-                        print msg
-                        for details in list:
-                            print "   " + details
-
-                    if count_bytes_leaked > 0:
-                        msg = "Valgrind detected %s bytes definitely leaked" % (count_bytes_leaked)
-                        self.stdout += msg + "\n"
-                        print msg
-                        self.passed = False
-                    if count_errors_found > 0:
-                        msg = "Valgrind detected %s total errors" % (count_errors_found)
-                        self.stdout += msg + "\n"
-                        print msg
-                        self.passed = False
-
+                    self.__parse_valgrind_xml_doc(xmldoc)
             else:
                 break
             i += 1




More information about the asterisk-commits mailing list