aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_stats.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_stats.py b/tests/test_stats.py
index fad6cc2..81acdba 100644
--- a/tests/test_stats.py
+++ b/tests/test_stats.py
@@ -21,5 +21,28 @@ class Stats(unittest.TestCase):
self.assertIn("stats", names)
+class Intel(unittest.TestCase):
+ def test_parse_bytes(self):
+ self.assertEqual(stats._parse_bytes("12G"), 12 * 1024 ** 3)
+ self.assertEqual(stats._parse_bytes("512M"), 512 * 1024 ** 2)
+ self.assertEqual(stats._parse_bytes(2048), 2048)
+ self.assertIsNone(stats._parse_bytes("nope"))
+
+ def test_vram_scan_counts_each_client_once(self):
+ import tempfile
+ root = Path(tempfile.mkdtemp())
+ rows = [
+ ("100", "3", "drm-driver:\txe\ndrm-client-id:\t7\ndrm-resident-vram0:\t1024 MiB\n"),
+ ("100", "4", "drm-driver:\txe\ndrm-client-id:\t7\ndrm-resident-vram0:\t1024 MiB\n"),
+ ("200", "5", "drm-driver:\txe\ndrm-client-id:\t8\ndrm-resident-vram0:\t512 MiB\n"),
+ ("300", "6", "drm-driver:\ti915\ndrm-client-id:\t9\ndrm-resident-vram0:\t999 MiB\n"),
+ ]
+ for pid, fd, body in rows:
+ d = root / pid / "fdinfo"
+ d.mkdir(parents=True, exist_ok=True)
+ (d / fd).write_text(body)
+ self.assertEqual(stats._intel_vram_used(root), (1024 + 512) * 1024 ** 2)
+
+
if __name__ == "__main__":
unittest.main()