Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.9 KB
Raw Blame
"""Keep child memory gates independent from the spawning test runner."""
# allow: no-sut-import — tests the shared workload memory reader in owned children.

from pathlib import Path
import subprocess
import sys
from types import SimpleNamespace

import pytest

from tests.performance._shared import resources


@pytest.mark.skipif(
    sys.platform != "linux" or not Path("/proc/self/status").is_file(),
    reason="Linux procfs memory accounting",
)
def test_child_peak_excludes_parent_and_detects_own_allocation():
    child = """
from tests.performance._shared.resources import peak_rss_mib
before = peak_rss_mib()
assert before < 24, before
payload = bytearray(32 * 1024 * 1024)
payload[::4096] = b'x' * len(payload[::4096])
after = peak_rss_mib()
assert after >= before + 24, (before, after)
"""
    parent = """
import subprocess
import sys
payload = bytearray(32 * 1024 * 1024)
payload[::4096] = b'x' * len(payload[::4096])
subprocess.run([sys.executable, '-c', sys.argv[1]], check=True)
"""
    result = subprocess.run(
        [sys.executable, "-c", parent, child],
        capture_output=True,
        text=True,
        timeout=30,
    )
    assert result.returncode == 0, result.stdout + result.stderr


@pytest.mark.parametrize(
    "platform,peak", [("linux", 2048), ("darwin", 2 * 1024 * 1024)]
)
def test_fallback_keeps_platform_specific_rss_units(
    monkeypatch, platform, peak
):
    def unavailable():
        raise OSError("procfs unavailable")

    monkeypatch.setattr(resources, "sys", SimpleNamespace(platform=platform))
    monkeypatch.setattr(
        resources, "Path", lambda _: SimpleNamespace(read_text=unavailable)
    )
    monkeypatch.setitem(
        sys.modules,
        "resource",
        SimpleNamespace(
            RUSAGE_SELF=0,
            getrusage=lambda _: SimpleNamespace(ru_maxrss=peak),
        ),
    )
    assert resources.peak_rss_mib() == 2