This repository was archived by the owner on Apr 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_valgrind_utils.py
More file actions
47 lines (37 loc) · 1.44 KB
/
test_valgrind_utils.py
File metadata and controls
47 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from pathlib import Path
import pytest
from utils.valgrind import assert_valgrind_clean, parse_valgrind_log
def test_parse_valgrind_log_detects_clean_run(tmp_path):
log_path = tmp_path / "valgrind.log"
log_path.write_text(
"\n".join(
[
"==1== HEAP SUMMARY:",
"==1== in use at exit: 0 bytes in 0 blocks",
"==1== total heap usage: 10 allocs, 10 frees, 100 bytes allocated",
"==1== All heap blocks were freed -- no leaks are possible",
"==1== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)",
]
),
encoding="utf-8",
)
summary = parse_valgrind_log(log_path)
assert summary.definitely_lost == 0
assert summary.error_count == 0
assert summary.has_leaks is False
def test_assert_valgrind_clean_rejects_leaks(tmp_path):
log_path = tmp_path / "valgrind.log"
log_path.write_text(
"\n".join(
[
"==1== definitely lost: 45 bytes in 2 blocks",
"==1== indirectly lost: 0 bytes in 0 blocks",
"==1== possibly lost: 0 bytes in 0 blocks",
"==1== still reachable: 0 bytes in 0 blocks",
"==1== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)",
]
),
encoding="utf-8",
)
with pytest.raises(AssertionError):
assert_valgrind_clean(log_path)