Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465"""The kernel's memory cap keeps measuring under a /proc without the split counters.
footprint() sums RssAnon, RssShmem and VmSwap from /proc/self/status. A sandboxor an old kernel whose status lacks them must fall back to the statm residentset rather than return None, which would turn the cap off. E2E runs on hostswhose /proc has the counters, so it cannot reach the fallback."""
import iofrom pathlib import Pathimport sysimport unittestfrom unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "priv" / "python"))import albedo_memory # noqa: E402
FULL = ( b"Name:\tpython3\n" b"VmData:\t 9000 kB\n" b"RssAnon:\t 1000 kB\n" b"RssFile:\t 5000 kB\n" b"RssShmem:\t 20 kB\n" b"VmSwap:\t 300 kB\n")SPLIT_MISSING = b"Name:\tpython3\nVmRSS:\t 6000 kB\n"STATM = b"9000 1500 400 1 0 800 0\n"
def proc(status: bytes | None): """open() over a fake /proc/self: status as given (None: unreadable)."""
def fake(path, mode="r", *args, **kwargs): if path == "/proc/self/status": if status is None: raise FileNotFoundError(path) return io.BytesIO(status) if path == "/proc/self/statm": return io.BytesIO(STATM) raise FileNotFoundError(path)
return mock.patch.object(albedo_memory, "open", fake, create=True)
class FootprintTest(unittest.TestCase): def test_the_split_counters_are_summed(self): with proc(FULL): self.assertEqual(albedo_memory.footprint(), (1000 + 20 + 300) * 1024)
def test_a_status_without_them_falls_back_to_the_resident_set(self): with proc(SPLIT_MISSING): self.assertEqual(albedo_memory.footprint(), 1500 * albedo_memory.PAGE)
def test_an_unreadable_status_falls_back_to_the_resident_set(self): with proc(None): self.assertEqual(albedo_memory.footprint(), 1500 * albedo_memory.PAGE)
def test_a_malformed_counter_counts_as_missing(self): with proc(FULL.replace(b" 300 kB", b"")): self.assertEqual(albedo_memory.footprint(), 1500 * albedo_memory.PAGE)
if __name__ == "__main__": unittest.main()