984292c368
core/syslogs.py gathers, scoped to the diagnostic window: - kernel-log slice (journalctl -k): Xid, OOM, MCE, PCIe AER, thermal, hung tasks - crashed-process records (coredumpctl): exe, signal, when Stored as syslogs.txt in the diagnostic dir, included in the Report bundle, and fed to the AI on "Explain" alongside the game logs. Best-effort (degrades if the tools are missing/denied); treats journalctl's "-- No entries --" as empty. Tests + docs (M15/SPEC). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""Tests for M15 session-scoped system-log collection (kernel + coredumps)."""
|
|
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from rigdoctor.core import syslogs
|
|
|
|
|
|
class KernelLogTests(unittest.TestCase):
|
|
def test_passes_since_and_tails(self):
|
|
with mock.patch("shutil.which", return_value="/usr/bin/journalctl"), \
|
|
mock.patch.object(syslogs, "_run", return_value="X" * 100 + "TAILLINE") as run:
|
|
out = syslogs.kernel_log(since=1_000_000_000, max_bytes=8)
|
|
self.assertEqual(out, "TAILLINE")
|
|
cmd = run.call_args[0][0]
|
|
self.assertIn("-k", cmd)
|
|
self.assertIn("--since", cmd)
|
|
|
|
def test_missing_tool_returns_empty(self):
|
|
with mock.patch("shutil.which", return_value=None):
|
|
self.assertEqual(syslogs.kernel_log(), "")
|
|
|
|
|
|
class CoredumpTests(unittest.TestCase):
|
|
def test_empty_when_no_coredumps(self):
|
|
with mock.patch("shutil.which", return_value="/usr/bin/coredumpctl"), \
|
|
mock.patch.object(syslogs, "_run", return_value="No coredumps found."):
|
|
self.assertEqual(syslogs.coredumps(), "")
|
|
|
|
def test_returns_list(self):
|
|
with mock.patch("shutil.which", return_value="/usr/bin/coredumpctl"), \
|
|
mock.patch.object(syslogs, "_run", return_value="TIME PID SIG EXE\n... SEGV PathOfExile"):
|
|
out = syslogs.coredumps()
|
|
self.assertIn("PathOfExile", out)
|
|
|
|
|
|
class CollectTests(unittest.TestCase):
|
|
def test_collect_combines_sections(self):
|
|
with mock.patch.object(syslogs, "kernel_log", return_value="NVRM: Xid 79"), \
|
|
mock.patch.object(syslogs, "coredumps", return_value="game SIGSEGV"):
|
|
out = syslogs.collect()
|
|
self.assertIn("Kernel log", out)
|
|
self.assertIn("Xid 79", out)
|
|
self.assertIn("Crashed processes", out)
|
|
self.assertIn("SIGSEGV", out)
|
|
|
|
def test_collect_empty_when_nothing(self):
|
|
with mock.patch.object(syslogs, "kernel_log", return_value=""), \
|
|
mock.patch.object(syslogs, "coredumps", return_value=""):
|
|
self.assertEqual(syslogs.collect(), "")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|