From 7a22dcb687324a464d2b03dc7227969922203899 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 4 Oct 2023 16:02:13 +0200 Subject: [PATCH] pexpect: Check if the process exited with a signal This would have been helpful in #10044: > signals.py:28: SIGNAL SIGSEGV from expect_prompt() instead of "EOF". --- build_tools/pexpect_helper.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build_tools/pexpect_helper.py b/build_tools/pexpect_helper.py index 68d14ba62..d8c705949 100644 --- a/build_tools/pexpect_helper.py +++ b/build_tools/pexpect_helper.py @@ -22,6 +22,7 @@ import re import sys import time import pexpect +from signal import Signals # Default timeout for failing to match. TIMEOUT_SECS = 5 @@ -246,8 +247,15 @@ class SpawnedProc(object): Report it to stdout, along with the offending call site. If 'unmatched' is set, print it to stdout. """ + # Close the process so we can get the status + self.spawn.close() colors = self.colors() failtype = pexpect_error_type(err) + # If we get an EOF, we check if the process exited with a signal. + # This shows us e.g. if it crashed + if failtype == 'EOF' and self.spawn.signalstatus != 0: + failtype = "SIGNAL " + Signals(self.spawn.signalstatus).name + fmtkeys = {"failtype": failtype, "pat": escape(pat)} fmtkeys.update(**colors)