testsAndMisc/python_pkg/swap_bench/tests/test_stats.py
Krzysztof kuhy Rudnicki c76ce53e90
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Gate swap_bench host runs on desktop stall
The C6 live check failed: global memory PSI full avg10 rose during host
runs. Global PSI full counts moments when every busy task is stalled,
which the bench scope causes by itself, so no global figure measures the
desktop. A host run now fails (exit 3, row kept) when the login session
scopes stall over 1 s, and records outside_pswpout: zram's pool is not
charged to the scope, so global reclaim swaps other processes too
(153k-224k pages per run vs 111k idle). DOCS corrected: the scope does
not keep the desktop out of swap, and a nonzero zram disk_wb_pages on
the host is background (20k pages over an idle 28 s).

Bug-class-check: linux_configuration/fixes/lib/tests/test_swap_bench.sh (pressed-desktop case)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:24:52 +01:00

90 lines
3.1 KiB
Python

"""Tests for turning one run's raw /proc and /sys copies into a TSV row."""
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from python_pkg.swap_bench.stats import COLUMNS, compute_row, format_row
if TYPE_CHECKING:
from pathlib import Path
def _row(run_dir: Path, env: str, setup: str) -> dict[str, str]:
return compute_row(run_dir, env=env, setup=setup, seed=1, size_mib=1, date="d")
def test_zram_host_row(run_dir: Path) -> None:
"""Host zram: scope PSI, per-run mm_stat ratio, zram writes not disk."""
row = _row(run_dir, "host", "zram")
assert row["ratio"] == "3.00" # (4-1) GiB in over (1.5-0.5) GiB stored
assert row["psi_some_ms"] == "40"
assert row["psi_full_ms"] == "30"
assert row["majflt"] == "500"
# 8000 pswpout pages minus (65600-8000)/8 = 7200 zram pages.
assert row["disk_wb_pages"] == "800"
assert row["zswpwb"] == "3"
assert row["global_full_avg10"] == "0.20"
assert row["pages"] == "256"
assert row["desktop_full_ms"] == "6" # two sessions, 3000 us each
# Global pswpout grew 8000 pages, the scope swapped out 7000.
assert row["outside_pswpout"] == "1000"
assert list(row) == list(COLUMNS)
def test_zswap_host_ratio_from_cgroup(run_dir: Path) -> None:
"""Host zswap: ratio from the scope's zswapped/zswap at peak."""
assert _row(run_dir, "host", "zswap")["ratio"] == "3.50"
def test_vm_rows_are_system_wide(run_dir: Path) -> None:
"""VM: global PSI and zswpwb deltas, ratio from /proc/meminfo."""
row = _row(run_dir, "vm", "zswap")
assert row["psi_some_ms"] == "300"
assert row["psi_full_ms"] == "200"
assert row["zswpwb"] == "2"
assert row["ratio"] == "2.50"
assert row["desktop_full_ms"] == "na"
assert row["outside_pswpout"] == "na"
def test_host_without_sessions_has_no_desktop_psi(run_dir: Path) -> None:
"""No login session scope (a headless host) gives na, not zero."""
(run_dir / "before/desktop_pressure").unlink()
assert _row(run_dir, "host", "zram")["desktop_full_ms"] == "na"
def test_missing_zram_files_mean_no_zram(run_dir: Path) -> None:
"""Without zram stats, every pswpout page counts as disk writeback."""
for name in (
"before/zram_stat",
"after/zram_stat",
"before/mm_stat",
"peak/mm_stat",
):
(run_dir / name).unlink()
row = _row(run_dir, "vm", "zram")
assert row["disk_wb_pages"] == "8000"
assert row["ratio"] == "na"
def test_zero_pool_ratio_is_na(run_dir: Path) -> None:
"""A run that never reached the pool has no ratio, not a crash."""
(run_dir / "peak/meminfo").write_text("Zswap: 0 kB\nZswapped: 0 kB\n")
assert _row(run_dir, "vm", "zswap")["ratio"] == "na"
def test_bad_env_is_refused(run_dir: Path) -> None:
"""Only host and vm exist."""
with pytest.raises(ValueError, match="env"):
_row(run_dir, "cloud", "zram")
def test_format_row_is_tab_separated(run_dir: Path) -> None:
"""format_row joins the columns in order with tabs."""
row = _row(run_dir, "host", "zram")
assert format_row(row) == "\t".join(row[c] for c in COLUMNS)
assert format_row(None) == "\t".join(COLUMNS)