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

George Joseph asteriskteam at digium.com
Fri Sep 2 10:15:54 CDT 2022


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/testsuite/+/19079 )


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(-)



  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/79/19079/1

diff --git a/runtests.py b/runtests.py
index c6f4149..bf4baaa 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/+/19079
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Change-Id: I06d659400a1ebc29c82b16f1508506a2a331e2b1
Gerrit-Change-Number: 19079
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220902/ea388bd5/attachment-0001.html>


More information about the asterisk-code-review mailing list