Debian Codegraph @

rpython/tool/test/test_leakfinder.py

raw symbols SCIP
1 import py
2 from rpython.tool import leakfinder
3
4 def test_start_stop():
5 leakfinder.start_tracking_allocations()
6 assert leakfinder.TRACK_ALLOCATIONS
7 leakfinder.stop_tracking_allocations(True)
8 assert not leakfinder.TRACK_ALLOCATIONS
9
10 def test_start_stop_nested():
11 leakfinder.start_tracking_allocations()
12 p2 = leakfinder.start_tracking_allocations()
13 assert leakfinder.TRACK_ALLOCATIONS
14 leakfinder.stop_tracking_allocations(True, prev=p2)
15 assert leakfinder.TRACK_ALLOCATIONS
16 leakfinder.stop_tracking_allocations(True)
17 assert not leakfinder.TRACK_ALLOCATIONS
18
19 def test_remember_free():
20 leakfinder.start_tracking_allocations()
21 x = 1234
22 leakfinder.remember_malloc(x)
23 leakfinder.remember_free(x)
24 leakfinder.stop_tracking_allocations(True)
25
26 def test_remember_forget():
27 leakfinder.start_tracking_allocations()
28 x = 1234
29 leakfinder.remember_malloc(x)
30 py.test.raises(leakfinder.MallocMismatch,
31 leakfinder.stop_tracking_allocations, True)
32
33 def test_nested_remember_forget_1():
34 leakfinder.start_tracking_allocations()
35 x = 1234
36 leakfinder.remember_malloc(x)
37 p2 = leakfinder.start_tracking_allocations()
38 leakfinder.stop_tracking_allocations(True, prev=p2)
39 py.test.raises(leakfinder.MallocMismatch,
40 leakfinder.stop_tracking_allocations, True)
41
42 def test_nested_remember_forget_2():
43 p2 = leakfinder.start_tracking_allocations()
44 x = 1234
45 leakfinder.remember_malloc(x)
46 py.test.raises(leakfinder.MallocMismatch,
47 leakfinder.stop_tracking_allocations, True, prev=p2)
48 leakfinder.stop_tracking_allocations(True)
49
50 def test_traceback():
51 leakfinder.start_tracking_allocations()
52 x = 1234
53 leakfinder.remember_malloc(x)
54 res = leakfinder.stop_tracking_allocations(check=False)
55 assert res.keys() == [x]
56 print res[x]
57 assert isinstance(res[x], str)
58 assert 'test_traceback' in res[x]
59 assert 'leakfinder.remember_malloc(x)' in res[x]
60
61 def test_malloc_mismatch():
62 import sys, traceback, cStringIO
63 sio = cStringIO.StringIO()
64 traceback.print_stack(sys._getframe(), limit=10, file=sio)
65 tb = sio.getvalue()
66 e = leakfinder.MallocMismatch({1234: tb, 2345: tb})
67 print str(e)
68 # grouped entries for 1234 and 2345
69 assert '1234:\n2345:\n' in str(e) or '2345:\n1234:\n' in str(e)
70 assert tb[-80:] in str(e)