[Asterisk-code-review] runtests.py: Fix detection of asterisk core files (testsuite[20])

Friendly Automation asteriskteam at digium.com
Wed Sep 7 05:51:14 CDT 2022


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/19078 )

Change subject: runtests.py: Fix detection of asterisk core files
......................................................................

runtests.py: Fix detection of asterisk core files

Any core file found, whether generated by asterisk or not, was
triggering a failed test.  On a development system, core files
can easily exist from completely unrelated activity and can
therefore give erroneous failures.

We now call the "file" utility to make sure the file is actually
an LSB core file, then call gdb with "info proc" to get the
executable file name.  If it doesn't contain "asterisk", we don't
bother with it.

Change-Id: I06d659400a1ebc29c82b16f1508506a2a331e2b1
---
M runtests.py
1 file changed, 60 insertions(+), 6 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit




diff --git a/runtests.py b/runtests.py
index e45a5da..1a50994 100755
--- a/runtests.py
+++ b/runtests.py
@@ -153,7 +153,6 @@
                 self.stdout_print("Test passed but was expected to fail.")
             if not did_pass and not self.test_config.expect_pass:
                 print("Test failed as expected.")
-
             self.passed = (did_pass == self.test_config.expect_pass)
             if abandon_test:
                 self.passed = False
@@ -202,23 +201,59 @@
             print("FAILED TO EXECUTE %s, it must exist and be executable" % cmd)
         self.time = time.time() - start_time
 
+    def _is_asterisk_coredump(self, corefile):
+        file_cmd = ["file", corefile]
+        try:
+            cp = subprocess.run(file_cmd, capture_output=True, universal_newlines=True)
+            if not re.search("LSB core file", cp.stdout):
+                return False
+        except:
+            print("Unknown exception occurred while executing %r" % (file_cmd,))
+            return False
+
+        gdb_cmd = ["gdb",
+            "-nh", "--batch-silent",
+            "-iex", "set auto-solib-add off",
+            "-ex", "set logging file /dev/stderr",
+            "-ex", "set logging redirect",
+            "-ex", "set logging enabled",
+            "-ex", "info proc exe",
+            "asterisk", corefile
+            ]
+        try:
+            reg = re.compile(r"exe\s+=\s+.*/asterisk.*")
+            # The output of the gdb command will be something like...
+            # exe = '/usr/sbin/asterisk -fcg'
+            # We'll check it for "asterisk" and if it doesn't
+            # match it's not an asterisk coredump
+            cp = subprocess.run(gdb_cmd, capture_output=True, universal_newlines=True)
+            if reg.match(cp.stderr):
+                return True
+            else:
+                return False
+        except:
+            print("Unknown exception occurred while executing %r" % (gdb_cmd,))
+        return False
+
     def _check_for_core(self):
         core_files = []
 
         contents = os.listdir('.')
         for item in contents:
-            if item.startswith('core') or item.startswith('vgcore'):
+            if self._is_asterisk_coredump(item):
                 core_files.append(item)
 
         contents = os.listdir('/tmp')
         for item in contents:
-            if item.startswith('core') or item.startswith('vgcore'):
-                core_files.append(os.path.join('/tmp', item))
+            corepath = os.path.join('/tmp', item);
+            if self._is_asterisk_coredump(corepath):
+                core_files.append(corepath)
 
         contents = os.listdir(self.test_name)
         for item in contents:
-            if item.startswith('core') or item.startswith('vgcore'):
-                core_files.append(os.path.join(self.test_name, item))
+            corepath = os.path.join(self.test_name, item);
+            if self._is_asterisk_coredump(corepath):
+                core_files.append(corepath)
 
         return core_files
 

-- 
To view, visit https://gerrit.asterisk.org/c/testsuite/+/19078
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 20
Gerrit-Change-Id: I06d659400a1ebc29c82b16f1508506a2a331e2b1
Gerrit-Change-Number: 19078
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220907/a7c13cec/attachment-0001.html>


More information about the asterisk-code-review mailing list