<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/testsuite/+/19077">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">runtests.py: Fix detection of asterisk core files<br><br>Any core file found, whether generated by asterisk or not, was<br>triggering a failed test. On a development system, core files<br>can easily exist from completely unrelated activity and can<br>therefore give erroneous failures.<br><br>We now call the "file" utility to make sure the file is actually<br>an LSB core file, then call gdb with "info proc" to get the<br>executable file name. If it doesn't contain "asterisk", we don't<br>bother with it.<br><br>Change-Id: I06d659400a1ebc29c82b16f1508506a2a331e2b1<br>---<br>M runtests.py<br>1 file changed, 60 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/77/19077/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/runtests.py b/runtests.py</span><br><span>index c6f4149..bf4baaa 100755</span><br><span>--- a/runtests.py</span><br><span>+++ b/runtests.py</span><br><span>@@ -153,7 +153,6 @@</span><br><span> self.stdout_print("Test passed but was expected to fail.")</span><br><span> if not did_pass and not self.test_config.expect_pass:</span><br><span> print("Test failed as expected.")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> self.passed = (did_pass == self.test_config.expect_pass)</span><br><span> if abandon_test:</span><br><span> self.passed = False</span><br><span>@@ -202,23 +201,59 @@</span><br><span> print("FAILED TO EXECUTE %s, it must exist and be executable" % cmd)</span><br><span> self.time = time.time() - start_time</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ def _is_asterisk_coredump(self, corefile):</span><br><span style="color: hsl(120, 100%, 40%);">+ file_cmd = ["file", corefile]</span><br><span style="color: hsl(120, 100%, 40%);">+ try:</span><br><span style="color: hsl(120, 100%, 40%);">+ cp = subprocess.run(file_cmd, capture_output=True, universal_newlines=True)</span><br><span style="color: hsl(120, 100%, 40%);">+ if not re.search("LSB core file", cp.stdout):</span><br><span style="color: hsl(120, 100%, 40%);">+ return False</span><br><span style="color: hsl(120, 100%, 40%);">+ except:</span><br><span style="color: hsl(120, 100%, 40%);">+ print("Unknown exception occurred while executing %r" % (file_cmd,))</span><br><span style="color: hsl(120, 100%, 40%);">+ return False</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ gdb_cmd = ["gdb",</span><br><span style="color: hsl(120, 100%, 40%);">+ "-nh", "--batch-silent",</span><br><span style="color: hsl(120, 100%, 40%);">+ "-iex", "set auto-solib-add off",</span><br><span style="color: hsl(120, 100%, 40%);">+ "-ex", "set logging file /dev/stderr",</span><br><span style="color: hsl(120, 100%, 40%);">+ "-ex", "set logging redirect",</span><br><span style="color: hsl(120, 100%, 40%);">+ "-ex", "set logging enabled",</span><br><span style="color: hsl(120, 100%, 40%);">+ "-ex", "info proc exe",</span><br><span style="color: hsl(120, 100%, 40%);">+ "asterisk", corefile</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ try:</span><br><span style="color: hsl(120, 100%, 40%);">+ reg = re.compile(r"exe\s+=\s+.*/asterisk.*")</span><br><span style="color: hsl(120, 100%, 40%);">+ # The output of the gdb command will be something like...</span><br><span style="color: hsl(120, 100%, 40%);">+ # exe = '/usr/sbin/asterisk -fcg'</span><br><span style="color: hsl(120, 100%, 40%);">+ # We'll check it for "asterisk" and if it doesn't</span><br><span style="color: hsl(120, 100%, 40%);">+ # match it's not an asterisk coredump</span><br><span style="color: hsl(120, 100%, 40%);">+ cp = subprocess.run(gdb_cmd, capture_output=True, universal_newlines=True)</span><br><span style="color: hsl(120, 100%, 40%);">+ if reg.match(cp.stderr):</span><br><span style="color: hsl(120, 100%, 40%);">+ return True</span><br><span style="color: hsl(120, 100%, 40%);">+ else:</span><br><span style="color: hsl(120, 100%, 40%);">+ return False</span><br><span style="color: hsl(120, 100%, 40%);">+ except:</span><br><span style="color: hsl(120, 100%, 40%);">+ print("Unknown exception occurred while executing %r" % (gdb_cmd,))</span><br><span style="color: hsl(120, 100%, 40%);">+ return False</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> def _check_for_core(self):</span><br><span> core_files = []</span><br><span> </span><br><span> contents = os.listdir('.')</span><br><span> for item in contents:</span><br><span style="color: hsl(0, 100%, 40%);">- if item.startswith('core') or item.startswith('vgcore'):</span><br><span style="color: hsl(120, 100%, 40%);">+ if self._is_asterisk_coredump(item):</span><br><span> core_files.append(item)</span><br><span> </span><br><span> contents = os.listdir('/tmp')</span><br><span> for item in contents:</span><br><span style="color: hsl(0, 100%, 40%);">- if item.startswith('core') or item.startswith('vgcore'):</span><br><span style="color: hsl(0, 100%, 40%);">- core_files.append(os.path.join('/tmp', item))</span><br><span style="color: hsl(120, 100%, 40%);">+ corepath = os.path.join('/tmp', item);</span><br><span style="color: hsl(120, 100%, 40%);">+ if self._is_asterisk_coredump(corepath):</span><br><span style="color: hsl(120, 100%, 40%);">+ core_files.append(corepath)</span><br><span> </span><br><span> contents = os.listdir(self.test_name)</span><br><span> for item in contents:</span><br><span style="color: hsl(0, 100%, 40%);">- if item.startswith('core') or item.startswith('vgcore'):</span><br><span style="color: hsl(0, 100%, 40%);">- core_files.append(os.path.join(self.test_name, item))</span><br><span style="color: hsl(120, 100%, 40%);">+ corepath = os.path.join(self.test_name, item);</span><br><span style="color: hsl(120, 100%, 40%);">+ if self._is_asterisk_coredump(corepath):</span><br><span style="color: hsl(120, 100%, 40%);">+ core_files.append(corepath)</span><br><span> </span><br><span> return core_files</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/testsuite/+/19077">change 19077</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/testsuite/+/19077"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 19 </div>
<div style="display:none"> Gerrit-Change-Id: I06d659400a1ebc29c82b16f1508506a2a331e2b1 </div>
<div style="display:none"> Gerrit-Change-Number: 19077 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>