Skip to content

Commit

Permalink
collect logs
Browse files Browse the repository at this point in the history
  • Loading branch information
P403n1x87 committed Aug 30, 2023
1 parent edfce19 commit 108a651
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
5 changes: 4 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
62 changes: 61 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"] = []

Expand All @@ -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)
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 108a651

Please sign in to comment.