From 108a651f9cc03658b7ddfb583c27266e74f6239b Mon Sep 17 00:00:00 2001 From: "Gabriele N. Tornetta" Date: Wed, 30 Aug 2023 09:56:49 +0100 Subject: [PATCH] collect logs --- configure.ac | 5 +++- src/Makefile.am | 5 ++-- test/utils.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 1f62949c..9d1b0cef 100644 --- a/configure.ac +++ b/configure.ac @@ -81,7 +81,10 @@ AM_CONDITIONAL([COVERAGE], [test x$coverage = xtrue]) AC_ARG_ENABLE([debug-symbols], [ --enable-debug-symbols Include debug symbols], [ case "${enableval}" in - yes) debugsymbols=true ;; + yes) + debugsymbols=true + AUSTINP_LDADD+=" -lm" + ;; no) debugsymbols=false ;; *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug-symbols]) ;; esac], [debugsymbols=false]) diff --git a/src/Makefile.am b/src/Makefile.am index 380bb12d..73644cad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,7 +25,8 @@ OPT_FLAGS = -O3 STRIP_FLAGS = -Os -s if DEBUG_SYMBOLS -DEBUG_OPTS = -g +DEBUG_OPTS = -g -DDEBUG +austin_LDADD = -lm undefine STRIP_FLAGS endif @@ -62,5 +63,5 @@ bin_PROGRAMS += austinp austinp_SOURCES = $(austin_SOURCES) austinp_CFLAGS = $(austin_CFLAGS) @AUSTINP_CFLAGS@ -austinp_LDADD = @AUSTINP_LDADD@ +austinp_LDADD = $(austin_LDADD) @AUSTINP_LDADD@ endif diff --git a/test/utils.py b/test/utils.py index c54f48de..ba4f5094 100644 --- a/test/utils.py +++ b/test/utils.py @@ -31,14 +31,16 @@ from pathlib import Path from shutil import rmtree from subprocess import PIPE +from subprocess import CalledProcessError from subprocess import CompletedProcess from subprocess import Popen +from subprocess import TimeoutExpired from subprocess import check_output -from subprocess import run from test import PYTHON_VERSIONS from time import sleep from types import ModuleType from typing import Iterator +from typing import List from typing import TypeVar @@ -131,9 +133,60 @@ def bt(binary: Path) -> str: return "No core dump available." +def collect_logs(variant: str, pid: int) -> List[str]: + match platform.system(): + case "Linux": + with Path("/var/log/syslog").open() as logfile: + needle = f"{variant}[{pid}]" + return [_.strip() for _ in logfile.readlines() if needle in _] + case _: + return [] + + EXEEXT = ".exe" if platform.system() == "Windows" else "" +# Taken from the subprocess module +def run( + *popenargs, input=None, capture_output=False, timeout=None, check=False, **kwargs +): + if input is not None: + if kwargs.get("stdin") is not None: + raise ValueError("stdin and input arguments may not both be used.") + kwargs["stdin"] = PIPE + + if capture_output: + if kwargs.get("stdout") is not None or kwargs.get("stderr") is not None: + raise ValueError( + "stdout and stderr arguments may not be used " "with capture_output." + ) + kwargs["stdout"] = PIPE + kwargs["stderr"] = PIPE + + with Popen(*popenargs, **kwargs) as process: + try: + stdout, stderr = process.communicate(input, timeout=timeout) + except TimeoutExpired as exc: + process.kill() + if platform.system() == "Windows": + exc.stdout, exc.stderr = process.communicate() + else: + process.wait() + raise + except: # noqa + process.kill() + raise + retcode = process.poll() + if check and retcode: + raise CalledProcessError( + retcode, process.args, output=stdout, stderr=stderr + ) + result = CompletedProcess(process.args, retcode, stdout, stderr) + result.pid = process.pid + + return result + + class Variant(str): ALL: list["Variant"] = [] @@ -144,6 +197,7 @@ def __init__(self, name: str) -> None: if not path.is_file(): path = Path(name).with_suffix(EXEEXT) + self.name = name self.path = path self.ALL.append(self) @@ -174,6 +228,12 @@ def __call__( result.stdout = result.stdout.decode(errors="ignore") result.stderr = result.stderr.decode() + if result.returncode and (logs := collect_logs(self.name, result.pid)): + print(f"logs for {result.pid}".center(80, "=")) + for log in logs: + print(log) + print(f"end of logs for {result.pid}".center(80, "=")) + return result