[asterisk-commits] runtests: Add an option (-k|--keep-core) to keep a core file (testsuite[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Oct 25 07:53:38 CDT 2015


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: runtests: Add an option (-k|--keep-core) to keep a core file
......................................................................


runtests: Add an option (-k|--keep-core) to keep a core file

Sometimes, when the Test Suite is being used to diagnose some particularly
heinous crash in Asterisk, it is useful to keep the core file generated from
the crashing instance. By default, the Test Suite removes these core files.
This is a good default option to have; the Test Suite is run on CI build
agents, and in the past we ran into situations where the generated core files
caused the disk to run out of memory (particularly when someone commits a
change that causes Asterisk to crash on startup/shutdown).

This patch adds a command line option, -k or --keep-core, that lets you
override this behaviour when running the Test Suite. This makes it a bit
easier to diagnose problems when running the Test Suite locally.

Change-Id: I5a468e98811b1ff814fdb64aa6808eba3c17460b
---
M runtests.py
1 file changed, 14 insertions(+), 3 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, approved
  Corey Farrell: Looks good to me, but someone else must approve



diff --git a/runtests.py b/runtests.py
index 13bd8bc..bb121a5 100755
--- a/runtests.py
+++ b/runtests.py
@@ -173,7 +173,9 @@
             dest_dir = "./logs/%s" % self.test_relpath
             if not os.path.exists(dest_dir):
                 os.makedirs(dest_dir)
-            dest_file = open(dest_dir + "/backtrace_%s.txt" % str(random_num), "w")
+            dest_file_name = os.path.join(dest_dir,
+                                          "backtrace_{0}.txt".format(random_num))
+            dest_file = open(dest_file_name, "w")
             gdb_cmd = ["gdb",
                        "-se", "asterisk",
                        "-ex", "bt full",
@@ -186,15 +188,21 @@
                 if res != 0:
                     print "error analyzing core dump; gdb exited with %d" % res
                 # Copy the backtrace over to the logs
+                print "Archived backtrace: {0}".format(dest_file_name)
             except OSError, ose:
                 print "OSError ([%d]: %s) occurred while executing %r" % \
                     (ose.errno, ose.strerror, gdb_cmd)
-                return
             except:
                 print "Unknown exception occurred while executing %r" % (gdb_cmd,)
-                return
             finally:
                 dest_file.close()
+                if self.options.keep_core:
+                    try:
+                        dst_core = os.path.join(dest_dir, "core_{0}".format(random_num))
+                        shutil.copy(core, dst_core)
+                        print "Archived core file: {0}".format(dst_core)
+                    except Exception as e:
+                        print "Error occurred while copying core: {0}".format(e)
                 try:
                     os.unlink(core)
                 except OSError, e:
@@ -607,6 +615,9 @@
     parser.add_option("-v", "--version",
                       dest="version", default=None,
                       help="Specify the version of Asterisk rather then detecting it.")
+    parser.add_option("-k", "--keep-core", action="store_true",
+                      dest="keep_core", default=False,
+                      help="Archive the 'core' file if Asterisk crashes.")
     parser.add_option("-L", "--list-tags", action="store_true",
                       dest="list_tags", default=False,
                       help="List available tags")

-- 
To view, visit https://gerrit.asterisk.org/1373
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5a468e98811b1ff814fdb64aa6808eba3c17460b
Gerrit-PatchSet: 3
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list